• 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 .ppc_const import *
6
7# define the API
8class PpcOpMem(ctypes.Structure):
9    _fields_ = (
10        ('base', ctypes.c_uint),
11        ('disp', ctypes.c_int32),
12    )
13
14class PpcOpCrx(ctypes.Structure):
15    _fields_ = (
16        ('scale', ctypes.c_uint),
17        ('reg', ctypes.c_uint),
18        ('cond', ctypes.c_uint),
19    )
20
21class PpcOpValue(ctypes.Union):
22    _fields_ = (
23        ('reg', ctypes.c_uint),
24        ('imm', ctypes.c_int32),
25        ('mem', PpcOpMem),
26        ('crx', PpcOpCrx),
27    )
28
29class PpcOp(ctypes.Structure):
30    _fields_ = (
31        ('type', ctypes.c_uint),
32        ('value', PpcOpValue),
33    )
34
35    @property
36    def imm(self):
37        return self.value.imm
38
39    @property
40    def reg(self):
41        return self.value.reg
42
43    @property
44    def mem(self):
45        return self.value.mem
46
47    @property
48    def crx(self):
49        return self.value.crx
50
51
52class CsPpc(ctypes.Structure):
53    _fields_ = (
54        ('bc', ctypes.c_uint),
55        ('bh', ctypes.c_uint),
56        ('update_cr0', ctypes.c_bool),
57        ('op_count', ctypes.c_uint8),
58        ('operands', PpcOp * 8),
59    )
60
61def get_arch_info(a):
62    return (a.bc, a.bh, a.update_cr0, copy_ctypes_list(a.operands[:a.op_count]))
63
64