libsla 0.4.3

Rust bindings to Ghidra Sleigh library libsla
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
64
65
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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
//! The opcode for a p-code instruction determines the semantics of the instruction. The [OpCode]
//! enum contains the full list of possible opcodes. However, the [AnalysisOp] opcodes are only
//! ever emitted by analysis programs; they are not permitted in Sleigh processor specifications.
//! The [PseudoOp] opcodes may be emitted but do not have fully defined semantics.
use libsla_sys::sys;

/// A representation of opcodes for p-code instructions.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum OpCode {
    /// Copy a sequence of bytes from one fixed location to another.
    Copy,

    /// Load a sequence of bytes from a dynamic location to a fixed location.
    Load,

    /// Store a sequence of bytes from a fixed location to a dynamic location.
    Store,

    /// Jump to a fixed destination. The destination may be an absolute address or a relative
    /// p-code address for the current instruction.
    Branch,

    /// Jump to a fixed destination based on a condition. See [OpCode::Branch] for details on
    /// an explanation on possible destinations.
    BranchConditional,

    /// Jump to a dynamic destination.
    BranchIndirect,

    /// Semantically identical to [OpCode::Branch] but is used as a hint to analysis programs.
    Call,

    /// Semantically identical to [OpCode::BranchIndirect] but is used as a hint to analysis programs.
    CallIndirect,

    /// Semantically identical to [OpCode::BranchIndirect] but is used as a hint to analysis programs.
    Return,

    /// Concatenates two inputs together: `x:y`.
    Piece,

    /// Truncates an input: `x:y => x`.
    Subpiece,

    /// Counts the number of bits set in an input.
    Popcount,

    /// Count the number of leading 0-bits
    LzCount,

    /// Operations which operate on boolean (single bit) inputs.
    Bool(BoolOp),

    /// Operations which operate on integers.
    Int(IntOp),

    /// Operations which operate on floating-point numbers.
    Float(FloatOp),

    /// A pseudo operation.
    Pseudo(PseudoOp),

    /// An operation produced by analysis.
    Analysis(AnalysisOp),

    /// An unknown operation that holds the raw opcode.
    Unknown(i32),
}

/// Operations for boolean, single-bit inputs.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum BoolOp {
    /// Negate a single bit: `!x`.
    Negate,

    /// The and operation of two bits: `x & y`.
    And,

    /// The inclusive-or of two bits: `x | y`.
    Or,

    /// The exclusive-or of two bits: `x ^ y`.
    Xor,
}

/// Indicates whether an integer operation is operating on signed or unsigned inputs. If the
/// operation does not include `IntSign` as an argument, then distinguishing between signed and
/// unsigned is not applicable for the operation.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum IntSign {
    /// An integer where the most significant bit (msb) indicates the sign of the integer. The integer is
    /// positive if the msb is `0` and negative if the msb is `1`. Signed integers are represented
    /// using the two's complement encoding.
    Signed,

    /// An integer that does not have a sign bit and therefore cannot be negative.
    Unsigned,
}

/// Operations on integers.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum IntOp {
    /// Add two integers: `x + y`.
    Add,

    /// Negate an integer by converting it to its two's complement: `-x`.
    Negate,

    /// Subtract two integers: `x - y`.
    Subtract,

    /// Multiply two integers: `x * y`.
    Multiply,

    /// Divide two integers: `x / y`.
    Divide(IntSign),

    /// The remainder from integer division: `x % y`.
    Remainder(IntSign),

    /// Check if two integers are equal: `x == y`.
    Equal,

    /// Check if two integers are not equal: `x != y`.
    NotEqual,

    /// Check if an integer is less than another: `x < y`.
    LessThan(IntSign),

    /// Check if an integer is less than or equal to another: `x <= y`.
    LessThanOrEqual(IntSign),

    /// Extend an integer with additional bits. Extends with zero bits if unsigned and with the
    /// sign bit if the integer is signed.
    Extension(IntSign),

    /// The carry flag for an addition indicating an overflow would occur.
    Carry(IntSign),

    /// The borrow flag for a subtraction indicating an overflow would occur. The inputs for this
    /// operation are always signed. The equivalent unsigned check is
    /// `LessThan(IntSign::Unsigned)`.
    Borrow,

    /// Shift the integer left by some number of bits: x << y.
    ShiftLeft,

    /// Shift the integer right by some number of bits: x >> y. A signed shift right will shift in
    /// the sign bit of `x` instead of zero.
    ShiftRight(IntSign),

    /// Bitwise boolean operations applied to each bit of the integer.
    Bitwise(BoolOp),
}

