libWiiPy.title package

Contents

libWiiPy.title package#

Submodules#

libWiiPy.title.commonkeys module#

libWiiPy.title.commonkeys.get_common_key(common_key_index, dev=False) bytes#

Gets the specified Wii Common Key based on the index provided. If an invalid common key index is provided, this function falls back on always returning key 0 (the Common Key). If the kwarg “dev” is specified, then key 0 will point to the development common key rather than the retail one. Keys 1 and 2 are unaffected by this argument.

Possible values for common_key_index: 0: Common Key, 1: Korean Key, 2: vWii Key

Parameters:
  • common_key_index (int) – The index of the common key to be returned.

  • dev (bool) – If the dev keys should be used in place of the retail keys. Only affects key 0.

Returns:

The specified common key, in binary format.

Return type:

bytes

libWiiPy.title.content module#

class libWiiPy.title.content.ContentRegion#

Bases: object

A ContentRegion object to parse the continuous content region of a WAD. Allows for retrieving content from the region in both encrypted or decrypted form, and setting new content.

content_records#

The content records for the content stored in the region.

Type:

List[_ContentRecord]

num_contents#

The total number of contents stored in the region.

Type:

int

add_content(dec_content: bytes, cid: int, content_type: int, title_key: bytes) None#

Adds a new decrypted content to the end of the ContentRegion, and adds the provided Content ID, content type, content size, and content hash to a new record in the ContentRecord list. The index will be automatically assigned by incrementing the current highest index in the records.

This first gets the content hash and size from the provided data, and then encrypts the content with the provided Title Key before adding it to the ContentRegion.

Parameters:
  • dec_content (bytes) – The new decrypted content to add.

  • cid (int) – The Content ID to assign the new content in the content record.

  • content_type (int) – The type of the new content.

  • title_key (bytes) – The Title Key that matches the other content in the ContentRegion.

add_enc_content(enc_content: bytes, cid: int, index: int, content_type: int, content_size: int, content_hash: bytes) None#

Adds a new encrypted content to the ContentRegion, and adds the provided Content ID, index, content type, content size, and content hash to a new record in the ContentRecord list.

Parameters:
  • enc_content (bytes) – The new encrypted content to add.

  • cid (int) – The Content ID to assign the new content in the content record.

  • index (int) – The index used when encrypting the new content.

  • content_type (int) – The type of the new content.

  • content_size (int) – The size of the new encrypted content when decrypted.

  • content_hash (bytes) – The hash of the new encrypted content when decrypted.

dump() tuple[bytes, int]#

Takes the list of contents and assembles them back into one content region. Returns this content region as a bytes object and sets the raw content region variable to this result, then calls load() again to make sure the content list matches the raw data.

Returns:

  • bytes – The full ContentRegion as bytes, including padding between content.

  • int – The size of the ContentRegion, including padding.

get_content_by_cid(cid: int, title_key: bytes, skip_hash=False) bytes#

Gets an individual content from the content region based on the provided Content ID, in decrypted form.

Parameters:
  • cid (int) – The Content ID of the content you want to get. Expected to be in decimal form, not hex.

  • title_key (bytes) – The Title Key for the title the content is from.

  • skip_hash (bool, optional) – Skip the hash check and return the content regardless of its hash. Defaults to false.

Returns:

The decrypted content listed in the content record.

Return type:

bytes

get_content_by_index(index: int, title_key: bytes, skip_hash=False) bytes#

Gets an individual content from the content region based on the provided index, in decrypted form.

Parameters:
  • index (int) – The index of the content you want to get.

  • title_key (bytes) – The Title Key for the title the content is from.

  • skip_hash (bool, optional) – Skip the hash check and return the content regardless of its hash. Defaults to false.

Returns:

The decrypted content listed in the content record.

Return type:

bytes

get_contents(title_key: bytes, skip_hash=False) List[bytes]#

Gets a list of all contents from the content region, in decrypted form.

Parameters:
  • title_key (bytes) – The Title Key for the title the content is from.

  • skip_hash (bool, optional) – Skip the hash check and return the content regardless of its hash. Defaults to false.

Returns:

A list containing all decrypted contents.

Return type:

List[bytes]

get_enc_content_by_cid(cid: int) bytes#

Gets an individual content from the content region based on the provided Content ID, in encrypted form.

Parameters:

cid (int) – The Content ID of the content you want to get. Expected to be in decimal form, not hex.

Returns:

The encrypted content listed in the content record.

Return type:

bytes

get_enc_content_by_index(index: int) bytes#

Gets an individual content from the content region based on the provided index, in encrypted form.

