wiithon.disc.reader module

Read-only access to a Wii disc image

This module exposes WiiIsoReader, the entry point for inspecting an ISO without modifying it. To modify one, see wiithon.disc.patcher

class wiithon.disc.reader.WiiIsoReader(path)[source]

Bases: object

Read-only view of a Wii disc image

Opening a reader parses the unencrypted disc header and the partition table immediately, then validates the Wii magic word. Partitions themselves are read lazily, only when open_partition() is called

The reader holds an open file handle for its whole lifetime. Use it as a context manager so the handle is released even when an error occurs

Example

>>> with WiiIsoReader("game.iso") as reader:
...     partition = reader.open_partition(reader.get_data_partition())
...     data = partition.read_file("opening.bnr")
Parameters:

path (str)

path: str

Path the reader was opened on.

file: BinaryIO

Underlying binary file handle.

disc_header: DiscHeader

Unencrypted disc header, read from offset 0x000.

partitions: List[WiiPartitionEntry]

Every entry of the partition table, in disc order

region: bytes

Raw region bytes

magic_word: int

Wii magic word, validated at construction

get_data_partition()[source]

Return the DATA partition entry, which holds the game itself

Return type:

Optional[WiiPartitionEntry]

Returns:

The first DATA entry found, or None if the disc has none

get_update_partition()[source]

Return the UPDATE partition entry, which holds a system update

Return type:

Optional[WiiPartitionEntry]

Returns:

The first UPDATE entry found, or None. An update partition is optional and many discs do not carry one

get_partitions()[source]

Return every partition entry listed in the partition table

Return type:

List[WiiPartitionEntry]

Returns:

The entries in disc order, including types Wiithon cannot open yet such as CHANNEL

read_region()[source]

Read the raw region bytes from the disc

Return type:

bytes

Returns:

The region block, read at its fixed offset

Note

This seeks the underlying file handle. The value is already cached in region at construction, so you rarely need to call this

read_magic_word()[source]

Read the Wii magic word from its fixed offset

Return type:

int

Returns:

The 32-bit word stored at offset 0x4FFFC. A valid Wii disc yields 0xC3F81A8E.

Note

This seeks the underlying file handle. The value is already validated and cached in magic_word at construction

open_partition(entry)[source]

Decrypt a partition and load its file system table

This reads the partition header, the TMD and the certificate chain, then sets up AES decryption using the title key from the ticket. It finally reads the internal disc header and the FST from the decrypted data

Parameters:

entry (WiiPartitionEntry) – Partition table entry, obtained from get_data_partition(), get_update_partition() or get_partitions()

Return type:

WiiPartitionInfo

Returns:

A WiiPartitionInfo giving access to the files inside the partition

Warning

CHANNEL partitions are not supported yet

Note

The certificate chain is assumed to hold exactly three certificates, which covers every retail disc seen so far

close()[source]

Close the underlying file handle

Called automatically when leaving a with block

Return type:

None