Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lifter] Addresses representation in the decompiled code #397

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions decompiler/frontend/binaryninja/handlers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import math
from typing import Union

from binaryninja import DataVariable, SymbolType, Type, mediumlevelil
from binaryninja import BinaryView, DataVariable, SymbolType, Type, mediumlevelil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unused import again.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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
Loading