libWiiPy.title.content Module#
The libWiiPy.title.content
module provides support for parsing, adding, removing, and editing content files from a digital Wii title.
Module Contents#
- 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#
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.
The shared content records stored in content.map.
- Type:
List[_SharedContentRecord]
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
Dumps the SharedContentMap object back into a content.map file.
- Returns:
The raw data of the content.map file.
- Return type:
bytes
Loads the raw content map and parses the records in it.
- Parameters:
content_map (bytes) – The data of a content.map file.