Parameters:

index (int) – The index of the content you want to get.

Returns:

The encrypted content listed in the content record.

Return type:

bytes

get_enc_contents() List[bytes]#

Gets a list of all encrypted contents from the content region.

Returns:

A list containing all encrypted contents.

Return type:

List[bytes]

get_index_from_cid(cid: int) int#

Gets the index of a content by its Content ID.

Parameters:

cid (int) – The Content ID to get the index of.

Returns:

The content index.

Return type:

int

load(content_region: bytes, content_records: List[_ContentRecord]) None#

Loads the raw content region and builds a list of all the contents.

Parameters:
  • content_region (bytes) – The raw data for the content region being loaded.

  • content_records (list[_ContentRecord]) – A list of ContentRecord objects detailing all contents contained in the region.

load_content(dec_content: bytes, index: int, title_key: bytes) None#

Loads the provided decrypted content into the ContentRegion at the specified index, but first checks to make sure that it matches the corresponding record. This content will then be encrypted using the provided Title Key before being loaded.

Parameters:
  • dec_content (bytes) – The decrypted content to load.

  • index (int) – The index to load the content at.

  • title_key (bytes) – The Title Key that matches the decrypted content.

load_enc_content(enc_content: bytes, index: int) None#

Loads the provided encrypted content into the content region at the specified index, with the assumption that it matches the record at that index. Not recommended for most use cases, use decrypted content and load_content() instead.

Parameters:
  • enc_content (bytes) – The encrypted content to load.

  • index (int) – The content index to load the content at.

remove_content_by_cid(cid: int) None#

Removes the content with the specified Content ID from the ContentRegion and content records.

This will allow gaps to be left in content indices, however this should not cause any issues.

Parameters:

cid (int) – The Content ID of the content you want to remove.

remove_content_by_index(index: int) None#

Removes the content at the specified index from the ContentRegion and content records.

This will allow gaps to be left in content indices, however this should not cause any issues.

Parameters:

index (int) – The index of the content you want to remove.

set_content(dec_content: bytes, index: int, title_key: bytes, cid: int = None, content_type: int = None) None#

Sets the content at the provided content index to the provided new decrypted content. The hash and content size of this content will be generated and then set in the corresponding content record. A new Content ID or content type can also be specified, but if it isn’t then the current values are preserved.

The provided Title Key is used to encrypt the content so that it can be set in the ContentRegion.

Parameters:
  • dec_content (bytes) – The new decrypted content to set.

  • index (int) – The index to place the new content at.

  • title_key (bytes) – The Title Key that matches the new decrypted content.

  • cid (int) – The Content ID to assign the new content in the content record.

  • content_type (int) – The type of the new content.

set_enc_content(enc_content: bytes, index: int, content_size: int, content_hash: bytes, cid: int = None, content_type: int = None) None#

Sets the content at the provided content index to the provided new encrypted content. The provided hash and content size are set in the corresponding content record. A new Content ID or content type can also be specified, but if it isn’t then the current values are preserved.

Parameters:
  • enc_content (bytes) – The new encrypted content to set.

  • index (int) – The target index to set the new content at.

  • content_size (int) – The size of the new encrypted content when decrypted.

  • content_hash (bytes) – The hash of the new encrypted content when decrypted.

  • cid (int, optional) – The Content ID to assign the new content in the content record. Current value will be preserved if not set.

  • content_type (int, optional) – The type of the new content. Current value will be preserved if not set.

class libWiiPy.title.content.ContentType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: IntEnum

DLC = 16385#
HASH_TREE = 3#
NORMAL = 1#
SHARED = 32769#
class libWiiPy.title.content.SharedContentMap#

Bases: object

A SharedContentMap object to parse and edit the content.map file stored in /shared1/ on the Wii’s NAND. This file is used to keep track of all shared contents installed on the console.

shared_records#

The shared content records stored in content.map.

Type:

List[_SharedContentRecord]

add_content(content_hash: str | bytes) str#

Adds a new shared content SHA-1 hash to the content map and returns the file name assigned to that hash.

Parameters:

content_hash (str, bytes) – The SHA-1 hash of the new shared content.

Returns:

The filename assigned to the provided content hash.

Return type:

str

dump() bytes#

Dumps the SharedContentMap object back into a content.map file.

Returns:

The raw data of the content.map file.

Return type:

bytes

load(content_map: bytes) None#

Loads the raw content map and parses the records in it.

Parameters:

content_map (bytes) – The data of a content.map file.

libWiiPy.title.crypto module#

