diff --git a/README b/README index 6fc8d14..d445865 100644 --- a/README +++ b/README @@ -167,7 +167,7 @@ method and subsequently run the shellcode emulation test again as shown above. License information =================== -Copyright (C) 2011 Angelo Dell'Aera +Copyright (C) 2011-2012 Angelo Dell'Aera License: GNU General Public License, version 2 or later; see COPYING.txt included in this archive for details. diff --git a/setup.py b/setup.py index 2226f92..0ebab15 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name = "pylibemu", packages = [], - version = "0.1.4", + version = "0.1.5", description = "Libemu Python wrapper", url = "", author = "Angelo Dell'Aera", diff --git a/src/pylibemu.c b/src/pylibemu.c index d7d343f..ef8d075 100644 --- a/src/pylibemu.c +++ b/src/pylibemu.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.14.1 on Sat Apr 7 00:39:20 2012 */ +/* Generated by Cython 0.14.1 on Fri May 4 10:41:38 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -5219,7 +5219,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_11emu_profile_truncated(PyObject * * return self.emu_profile.truncate * * def memory_write_dword(self, addr, dword): # <<<<<<<<<<<<<< - * cdef c_emu_memory *_mem + * cdef c_emu_memory *_mem * */ @@ -5276,7 +5276,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_12memory_write_dword(PyObject *__p __pyx_L4_argument_unpacking_done:; /* "pylibemu.pyx":601 - * cdef c_emu_memory *_mem + * cdef c_emu_memory *_mem * * if self._emu is NULL: # <<<<<<<<<<<<<< * return -1 @@ -5304,25 +5304,25 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_12memory_write_dword(PyObject *__p * return -1 * * _mem = emu_memory_get(self._emu) # <<<<<<<<<<<<<< - * * emu_memory_write_dword(_mem, addr, dword) + * return 0 */ __pyx_v__mem = emu_memory_get(((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu); - /* "pylibemu.pyx":606 - * _mem = emu_memory_get(self._emu) + /* "pylibemu.pyx":605 * + * _mem = emu_memory_get(self._emu) * emu_memory_write_dword(_mem, addr, dword) # <<<<<<<<<<<<<< - * * return 0 + * */ - __pyx_t_2 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_addr); if (unlikely((__pyx_t_2 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_dword); if (unlikely((__pyx_t_3 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_addr); if (unlikely((__pyx_t_2 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_dword); if (unlikely((__pyx_t_3 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 605; __pyx_clineno = __LINE__; goto __pyx_L1_error;} emu_memory_write_dword(__pyx_v__mem, __pyx_t_2, __pyx_t_3); - /* "pylibemu.pyx":608 + /* "pylibemu.pyx":606 + * _mem = emu_memory_get(self._emu) * emu_memory_write_dword(_mem, addr, dword) - * * return 0 # <<<<<<<<<<<<<< * * def cpu_reg32_set(self, reg, val): @@ -5343,11 +5343,11 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_12memory_write_dword(PyObject *__p return __pyx_r; } -/* "pylibemu.pyx":610 +/* "pylibemu.pyx":608 * return 0 * * def cpu_reg32_set(self, reg, val): # <<<<<<<<<<<<<< - * cdef c_emu_cpu *_cpu + * cdef c_emu_cpu *_cpu * */ @@ -5380,11 +5380,11 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set(PyObject *__pyx_v_ values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__val); if (likely(values[1])) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("cpu_reg32_set", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("cpu_reg32_set", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "cpu_reg32_set") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "cpu_reg32_set") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_reg = values[0]; __pyx_v_val = values[1]; @@ -5396,15 +5396,15 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set(PyObject *__pyx_v_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("cpu_reg32_set", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("cpu_reg32_set", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pylibemu.Emulator.cpu_reg32_set"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - /* "pylibemu.pyx":613 - * cdef c_emu_cpu *_cpu + /* "pylibemu.pyx":611 + * cdef c_emu_cpu *_cpu * * if self._emu is NULL: # <<<<<<<<<<<<<< * return -1 @@ -5413,7 +5413,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set(PyObject *__pyx_v_ __pyx_t_1 = (((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu == NULL); if (__pyx_t_1) { - /* "pylibemu.pyx":614 + /* "pylibemu.pyx":612 * * if self._emu is NULL: * return -1 # <<<<<<<<<<<<<< @@ -5428,29 +5428,29 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set(PyObject *__pyx_v_ } __pyx_L6:; - /* "pylibemu.pyx":616 + /* "pylibemu.pyx":614 * return -1 * * _cpu = emu_cpu_get(self._emu) # <<<<<<<<<<<<<< - * * emu_cpu_reg32_set(_cpu, reg, val) + * return 0 */ __pyx_v__cpu = emu_cpu_get(((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu); - /* "pylibemu.pyx":618 - * _cpu = emu_cpu_get(self._emu) + /* "pylibemu.pyx":615 * + * _cpu = emu_cpu_get(self._emu) * emu_cpu_reg32_set(_cpu, reg, val) # <<<<<<<<<<<<<< - * * return 0 + * */ - __pyx_t_2 = ((enum emu_reg32)PyInt_AsLong(__pyx_v_reg)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_val); if (unlikely((__pyx_t_3 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((enum emu_reg32)PyInt_AsLong(__pyx_v_reg)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_val); if (unlikely((__pyx_t_3 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;} emu_cpu_reg32_set(__pyx_v__cpu, __pyx_t_2, __pyx_t_3); - /* "pylibemu.pyx":620 + /* "pylibemu.pyx":616 + * _cpu = emu_cpu_get(self._emu) * emu_cpu_reg32_set(_cpu, reg, val) - * * return 0 # <<<<<<<<<<<<<< * * def cpu_reg32_get(self, reg): @@ -5471,7 +5471,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set(PyObject *__pyx_v_ return __pyx_r; } -/* "pylibemu.pyx":622 +/* "pylibemu.pyx":618 * return 0 * * def cpu_reg32_get(self, reg): # <<<<<<<<<<<<<< @@ -5489,7 +5489,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_ PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("cpu_reg32_get"); - /* "pylibemu.pyx":625 + /* "pylibemu.pyx":621 * cdef c_emu_cpu *_cpu * * if self._emu is NULL: # <<<<<<<<<<<<<< @@ -5499,7 +5499,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_ __pyx_t_1 = (((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu == NULL); if (__pyx_t_1) { - /* "pylibemu.pyx":626 + /* "pylibemu.pyx":622 * * if self._emu is NULL: * return -1 # <<<<<<<<<<<<<< @@ -5514,7 +5514,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_ } __pyx_L5:; - /* "pylibemu.pyx":628 + /* "pylibemu.pyx":624 * return -1 * * _cpu = emu_cpu_get(self._emu) # <<<<<<<<<<<<<< @@ -5523,17 +5523,17 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_ */ __pyx_v__cpu = emu_cpu_get(((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu); - /* "pylibemu.pyx":630 + /* "pylibemu.pyx":626 * _cpu = emu_cpu_get(self._emu) * * val = emu_cpu_reg32_get(_cpu, reg) # <<<<<<<<<<<<<< * * return val */ - __pyx_t_2 = ((enum emu_reg32)PyInt_AsLong(__pyx_v_reg)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((enum emu_reg32)PyInt_AsLong(__pyx_v_reg)); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_val = emu_cpu_reg32_get(__pyx_v__cpu, __pyx_t_2); - /* "pylibemu.pyx":632 + /* "pylibemu.pyx":628 * val = emu_cpu_reg32_get(_cpu, reg) * * return val # <<<<<<<<<<<<<< @@ -5541,7 +5541,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_ * def cpu_step(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_val); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_val); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 628; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -5559,7 +5559,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_ return __pyx_r; } -/* "pylibemu.pyx":634 +/* "pylibemu.pyx":630 * return val * * def cpu_step(self): # <<<<<<<<<<<<<< @@ -5574,7 +5574,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_15cpu_step(PyObject *__pyx_v_self, PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("cpu_step"); - /* "pylibemu.pyx":635 + /* "pylibemu.pyx":631 * * def cpu_step(self): * if self._emu is NULL: # <<<<<<<<<<<<<< @@ -5584,7 +5584,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_15cpu_step(PyObject *__pyx_v_self, __pyx_t_1 = (((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu == NULL); if (__pyx_t_1) { - /* "pylibemu.pyx":636 + /* "pylibemu.pyx":632 * def cpu_step(self): * if self._emu is NULL: * return -1 # <<<<<<<<<<<<<< @@ -5599,15 +5599,15 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_15cpu_step(PyObject *__pyx_v_self, } __pyx_L5:; - /* "pylibemu.pyx":638 + /* "pylibemu.pyx":634 * return -1 * * return emu_cpu_step(emu_cpu_get(self._emu)) # <<<<<<<<<<<<<< * - * + * def cpu_eip_get(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(emu_cpu_step(emu_cpu_get(((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 638; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(emu_cpu_step(emu_cpu_get(((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -5624,6 +5624,79 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_15cpu_step(PyObject *__pyx_v_self, __Pyx_RefNannyFinishContext(); return __pyx_r; } + +/* "pylibemu.pyx":636 + * return emu_cpu_step(emu_cpu_get(self._emu)) + * + * def cpu_eip_get(self): # <<<<<<<<<<<<<< + * cdef c_emu_cpu *_cpu + * + */ + +static PyObject *__pyx_pf_8pylibemu_8Emulator_16cpu_eip_get(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pf_8pylibemu_8Emulator_16cpu_eip_get(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + struct emu_cpu *__pyx_v__cpu; + PyObject *__pyx_r = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("cpu_eip_get"); + + /* "pylibemu.pyx":639 + * cdef c_emu_cpu *_cpu + * + * if self._emu is NULL: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_1 = (((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu == NULL); + if (__pyx_t_1) { + + /* "pylibemu.pyx":640 + * + * if self._emu is NULL: + * return -1 # <<<<<<<<<<<<<< + * + * _cpu = emu_cpu_get(self._emu) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_neg_1); + __pyx_r = __pyx_int_neg_1; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "pylibemu.pyx":642 + * return -1 + * + * _cpu = emu_cpu_get(self._emu) # <<<<<<<<<<<<<< + * return emu_cpu_eip_get(_cpu) + */ + __pyx_v__cpu = emu_cpu_get(((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu); + + /* "pylibemu.pyx":643 + * + * _cpu = emu_cpu_get(self._emu) + * return emu_cpu_eip_get(_cpu) # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(emu_cpu_eip_get(__pyx_v__cpu)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pylibemu.Emulator.cpu_eip_get"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} static struct __pyx_vtabstruct_8pylibemu_EmuProfile __pyx_vtable_8pylibemu_EmuProfile; static PyObject *__pyx_tp_new_8pylibemu_EmuProfile(PyTypeObject *t, PyObject *a, PyObject *k) { @@ -5862,6 +5935,7 @@ static PyMethodDef __pyx_methods_8pylibemu_Emulator[] = { {__Pyx_NAMESTR("cpu_reg32_set"), (PyCFunction)__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("cpu_reg32_get"), (PyCFunction)__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("cpu_step"), (PyCFunction)__pyx_pf_8pylibemu_8Emulator_15cpu_step, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("cpu_eip_get"), (PyCFunction)__pyx_pf_8pylibemu_8Emulator_16cpu_eip_get, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; diff --git a/src/pylibemu.pxd b/src/pylibemu.pxd index 9eb2ce5..38c54e0 100644 --- a/src/pylibemu.pxd +++ b/src/pylibemu.pxd @@ -1,6 +1,6 @@ # pylibemu.pxd # -# Copyright(c) 2011 Angelo Dell'Aera +# Copyright(c) 2011-2012 Angelo Dell'Aera # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as diff --git a/src/pylibemu.pyx b/src/pylibemu.pyx index e6bffc5..28502be 100644 --- a/src/pylibemu.pyx +++ b/src/pylibemu.pyx @@ -1,7 +1,7 @@ # # pylibemu.pyx # -# Copyright(c) 2011 Angelo Dell'Aera +# Copyright(c) 2011-2012 Angelo Dell'Aera # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -596,27 +596,23 @@ cdef class Emulator: return self.emu_profile.truncate def memory_write_dword(self, addr, dword): - cdef c_emu_memory *_mem + cdef c_emu_memory *_mem if self._emu is NULL: return -1 _mem = emu_memory_get(self._emu) - emu_memory_write_dword(_mem, addr, dword) - return 0 def cpu_reg32_set(self, reg, val): - cdef c_emu_cpu *_cpu + cdef c_emu_cpu *_cpu if self._emu is NULL: return -1 _cpu = emu_cpu_get(self._emu) - emu_cpu_reg32_set(_cpu, reg, val) - return 0 def cpu_reg32_get(self, reg): @@ -637,4 +633,11 @@ cdef class Emulator: return emu_cpu_step(emu_cpu_get(self._emu)) + def cpu_eip_get(self): + cdef c_emu_cpu *_cpu + if self._emu is NULL: + return -1 + + _cpu = emu_cpu_get(self._emu) + return emu_cpu_eip_get(_cpu)