romfs - RomFS reader

The romfs module enables reading application read-only filesystems.

RomFSReader objects

class pyctr.type.romfs.RomFSReader(file, case_insensitive=False, *, closefd=None)[source]

Bases: TypeReaderBase

Reads the contents of the RomFS, found inside NCCH containers.

The RomFS found inside an NCCH is wrapped in an IVFC hash-tree container. This class only supports Level 3, which contains the actual files.

Parameters:
  • file (FilePathOrObject) – A file path or a file-like object with the RomFS data.

  • case_insensitive (bool) – Use case-insensitive paths.

  • closefd (bool) – Close the underlying file object when closed. Defaults to True for file paths, and False for file-like objects.

open(path: str, encoding: str, errors: str | None = None, newline: str | None = None) io.TextIOWrapper[source]
open(path: str, encoding: None = None, errors: str | None = None, newline: str | None = None) SubsectionIO

Open a file in the RomFS for reading.

The file opens in binary mode by default, unless encoding is specified.

Parameters:
  • path – Path to a file within the RomFS.

  • encoding – The name of the encoding used to decode. Specifying this opens the file in text mode.

  • errors – The error setting of the decoder.

  • newline – Controls how newlines are handled in text mode. This is passed to io.TextIOWrapper.

Returns:

A SubsectionIO object for bytes, or io.TextIOWrapper for text.

Raises:

RomFSIsADirectoryError – If the item is a directory.

get_info_from_path(path)[source]

Get a directory or file entry.

Parameters:

path (str) – Path to a file or directory within the RomFS.

Returns:

A RomFSFileEntry or RomFSDirectoryEntry.

Raises:

RomFSFileNotFoundError – If the item doesn’t exist.

Return type:

Union[RomFSDirectoryEntry, RomFSFileEntry]

Data classes

class pyctr.type.romfs.RomFSDirectoryEntry(name, type, contents)[source]
Parameters:
  • name (str) –

  • type (str) –

  • contents (Tuple[str, ...]) –

class pyctr.type.romfs.RomFSFileEntry(name, type, offset, size)[source]
Parameters:
  • name (str) –

  • type (str) –

  • offset (int) –

  • size (int) –

Exceptions

exception pyctr.type.romfs.RomFSError[source]

Generic exception for RomFS operations.

exception pyctr.type.romfs.InvalidIVFCError[source]

Invalid IVFC header exception.

exception pyctr.type.romfs.InvalidRomFSHeaderError[source]

Invalid RomFS Level 3 header.

exception pyctr.type.romfs.RomFSEntryError[source]

Error with RomFS Directory or File entry.

exception pyctr.type.romfs.RomFSFileNotFoundError[source]

Invalid file path in RomFS Level 3.

exception pyctr.type.romfs.RomFSIsADirectoryError[source]

Attempted to open a directory as a file.