libWiiPy.title.crypto.decrypt_content(content_enc, title_key, content_index, content_length) bytes#

Gets the decrypted version of the encrypted content.

This requires the index of the content to decrypt as it is used as the IV, as well as the content length to adjust padding as necessary.

Parameters:
  • content_enc (bytes) – The encrypted content.

  • title_key (bytes) – The Title Key for the title the content is from.

  • content_index (int) – The index in the TMD’s content record of the content being decrypted.

  • content_length (int) – The length in the TMD’s content record of the content being decrypted.

Returns:

The decrypted content.

Return type:

bytes

libWiiPy.title.crypto.decrypt_title_key(title_key_enc: bytes, common_key_index: int, title_id: bytes | str, dev=False) bytes#

Gets the decrypted version of the encrypted Title Key provided.

Requires the index of the common key to use, and the Title ID of the title that the Title Key is for.

Parameters:
  • title_key_enc (bytes) – The encrypted Title Key.

  • common_key_index (int) – The index of the common key used to encrypt the Title Key.

  • title_id (bytes, str) – The Title ID of the title that the key is for.

  • dev (bool) – Whether the Title Key is encrypted with the development key or not.

Returns:

The decrypted Title Key.

Return type:

bytes

libWiiPy.title.crypto.encrypt_content(content_dec, title_key, content_index) bytes#

Gets the encrypted version of the decrypted content.

This requires the index of the content to encrypt as it is used as the IV, as well as the content length to adjust padding as necessary.

Parameters:
  • content_dec (bytes) – The decrypted content.

  • title_key (bytes) – The Title Key for the title the content is from.

  • content_index (int) – The index in the TMD’s content record of the content being decrypted.

Returns:

The encrypted content.

Return type:

bytes

libWiiPy.title.crypto.encrypt_title_key(title_key_dec: bytes, common_key_index: int, title_id: bytes | str, dev=False) bytes#

Encrypts the provided Title Key with the selected common key.

Requires the index of the common key to use, and the Title ID of the title that the Title Key is for.

Parameters:
  • title_key_dec (bytes) – The decrypted Title Key.

  • common_key_index (int) – The index of the common key used to encrypt the Title Key.

  • title_id (bytes, str) – The Title ID of the title that the key is for.

  • dev (bool) – Whether the Title Key is encrypted with the development key or not.

Returns:

An encrypted Title Key.

Return type:

bytes

libWiipy.title.iospatcher module#

class libWiiPy.title.iospatcher.IOSPatcher#

Bases: object

An IOSPatcher object that allows for applying patches to IOS WADs loaded into Title objects.

title#

The loaded Title object to be patched.

Type:

Title

es_module_index#

The content index that ES resides in and where ES patches are applied.

Type:

int

dip_module_index#

The content index that DIP resides in and where DIP patches are applied. -1 if DIP patches are not applied.

Type:

int

dump() Title#

Returns the patched Title object.

Returns:

The patched Title object.

Return type:

Title

load(title: Title) None#

Loads a Title object containing an IOS WAD and locates the content containing the ES module that needs to be patched.

Parameters:

title (Title) – A Title object containing the IOS to be patched.

patch_all() int#

Applies all patches to patch in fakesigning, ES_Identify access, /dev/flash access, and the version downgrading patch.

Returns:

The number of patches successfully applied.

Return type:

int

patch_drive_inquiry() int#

Patches out IOS’ drive inquiry on startup, allowing IOS to load without a disc drive. Only required/useful if you do not have a disc drive connected to your console.

This drive inquiry patch is EXPERIMENTAL, and may introduce unexpected side effects on some consoles.

Returns:

The number of patches successfully applied.

Return type:

int

patch_es_identify() int#

Patches the ability to call ES_Identify back into the IOS’ ES module to allow for changing the permissions of a title.

Returns:

The number of patches successfully applied.

Return type:

int

patch_fakesigning() int#

Patches the trucha/fakesigning bug back into the IOS’ ES module to allow it to accept fakesigned TMDs and Tickets.

Returns:

The number of patches successfully applied.

Return type:

int

patch_nand_access() int#

Patches the ability to directly access /dev/flash back into the IOS’ ES module to allow for raw access to the Wii’s filesystem.

Returns:

The number of patches successfully applied.

Return type:

int

patch_version_downgrading() int#

Patches the ability to downgrade installed titles into IOS’ ES module.

Returns:

The number of patches successfully applied.

Return type:

int

libWiiPy.title.nus module#

libWiiPy.title.nus.download_cert(wiiu_endpoint: bool = False, endpoint_override: str = None) bytes#

