mirror of
https://github.com/NinjaCheetah/libWiiPy.git
synced 2025-07-03 16:31:01 -04:00
Compare commits
No commits in common. "main" and "v0.6.0" have entirely different histories.
@ -17,13 +17,7 @@ release = 'main'
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
||||
extensions = [
|
||||
'myst_parser',
|
||||
'sphinx.ext.napoleon',
|
||||
'sphinx_copybutton',
|
||||
'sphinx_tippy',
|
||||
'sphinx_design'
|
||||
]
|
||||
extensions = ['myst_parser', 'sphinx.ext.napoleon', 'sphinx_copybutton', 'sphinx_tippy', 'sphinx_design']
|
||||
|
||||
templates_path = ['_templates']
|
||||
exclude_patterns = ["Thumbs.db", ".DS_Store"]
|
||||
|
@ -11,5 +11,4 @@ The `libWiiPy.title.nus` module provides support for downloading digital Wii tit
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
:special-members: __call__
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "libWiiPy"
|
||||
version = "1.0.0"
|
||||
version = "0.6.0"
|
||||
authors = [
|
||||
{ name="NinjaCheetah", email="ninjacheetah@ncxprogramming.com" },
|
||||
{ name="Lillian Skinner", email="lillian@randommeaninglesscharacters.com" }
|
||||
@ -13,7 +13,7 @@ classifiers = [
|
||||
# 3 - Alpha
|
||||
# 4 - Beta
|
||||
# 5 - Production/Stable
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Development Status :: 4 - Beta",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
@ -23,8 +23,7 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"pycryptodome",
|
||||
"requests",
|
||||
"types-requests"
|
||||
"requests"
|
||||
]
|
||||
keywords = ["Wii", "wii"]
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
build
|
||||
pycryptodome
|
||||
requests
|
||||
types-requests
|
||||
sphinx
|
||||
sphinx-book-theme
|
||||
myst-parser
|
||||
|
@ -8,11 +8,10 @@
|
||||
# See <link pending> for details about the ASH compression format.
|
||||
|
||||
import io
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
from dataclasses import dataclass as _dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
@_dataclass
|
||||
class _ASHBitReader:
|
||||
"""
|
||||
An _ASHBitReader class used to parse individual words in an ASH file. Private class used by the ASH module.
|
||||
@ -94,7 +93,7 @@ def _ash_bit_reader_read_bits(bit_reader: _ASHBitReader, num_bits: int):
|
||||
return bits
|
||||
|
||||
|
||||
def _ash_read_tree(bit_reader: _ASHBitReader, width: int, left_tree: List[int], right_tree: List[int]):
|
||||
def _ash_read_tree(bit_reader: _ASHBitReader, width: int, left_tree: [int], right_tree: [int]):
|
||||
# Read either the symbol or distance tree from the ASH file, and return the root of that tree.
|
||||
work = [0] * (2 * (1 << width))
|
||||
work_pos = 0
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
import io
|
||||
from dataclasses import dataclass as _dataclass
|
||||
from typing import List, Tuple
|
||||
from typing import List as _List
|
||||
|
||||
|
||||
_LZ_MIN_DISTANCE = 0x01 # Minimum distance for each reference.
|
||||
@ -21,7 +21,7 @@ class _LZNode:
|
||||
weight: int = 0
|
||||
|
||||
|
||||
def _compress_compare_bytes(buffer: List[int], offset1: int, offset2: int, abs_len_max: int) -> int:
|
||||
def _compress_compare_bytes(buffer: _List[int], offset1: int, offset2: int, abs_len_max: int) -> int:
|
||||
# Compare bytes up to the maximum length we can match. Start by comparing the first 3 bytes, since that's the
|
||||
# minimum match length and this allows for a more optimized early exit.
|
||||
num_matched = 0
|
||||
@ -32,7 +32,7 @@ def _compress_compare_bytes(buffer: List[int], offset1: int, offset2: int, abs_l
|
||||
return num_matched
|
||||
|
||||
|
||||
def _compress_search_matches_optimized(buffer: List[int], pos: int) -> Tuple[int, int]:
|
||||
def _compress_search_matches_optimized(buffer: _List[int], pos: int) -> (int, int):
|
||||
bytes_left = len(buffer) - pos
|
||||
global _LZ_MAX_DISTANCE, _LZ_MIN_LENGTH, _LZ_MAX_LENGTH, _LZ_MIN_DISTANCE
|
||||
# Default to only looking back 4096 bytes, unless we've moved fewer than 4096 bytes, in which case we should
|
||||
@ -54,7 +54,7 @@ def _compress_search_matches_optimized(buffer: List[int], pos: int) -> Tuple[int
|
||||
return biggest_match, biggest_match_pos
|
||||
|
||||
|
||||
def _compress_search_matches_greedy(buffer: List[int], pos: int) -> Tuple[int, int]:
|
||||
def _compress_search_matches_greedy(buffer: _List[int], pos: int) -> (int, int):
|
||||
# Finds and returns the first valid match, rather that finding the best one.
|
||||
bytes_left = len(buffer) - pos
|
||||
global _LZ_MAX_DISTANCE, _LZ_MAX_LENGTH, _LZ_MIN_DISTANCE
|
||||
|
@ -57,7 +57,7 @@ class U8Archive:
|
||||
imet_header: IMETHeader
|
||||
The IMET header of the U8 archive, if one exists. Otherwise, an empty IMETHeader object.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.u8_magic = b''
|
||||
self.u8_node_list: List[_U8Node] = [] # All the nodes in the header of a U8 file.
|
||||
self.file_name_list: List[str] = []
|
||||
@ -68,16 +68,16 @@ class U8Archive:
|
||||
self.root_node: _U8Node = _U8Node(0, 0, 0, 0)
|
||||
self.imet_header: IMETHeader = IMETHeader()
|
||||
|
||||
def load(self, u8: bytes) -> None:
|
||||
def load(self, u8_data: bytes) -> None:
|
||||
"""
|
||||
Loads raw U8 data into a new U8 object. This allows for extracting the file and updating its contents.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
u8 : bytes
|
||||
u8_data : bytes
|
||||
The data for the U8 file to load.
|
||||
"""
|
||||
with io.BytesIO(u8) as u8_data:
|
||||
with io.BytesIO(u8_data) as u8_data:
|
||||
# Read the first 4 bytes of the file to ensure that it's a U8 archive.
|
||||
u8_data.seek(0x0)
|
||||
self.u8_magic = u8_data.read(4)
|
||||
@ -126,7 +126,7 @@ class U8Archive:
|
||||
# Seek back before the root node so that it gets read with all the rest.
|
||||
u8_data.seek(u8_data.tell() - 12)
|
||||
# Iterate over the number of nodes that the root node lists.
|
||||
for _ in range(root_node_size):
|
||||
for node in range(root_node_size):
|
||||
node_type = int.from_bytes(u8_data.read(1))
|
||||
node_name_offset = int.from_bytes(u8_data.read(3))
|
||||
node_data_offset = int.from_bytes(u8_data.read(4))
|
||||
@ -160,7 +160,7 @@ class U8Archive:
|
||||
# This is 0 because the header size DOES NOT include the initial 32 bytes describing the file.
|
||||
header_size = 0
|
||||
# Add 12 bytes for each node, since that's how many bytes each one is made up of.
|
||||
for _ in range(len(self.u8_node_list)):
|
||||
for node in range(len(self.u8_node_list)):
|
||||
header_size += 12
|
||||
# Add the number of bytes used for each file/folder name in the string table.
|
||||
for file_name in self.file_name_list:
|
||||
@ -170,13 +170,13 @@ class U8Archive:
|
||||
# Adjust all nodes to place file data in the same order as the nodes. Why isn't it already like this?
|
||||
current_data_offset = data_offset
|
||||
current_name_offset = 0
|
||||
for idx in range(len(self.u8_node_list)):
|
||||
if self.u8_node_list[idx].type == 0:
|
||||
self.u8_node_list[idx].data_offset = _align_value(current_data_offset, 32)
|
||||
current_data_offset += _align_value(self.u8_node_list[idx].size, 32)
|
||||
for node in range(len(self.u8_node_list)):
|
||||
if self.u8_node_list[node].type == 0:
|
||||
self.u8_node_list[node].data_offset = _align_value(current_data_offset, 32)
|
||||
current_data_offset += _align_value(self.u8_node_list[node].size, 32)
|
||||
# Calculate the name offsets, including the extra 1 for the NULL byte at the end of each name.
|
||||
self.u8_node_list[idx].name_offset = current_name_offset
|
||||
current_name_offset += len(self.file_name_list[idx]) + 1
|
||||
self.u8_node_list[node].name_offset = current_name_offset
|
||||
current_name_offset += len(self.file_name_list[node]) + 1
|
||||
# Begin joining all the U8 archive data into bytes.
|
||||
u8_data = b''
|
||||
# Magic number.
|
||||
@ -300,7 +300,7 @@ def _pack_u8_dir(u8_archive: U8Archive, current_path, node_count, parent_node):
|
||||
return u8_archive, node_count
|
||||
|
||||
|
||||
def pack_u8(input_path, generate_imet=False, imet_titles:List[str] | None = None) -> bytes:
|
||||
def pack_u8(input_path, generate_imet=False, imet_titles:List[str]=None) -> bytes:
|
||||
"""
|
||||
Packs the provided file or folder into a new U8 archive, and returns the raw file data for it.
|
||||
|
||||
@ -369,7 +369,7 @@ class IMETHeader:
|
||||
md5_hash : bytes
|
||||
MD5 sum of the entire header, with this field being all zeros during the hashing.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.magic: str = "" # Should always be "IMET"
|
||||
self.header_size: int = 0 # Always 1536? I assumed this would mean something, but it's just the header length.
|
||||
self.imet_version: int = 0 # Always 3?
|
||||
@ -513,15 +513,13 @@ class IMETHeader:
|
||||
raise ValueError(f"The specified language is not valid!")
|
||||
return self.channel_names[target_languages]
|
||||
# If multiple channel names were requested.
|
||||
elif type(target_languages) == List:
|
||||
else:
|
||||
channel_names = []
|
||||
for lang in target_languages:
|
||||
if lang not in self.LocalizedTitles:
|
||||
raise ValueError(f"The specified language at index {target_languages.index(lang)} is not valid!")
|
||||
channel_names.append(self.channel_names[lang])
|
||||
return channel_names
|
||||
else:
|
||||
raise TypeError("Target languages must be type int or List[int]!")
|
||||
|
||||
def set_channel_names(self, channel_names: Tuple[int, str] | List[Tuple[int, str]]) -> None:
|
||||
"""
|
||||
@ -546,7 +544,7 @@ class IMETHeader:
|
||||
f"42 characters!")
|
||||
self.channel_names[channel_names[0]] = channel_names[1]
|
||||
# If a list of channel names was provided.
|
||||
elif type(channel_names) == list:
|
||||
else:
|
||||
for name in channel_names:
|
||||
if name[0] not in self.LocalizedTitles:
|
||||
raise ValueError(f"The target language \"{name[0]}\" for the name at index {channel_names.index(name)} "
|
||||
@ -555,5 +553,3 @@ class IMETHeader:
|
||||
raise ValueError(f"The channel name \"{name[1]}\" at index {channel_names.index(name)} is too long! "
|
||||
f"Channel names cannot exceed 42 characters!")
|
||||
self.channel_names[name[0]] = name[1]
|
||||
else:
|
||||
raise TypeError("Channel names must be type Tuple[int, str] or List[Tuple[int, str]]!")
|
||||
|
@ -14,10 +14,16 @@ class IMD5Header:
|
||||
|
||||
An IMD5 header is always 32 bytes long.
|
||||
|
||||
:ivar magic: Magic number for the header, should be "IMD5".
|
||||
:ivar file_size: The size of the file this header precedes.
|
||||
:ivar zeros: 8 bytes of zero padding.
|
||||
:ivar md5_hash: The MD5 hash of the file this header precedes.
|
||||
Attributes
|
||||
----------
|
||||
magic : str
|
||||
Magic number for the header, should be "IMD5".
|
||||
file_size : int
|
||||
The size of the file this header precedes.
|
||||
zeros : int
|
||||
8 bytes of zero padding.
|
||||
md5_hash : bytes
|
||||
The MD5 hash of the file this header precedes.
|
||||
"""
|
||||
magic: str # Should always be "IMD5"
|
||||
file_size: int
|
||||
|
@ -7,7 +7,7 @@ import os
|
||||
import pathlib
|
||||
import shutil
|
||||
from dataclasses import dataclass as _dataclass
|
||||
from typing import Callable, List
|
||||
from typing import List
|
||||
from ..title.ticket import Ticket
|
||||
from ..title.title import Title
|
||||
from ..title.tmd import TMD
|
||||
@ -32,7 +32,7 @@ class EmuNAND:
|
||||
emunand_root : pathlib.Path
|
||||
The path to the EmuNAND root directory.
|
||||
"""
|
||||
def __init__(self, emunand_root: str | pathlib.Path, callback: Callable | None = None):
|
||||
def __init__(self, emunand_root: str | pathlib.Path, callback: callable = None):
|
||||
self.emunand_root = pathlib.Path(emunand_root)
|
||||
self.log = callback if callback is not None else None
|
||||
|
||||
@ -128,10 +128,6 @@ class EmuNAND:
|
||||
uid_sys = _UidSys()
|
||||
if not uid_sys_path.exists():
|
||||
uid_sys.create()
|
||||
else:
|
||||
uid_sys.load(uid_sys_path.read_bytes())
|
||||
uid_sys.add(title.tmd.title_id)
|
||||
uid_sys_path.write_bytes(uid_sys.dump())
|
||||
|
||||
def uninstall_title(self, tid: str) -> None:
|
||||
"""
|
||||
@ -174,8 +170,12 @@ class EmuNAND:
|
||||
An InstalledTitles object that is used to track a title type and any titles that belong to that type that are
|
||||
installed to an EmuNAND.
|
||||
|
||||
:ivar type: The type (Title ID high) of the installed titles.
|
||||
:ivar titles: The Title ID low of each installed title.
|
||||
Attributes
|
||||
----------
|
||||
type : str
|
||||
The type (Title ID high) of the installed titles.
|
||||
titles : List[str]
|
||||
The Title ID low of each installed title.
|
||||
"""
|
||||
type: str
|
||||
titles: List[str]
|
||||
|
@ -4,7 +4,6 @@
|
||||
# See https://wiibrew.org/wiki//title/00000001/00000002/data/setting.txt for information about setting.txt.
|
||||
|
||||
import io
|
||||
from typing import List
|
||||
from ..shared import _pad_bytes
|
||||
|
||||
|
||||
@ -33,7 +32,7 @@ class SettingTxt:
|
||||
game : str
|
||||
Another region code, possibly set by the hidden region select channel.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.area: str = ""
|
||||
self.model: str = ""
|
||||
self.dvd: int = 0
|
||||
@ -54,16 +53,16 @@ class SettingTxt:
|
||||
"""
|
||||
with io.BytesIO(setting_txt) as setting_data:
|
||||
global _key # I still don't actually know what *kind* of encryption this is.
|
||||
setting_txt_dec: List[int] = []
|
||||
setting_txt_dec: [int] = []
|
||||
for i in range(0, 256):
|
||||
setting_txt_dec.append(int.from_bytes(setting_data.read(1)) ^ (_key & 0xff))
|
||||
_key = (_key << 1) | (_key >> 31)
|
||||
setting_txt_bytes = bytes(setting_txt_dec)
|
||||
setting_txt_dec = bytes(setting_txt_dec)
|
||||
try:
|
||||
setting_str = setting_txt_bytes.decode('utf-8')
|
||||
setting_str = setting_txt_dec.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
last_newline_pos = setting_txt_bytes.rfind(b'\n') # This makes sure we don't try to decode any garbage data.
|
||||
setting_str = setting_txt_bytes[:last_newline_pos + 1].decode('utf-8')
|
||||
last_newline_pos = setting_txt_dec.rfind(b'\n') # This makes sure we don't try to decode any garbage data.
|
||||
setting_str = setting_txt_dec[:last_newline_pos + 1].decode('utf-8')
|
||||
self.load_decrypted(setting_str)
|
||||
|
||||
def load_decrypted(self, setting_txt: str) -> None:
|
||||
@ -105,13 +104,13 @@ class SettingTxt:
|
||||
setting_txt_dec = setting_str.encode()
|
||||
global _key
|
||||
# This could probably be made more efficient somehow.
|
||||
setting_txt_enc: List[int] = []
|
||||
setting_txt_enc: [int] = []
|
||||
with io.BytesIO(setting_txt_dec) as setting_data:
|
||||
for i in range(0, len(setting_txt_dec)):
|
||||
setting_txt_enc.append(int.from_bytes(setting_data.read(1)) ^ (_key & 0xff))
|
||||
_key = (_key << 1) | (_key >> 31)
|
||||
setting_txt_bytes = _pad_bytes(bytes(setting_txt_enc), 256)
|
||||
return setting_txt_bytes
|
||||
setting_txt_enc = _pad_bytes(bytes(setting_txt_enc), 256)
|
||||
return setting_txt_enc
|
||||
|
||||
def dump_decrypted(self) -> str:
|
||||
"""
|
||||
|
@ -36,7 +36,7 @@ class UidSys:
|
||||
The entries stored in the uid.sys file.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.uid_entries: List[_UidSysEntry] = []
|
||||
|
||||
def load(self, uid_sys: bytes) -> None:
|
||||
@ -77,8 +77,7 @@ class UidSys:
|
||||
|
||||
def add(self, title_id: str | bytes) -> int:
|
||||
"""
|
||||
Adds a new Title ID to the uid.sys file and returns the UID assigned to that title. The new entry will only
|
||||
be added if the provided Title ID doesn't already have an assigned UID.
|
||||
Adds a new Title ID to the uid.sys file and returns the UID assigned to that title.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@ -91,8 +90,11 @@ class UidSys:
|
||||
The UID assigned to the new Title ID.
|
||||
"""
|
||||
if type(title_id) is bytes:
|
||||
# This catches the format b'0000000100000002'
|
||||
if len(title_id) == 16:
|
||||
title_id_converted = title_id.encode()
|
||||
# This catches the format b'\x00\x00\x00\x01\x00\x00\x00\x02'
|
||||
if len(title_id) == 8:
|
||||
elif len(title_id) == 8:
|
||||
title_id_converted = binascii.hexlify(title_id).decode()
|
||||
# If it isn't one of those lengths, it cannot possibly be valid, so reject it.
|
||||
else:
|
||||
@ -104,11 +106,6 @@ class UidSys:
|
||||
title_id_converted = title_id
|
||||
else:
|
||||
raise TypeError("Title ID type is not valid! It must be either type str or bytes.")
|
||||
# Ensure this TID hasn't already been assigned a UID. If it has, just exit early and return the UID.
|
||||
if self.uid_entries.count != 0:
|
||||
for entry in self.uid_entries:
|
||||
if entry.title_id == title_id_converted:
|
||||
return entry.uid
|
||||
# Generate the new UID by incrementing the current highest UID by 1.
|
||||
try:
|
||||
new_uid = self.uid_entries[-1].uid + 1
|
||||
|
@ -60,11 +60,11 @@ class Certificate:
|
||||
pub_key_exponent: int
|
||||
The exponent of this certificate's public key. Combined with the modulus to get the full key.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
self.type: CertificateType = CertificateType.RSA_4096
|
||||
def __init__(self):
|
||||
self.type: CertificateType | None = None
|
||||
self.signature: bytes = b''
|
||||
self.issuer: str = ""
|
||||
self.pub_key_type: CertificateKeyType = CertificateKeyType.RSA_4096
|
||||
self.pub_key_type: CertificateKeyType | None = None
|
||||
self.child_name: str = ""
|
||||
self.pub_key_id: int = 0
|
||||
self.pub_key_modulus: int = 0
|
||||
@ -151,7 +151,7 @@ class CertificateChain:
|
||||
ticket_cert: Certificate
|
||||
The XS (Ticket) certificate from the chain.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.ca_cert: Certificate = Certificate()
|
||||
self.tmd_cert: Certificate = Certificate()
|
||||
self.ticket_cert: Certificate = Certificate()
|
||||
|
@ -34,7 +34,7 @@ class ContentRegion:
|
||||
The total number of contents stored in the region.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.content_records: List[_ContentRecord] = []
|
||||
self.content_region_size: int = 0 # Size of the content region.
|
||||
self.num_contents: int = 0 # Number of contents in the content region.
|
||||
@ -66,16 +66,16 @@ class ContentRegion:
|
||||
start_offset += 64 - (content.content_size % 64)
|
||||
self.content_start_offsets.append(start_offset)
|
||||
# Build a list of all the encrypted content data.
|
||||
for idx in range(self.num_contents):
|
||||
for content in range(self.num_contents):
|
||||
# Seek to the start of the content based on the list of offsets.
|
||||
content_region_data.seek(self.content_start_offsets[idx])
|
||||
content_region_data.seek(self.content_start_offsets[content])
|
||||
# Calculate the number of bytes we need to read by adding bytes up the nearest multiple of 16 if needed.
|
||||
content_size = self.content_records[idx].content_size
|
||||
if (content_size % 16) != 0:
|
||||
content_size += 16 - (content_size % 16)
|
||||
bytes_to_read = self.content_records[content].content_size
|
||||
if (bytes_to_read % 16) != 0:
|
||||
bytes_to_read += 16 - (bytes_to_read % 16)
|
||||
# Read the file based on the size of the content in the associated record, then append that data to
|
||||
# the list of content.
|
||||
content_enc = content_region_data.read(content_size)
|
||||
content_enc = content_region_data.read(bytes_to_read)
|
||||
self.content_list.append(content_enc)
|
||||
|
||||
def dump(self) -> tuple[bytes, int]:
|
||||
@ -336,8 +336,8 @@ class ContentRegion:
|
||||
enc_content = encrypt_content(dec_content, title_key, index)
|
||||
self.add_enc_content(enc_content, cid, index, content_type, content_size, content_hash)
|
||||
|
||||
def set_enc_content(self, enc_content: bytes, index: int, content_size: int, content_hash: bytes,
|
||||
cid: int | None = None, content_type: int | None = None) -> None:
|
||||
def set_enc_content(self, 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
|
||||
@ -373,8 +373,8 @@ class ContentRegion:
|
||||
self.content_list.append(b'')
|
||||
self.content_list[index] = enc_content
|
||||
|
||||
def set_content(self, dec_content: bytes, index: int, title_key: bytes, cid: int | None = None,
|
||||
content_type: int | None = None) -> None:
|
||||
def set_content(self, 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
|
||||
@ -525,7 +525,7 @@ class SharedContentMap:
|
||||
The shared content records stored in content.map.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.shared_records: List[_SharedContentRecord] = []
|
||||
|
||||
def load(self, content_map: bytes) -> None:
|
||||
|
@ -20,7 +20,7 @@ class IOSPatcher:
|
||||
dip_module_index : int
|
||||
The content index that DIP resides in and where DIP patches are applied. -1 if DIP patches are not applied.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.title: Title = Title()
|
||||
self.es_module_index: int = -1
|
||||
self.dip_module_index: int = -1
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
import requests
|
||||
#import hashlib
|
||||
from typing import Any, List, Protocol
|
||||
from typing import List
|
||||
#from urllib.parse import urlparse as _urlparse
|
||||
from .title import Title
|
||||
from .tmd import TMD
|
||||
@ -14,36 +14,13 @@ from .ticket import Ticket
|
||||
_nus_endpoint = ["http://nus.cdn.shop.wii.com/ccs/download/", "http://ccs.cdn.wup.shop.nintendo.net/ccs/download/"]
|
||||
|
||||
|
||||
class DownloadCallback(Protocol):
|
||||
"""
|
||||
The format of a callable passed to a NUS download function.
|
||||
"""
|
||||
def __call__(self, done: int, total: int) -> Any:
|
||||
"""
|
||||
This function will be called with the current number of bytes downloaded and the total size of the file being
|
||||
downloaded.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
done : int
|
||||
The number of bytes already downloaded.
|
||||
total : int
|
||||
The total size of the file being downloaded.
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
def download_title(title_id: str, title_version: int | None = None, wiiu_endpoint: bool = False,
|
||||
endpoint_override: str | None = None, progress: DownloadCallback = lambda done, total: None) -> Title:
|
||||
def download_title(title_id: str, title_version: int = None, wiiu_endpoint: bool = False,
|
||||
endpoint_override: str = None) -> 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 extremely limited verbosity. It is instead
|
||||
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.
|
||||
|
||||
Be aware that you will receive fairly vague feedback from this function if you attach a progress callback. The
|
||||
callback will be connected to each of the individual functions called by this function, but there will be no
|
||||
indication of which function is currently running, just the progress of its download.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
title_id : str
|
||||
@ -55,34 +32,27 @@ def download_title(title_id: str, title_version: int | None = None, wiiu_endpoin
|
||||
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.
|
||||
progress: DownloadCallback, optional
|
||||
A callback function used to return the progress of the downloads. The provided callable must match the signature
|
||||
defined in DownloadCallback.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Title
|
||||
A Title object containing all the data from the downloaded title.
|
||||
|
||||
See Also
|
||||
--------
|
||||
libWiiPy.title.nus.DownloadCallback
|
||||
"""
|
||||
# First, create the new title.
|
||||
title = Title()
|
||||
# Download and load the certificate chain, TMD, and Ticket.
|
||||
title.load_cert_chain(download_cert_chain(wiiu_endpoint, endpoint_override))
|
||||
title.load_tmd(download_tmd(title_id, title_version, wiiu_endpoint, endpoint_override, progress))
|
||||
title.load_ticket(download_ticket(title_id, wiiu_endpoint, endpoint_override, progress))
|
||||
title.load_tmd(download_tmd(title_id, title_version, wiiu_endpoint, endpoint_override))
|
||||
title.load_ticket(download_ticket(title_id, wiiu_endpoint, endpoint_override))
|
||||
# Download all contents
|
||||
title.load_content_records()
|
||||
title.content.content_list = download_contents(title_id, title.tmd, wiiu_endpoint, endpoint_override, progress)
|
||||
title.content.content_list = download_contents(title_id, title.tmd, wiiu_endpoint, endpoint_override)
|
||||
# Return the completed title.
|
||||
return title
|
||||
|
||||
|
||||
def download_tmd(title_id: str, title_version: int | None = None, wiiu_endpoint: bool = False,
|
||||
endpoint_override: str | None = None, progress: DownloadCallback = lambda done, total: None) -> bytes:
|
||||
def 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.
|
||||
@ -98,18 +68,11 @@ def download_tmd(title_id: str, title_version: int | None = None, wiiu_endpoint:
|
||||
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.
|
||||
progress: DownloadCallback, optional
|
||||
A callback function used to return the progress of the download. The provided callable must match the signature
|
||||
defined in DownloadCallback.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bytes
|
||||
The TMD file from the NUS.
|
||||
|
||||
See Also
|
||||
--------
|
||||
libWiiPy.title.nus.DownloadCallback
|
||||
"""
|
||||
# Build the download URL. The structure is download/<TID>/tmd for latest and download/<TID>/tmd.<version> for
|
||||
# when a specific version is requested.
|
||||
@ -126,7 +89,7 @@ def download_tmd(title_id: str, title_version: int | None = None, wiiu_endpoint:
|
||||
tmd_url += "." + str(title_version)
|
||||
# Make the request.
|
||||
try:
|
||||
response = requests.get(url=tmd_url, headers={'User-Agent': 'wii libnup/1.0'}, stream=True)
|
||||
tmd_request = requests.get(url=tmd_url, headers={'User-Agent': 'wii libnup/1.0'}, stream=True)
|
||||
except requests.exceptions.ConnectionError:
|
||||
if endpoint_override:
|
||||
raise ValueError("A connection could not be made to the NUS endpoint. Please make sure that your endpoint "
|
||||
@ -134,16 +97,11 @@ def download_tmd(title_id: str, title_version: int | None = None, wiiu_endpoint:
|
||||
else:
|
||||
raise Exception("A connection could not be made to the NUS endpoint. The NUS may be unavailable.")
|
||||
# Handle a 404 if the TID/version doesn't exist.
|
||||
if response.status_code != 200:
|
||||
if tmd_request.status_code != 200:
|
||||
raise ValueError("The requested Title ID or TMD version does not exist. Please check the Title ID and Title"
|
||||
" version and then try again.")
|
||||
total_size = int(response.headers["Content-Length"])
|
||||
progress(0, total_size)
|
||||
# Stream the TMD's data in chunks so that we can post updates to the callback function (assuming one was supplied).
|
||||
raw_tmd = b""
|
||||
for chunk in response.iter_content(512):
|
||||
raw_tmd += chunk
|
||||
progress(len(raw_tmd), total_size)
|
||||
# Save the raw TMD.
|
||||
raw_tmd = tmd_request.content
|
||||
# Use a TMD object to load the data and then return only the actual TMD.
|
||||
tmd_temp = TMD()
|
||||
tmd_temp.load(raw_tmd)
|
||||
@ -151,8 +109,7 @@ def download_tmd(title_id: str, title_version: int | None = None, wiiu_endpoint:
|
||||
return tmd
|
||||
|
||||
|
||||
def download_ticket(title_id: str, wiiu_endpoint: bool = False, endpoint_override: str | None = None,
|
||||
progress: DownloadCallback = lambda done, total: None) -> bytes:
|
||||
def 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.
|
||||
@ -166,18 +123,11 @@ def download_ticket(title_id: str, wiiu_endpoint: bool = False, endpoint_overrid
|
||||
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.
|
||||
progress: DownloadCallback, optional
|
||||
A callback function used to return the progress of the download. The provided callable must match the signature
|
||||
defined in DownloadCallback.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bytes
|
||||
The Ticket file from the NUS.
|
||||
|
||||
See Also
|
||||
--------
|
||||
libWiiPy.title.nus.DownloadCallback
|
||||
"""
|
||||
# Build the download URL. The structure is download/<TID>/cetk, and cetk will only exist if this is a free
|
||||
# title.
|
||||
@ -191,23 +141,18 @@ def download_ticket(title_id: str, wiiu_endpoint: bool = False, endpoint_overrid
|
||||
ticket_url = endpoint_url + title_id + "/cetk"
|
||||
# Make the request.
|
||||
try:
|
||||
response = requests.get(url=ticket_url, headers={'User-Agent': 'wii libnup/1.0'}, stream=True)
|
||||
ticket_request = requests.get(url=ticket_url, headers={'User-Agent': 'wii libnup/1.0'}, stream=True)
|
||||
except requests.exceptions.ConnectionError:
|
||||
if endpoint_override:
|
||||
raise ValueError("A connection could not be made to the NUS endpoint. Please make sure that your endpoint "
|
||||
"override is valid.")
|
||||
else:
|
||||
raise Exception("A connection could not be made to the NUS endpoint. The NUS may be unavailable.")
|
||||
if response.status_code != 200:
|
||||
if ticket_request.status_code != 200:
|
||||
raise ValueError("The requested Title ID does not exist, or refers to a non-free title. Tickets can only"
|
||||
" be downloaded for titles that are free on the NUS.")
|
||||
total_size = int(response.headers["Content-Length"])
|
||||
progress(0, total_size)
|
||||
# Stream the Ticket's data just like with the TMD.
|
||||
cetk = b""
|
||||
for chunk in response.iter_content(chunk_size=1024):
|
||||
cetk += chunk
|
||||
progress(len(cetk), total_size)
|
||||
# Save the raw cetk file.
|
||||
cetk = ticket_request.content
|
||||
# Use a Ticket object to load only the Ticket data from cetk and return it.
|
||||
ticket_temp = Ticket()
|
||||
ticket_temp.load(cetk)
|
||||
@ -215,7 +160,7 @@ def download_ticket(title_id: str, wiiu_endpoint: bool = False, endpoint_overrid
|
||||
return ticket
|
||||
|
||||
|
||||
def download_cert_chain(wiiu_endpoint: bool = False, endpoint_override: str | None = None) -> bytes:
|
||||
def download_cert_chain(wiiu_endpoint: bool = False, endpoint_override: str = None) -> bytes:
|
||||
"""
|
||||
Downloads the signing certificate chain used by all WADs. This uses System Menu 4.3U as the source.
|
||||
|
||||
@ -266,8 +211,8 @@ def download_cert_chain(wiiu_endpoint: bool = False, endpoint_override: str | No
|
||||
return cert_chain
|
||||
|
||||
|
||||
def download_content(title_id: str, content_id: int, wiiu_endpoint: bool = False, endpoint_override: str | None = None,
|
||||
progress: DownloadCallback = lambda done, total: None) -> bytes:
|
||||
def 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.
|
||||
|
||||
@ -282,18 +227,11 @@ def download_content(title_id: str, content_id: int, wiiu_endpoint: bool = 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.
|
||||
progress: DownloadCallback, optional
|
||||
A callback function used to return the progress of the download. The provided callable must match the signature
|
||||
defined in DownloadCallback.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bytes
|
||||
The downloaded content.
|
||||
|
||||
See Also
|
||||
--------
|
||||
libWiiPy.title.nus.DownloadCallback
|
||||
"""
|
||||
# Build the download URL. The structure is download/<TID>/<Content ID>.
|
||||
content_id_hex = hex(content_id)[2:]
|
||||
@ -309,29 +247,23 @@ def download_content(title_id: str, content_id: int, wiiu_endpoint: bool = False
|
||||
content_url = endpoint_url + title_id + "/000000" + content_id_hex
|
||||
# Make the request.
|
||||
try:
|
||||
response = requests.get(url=content_url, headers={'User-Agent': 'wii libnup/1.0'}, stream=True)
|
||||
content_request = requests.get(url=content_url, headers={'User-Agent': 'wii libnup/1.0'}, stream=True)
|
||||
except requests.exceptions.ConnectionError:
|
||||
if endpoint_override:
|
||||
raise ValueError("A connection could not be made to the NUS endpoint. Please make sure that your endpoint "
|
||||
"override is valid.")
|
||||
else:
|
||||
raise Exception("A connection could not be made to the NUS endpoint. The NUS may be unavailable.")
|
||||
if response.status_code != 200:
|
||||
if content_request.status_code != 200:
|
||||
raise ValueError("The requested Title ID does not exist, or an invalid Content ID is present in the"
|
||||
" content records provided.\n Failed while downloading Content ID: 000000" +
|
||||
content_id_hex)
|
||||
total_size = int(response.headers["Content-Length"])
|
||||
progress(0, total_size)
|
||||
# Stream the content just like the TMD/Ticket.
|
||||
content = b""
|
||||
for chunk in response.iter_content(chunk_size=1024):
|
||||
content += chunk
|
||||
progress(len(content), total_size)
|
||||
return content
|
||||
content_data = content_request.content
|
||||
return content_data
|
||||
|
||||
|
||||
def download_contents(title_id: str, tmd: TMD, wiiu_endpoint: bool = False, endpoint_override: str | None = None,
|
||||
progress: DownloadCallback = lambda done, total: None) -> List[bytes]:
|
||||
def 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.
|
||||
@ -347,18 +279,11 @@ def download_contents(title_id: str, tmd: TMD, wiiu_endpoint: bool = False, endp
|
||||
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.
|
||||
progress: DownloadCallback, optional
|
||||
A callback function used to return the progress of the downloads. The provided callable must match the signature
|
||||
defined in DownloadCallback.
|
||||
|
||||
Returns
|
||||
-------
|
||||
List[bytes]
|
||||
A list of all the downloaded contents.
|
||||
|
||||
See Also
|
||||
--------
|
||||
libWiiPy.title.nus.DownloadCallback
|
||||
"""
|
||||
# Retrieve the content records from the TMD.
|
||||
content_records = tmd.content_records
|
||||
@ -370,7 +295,7 @@ def download_contents(title_id: str, tmd: TMD, wiiu_endpoint: bool = False, endp
|
||||
content_list = []
|
||||
for content_id in content_ids:
|
||||
# Call self.download_content() for each Content ID.
|
||||
content = download_content(title_id, content_id, wiiu_endpoint, endpoint_override, progress)
|
||||
content = download_content(title_id, content_id, wiiu_endpoint, endpoint_override)
|
||||
content_list.append(content)
|
||||
return content_list
|
||||
|
||||
|
@ -57,7 +57,7 @@ class Ticket:
|
||||
common_key_index : int
|
||||
The index of the common key required to decrypt this ticket's Title Key.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
# If this is a dev ticket
|
||||
self.is_dev: bool = False # Defaults to false, set to true during load if this ticket is using dev certs.
|
||||
# Signature blob header
|
||||
@ -75,7 +75,7 @@ class Ticket:
|
||||
self.title_version: int = 0 # Version of the ticket's associated title.
|
||||
self.permitted_titles: bytes = b'' # Permitted titles mask
|
||||
# "Permit mask. The current disc title is ANDed with the inverse of this mask to see if the result matches the
|
||||
# Permitted Titles Mask." -WiiBrew
|
||||
# Permitted Titles Mask."
|
||||
self.permit_mask: bytes = b''
|
||||
self.title_export_allowed: int = 0 # Whether title export is allowed with a PRNG key or not.
|
||||
self.common_key_index: int = 0 # Which common key should be used. 0 = Common Key, 1 = Korean Key, 2 = vWii Key
|
||||
|
@ -33,7 +33,7 @@ class Title:
|
||||
content: ContentRegion
|
||||
A ContentRegion object containing the title's contents.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.wad: _WAD = _WAD()
|
||||
self.cert_chain: _CertificateChain = _CertificateChain()
|
||||
self.tmd: _TMD = _TMD()
|
||||
@ -178,7 +178,7 @@ class Title:
|
||||
self.tmd.set_title_version(title_version)
|
||||
self.ticket.set_title_version(title_version)
|
||||
|
||||
def get_content_by_index(self, index: int, skip_hash=False) -> bytes:
|
||||
def get_content_by_index(self, index: id, skip_hash=False) -> bytes:
|
||||
"""
|
||||
Gets an individual content from the content region based on the provided index, in decrypted form.
|
||||
|
||||
@ -194,8 +194,6 @@ class Title:
|
||||
bytes
|
||||
The decrypted content listed in the content record.
|
||||
"""
|
||||
if self.ticket.title_id == "":
|
||||
raise ValueError("A Ticket must be loaded to get decrypted content.")
|
||||
dec_content = self.content.get_content_by_index(index, self.ticket.get_title_key(), skip_hash)
|
||||
return dec_content
|
||||
|
||||
@ -215,8 +213,6 @@ class Title:
|
||||
bytes
|
||||
The decrypted content listed in the content record.
|
||||
"""
|
||||
if self.ticket.title_id == "":
|
||||
raise ValueError("A Ticket must be loaded to get decrypted content.")
|
||||
dec_content = self.content.get_content_by_cid(cid, self.ticket.get_title_key(), skip_hash)
|
||||
return dec_content
|
||||
|
||||
@ -321,8 +317,8 @@ class Title:
|
||||
# Update the TMD to match.
|
||||
self.tmd.content_records = self.content.content_records
|
||||
|
||||
def set_enc_content(self, enc_content: bytes, index: int, content_size: int, content_hash: bytes,
|
||||
cid: int | None = None, content_type: int | None = None) -> None:
|
||||
def set_enc_content(self, 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
|
||||
@ -350,8 +346,7 @@ class Title:
|
||||
# Update the TMD to match.
|
||||
self.tmd.content_records = self.content.content_records
|
||||
|
||||
def set_content(self, dec_content: bytes, index: int, cid: int | None = None,
|
||||
content_type: int | None = None) -> None:
|
||||
def set_content(self, 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
|
||||
|
@ -12,7 +12,7 @@ from typing import List
|
||||
from enum import IntEnum as _IntEnum
|
||||
from ..types import _ContentRecord
|
||||
from ..shared import _bitmask
|
||||
from .util import title_ver_standard_to_dec
|
||||
from .util import title_ver_dec_to_standard, title_ver_standard_to_dec
|
||||
|
||||
|
||||
class TMD:
|
||||
@ -34,9 +34,9 @@ class TMD:
|
||||
num_contents : int
|
||||
The number of contents listed in the TMD.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.blob_header: bytes = b''
|
||||
self.signature_type: bytes = b''
|
||||
self.signature_type: int = 0
|
||||
self.signature: bytes = b''
|
||||
self.signature_issuer: str = "" # Follows the format "Root-CA%08x-CP%08x"
|
||||
self.tmd_version: int = 0 # This seems to always be 0 no matter what?
|
||||
@ -55,6 +55,7 @@ class TMD:
|
||||
self.reserved2: bytes = b'' # Other "Reserved" data from WiiBrew.
|
||||
self.access_rights: int = 0
|
||||
self.title_version: int = 0 # The version of the associated title.
|
||||
self.title_version_converted: int = 0 # The title version in vX.X format.
|
||||
self.num_contents: int = 0 # The number of contents contained in the associated title.
|
||||
self.boot_index: int = 0 # The content index that contains the bootable executable.
|
||||
self.minor_version: int = 0 # Minor version (unused typically).
|
||||
@ -136,6 +137,8 @@ class TMD:
|
||||
# Version number straight from the TMD.
|
||||
tmd_data.seek(0x1DC)
|
||||
self.title_version = int.from_bytes(tmd_data.read(2))
|
||||
# Calculate the converted version number via util module.
|
||||
self.title_version_converted = title_ver_dec_to_standard(self.title_version, self.title_id, bool(self.vwii))
|
||||
# The number of contents listed in the TMD.
|
||||
tmd_data.seek(0x1DE)
|
||||
self.num_contents = int.from_bytes(tmd_data.read(2))
|
||||
@ -302,8 +305,6 @@ class TMD:
|
||||
return "None"
|
||||
case 4:
|
||||
return "KOR"
|
||||
case _:
|
||||
raise ValueError(f"Title contains unknown region \"{self.region}\".")
|
||||
|
||||
def get_title_type(self) -> str:
|
||||
"""
|
||||
@ -499,7 +500,7 @@ class TMD:
|
||||
Parameters
|
||||
----------
|
||||
new_version : str, int
|
||||
The new version of the title.
|
||||
The new version of the title. See description for valid formats.
|
||||
"""
|
||||
if type(new_version) is str:
|
||||
# Validate string input is in the correct format, then validate that the version isn't higher than v255.0.
|
||||
@ -509,7 +510,8 @@ class TMD:
|
||||
raise ValueError("Title version is not valid! String version must be entered in format \"X.X\".")
|
||||
if int(version_str_split[0]) > 255 or int(version_str_split[1]) > 255:
|
||||
raise ValueError("Title version is not valid! String version number cannot exceed v255.255.")
|
||||
version_converted: int = title_ver_standard_to_dec(new_version, self.title_id)
|
||||
self.title_version_converted = new_version
|
||||
version_converted = title_ver_standard_to_dec(new_version, self.title_id)
|
||||
self.title_version = version_converted
|
||||
elif type(new_version) is int:
|
||||
# Validate that the version isn't higher than v65280. If the check passes, set that as the title version,
|
||||
@ -517,5 +519,7 @@ class TMD:
|
||||
if new_version > 65535:
|
||||
raise ValueError("Title version is not valid! Integer version number cannot exceed v65535.")
|
||||
self.title_version = new_version
|
||||
version_converted = title_ver_dec_to_standard(new_version, self.title_id, bool(self.vwii))
|
||||
self.title_version_converted = version_converted
|
||||
else:
|
||||
raise TypeError("Title version type is not valid! Type must be either integer or string.")
|
||||
|
@ -29,7 +29,7 @@ class WAD:
|
||||
wad_meta_size : int
|
||||
The size of the WAD's meta/footer.
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
self.wad_hdr_size: int = 64
|
||||
self.wad_type: str = "Is"
|
||||
self.wad_version: bytes = b'\x00\x00'
|
||||
@ -49,17 +49,17 @@ class WAD:
|
||||
self.wad_content_data: bytes = b''
|
||||
self.wad_meta_data: bytes = b''
|
||||
|
||||
def load(self, wad: bytes) -> None:
|
||||
def load(self, 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 : bytes
|
||||
wad_data : bytes
|
||||
The data for the WAD file to load.
|
||||
"""
|
||||
with io.BytesIO(wad) as wad_data:
|
||||
with io.BytesIO(wad_data) as wad_data:
|
||||
# Read the first 8 bytes of the file to ensure that it's a WAD. Has two possible valid values for the two
|
||||
# different types of WADs that might be encountered.
|
||||
wad_data.seek(0x0)
|
||||
@ -311,7 +311,7 @@ class WAD:
|
||||
# Calculate the size of the new Ticket data.
|
||||
self.wad_tik_size = len(tik_data)
|
||||
|
||||
def set_content_data(self, content_data, size: int | None = None) -> None:
|
||||
def set_content_data(self, content_data, size: int = None) -> None:
|
||||
"""
|
||||
Sets the content data of the WAD. Also calculates the new size.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user