1# Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
2
3import ctypes
4from . import copy_ctypes_list
5from .arm_const import *
6
7# define the API
8class ArmOpMem(ctypes.Structure):
9    _fields_ = (
10        ('base', ctypes.c_uint),
11        ('index', ctypes.c_uint),
12        ('scale', ctypes.c_int),
13        ('disp', ctypes.c_int),
14    )
15
16class ArmOpShift(ctypes.Structure):
17    _fields_ = (
18        ('type', ctypes.c_uint),
19        ('value', ctypes.c_uint),
20    )
21
22class ArmOpValue(ctypes.Union):
23    _fields_ = (
24        ('reg', ctypes.c_uint),
25        ('imm', ctypes.c_int32),
26        ('fp', ctypes.c_double),
27        ('mem', ArmOpMem),
28        ('setend', ctypes.c_int),
29    )
30
31class ArmOp(ctypes.Structure):
32    _fields_ = (
33        ('vector_index', ctypes.c_int),
34        ('shift', ArmOpShift),
35        ('type', ctypes.c_uint),
36        ('value', ArmOpValue),
37        ('subtracted', ctypes.c_bool),
38    )
39
40    @property
41    def imm(self):
42        return self.value.imm
43
44    @property
45    def reg(self):
46        return self.value.reg
47
48    @property
49    def fp(self):
50        return self.value.fp
51
52    @property
53    def mem(self):
54        return self.value.mem
55
56    @property
57    def setend(self):
58        return self.value.setend
59
60
61class CsArm(ctypes.Structure):
62    _fields_ = (
63        ('usermode', ctypes.c_bool),
64        ('vector_size', ctypes.c_int),
65        ('vector_data', ctypes.c_int),
66        ('cps_mode', ctypes.c_int),
67        ('cps_flag', ctypes.c_int),
68        ('cc', ctypes.c_uint),
69        ('update_flags', ctypes.c_bool),
70        ('writeback', ctypes.c_bool),
71        ('mem_barrier', ctypes.c_int),
72        ('op_count', ctypes.c_uint8),
73        ('operands', ArmOp * 36),
74    )
75
76def get_arch_info(a):
77    return (a.usermode, a.vector_size, a.vector_data, a.cps_mode, a.cps_flag, a.cc, a.update_flags, \
78        a.writeback, a.mem_barrier, copy_ctypes_list(a.operands[:a.op_count]))
79
80