Skip to content

Commit

Permalink
[Binexport] Add optional executable path
Browse files Browse the repository at this point in the history
  • Loading branch information
patacca committed Sep 9, 2024
1 parent 98af48d commit 5d0d383
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/qbindiff/loader/backend/binexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def __init__(self, file: str, *, arch: str | None = None):

self.be_prog = binexport.ProgramBinExport(file)
self.architecture_name = self.be_prog.architecture
self._exec_path: str | None = exec_path
self._fun_names: dict[str, Addr] = {} # {fun_name : fun_address}
self.cs = None

Expand Down Expand Up @@ -488,9 +489,12 @@ def fun_names(self) -> dict[str, int]:
@property
def exec_path(self) -> str:
"""
Guess the raw binary name by removing the final .BinExport
Returns the executable path if it has been provided, otherwise try to guess it
by removing the final .BinExport suffix
"""
return self.name.replace(".BinExport", "")
if self._exec_path:
return self._exec_path
return self.name.replace(".BinExport", "") # Try to guess it as best effort

@property
def capabilities(self) -> ProgramCapability:
Expand Down
5 changes: 3 additions & 2 deletions src/qbindiff/loader/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(
self._load_functions()

@staticmethod
def from_binexport(file_path: str, arch: str | None = None) -> Program:
def from_binexport(file_path: str, arch: str | None = None, exec_path: str | None = None) -> Program:
"""
Load the Program using the binexport backend
Expand All @@ -114,10 +114,11 @@ def from_binexport(file_path: str, arch: str | None = None) -> Program:
useful when the binexport'ed architecture is not enough to
correctly disassemble the binary (for example with arm
thumb2 or some mips modes).
:param exec_path: Optional path to raw executable binary
:return: Program instance
"""

return Program(file_path, arch=arch, loader=LoaderType.binexport)
return Program(file_path, arch=arch, exec_path=exec_path, loader=LoaderType.binexport)

@staticmethod
def from_quokka(file_path: str, exec_path: str) -> Program:
Expand Down

0 comments on commit 5d0d383

Please sign in to comment.