From 38a316f09ac11ea02a048748d2e848fc5296b123 Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:22:12 -0500 Subject: [PATCH 1/2] Added more minor functions to tmd.py --- src/libWiiPy/tmd.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libWiiPy/tmd.py b/src/libWiiPy/tmd.py index e65615b..7312ecd 100644 --- a/src/libWiiPy/tmd.py +++ b/src/libWiiPy/tmd.py @@ -23,7 +23,7 @@ class TMD: self.sig_type: int self.sig: bytearray self.issuer: bytearray # Follows the format "Root-CA%08x-CP%08x" - self.version: bytearray # This seems to always be 0 no matter what? + self.version: int # This seems to always be 0 no matter what? self.ca_crl_version: int self.signer_crl_version: int self.vwii: int @@ -44,9 +44,9 @@ class TMD: # Signing certificate issuer tmdfile.seek(0x140) self.issuer = tmdfile.read(64) - # TMD version, always seems to be 0? + # TMD version, seems to usually be 0, but I've seen references to other numbers tmdfile.seek(0x180) - self.version = tmdfile.read(1) + self.version = int.from_bytes(tmdfile.read(1)) # TODO: label tmdfile.seek(0x181) self.ca_crl_version = tmdfile.read(1) @@ -94,7 +94,7 @@ class TMD: self.title_version = title_version_high + title_version_low # The number of contents listed in the TMD tmdfile.seek(0x1DE) - self.num_contents = tmdfile.read(2) + self.num_contents = int.from_bytes(tmdfile.read(2)) # Content index in content list that contains the boot file tmdfile.seek(0x1E0) self.boot_index = tmdfile.read(2) @@ -128,6 +128,10 @@ class TMD: else: return False + def get_tmd_version(self): + """Returns the version of the TMD.""" + return self.version + def get_required_ios_tid(self): """Returns the TID of the required IOS for the title.""" return self.ios_tid @@ -154,3 +158,7 @@ class TMD: return "DLC" case '00010008': return "HiddenChannel" + + def get_num_contents(self): + """Returns the number of contents listed in the TMD.""" + return self.num_contents From 0a275e3d15ab88ba1ad8c71ceb38f4b1f6df7537 Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:43:43 -0500 Subject: [PATCH 2/2] Added function to get content type --- src/libWiiPy/tmd.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libWiiPy/tmd.py b/src/libWiiPy/tmd.py index 7312ecd..fc3e22c 100644 --- a/src/libWiiPy/tmd.py +++ b/src/libWiiPy/tmd.py @@ -30,7 +30,7 @@ class TMD: self.ios_tid: str self.ios_version: int self.title_id: str - self.title_type: str + self.content_type: str self.group_id: int # Publisher of the title self.region: int self.ratings: int @@ -68,11 +68,11 @@ class TMD: title_id_bin = tmdfile.read(8) title_id_hex = binascii.hexlify(title_id_bin) self.title_id = str(title_id_hex.decode()) - # Type of title + # Type of content tmdfile.seek(0x194) - title_type_bin = tmdfile.read(4) - title_type_hex = binascii.hexlify(title_type_bin) - self.title_type = str(title_type_hex.decode()) + content_type_bin = tmdfile.read(4) + content_type_hex = binascii.hexlify(content_type_bin) + self.content_type = str(content_type_hex.decode()) # Publisher of the title tmdfile.seek(0x198) self.group_id = tmdfile.read(2) @@ -158,6 +158,24 @@ class TMD: return "DLC" case '00010008': return "HiddenChannel" + case _: + return "Unknown" + + def get_content_type(self): + """Returns the type of content contained in the TMD's associated title.""" + match self.content_type: + case '00000001': + return "Normal" + case '00000002': + return "Development/Unknown" + case '00000003': + return "Hash Tree" + case '00004001': + return "DLC" + case '00008001': + return "Shared" + case _: + return "Unknown" def get_num_contents(self): """Returns the number of contents listed in the TMD."""