pyctr.type.ncch module
Module for interacting with NCCH files.
- exception pyctr.type.ncch.NCCHError[source]
Bases:
PyCTRError
Generic exception for NCCH operations.
- exception pyctr.type.ncch.NCCHSeedError[source]
Bases:
NCCHError
NCCH seed is not set up, or attempted to set up seed when seed crypto is not used.
- exception pyctr.type.ncch.MissingSeedError[source]
Bases:
NCCHSeedError
Seed could not be found.
- class pyctr.type.ncch.NCCHSection(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- ExtendedHeader = 1
- ExeFS = 2
- RomFS = 3
- Header = 4
- Logo = 5
- Plain = 6
- FullDecrypted = 7
- Raw = 8
- class pyctr.type.ncch.NCCHRegion(section, offset, size, end, iv)[source]
Bases:
NamedTuple
- Parameters:
section (NCCHSection) –
offset (int) –
size (int) –
end (int) –
iv (int) –
- section: NCCHSection
Alias for field number 0
- class pyctr.type.ncch.NCCHFlags(crypto_method, executable, fixed_crypto_key, no_romfs, no_crypto, uses_seed)[source]
Bases:
NamedTuple
Flags for an NCCH. This is not a complete set. See: https://3dbrew.org/wiki/NCCH#NCCH_Flags
- Parameters:
- crypto_method: int
Determines the extra keyslot used for RomFS and parts of ExeFS. 0x00 = NCCH, 0x01 = NCCH70, 0x0A = NCCH93, 0x0B = NCCH96
- executable: bool
If this content is a CXI (CTR Executable Image) or CFA (CTR File Archive). In the raw flags, “Data” needs to be set with “Executable” unset for this to be a CFA.
- fixed_crypto_key: bool
If a fixed normal key is used to encrypt the contents. This is often a zero-key, with a different “fixed system key” used in specfic situations.
- class pyctr.type.ncch.NCCHReader(file, *, fs=None, closefd=None, case_insensitive=True, crypto=None, dev=False, seed=None, load_sections=True, assume_decrypted=False)[source]
Bases:
TypeReaderCryptoBase
Reads the contents of NCCH containers.
The NCCH header contains information such as Title ID, Product Code, flags, and section info.
NCCH containers can be classified as a CTR Executable Image (CXI) if it has executable code, or a CTR File Archive (CFA) if it doesn’t.
A CXI can contain:
an Extended Header (extheader) with executable info and access permissions
a logo region (for titles released before System Menu 5.0.0-11, this is in the ExeFS)
a plain region with SDK library strings
an Executable Filesystem (ExeFS) with .code, icon, and banner
a Read-only Filesystem (RomFS)
A CFA can contain:
an ExeFS with icon and banner
a RomFS
- Parameters:
file (FilePathOrObject) – A file path or a file-like object with the NCCH data.
case_insensitive (bool) – Use case-insensitive paths for the RomFS.
crypto (CryptoEngine) – A custom
CryptoEngine
object to be used. Defaults to None, which causes a new one to be created.dev (bool) – Use devunit keys.
seed (bytes) – Seed to use. This is a quick way to add a seed using
add_seed()
.load_sections (bool) – Load the ExeFS and RomFS as
ExeFSReader
andRomFSReader
objects.assume_decrypted (bool) – Assume each NCCH content is decrypted. Needed if the image was decrypted without fixing the NCCH flags.
fs (Optional[FS]) –
closefd (bool) –
- exefs: ExeFSReader | None
The
ExeFSReader
of the NCCH, if it has one.
- romfs: RomFSReader | None
The
RomFSReader
of the NCCH, if it has one.
- partition_id: str
Partition ID as an integer. Usually this is different for NCCH in a title, incrementing the platform section (e.g. 0004 for Application, 0005 for Manual, 0006 for Download Play Child). DLC does not follow this, all contents use 0004 for the platform.
- sections: Dict[NCCHSection, NCCHRegion]
Contains all the sections the NCCH has.
- main_keyslot: Keyslot
Keyslot to use for decrypting the Extended Header and ExeFS header. In most cases this is Original NCCH (0x2C). Some titles may use a fixed crypto key though, either all zeros, or a special key for system titles. PyCTR uses the fake keyslots 0x41 and 0x42 for these respectively.
- extra_keyslot: Keyslot
Second keyslot to use for the ExeFS contents and RomFS. This is determined by the crypto method in the NCCH flags. This is set to the same as main_keyslot for titles without an extra crypto method, or with a fixed crypto key.
- open_raw_section(section)[source]
Open a raw NCCH section for reading with on-the-fly decryption.
- Parameters:
section (NCCHSection) – The section to open.
- Returns:
A file-like object that reads from the section.
- check_for_extheader()[source]
Checks if the NCCH has an Extended Header.
- Returns:
True if it has an ExtHeader.
- Return type:
- get_data(section, offset, size)[source]
Get data from an NCCH section.
- Parameters:
section (Union[NCCHRegion, NCCHSection]) – A region or section to read from.
offset (int) – Offset from the section start.
size (int) – Data size.
- Returns:
Decrypted data from the region.
- Return type: