Skip to content

types

Types used in Quokka

AccessMode

Bases: IntFlag

Register access mode

Source code in bindings/python/quokka/types.py
35
36
37
38
39
class AccessMode(enum.IntFlag):
    """Register access mode"""

    READ = enum.auto()
    WRITE = enum.auto()

AddressSize

Bases: Enum

Address size

Source code in bindings/python/quokka/types.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class AddressSize(enum.Enum):
    """Address size"""

    ADDRESS_64 = enum.auto()
    ADDRESS_32 = enum.auto()
    ADDRESS_16 = enum.auto()
    ADDRESS_UNK = enum.auto()

    @staticmethod
    def from_proto(
        address_size: "Pb.AddressSizeValue",
    ) -> "AddressSize":
        """Convert the protobuf value into this enumeration"""
        mapping = {
            Pb.ADDR_32: AddressSize.ADDRESS_32,
            Pb.ADDR_64: AddressSize.ADDRESS_64,
        }

        return mapping.get(address_size, AddressSize.ADDRESS_UNK)

from_proto(address_size) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
57
58
59
60
61
62
63
64
65
66
67
@staticmethod
def from_proto(
    address_size: "Pb.AddressSizeValue",
) -> "AddressSize":
    """Convert the protobuf value into this enumeration"""
    mapping = {
        Pb.ADDR_32: AddressSize.ADDRESS_32,
        Pb.ADDR_64: AddressSize.ADDRESS_64,
    }

    return mapping.get(address_size, AddressSize.ADDRESS_UNK)

BlockType

Bases: Enum

Block Type

Source code in bindings/python/quokka/types.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
class BlockType(enum.Enum):
    """Block Type"""

    NORMAL = enum.auto()
    INDJUMP = enum.auto()
    RET = enum.auto()
    NORET = enum.auto()
    CNDRET = enum.auto()
    ENORET = enum.auto()
    EXTERN = enum.auto()
    ERROR = enum.auto()

    @staticmethod
    def from_proto(
        block_type: "Pb.Block.BlockTypeValue",
    ) -> BlockType:
        """Convert the protobuf value into this enumeration"""
        mapping = {
            Pb.Block.BLOCK_TYPE_NORMAL: BlockType.NORMAL,
            Pb.Block.BLOCK_TYPE_INDJUMP: BlockType.INDJUMP,
            Pb.Block.BLOCK_TYPE_RET: BlockType.RET,
            Pb.Block.BLOCK_TYPE_NORET: BlockType.NORET,
            Pb.Block.BLOCK_TYPE_CNDRET: BlockType.CNDRET,
            Pb.Block.BLOCK_TYPE_ENORET: BlockType.ENORET,
            Pb.Block.BLOCK_TYPE_EXTERN: BlockType.EXTERN,
            Pb.Block.BLOCK_TYPE_ERROR: BlockType.ERROR,
        }

        return mapping.get(block_type, BlockType.NORMAL)

from_proto(block_type) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
@staticmethod
def from_proto(
    block_type: "Pb.Block.BlockTypeValue",
) -> BlockType:
    """Convert the protobuf value into this enumeration"""
    mapping = {
        Pb.Block.BLOCK_TYPE_NORMAL: BlockType.NORMAL,
        Pb.Block.BLOCK_TYPE_INDJUMP: BlockType.INDJUMP,
        Pb.Block.BLOCK_TYPE_RET: BlockType.RET,
        Pb.Block.BLOCK_TYPE_NORET: BlockType.NORET,
        Pb.Block.BLOCK_TYPE_CNDRET: BlockType.CNDRET,
        Pb.Block.BLOCK_TYPE_ENORET: BlockType.ENORET,
        Pb.Block.BLOCK_TYPE_EXTERN: BlockType.EXTERN,
        Pb.Block.BLOCK_TYPE_ERROR: BlockType.ERROR,
    }

    return mapping.get(block_type, BlockType.NORMAL)

CallingConvention

Bases: Enum

Calling convention

Source code in bindings/python/quokka/types.py
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
class CallingConvention(enum.Enum):
    """Calling convention"""

    UNKNOWN = enum.auto()
    CDECL = enum.auto()
    ELLIPSIS = enum.auto()
    STDCALL = enum.auto()
    PASCAL = enum.auto()
    FASTCALL = enum.auto()
    THISCALL = enum.auto()
    SWIFT = enum.auto()
    GOLANG = enum.auto()
    GOSTK = enum.auto()

    @staticmethod
    def from_proto(proto_cc: "Pb.CallingConvention") -> "CallingConvention":
        """Convert the protobuf value into this enumeration"""
        return {
            Pb.CC_CDECL: CallingConvention.CDECL,
            Pb.CC_ELLIPSIS: CallingConvention.ELLIPSIS,
            Pb.CC_STDCALL: CallingConvention.STDCALL,
            Pb.CC_PASCAL: CallingConvention.PASCAL,
            Pb.CC_FASTCALL: CallingConvention.FASTCALL,
            Pb.CC_THISCALL: CallingConvention.THISCALL,
            Pb.CC_SWIFT: CallingConvention.SWIFT,
            Pb.CC_GOLANG: CallingConvention.GOLANG,
            Pb.CC_GOSTK: CallingConvention.GOSTK,
        }[proto_cc]

