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
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(improper_ctypes)]

use std::convert::From;
use std::fmt;
use std::mem::transmute;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

// It seems that bindgen fails to derive Debug, Clone and Copy for `cs_arm`. Let's implement them
// manually.
impl fmt::Debug for cs_arm {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let mut operands = String::new();
        for i in self.operands.iter() {
            operands.push_str(format!(" {:?}", i).as_str());
        }

        write!(f, "cs_arm {{ usermode: {:?}, vector_size: {:?}, vector_data: {:?}, \
            cps_mode: {:?}, cps_flag: {:?}, cc: {:?}, update_flags: {:?}, writeback: {:?}, \
            mem_barrier: {:?}, op_count: {:?},{}}}", self.usermode, self.vector_size,
            self.vector_data, self.cps_mode, self.cps_flag, self.cc, self.update_flags,
            self.writeback, self.mem_barrier, self.op_count, operands)
    }
}

impl Clone for cs_arm {
    fn clone(&self) -> cs_arm {
        *self
    }
}

impl Copy for cs_arm { }

// Operand enum getters.
impl cs_x86_op {
    pub fn reg(&self) -> &x86_reg {
        return unsafe { self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i64 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn fp(&self) -> f64 {
        return unsafe { *self.__bindgen_anon_1.fp.as_ref() };
    }
    pub fn mem(&self) -> &x86_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
}

impl cs_arm64_op {
    pub fn reg(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i64 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn fp(&self) -> f64 {
        return unsafe { *self.__bindgen_anon_1.fp.as_ref() };
    }
    pub fn mem(&self) -> &arm64_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
    pub fn pstate(&self) -> &arm64_pstate {
        return unsafe { self.__bindgen_anon_1.pstate.as_ref() };
    }
    pub fn sys(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.sys.as_ref() };
    }
    pub fn prefetch(&self) -> &arm64_prefetch_op {
        return unsafe { self.__bindgen_anon_1.prefetch.as_ref() };
    }
    pub fn barrier(&self) -> &arm64_barrier_op {
        return unsafe { self.__bindgen_anon_1.barrier.as_ref() };
    }

}

impl cs_arm_op {
    pub fn reg(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i32 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn fp(&self) -> f64 {
        return unsafe { *self.__bindgen_anon_1.fp.as_ref() };
    }
    pub fn mem(&self) -> &arm_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
    pub fn setend(&self) -> &arm_setend_type {
        return unsafe { self.__bindgen_anon_1.setend.as_ref() };
    }
}

impl cs_mips_op {
    pub fn reg(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i64 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn mem(&self) -> &mips_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
}

impl cs_ppc_op {
    pub fn reg(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i32 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn mem(&self) -> &ppc_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
    pub fn crx(&self) -> &ppc_op_crx {
        return unsafe { self.__bindgen_anon_1.crx.as_ref() };
    }
}

impl cs_sparc_op {
    pub fn reg(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i32 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn mem(&self) -> &sparc_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
}

impl cs_sysz_op {
    pub fn reg(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i64 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn mem(&self) -> &sysz_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
}

impl cs_xcore_op {
    pub fn reg(&self) -> u32 {
        return unsafe { *self.__bindgen_anon_1.reg.as_ref() };
    }
    pub fn imm(&self) -> i32 {
        return unsafe { *self.__bindgen_anon_1.imm.as_ref() };
    }
    pub fn mem(&self) -> &xcore_op_mem {
        return unsafe { self.__bindgen_anon_1.mem.as_ref() };
    }
}

// Register: enum <-> integer
impl From<u32> for x86_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl x86_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for arm64_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl arm64_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for arm_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl arm_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for mips_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl mips_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for ppc_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl ppc_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for sparc_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl sparc_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for sysz_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl sysz_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for xcore_reg {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl xcore_reg {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

// Groups: enum <-> integer.
impl From<u32> for x86_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl x86_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for arm64_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl arm64_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for arm_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl arm_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for mips_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl mips_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for ppc_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl ppc_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for sparc_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl sparc_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for sysz_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl sysz_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}

impl From<u32> for xcore_insn_group {
    fn from(i: u32) -> Self {
        return unsafe { transmute::<u32, Self>(i) }
    }
}
impl xcore_insn_group {
    pub fn as_int(&self) -> u32 {
        return unsafe { transmute::<Self, u32>(*self) }
    }
}