Skip to content

Commit 66af6ee

Browse files
authored
Merge pull request #69 from quarkslab/fix-filename-bindiff-db
Update qbindiff (export_path) and failsafe InstructionGroup
2 parents 0ecbc99 + 2d7be4b commit 66af6ee

File tree

8 files changed

+55
-10
lines changed

8 files changed

+55
-10
lines changed

src/qbindiff/__main__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def load_program(
233233
default=DEFAULT_FEATURES,
234234
multiple=True,
235235
metavar="<feature>",
236+
show_default=True,
236237
help=help_features,
237238
)
238239
@click.option(
@@ -420,6 +421,11 @@ def main(
420421
)
421422
return 1
422423

424+
if not features:
425+
logging.error("no feature provided")
426+
return 1
427+
428+
423429
with Progress() as progress:
424430
if not quiet:
425431
load_bar_total = 2
@@ -456,10 +462,6 @@ def main(
456462
logging.error(e)
457463
exit(1)
458464

459-
if not features:
460-
logging.error("no feature provided")
461-
exit(1)
462-
463465
try:
464466
# Check for the 'all' option
465467
if "all" in set(features):

src/qbindiff/loader/backend/abstract.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ def exec_path(self) -> str:
320320
"""
321321
raise NotImplementedError()
322322

323+
@property
324+
@abstractmethod
325+
def export_path(self) -> str:
326+
"""
327+
Returns the export file path (if any).
328+
Empty string if not export file
329+
"""
330+
raise NotImplementedError()
331+
323332
@property
324333
def capabilities(self) -> ProgramCapability:
325334
"""

src/qbindiff/loader/backend/binexport.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ def exec_path(self) -> str:
496496
return self._exec_path
497497
return self.name.replace(".BinExport", "") # Try to guess it as best effort
498498

499+
@property
500+
def export_path(self) -> str:
501+
"""
502+
Returns the .Binexport path
503+
"""
504+
return str(self.be_prog.path)
505+
499506
@property
500507
def capabilities(self) -> ProgramCapability:
501508
"""

src/qbindiff/loader/backend/ida.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,10 @@ def exec_path(self) -> str:
514514
"""
515515

516516
return ida_nalt.get_input_file_path()
517+
518+
@property
519+
def export_path(self) -> str:
520+
"""
521+
Returns empty string as IDA does not have exports
522+
"""
523+
return ""

src/qbindiff/loader/backend/quokka.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,15 @@ def exec_path(self) -> str:
609609
"""
610610
Returns the executable path
611611
"""
612-
613612
return self._exec_path
614613

614+
@property
615+
def export_path(self) -> str:
616+
"""
617+
Returns the Quokka export path
618+
"""
619+
return str(self.qb_prog.export_file)
620+
615621
@property
616622
def capabilities(self) -> ProgramCapability:
617623
"""

src/qbindiff/loader/program.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from collections.abc import MutableMapping
2020
from typing import TYPE_CHECKING
2121
from pathlib import Path
22+
import logging
2223

2324
from qbindiff.abstract import GenericGraph
2425
from qbindiff.loader import Function
@@ -255,6 +256,14 @@ def exec_path(self) -> str | None:
255256

256257
return self._backend.exec_path
257258

259+
@property
260+
def export_path(self) -> str | None:
261+
"""
262+
The exported file path if it has been specified, None otherwise
263+
"""
264+
exp = self._backend.export_path
265+
return exp if exp else None
266+
258267
def set_function_filter(self, func: Callable[[Addr], bool]) -> None:
259268
"""
260269
Filter out some functions, to ignore them in later processing.

src/qbindiff/loader/types.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
"""
1717

1818
from __future__ import annotations
19+
20+
import logging
1921
from enum import IntEnum, IntFlag, auto
2022
from typing import TypeAlias, TYPE_CHECKING
2123
import enum_tools.documentation
2224

25+
from qbindiff.utils import log_once
26+
2327
if TYPE_CHECKING:
2428
from qbindiff.loader.data import Data
2529
from qbindiff.loader.structure import Structure, StructureMember
@@ -143,10 +147,11 @@ def from_capstone(cls, capstone_group: int):
143147
try:
144148
return InstructionGroup(capstone_group)
145149
except ValueError:
146-
# Raise an exception if cast is not possible
147-
raise ValueError(
148-
f"Misalignment between capstone group {capstone_group} and InstructionGroup"
150+
# Log once the unsupported
151+
log_once(logging.WARN,
152+
f"Misalignment between capstone group {capstone_group} and InstructionGroup"
149153
)
154+
return InstructionGroup.GRP_INVALID
150155

151156

152157
@enum_tools.documentation.document_enum

src/qbindiff/mapping/bindiff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ def count_items(program: Program) -> tuple[int, int, int, int]:
164164

165165
binfile = BindiffFile.create(
166166
filename,
167-
primary.exec_path,
168-
secondary.exec_path,
167+
primary.export_path,
168+
secondary.export_path,
169169
f"Qbindiff {__version__}",
170170
"",
171171
mapping.normalized_similarity,

0 commit comments

Comments
 (0)