yretenai / Cethleann

KTGL (Soft Engine) data exploration and research
MIT License
56 stars 16 forks source link

Persona 5 Strikers PC Assets Decryption #36

Closed zarroboogs closed 3 years ago

zarroboogs commented 3 years ago

This PR adds support for P5S PC asset decryption.

The decryption algorithms were reversed from the executable and later simplified to readable code (I hope 😳).

Encryption is also implemented, but not used at the moment.

LINKDATA Decryption

P5S PC LINKDATA.BIN entries can either be compressed or encrypted, but never both at the same time.

The encryption algorithm is a form of Mersenne twister, and the key is the index of the entry in LINKDATA.IDX, plus a constant.

LINKDATA.IDX itself is located in the executable.

RDB Decryption

P5S PC RDB ZLib compressed entries are always encrypted.

Conversely, non-compressed RDB entries are never encrypted.

The encryption algorithm uses XORShift32, and the key is the entry's KTID.

SRST Decryption

P5S PC external .files with an SRST header can be encrypted.

To determine whether a file is encrypted, the game checks offset 0x20 in the KTSR header which immediately follows the 0x10 byte SRST header.

The byte value stored in that offset is the encryption key length, with the key itself following from the next byte - if the value is 0, no decryption is performed.

Only the audio files themselves (KOVS header) are encrypted. The SRST, KTSR and KOVS wrapper headers remain unencrypted, and are used by the game to determine what needs to be decrypted.

The encryption algorithm is Blowfish in ECB mode.

The game decrypts SRST file contents on-the-fly, during stream playback.

yretenai commented 3 years ago

Thanks