from_proto(proto_cc) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
287
288
289
290
291
292
293
294
295
296
297
298
299
300
@staticmethod
def from_proto(proto_cc: "Pb.CallingConvention") -> "CallingConvention":
    """Convert the protobuf value into this enumeration"""
    return {
        Pb.CC_CDECL: CallingConvention.CDECL,
        Pb.CC_ELLIPSIS: CallingConvention.ELLIPSIS,
        Pb.CC_STDCALL: CallingConvention.STDCALL,
        Pb.CC_PASCAL: CallingConvention.PASCAL,
        Pb.CC_FASTCALL: CallingConvention.FASTCALL,
        Pb.CC_THISCALL: CallingConvention.THISCALL,
        Pb.CC_SWIFT: CallingConvention.SWIFT,
        Pb.CC_GOLANG: CallingConvention.GOLANG,
        Pb.CC_GOSTK: CallingConvention.GOSTK,
    }[proto_cc]

Disassembler

Bases: Enum

Disassembler

Source code in bindings/python/quokka/types.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
class Disassembler(enum.Enum):
    """Disassembler"""

    UNKNOWN = enum.auto()
    IDA = enum.auto()
    GHIDRA = enum.auto()
    BINARY_NINJA = enum.auto()

    @staticmethod
    def from_proto(
        proto_disass: "Pb.Meta.Backend.Disassembler",
    ) -> "Disassembler":
        """Convert the protobuf value into this enumeration"""
        mapping = {
            Pb.Meta.Backend.Disassembler.DISASS_IDA: Disassembler.IDA,
            Pb.Meta.Backend.Disassembler.DISASS_GHIDRA: Disassembler.GHIDRA,
            Pb.Meta.Backend.Disassembler.DISASS_BINARY_NINJA: Disassembler.BINARY_NINJA,
        }

        return mapping.get(proto_disass, Disassembler.UNKNOWN)

from_proto(proto_disass) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
311
312
313
314
315
316
317
318
319
320
321
322
@staticmethod
def from_proto(
    proto_disass: "Pb.Meta.Backend.Disassembler",
) -> "Disassembler":
    """Convert the protobuf value into this enumeration"""
    mapping = {
        Pb.Meta.Backend.Disassembler.DISASS_IDA: Disassembler.IDA,
        Pb.Meta.Backend.Disassembler.DISASS_GHIDRA: Disassembler.GHIDRA,
        Pb.Meta.Backend.Disassembler.DISASS_BINARY_NINJA: Disassembler.BINARY_NINJA,
    }

    return mapping.get(proto_disass, Disassembler.UNKNOWN)

Endianness

Bases: Enum

Endianness of the program

LE: Little endian (least significant bit first) BE: Big endian (most significant bit first)

TODO

See how we can support mixed endianness

Source code in bindings/python/quokka/types.py
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
class Endianness(enum.Enum):
    """Endianness of the program

    LE: Little endian (least significant bit first)
    BE: Big endian (most significant bit first)

    TODO:
        See how we can support mixed endianness
    """

    LITTLE_ENDIAN = enum.auto()
    BIG_ENDIAN = enum.auto()
    UNKNOWN = enum.auto()

    @staticmethod
    def from_proto(
        endianness: "Pb.Meta.EndianessValue",
    ) -> Endianness:
        """Convert the protobuf value into this enumeration"""
        mapping = {
            Pb.Meta.END_BE: Endianness.BIG_ENDIAN,
            Pb.Meta.END_LE: Endianness.LITTLE_ENDIAN,
        }

        return mapping.get(endianness, Endianness.UNKNOWN)

from_proto(endianness) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
84
85
86
87
88
89
90
91
92
93
94
@staticmethod
def from_proto(
    endianness: "Pb.Meta.EndianessValue",
) -> Endianness:
    """Convert the protobuf value into this enumeration"""
    mapping = {
        Pb.Meta.END_BE: Endianness.BIG_ENDIAN,
        Pb.Meta.END_LE: Endianness.LITTLE_ENDIAN,
    }

    return mapping.get(endianness, Endianness.UNKNOWN)

