diff --git a/isotool.py b/isotool.py index 08f68e9..073dbc3 100644 --- a/isotool.py +++ b/isotool.py @@ -3,11 +3,13 @@ import argparse from pathlib import Path from dataclasses import dataclass +SCRIPT_VERSION = "1.0" @dataclass class FileListData: path: Path inode: int + lba: int @dataclass @@ -17,14 +19,14 @@ class FileListInfo: def main(): - print("pyPS2 ISO Rebuilder") + print(f"pyPS2 ISO Rebuilder v{SCRIPT_VERSION}") print("Original by RaynĂȘ Games") args = get_arguments() if args.mode == "extract": - print("Dumping mode is not (re)implemented yet!") - # dump_iso(args.iso, args.filelist, args.files, args.output) + dump_iso(args.iso, args.filelist, args.files) + print("dumping finished") else: rebuild_iso(args.iso, args.filelist, args.files, args.output, args.with_padding) print("rebuild finished") @@ -99,54 +101,97 @@ def get_arguments(argv=None): return args -def dump_iso( - iso_path: Path, filelist: Path, iso_files: Path, output: Path, add_padding: bool -) -> None: - # curr_file = (file_info *)malloc(24u); - # Both arrays have 6000 elements - # seen_lbas = (int *)malloc(0x5DC0u); - # fdata_arr = (file_data *)malloc(0x188940u); +def dump_iso(iso_path: Path, filelist: Path, iso_files: Path) -> None: - # make path all uppercase - PathName = f"@{iso_path.name}".upper() - Path(PathName).mkdir(parents=True, exist_ok=True) + iso_files.mkdir(parents=True, exist_ok=True) with open(iso_path, "rb") as iso: - # Go to PathTableTypeL and check how many folders are there - # Original just kept going until it found a 0x00 byte, we'll - # trust the PVD about the size of the PathTable and parse each - # field - # - # Also, the original checked that the name was only A-Z 0-9 ' ' and _ - # but didn't bail out or anything, so we'll skip the check and - # assume the folders have valid names - iso.seek(0x8084) - path_table_size = struct.unpack("= record_ends[-1]: + if len(record_ends) == 1: + break + else: + record_ends.pop() + path_parts.pop() + iso.seek(record_pos.pop()) + + inode = iso.tell() + dr_len = struct.unpack(" None: - blk[i] = lba - - -def sub_402D40(FileName: str, iso, lba: int, size: int): - iso.seek(lba * 0x800) - # sub_402B80((unsigned __int8 *)FileName); - Path(FileName).parent.mkdir(parents=True, exist_ok=True) - with open(FileName, "wb+") as f: - f.write(iso.read(size)) - print(FileName) # why here? - - -# Don't even date to look at this in the original program -# it does the following read the size field from back to front -# convert it to string, so 0xDEADBEEF -> "DEADBEEF" -# loop each character and do acc += pow(16.0, pos) * char -# YES with double floats, and then, finally store it -# dunno why size is different when the lba field was just -# normal god fearing byte shifting and casting to int64 -# -# Anyway, Block is an ISO9660 DirectoryRecord -def sub_402350(Block, a3): - a3.byte15 = "2" - a3.lba = struct.unpack_from("