diff --git a/decompiler/frontend/binaryninja/handlers/constants.py b/decompiler/frontend/binaryninja/handlers/constants.py index 20b4bfbb9..d351a2a2e 100644 --- a/decompiler/frontend/binaryninja/handlers/constants.py +++ b/decompiler/frontend/binaryninja/handlers/constants.py @@ -4,6 +4,7 @@ from typing import Union from binaryninja import DataVariable, SymbolType, Type, mediumlevelil +from decompiler.frontend.binaryninja.handlers.globals import addr_in_section from decompiler.frontend.lifter import Handler from decompiler.structures.pseudo import ( Constant, @@ -35,10 +36,12 @@ def register(self): } ) - def lift_constant(self, constant: mediumlevelil.MediumLevelILConst, **kwargs) -> Constant: + def lift_constant(self, constant: mediumlevelil.MediumLevelILConst, **kwargs): """Lift the given constant value.""" if constant.constant in [math.inf, -math.inf, math.nan]: return NotUseableConstant(str(constant.constant)) + if addr_in_section(constant.function.view, constant.constant): + return self.lift_constant_pointer(constant) return Constant(constant.constant, vartype=self._lifter.lift(constant.expr_type)) @staticmethod diff --git a/decompiler/frontend/binaryninja/handlers/globals.py b/decompiler/frontend/binaryninja/handlers/globals.py index b37b2d07b..f62dcb32b 100644 --- a/decompiler/frontend/binaryninja/handlers/globals.py +++ b/decompiler/frontend/binaryninja/handlers/globals.py @@ -15,7 +15,6 @@ Type, VoidType, ) -from decompiler.frontend.binaryninja.handlers.constants import BYTE_SIZE from decompiler.frontend.binaryninja.handlers.symbols import GLOBAL_VARIABLE_PREFIX from decompiler.frontend.lifter import Handler from decompiler.structures.pseudo import ArrayType as PseudoArrayType @@ -33,6 +32,8 @@ UnaryOperation, ) +BYTE_SIZE = 8 + """ Lift a given address inside of a binary by BNinjas DataVariable type. If some code references a address, bninja stores the information about the address inside of a DataVariable (dv).