From fb87c2c58ccfb468e87f83c1436de2c00a2ac4d3 Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Sat, 3 Aug 2024 14:01:09 -0400 Subject: [PATCH] Added methods to check if a TMD, Ticket, and Title are fakesigned --- src/libWiiPy/title/ticket.py | 23 ++++++++++++++++++++++- src/libWiiPy/title/title.py | 19 +++++++++++++++++++ src/libWiiPy/title/tmd.py | 23 ++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/libWiiPy/title/ticket.py b/src/libWiiPy/title/ticket.py index 7f8ce13..8266bb7 100644 --- a/src/libWiiPy/title/ticket.py +++ b/src/libWiiPy/title/ticket.py @@ -252,6 +252,27 @@ class Ticket: except OverflowError: raise Exception("An error occurred during fakesigning. Ticket could not be fakesigned!") + def get_is_fakesigned(self) -> bool: + """ + Checks the Ticket object to see if it is currently fakesigned. For a description of fakesigning, refer to the + fakesign() method. + + Returns + ------- + bool: + True if the Ticket is fakesigned, False otherwise. + + See Also + -------- + libWiiPy.title.ticket.Ticket.fakesign() + """ + if self.signature != b'\x00' * 256: + return False + test_hash = hashlib.sha1(self.dump()[320:]).hexdigest() + if test_hash[:2] != '00': + return False + return True + def get_title_id(self) -> str: """ Gets the Title ID of the ticket's associated title. @@ -275,7 +296,7 @@ class Ticket: See Also -------- - commonkeys.get_common_key + libWiiPy.title.commonkeys.get_common_key """ match self.common_key_index: case 0: diff --git a/src/libWiiPy/title/title.py b/src/libWiiPy/title/title.py index a058592..9f5b5e6 100644 --- a/src/libWiiPy/title/title.py +++ b/src/libWiiPy/title/title.py @@ -316,3 +316,22 @@ class Title: """ self.tmd.fakesign() self.ticket.fakesign() + + def get_is_fakesigned(self): + """ + 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 + ------- + bool: + True if the Title is fakesigned, False otherwise. + + See Also + -------- + libWiiPy.title.title.Title.fakesign() + """ + if self.tmd.get_is_fakesigned and self.ticket.get_is_fakesigned(): + return True + else: + return False diff --git a/src/libWiiPy/title/tmd.py b/src/libWiiPy/title/tmd.py index 26a666b..65b4a47 100644 --- a/src/libWiiPy/title/tmd.py +++ b/src/libWiiPy/title/tmd.py @@ -257,6 +257,27 @@ class TMD: except OverflowError: raise Exception("An error occurred during fakesigning. TMD could not be fakesigned!") + def get_is_fakesigned(self) -> bool: + """ + Checks the TMD object to see if it is currently fakesigned. For a description of fakesigning, refer to the + fakesign() method. + + Returns + ------- + bool: + True if the TMD is fakesigned, False otherwise. + + See Also + -------- + libWiiPy.title.tmd.TMD.fakesign() + """ + if self.signature != b'\x00' * 256: + return False + test_hash = hashlib.sha1(self.dump()[320:]).hexdigest() + if test_hash[:2] != '00': + return False + return True + def get_title_region(self) -> str: """ Gets the region of the TMD's associated title. @@ -386,7 +407,7 @@ class TMD: Returns ------- bool - Whether the flag is enabled. + True if the flag is enabled, False otherwise. """ return bool(self.access_rights & _bitmask(flag))