Fixed ArcSys script

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
TGE
Posts: 38
Joined: Sat Dec 20, 2014 5:14 pm

Fixed ArcSys script

Post by TGE »

Implemented an endian check and added the name length (the script would break on FPAC files from Persona 4 Arena)

Code: Select all

# AR segs archives - Arc System Works (script 0.1.1)
#   Sonic Unleashed
#   Battle Fantasia
#   BlazBlue
#   Arcana Heart 3
#   Persona 4 Arena (Ultimax)
#   ...
# script for QuickBMS http://quickbms.aluigi.org

get BASE_NAME basename
string BASE_NAME += /
comtype deflate
endian big
getdstring SIGN 4
if SIGN == "segs"
    get DUMMY short
    get CHUNKS short
    get FULL_SIZE long
    get FULL_ZSIZE long
    putvarchr MEMORY_FILE 0 FULL_SIZE
    log MEMORY_FILE 0 0
    append
    for i = 0 < CHUNKS
        get ZSIZE short
        get SIZE short
        get OFFSET long
        math OFFSET -= 1
        if SIZE == 0
            math SIZE = 0x00010000
        endif
        clog MEMORY_FILE OFFSET ZSIZE SIZE
    next i
    append
else
    # pfd
    get SIZE asize
    log MEMORY_FILE 0 SIZE
endif

# the files are just compressed pfd files
# so we handle them here automatically (both!)

goto 0 MEMORY_FILE
get FULL_SIZE asize MEMORY_FILE
endian big
getdstring TYPE 4 MEMORY_FILE
if TYPE == ""   # pfd
    get DUMMY long MEMORY_FILE
    get DUMMY long MEMORY_FILE
    get FILES long MEMORY_FILE
    savepos BASE_OFF MEMORY_FILE
    for BASE_OFF = BASE_OFF < FULL_SIZE
        get HEADDATA_SIZE long MEMORY_FILE
        get SIZE long MEMORY_FILE
        get OFFSET long MEMORY_FILE
        get DUMMY long MEMORY_FILE
        get DUMMY long MEMORY_FILE
        get NAME string MEMORY_FILE
        math OFFSET += BASE_OFF
        set FNAME string BASE_NAME
        string FNAME += NAME
        log FNAME OFFSET SIZE MEMORY_FILE
        math BASE_OFF += HEADDATA_SIZE
        goto BASE_OFF MEMORY_FILE
    next
elif TYPE == "FPAC"
    endian little
    get BASE_OFF long MEMORY_FILE
    if BASE_OFF u>= FULL_SIZE
      endian big
      ReverseLong BASE_OFF
    endif
    get TOT_SIZE long MEMORY_FILE
    get FILES long MEMORY_FILE
    get DUMMY long MEMORY_FILE
    get NAMELEN long MEMORY_FILE
    get DUMMY long MEMORY_FILE
    get DUMMY long MEMORY_FILE
    for i = 0 < FILES
        getdstring NAME NAMELEN MEMORY_FILE
   get FILEID long MEMORY_FILE
        get OFFSET long MEMORY_FILE
        get SIZE long MEMORY_FILE
        Padding 16 MEMORY_FILE 0
        math OFFSET += BASE_OFF
        set FNAME string BASE_NAME
        string FNAME += NAME
        log FNAME OFFSET SIZE MEMORY_FILE
    next i
else
    get NAME basename
    get EXT extension
    string NAME += "_unpacked."
    string NAME += EXT
    set FNAME string BASE_NAME
    string FNAME += NAME
    log FNAME 0 FULL_SIZE MEMORY_FILE
endif

print "\nyou can try to reuse this script with the output files (pac, pfd and so on)\nfor extracting the other files contained in them"
Last edited by TGE on Fri Apr 24, 2015 2:06 pm, edited 1 time in total.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Fixed ArcSys script

Post by aluigi »

Well done, I have used it on the script online.
The only thing I changed was the check where I preferred to use an unsigned check (">=" instead of ">=")
TGE
Posts: 38
Joined: Sat Dec 20, 2014 5:14 pm

Re: Fixed ArcSys script

Post by TGE »

aluigi wrote:Well done, I have used it on the script online.
The only thing I changed was the check where I preferred to use an unsigned check (">=" instead of ">=")

No problem, but I found another issue.
The FPAC FILES loop needs to have the dummies replaced with padding instead.
Sorry for not noticing this earlier :p

Code: Select all

for i = 0 < FILES
   getdstring NAME NAMELEN MEMORY_FILE
   get FILEID long MEMORY_FILE
   get OFFSET long MEMORY_FILE
   get SIZE long MEMORY_FILE
   Padding 16 MEMORY_FILE 0
   math OFFSET += BASE_OFF
   set FNAME string BASE_NAME
   string FNAME += NAME
   log FNAME OFFSET SIZE MEMORY_FILE
next i


and the endian check should be

Code: Select all

endian big
get BASE_OFF long MEMORY_FILE
get TOT_SIZE long MEMORY_FILE
if TOT_SIZE != FULL_SIZE
  endian big
  ReverseLong BASE_OFF
  ReverseLong TOT_SIZE
endif
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Fixed ArcSys script

Post by aluigi »

Ok done (yeah it's "endian little" the first line in the second patch)
TGE
Posts: 38
Joined: Sat Dec 20, 2014 5:14 pm

Re: Fixed ArcSys script

Post by TGE »

aluigi wrote:Ok done (yeah it's "endian little" the first line in the second patch)

Oops, it was there because of testing :P
Thanks, by the way.