summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-12-21 23:34:14 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-12-21 23:34:14 (GMT)
commit3bfff245c47c4dd1404c5ea7af0ff4858ac8d130 (patch)
treedc3613e2ebdef4d04fa874335795268dba732d31 /plugins/pychrysa/arch
parent0cfcbee3c536ac6d11ec806d47ce4c136f695697 (diff)
Resolved relative addresses for routines and fixed bugs related to PyGObjects construction.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@308 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/arch')
-rw-r--r--plugins/pychrysa/arch/instruction.c62
-rw-r--r--plugins/pychrysa/arch/instruction.h5
-rw-r--r--plugins/pychrysa/arch/processor.c26
3 files changed, 24 insertions, 69 deletions
diff --git a/plugins/pychrysa/arch/instruction.c b/plugins/pychrysa/arch/instruction.c
index bed937b..09397fc 100644
--- a/plugins/pychrysa/arch/instruction.c
+++ b/plugins/pychrysa/arch/instruction.c
@@ -30,6 +30,9 @@
#include <string.h>
+#include <arch/instruction.h>
+
+
#include "../quirks.h"
@@ -105,13 +108,14 @@ static PyObject *py_arch_instruction_iterator_create(PyObject *origin)
Py_DECREF(module);
result = (PyArchInstructionIter *)type->tp_alloc(type, 0);
+ Py_DECREF(type);
if (result != NULL)
{
+ Py_INCREF(origin);
result->head = G_ARCH_INSTRUCTION(pygobject_get(origin));
g_object_ref(G_OBJECT(result->head));
- Py_INCREF(origin);
result->current = origin;
}
@@ -134,8 +138,12 @@ static PyObject *py_arch_instruction_iterator_create(PyObject *origin)
static void py_arch_instruction_iterator_dealloc(PyArchInstructionIter *self)
{
+ PyObject *first; /* Récupération de la première */
+
+ first = pychrysalide_get_pygobject(G_OBJECT(self->head));
+
+ Py_DECREF(first);
g_object_unref(G_OBJECT(self->head));
- Py_DECREF(self->current);
#if PY_VERSION_HEX < 0x03000000
self->ob_type->tp_free((PyObject *)self);
@@ -167,6 +175,8 @@ static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *self)
{
self->started = true;
result = self->current;
+ Py_INCREF(result);
+
}
else
{
@@ -175,17 +185,14 @@ static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *self)
if (next != NULL)
{
- result = py_arch_instruction_from_c(next);
-
- Py_INCREF(result);
- Py_DECREF(self->current);
+ result = pygobject_new(G_OBJECT(next));
self->current = result;
-
}
else result = NULL;
}
+ Py_XINCREF(result);
return (PyObject *)result;
}
@@ -258,35 +265,7 @@ bool register_python_arch_instruction_iterator(PyObject *module)
static PyObject *py_arch_instruction_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- return Py_None;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = instance existante GLib. *
-* *
-* Description : Crée un nouvel objet Python de type 'ArchInstruction'. *
-* *
-* Retour : Instance Python mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyObject *py_arch_instruction_from_c(GArchInstruction *instr)
-{
- PyObject *module; /* Module d'appartenance */
- PyTypeObject *type; /* Type Python correspondant */
-
- module = PyImport_ImportModule("pychrysalide.arch");
- type = (PyTypeObject *)PyObject_GetAttrString(module, "ArchInstruction");
- Py_DECREF(module);
-
- pychrysalide_set_instance_data(G_OBJECT(instr), type);
-
- return pygobject_new(G_OBJECT(instr));
+ Py_RETURN_NONE;
}
@@ -337,12 +316,15 @@ static PyObject *py_arch_instruction_get_location(PyObject *self, char *name)
if (strcmp(name, "offset") == 0)
result = PyLong_FromLong(offset);
- else if (strcmp(name, "") == 0)
+ else if (strcmp(name, "length") == 0)
result = PyLong_FromLong(length);
- else /*if (strcmp(name, "") == 0)*/
+ else if (strcmp(name, "address") == 0)
result = PyLong_FromLongLong(address);
+ else
+ result = NULL;
+
return result;
}
@@ -449,6 +431,10 @@ bool register_python_arch_instruction(PyObject *module)
Py_INCREF(&py_arch_instruction_type);
ret = PyModule_AddObject(module, "ArchInstruction", (PyObject *)&py_arch_instruction_type);
+ pygobject_register_class(module, "GArchInstruction", G_TYPE_ARCH_INSTRUCTION,
+ &py_arch_instruction_type,
+ Py_BuildValue("(O)", py_arch_instruction_type.tp_base));
+
return (ret == 0);
}
diff --git a/plugins/pychrysa/arch/instruction.h b/plugins/pychrysa/arch/instruction.h
index 545d88e..d91b8d1 100644
--- a/plugins/pychrysa/arch/instruction.h
+++ b/plugins/pychrysa/arch/instruction.h
@@ -29,8 +29,6 @@
#include <Python.h>
#include <stdbool.h>
-#include <arch/instruction.h>
-
/* --------------------- ITERATEUR POUR BOUCLE SUR INSTRUCTIONS --------------------- */
@@ -44,9 +42,6 @@ bool register_python_arch_instruction_iterator(PyObject *);
/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */
-/* Crée un nouvel objet Python de type 'ArchInstruction'. */
-PyObject *py_arch_instruction_from_c(GArchInstruction *);
-
/* Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. */
bool register_python_arch_instruction(PyObject *);
diff --git a/plugins/pychrysa/arch/processor.c b/plugins/pychrysa/arch/processor.c
index 0a3fe95..cc1113a 100644
--- a/plugins/pychrysa/arch/processor.c
+++ b/plugins/pychrysa/arch/processor.c
@@ -224,32 +224,6 @@ static PyObject *py_processor_new(PyTypeObject *type, PyObject *args, PyObject *
-static PyObject *util_FromImport(const char *name, const char *from_item)
-{
- PyObject *from_list;
- PyObject *module;
- PyObject *item;
-
- /* Make the from list. */
- from_list = PyList_New(1);
- PyList_SetItem(from_list, 0, PyString_FromString(from_item));
-
- /* Attempt the import, with const correctness removed. */
- module = PyImport_ImportModuleEx((char *)name, NULL, NULL, from_list);
- Py_DECREF(from_list);
- if (!module)
- {
- return NULL;
- }
-
- /* Get the from_item from the module. */
- item = PyObject_GetAttrString(module, (char *)from_item);
- Py_DECREF(module);
-
- return item;
-}
-
-