Downloads the signing certificate used by all WADs. This uses System Menu 4.3U as the source.

Parameters:
  • wiiu_endpoint (bool, option) – Whether the Wii U endpoint for the NUS should be used or not. This increases download speeds. Defaults to False.

  • endpoint_override (str, optional) – A custom endpoint URL to use instead of the standard Wii or Wii U endpoints. Defaults to no override, and if set entirely overrides the “wiiu_endpoint” parameter.

Returns:

The cert file.

Return type:

bytes

libWiiPy.title.nus.download_content(title_id: str, content_id: int, wiiu_endpoint: bool = False, endpoint_override: str = None) bytes#

Downloads a specified content for the title specified in the object.

Parameters:
  • title_id (str) – The Title ID of the title to download content from.

  • content_id (int) – The Content ID of the content you wish to download.

  • wiiu_endpoint (bool, option) – Whether the Wii U endpoint for the NUS should be used or not. This increases download speeds. Defaults to False.

  • endpoint_override (str, optional) – A custom endpoint URL to use instead of the standard Wii or Wii U endpoints. Defaults to no override, and if set entirely overrides the “wiiu_endpoint” parameter.

Returns:

The downloaded content.

Return type:

bytes

libWiiPy.title.nus.download_contents(title_id: str, tmd: TMD, wiiu_endpoint: bool = False, endpoint_override: str = None) List[bytes]#

Downloads all the contents for the title specified in the object. This requires a TMD to already be available so that the content records can be accessed.

Parameters:
  • title_id (str) – The Title ID of the title to download content from.

  • tmd (TMD) – The TMD that matches the title that the contents being downloaded are from.

  • wiiu_endpoint (bool, option) – Whether the Wii U endpoint for the NUS should be used or not. This increases download speeds. Defaults to False.

  • endpoint_override (str, optional) – A custom endpoint URL to use instead of the standard Wii or Wii U endpoints. Defaults to no override, and if set entirely overrides the “wiiu_endpoint” parameter.

Returns:

A list of all the downloaded contents.

Return type:

List[bytes]

libWiiPy.title.nus.download_ticket(title_id: str, wiiu_endpoint: bool = False, endpoint_override: str = None) bytes#

Downloads the Ticket of the Title specified in the object. This will only work if the Title ID specified is for a free title.

Parameters:
  • title_id (str) – The Title ID of the title to download the Ticket for.

  • wiiu_endpoint (bool, option) – Whether the Wii U endpoint for the NUS should be used or not. This increases download speeds. Defaults to False.

  • endpoint_override (str, optional) – A custom endpoint URL to use instead of the standard Wii or Wii U endpoints. Defaults to no override, and if set entirely overrides the “wiiu_endpoint” parameter.

Returns:

The Ticket file from the NUS.

Return type:

bytes

libWiiPy.title.nus.download_title(title_id: str, title_version: int = None, wiiu_endpoint: bool = False, endpoint_override: str = False) Title#

Download an entire title and all of its contents, then load the downloaded components into a Title object for further use. This method is NOT recommended for general use, as it has absolutely no verbosity. It is instead recommended to call the individual download methods instead to provide more flexibility and output.

Parameters:
  • title_id (str) – The Title ID of the title to download.

  • title_version (int, optional) – The version of the title to download. Defaults to latest if not set.

  • wiiu_endpoint (bool, optional) – Whether the Wii U endpoint for the NUS should be used or not. This increases download speeds. Defaults to False.

  • endpoint_override (str, optional) – A custom endpoint URL to use instead of the standard Wii or Wii U endpoints. Defaults to no override, and if set entirely overrides the “wiiu_endpoint” parameter.

Returns:

A Title object containing all the data from the downloaded title.

Return type:

Title

libWiiPy.title.nus.download_tmd(title_id: str, title_version: int = None, wiiu_endpoint: bool = False, endpoint_override: str = None) bytes#

Downloads the TMD of the Title specified in the object. Will download the latest version by default, or another version if it was manually specified in the object.

Parameters:
  • title_id (str) – The Title ID of the title to download the TMD for.

  • title_version (int, option) – The version of the TMD to download. Defaults to latest if not set.

  • wiiu_endpoint (bool, option) – Whether the Wii U endpoint for the NUS should be used or not. This increases download speeds. Defaults to False.

  • endpoint_override (str, optional) – A custom endpoint URL to use instead of the standard Wii or Wii U endpoints. Defaults to no override, and if set entirely overrides the “wiiu_endpoint” parameter.

Returns:

The TMD file from the NUS.

Return type:

bytes

libWiiPy.title.ticket module#

