mirror of
https://github.com/isledecomp/isle.git
synced 2026-02-03 05:31:17 +00:00
Use isledecomp lib in reccmp
This commit is contained in:
parent
0fa6d207f8
commit
6a1e05c270
@ -7,11 +7,15 @@ def file_is_cpp(filename: str) -> bool:
|
|||||||
return ext.lower() in ('.h', '.cpp')
|
return ext.lower() in ('.h', '.cpp')
|
||||||
|
|
||||||
|
|
||||||
def walk_source_dir(source: str) -> Iterator[str]:
|
def walk_source_dir(source: str, recursive: bool = True) -> Iterator[str]:
|
||||||
"""Generator to walk the given directory recursively and return
|
"""Generator to walk the given directory recursively and return
|
||||||
any C++ files found."""
|
any C++ files found."""
|
||||||
|
|
||||||
|
source = os.path.abspath(source)
|
||||||
for subdir, dirs, files in os.walk(source):
|
for subdir, dirs, files in os.walk(source):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file_is_cpp(file):
|
if file_is_cpp(file):
|
||||||
yield os.path.join(subdir, file)
|
yield os.path.join(subdir, file)
|
||||||
|
|
||||||
|
if not recursive:
|
||||||
|
break
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
import colorama
|
import colorama
|
||||||
import html
|
import html
|
||||||
import re
|
import re
|
||||||
|
from isledecomp.dir import walk_source_dir
|
||||||
|
from isledecomp.parser import find_code_blocks
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(allow_abbrev=False,
|
parser = argparse.ArgumentParser(allow_abbrev=False,
|
||||||
description='Recompilation Compare: compare an original EXE with a recompiled EXE + PDB.')
|
description='Recompilation Compare: compare an original EXE with a recompiled EXE + PDB.')
|
||||||
@ -414,30 +416,18 @@ def can_resolve_register_differences(original_asm, new_asm):
|
|||||||
basename = os.path.basename(os.path.splitext(original)[0])
|
basename = os.path.basename(os.path.splitext(original)[0])
|
||||||
pattern = '// OFFSET:'
|
pattern = '// OFFSET:'
|
||||||
|
|
||||||
for subdir, dirs, files in os.walk(source):
|
for srcfilename in walk_source_dir(source):
|
||||||
for file in files:
|
|
||||||
srcfilename = os.path.join(os.path.abspath(subdir), file)
|
|
||||||
with open(srcfilename, 'r') as srcfile:
|
with open(srcfilename, 'r') as srcfile:
|
||||||
line_no = 0
|
blocks = find_code_blocks(srcfile)
|
||||||
|
|
||||||
while True:
|
for block in blocks:
|
||||||
try:
|
if block.is_stub:
|
||||||
line = srcfile.readline()
|
|
||||||
line_no += 1
|
|
||||||
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
|
|
||||||
line = line.strip()
|
|
||||||
|
|
||||||
if line.startswith(pattern) and not line.endswith('STUB'):
|
|
||||||
par = line[len(pattern):].strip().split()
|
|
||||||
module = par[0]
|
|
||||||
if module != basename:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
addr = int(par[1], 16)
|
if block.module != basename:
|
||||||
|
continue
|
||||||
|
|
||||||
|
addr = block.offset
|
||||||
# Verbose flag handling
|
# Verbose flag handling
|
||||||
if verbose:
|
if verbose:
|
||||||
if addr == verbose:
|
if addr == verbose:
|
||||||
@ -445,22 +435,12 @@ def can_resolve_register_differences(original_asm, new_asm):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if line.endswith('TEMPLATE'):
|
if block.is_template:
|
||||||
line = srcfile.readline()
|
recinfo = syminfo.get_recompiled_address_from_name(block.signature)
|
||||||
line_no += 1
|
|
||||||
# Name comes after // comment
|
|
||||||
name = line.strip()[2:].strip()
|
|
||||||
|
|
||||||
recinfo = syminfo.get_recompiled_address_from_name(name)
|
|
||||||
if not recinfo:
|
if not recinfo:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
find_open_bracket = line
|
recinfo = syminfo.get_recompiled_address(srcfilename, block.start_line)
|
||||||
while '{' not in find_open_bracket:
|
|
||||||
find_open_bracket = srcfile.readline()
|
|
||||||
line_no += 1
|
|
||||||
|
|
||||||
recinfo = syminfo.get_recompiled_address(srcfilename, line_no)
|
|
||||||
if not recinfo:
|
if not recinfo:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -549,8 +529,6 @@ def can_resolve_register_differences(original_asm, new_asm):
|
|||||||
escaped = html.escape('\\n'.join(udiff).replace('"', '\\"').replace('\n', '\\n'))
|
escaped = html.escape('\\n'.join(udiff).replace('"', '\\"').replace('\n', '\\n'))
|
||||||
htmlinsert.append(f'{{address: "0x{addr:x}", name: "{html.escape(recinfo.name)}", matching: {effective_ratio}, diff: "{escaped}"}}')
|
htmlinsert.append(f'{{address: "0x{addr:x}", name: "{html.escape(recinfo.name)}", matching: {effective_ratio}, diff: "{escaped}"}}')
|
||||||
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
break
|
|
||||||
|
|
||||||
def gen_html(html_path, data):
|
def gen_html(html_path, data):
|
||||||
templatedata = None
|
templatedata = None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user