Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update qbindiff (export_path) and failsafe InstructionGroup #69

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/qbindiff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def load_program(
default=DEFAULT_FEATURES,
multiple=True,
metavar="<feature>",
show_default=True,
help=help_features,
)
@click.option(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions src/qbindiff/loader/backend/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
7 changes: 7 additions & 0 deletions src/qbindiff/loader/backend/binexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
7 changes: 7 additions & 0 deletions src/qbindiff/loader/backend/ida.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
8 changes: 7 additions & 1 deletion src/qbindiff/loader/backend/quokka.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
9 changes: 9 additions & 0 deletions src/qbindiff/loader/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions src/qbindiff/loader/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/qbindiff/mapping/bindiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down