Skip to content

Commit

Permalink
lift classes exactly like structs
Browse files Browse the repository at this point in the history
  • Loading branch information
blattm committed Oct 13, 2023
1 parent 2155726 commit 41d1b28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion decompiler/frontend/binaryninja/handlers/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from decompiler.frontend.lifter import Handler
from decompiler.structures.pseudo import CustomType, Float, FunctionTypeDef, Integer, Pointer, UnknownType, Variable
from decompiler.structures.pseudo.complextypes import ComplexTypeMember, ComplexTypeName, Enum, Struct
from decompiler.structures.pseudo.complextypes import Class, ComplexTypeMember, ComplexTypeName, Enum, Struct
from decompiler.structures.pseudo.complextypes import Union as Union_


Expand Down Expand Up @@ -98,6 +98,9 @@ def lift_struct(self, struct: StructureType, name: str = None, **kwargs) -> Unio
elif struct.type == StructureVariant.UnionStructureType:
type_name = name if name else self._get_data_type_name(struct, keyword="union")
lifted_struct = Union_(struct.width * self.BYTE_SIZE, type_name, [])
elif struct.type == StructureVariant.ClassStructureType:
type_name = name if name else self._get_data_type_name(struct, keyword="class")
lifted_struct = Class(struct.width * self.BYTE_SIZE, type_name, {})
else:
raise RuntimeError(f"Unknown struct type {struct.type.name}")
self._lifter.complex_types.add(lifted_struct)
Expand Down
14 changes: 12 additions & 2 deletions decompiler/structures/pseudo/complextypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def declaration(self) -> str:


@dataclass(frozen=True, order=True)
class Struct(ComplexType):
class _BaseStruct(ComplexType):
"""Class representing a struct type."""

members: Dict[int, ComplexTypeMember] = field(compare=False)
type_specifier: ComplexTypeSpecifier = ComplexTypeSpecifier.STRUCT
type_specifier: ComplexTypeSpecifier

def add_member(self, member: ComplexTypeMember):
self.members[member.offset] = member
Expand All @@ -71,6 +71,16 @@ def declaration(self) -> str:
return f"{self.type_specifier.value} {self.name} {{\n\t{members}\n}}"


@dataclass(frozen=True, order=True)
class Struct(_BaseStruct):
type_specifier: ComplexTypeSpecifier = ComplexTypeSpecifier.STRUCT


@dataclass(frozen=True, order=True)
class Class(_BaseStruct):
type_specifier: ComplexTypeSpecifier = ComplexTypeSpecifier.CLASS


@dataclass(frozen=True, order=True)
class Union(ComplexType):
members: List[ComplexTypeMember] = field(compare=False)
Expand Down

0 comments on commit 41d1b28

Please sign in to comment.