Skip to content

structure

Structure management

Structure

Bases: dict

Structure

All IDA structure are merged inside this class (Enum, Structure, Union).

Parameters:

Name Type Description Default
structure 'quokka.pb.Quokka.Structure'

Structure protobuf data

required
program Program

Program back reference

required

Attributes:

Name Type Description
program Program

Program backreference

name str

Structure name

size Optional[int]

Structure size (if known)

type

Structure type

index_to_offset Dict[int, int]

Mapping from offsets to structure members

comments List[str]

Structure comments

Source code in quokka/structure.py
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
class Structure(dict):
    """Structure

    All IDA structure are merged inside this class (Enum, Structure, Union).

    Arguments:
        structure: Structure protobuf data
        program: Program back reference

    Attributes:
        program: Program backreference
        name: Structure name
        size: Structure size (if known)
        type: Structure type
        index_to_offset: Mapping from offsets to structure members
        comments: Structure comments
    """

    def __init__(
        self,
        structure: "quokka.pb.Quokka.Structure",
        program: quokka.Program,
    ) -> None:
        """Constructor"""
        super(dict, self).__init__()
        self.program: quokka.Program = program
        self.name: str = structure.name
        self.size: Optional[int] = (
            structure.size if structure.variable_size is False else 0
        )
        self.type = StructureType.from_proto(structure.type)

        self.index_to_offset: Dict[int, int] = {}
        for index, member in enumerate(structure.members):
            self[member.offset] = StructureMember(member, self)
            self.index_to_offset[index] = member.offset

        self.comments: List[str] = []

__init__(structure, program)

Constructor

Source code in quokka/structure.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(
    self,
    structure: "quokka.pb.Quokka.Structure",
    program: quokka.Program,
) -> None:
    """Constructor"""
    super(dict, self).__init__()
    self.program: quokka.Program = program
    self.name: str = structure.name
    self.size: Optional[int] = (
        structure.size if structure.variable_size is False else 0
    )
    self.type = StructureType.from_proto(structure.type)

    self.index_to_offset: Dict[int, int] = {}
    for index, member in enumerate(structure.members):
        self[member.offset] = StructureMember(member, self)
        self.index_to_offset[index] = member.offset

    self.comments: List[str] = []

StructureMember

StructureMember

This class represents structure members (fields).

Parameters:

Name Type Description Default
member 'quokka.pb.Quokka.Structure.Member'

Protobuf data

required
structure Structure

Reference to the parent structure

required

Attributes:

Name Type Description
name str

Member name

size int

Member size (if known)

type DataType

Member data type

value Optional[int]

Member value

comments List[str]

Member comments

Source code in quokka/structure.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class StructureMember:
    """StructureMember

    This class represents structure members (fields).

    Arguments:
        member: Protobuf data
        structure: Reference to the parent structure

    Attributes:
        name: Member name
        size: Member size (if known)
        type: Member data type
        value: Member value
        comments: Member comments
    """

    def __init__(
        self,
        member: "quokka.pb.Quokka.Structure.Member",
        structure: Structure,
    ) -> None:
        """Constructor"""
        self.name: str = member.name
        self.type: DataType = DataType.from_proto(member.type)
        self.size: int = member.size
        self.value: Optional[int] = member.value if member.value != 0 else None
        self._structure: weakref.ref[Structure] = weakref.ref(structure)

        self.comments: List[str] = []

    @property
    def structure(self) -> Structure:
        """Back reference to the parent structure"""
        return self._structure()

structure: Structure property

Back reference to the parent structure

__init__(member, structure)

Constructor

Source code in quokka/structure.py
46
47
48
49
50
51
52
53
54
55
56
57
58
def __init__(
    self,
    member: "quokka.pb.Quokka.Structure.Member",
    structure: Structure,
) -> None:
    """Constructor"""
    self.name: str = member.name
    self.type: DataType = DataType.from_proto(member.type)
    self.size: int = member.size
    self.value: Optional[int] = member.value if member.value != 0 else None
    self._structure: weakref.ref[Structure] = weakref.ref(structure)

    self.comments: List[str] = []