Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
mari-mari committed Apr 16, 2024
1 parent 1907062 commit dde4cd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
19 changes: 3 additions & 16 deletions decompiler/frontend/binaryninja/handlers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
)
3 changes: 2 additions & 1 deletion decompiler/frontend/binaryninja/handlers/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down

0 comments on commit dde4cd6

Please sign in to comment.