class libWiiPy.title.ticket.Ticket#

Bases: object

A Ticket object that allows for either loading and editing an existing Ticket or creating one manually if desired.

is_dev#

Whether this Ticket is signed for development or not, and whether the Title Key is encrypted for development or not.

Type:

bool

signature#

The signature applied to the ticket.

Type:

bytes

ticket_version#

The version of the ticket.

Type:

int

title_key_enc#

The Title Key contained in the ticket, in encrypted form.

Type:

bytes

ticket_id#

The unique ID of this ticket, used for console-specific title installations.

Type:

bytes

console_id#

The unique ID of the console this ticket was designed for, if this is a console-specific ticket.

Type:

int

title_version#

The version of the title this ticket was designed for.

Type:

int

common_key_index#

The index of the common key required to decrypt this ticket’s Title Key.

Type:

int

dump() bytes#

Dumps the Ticket object back into bytes.

Returns:

The full Ticket file as bytes.

Return type:

bytes

fakesign() None#

Fakesigns this Ticket for the trucha bug.

This is done by brute-forcing a Ticket body hash starting with 00, causing it to pass signature verification on older IOS versions that incorrectly check the hash using strcmp() instead of memcmp(). The signature will also be erased and replaced with all NULL bytes.

The hash is brute-forced by using the first two bytes of an unused section of the Ticket as a 16-bit integer, and incrementing that value by 1 until an appropriate hash is found.

This modifies the Ticket object in place. You will need to call this method after any changes, and before dumping the Ticket object back into bytes.

get_common_key_type() str#

Gets the name of the common key used to encrypt the Title Key contained in the ticket.

Returns:

The name of the common key required.

Return type:

str

get_is_fakesigned() bool#

Checks the Ticket object to see if it is currently fakesigned. For a description of fakesigning, refer to the fakesign() method.

Returns:

True if the Ticket is fakesigned, False otherwise.

Return type:

bool

get_title_id() str#

Gets the Title ID of the ticket’s associated title.

Returns:

The Title ID of the title.

Return type:

str

get_title_key() bytes#

Gets the decrypted title key contained in the ticket.

Returns:

The decrypted title key.

Return type:

bytes

load(ticket: bytes) None#

Loads raw Ticket data and sets all attributes of the WAD object. This allows for manipulating an already existing Ticket.

Parameters:

ticket (bytes) – The data for the Ticket you wish to load.

set_title_id(title_id) None#

Sets the Title ID property of the Ticket. Recommended over setting the property directly because of input validation.

Parameters:

title_id (str) – The new Title ID of the title.

set_title_version(new_version: str | int) None#

Sets the version of the title in the Ticket. Recommended over setting the data directly because of input validation.

Accepts either standard form (vX.X) as a string or decimal form (vXXX) as an integer.

Parameters:

new_version (str, int) – The new version of the title. See description for valid formats.

libWiiPy.title.title module#

class libWiiPy.title.title.Title#

Bases: object

A Title object that contains all components of a title, and allows altering them. Provides higher-level access than manually creating WAD, TMD, Ticket, and ContentRegion objects and ensures that any data that needs to match between files matches.

wad#

A WAD object of a WAD containing the title’s data.

Type:

WAD

tmd#

A TMD object of the title’s TMD.

Type:

TMD

ticket#

A Ticket object of the title’s Ticket.

Type:

Ticket

content#

A ContentRegion object containing the title’s contents.

Type:

ContentRegion

add_content(dec_content: bytes, cid: int, content_type: int) None#

Adds a new decrypted content to the end of the ContentRegion, and adds the provided Content ID, content type, content size, and content hash to a new record in the ContentRecord list. The index will be automatically assigned by incrementing the current highest index in the records.

This first gets the content hash and size from the provided data, and then encrypts the content with the Title Key before adding it to the ContentRegion.

Parameters:
  • dec_content (bytes) – The new decrypted content to add.

  • cid (int) – The Content ID to assign the new content in the content record.

  • content_type (int) – The type of the new content.

add_enc_content(enc_content: bytes, cid: int, index: int, content_type: int, content_size: int, content_hash: bytes) None#

Adds a new encrypted content to the ContentRegion, and adds the provided Content ID, index, content type, content size, and content hash to a new record in the ContentRecord list.

Parameters:
  • enc_content (bytes) – The new encrypted content to add.

  • cid (int) – The Content ID to assign the new content in the content record.

  • index (int) – The index used when encrypting the new content.

  • content_type (int) – The type of the new content.

  • content_size (int) – The size of the new encrypted content when decrypted.

  • content_hash (bytes) – The hash of the new encrypted content when decrypted.

