libWiiPy.title.title Module#
The libWiiPy.title.title
module provides a high-level interface for handling all the components of a digital Wii title through one class. It allows for directly importing a WAD, and will automatically extract the various components and load them into their appropriate classes. Additionally, it provides duplicates of some methods found in those classes that require fewer arguments, as it has the context of the other components and is able to retrieve additional data automatically.
An example of that idea can be seen with the method get_content_by_index()
. In its original definition, which can be seen at libWiiPy.title.content.ContentRegion.get_content_by_index
, you are required to supply the Title Key for the title that the content is sourced from. In contrast, when using libWiiPy.title.title.Title.get_content_by_index
, you do not need to supply a Title Key, as the Title object already has the context of the Ticket and can retrieve the Title Key from it automatically. In a similar vein, this module provides the easiest route for verifying that a title is legitimately signed by Nintendo. The method libWiiPy.title.title.Title.get_is_signed
is able to access the entire certificate chain, the TMD, and the Ticket, and is therefore able to verify all components of the title by itself.
Because using libWiiPy.title.title.Title
allows many operations to be much simpler than if you manage the components separately, it’s generally recommended to use it whenever possible.
Module Contents#
- 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.
- cert_chain#
The chain of certificates used to verify the contents of a title.
- Type:
- content#
A ContentRegion object containing the title’s contents.
- Type:
- 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
See also
- get_is_signed() bool #
Uses the certificate chain to verify whether the Title object contains a properly signed title or not. This verifies both the TMD and Ticket, and if either one fails verification then the title is not considered valid.
This will validate the entire certificate chain. If any part of the chain doesn’t match the other pieces, then this method will raise an exception.
- Returns:
Whether the title is properly signed or not.
- Return type:
bool
See also
- 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_cert_chain(cert_chain: bytes) None #
Load an existing certificate chain into the title. Note that this will overwrite any existing certificate chain data for this title.
- Parameters:
cert_chain (bytes) – The data for the certificate chain to load.
- 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 Ticket 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 TMD 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.