From 4e2f7b14e7578149fd5a3c5d41b2f9353c1744fd Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:16:08 -0400 Subject: [PATCH] Add option to skip hash checks when unpacking WAD --- modules/title/wad.py | 26 +++++++++++++------------- wiipy.py | 8 ++++++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/title/wad.py b/modules/title/wad.py index 480e267..aae5a63 100644 --- a/modules/title/wad.py +++ b/modules/title/wad.py @@ -70,22 +70,16 @@ def handle_wad(args): # Method to ensure that the title's content records match between the TMD() and ContentRegion() objects. title.load_content_records() + # Iterate over every file in the content_files list, and set them in the Title(). + for record in title.content.content_records: + index = title.content.content_records.index(record) + dec_content = open(content_files[index], "rb").read() + title.set_content(dec_content, index) + # Fakesign the TMD and Ticket using the trucha bug, if enabled. This is built-in in libWiiPy v0.4.1+. if args.fakesign: title.fakesign() - # Iterate over every file in the content_files list, and attempt to load it into the Title(). - for index in range(len(title.content.content_records)): - for content in range(len(content_files)): - dec_content = open(content_files[content], "rb").read() - try: - # Attempt to load the content into the correct index. - title.load_content(dec_content, index) - break - except ValueError: - # Wasn't the right content, so try again. - pass - output_path.write(title.dump_wad()) print("WAD file packed!") @@ -128,10 +122,16 @@ def handle_wad(args): meta_out.write(title.wad.get_meta_data()) meta_out.close() + # Skip validating hashes if -s/--skip-hash was passed. + if args.skip_hash: + skip_hash = True + else: + skip_hash = False + for content_file in range(0, title.tmd.num_contents): content_file_name = "000000" + str(binascii.hexlify(content_file.to_bytes()).decode()) + ".app" content_out = open(output_path.joinpath(content_file_name), "wb") - content_out.write(title.get_content_by_index(content_file)) + content_out.write(title.get_content_by_index(content_file, skip_hash)) content_out.close() print("WAD file unpacked!") diff --git a/wiipy.py b/wiipy.py index ead8f6b..60f439d 100644 --- a/wiipy.py +++ b/wiipy.py @@ -90,8 +90,12 @@ if __name__ == "__main__": wad_group.add_argument("-u", "--unpack", help="unpack a WAD file to a directory", action="store_true") wad_parser.add_argument("input", metavar="IN", type=str, help="input file") wad_parser.add_argument("output", metavar="OUT", type=str, help="output file") - wad_parser.add_argument("--fakesign", help="fakesign the TMD and Ticket (trucha bug)", - action="store_true") + wad_pack_group = wad_parser.add_argument_group(title="packing options") + wad_pack_group.add_argument("-f", "--fakesign", help="fakesign the TMD and Ticket (trucha bug)", + action="store_true") + wad_unpack_group = wad_parser.add_argument_group(title="unpacking options") + wad_unpack_group.add_argument("-s", "--skip-hash", help="skips validating the hashes of decrypted " + "content", action="store_true") # Parse all the args, and call the appropriate function with all of those args if a valid subcommand was passed. args = parser.parse_args()