Skip to content

Commit

Permalink
add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
blattm committed Aug 19, 2024
1 parent 89810b6 commit 7f220f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions decompiler/backend/cexpressiongenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def get_data_of_struct_string(variable) -> GlobalVariable:


def inline_global_variable(var) -> bool:
"""Decides whether or not to inline a global variable."""
if not var.is_constant:
return False
match var.type:
Expand Down
6 changes: 6 additions & 0 deletions decompiler/frontend/binaryninja/handlers/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,16 @@ def _lift_named_type_ref(self, variable: DataVariable, parent: Optional[MediumLe
raise NotImplementedError(f"No handler for '{variable.type.named_type_class}' in lifter")

def _lift_structure_type(self, variable: DataVariable, parent: Optional[MediumLevelILInstruction] = None, **_):
"""Lift a struct"""
struct_type = variable.type
return self._lift_struct_helper(variable, parent, struct_type)

def _lift_struct_helper(self, variable, parent, struct_type):
"""This helper method for lifting structs does the heavy lifting.
A structs initial value is comprised of its membembers' initial values.
This method iterates over all struct members, interprets the corresponding memory locations as new data variables
and lifts them (recursively) to gain access to the members' initial values.
"""
values = {}
s_type = self._lifter.lift(struct_type)
for member_type in struct_type.members:
Expand Down
7 changes: 7 additions & 0 deletions decompiler/structures/pseudo/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ def accept(self, visitor: DataflowObjectVisitorInterface[T]) -> T:


class ConstantComposition(Constant):
"""This class stores multiple constants of the same type in a list.
It is used to represent arrays and string constants"""

def __init__(self, value: list[Constant], vartype: DecompiledType = UnknownType(), tags: Optional[Tuple[Tag, ...]] = None):
super().__init__(
value,
Expand Down Expand Up @@ -587,6 +590,10 @@ def accept(self, visitor: DataflowObjectVisitorInterface[T]) -> T:


class StructConstant(Constant):
"""This class represents constant structs.
The value is a dictionary mapping offsets to the corresponding fields' value.
The vartype is a 'Struct' (a special ComplexType), which provides a mapping from offsets to field names."""

def __init__(self, value: dict[int, Expression], vartype: Struct, tags: Optional[Tuple[Tag, ...]] = None):
super().__init__(
value,
Expand Down

0 comments on commit 7f220f8

Please sign in to comment.