/// Operations on floating-point numbers.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum FloatOp {
    /// Check if two numbers are equal: `x == y`.
    Equal,

    /// Check if two numbers are not equal: `x != `y.
    NotEqual,

    /// Check if a number is less than another: `x < y`
    LessThan,

    /// Check if a number is less than or equal to another: `x <= y`
    LessThanOrEqual,

    /// Check if a number is interpreted as NaN.
    IsNaN,

    /// Add two numbers: `x + y`.
    Add,

    /// Subtract two numbers: `x - y`.
    Subtract,

    /// Multiply two numbers: `x + y`.
    Multiply,

    /// Divide two numbers: `x / y`.
    Divide,

    /// Negate a number: `-x`.
    Negate,

    /// Take the absolute value of a number: `|x|`.
    AbsoluteValue,

    /// Take the square root of a number: `x`<sup>0.5</sup>.
    SquareRoot,

    /// Convert an integer to a floating point number.
    IntToFloat,

    /// Convert a floating point number to another with different precision.
    FloatToFloat,

    /// Convert a floating point number to an integer.
    Truncate,

    /// Round a number towards positive infinity.
    Ceiling,

    /// Round a number towards negative infinity.
    Floor,

    /// Round a number to the closest integral value.
    Round,
}

/// Operations which represent black-box placeholders for some sequence of changes to the machine state.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum PseudoOp {
    /// A call that cannot be semantically represented in p-code. For example, a syscall.
    CallOther,

    /// Returns specific run-time dependent values from the constant pool. Used by object-oriented
    /// instruction sets and other managed code environments.
    ConstantPoolRef,

    /// Allocates memory for an object or set of objects.
    New,
}

/// Operations which are only generated by analysis programs. These operations are not permitted
/// for use in processor specifications and therefore will never be emitted when directly
/// translating machine instructions.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum AnalysisOp {
    /// Copies a sequence of bytes to a fixed location. There are multiple origins possible for the
    /// bytes. The selected origin depends on the execution path leading to this operation.
    MultiEqual,

    /// Copies a sequence of bytes to a fixed location. However, the value may be altered
    /// indirectly by another operation referenced by this one.
    CopyIndirect,

    /// Add an offset to a pointer: `(p + i)`
    PointerAdd,

    /// Access a subcomponent of a pointer: `p->x`.
    PointerSubcomponent,

    /// Identical to a [OpCode::Copy]. This operation is a signal that the output data-type
    /// interpretation has changed.
    Cast,

    /// Insert bits from one input into the section of another: `x[8..16] = y`
    Insert,

    /// Extract bits from the section of an input and copy them to another: `y = x[8..16]`.
    Extract,

    /// A placeholder for address mappings involving segments.
    SegmentOp,
}

