• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
2
3import ctypes
4from . import copy_ctypes_list
5from .sysz_const import *
6
7# define the API
8class SyszOpMem(ctypes.Structure):
9    _fields_ = (
10        ('base', ctypes.c_uint8),
11        ('index', ctypes.c_uint8),
12        ('length', ctypes.c_uint64),
13        ('disp', ctypes.c_int64),
14    )
15
16class SyszOpValue(ctypes.Union):
17    _fields_ = (
18        ('reg', ctypes.c_uint),
19        ('imm', ctypes.c_int64),
20        ('mem', SyszOpMem),
21    )
22
23class SyszOp(ctypes.Structure):
24    _fields_ = (
25        ('type', ctypes.c_uint),
26        ('value', SyszOpValue),
27    )
28
29    @property
30    def imm(self):
31        return self.value.imm
32
33    @property
34    def reg(self):
35        return self.value.reg
36
37    @property
38    def mem(self):
39        return self.value.mem
40
41
42class CsSysz(ctypes.Structure):
43    _fields_ = (
44        ('cc', ctypes.c_uint),
45        ('op_count', ctypes.c_uint8),
46        ('operands', SyszOp * 6),
47    )
48
49def get_arch_info(a):
50    return (a.cc, copy_ctypes_list(a.operands[:a.op_count]))
51
52