diff --git a/generate_act_format.py b/generate_act_format.py index 4104159..db0d2d8 100644 --- a/generate_act_format.py +++ b/generate_act_format.py @@ -31,22 +31,11 @@ desired_names = { } -@click.command() -@click.argument("opcodes_file", type=click.File("r")) -def generate_act_format(opcodes_file): - """ - Parses an OPCODES_FILE and outputs opcodes in a format expected by ACT. - This is also just a bunch of regexes slapped together. - - Outputs to stdout. - - Example: - - python generate_act_format.py Ipcs.h - """ +def write_act_format(opcodes_lines): + output_lines = [] opcode_mapping = dict() - for line in opcodes_file.readlines(): + for line in opcodes_lines: match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line) if len(match_groups) != 1: continue @@ -66,11 +55,31 @@ def generate_act_format(opcodes_file): desired = name opcodes = opcode_mapping[name] if len(opcodes) == 1: - print(f"{desired}|{opcodes[0]:x}") + output_lines.append(f"{desired}|{opcodes[0]:x}") elif len(opcodes) > 1: - print(f'{desired}|{[f"{opcode:x}" for opcode in opcodes]}') + output_lines.append(f'{desired}|{[f"{opcode:x}" for opcode in opcodes]}') else: - print(f"{desired}|???") + output_lines.append(f"{desired}|???") + + return output_lines + + +@click.command() +@click.argument("opcodes_file", type=click.File("r")) +def generate_act_format(opcodes_file): + """ + Parses an OPCODES_FILE and outputs opcodes in a format expected by ACT. + This is also just a bunch of regexes slapped together. + + Outputs to stdout. + + Example: + + python generate_act_format.py Ipcs.h + """ + lines = write_act_format(opcodes_file.readlines()) + for line in lines: + print(line) if __name__ == "__main__": diff --git a/vtable_diff.py b/vtable_diff.py index 690922a..54664b4 100644 --- a/vtable_diff.py +++ b/vtable_diff.py @@ -78,6 +78,29 @@ def find_opcode_matches(old_opcodes_db, new_opcodes_db): return matches +def diff_exes(old_exe, new_exe): + old_opcodes_db = extract_opcode_data(old_exe) + new_opcodes_db = extract_opcode_data(new_exe) + + if len(old_opcodes_db) != len(new_opcodes_db): + eprint( + f"WARNING: vtables have different sizes: {len(old_opcodes_db)} != {len(new_opcodes_db)}. Matches may not be correct." + ) + + opcodes_found = find_opcode_matches(old_opcodes_db, new_opcodes_db) + opcodes_object = [] + + for old, new in opcodes_found: + opcodes_object.append( + { + "old": [hex(old)], + "new": [hex(new)], + } + ) + + return opcodes_object + + @click.command() @click.argument( "old_exe", type=click.Path(exists=True, dir_okay=False, resolve_path=True) @@ -106,25 +129,7 @@ def vtable_diff(old_exe, new_exe): python vtable_diff.py ffxiv_dx11.old.exe ffxiv_dx11.new.exe > diff.json """ - old_opcodes_db = extract_opcode_data(old_exe) - new_opcodes_db = extract_opcode_data(new_exe) - - if len(old_opcodes_db) != len(new_opcodes_db): - eprint( - f"WARNING: vtables have different sizes: {len(old_opcodes_db)} != {len(new_opcodes_db)}. Matches may not be correct." - ) - - opcodes_found = find_opcode_matches(old_opcodes_db, new_opcodes_db) - opcodes_object = [] - - for old, new in opcodes_found: - opcodes_object.append( - { - "old": [hex(old)], - "new": [hex(new)], - } - ) - + opcodes_object = diff_exes(old_exe, new_exe) print(json.dumps(opcodes_object, indent=2))