03-07-2011, 12:07 AM
(03-06-2011, 09:17 PM)Hykem Wrote: Thanks to Darth's help, I was finally able to decrypt and reverse the necessary parts of the PGD header struct which, in turn, allowed to sucessfully decrypt most of the known existing PGD files.
-----------------------------------------------------------------------------------
[PGD File header]:
-----------------------------------------------------------------------------------Code:0x00: 00 50 47 44 01 00 00 00 01 00 00 00 00 00 00 00 -> " PGD" and three bit fields that act as flags for version and encryption mode.
0x10: AES-128 bit hash key used for header decryption.
0x20: Generated hash from the 0x10 key.
0x30 - 0x50: Encrypted header of the PGD which when decrypted reveals a new hash key and four bit fields. The first is NULL, the second represents the decrypted data size, the third is the decrypting chunk size and the fourth is the data hash address.
0x60: File hash.
0x70: Hash generated from the sceIoIoctl key.
0x80: Encrypted hash generated from the sceIoIoctl key.
0x90: Data hash.
0xA0: Encrypted data hash.
By using the hash key obtained at 0x30 and decrypting the whole file again, starting at 0x90 this time, it's now possible to obtain the original plain binary file. This works great for smaller files, but for huge files, like in KHBBS case, Java needs to work with streams to avoid running out of heap.
I'll commit all this for now in order to be tested with the other games that make a less important usage of these files, but I'm still working on integrating a read/write decryption that works by chunks for the big data files.
Enjoy!
You're great man... ;-)