dump_wad() bytes#

Dumps all title components (TMD, Ticket, and contents) back into the WAD object, and then dumps the WAD back into raw data and returns it.

Returns:

wad_data – The raw data of the WAD.

Return type:

bytes

fakesign() None#

Fakesigns this Title for the trucha bug.

This is done by brute-forcing a TMD and Ticket body hash starting with 00, causing it to pass signature verification on older IOS versions that incorrectly check the hash using strcmp() instead of memcmp(). The TMD and Ticket signatures will also be erased and replaced with all NULL bytes.

This modifies the TMD and Ticket objects that are part of this Title in place. You will need to call this method after any changes to the TMD or Ticket, and before dumping the Title object into a WAD to ensure that the WAD is properly fakesigned.

get_content_by_cid(cid: int, skip_hash=False) bytes#

Gets an individual content from the content region based on the provided Content ID, in decrypted form.

Parameters:
  • cid (int) – The Content ID of the content you want to get. Expected to be in decimal form.

  • skip_hash (bool, optional) – Skip the hash check and return the content regardless of its hash. Defaults to false.

Returns:

The decrypted content listed in the content record.

Return type:

bytes

get_content_by_index(index: id, skip_hash=False) bytes#

Gets an individual content from the content region based on the provided index, in decrypted form.

Parameters:
  • index (int) – The index of the content you want to get.

  • skip_hash (bool, optional) – Skip the hash check and return the content regardless of its hash. Defaults to false.

Returns:

The decrypted content listed in the content record.

Return type:

bytes

get_is_fakesigned()#

Checks the Title object to see if it is currently fakesigned. This ensures that both the TMD and Ticket are fakesigned. For a description of fakesigning, refer to the fakesign() method.

Returns:

True if the Title is fakesigned, False otherwise.

Return type:

bool

get_title_size(absolute=False) int#

Gets the installed size of the title, including the TMD and Ticket, in bytes. The “absolute” option determines whether shared content sizes should be included in the total size or not. This option defaults to False.

Parameters:

absolute (bool, optional) – Whether shared contents should be included in the total size or not. Defaults to False.

Returns:

The installed size of the title, in bytes.

Return type:

int

get_title_size_blocks(absolute=False) int#

Gets the installed size of the title, including the TMD and Ticket, in the Wii’s displayed “blocks” format. The “absolute” option determines whether shared content sizes should be included in the total size or not. This option defaults to False.

1 Wii block is equal to 128KiB, and if any amount of a block is used, the entire block is considered used.

Parameters:

absolute (bool, optional) – Whether shared contents should be included in the total size or not. Defaults to False.

Returns:

The installed size of the title, in blocks.

Return type:

int

load_content(dec_content: bytes, index: int) None#

Loads the provided decrypted content into the ContentRegion at the specified index, but first checks to make sure that it matches the corresponding record. This content will then be encrypted using the title’s Title Key before being loaded.

Parameters:
  • dec_content (bytes) – The decrypted content to load.

  • index (int) – The index to load the content at.

load_content_records() None#

Load content records from the TMD into the ContentRegion to allow loading content files based on the records. This requires that a TMD has already been loaded and will throw an exception if it isn’t.

load_ticket(ticket: bytes) None#

Load existing Ticket data into the title. Note that this will overwrite any existing Ticket data for this title.

Parameters:

ticket (bytes) – The data for the WAD you wish to load.

load_tmd(tmd: bytes) None#

Load existing TMD data into the title. Note that this will overwrite any existing TMD data for this title.

Parameters:

tmd (bytes) – The data for the WAD you wish to load.

load_wad(wad: bytes) None#

Load existing WAD data into the title and create WAD, TMD, Ticket, and ContentRegion objects based off of it to allow you to modify that data. Note that this will overwrite any existing data for this title.

Parameters:

wad (bytes) – The data for the WAD you wish to load.

set_content(dec_content: bytes, index: int, cid: int = None, content_type: int = None) None#

Sets the content at the provided index to the provided new decrypted content. The hash and content size of this content will be generated and then set in the corresponding content record. A new Content ID or content type can also be specified, but if it isn’t then the current values are preserved.

This also updates the content records in the TMD after the content is set.

Parameters:
  • dec_content (bytes) – The new decrypted content to set.

  • index (int) – The index to place the new content at.

  • cid (int, optional) – The Content ID to assign the new content in the content record.

  • content_type (int, optional) – The type of the new content.

set_enc_content(enc_content: bytes, index: int, content_size: int, content_hash: bytes, cid: int = None, content_type: int = None) None#

