ihaveamac / ninfs

FUSE filesystem Python scripts for Nintendo console files
MIT License
436 stars 18 forks source link

[Request] Add Decryption/Re-ecryption options #75

Open SamRohod opened 3 years ago

SamRohod commented 3 years ago

Hello ihaveamac

Given your obvious knowledge about the 3DS formats, I thought that you are probably the right person to ask. When it comes to .cia files, I haven't found a tool that could decrypt them to match no-intro database, and I haven't found any tool to re-encrypt them at all. My understanding is that the No-Intro database for encrypted and decrypted 3DS files is based on the tool "GodMod9" which can only be used on the 3DS right now. Giving that at this point in time we have ways to access the 3DS keys/bootroms/seeddb.bin, can we compile the GodMode9 encryptor/decryptor/converter to run on PC ? Can you add it to NINFS ?

Some of the tools I found:-

NDecrypt: Decrypts/re-encrypts .3ds files matching no-intro database Doesn't support .cia files Also decrypts/re-encrypts DS and DSi files

3DS + CIA Rom Script: Decrypts/re-encrypts .3ds files matching no-intro database Decrypts .cia files but not matching no-intro database & can't re-encrypt them

Batch CIA 3DS Decryptor: Decrypts .3ds/.cia files but not matching no-intro database & can't re-encrypt either

ihaveamac commented 3 years ago

My understanding is that the No-Intro database for encrypted and decrypted 3DS files is based on the tool "GodMod9" which can only be used on the 3DS right now.

How do you know that? As far as I know the No-Intro database has existed long before GodMode9.

Giving that at this point in time we have ways to access the 3DS keys/bootroms/seeddb.bin, can we compile the GodMode9 encryptor/decryptor/converter to run on PC ? Can you add it to NINFS ?

GodMode9 is exclusively a 3DS application, it uses 3DS-specific hardware and APIs. But it can be replicated on PC and ninfs is probably the closest equivalent to it.

Neither tool decrypts it 100% cleanly though. In particular for any title using extra crypto (7x, 9.3, 9.6), the ExeFS has a bit of garbage in the unused space of the last block of the .code, due to how the encryption works. This doesn't affect functionality since it is unused space, but it means hashes that expect 100% perfect decryption will not match. It is something that can be fixed by hand though since the garbage just needs to be replaced with null bytes.

Re-encryption is not something I felt needed doing, but could be done if it's really desired.

ihaveamac commented 3 years ago

Neither tool decrypts it 100% cleanly though. In particular for any title using extra crypto (7x, 9.3, 9.6), the ExeFS has a bit of garbage in the unused space of the last block of the .code, due to how the encryption works. This doesn't affect functionality since it is unused space, but it means hashes that expect 100% perfect decryption will not match. It is something that can be fixed by hand though since the garbage just needs to be replaced with null bytes.

This part will be fixed once a new pyctr release with this change is implemented: https://github.com/ihaveamac/pyctr/issues/10

SamRohod commented 2 years ago

Sorry for the bother but any updates on this?