Added verbose slot/version output to iospatch, allow skipping hashes for emunand

This commit is contained in:
Campbell 2024-08-04 18:05:46 -04:00
parent d9c5940307
commit bc1b6623bb
Signed by: NinjaCheetah
GPG Key ID: 670C282B3291D63D
3 changed files with 14 additions and 5 deletions

View File

@ -32,7 +32,7 @@ class _EmuNANDStructure:
self.wfs_dir.mkdir(exist_ok=True) self.wfs_dir.mkdir(exist_ok=True)
def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Title): def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Title, skip_hash=False):
# Save the upper and lower portions of the Title ID, because these are used as target install directories. # Save the upper and lower portions of the Title ID, because these are used as target install directories.
tid_upper = title.tmd.title_id[:8] tid_upper = title.tmd.title_id[:8]
tid_lower = title.tmd.title_id[8:] tid_lower = title.tmd.title_id[8:]
@ -56,7 +56,8 @@ def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Tit
for content_file in range(0, title.tmd.num_contents): for content_file in range(0, title.tmd.num_contents):
if title.tmd.content_records[content_file].content_type == 1: if title.tmd.content_records[content_file].content_type == 1:
content_file_name = f"{title.tmd.content_records[content_file].content_id:08X}".lower() content_file_name = f"{title.tmd.content_records[content_file].content_id:08X}".lower()
open(content_dir.joinpath(content_file_name + ".app"), "wb").write(title.get_content_by_index(content_file)) open(content_dir.joinpath(content_file_name + ".app"), "wb").write(
title.get_content_by_index(content_file, skip_hash=skip_hash))
title_dir.joinpath("data").mkdir(exist_ok=True) # Empty directory used for save data for the title. title_dir.joinpath("data").mkdir(exist_ok=True) # Empty directory used for save data for the title.
# Shared contents need to be installed to /shared1/, with incremental names determined by /shared1/content.map. # Shared contents need to be installed to /shared1/, with incremental names determined by /shared1/content.map.
@ -72,7 +73,7 @@ def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Tit
if title.tmd.content_records[content_file].content_hash not in existing_hashes: if title.tmd.content_records[content_file].content_hash not in existing_hashes:
content_file_name = content_map.add_content(title.tmd.content_records[content_file].content_hash) content_file_name = content_map.add_content(title.tmd.content_records[content_file].content_hash)
open(emunand_struct.shared1_dir.joinpath(content_file_name + ".app"), "wb").write( open(emunand_struct.shared1_dir.joinpath(content_file_name + ".app"), "wb").write(
title.get_content_by_index(content_file)) title.get_content_by_index(content_file, skip_hash=skip_hash))
open(emunand_struct.shared1_dir.joinpath("content.map"), "wb").write(content_map.dump()) open(emunand_struct.shared1_dir.joinpath("content.map"), "wb").write(content_map.dump())
# The "footer" or meta file is installed as title.met in /meta/<tid_upper>/<tid_lower>/. Only write this if meta # The "footer" or meta file is installed as title.met in /meta/<tid_upper>/<tid_lower>/. Only write this if meta
@ -104,6 +105,10 @@ def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Tit
def handle_emunand_title(args): def handle_emunand_title(args):
emunand_path = pathlib.Path(args.emunand) emunand_path = pathlib.Path(args.emunand)
if args.skip_hash:
skip_hash = True
else:
skip_hash = False
# Code for if the --install argument was passed. # Code for if the --install argument was passed.
if args.install: if args.install:
@ -128,13 +133,13 @@ def handle_emunand_title(args):
for wad in wad_files: for wad in wad_files:
title = libWiiPy.title.Title() title = libWiiPy.title.Title()
title.load_wad(open(wad, "rb").read()) title.load_wad(open(wad, "rb").read())
_do_wad_install(emunand_struct, title) _do_wad_install(emunand_struct, title, skip_hash)
wad_count += 1 wad_count += 1
print(f"Successfully installed {wad_count} WAD(s) to EmuNAND!") print(f"Successfully installed {wad_count} WAD(s) to EmuNAND!")
else: else:
title = libWiiPy.title.Title() title = libWiiPy.title.Title()
title.load_wad(open(input_path, "rb").read()) title.load_wad(open(input_path, "rb").read())
_do_wad_install(emunand_struct, title) _do_wad_install(emunand_struct, title, skip_hash)
print("Successfully installed WAD to EmuNAND!") print("Successfully installed WAD to EmuNAND!")
# Code for if the --uninstall argument was passed. # Code for if the --uninstall argument was passed.

View File

@ -73,12 +73,14 @@ def handle_iospatch(args):
if args.version is not None: if args.version is not None:
title.set_title_version(args.version) title.set_title_version(args.version)
print(f"Title version set to {args.version}!")
if args.slot is not None: if args.slot is not None:
slot = args.slot slot = args.slot
if 3 <= slot <= 255: if 3 <= slot <= 255:
tid = title.tmd.title_id[:-2] + f"{slot:02X}" tid = title.tmd.title_id[:-2] + f"{slot:02X}"
title.set_title_id(tid) title.set_title_id(tid)
print(f"IOS slot set to {slot}!")
ios_patcher = libWiiPy.title.IOSPatcher() ios_patcher = libWiiPy.title.IOSPatcher()
ios_patcher.load(title) ios_patcher.load(title)

View File

@ -52,6 +52,8 @@ if __name__ == "__main__":
emunand_title_install_group.add_argument("--uninstall", metavar="TID", type=str, emunand_title_install_group.add_argument("--uninstall", metavar="TID", type=str,
help="uninstall a title with the provided Title ID from an EmuNAND (also" help="uninstall a title with the provided Title ID from an EmuNAND (also"
"accepts a WAD file to read the TID from)") "accepts a WAD file to read the TID from)")
emunand_title_parser.add_argument("-s", "--skip-hash", help="skips validating the hashes of decrypted "
"content (install only)", action="store_true")
# Argument parser for the fakesign subcommand. # Argument parser for the fakesign subcommand.
fakesign_parser = subparsers.add_parser("fakesign", help="fakesign a TMD, Ticket, or WAD (trucha bug)", fakesign_parser = subparsers.add_parser("fakesign", help="fakesign a TMD, Ticket, or WAD (trucha bug)",