Skip to content

Commit fd26937

Browse files
authored
Merge pull request #12 from braindead-bf/main
Improve error handling for missing function matches (corrupted binexport)
2 parents b25fc89 + e5a763e commit fd26937

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/bindiff/bindiff.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,17 @@ def iter_function_matches(
131131
:return: list of tuple, each containing the primary function, the secondary function and
132132
the FunctionMatch object
133133
"""
134-
return [
135-
(self.primary[match.address1], self.secondary[match.address2], match)
136-
for match in self.primary_functions_match.values()
137-
]
134+
matches = []
135+
for match in self.primary_functions_match.values():
136+
if match.address1 not in self.primary:
137+
logging.error(f"missing primary function match at: {match.address1:#08x}")
138+
elif match.address2 not in self.secondary:
139+
logging.error(f"missing secondary function match at: {match.address1:#08x}")
140+
else:
141+
matches.append(
142+
(self.primary[match.address1], self.secondary[match.address2], match)
143+
)
144+
return matches
138145

139146
def _unmatched_bbs(
140147
self, function: FunctionBinExport, map: dict[int, dict[int, BasicBlockMatch]]
@@ -294,7 +301,7 @@ def raw_diffing(p1_path: Union[Path, str], p2_path: Union[Path, str], out_diff:
294301
if not f1.exists():
295302
logging.error(f"file '{p1_path}' doesn't exist")
296303
return False
297-
304+
298305
if not f2.exists():
299306
logging.error(f"file '{p2_path}' doesn't exist")
300307
return False
@@ -335,8 +342,9 @@ def raw_diffing(p1_path: Union[Path, str], p2_path: Union[Path, str], out_diff:
335342
return True
336343

337344
@staticmethod
338-
def from_binary_files(p1_path: str, p2_path: str, diff_out: str,
339-
override: bool = False) -> Optional["BinDiff"]:
345+
def from_binary_files(
346+
p1_path: str, p2_path: str, diff_out: str, override: bool = False
347+
) -> Optional["BinDiff"]:
340348
"""
341349
Diff two executable files. Thus it export .BinExport files from IDA
342350
and then diff the two resulting files in BinDiff.
@@ -361,7 +369,7 @@ def from_binexport_files(
361369
p1_binexport: Union[ProgramBinExport, str],
362370
p2_binexport: Union[ProgramBinExport, str],
363371
diff_out: str,
364-
override: bool = False
372+
override: bool = False,
365373
) -> Optional["BinDiff"]:
366374
"""
367375
Diff two binexport files. Diff the two binexport files with bindiff

0 commit comments

Comments
 (0)