wiithon.builder.copy_source module

Building a partition from one already present in an ISO

class wiithon.builder.copy_source.CopyPartitionSource(reader, partition, fst_modifier=None, dol_modifier=None, file_overrides=None)[source]

Bases: PartitionSource

Feeds the builder from a partition of an existing disc

Everything is read in the constructor, so building an instance opens the partition and pulls its system files immediately. The optional callbacks run at that point too, which means the FST and the DOL handed to the builder are already modified

File data is streamed later, on demand, straight from the source ISO. Only the files you override are held in memory

This is what WiiIsoPatcher uses for every partition of the disc it rebuilds

Example

>>> with WiiIsoReader("game.iso") as reader:
...     entry = reader.get_data_partition()
...     source = CopyPartitionSource(reader, entry, file_overrides={"opening.bnr": new_banner})
Parameters:
partition_info: WiiPartitionInfo

Partition opened from the source ISO, used to read file data on demand

partition_type: int

Type of the partition being copied

bi2: bytes

Disc configuration block read from the source

apploader: bytes

Apploader read from the source

dol: DOL

Parsed executable, already patched if a dol_modifier was given

tmd: TMD

Title metadata of the source partition

certificates: List[Certificate]

Certificate chain of the source partition

fst: FST

File system table, already modified if a fst_modifier was given

encrypted_header: DiscHeader

Internal disc header of the source partition

ticket: Ticket

Ticket of the source partition, holding the title key

get_partition_type()[source]

Return the type of the partition

Return type:

int

Returns:

A WiiPartType value

get_ticket()[source]

Return the ticket of the partition

The builder takes the title key from it to encrypt every block of partition data, so this is the first thing it needs

Return type:

Ticket

Returns:

The ticket, written at offset 0 of the partition

get_tmd()[source]

Return the title metadata

Return type:

TMD

Returns:

The TMD. The builder rewrites its H3 hash, its data size and its signature padding before writing it, so the content hashes it carries do not need to be correct

get_certificates()[source]

Return the certificate chain of the partition

Return type:

List[Certificate]

Returns:

The certificates, written back to back in the order given. Retail discs carries three

get_encrypted_header()[source]

Return the disc header stored at offset 0 of the partition data

This is the internal header, also known as boot.bin, not the unencrypted one at the start of the disc. The builder overwrites its DOL and FST offsets once it knows where those landed

Return type:

DiscHeader

Returns:

The header to place at the beginning of the partition data

get_bi2()[source]

Return the BI2

Return type:

bytes

Returns:

The raw block, written at its fixed offset

get_apploader()[source]

Return the apploader, the code that boots the game

Return type:

bytes

Returns:

The complete apploader, its own header included

get_dol()[source]

Serialise the executable, including any patch applied by dol_modifier

Return type:

bytes

Returns:

The DOL as raw bytes

get_fst()[source]

Return the file system table of the partition

The tree drives everything that follows: the builder walks it to know which files to ask for, and rewrites the offset and length of each node once the data is placed

Return type:

FST

Returns:

The tree of directories and files

get_file_data(path)[source]

Return the content of one file, from the overrides or from the source disc

Paths present in file_overrides are served from memory. Everything else is read from the source ISO at the offset the node had before the builder started moving files around

Parameters:

path (List[str]) – Path split into components, from the root of the partition

Return type:

bytes

Returns:

The file content

Raises:

FstFileNotFoundError – If the path matches no file, which also covers the case of a path resolving to a directory