|
miasm
Reverse engineering framework
|
Go to the documentation of this file.
5 #define _MIASM_EXPORT __declspec(dllexport)
9 #define SSIZE_MAX _I64_MAX
11 #define SSIZE_MAX INT_MAX
19 #define RAISE(errtype, msg) {PyObject* p; p = PyErr_Format( errtype, msg ); return p;}
20 #define RAISE_ret0(errtype, msg) {PyObject* p; p = PyErr_Format( errtype, msg ); return 0;}
23 #if PY_MAJOR_VERSION >= 3
24 #define getset_reg_bn(regname, size) \
25 static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \
29 bn = (self->cpu)->regname; \
30 bn = bignum_mask(bn, (size)); \
31 py_long = bn_to_PyLong(bn); \
35 static PyObject *JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \
38 PyObject* py_long = value; \
39 if (PyLong_Check(py_long)){ \
42 RAISE(PyExc_TypeError,"arg must be int"); \
45 bn = PyLong_to_bn(py_long); \
47 (self->cpu)->regname = bignum_mask(bn, (size)); \
53 #define getset_reg_bn(regname, size) \
54 static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \
58 bn = (self->cpu)->regname; \
59 bn = bignum_mask(bn, (size)); \
60 py_long = bn_to_PyLong(bn); \
64 static PyObject *JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \
67 PyObject* py_long = value; \
70 if (PyInt_Check(py_long)){ \
71 tmp = (uint64_t)PyInt_AsLong(py_long); \
72 py_long = PyLong_FromLong((long)tmp); \
73 } else if (PyLong_Check(py_long)){ \
77 RAISE(PyExc_TypeError,"arg must be int"); \
80 bn = PyLong_to_bn(py_long); \
82 self->cpu->regname = bignum_mask(bn, (size)); \
97 #define getset_reg_u64(regname) \
98 static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \
100 return PyLong_FromUnsignedLongLong(self->cpu->regname); \
102 static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \
105 PyGetInt_uint64_t_retneg(value, val); \
106 self->cpu->regname = val; \
110 #define getset_reg_u32(regname) \
111 static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \
113 return PyLong_FromUnsignedLongLong(self->cpu->regname); \
115 static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \
118 PyGetInt_uint32_t_retneg(value, val); \
119 self->cpu->regname = val; \
124 #define getset_reg_u16(regname) \
125 static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \
127 return PyLong_FromUnsignedLongLong(self->cpu->regname); \
129 static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \
132 PyGetInt_uint16_t_retneg(value, val); \
133 self->cpu->regname = val; \
138 #define getset_reg_u8(regname) \
139 static PyObject *JitCpu_get_ ## regname (JitCpu *self, void *closure) \
141 return PyLong_FromUnsignedLongLong(self->cpu->regname); \
143 static int JitCpu_set_ ## regname (JitCpu *self, PyObject *value, void *closure) \
146 PyGetInt_uint8_t_retneg(value, val); \
147 self->cpu->regname = val; \
152 #define get_reg(reg) do { \
153 o = PyLong_FromUnsignedLongLong((uint64_t)self->cpu->reg); \
154 PyDict_SetItemString(dict, #reg, o); \
159 #define get_reg_bn(reg, size) do { \
162 bn = self->cpu->reg; \
163 bn = bignum_mask(bn, size); \
164 py_long = bn_to_PyLong(bn); \
165 PyDict_SetItemString(dict, #reg, py_long); \
166 Py_DECREF(py_long); \
170 #define get_reg_off(reg) do { \
171 o = PyLong_FromUnsignedLongLong((uint64_t)offsetof(struct vm_cpu, reg)); \
172 PyDict_SetItemString(dict, #reg, o); \
212 #define Resolve_dst(b, arg_addr, arg_is_local) do {(b)->address = (arg_addr); (b)->is_local = (arg_is_local);} while(0)
236 #define VM_exception_flag (jitcpu->pyvm->vm_mngr.exception_flags)
237 #define CPU_exception_flag (((struct vm_cpu*)jitcpu->cpu)->exception_flags)
238 #define CPU_exception_flag_at_instr ((CPU_exception_flag) && ((CPU_exception_flag) > EXCEPT_NUM_UPDT_EIP))
239 #define JIT_RET_EXCEPTION 1
240 #define JIT_RET_NO_EXCEPTION 0
_MIASM_EXPORT bn_t MEM_LOOKUP_BN_BN(JitCpu *jitcpu, int size, bn_t addr)
Definition: JitCore.c:99
uint8_t MEM_LOOKUP_08(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:79
uint32_t MEM_LOOKUP_32(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:89
_MIASM_EXPORT void MEM_LOOKUP_INT_BN_TO_PTR(JitCpu *jitcpu, int size, uint64_t addr, char *ptr)
Definition: JitCore.c:166
bn_t bignum_rshift(bn_t a, int nbits)
Definition: bn.c:416
Definition: JitCore.h:194
_MIASM_EXPORT uint8_t MEM_LOOKUP_08(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:79
def mem_read(self, expr_mem)
Definition: emulatedsymbexec.py:70
def update_cpu_from_engine(self)
Definition: emulatedsymbexec.py:114
PyObject * JitCpu_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Definition: JitCore.c:20
void MEM_WRITE_INT_BN(JitCpu *jitcpu, int size, uint64_t addr, bn_t src)
Definition: JitCore.c:221
def reset_regs(self)
Definition: emulatedsymbexec.py:64
void vm_MEM_WRITE_32(vm_mngr_t *vm_mngr, uint64_t addr, unsigned int src)
Definition: vm_mngr.c:473
void MEM_WRITE_BN_INT(JitCpu *jitcpu, int size, bn_t addr, uint64_t src)
Definition: JitCore.c:196
Definition: expression.py:1
#define Resolve_dst(b, arg_addr, arg_is_local)
Definition: JitCore.h:212
Definition: symbexec.py:757
bn_t bignum_or(bn_t a, bn_t b)
Definition: bn.c:531
def _simp_handle_x86_cpuid(self, e_s, expr)
Definition: emulatedsymbexec.py:152
PyObject * JitCpu_get_vmmngr(JitCpu *self, void *closure)
Definition: JitCore.c:28
uint64_t MEM_LOOKUP_BN_INT(JitCpu *jitcpu, int size, bn_t addr)
Definition: JitCore.c:119
def __init__(self, cpu, vm, *args, **kwargs)
Definition: emulatedsymbexec.py:55
i
Definition: modint.py:70
PyObject * JitCpu_get_jitter(JitCpu *self, void *closure)
Definition: JitCore.c:63
vm_mngr_t vm_mngr
Definition: vm_mngr_py.h:11
void MEM_WRITE_BN_BN(JitCpu *jitcpu, int size, bn_t addr, bn_t src)
Definition: JitCore.c:180
bn_t MEM_LOOKUP_BN_BN(JitCpu *jitcpu, int size, bn_t addr)
Definition: JitCore.c:99
_MIASM_EXPORT uint64_t MEM_LOOKUP_BN_INT(JitCpu *jitcpu, int size, bn_t addr)
Definition: JitCore.c:119
expr_simp
Definition: symbexec.py:828
void vm_MEM_WRITE_64(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t src)
Definition: vm_mngr.c:478
PyObject * JitCpu_set_vmmngr(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:38
def ret(arg1)
Definition: sem.py:1796
unsigned char vm_MEM_LOOKUP_08(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:484
void add_mem_read(vm_mngr_t *vm_mngr, uint64_t addr, uint64_t size)
Definition: vm_mngr.c:365
value
Definition: export_llvm.py:69
char * name
Definition: JitCore.h:195
_MIASM_EXPORT void MEM_WRITE_INT_BN_FROM_PTR(JitCpu *jitcpu, int size, uint64_t addr, char *ptr)
Definition: JitCore.c:235
PyObject * JitCpu_set_jitter(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:73
unsigned short vm_MEM_LOOKUP_16(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:491
uint64_t vm_MEM_LOOKUP_64(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:505
void JitCpu_dealloc(JitCpu *self)
Definition: JitCore.c:14
type
Definition: full.py:35
PyObject * JitCpu_get_vmcpu(JitCpu *self, void *closure)
Definition: JitCore.c:46
Definition: vm_mngr_py.h:8
void vm_MEM_WRITE_08(vm_mngr_t *vm_mngr, uint64_t addr, unsigned char src)
Definition: vm_mngr.c:462
Definition: emulatedsymbexec.py:7
_MIASM_EXPORT uint32_t MEM_LOOKUP_32(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:89
cpu
Definition: emulatedsymbexec.py:61
uint8_t is_local
Definition: JitCore.h:180
PyObject * jitter
Definition: JitCore.h:189
PyObject * JitCpu_get_jitter(JitCpu *self, void *closure)
Definition: JitCore.c:63
void MEM_WRITE_INT_BN_FROM_PTR(JitCpu *jitcpu, int size, uint64_t addr, char *ptr)
Definition: JitCore.c:235
bn_t bignum_from_int(DTYPE_TMP i)
Definition: bn.c:54
ptr
Definition: expr_c.py:44
uint64_t MEM_LOOKUP_64(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:94
void vm_MEM_WRITE_16(vm_mngr_t *vm_mngr, uint64_t addr, unsigned short src)
Definition: vm_mngr.c:468
stderr
Definition: dse_crackme.py:320
def update_engine_from_cpu(self)
Definition: emulatedsymbexec.py:129
PyObject * JitCpu_set_vmmngr(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:38
def encode_hex(value)
Definition: utils.py:133
_MIASM_EXPORT void MEM_WRITE_BN_BN(JitCpu *jitcpu, int size, bn_t addr, bn_t src)
Definition: JitCore.c:180
dictionary x86_cpuid
Definition: emulatedsymbexec.py:10
bn_t bignum_lshift(bn_t a, int nbits)
Definition: bn.c:387
args
Definition: shellcode.py:26
unsigned int vm_MEM_LOOKUP_32(vm_mngr_t *vm_mngr, uint64_t addr)
Definition: vm_mngr.c:498
size_t offset
Definition: JitCore.h:196
PyObject_HEAD VmMngr * pyvm
Definition: JitCore.h:188
def enable_emulated_simplifications(self)
Definition: emulatedsymbexec.py:164
uint64_t address
Definition: JitCore.h:181
ir_arch
Definition: symbexec.py:827
def decode_hex(value)
Definition: utils.py:130
size_t size
Definition: JitCore.h:197
void JitCpu_dealloc(JitCpu *self)
Definition: JitCore.c:14
uint64_t bignum_to_uint64(bn_t n)
Definition: bn.c:134
_MIASM_EXPORT void MEM_WRITE_INT_BN(JitCpu *jitcpu, int size, uint64_t addr, bn_t src)
Definition: JitCore.c:221
uint16_t MEM_LOOKUP_16(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:84
bn_t MEM_LOOKUP_INT_BN(JitCpu *jitcpu, int size, uint64_t addr)
Definition: JitCore.c:150
#define _MIASM_EXPORT
Definition: JitCore.h:16
PyObject * JitCpu_set_vmcpu(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:55
void MEM_LOOKUP_INT_BN_TO_PTR(JitCpu *jitcpu, int size, uint64_t addr, char *ptr)
Definition: JitCore.c:166
addr
Definition: dis_binary.py:24
PyObject * JitCpu_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Definition: JitCore.c:20
def mem_write(self, dest, data)
Definition: emulatedsymbexec.py:89
PyObject * JitCpu_set_vmcpu(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:55
PyObject * JitCpu_get_vmmngr(JitCpu *self, void *closure)
Definition: JitCore.c:28
vm
Definition: emulatedsymbexec.py:62
def is_op_segm(expr)
Definition: arch.py:190
val
Definition: example_types.py:218
symbols
Definition: symbexec.py:822
PyObject * JitCpu_set_jitter(JitCpu *self, PyObject *value, void *closure)
Definition: JitCore.c:73
Definition: symbexec.py:1
struct _reg_dict reg_dict
struct vm_cpu * cpu
Definition: JitCore.h:190
Definition: JitCore.h:179
size
Definition: shellcode.py:32
Definition: JitCore.h:186
Definition: JitCore_aarch64.h:2
_MIASM_EXPORT bn_t MEM_LOOKUP_INT_BN(JitCpu *jitcpu, int size, uint64_t addr)
Definition: JitCore.c:150
PyObject * JitCpu_get_vmcpu(JitCpu *self, void *closure)
Definition: JitCore.c:46
_MIASM_EXPORT uint64_t MEM_LOOKUP_64(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:94
_MIASM_EXPORT void MEM_WRITE_BN_INT(JitCpu *jitcpu, int size, bn_t addr, uint64_t src)
Definition: JitCore.c:196
_MIASM_EXPORT uint16_t MEM_LOOKUP_16(JitCpu *jitcpu, uint64_t addr)
Definition: JitCore.c:84
def _simp_handle_segm(self, e_s, expr)
Definition: emulatedsymbexec.py:142