Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

export cpu_reg32_get and cpu_step

  • Loading branch information...
commit 1ae9edfd47299c7d30a88f48ed9d2700c1a66942 1 parent 2ba98b0
@rep rep authored
Showing with 204 additions and 2 deletions.
  1. +185 −2 src/pylibemu.c
  2. +1 −0  src/pylibemu.pxd
  3. +18 −0 src/pylibemu.pyx
View
187 src/pylibemu.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.14.1 on Thu Apr 5 12:51:24 2012 */
+/* Generated by Cython 0.14.1 on Sat Apr 7 00:39:20 2012 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
@@ -510,6 +510,8 @@ static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/
static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject *);
+static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t);
+
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
@@ -5451,7 +5453,7 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set(PyObject *__pyx_v_
*
* return 0 # <<<<<<<<<<<<<<
*
- *
+ * def cpu_reg32_get(self, reg):
*/
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_int_0);
@@ -5468,6 +5470,160 @@ static PyObject *__pyx_pf_8pylibemu_8Emulator_13cpu_reg32_set(PyObject *__pyx_v_
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+
+/* "pylibemu.pyx":622
+ * return 0
+ *
+ * def cpu_reg32_get(self, reg): # <<<<<<<<<<<<<<
+ * cdef c_emu_cpu *_cpu
+ *
+ */
+
+static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_self, PyObject *__pyx_v_reg); /*proto*/
+static PyObject *__pyx_pf_8pylibemu_8Emulator_14cpu_reg32_get(PyObject *__pyx_v_self, PyObject *__pyx_v_reg) {
+ struct emu_cpu *__pyx_v__cpu;
+ uint32_t __pyx_v_val;
+ PyObject *__pyx_r = NULL;
+ int __pyx_t_1;
+ enum emu_reg32 __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ __Pyx_RefNannySetupContext("cpu_reg32_get");
+
+ /* "pylibemu.pyx":625
+ * 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":626
+ *
+ * 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":628
+ * return -1
+ *
+ * _cpu = emu_cpu_get(self._emu) # <<<<<<<<<<<<<<
+ *
+ * val = emu_cpu_reg32_get(_cpu, reg)
+ */
+ __pyx_v__cpu = emu_cpu_get(((struct __pyx_obj_8pylibemu_Emulator *)__pyx_v_self)->_emu);
+
+ /* "pylibemu.pyx":630
+ * _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_v_val = emu_cpu_reg32_get(__pyx_v__cpu, __pyx_t_2);
+
+ /* "pylibemu.pyx":632
+ * val = emu_cpu_reg32_get(_cpu, reg)
+ *
+ * return val # <<<<<<<<<<<<<<
+ *
+ * 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_GOTREF(__pyx_t_3);
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("pylibemu.Emulator.cpu_reg32_get");
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "pylibemu.pyx":634
+ * return val
+ *
+ * def cpu_step(self): # <<<<<<<<<<<<<<
+ * if self._emu is NULL:
+ * return -1
+ */
+
+static PyObject *__pyx_pf_8pylibemu_8Emulator_15cpu_step(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pf_8pylibemu_8Emulator_15cpu_step(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = NULL;
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ __Pyx_RefNannySetupContext("cpu_step");
+
+ /* "pylibemu.pyx":635
+ *
+ * def cpu_step(self):
+ * 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":636
+ * def cpu_step(self):
+ * if self._emu is NULL:
+ * return -1 # <<<<<<<<<<<<<<
+ *
+ * return emu_cpu_step(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":638
+ * return -1
+ *
+ * return emu_cpu_step(emu_cpu_get(self._emu)) # <<<<<<<<<<<<<<
+ *
+ *
+ */
+ __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_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_step");
+ __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) {
@@ -5704,6 +5860,8 @@ static PyMethodDef __pyx_methods_8pylibemu_Emulator[] = {
{__Pyx_NAMESTR("emu_profile_truncated"), (PyCFunction)__pyx_pf_8pylibemu_8Emulator_11emu_profile_truncated, METH_NOARGS, __Pyx_DOCSTR(0)},
{__Pyx_NAMESTR("memory_write_dword"), (PyCFunction)__pyx_pf_8pylibemu_8Emulator_12memory_write_dword, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
{__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)},
{0, 0, 0, 0}
};
@@ -7064,6 +7222,31 @@ static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject* x) {
}
}
+static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t val) {
+ const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
+ const int is_unsigned = const_zero < neg_one;
+ if ((sizeof(uint32_t) == sizeof(char)) ||
+ (sizeof(uint32_t) == sizeof(short))) {
+ return PyInt_FromLong((long)val);
+ } else if ((sizeof(uint32_t) == sizeof(int)) ||
+ (sizeof(uint32_t) == sizeof(long))) {
+ if (is_unsigned)
+ return PyLong_FromUnsignedLong((unsigned long)val);
+ else
+ return PyInt_FromLong((long)val);
+ } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
+ if (is_unsigned)
+ return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
+ else
+ return PyLong_FromLongLong((PY_LONG_LONG)val);
+ } else {
+ int one = 1; int little = (int)*(unsigned char *)&one;
+ unsigned char *bytes = (unsigned char *)&val;
+ return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
+ little, !is_unsigned);
+ }
+}
+
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
View
1  src/pylibemu.pxd
@@ -203,6 +203,7 @@ cdef extern from "emu/emu_cpu.h":
edi = 7
void emu_cpu_reg32_set(c_emu_cpu *cpu_p, c_emu_reg32 reg, uint32_t val)
+ uint32_t emu_cpu_reg32_get(c_emu_cpu *cpu_p, c_emu_reg32 reg)
void emu_cpu_eflags_set(c_emu_cpu *c, uint32_t val)
void emu_cpu_eip_set(c_emu_cpu *c, uint32_t eip)
uint32_t emu_cpu_eip_get(c_emu_cpu *c)
View
18 src/pylibemu.pyx
@@ -618,5 +618,23 @@ cdef class Emulator:
emu_cpu_reg32_set(_cpu, reg, val)
return 0
+
+ def cpu_reg32_get(self, reg):
+ cdef c_emu_cpu *_cpu
+
+ if self._emu is NULL:
+ return -1
+
+ _cpu = emu_cpu_get(self._emu)
+
+ val = emu_cpu_reg32_get(_cpu, reg)
+
+ return val
+
+ def cpu_step(self):
+ if self._emu is NULL:
+ return -1
+ return emu_cpu_step(emu_cpu_get(self._emu))
+
Please sign in to comment.
Something went wrong with that request. Please try again.