From dde4cd6642ec618d88af942436bc9e8d17befd4f Mon Sep 17 00:00:00 2001 From: Mariia Rybalka Date: Tue, 16 Apr 2024 15:42:54 +0200 Subject: [PATCH] Remove redundant code --- .../binaryninja/handlers/constants.py | 19 +++---------------- .../frontend/binaryninja/handlers/globals.py | 3 ++- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/decompiler/frontend/binaryninja/handlers/constants.py b/decompiler/frontend/binaryninja/handlers/constants.py index 5b09a4687..fa30e5fc0 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 BinaryView, 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, @@ -39,7 +40,7 @@ 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 self._addr_in_section(constant.function.view, 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)) @@ -81,18 +82,4 @@ def lift_constant_pointer(self, pointer: mediumlevelil.MediumLevelILConstPtr, ** OperationType.address, [res], vartype=res.type, - ) - - def _in_read_only_section(self, addr: int, view: BinaryView) -> bool: - """Returns True if address is contained in a read only section, False otherwise""" - for _, section in view.sections.items(): - if addr >= section.start and addr <= section.end and section.semantics == SectionSemantics.ReadOnlyDataSectionSemantics: - return True - return False - - def _addr_in_section(self, view: BinaryView, addr: int) -> bool: - """Returns True if address is contained in a section, False otherwise""" - for _, section in view.sections.items(): - if addr >= section.start and addr <= section.end: - return True - return False + ) \ No newline at end of file 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).