[PSP] THFS file unpack/repack script

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
Ensight
Posts: 2
Joined: Fri Jan 13, 2023 9:26 am

[PSP] THFS file unpack/repack script

Post by Ensight »

Hi, guys. I want to translate PSP game Shinseiki Evangelion Koutetsu no Girl Friend 2nd Portable. I need to repack THFS files, but i can`t make QuickBMS script for this file format. Can you help me with this?

The THFS file starts with a 16 byte header:
4 byte ASCII encoded "THFS" string
Little-endian 32bit unsigned integer: the total size of the THFS file.
Little-endian 32bit unsigned integer: the number of files in the table of contents.
4 null bytes

After the header there's the table of contents with each entry being 64 bytes:
8 bytes of unknown data that I couldn't identify. Perhaps a hash or cipher of some sort.
File name 40 bytes long and padded at the end with nulls.
Little-endian 32bit unsigned integer that represents the offset of data in the THFS file.
Little-endian 32bit unsigned integer filesize.
4 null bytes.
Little-endian 32bit unsigned integer filesize (again for some reason).
After the table of contents there is the data of the files. For some reason the file data offsets start at multiples of 0x1000, I don't know why but it's irrelevant.
BloodRaynare
Posts: 367
Joined: Fri Mar 10, 2017 7:23 am

Re: [PSP] THFS file unpack/repack script

Post by BloodRaynare »

You can extract it with this script below:

Code: Select all

comtype zlib_noerror

IDString "THFS"
get THPS_SZ long
get FILES long
get ZERO long

for i = 0 < FILES
	get UNK1 long
	get UNK2 long
	getDstring NAME 40
	get OFFSET long
	get ZSIZE long
	get IS_COMPRESSED long
	get SIZE long
	if IS_COMPRESSED == 1
		clog NAME OFFSET ZSIZE SIZE
	else
		log NAME OFFSET SIZE
	endif
next i
However, repacking files might be a different story. You can try repack the files with:

Code: Select all

quickbms -w -r -r
or

Code: Select all

quickbms -w -r -r -r
or just use the GUI way: reimport2.bat/reimport3.bat

But, expect the game's crashing if those unknown 8-byte values were indeed a hashes.
It's currently unknown how they were calculated and what are those hashes represents. You're going have to reverse-engineer the game yourself or ask some TL groups that handled this game.
Ensight
Posts: 2
Joined: Fri Jan 13, 2023 9:26 am

Re: [PSP] THFS file unpack/repack script

Post by Ensight »

Thank you, it works fine. I use reimport2 with quickbms -w -r -r -r and it successfully works!