From 1eecf0d9370b6f37be7de027324b78641c3fb53b Mon Sep 17 00:00:00 2001 From: Robin David Date: Thu, 28 Nov 2024 22:56:52 +0100 Subject: [PATCH 1/3] add export_path property on program --- src/qbindiff/loader/backend/abstract.py | 9 +++++++++ src/qbindiff/loader/backend/binexport.py | 7 +++++++ src/qbindiff/loader/backend/ida.py | 7 +++++++ src/qbindiff/loader/backend/quokka.py | 8 +++++++- src/qbindiff/loader/program.py | 9 +++++++++ src/qbindiff/mapping/bindiff.py | 4 ++-- 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/qbindiff/loader/backend/abstract.py b/src/qbindiff/loader/backend/abstract.py index b64f07b..29c42eb 100644 --- a/src/qbindiff/loader/backend/abstract.py +++ b/src/qbindiff/loader/backend/abstract.py @@ -320,6 +320,15 @@ def exec_path(self) -> str: """ raise NotImplementedError() + @property + @abstractmethod + def export_path(self) -> str: + """ + Returns the export file path (if any). + Empty string if not export file + """ + raise NotImplementedError() + @property def capabilities(self) -> ProgramCapability: """ diff --git a/src/qbindiff/loader/backend/binexport.py b/src/qbindiff/loader/backend/binexport.py index 53471d3..199cae1 100644 --- a/src/qbindiff/loader/backend/binexport.py +++ b/src/qbindiff/loader/backend/binexport.py @@ -496,6 +496,13 @@ def exec_path(self) -> str: return self._exec_path return self.name.replace(".BinExport", "") # Try to guess it as best effort + @property + def export_path(self) -> str: + """ + Returns the .Binexport path + """ + return str(self.be_prog.path) + @property def capabilities(self) -> ProgramCapability: """ diff --git a/src/qbindiff/loader/backend/ida.py b/src/qbindiff/loader/backend/ida.py index 23f5a15..2690c01 100644 --- a/src/qbindiff/loader/backend/ida.py +++ b/src/qbindiff/loader/backend/ida.py @@ -514,3 +514,10 @@ def exec_path(self) -> str: """ return ida_nalt.get_input_file_path() + + @property + def export_path(self) -> str: + """ + Returns empty string as IDA does not have exports + """ + return "" diff --git a/src/qbindiff/loader/backend/quokka.py b/src/qbindiff/loader/backend/quokka.py index f39a1a5..4550c39 100644 --- a/src/qbindiff/loader/backend/quokka.py +++ b/src/qbindiff/loader/backend/quokka.py @@ -609,9 +609,15 @@ def exec_path(self) -> str: """ Returns the executable path """ - return self._exec_path + @property + def export_path(self) -> str: + """ + Returns the Quokka export path + """ + return str(self.qb_prog.export_file) + @property def capabilities(self) -> ProgramCapability: """ diff --git a/src/qbindiff/loader/program.py b/src/qbindiff/loader/program.py index ca598ce..4be14a4 100644 --- a/src/qbindiff/loader/program.py +++ b/src/qbindiff/loader/program.py @@ -19,6 +19,7 @@ from collections.abc import MutableMapping from typing import TYPE_CHECKING from pathlib import Path +import logging from qbindiff.abstract import GenericGraph from qbindiff.loader import Function @@ -255,6 +256,14 @@ def exec_path(self) -> str | None: return self._backend.exec_path + @property + def export_path(self) -> str | None: + """ + The exported file path if it has been specified, None otherwise + """ + exp = self._backend.export_path + return exp if exp else None + def set_function_filter(self, func: Callable[[Addr], bool]) -> None: """ Filter out some functions, to ignore them in later processing. diff --git a/src/qbindiff/mapping/bindiff.py b/src/qbindiff/mapping/bindiff.py index 36c68fe..93be8c5 100644 --- a/src/qbindiff/mapping/bindiff.py +++ b/src/qbindiff/mapping/bindiff.py @@ -164,8 +164,8 @@ def count_items(program: Program) -> tuple[int, int, int, int]: binfile = BindiffFile.create( filename, - primary.exec_path, - secondary.exec_path, + primary.export_path, + secondary.export_path, f"Qbindiff {__version__}", "", mapping.normalized_similarity, From f76b82879b3fd8c69011e10971ee483f5abbd828 Mon Sep 17 00:00:00 2001 From: Robin David Date: Thu, 28 Nov 2024 22:57:16 +0100 Subject: [PATCH 2/3] add show default features --- src/qbindiff/__main__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/qbindiff/__main__.py b/src/qbindiff/__main__.py index 10fd99e..751d514 100644 --- a/src/qbindiff/__main__.py +++ b/src/qbindiff/__main__.py @@ -233,6 +233,7 @@ def load_program( default=DEFAULT_FEATURES, multiple=True, metavar="", + show_default=True, help=help_features, ) @click.option( @@ -420,6 +421,11 @@ def main( ) return 1 + if not features: + logging.error("no feature provided") + return 1 + + with Progress() as progress: if not quiet: load_bar_total = 2 @@ -456,10 +462,6 @@ def main( logging.error(e) exit(1) - if not features: - logging.error("no feature provided") - exit(1) - try: # Check for the 'all' option if "all" in set(features): From 2d7be4bdf177ecbb04af2a2bf6cb69a07807e98e Mon Sep 17 00:00:00 2001 From: Robin David Date: Thu, 28 Nov 2024 22:57:43 +0100 Subject: [PATCH 3/3] change groups not to raise an exception when one is not supported --- src/qbindiff/loader/types.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/qbindiff/loader/types.py b/src/qbindiff/loader/types.py index a39133e..5a7f505 100644 --- a/src/qbindiff/loader/types.py +++ b/src/qbindiff/loader/types.py @@ -16,10 +16,14 @@ """ from __future__ import annotations + +import logging from enum import IntEnum, IntFlag, auto from typing import TypeAlias, TYPE_CHECKING import enum_tools.documentation +from qbindiff.utils import log_once + if TYPE_CHECKING: from qbindiff.loader.data import Data from qbindiff.loader.structure import Structure, StructureMember @@ -143,10 +147,11 @@ def from_capstone(cls, capstone_group: int): try: return InstructionGroup(capstone_group) except ValueError: - # Raise an exception if cast is not possible - raise ValueError( - f"Misalignment between capstone group {capstone_group} and InstructionGroup" + # Log once the unsupported + log_once(logging.WARN, + f"Misalignment between capstone group {capstone_group} and InstructionGroup" ) + return InstructionGroup.GRP_INVALID @enum_tools.documentation.document_enum