@@ -326,44 +326,52 @@ def raw_diffing(p1_path: Union[Path, str], p2_path: Union[Path, str], out_diff:
326326 return True
327327
328328 @staticmethod
329- def from_binary_files (p1_path : str , p2_path : str , diff_out : str ) -> Optional ["BinDiff" ]:
329+ def from_binary_files (p1_path : str , p2_path : str , diff_out : str ,
330+ override : bool = False ) -> Optional ["BinDiff" ]:
330331 """
331332 Diff two executable files. Thus it export .BinExport files from IDA
332333 and then diff the two resulting files in BinDiff.
333334
334335 :param p1_path: primary binary file to diff
335336 :param p2_path: secondary binary file to diff
336337 :param diff_out: output file for the diff
338+ :param override: override Binexports files and diffing
337339 :return: BinDiff object representing the diff
338340 """
339341
340- p1 = ProgramBinExport .from_binary_file (p1_path )
341- p2 = ProgramBinExport .from_binary_file (p2_path )
342- p1_binexport = Path (f"{ p1_path } .BinExport" )
343- p2_binexport = Path (f"{ p2_path } .BinExport" )
342+ p1 = ProgramBinExport .from_binary_file (p1_path , override = override )
343+ p2 = ProgramBinExport .from_binary_file (p2_path , override = override )
344344 if p1 and p2 :
345- retcode = BinDiff .raw_diffing (p1_binexport , p2_binexport , diff_out )
346- return BinDiff (p1 , p2 , diff_out ) if retcode else None
345+ return BinDiff .from_binexport_files (p1 , p2 , diff_out , override = override )
347346 else :
348347 logging .error ("p1 or p2 could not have been 'binexported'" )
349348 return None
350349
351350 @staticmethod
352351 def from_binexport_files (
353- p1_binexport : str , p2_binexport : str , diff_out : str
352+ p1_binexport : Union [ProgramBinExport , str ],
353+ p2_binexport : Union [ProgramBinExport , str ],
354+ diff_out : str ,
355+ override : bool = False
354356 ) -> Optional ["BinDiff" ]:
355357 """
356358 Diff two binexport files. Diff the two binexport files with bindiff
357359 and then load a BinDiff instance.
358360
359- :param p1_binexport: primary binexport file to diff
360- :param p2_binexport: secondary binexport file to diff
361+ :param p1_binexport: primary binexport file to diff (path or object)
362+ :param p2_binexport: secondary binexport file to diff (path or object)
361363 :param diff_out: output file for the diff
364+ :param override: override Binexports files and diffing
362365 :return: BinDiff object representing the diff
363366 """
367+ p1_path = p1_binexport .path if isinstance (p1_binexport , ProgramBinExport ) else p1_binexport
368+ p2_path = p2_binexport .path if isinstance (p2_binexport , ProgramBinExport ) else p2_binexport
364369
365- retcode = BinDiff .raw_diffing (p1_binexport , p2_binexport , diff_out )
366- return BinDiff (p1_binexport , p2_binexport , diff_out ) if retcode else None
370+ if not Path (diff_out ).exists () or override :
371+ retcode = BinDiff .raw_diffing (p1_path , p2_path , diff_out )
372+ return BinDiff (p1_binexport , p2_binexport , diff_out ) if retcode else None
373+ else :
374+ return BinDiff (p1_binexport , p2_binexport , diff_out )
367375
368376 @staticmethod
369377 def _configure_bindiff_path () -> None :
0 commit comments