1# Capstone Python bindings, by Fotis Loukos <[email protected]> 2 3import ctypes, copy 4from .tms320c64x_const import * 5 6# define the API 7class TMS320C64xOpMem(ctypes.Structure): 8 _fields_ = ( 9 ('base', ctypes.c_int), 10 ('disp', ctypes.c_int), 11 ('unit', ctypes.c_int), 12 ('scaled', ctypes.c_int), 13 ('disptype', ctypes.c_int), 14 ('direction', ctypes.c_int), 15 ('modify', ctypes.c_int), 16 ) 17 18class TMS320C64xOpValue(ctypes.Union): 19 _fields_ = ( 20 ('reg', ctypes.c_uint), 21 ('imm', ctypes.c_int32), 22 ('mem', TMS320C64xOpMem), 23 ) 24 25class TMS320C64xCondition(ctypes.Structure): 26 _fields_ = ( 27 ('reg', ctypes.c_uint), 28 ('zero', ctypes.c_uint), 29 ) 30 31class TMS320C64xFunctionalUnit(ctypes.Structure): 32 _fields_ = ( 33 ('unit', ctypes.c_uint), 34 ('side', ctypes.c_uint), 35 ('crosspath', ctypes.c_uint), 36 ) 37 38class TMS320C64xOp(ctypes.Structure): 39 _fields_ = ( 40 ('type', ctypes.c_uint), 41 ('value', TMS320C64xOpValue), 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 mem(self): 54 return self.value.mem 55 56class CsTMS320C64x(ctypes.Structure): 57 _fields_ = ( 58 ('op_count', ctypes.c_uint8), 59 ('operands', TMS320C64xOp * 8), 60 ('condition', TMS320C64xCondition), 61 ('funit', TMS320C64xFunctionalUnit), 62 ('parallel', ctypes.c_uint), 63 ) 64 65def get_arch_info(a): 66 return (a.condition, a.funit, a.parallel, copy.deepcopy(a.operands[:a.op_count])) 67