• 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 .arm64_const import *
6
7# define the API
8class Arm64OpMem(ctypes.Structure):
9    _fields_ = (
10        ('base', ctypes.c_uint),
11        ('index', ctypes.c_uint),
12        ('disp', ctypes.c_int32),
13    )
14
15class Arm64OpShift(ctypes.Structure):
16    _fields_ = (
17        ('type', ctypes.c_uint),
18        ('value', ctypes.c_uint),
19    )
20
21class Arm64OpValue(ctypes.Union):
22    _fields_ = (
23        ('reg', ctypes.c_uint),
24        ('imm', ctypes.c_int64),
25        ('fp', ctypes.c_double),
26        ('mem', Arm64OpMem),
27        ('pstate', ctypes.c_int),
28        ('sys', ctypes.c_uint),
29        ('prefetch', ctypes.c_int),
30        ('barrier', ctypes.c_int),
31    )
32
33class Arm64Op(ctypes.Structure):
34    _fields_ = (
35        ('vector_index', ctypes.c_int),
36        ('vas', ctypes.c_int),
37        ('vess', ctypes.c_int),
38        ('shift', Arm64OpShift),
39        ('ext', ctypes.c_uint),
40        ('type', ctypes.c_uint),
41        ('value', Arm64OpValue),
42    )
43
44    @property
45    def imm(self):
46        return self.value.imm
47
48    @property
49    def reg(self):
50        return self.value.reg
51
52    @property
53    def fp(self):
54        return self.value.fp
55
56    @property
57    def mem(self):
58        return self.value.mem
59
60    @property
61    def pstate(self):
62        return self.value.pstate
63
64    @property
65    def sys(self):
66        return self.value.sys
67
68    @property
69    def prefetch(self):
70        return self.value.prefetch
71
72    @property
73    def barrier(self):
74        return self.value.barrier
75
76
77
78class CsArm64(ctypes.Structure):
79    _fields_ = (
80        ('cc', ctypes.c_uint),
81        ('update_flags', ctypes.c_bool),
82        ('writeback', ctypes.c_bool),
83        ('op_count', ctypes.c_uint8),
84        ('operands', Arm64Op * 8),
85    )
86
87def get_arch_info(a):
88    return (a.cc, a.update_flags, a.writeback, copy_ctypes_list(a.operands[:a.op_count]))
89
90