ExporterMode

Bases: IntEnum

Mode type

The exporter mode controls the type of exported data.

Source code in bindings/python/quokka/types.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
class ExporterMode(enum.IntEnum):
    """Mode type

    The exporter mode controls the type of exported data.
    """

    LIGHT = enum.auto()
    FULL = enum.auto()

    @staticmethod
    def from_proto(mode: "Pb.ExporterMeta.ModeValue") -> "ExporterMode":
        mapping = {
            Pb.ExporterMeta.MODE_LIGHT: ExporterMode.LIGHT,
            Pb.ExporterMeta.MODE_SELF_CONTAINED: ExporterMode.FULL,
        }

        return mapping[mode]

FunctionType

Bases: Enum

Function Type

Source code in bindings/python/quokka/types.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
class FunctionType(enum.Enum):
    """Function Type"""

    NORMAL = enum.auto()
    IMPORTED = enum.auto()
    LIBRARY = enum.auto()
    THUNK = enum.auto()
    EXTERN = enum.auto()
    INVALID = enum.auto()

    @staticmethod
    def from_proto(
        function_type: "Pb.Function.FunctionTypeValue",
    ) -> "FunctionType":
        """Convert the protobuf value into this enumeration"""
        mapping = {
            Pb.Function.TYPE_NORMAL: FunctionType.NORMAL,
            Pb.Function.TYPE_IMPORTED: FunctionType.IMPORTED,
            Pb.Function.TYPE_LIBRARY: FunctionType.LIBRARY,
            Pb.Function.TYPE_THUNK: FunctionType.THUNK,
        }

        return mapping.get(function_type, FunctionType.INVALID)

from_proto(function_type) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
156
157
158
159
160
161
162
163
164
165
166
167
168
@staticmethod
def from_proto(
    function_type: "Pb.Function.FunctionTypeValue",
) -> "FunctionType":
    """Convert the protobuf value into this enumeration"""
    mapping = {
        Pb.Function.TYPE_NORMAL: FunctionType.NORMAL,
        Pb.Function.TYPE_IMPORTED: FunctionType.IMPORTED,
        Pb.Function.TYPE_LIBRARY: FunctionType.LIBRARY,
        Pb.Function.TYPE_THUNK: FunctionType.THUNK,
    }

    return mapping.get(function_type, FunctionType.INVALID)

OperandType

Bases: Enum

Operand Type

Source code in bindings/python/quokka/types.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
class OperandType(enum.Enum):
    """Operand Type"""

    REGISTER = enum.auto()
    IMMEDIATE = enum.auto()
    MEMORY = enum.auto()
    OTHER = enum.auto()

    @staticmethod
    def from_proto(
        operand_type: "Pb.Operand.OperandType",
    ) -> "OperandType":
        """Convert the protobuf value into this enumeration"""
        mapping = {
            Pb.Operand.OPERAND_REGISTER: OperandType.REGISTER,
            Pb.Operand.OPERAND_IMMEDIATE: OperandType.IMMEDIATE,
            Pb.Operand.OPERAND_MEMORY: OperandType.MEMORY,
            Pb.Operand.OPERAND_OTHER: OperandType.OTHER,
        }

        return mapping.get(operand_type, OperandType.OTHER)

from_proto(operand_type) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
209
210
211
212
213
214
215
216
217
218
219
220
221
@staticmethod
def from_proto(
    operand_type: "Pb.Operand.OperandType",
) -> "OperandType":
    """Convert the protobuf value into this enumeration"""
    mapping = {
        Pb.Operand.OPERAND_REGISTER: OperandType.REGISTER,
        Pb.Operand.OPERAND_IMMEDIATE: OperandType.IMMEDIATE,
        Pb.Operand.OPERAND_MEMORY: OperandType.MEMORY,
        Pb.Operand.OPERAND_OTHER: OperandType.OTHER,
    }

    return mapping.get(operand_type, OperandType.OTHER)

Perm

Bases: IntFlag

Segment permissions

Source code in bindings/python/quokka/types.py
41
42
43
44
45
46
class Perm(enum.IntFlag):
    """Segment permissions"""

    R = 4
    W = 2
    X = 1

RefType

Bases: IntEnum

Reference Type