Sets the content at the provided index to the provided new encrypted content. The provided hash and content size are set in the corresponding content record. A new Content ID or content type can also be specified, but if it isn’t then the current values are preserved.

This also updates the content records in the TMD after the content is set.

Parameters:
  • enc_content (bytes) – The new encrypted content to set.

  • index (int) – The index to place the new content at.

  • content_size (int) – The size of the new encrypted content when decrypted.

  • content_hash (bytes) – The hash of the new encrypted content when decrypted.

  • cid (int) – The Content ID to assign the new content in the content record.

  • content_type (int) – The type of the new content.

set_title_id(title_id: str) None#

Sets the Title ID of the title in both the TMD and Ticket. This also re-encrypts the Title Key as the Title Key is used as the IV for decrypting it.

Parameters:

title_id (str) – The new Title ID of the title.

set_title_version(title_version: str | int) None#

Sets the version of the title in both the TMD and Ticket.

Accepts either standard form (vX.X) as a string or decimal form (vXXX) as an integer.

Parameters:

title_version (str, int) – The new version of the title. See description for valid formats.

libWiiPy.title.tmd module#

class libWiiPy.title.tmd.TMD#

Bases: object

A TMD object that allows for either loading and editing an existing TMD or creating one manually if desired.

title_id#

The title ID of the title listed in the TMD.

Type:

str

title_version#

The version of the title listed in the TMD.

Type:

int

tmd_version#

The version of the TMD.

Type:

int

ios_tid#

The title ID of the IOS the title runs on.

Type:

str

ios_version#

The IOS version the title runs on.

Type:

int

num_contents#

The number of contents listed in the TMD.

Type:

int

