diff --git a/decompiler/backend/cexpressiongenerator.py b/decompiler/backend/cexpressiongenerator.py index 7d85e964..cbea3d5b 100644 --- a/decompiler/backend/cexpressiongenerator.py +++ b/decompiler/backend/cexpressiongenerator.py @@ -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: diff --git a/decompiler/frontend/binaryninja/handlers/globals.py b/decompiler/frontend/binaryninja/handlers/globals.py index bcc7b692..fff56957 100644 --- a/decompiler/frontend/binaryninja/handlers/globals.py +++ b/decompiler/frontend/binaryninja/handlers/globals.py @@ -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: diff --git a/decompiler/structures/pseudo/expressions.py b/decompiler/structures/pseudo/expressions.py index d28685e1..9f17d6d5 100644 --- a/decompiler/structures/pseudo/expressions.py +++ b/decompiler/structures/pseudo/expressions.py @@ -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, @@ -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,