diff --git a/decompiler/frontend/binaryninja/frontend.py b/decompiler/frontend/binaryninja/frontend.py index 0b04799e..832c71e4 100644 --- a/decompiler/frontend/binaryninja/frontend.py +++ b/decompiler/frontend/binaryninja/frontend.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging +from typing import List import binaryninja from binaryninja import BinaryView @@ -87,9 +88,11 @@ def lift(self, task: DecompilerTask): if task.options.getboolean("pipeline.debug", fallback=False): raise e - def _parameter_locations(self, function: binaryninja.function.Function) -> list[str | None]: - """For a given Binary Ninja Function, this method returns a list of its parameters' locations in the correct order. - E.g. if the first parameter is stored in r14, the first entry in the returned list will be 'r14'.""" + def _parameter_locations(self, function: binaryninja.function.Function) -> List[str | None]: + """ + For a given Binary Ninja Function, this method returns a list of its parameters' locations in the correct order. + E.g. if the first parameter is stored in r14, the first entry in the returned list will be 'r14'. + """ raw_parameters = function.type.parameters parameter_locations = [] for parameter in raw_parameters: diff --git a/decompiler/frontend/binaryninja/handlers/constants.py b/decompiler/frontend/binaryninja/handlers/constants.py index 16794a58..e2a77309 100644 --- a/decompiler/frontend/binaryninja/handlers/constants.py +++ b/decompiler/frontend/binaryninja/handlers/constants.py @@ -15,7 +15,7 @@ OperationType, Pointer, Symbol, - UnaryOperation, + UnaryOperation, FunctionSymbol, ) BYTE_SIZE = 8 @@ -61,18 +61,17 @@ def lift_constant_pointer(self, pointer: mediumlevelil.MediumLevelILConstPtr, ** res = self._lifter.lift(variable, view=view, parent=pointer) elif (symbol := view.get_symbol_at(pointer.constant)) and symbol.type != SymbolType.DataSymbol: - result = self._lifter.lift(symbol) - can_return = None - try: - can_return = view.get_function_at(pointer.constant).can_return.value - except Exception: - pass - result.can_return = can_return + if isinstance(result := self._lifter.lift(symbol), FunctionSymbol): + try: + result.can_return = view.get_function_at(pointer.constant).can_return.value + return result + except Exception: + pass return result elif function := view.get_function_at(pointer.constant): - result = self._lifter.lift(function.symbol) - result.can_return = function.can_return.value + if isinstance(result := self._lifter.lift(function.symbol), FunctionSymbol): + result.can_return = function.can_return.value return result else: diff --git a/decompiler/frontend/binaryninja/rust_string_detection.py b/decompiler/frontend/binaryninja/rust_string_detection.py index 8290874a..57b54813 100644 --- a/decompiler/frontend/binaryninja/rust_string_detection.py +++ b/decompiler/frontend/binaryninja/rust_string_detection.py @@ -17,10 +17,10 @@ class RustStringDetection: def __init__(self, binary_view: BinaryView, options: Options): self._bv = binary_view - self._enabled = options.getboolean("rust-string-detection.enabled", fallback=True) - self._rust_binaries_only = options.getboolean("rust-string-detection.rust_binaries_only", fallback=True) - self._string_slicer_path = options.getstring("rust-string-detection.string_slicer_path") - self._debug_submodules = options.getboolean("logging.debug-submodules") + self._enabled = options.getboolean("rust-string-detection.enabled", fallback=False) + self._rust_binaries_only = options.getboolean("rust-string-detection.rust_binaries_only", fallback=False) + self._string_slicer_path = options.getstring("rust-string-detection.string_slicer_path", fallback="") + self._debug_submodules = options.getboolean("logging.debug-submodules", fallback=False) def is_rust_binary(self): """ @@ -40,6 +40,7 @@ def run(self): String Slicer's path will be added to Python's path before importing the module. """ if not self._enabled: + logging.info("Rust String Slicer not executed") return if self._rust_binaries_only and not self.is_rust_binary(): diff --git a/decompiler/pipeline/preprocessing/remove_stack_canary.py b/decompiler/pipeline/preprocessing/remove_stack_canary.py index ed65371e..03725714 100644 --- a/decompiler/pipeline/preprocessing/remove_stack_canary.py +++ b/decompiler/pipeline/preprocessing/remove_stack_canary.py @@ -29,14 +29,6 @@ def run(self, task: DecompilerTask): for fail_node in list(self._contains_stack_check_fail()): self._patch_canary(fail_node) - def _get_called_functions(self, instructions): - """ - Yields all functions called by an instruction - """ - for instruction in instructions: - if isinstance(instruction, Assignment) and isinstance(instruction.value, Call): - yield instruction.value.function - def _contains_stack_check_fail(self) -> Iterator[BasicBlock]: """ Iterate leaf nodes of cfg, yield nodes containing canary check. @@ -53,7 +45,8 @@ def _is_stack_chk_fail(self, node: BasicBlock) -> bool: return any(self.STACK_FAIL_STR in str(inst) for inst in node.instructions) or self._reached_by_failed_canary_check(node) def _reached_by_failed_canary_check(self, node: BasicBlock) -> bool: - """Determine if the given `node` is reached by a failed stack canary check. + """ + Determine if the given `node` is reached by a failed stack canary check. This function checks if any incoming edges to the `node` are conditional branches that failed a stack canary check. It examines the predecessor nodes to see if the diff --git a/decompiler/task.py b/decompiler/task.py index 08c25c22..f4ff8d33 100644 --- a/decompiler/task.py +++ b/decompiler/task.py @@ -25,7 +25,7 @@ class DecompilerTask: ast: AbstractSyntaxTree | None = None function_return_type: Type = Integer.int32_t() function_parameters: List[Variable] = field(default_factory=list) - function_parameter_locations: List[str | None] = (field(default_factory=list),) + function_parameter_locations: List[str | None] = field(default_factory=list) complex_types: ComplexTypeMap = field(default_factory=ComplexTypeMap) _failure_origin: str | None = field(default=None, init=False) diff --git a/decompiler/util/default.json b/decompiler/util/default.json index f56fb220..d3304862 100644 --- a/decompiler/util/default.json +++ b/decompiler/util/default.json @@ -141,7 +141,7 @@ }, { "dest": "rust-string-detection.rust_binaries_only", - "default": true, + "default": false, "title": "Restrict string slice detection to Rust binaries", "type": "boolean", "description": "string slices will only be detected for Rust binaries",