Skip to content

Commit

Permalink
[Lifter] Infinite reccursion of global Variable (#220)
Browse files Browse the repository at this point in the history
* Create draft PR for #209

* Catch recursive type* ptr

* Move init value code into method

* Forgot to add param view

* issort

---------

Co-authored-by: NeoQuix <[email protected]>
Co-authored-by: Spartak Ehrlich <[email protected]>
Co-authored-by: Spartak Ehrlich <[email protected]>
  • Loading branch information
4 people authored Apr 20, 2023
1 parent 532641f commit bdb0eac
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions decompiler/frontend/binaryninja/handlers/globals.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
"""Module implementing the ConstantHandler for the binaryninja frontend."""
from typing import Optional
from typing import Optional, Union

from binaryninja import BinaryView, DataVariable, Endianness, MediumLevelILInstruction, PointerType
from decompiler.frontend.lifter import Handler
from decompiler.structures.pseudo import (
Constant,
GlobalVariable,
ImportedFunctionSymbol,
Integer,
OperationType,
Pointer,
StringSymbol,
UnaryOperation,
)
from decompiler.structures.pseudo import Constant, GlobalVariable, OperationType, UnaryOperation


class GlobalHandler(Handler):
Expand All @@ -36,9 +27,15 @@ def lift_global_variable(self, variable: DataVariable, view: BinaryView,
variable.name if variable.name else "data_" + f"{variable.address:x}",
self._lifter.lift(variable.type),
ssa_label=parent.ssa_memory_version if parent else 0,
initial_value=self._lifter.lift(view.get_data_var_at(variable.value), view=view) if isinstance(variable.type, PointerType) \
and variable.value != 0 else Constant(variable.value) # pointer can point to NULL as well
initial_value=self._get_initial_value(variable, view)
)
],
)



def _get_initial_value(self, variable: DataVariable, view: BinaryView) -> Union[UnaryOperation, Constant]:
"""Return initial value of data variable"""
if isinstance(variable.type, PointerType) and variable.value != 0 and variable.address != variable.value:
return self._lifter.lift(view.get_data_var_at(variable.value), view=view)
else:
return Constant(variable.value)

0 comments on commit bdb0eac

Please sign in to comment.