Rizin
unix-like reverse engineering framework and cli tools
x86.py
Go to the documentation of this file.
1 # Capstone Python bindings, by Nguyen Anh Quynnh <aquynh@gmail.com>
2 
3 import ctypes
4 from . import copy_ctypes_list
5 from .x86_const import *
6 
7 # define the API
8 class X86OpMem(ctypes.Structure):
9  _fields_ = (
10  ('segment', ctypes.c_uint),
11  ('base', ctypes.c_uint),
12  ('index', ctypes.c_uint),
13  ('scale', ctypes.c_int),
14  ('disp', ctypes.c_int64),
15  )
16 
17 class X86OpValue(ctypes.Union):
18  _fields_ = (
19  ('reg', ctypes.c_uint),
20  ('imm', ctypes.c_int64),
21  ('mem', X86OpMem),
22  )
23 
24 class X86Op(ctypes.Structure):
25  _fields_ = (
26  ('type', ctypes.c_uint),
27  ('value', X86OpValue),
28  ('size', ctypes.c_uint8),
29  ('access', ctypes.c_uint8),
30  ('avx_bcast', ctypes.c_uint),
31  ('avx_zero_opmask', ctypes.c_bool),
32  )
33 
34  @property
35  def imm(self):
36  return self.value.imm
37 
38  @property
39  def reg(self):
40  return self.value.reg
41 
42  @property
43  def mem(self):
44  return self.value.mem
45 
46 
47 class CsX86Encoding(ctypes.Structure):
48  _fields_ = (
49  ('modrm_offset', ctypes.c_uint8),
50  ('disp_offset', ctypes.c_uint8),
51  ('disp_size', ctypes.c_uint8),
52  ('imm_offset', ctypes.c_uint8),
53  ('imm_size', ctypes.c_uint8),
54  )
55 
56 class CsX86(ctypes.Structure):
57  _fields_ = (
58  ('prefix', ctypes.c_uint8 * 4),
59  ('opcode', ctypes.c_uint8 * 4),
60  ('rex', ctypes.c_uint8),
61  ('addr_size', ctypes.c_uint8),
62  ('modrm', ctypes.c_uint8),
63  ('sib', ctypes.c_uint8),
64  ('disp', ctypes.c_int64),
65  ('sib_index', ctypes.c_uint),
66  ('sib_scale', ctypes.c_int8),
67  ('sib_base', ctypes.c_uint),
68  ('xop_cc', ctypes.c_uint),
69  ('sse_cc', ctypes.c_uint),
70  ('avx_cc', ctypes.c_uint),
71  ('avx_sae', ctypes.c_bool),
72  ('avx_rm', ctypes.c_uint),
73  ('eflags', ctypes.c_uint64),
74  ('op_count', ctypes.c_uint8),
75  ('operands', X86Op * 8),
76  ('encoding', CsX86Encoding),
77  )
78 
80  return (a.prefix[:], a.opcode[:], a.rex, a.addr_size, \
81  a.modrm, a.sib, a.disp, a.sib_index, a.sib_scale, \
82  a.sib_base, a.xop_cc, a.sse_cc, a.avx_cc, a.avx_sae, a.avx_rm, a.eflags, \
83  a.encoding.modrm_offset, a.encoding.disp_offset, a.encoding.disp_size, a.encoding.imm_offset, a.encoding.imm_size, \
84  copy_ctypes_list(a.operands[:a.op_count]))
85 
def imm(self)
Definition: x86.py:35
def reg(self)
Definition: x86.py:39
def mem(self)
Definition: x86.py:43
def get_arch_info(a)
Definition: x86.py:79
def copy_ctypes_list(src)
Definition: __init__.py:326