summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/arch/instruction.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-07-27 17:13:19 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-07-27 17:13:19 (GMT)
commit77f88a59bfb9296df7e995e99218d27862136588 (patch)
tree6e9897f690b50da53d77266095eccb358912a1cb /plugins/pychrysa/arch/instruction.c
parent359055e28bcd195fb03fd0deb1a30e5a04d5ce58 (diff)
Fixed several mistakes in the Python bindings.
Diffstat (limited to 'plugins/pychrysa/arch/instruction.c')
-rw-r--r--plugins/pychrysa/arch/instruction.c215
1 files changed, 6 insertions, 209 deletions
diff --git a/plugins/pychrysa/arch/instruction.c b/plugins/pychrysa/arch/instruction.c
index 0efca5a..61d1987 100644
--- a/plugins/pychrysa/arch/instruction.c
+++ b/plugins/pychrysa/arch/instruction.c
@@ -34,6 +34,7 @@
#include "vmpa.h"
#include "../helpers.h"
+#include "../glibext/linegen.h"
@@ -440,6 +441,7 @@ bool register_python_arch_instruction(PyObject *module)
{
PyTypeObject *py_arch_instruction_type; /* Type Python 'ArchInstruc...'*/
PyObject *dict; /* Dictionnaire du module */
+ PyTypeObject *py_line_generator_type; /* Type Python 'LineGenerator' */
py_arch_instruction_type = get_python_arch_instruction_type();
@@ -447,217 +449,12 @@ bool register_python_arch_instruction(PyObject *module)
dict = PyModule_GetDict(module);
- if (!register_class_for_pygobject(dict, G_TYPE_ARCH_INSTRUCTION, py_arch_instruction_type, &PyGObject_Type))
- return false;
-
- return true;
-
-}
-
-
-
-
-
-
-
-#if 0
-
-
-#include <pygobject.h>
-#include <stdbool.h>
-#include <string.h>
-
-
-#include <arch/instruction.h>
-
-
-#include "../quirks.h"
-
-
-
-/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */
-
-
-/* Crée un nouvel objet Python de type 'ArchInstruction'. */
-static PyObject *py_arch_instruction_new(PyTypeObject *, PyObject *, PyObject *);
-
-/* Prépare un parcours d'instructions. */
-static PyObject *py_arch_instruction_get_iter(PyObject *);
-
-/* Fournit la valeur associée à une propriété donnée. */
-static PyObject *py_arch_instruction_get_location(PyObject *, char *);
-
-/* Fournit le nom humain de l'instruction manipulée. */
-static PyObject *py_arch_instruction_get_keyword(PyObject *, void *);
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* INSTRUCTIONS D'ARCHITECTURES EN PYTHON */
-/* ---------------------------------------------------------------------------------- */
-
+ py_line_generator_type = get_python_line_generator_type();
-/******************************************************************************
-* *
-* Paramètres : type = type de l'objet à instancier. *
-* args = arguments fournis à l'appel. *
-* kwds = arguments de type key=val fournis. *
-* *
-* Description : Crée un nouvel objet Python de type 'ArchInstruction'. *
-* *
-* Retour : Instance Python mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_arch_instruction_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- Py_RETURN_NONE;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = instance manipulée à traiter. *
-* *
-* Description : Prépare un parcours d'instructions. *
-* *
-* Retour : Point de départ d'un parcours. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_arch_instruction_get_iter(PyObject *self)
-{
- return py_arch_instruction_iterator_create(self);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = classe représentant une instruction. *
-* name = nom de la propriété à lire. *
-* *
-* Description : Fournit la valeur associée à une propriété donnée. *
-* *
-* Retour : Valeur associée à la propriété consultée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_arch_instruction_get_location(PyObject *self, char *name)
-{
- PyObject *result; /* Trouvailles à retourner */
- GArchInstruction *instr; /* Version native */
- off_t offset; /* Position dans le fichier */
- off_t length; /* Taille de l'instruction */
- vmpa_t address; /* Position en mémoire */
-
- instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- g_arch_instruction_get_location(instr, &offset, &length, &address);
-
- if (strcmp(name, "offset") == 0)
- result = PyLong_FromLong(offset);
-
- else if (strcmp(name, "length") == 0)
- result = PyLong_FromLong(length);
-
- else if (strcmp(name, "address") == 0)
- result = PyLong_FromLongLong(address);
-
- else
- result = NULL;
-
- return result;
-
-}
-
-
-
-/******************************************************************************
-* *
-* Paramètres : module = module dont la définition est à compléter. *
-* *
-* Description : Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool register_python_arch_instruction(PyObject *module)
-{
- PyObject *pygobj_mod; /* Module Python-GObject */
- int ret; /* Bilan d'un appel */
-
- static PyMethodDef py_arch_instruction_methods[] = {
- { NULL }
- };
-
- static PyGetSetDef py_arch_instruction_getseters[] = {
- {
- "offset", (getter)py_arch_instruction_get_location, (setter)NULL,
- "Provide the location of the instruction in the binary file.", "offset"
- },
- {
- "length", (getter)py_arch_instruction_get_location, (setter)NULL,
- "Provide the length of the instruction.", "length"
- },
- {
- "address", (getter)py_arch_instruction_get_location, (setter)NULL,
- "Provide the location of the instruction in memory.", "address"
- },
- {
- "keyword", (getter)py_arch_instruction_get_keyword, (setter)NULL,
- "Give le name of the assembly instruction.", NULL
- },
- { NULL }
- };
-
- static PyTypeObject py_arch_instruction_type = {
-
- PyObject_HEAD_INIT(NULL)
-
- .tp_name = "pychrysalide.arch.ArchInstruction",
- .tp_basicsize = sizeof(PyGObject),
-
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
-
- .tp_doc = "PyChrysalide architecture instruction",
-
- .tp_methods = py_arch_instruction_methods,
- .tp_getset = py_arch_instruction_getseters,
- .tp_new = (newfunc)py_arch_instruction_new,
-
- .tp_iter = (getiterfunc)py_arch_instruction_get_iter
-
- };
-
- pygobj_mod = PyImport_ImportModule("gobject");
- if (pygobj_mod == NULL) return false;
-
- py_arch_instruction_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
- Py_DECREF(pygobj_mod);
-
- if (PyType_Ready(&py_arch_instruction_type) < 0)
+ if (!_register_class_for_pygobject(dict, G_TYPE_ARCH_INSTRUCTION, py_arch_instruction_type,
+ &PyGObject_Type, py_line_generator_type, NULL))
return false;
- Py_INCREF(&py_arch_instruction_type);
- ret = PyModule_AddObject(module, "ArchInstruction", (PyObject *)&py_arch_instruction_type);
-
- register_class_for_pygobject(module, "GArchInstruction", G_TYPE_ARCH_INSTRUCTION,
- &py_arch_instruction_type,
- Py_BuildValue("(O)", py_arch_instruction_type.tp_base));
-
- return (ret == 0);
+ return true;
}
-
-
-#endif