wiithon.builder.disc_builder module

Assembling a Wii disc image from partitions

WiiDiscBuilder writes partitions one after another, then closes the disc. Where the content comes from is the job of a PartitionSource

wiithon.builder.disc_builder.fakesign_tmd(tmd_bytes, h3, data_size)[source]

Patch a TMD in place so Dolphin accepts it without a valid signature

Writes the H3 hash and the partition data size, zeroes the signature, then brute-forces the padding until the SHA-1 of the signed blob starts with a null byte

Parameters:
  • tmd_bytes (bytearray) – TMD to patch, modified in place

  • h3 (bytes) – H3 hash table of the partition, as returned by the crypt writer

  • data_size (int) – Size of the partition data, aligned to a full group

Return type:

None

Note

The resulting signature is not valid.

class wiithon.builder.disc_builder.WiiDiscBuilder(header, region)[source]

Bases: object

Writes a Wii disc image, one partition at a time

Call add_partition() for each partition, then finish() once. Partitions are laid out in the order they are added, starting at the first partition offset, and the builder tracks where the next one goes

Example

>>> with open("out.iso", "w+b") as dest:
...     builder = WiiDiscBuilder(disc_header, region)
...     builder.add_partition(dest, source, None)
...     builder.finish(dest)

See also

WiiIsoPatcher drives this class for you when patching an existing disc

Parameters:
header: DiscHeader

Unencrypted disc header written at the start of the image

region: bytes

Raw region bytes

partitions: List[tuple]

One tuple per partition added so far, consumed by finish() to write the partition table

current_data_offset

Offset where the next partition will be written, advanced by add_partition()

add_partition(stream, new_partition, progress_cb=None)[source]

Write one partition to the stream

Pulls every piece from the source, writes the ticket, TMD and certificate chain in clear, then the system files and the file data through an encrypting writer. Once the data is placed, the FST is rewritten with the real offsets, the H3 table is stored, and the TMD is fakesigned

The partition is padded to a whole number of encryption groups, and current_data_offset is advanced past it

Parameters:
  • stream (BinaryIO) – Destination, opened in binary read and write mode. It must be seekable

  • new_partition (PartitionSource) – Where the content of this partition comes from

  • progress_cb (Optional[Callable], default: None) – Called with an integer percentage from 0 to 100 as file data is written, or None.

Return type:

None

Note

Progress restarts at 0 for every partition, since the builder has no idea how many will follow

finish(stream)[source]

Close the disc image

Writes the disc header, the partition table describing every partition added so far, the region and the magic word. Call this once, after the last add_partition()

Parameters:

stream (BinaryIO) – The same stream the partitions were written to

Return type:

None

Warning

A disc image whose finish() was never called has no partition table and will not boot