impl From<sys::OpCode> for OpCode {
    fn from(value: sys::OpCode) -> Self {
        match value {
            sys::OpCode::CPUI_COPY => OpCode::Copy,
            sys::OpCode::CPUI_LOAD => OpCode::Load,
            sys::OpCode::CPUI_STORE => OpCode::Store,
            sys::OpCode::CPUI_BRANCH => OpCode::Branch,
            sys::OpCode::CPUI_CBRANCH => OpCode::BranchConditional,
            sys::OpCode::CPUI_BRANCHIND => OpCode::BranchIndirect,
            sys::OpCode::CPUI_CALL => OpCode::Call,
            sys::OpCode::CPUI_CALLIND => OpCode::CallIndirect,
            sys::OpCode::CPUI_CALLOTHER => OpCode::Pseudo(PseudoOp::CallOther),
            sys::OpCode::CPUI_RETURN => OpCode::Return,
            sys::OpCode::CPUI_INT_EQUAL => OpCode::Int(IntOp::Equal),
            sys::OpCode::CPUI_INT_NOTEQUAL => OpCode::Int(IntOp::NotEqual),
            sys::OpCode::CPUI_INT_SLESS => OpCode::Int(IntOp::LessThan(IntSign::Signed)),
            sys::OpCode::CPUI_INT_SLESSEQUAL => {
                OpCode::Int(IntOp::LessThanOrEqual(IntSign::Signed))
            }
            sys::OpCode::CPUI_INT_LESS => OpCode::Int(IntOp::LessThan(IntSign::Unsigned)),
            sys::OpCode::CPUI_INT_LESSEQUAL => {
                OpCode::Int(IntOp::LessThanOrEqual(IntSign::Unsigned))
            }
            sys::OpCode::CPUI_INT_ZEXT => OpCode::Int(IntOp::Extension(IntSign::Unsigned)),
            sys::OpCode::CPUI_INT_SEXT => OpCode::Int(IntOp::Extension(IntSign::Signed)),
            sys::OpCode::CPUI_INT_ADD => OpCode::Int(IntOp::Add),
            sys::OpCode::CPUI_INT_SUB => OpCode::Int(IntOp::Subtract),
            sys::OpCode::CPUI_INT_CARRY => OpCode::Int(IntOp::Carry(IntSign::Unsigned)),
            sys::OpCode::CPUI_INT_SCARRY => OpCode::Int(IntOp::Carry(IntSign::Signed)),
            sys::OpCode::CPUI_INT_SBORROW => OpCode::Int(IntOp::Borrow),
            sys::OpCode::CPUI_INT_2COMP => OpCode::Int(IntOp::Negate),
            sys::OpCode::CPUI_INT_NEGATE => OpCode::Int(IntOp::Bitwise(BoolOp::Negate)),
            sys::OpCode::CPUI_INT_XOR => OpCode::Int(IntOp::Bitwise(BoolOp::Xor)),
            sys::OpCode::CPUI_INT_AND => OpCode::Int(IntOp::Bitwise(BoolOp::And)),
            sys::OpCode::CPUI_INT_OR => OpCode::Int(IntOp::Bitwise(BoolOp::Or)),
            sys::OpCode::CPUI_INT_LEFT => OpCode::Int(IntOp::ShiftLeft),
            sys::OpCode::CPUI_INT_RIGHT => OpCode::Int(IntOp::ShiftRight(IntSign::Unsigned)),
            sys::OpCode::CPUI_INT_SRIGHT => OpCode::Int(IntOp::ShiftRight(IntSign::Signed)),
            sys::OpCode::CPUI_INT_MULT => OpCode::Int(IntOp::Multiply),
            sys::OpCode::CPUI_INT_DIV => OpCode::Int(IntOp::Divide(IntSign::Unsigned)),
            sys::OpCode::CPUI_INT_SDIV => OpCode::Int(IntOp::Divide(IntSign::Signed)),
            sys::OpCode::CPUI_INT_REM => OpCode::Int(IntOp::Remainder(IntSign::Unsigned)),
            sys::OpCode::CPUI_INT_SREM => OpCode::Int(IntOp::Remainder(IntSign::Signed)),
            sys::OpCode::CPUI_BOOL_NEGATE => OpCode::Bool(BoolOp::Negate),
            sys::OpCode::CPUI_BOOL_XOR => OpCode::Bool(BoolOp::Xor),
            sys::OpCode::CPUI_BOOL_AND => OpCode::Bool(BoolOp::And),
            sys::OpCode::CPUI_BOOL_OR => OpCode::Bool(BoolOp::Or),
            sys::OpCode::CPUI_FLOAT_EQUAL => OpCode::Float(FloatOp::Equal),
            sys::OpCode::CPUI_FLOAT_NOTEQUAL => OpCode::Float(FloatOp::NotEqual),
            sys::OpCode::CPUI_FLOAT_LESS => OpCode::Float(FloatOp::LessThan),
            sys::OpCode::CPUI_FLOAT_LESSEQUAL => OpCode::Float(FloatOp::LessThanOrEqual),
            sys::OpCode::CPUI_FLOAT_NAN => OpCode::Float(FloatOp::IsNaN),
            sys::OpCode::CPUI_FLOAT_ADD => OpCode::Float(FloatOp::Add),
            sys::OpCode::CPUI_FLOAT_DIV => OpCode::Float(FloatOp::Divide),
            sys::OpCode::CPUI_FLOAT_MULT => OpCode::Float(FloatOp::Multiply),
            sys::OpCode::CPUI_FLOAT_SUB => OpCode::Float(FloatOp::Subtract),
            sys::OpCode::CPUI_FLOAT_NEG => OpCode::Float(FloatOp::Negate),
            sys::OpCode::CPUI_FLOAT_ABS => OpCode::Float(FloatOp::AbsoluteValue),
            sys::OpCode::CPUI_FLOAT_SQRT => OpCode::Float(FloatOp::SquareRoot),
            sys::OpCode::CPUI_FLOAT_INT2FLOAT => OpCode::Float(FloatOp::IntToFloat),
            sys::OpCode::CPUI_FLOAT_FLOAT2FLOAT => OpCode::Float(FloatOp::FloatToFloat),
            sys::OpCode::CPUI_FLOAT_TRUNC => OpCode::Float(FloatOp::Truncate),
            sys::OpCode::CPUI_FLOAT_CEIL => OpCode::Float(FloatOp::Ceiling),
            sys::OpCode::CPUI_FLOAT_FLOOR => OpCode::Float(FloatOp::Floor),
            sys::OpCode::CPUI_FLOAT_ROUND => OpCode::Float(FloatOp::Round),

            sys::OpCode::CPUI_MULTIEQUAL => OpCode::Analysis(AnalysisOp::MultiEqual),
            sys::OpCode::CPUI_INDIRECT => OpCode::Analysis(AnalysisOp::CopyIndirect),
            sys::OpCode::CPUI_PIECE => OpCode::Piece,
            sys::OpCode::CPUI_SUBPIECE => OpCode::Subpiece,

            sys::OpCode::CPUI_CAST => OpCode::Analysis(AnalysisOp::Cast),
            sys::OpCode::CPUI_PTRADD => OpCode::Analysis(AnalysisOp::PointerAdd),
            sys::OpCode::CPUI_PTRSUB => OpCode::Analysis(AnalysisOp::PointerSubcomponent),
            sys::OpCode::CPUI_SEGMENTOP => OpCode::Analysis(AnalysisOp::SegmentOp),
            sys::OpCode::CPUI_CPOOLREF => OpCode::Pseudo(PseudoOp::ConstantPoolRef),
            sys::OpCode::CPUI_NEW => OpCode::Pseudo(PseudoOp::New),
            sys::OpCode::CPUI_INSERT => OpCode::Analysis(AnalysisOp::Insert),
            sys::OpCode::CPUI_EXTRACT => OpCode::Analysis(AnalysisOp::Extract),
            sys::OpCode::CPUI_POPCOUNT => OpCode::Popcount,
            sys::OpCode::CPUI_LZCOUNT => OpCode::LzCount,
            sys::OpCode { repr } => OpCode::Unknown(repr),
        }
    }
}

