diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-01-31 22:09:29 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-01-31 22:09:29 (GMT) |
commit | 2834917e0e3b5e9ea3e6ea0fb90cdbf066ea9da7 (patch) | |
tree | 7ac7dc341e5247398d4549e75ee410277560dc44 /plugins/pychrysa/arch | |
parent | 2b8f655628652f3cfb61c8b82d4b54fbf3ed9869 (diff) |
Remove missing symbols in the Python bindings.
Diffstat (limited to 'plugins/pychrysa/arch')
-rw-r--r-- | plugins/pychrysa/arch/processor.c | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/plugins/pychrysa/arch/processor.c b/plugins/pychrysa/arch/processor.c index 63d93c5..c3d744b 100644 --- a/plugins/pychrysa/arch/processor.c +++ b/plugins/pychrysa/arch/processor.c @@ -25,6 +25,7 @@ #include "processor.h" +#include <malloc.h> #include <pygobject.h> @@ -65,6 +66,9 @@ /* Fournit les instructions désassemblées pour une architecture. */ static PyObject *py_arch_processor_get_instrs(PyObject *, void *); +/* Note les instructions désassemblées avec une architecture. */ +static int py_arch_processor_set_instrs(PyObject *, PyObject *, void *); + /* Recherche une instruction d'après son adresse. */ static PyObject *py_arch_processor_find_instr_by_addr(PyObject *, PyObject *); @@ -121,24 +125,55 @@ static PyObject *py_arch_processor_get_instrs(PyObject *self, void *closure) * * ******************************************************************************/ -static int py_arch_processor_set_disass_instrs(PyObject *self, PyObject *value, void *closure) +static int py_arch_processor_set_instrs(PyObject *self, PyObject *value, void *closure) { + size_t count; /* Nombre d'instructions */ + GArchInstruction **list; /* Liste d'instructions */ + size_t i; /* Boucle de parcours */ + PyObject *instr; /* Instruction en Python */ GArchProcessor *proc; /* Architecture visée */ - GArchInstruction *instrs; /* Série d'instructions liées */ - if (!PyObject_TypeCheck(value, get_python_arch_instruction_type())) + if (!PyTuple_Check(value)) { - PyErr_SetString(PyExc_TypeError, _("The attribute value must be an instruction.")); + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a tuple of instructions.")); return -1; } + count = PyTuple_Size(value); + + list = (GArchInstruction **)calloc(count, sizeof(GArchInstruction *)); + + for (i = 0; i < count; i++) + { + instr = PyTuple_GetItem(value, i); + + if (!PyObject_TypeCheck(value, get_python_arch_instruction_type())) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a tuple of instructions.")); + count = i; + goto papsi_error; + } + + list[i] = G_ARCH_INSTRUCTION(pygobject_get(instr)); + g_object_ref(G_OBJECT(list[i])); + + } + proc = G_ARCH_PROCESSOR(pygobject_get(self)); - instrs = G_ARCH_INSTRUCTION(pygobject_get(value)); - g_arch_processor_set_disassembled_instructions(proc, instrs); + g_arch_processor_set_instructions(proc, list, count); return 0; + papsi_error: + + for (i = 0; i < count; i++) + g_object_unref(G_OBJECT(list[i])); + + free(list); + + return -1; + } @@ -217,7 +252,7 @@ PyTypeObject *get_python_arch_processor_type(void) static PyGetSetDef py_arch_processor_getseters[] = { { - "instrs", py_arch_processor_get_instrs, py_arch_processor_set_disass_instrs, + "instrs", py_arch_processor_get_instrs, py_arch_processor_set_instrs, "Give access to the disassembled instructions run by the current processor.", NULL }, { NULL } |