wiithon.builder.directory_source module

Building a partition from a directory tree on disk

wiithon.builder.directory_source.build_from_directory_tree(files_dir)[source]

Build a file system table mirroring a directory

Directories are walked recursively. Entries are sorted by name, case insensitively, so the resulting tree is stable across platforms and filesystems

File nodes carry the size read from disk and an offset of zero, since the builder assigns real offsets when it writes the data

Parameters:

files_dir (str) – Directory to mirror, typically the files folder of an extracted partition

Return type:

FST

Returns:

The tree. An empty tree is returned if the path is not a directory

class wiithon.builder.directory_source.DirectoryPartitionSource(path, partition_type)[source]

Bases: PartitionSource

Feeds the builder from a partition extracted to disk

The layout expected is the one produced by extraction tools such as wit:

<path>/
    ticket.bin
    tmd.bin
    cert.bin
    sys/
        boot.bin
        bi2.bin
        apploader.img
        main.dol
    files/
        ...

Everything except the file contents is read in the constructor. File data is read from disk on demand as the builder asks for it

Note

h3.bin and disc/ are ignored if present. The H3 table is recomputed while encrypting, and the region belongs to the disc rather than to a partition, so you pass it to WiiDiscBuilder yourself

Example

>>> source = DirectoryPartitionSource("extracted/DATA", WiiPartType.DATA)

See also

CopyPartitionSource to build from an existing ISO instead

Parameters:
files_dir: str

Folder holding the game files, mirrored by the file system table

encrypted_header: DiscHeader

Internal disc header, with encryption and hash verification forced on

bi2: bytes

Disc configuration block read from sys/bi2.bin

apploader: bytes

Apploader read from sys/apploader.img

dol: bytes

Executable read from sys/main.dol, kept as raw bytes

tmd: TMD

Title metadata read from tmd.bin

certificates: List[Certificate]

Certificate chain read from cert.bin

ticket: Ticket

Ticket read from ticket.bin

fst: FST

File system table mirroring files

partition_type: int

Type recorded in the partition table

get_partition_type()[source]

Return the type of the partition

Return type:

WiiPartType

Returns:

A WiiPartType value

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_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_dol()[source]

Return the main executable

Return type:

bytes

Returns:

The DOL as raw bytes, not a parsed DOL. Serialise it yourself if you hold an object

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]

Read one file from the files directory

Parameters:

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

Return type:

bytes

Returns:

The file content

Raises:

FileNotFoundError – If the file disappeared between the construction of the tree and this call