Source code in bindings/python/quokka/types.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
class RefType(enum.IntEnum):
    """Reference Type"""

    JMP_UNCOND = 0
    JMP_COND = 1
    JMP_INDIR = 2
    CALL = 3
    CALL_INDIR = 4
    DATA_READ = 5
    DATA_WRITE = 6
    DATA_INDIR = 7
    TYPE_SYMBOL = 8
    UNKNOWN = 9

    @staticmethod
    def from_proto(
        edge_type: "Pb.EdgeTypeValue",
    ) -> "RefType":
        """Convert the protobuf value into this enumeration"""
        try:
            return RefType(edge_type)
        except ValueError as e:
            raise ValueError("Unable to decode Edge Type") from e

    def to_proto(self) -> "Pb.EdgeTypeValue":
        """Convert this enumeration into the protobuf value"""
        return Pb.EdgeTypeValue(self.value)

    @property
    def is_dynamic(self) -> bool:
        """Returns True if this edge type is a dynamic reference (i.e. indirect jump or call)"""
        return self in {RefType.JMP_INDIR, RefType.CALL_INDIR}

    @property
    def is_call(self) -> bool:
        """Returns True if this edge type is a call reference"""
        return self in {RefType.CALL, RefType.CALL_INDIR}

    @property
    def is_code(self) -> bool:
        """Returns True if this edge type is a code reference"""
        return self in {RefType.JMP_UNCOND, RefType.JMP_COND, RefType.JMP_INDIR, RefType.CALL, RefType.CALL_INDIR}

    @property
    def is_data(self) -> bool:
        """Returns True if this edge type is a data reference"""
        return self in {RefType.DATA_READ, RefType.DATA_WRITE, RefType.DATA_INDIR}

is_call property

Returns True if this edge type is a call reference

is_code property

Returns True if this edge type is a code reference

is_data property

Returns True if this edge type is a data reference

is_dynamic property

Returns True if this edge type is a dynamic reference (i.e. indirect jump or call)

from_proto(edge_type) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
111
112
113
114
115
116
117
118
119
@staticmethod
def from_proto(
    edge_type: "Pb.EdgeTypeValue",
) -> "RefType":
    """Convert the protobuf value into this enumeration"""
    try:
        return RefType(edge_type)
    except ValueError as e:
        raise ValueError("Unable to decode Edge Type") from e

to_proto()

Convert this enumeration into the protobuf value

Source code in bindings/python/quokka/types.py
121
122
123
def to_proto(self) -> "Pb.EdgeTypeValue":
    """Convert this enumeration into the protobuf value"""
    return Pb.EdgeTypeValue(self.value)

SegmentType

Bases: Enum

Segment Type

Source code in bindings/python/quokka/types.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
class SegmentType(enum.Enum):
    """Segment Type"""

    UNKNOWN = enum.auto()
    CODE = enum.auto()
    DATA = enum.auto()
    BSS = enum.auto()
    NULL = enum.auto()
    EXTERN = enum.auto()
    NORMAL = enum.auto()
    ABSOLUTE_SYMBOLS = enum.auto()

    @staticmethod
    def from_proto(
        segment_type: "Pb.Segment.TypeValue",
    ) -> "SegmentType":
        """Convert the protobuf value into this enumeration"""
        mapping = {
            Pb.Segment.SEGMENT_CODE: SegmentType.CODE,
            Pb.Segment.SEGMENT_DATA: SegmentType.DATA,
            Pb.Segment.SEGMENT_BSS: SegmentType.BSS,
            Pb.Segment.SEGMENT_NULL: SegmentType.NULL,
            Pb.Segment.SEGMENT_NORMAL: SegmentType.NORMAL,
            Pb.Segment.SEGMENT_EXTERN: SegmentType.EXTERN,
            Pb.Segment.SEGMENT_ABSOLUTE_SYMBOLS: SegmentType.ABSOLUTE_SYMBOLS,
        }

        return mapping.get(segment_type, SegmentType.UNKNOWN)

from_proto(segment_type) staticmethod

Convert the protobuf value into this enumeration

Source code in bindings/python/quokka/types.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
@staticmethod
def from_proto(
    segment_type: "Pb.Segment.TypeValue",
) -> "SegmentType":
    """Convert the protobuf value into this enumeration"""
    mapping = {
        Pb.Segment.SEGMENT_CODE: SegmentType.CODE,
        Pb.Segment.SEGMENT_DATA: SegmentType.DATA,
        Pb.Segment.SEGMENT_BSS: SegmentType.BSS,
        Pb.Segment.SEGMENT_NULL: SegmentType.NULL,
        Pb.Segment.SEGMENT_NORMAL: SegmentType.NORMAL,
        Pb.Segment.SEGMENT_EXTERN: SegmentType.EXTERN,
        Pb.Segment.SEGMENT_ABSOLUTE_SYMBOLS: SegmentType.ABSOLUTE_SYMBOLS,
    }

    return mapping.get(segment_type, SegmentType.UNKNOWN)