class AccessFlags(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: IntEnum

AHB = 0#
DVD_VIDEO = 1#
dump() bytes#

Dumps the TMD object back into bytes.

Returns:

The full TMD file as bytes.

Return type:

bytes

fakesign() None#

Fakesigns this TMD for the trucha bug.

This is done by brute-forcing a TMD body hash starting with 00, causing it to pass signature verification on older IOS versions that incorrectly check the hash using strcmp() instead of memcmp(). The signature will also be erased and replaced with all NULL bytes.

The hash is brute-forced by incrementing an unused 16-bit integer in the TMD by 1 until an appropriate hash is found.

This modifies the TMD object in place. You will need to call this method after any changes, and before dumping the TMD object back into bytes.

get_access_right(flag: int) bool#

Gets whether the specified access rights flag is enabled or not. This is done by checking the specified bit. Possible flags and their corresponding bits are defined in AccessFlags.

Parameters:

flag (int) – The flag to check.

Returns:

True if the flag is enabled, False otherwise.

Return type:

bool

get_content_record(record) _ContentRecord#

Gets the content record at the specified index.

Parameters:

record (int) – The content record to be retrieved.

Returns:

A ContentRecord object containing the data in the content record.

Return type:

_ContentRecord

get_content_type(content_index: int) str#

Gets the type of content contained in the TMD’s associated title.

Can be one of several possible values: ‘Normal’, ‘Development/Unknown’, ‘Hash Tree’, ‘DLC’, or ‘Shared’

Parameters:

content_index (int) – The index of the content you want the type of.

Returns:

The type of content.

Return type:

str

get_is_fakesigned() bool#

Checks the TMD object to see if it is currently fakesigned. For a description of fakesigning, refer to the fakesign() method.

Returns:

True if the TMD is fakesigned, False otherwise.

Return type:

bool

get_title_region() str#

Gets the system region specified in the TMD. This is not necessarily the true region of the title, but is the hardware region that this title is designed and allowed to be run on.

Can be one of several possible values: ‘JPN’, ‘USA’, ‘EUR’, ‘None’, or ‘KOR’.

Returns:

The region of the title.

Return type:

str

get_title_type() str#

Gets the type of the title this TMD describes. The title_type field is not related to these types.

Can be one of several possible values: ‘System’, ‘Game’, ‘Channel’, ‘SystemChannel’, ‘GameChannel’, or ‘HiddenChannel’

Returns:

The type of the title.

Return type:

str

load(tmd: bytes) None#

Loads raw TMD data and sets all attributes of the TMD object. This allows for manipulating an already existing TMD.

Parameters:

tmd (bytes) – The data for the TMD you wish to load.

set_title_id(title_id) None#

Sets the Title ID property of the TMD. Recommended over setting the property directly because of input validation.

Parameters:

title_id (str) – The new Title ID of the title.

set_title_version(new_version: str | int) None#

Sets the version of the title in the TMD. Recommended over setting the data directly because of input validation.

Accepts either standard form (vX.X) as a string or decimal form (vXXX) as an integer.

Parameters:

new_version (str, int) – The new version of the title. See description for valid formats.

libWiiPy.title.util module#

libWiiPy.title.util.title_ver_dec_to_standard(version: int, title_id: str, vwii: bool = False) str#

Converts a title’s version from decimal form (vXXX, the way the version is stored in the TMD/Ticket) to its standard and human-readable form (vX.X). The Title ID is required as some titles handle this version differently from others. For the System Menu, the returned version will include the region code (ex. 4.3U).

Parameters:
  • version (int) – The version of the title, in decimal form.

  • title_id (str) – The Title ID that the version is associated with.

  • vwii (bool) – Whether this title is for the vWii or not. Only relevant for the System Menu.

Returns:

The version of the title, in standard form.

Return type:

str

libWiiPy.title.util.title_ver_standard_to_dec(version: str, title_id: str) int#

Converts a title’s version from its standard and human-readable form (vX.X) to its decimal form (vXXX, the way the version is stored in the TMD/Ticket). The Title ID is required as some titles handle this version differently from others. For the System Menu, the supplied version must include the region code (ex. 4.3U) for the conversion to work correctly.

Parameters:
  • version (str) – The version of the title, in standard form.

  • title_id (str) – The Title ID that the version is associated with.

Returns:

The version of the title, in decimal form.

Return type:

int

libWiiPy.title.wad module#

class libWiiPy.title.wad.WAD#

Bases: object

A WAD object that allows for either loading and editing an existing WAD or creating a new WAD from raw data.

wad_type#

The type of WAD, either ib for boot2 or Is for normal installable WADs.

Type:

str

wad_cert_size#

The size of the WAD’s certificate.

Type:

int

wad_crl_size#

The size of the WAD’s crl.

Type:

int

wad_tik_size#

The size of the WAD’s Ticket.

Type:

int

wad_tmd_size#

The size of the WAD’s TMD.

Type:

int

wad_content_size#

The size of WAD’s total content region.

Type:

int

wad_meta_size#

The size of the WAD’s meta/footer.

Type:

int

dump() bytes#

Dumps the WAD object into the raw WAD file. This allows for creating a WAD file from the data contained in the WAD object.

Returns:

The full WAD file as bytes.

Return type:

bytes

get_cert_data() bytes#

Gets the certificate data from the WAD.

Returns:

The certificate data.

Return type:

bytes

get_content_data() bytes#

Gets the content of the WAD.

Returns:

The content data.

Return type:

bytes

get_crl_data() bytes#

Gets the crl data from the WAD, if it exists.

Returns:

The crl data.

Return type:

bytes

get_meta_data() bytes#

Gets the meta region of the WAD, which is typically unused.

Returns:

The meta region.

Return type:

bytes

get_ticket_data() bytes#

Gets the ticket data from the WAD.

Returns:

The ticket data.

Return type:

bytes

get_tmd_data() bytes#

Returns the TMD data from the WAD.

Returns:

The TMD data.

Return type:

bytes

get_wad_type() str#

Gets the type of the WAD.

Returns:

The type of the WAD. This is ‘Is’, unless the WAD contains boot2, where it is ‘ib’.

Return type:

str

load(wad_data: bytes) None#

Loads raw WAD data and sets all attributes of the WAD object. This allows for manipulating an already existing WAD file.

Parameters:

wad_data (bytes) – The data for the WAD file to load.

set_cert_data(cert_data) None#

Sets the certificate data of the WAD. Also calculates the new size.

Parameters:

cert_data (bytes) – The new certificate data.

set_content_data(content_data, size: int = None) None#

Sets the content data of the WAD. Also calculates the new size.

Parameters:
  • content_data (bytes) – The new content data.

  • size (int, option) – The size of the new content data.

set_crl_data(crl_data) None#

Sets the crl data of the WAD. Also calculates the new size.

Parameters:

crl_data (bytes) – The new crl data.

set_meta_data(meta_data) None#

Sets the meta data of the WAD. Also calculates the new size.

Parameters:

meta_data (bytes) – The new meta data.

set_ticket_data(tik_data) None#

Sets the Ticket data of the WAD. Also calculates the new size.

Parameters:

tik_data (bytes) – The new TMD data.

set_tmd_data(tmd_data) None#

Sets the TMD data of the WAD. Also calculates the new size.

Parameters:

tmd_data (bytes) – The new TMD data.

Module contents#