ihaveamac / pyctr

Python library to interact with Nintendo 3DS files
MIT License
30 stars 8 forks source link

Add split-file handler to merge multiple file-like objects into one #10

Open ihaveamac opened 3 years ago

ihaveamac commented 3 years ago

This could make it much easier to handle files like NCCH which use various different encryption settings. The current method is kinda crappy and inefficient.

The idea of this would be to create multiple CTRFileIO objects (or anything, really, as long as it's a file-like object) to provide decrypted access to a part of the NCCH/ExeFS, one for each section where the crypto settings changes (e.g. between NCCH header, ExtHeader, logo/plain, ExeFS header, ExeFS .code, ExeFS other files, RomFS). Then combine them all and provide access to it as if it was one large file.

This would especially make the ExeFS part much easier to implement due to its weird crypto requirements.

Another idea for this is to provide a decrypted version of a CCI. This wouldn't work so well for CIA due to the hashes in the tmd.

This is already mostly implemented in ninfs for use with Switch NAND backups: https://github.com/ihaveamac/ninfs/blob/fc50af10930c41fec37d7b99051121fb07f2c2db/ninfs/mount/_common.py#L219 but it only takes file paths.

ihaveamac commented 3 years ago

First step: 8c5282ddfef60ad0912fd1d984baf3545bea356c

ihaveamac commented 3 years ago

Second step (ExeFS encryption handling): b86119a2952022d65836726facc8e9e3dd33d07d