From bdb0eacbfc335b0a6f69e419e80b3a84801ff411 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 20 Apr 2023 13:55:17 +0200 Subject: [PATCH] [Lifter] Infinite reccursion of global Variable (#220) * Create draft PR for #209 * Catch recursive type* ptr * Move init value code into method * Forgot to add param view * issort --------- Co-authored-by: NeoQuix Co-authored-by: Spartak Ehrlich Co-authored-by: Spartak Ehrlich <83972469+NeoQuix@users.noreply.github.com> --- .../frontend/binaryninja/handlers/globals.py | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/decompiler/frontend/binaryninja/handlers/globals.py b/decompiler/frontend/binaryninja/handlers/globals.py index d46b29a62..3bddffd28 100644 --- a/decompiler/frontend/binaryninja/handlers/globals.py +++ b/decompiler/frontend/binaryninja/handlers/globals.py @@ -1,18 +1,9 @@ """Module implementing the ConstantHandler for the binaryninja frontend.""" -from typing import Optional +from typing import Optional, Union from binaryninja import BinaryView, DataVariable, Endianness, MediumLevelILInstruction, PointerType from decompiler.frontend.lifter import Handler -from decompiler.structures.pseudo import ( - Constant, - GlobalVariable, - ImportedFunctionSymbol, - Integer, - OperationType, - Pointer, - StringSymbol, - UnaryOperation, -) +from decompiler.structures.pseudo import Constant, GlobalVariable, OperationType, UnaryOperation class GlobalHandler(Handler): @@ -36,9 +27,15 @@ def lift_global_variable(self, variable: DataVariable, view: BinaryView, variable.name if variable.name else "data_" + f"{variable.address:x}", self._lifter.lift(variable.type), ssa_label=parent.ssa_memory_version if parent else 0, - initial_value=self._lifter.lift(view.get_data_var_at(variable.value), view=view) if isinstance(variable.type, PointerType) \ - and variable.value != 0 else Constant(variable.value) # pointer can point to NULL as well + initial_value=self._get_initial_value(variable, view) ) ], ) - \ No newline at end of file + + + def _get_initial_value(self, variable: DataVariable, view: BinaryView) -> Union[UnaryOperation, Constant]: + """Return initial value of data variable""" + if isinstance(variable.type, PointerType) and variable.value != 0 and variable.address != variable.value: + return self._lifter.lift(view.get_data_var_at(variable.value), view=view) + else: + return Constant(variable.value)