Home | History | Annotate | Download | only in capstone
      1 # Capstone Python bindings, by Nguyen Anh Quynnh <aquynh (at] 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         ('fp', ctypes.c_double),
     22         ('mem', X86OpMem),
     23     )
     24 
     25 class X86Op(ctypes.Structure):
     26     _fields_ = (
     27         ('type', ctypes.c_uint),
     28         ('value', X86OpValue),
     29         ('size', 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 fp(self):
     44         return self.value.fp
     45 
     46     @property
     47     def mem(self):
     48         return self.value.mem
     49 
     50 
     51 class CsX86(ctypes.Structure):
     52     _fields_ = (
     53         ('prefix', ctypes.c_uint8 * 4),
     54         ('opcode', ctypes.c_uint8 * 4),
     55         ('rex', ctypes.c_uint8),
     56         ('addr_size', ctypes.c_uint8),
     57         ('modrm', ctypes.c_uint8),
     58         ('sib', ctypes.c_uint8),
     59         ('disp', ctypes.c_int32),
     60         ('sib_index', ctypes.c_uint),
     61         ('sib_scale', ctypes.c_int8),
     62         ('sib_base', ctypes.c_uint),
     63         ('sse_cc', ctypes.c_uint),
     64         ('avx_cc', ctypes.c_uint),
     65         ('avx_sae', ctypes.c_bool),
     66         ('avx_rm', ctypes.c_uint),
     67         ('op_count', ctypes.c_uint8),
     68         ('operands', X86Op * 8),
     69     )
     70 
     71 def get_arch_info(a):
     72     return (a.prefix[:], a.opcode[:], a.rex, a.addr_size, \
     73             a.modrm, a.sib, a.disp, a.sib_index, a.sib_scale, \
     74             a.sib_base, a.sse_cc, a.avx_cc, a.avx_sae, a.avx_rm, \
     75             copy_ctypes_list(a.operands[:a.op_count]))
     76 
     77