impl From<OpCode> for sys::OpCode {
    fn from(value: OpCode) -> Self {
        match value {
            OpCode::Copy => sys::OpCode::CPUI_COPY,
            OpCode::Load => sys::OpCode::CPUI_LOAD,
            OpCode::Store => sys::OpCode::CPUI_STORE,
            OpCode::Branch => sys::OpCode::CPUI_BRANCH,
            OpCode::BranchConditional => sys::OpCode::CPUI_CBRANCH,
            OpCode::BranchIndirect => sys::OpCode::CPUI_BRANCHIND,
            OpCode::Call => sys::OpCode::CPUI_CALL,
            OpCode::CallIndirect => sys::OpCode::CPUI_CALLIND,
            OpCode::Return => sys::OpCode::CPUI_RETURN,
            OpCode::Subpiece => sys::OpCode::CPUI_SUBPIECE,
            OpCode::Piece => sys::OpCode::CPUI_PIECE,
            OpCode::Popcount => sys::OpCode::CPUI_POPCOUNT,
            OpCode::LzCount => sys::OpCode::CPUI_LZCOUNT,
            OpCode::Bool(BoolOp::Negate) => sys::OpCode::CPUI_BOOL_NEGATE,
            OpCode::Bool(BoolOp::Xor) => sys::OpCode::CPUI_BOOL_XOR,
            OpCode::Bool(BoolOp::And) => sys::OpCode::CPUI_BOOL_AND,
            OpCode::Bool(BoolOp::Or) => sys::OpCode::CPUI_BOOL_OR,
            OpCode::Int(IntOp::Equal) => sys::OpCode::CPUI_INT_EQUAL,
            OpCode::Int(IntOp::NotEqual) => sys::OpCode::CPUI_INT_NOTEQUAL,
            OpCode::Int(IntOp::LessThan(IntSign::Signed)) => sys::OpCode::CPUI_INT_SLESS,
            OpCode::Int(IntOp::LessThanOrEqual(IntSign::Signed)) => {
                sys::OpCode::CPUI_INT_SLESSEQUAL
            }
            OpCode::Int(IntOp::LessThan(IntSign::Unsigned)) => sys::OpCode::CPUI_INT_LESS,
            OpCode::Int(IntOp::LessThanOrEqual(IntSign::Unsigned)) => {
                sys::OpCode::CPUI_INT_LESSEQUAL
            }
            OpCode::Int(IntOp::Extension(IntSign::Unsigned)) => sys::OpCode::CPUI_INT_ZEXT,
            OpCode::Int(IntOp::Extension(IntSign::Signed)) => sys::OpCode::CPUI_INT_SEXT,
            OpCode::Int(IntOp::Add) => sys::OpCode::CPUI_INT_ADD,
            OpCode::Int(IntOp::Subtract) => sys::OpCode::CPUI_INT_SUB,
            OpCode::Int(IntOp::Carry(IntSign::Unsigned)) => sys::OpCode::CPUI_INT_CARRY,
            OpCode::Int(IntOp::Carry(IntSign::Signed)) => sys::OpCode::CPUI_INT_SCARRY,
            OpCode::Int(IntOp::Borrow) => sys::OpCode::CPUI_INT_SBORROW,
            OpCode::Int(IntOp::Negate) => sys::OpCode::CPUI_INT_2COMP,
            OpCode::Int(IntOp::Bitwise(BoolOp::Negate)) => sys::OpCode::CPUI_INT_NEGATE,
            OpCode::Int(IntOp::Bitwise(BoolOp::Xor)) => sys::OpCode::CPUI_INT_XOR,
            OpCode::Int(IntOp::Bitwise(BoolOp::And)) => sys::OpCode::CPUI_INT_AND,
            OpCode::Int(IntOp::Bitwise(BoolOp::Or)) => sys::OpCode::CPUI_INT_OR,
            OpCode::Int(IntOp::ShiftLeft) => sys::OpCode::CPUI_INT_LEFT,
            OpCode::Int(IntOp::ShiftRight(IntSign::Unsigned)) => sys::OpCode::CPUI_INT_RIGHT,
            OpCode::Int(IntOp::ShiftRight(IntSign::Signed)) => sys::OpCode::CPUI_INT_SRIGHT,
            OpCode::Int(IntOp::Multiply) => sys::OpCode::CPUI_INT_MULT,
            OpCode::Int(IntOp::Divide(IntSign::Unsigned)) => sys::OpCode::CPUI_INT_DIV,
            OpCode::Int(IntOp::Divide(IntSign::Signed)) => sys::OpCode::CPUI_INT_SDIV,
            OpCode::Int(IntOp::Remainder(IntSign::Unsigned)) => sys::OpCode::CPUI_INT_REM,
            OpCode::Int(IntOp::Remainder(IntSign::Signed)) => sys::OpCode::CPUI_INT_SREM,
            OpCode::Float(FloatOp::Equal) => sys::OpCode::CPUI_FLOAT_EQUAL,
            OpCode::Float(FloatOp::NotEqual) => sys::OpCode::CPUI_FLOAT_NOTEQUAL,
            OpCode::Float(FloatOp::LessThan) => sys::OpCode::CPUI_FLOAT_LESS,
            OpCode::Float(FloatOp::LessThanOrEqual) => sys::OpCode::CPUI_FLOAT_LESSEQUAL,
            OpCode::Float(FloatOp::IsNaN) => sys::OpCode::CPUI_FLOAT_NAN,
            OpCode::Float(FloatOp::Add) => sys::OpCode::CPUI_FLOAT_ADD,
            OpCode::Float(FloatOp::Divide) => sys::OpCode::CPUI_FLOAT_DIV,
            OpCode::Float(FloatOp::Multiply) => sys::OpCode::CPUI_FLOAT_MULT,
            OpCode::Float(FloatOp::Subtract) => sys::OpCode::CPUI_FLOAT_SUB,
            OpCode::Float(FloatOp::Negate) => sys::OpCode::CPUI_FLOAT_NEG,
            OpCode::Float(FloatOp::AbsoluteValue) => sys::OpCode::CPUI_FLOAT_ABS,
            OpCode::Float(FloatOp::SquareRoot) => sys::OpCode::CPUI_FLOAT_SQRT,
            OpCode::Float(FloatOp::IntToFloat) => sys::OpCode::CPUI_FLOAT_INT2FLOAT,
            OpCode::Float(FloatOp::FloatToFloat) => sys::OpCode::CPUI_FLOAT_FLOAT2FLOAT,
            OpCode::Float(FloatOp::Truncate) => sys::OpCode::CPUI_FLOAT_TRUNC,
            OpCode::Float(FloatOp::Ceiling) => sys::OpCode::CPUI_FLOAT_CEIL,
            OpCode::Float(FloatOp::Floor) => sys::OpCode::CPUI_FLOAT_FLOOR,
            OpCode::Float(FloatOp::Round) => sys::OpCode::CPUI_FLOAT_ROUND,
            OpCode::Pseudo(PseudoOp::CallOther) => sys::OpCode::CPUI_CALLOTHER,
            OpCode::Pseudo(PseudoOp::ConstantPoolRef) => sys::OpCode::CPUI_CPOOLREF,
            OpCode::Pseudo(PseudoOp::New) => sys::OpCode::CPUI_NEW,
            OpCode::Analysis(AnalysisOp::MultiEqual) => sys::OpCode::CPUI_MULTIEQUAL,
            OpCode::Analysis(AnalysisOp::CopyIndirect) => sys::OpCode::CPUI_INDIRECT,
            OpCode::Analysis(AnalysisOp::Cast) => sys::OpCode::CPUI_CAST,
            OpCode::Analysis(AnalysisOp::PointerAdd) => sys::OpCode::CPUI_PTRADD,
            OpCode::Analysis(AnalysisOp::PointerSubcomponent) => sys::OpCode::CPUI_PTRSUB,
            OpCode::Analysis(AnalysisOp::SegmentOp) => sys::OpCode::CPUI_SEGMENTOP,
            OpCode::Analysis(AnalysisOp::Insert) => sys::OpCode::CPUI_INSERT,
            OpCode::Analysis(AnalysisOp::Extract) => sys::OpCode::CPUI_EXTRACT,
            OpCode::Unknown(_) => sys::OpCode::CPUI_MAX,
        }
    }
}