Slight refactoring

This commit is contained in:
Flawed
2023-11-05 21:07:04 -08:00
parent e48db26870
commit 07e6e6cf26
2 changed files with 50 additions and 36 deletions
+26 -17
View File
@@ -31,22 +31,11 @@ desired_names = {
} }
@click.command() def write_act_format(opcodes_lines):
@click.argument("opcodes_file", type=click.File("r")) output_lines = []
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
"""
opcode_mapping = dict() opcode_mapping = dict()
for line in opcodes_file.readlines(): for line in opcodes_lines:
match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line) match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line)
if len(match_groups) != 1: if len(match_groups) != 1:
continue continue
@@ -66,11 +55,31 @@ def generate_act_format(opcodes_file):
desired = name desired = name
opcodes = opcode_mapping[name] opcodes = opcode_mapping[name]
if len(opcodes) == 1: if len(opcodes) == 1:
print(f"{desired}|{opcodes[0]:x}") output_lines.append(f"{desired}|{opcodes[0]:x}")
elif len(opcodes) > 1: 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: 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__": if __name__ == "__main__":
+24 -19
View File
@@ -78,6 +78,29 @@ def find_opcode_matches(old_opcodes_db, new_opcodes_db):
return matches 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.command()
@click.argument( @click.argument(
"old_exe", type=click.Path(exists=True, dir_okay=False, resolve_path=True) "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 python vtable_diff.py ffxiv_dx11.old.exe ffxiv_dx11.new.exe > diff.json
""" """
old_opcodes_db = extract_opcode_data(old_exe) opcodes_object = diff_exes(old_exe, new_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)],
}
)
print(json.dumps(opcodes_object, indent=2)) print(json.dumps(opcodes_object, indent=2))