Skip to content

Commit

Permalink
[Lifter] Addresses representation in the decompiled code (#397)
Browse files Browse the repository at this point in the history
* Lift as constant detected pointer

* Remove typo

* Fix isort

* Remove redundant code

* Redo deleting newline from the end of file

* Remove unused import

---------

Co-authored-by: fnhartmann <[email protected]>
  • Loading branch information
github-actions[bot] and fnhartmann authored Apr 17, 2024
1 parent d8d7671 commit 34f2b3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion 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 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 @@ -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
Expand Down
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 34f2b3e

Please sign in to comment.