Skip to content

Commit 07e6e6c

Browse files
committed
Slight refactoring
1 parent e48db26 commit 07e6e6c

File tree

2 files changed

+50
-36
lines changed

2 files changed

+50
-36
lines changed

generate_act_format.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,11 @@
3131
}
3232

3333

34-
@click.command()
35-
@click.argument("opcodes_file", type=click.File("r"))
36-
def generate_act_format(opcodes_file):
37-
"""
38-
Parses an OPCODES_FILE and outputs opcodes in a format expected by ACT.
39-
This is also just a bunch of regexes slapped together.
40-
41-
Outputs to stdout.
42-
43-
Example:
44-
45-
python generate_act_format.py Ipcs.h
46-
"""
34+
def write_act_format(opcodes_lines):
35+
output_lines = []
4736
opcode_mapping = dict()
4837

49-
for line in opcodes_file.readlines():
38+
for line in opcodes_lines:
5039
match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line)
5140
if len(match_groups) != 1:
5241
continue
@@ -66,11 +55,31 @@ def generate_act_format(opcodes_file):
6655
desired = name
6756
opcodes = opcode_mapping[name]
6857
if len(opcodes) == 1:
69-
print(f"{desired}|{opcodes[0]:x}")
58+
output_lines.append(f"{desired}|{opcodes[0]:x}")
7059
elif len(opcodes) > 1:
71-
print(f'{desired}|{[f"{opcode:x}" for opcode in opcodes]}')
60+
output_lines.append(f'{desired}|{[f"{opcode:x}" for opcode in opcodes]}')
7261
else:
73-
print(f"{desired}|???")
62+
output_lines.append(f"{desired}|???")
63+
64+
return output_lines
65+
66+
67+
@click.command()
68+
@click.argument("opcodes_file", type=click.File("r"))
69+
def generate_act_format(opcodes_file):
70+
"""
71+
Parses an OPCODES_FILE and outputs opcodes in a format expected by ACT.
72+
This is also just a bunch of regexes slapped together.
73+
74+
Outputs to stdout.
75+
76+
Example:
77+
78+
python generate_act_format.py Ipcs.h
79+
"""
80+
lines = write_act_format(opcodes_file.readlines())
81+
for line in lines:
82+
print(line)
7483

7584

7685
if __name__ == "__main__":

vtable_diff.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ def find_opcode_matches(old_opcodes_db, new_opcodes_db):
7878
return matches
7979

8080

81+
def diff_exes(old_exe, new_exe):
82+
old_opcodes_db = extract_opcode_data(old_exe)
83+
new_opcodes_db = extract_opcode_data(new_exe)
84+
85+
if len(old_opcodes_db) != len(new_opcodes_db):
86+
eprint(
87+
f"WARNING: vtables have different sizes: {len(old_opcodes_db)} != {len(new_opcodes_db)}. Matches may not be correct."
88+
)
89+
90+
opcodes_found = find_opcode_matches(old_opcodes_db, new_opcodes_db)
91+
opcodes_object = []
92+
93+
for old, new in opcodes_found:
94+
opcodes_object.append(
95+
{
96+
"old": [hex(old)],
97+
"new": [hex(new)],
98+
}
99+
)
100+
101+
return opcodes_object
102+
103+
81104
@click.command()
82105
@click.argument(
83106
"old_exe", type=click.Path(exists=True, dir_okay=False, resolve_path=True)
@@ -106,25 +129,7 @@ def vtable_diff(old_exe, new_exe):
106129
107130
python vtable_diff.py ffxiv_dx11.old.exe ffxiv_dx11.new.exe > diff.json
108131
"""
109-
old_opcodes_db = extract_opcode_data(old_exe)
110-
new_opcodes_db = extract_opcode_data(new_exe)
111-
112-
if len(old_opcodes_db) != len(new_opcodes_db):
113-
eprint(
114-
f"WARNING: vtables have different sizes: {len(old_opcodes_db)} != {len(new_opcodes_db)}. Matches may not be correct."
115-
)
116-
117-
opcodes_found = find_opcode_matches(old_opcodes_db, new_opcodes_db)
118-
opcodes_object = []
119-
120-
for old, new in opcodes_found:
121-
opcodes_object.append(
122-
{
123-
"old": [hex(old)],
124-
"new": [hex(new)],
125-
}
126-
)
127-
132+
opcodes_object = diff_exes(old_exe, new_exe)
128133
print(json.dumps(opcodes_object, indent=2))
129134

130135

0 commit comments

Comments
 (0)