• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Capstone Python bindings, by Wolfgang Schwotzer <wolfgang.schwotzer@gmx.net>
2
3import ctypes
4from . import copy_ctypes_list
5from .m680x_const import *
6
7# define the API
8class M680xOpIdx(ctypes.Structure):
9    _fields_ = (
10        ('base_reg', ctypes.c_uint),
11        ('offset_reg', ctypes.c_uint),
12        ('offset', ctypes.c_int16),
13        ('offset_addr', ctypes.c_uint16),
14        ('offset_bits', ctypes.c_uint8),
15        ('inc_dec', ctypes.c_int8),
16        ('flags', ctypes.c_uint8),
17    )
18
19class M680xOpRel(ctypes.Structure):
20    _fields_ = (
21        ('address', ctypes.c_uint16),
22        ('offset', ctypes.c_int16),
23    )
24
25class M680xOpExt(ctypes.Structure):
26    _fields_ = (
27        ('address', ctypes.c_uint16),
28        ('indirect', ctypes.c_bool),
29    )
30
31class M680xOpValue(ctypes.Union):
32    _fields_ = (
33        ('imm', ctypes.c_int32),
34        ('reg', ctypes.c_uint),
35        ('idx', M680xOpIdx),
36        ('rel', M680xOpRel),
37        ('ext', M680xOpExt),
38        ('direct_addr', ctypes.c_uint8),
39        ('const_val', ctypes.c_uint8),
40    )
41
42class M680xOp(ctypes.Structure):
43    _fields_ = (
44        ('type', ctypes.c_uint),
45        ('value', M680xOpValue),
46        ('size', ctypes.c_uint8),
47        ('access', ctypes.c_uint8),
48    )
49
50    @property
51    def imm(self):
52        return self.value.imm
53
54    @property
55    def reg(self):
56        return self.value.reg
57
58    @property
59    def idx(self):
60        return self.value.idx
61
62    @property
63    def rel(self):
64        return self.value.rel
65
66    @property
67    def ext(self):
68        return self.value.ext
69
70    @property
71    def direct_addr(self):
72        return self.value.direct_addr
73
74    @property
75    def const_val(self):
76        return self.value.const_val
77
78
79class CsM680x(ctypes.Structure):
80    _fields_ = (
81        ('flags', ctypes.c_uint8),
82        ('op_count', ctypes.c_uint8),
83        ('operands', M680xOp * 9),
84    )
85
86def get_arch_info(a):
87    return (a.flags, copy_ctypes_list(a.operands[:a.op_count]))
88
89