ZenHAX

Free Game Research Forum | Official QuickBMS support | twitter @zenhax | SSL HTTPS://zenhax.com
It is currently Sun Feb 28, 2021 6:47 pm

All times are UTC




Post new topic  Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed Mar 02, 2016 12:57 am 

Joined: Thu Aug 07, 2014 10:28 pm
Posts: 346
Code:
# Soul Sacrifice Delta (Vita)
# script for QuickBMS http://quickbms.aluigi.org
#made by chrrox
get name basename
endian big
Open FDDE PK 0
Open FDDE pfs 1
Open FDDE pkh 2
goto 8 1
get FOLDERS long 1
get TFILES long 1

for i = 0 < FOLDERS
   get FOLDERID long 1
   get FOLDERPARENT long 1
   get UNK long 1
   get SUBFLDR long 1
   get FILESTART long 1
   get FOLDERFILES long 1
   #print "%FOLDERID% %FOLDERPARENT% %UNK% %SUBFLDR% %FILESTART% %FOLDERFILES%"
   PutArray 3 i FOLDERPARENT
   PutArray 4 i FILESTART
   PutArray 5 i FOLDERFILES
next i

for i = 0 < FOLDERS
   get FOLDERNAMEOFF long 1
   PutArray 0 i FOLDERNAMEOFF
next i

for i = 0 < TFILES
   get FILENAMEOFF long 1
   PutArray 1 i FILENAMEOFF
next i

savepos NAMEBASE 1

for i = 0 < FOLDERS
   GetArray FOLDERNAMEOFF 0 i
   math FOLDERNAMEOFF += NAMEBASE
   goto FOLDERNAMEOFF 1
   get FOLDERNAME string 1
   #print "%FOLDERNAME%"
   string FOLDERNAME l FOLDERNAME
   PutArray 2 i FOLDERNAME
next i

for i = 0 < TFILES
   GetArray FILENAMEOFF 1 i
   math FILENAMEOFF += NAMEBASE
   goto FILENAMEOFF 1
   get FILENAME string 1
   #print "%FILENAME%"
   string FILENAME l FILENAME
   PutArray 7 i FILENAME
next i

set MEMORY_FILE binary ""

for i = 0 < FOLDERS
   GetArray FOLDERNAME 2 i
   GetArray FOLDERPARENT 3 i
   GetArray FILESTART 4 i
   GetArray FOLDERFILES 5 i
   math FOLDERFILES += FILESTART
   set FOLDERBASE ""
   #print "%FOLDERPARENT% %FILESTART% %FOLDERFILES%"
   if FOLDERPARENT > 0
   GetArray FOLDERBASE 6 FOLDERPARENT
   string FOLDERBASE += /
   #print "%FOLDERNAME%"
   endif
   string FOLDERBASE += FOLDERNAME
   PutArray 6 i FOLDERBASE
   #print "%FOLDERBASE%"
   if FOLDERFILES > 0
      for a = FILESTART < FOLDERFILES
         set NAME FOLDERBASE
         GetArray FILE 7 a
         string NAME += /
         string NAME += FILE
         #print "%NAME%"
         PutArray 8 a NAME
         #Put NAME LINE MEMORY_FILE
         # calculate checksum
         encryption crc 0x04c11db7 "32 -1 -1 1 0 0"
         string NAME E= NAME
         encryption "" ""
         #print "CRC %QUICKBMS_CRC|x%"
         string TEST p= "0x%08x " QUICKBMS_CRC
         string TEST += NAME
         #print "%TEST%"
         Put TEST LINE MEMORY_FILE
      next a
   endif
next i

goto 0 MEMORY_FILE

get FILES long 2
for i = 0 < FILES
   #GetArray NAME 8 i
   get NAME_CRC long 2
   get OFFSET long 2
   get SIZE long 2
   get ZSIZE long 2
   NameCRC NAME NAME_CRC MEMORY_FILE 32
   if ZSIZE == 0
      log NAME OFFSET SIZE
   else
      clog NAME OFFSET ZSIZE SIZE
   endif
next i


Last edited by chrrox on Sun May 15, 2016 12:41 pm, edited 1 time in total.

Top
   
PostPosted: Wed Mar 02, 2016 12:57 pm 

Joined: Mon Aug 03, 2015 7:51 am
Posts: 4
So I looked at this format recently at the request of a friend. I sorted the file table by offset, but even after that some files seemed to be a bit off from their true filenames based on comparing some locale-related images to what language appeared on the image. And even then, what would the point be in storing the table sorted on checksum and then sorting it when reading the file... it all seems weird to me, like we're missing something.

Apart from that, here's some notes that might be helpful. I don't know BMS, so I don't know what log vs. clog does, but compressed files are zlib-compressed, complete with zlib header and all. Additionally, for the pfs file I have all fields figured out I think: dirid, parentid, subdir_offset, nsubdirs, subfile_offset, nsubfiles. nsubdirs and nsubfiles give the #subdirectories and regular files that are direct children to this directory, and sub{dir,file}_offset give the index to the first subdirectory/file in terms of index into the dir table (pfs) or file table (pkh, though order is weird).


Top
   
PostPosted: Wed Mar 02, 2016 8:43 pm 

Joined: Thu Aug 07, 2014 10:28 pm
Posts: 346
the file names look perfect they are just not lining up with the actual offset table. not sure what needs to change to make it work.


Top
   
PostPosted: Fri May 06, 2016 4:29 am 

Joined: Wed May 04, 2016 8:45 pm
Posts: 2
The HASH field may be result of hash-function with a filename or with a full path and filename. Like it is in the Dark Souls packages.


Top
   
PostPosted: Fri May 06, 2016 5:48 am 

Joined: Wed May 04, 2016 8:45 pm
Posts: 2
Correct. HASH is a result of CRC-32 checksum function for full name with path. For example:
Hash: CC2F8C6D
Offset: 1673354624
Size: 2998
ZSize: 1161
Index in PKH table: 40398
Path: resource/windows/camera.ico

You can check it here:
http://hash.online-convert.com/crc32-generator


Top
   
PostPosted: Sun May 15, 2016 12:41 pm 

Joined: Thu Aug 07, 2014 10:28 pm
Posts: 346
Here is the correct script updated in first post


Top
   
PostPosted: Thu Jun 02, 2016 6:59 am 
User avatar

Joined: Sat Apr 02, 2016 10:25 pm
Posts: 11
This format seems to show up in Yakuza Zero as well, but the script is incompatible. Here are some sample files.


Top
   
PostPosted: Mon Jun 06, 2016 4:19 am 

Joined: Thu Aug 07, 2014 10:28 pm
Posts: 346
for yakuza just add
comtype gzip
to the start


Top
   
PostPosted: Mon Jun 06, 2016 3:01 pm 
User avatar

Joined: Sat Apr 02, 2016 10:25 pm
Posts: 11
Thanks a lot!


Top
   
PostPosted: Mon Feb 22, 2021 12:50 pm 

Joined: Fri Jun 15, 2018 2:46 pm
Posts: 8
Thank You! I can use this scrip to decompress .PK from Nintendo Wii The Last Story


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 10 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Limited