Skip to content

Commit

Permalink
Name of target binary is not always identical to the annotation id
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Dec 19, 2024
1 parent 4e71b48 commit c099a37
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
6 changes: 5 additions & 1 deletion reccmp/ghidra_scripts/import_functions_and_types_from_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ def main():
raise ValueError

isle_compare = IsleCompare(
origfile, recompfile, target.recompiled_pdb, target.source_root
origfile,
recompfile,
target.recompiled_pdb,
target.source_root,
target_id=target.target_id,
)

logger.info("Comparison complete.")
Expand Down
14 changes: 10 additions & 4 deletions reccmp/isledecomp/compare/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,20 @@ def __init__(
recomp_bin: PEImage,
pdb_file: Path | str,
code_dir: Path | str,
target_id: str = None,
):
self.orig_bin = orig_bin
self.recomp_bin = recomp_bin
self.pdb_file = str(pdb_file)
self.code_dir = str(code_dir)
self.target_id = target_id
if self.target_id is None:
# Assume module name is the base filename of the original binary.
self.target_id, _ = os.path.splitext(
os.path.basename(self.orig_bin.filepath)
)
self.target_id = self.target_id.upper()
logger.warning('Assuming id="%s"', self.target_id)
# Controls whether we dump the asm output to a file
self.debug: bool = False
self.runid: str = uuid.uuid4().hex[:8]
Expand Down Expand Up @@ -206,11 +215,8 @@ def _load_cvdump(self):
self._db.set_function_pair(self.orig_bin.entry, self.recomp_bin.entry)

def _load_markers(self):
# Assume module name is the base filename of the original binary.
(module, _) = os.path.splitext(os.path.basename(self.orig_bin.filepath))

codefiles = list(walk_source_dir(self.code_dir))
codebase = DecompCodebase(codefiles, module.upper())
codebase = DecompCodebase(codefiles, self.target_id)

def orig_bin_checker(addr: int) -> bool:
return self.orig_bin.is_valid_vaddr(addr)
Expand Down
6 changes: 5 additions & 1 deletion reccmp/tools/asmcmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ def main():
logging.getLogger("isledecomp.compare.lines").setLevel(logging.CRITICAL)

isle_compare = IsleCompare(
origfile, recompfile, target.recompiled_pdb, target.source_root
origfile,
recompfile,
target.recompiled_pdb,
target.source_root,
target_id=target.target_id,
)

if args.loglevel == logging.DEBUG:
Expand Down
1 change: 1 addition & 0 deletions reccmp/tools/datacmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def do_the_comparison(target: RecCmpBuiltTarget) -> Iterable[ComparisonItem]:
recompfile,
target.recompiled_pdb,
target.source_root,
target_id=target.target_id,
)

# TODO: We don't currently retain the type information of each variable
Expand Down
6 changes: 5 additions & 1 deletion reccmp/tools/roadmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ def main() -> int:
assert isinstance(recomp_bin, PEImage)

engine = IsleCompare(
orig_bin, recomp_bin, target.recompiled_pdb, target.source_root
orig_bin,
recomp_bin,
target.recompiled_pdb,
target.source_root,
target_id=target.target_id,
)

module_map = ModuleMap(target.recompiled_pdb, recomp_bin)
Expand Down
6 changes: 5 additions & 1 deletion reccmp/tools/stackcmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ def main():
raise ValueError(f"{target.recompiled_path} is not a PE executable")

isle_compare = IsleCompare(
origfile, recompfile, target.recompiled_pdb, target.source_root
origfile,
recompfile,
target.recompiled_pdb,
target.source_root,
target_id=target.target_id,
)
if args.loglevel == logging.DEBUG:
isle_compare.debug = True
Expand Down
6 changes: 5 additions & 1 deletion reccmp/tools/vtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def main():
recomp_bin = detect_image(target.recompiled_path)
assert isinstance(recomp_bin, PEImage)
engine = IsleCompare(
orig_bin, recomp_bin, target.recompiled_pdb, target.source_root
orig_bin,
recomp_bin,
target.recompiled_pdb,
target.source_root,
target_id=target.target_id,
)

for tbl_match in engine.compare_vtables():
Expand Down

0 comments on commit c099a37

Please sign in to comment.