SabreTools / NDecrypt

Cartridge encrypt/decrypt
MIT License
43 stars 6 forks source link

Issue using latest NDecrypt for 3DS decryption #11

Open InternalLoss opened 1 year ago

InternalLoss commented 1 year ago

When decrypting a 3DS CCI (cart image) on my Mac using either the latest x64 release or building it directly with dotnet build, I get an incorrect decrypted hash:

❯ ./NDecrypt d -k aes_keys.txt 00040000001A0500_v02.3ds
00040000001A0500_v02.3ds
File recognized as Nintendo 3DS
Encryption Method: Key 0x25
Partition 0 ExeFS: Decrypting: ExHeader
Partition 0 ExeFS: Decrypting: ExeFS Filename Table
Partition 0 ExeFS: Decrypting: 4 / 4 mb... Done!
Partition 0 RomFS: Decrypting: 361 / 361 mb... Done!
Encryption Method: Key 0x2C
Partition 1 ExeFS: No Extended Header... Skipping...
Partition 1 ExeFS: No Data... Skipping...
Partition 1 RomFS: Decrypting: 3 / 3 mb... Done!
Partition 2 Not found... Skipping...
Partition 3 Not found... Skipping...
Partition 4 Not found... Skipping...
Partition 5 Not found... Skipping...
Encryption Method: Key 0x2C
Partition 6 ExeFS: No Extended Header... Skipping...
Partition 6 ExeFS: No Data... Skipping...
Partition 6 RomFS: Decrypting: 10 / 10 mb... Done!
Encryption Method: Key 0x2C
Partition 7 ExeFS: No Extended Header... Skipping...
Partition 7 ExeFS: No Data... Skipping...
Partition 7 RomFS: Decrypting: 39 / 39 mb... Done!
❯ sha256sum 00040000001A0500_v02.3ds
e606b9875e5e864d5ae207e3681c2a9429110ed943136f41ad65850c2f4badc4  00040000001A0500_v02.3ds
❯ sha1sum 00040000001A0500_v02.3ds
877bddfe701edabf07f733ef84b064cccd2d9498  00040000001A0500_v02.3ds

The expected hash (that 3ds_decrypt_v4.py produces) is SHA-1 94aac90f8b9d9c6f69d24c58ca53ecf205d1c248 and SHA-256 7fb81e592307e56f7b2dc85d72a0bc668dca427d3c812737deda2fcac8adde62

However, when re-encrypting using the program, it will issue the correct encrypted hashes.

mnadareski commented 1 year ago

Testing the same cart and subsequent encrypted image, the decrypted file is parsed properly by other third-party tools and emulators. There's a nonzero chance that there's an issue further into the game, but nothing was apparent from the outset.