summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/arch/instruction.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-07-17 16:36:21 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-07-17 16:36:21 (GMT)
commit24d3836fcf8d443eb654b981f65478cd9923b8f1 (patch)
tree7672a28b864127e8958c3c6cce751dcf646d2fbe /plugins/pychrysa/arch/instruction.c
parenta61f089babe336b012da31a494b0f7470b6e1a9a (diff)
Updated the Python bindings.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@552 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/arch/instruction.c')
-rw-r--r--plugins/pychrysa/arch/instruction.c409
1 files changed, 381 insertions, 28 deletions
diff --git a/plugins/pychrysa/arch/instruction.c b/plugins/pychrysa/arch/instruction.c
index efbdaa5..d675226 100644
--- a/plugins/pychrysa/arch/instruction.c
+++ b/plugins/pychrysa/arch/instruction.c
@@ -25,6 +25,384 @@
#include "instruction.h"
+#include <assert.h>
+#include <pygobject.h>
+
+
+#include <arch/instruction.h>
+
+
+#include "vmpa.h"
+#include "../helpers.h"
+
+
+
+
+/* ------------------- DEFINITION DES LIAISONS ENTRE INSTRUCTIONS ------------------- */
+
+
+
+
+
+/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */
+
+
+
+/* Fournit la place mémoire d'une instruction. */
+static PyObject *py_arch_instruction_get_range(PyObject *, void *);
+
+/* Définit la localisation d'une instruction. */
+static int py_arch_instruction_set_range(PyObject *, PyObject *, void *);
+
+
+
+/* Fournit le nom humain de l'instruction manipulée. */
+static PyObject *py_arch_instruction_get_keyword(PyObject *, void *);
+
+
+
+
+
+
+
+
+
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION DES LIAISONS ENTRE INSTRUCTIONS */
+/* ---------------------------------------------------------------------------------- */
+
+
+
+
+/* Fournit les origines d'une instruction donnée. */
+static PyObject *py_arch_instruction_get_sources(PyObject *, PyObject *);
+
+/* Fournit les destinations d'une instruction donnée. */
+static PyObject *py_arch_instruction_get_destinations(PyObject *, PyObject *);
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instruction d'architecture à manipuler. *
+* args = liste d'arguments non utilisée ici. *
+* *
+* Description : Fournit les origines d'une instruction donnée. *
+* *
+* Retour : Nombre de ces origines. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_get_sources(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Instance à retourner */
+ GArchInstruction *instr; /* Version native */
+ GArchInstruction **dests; /* Destination des liens */
+ InstructionLinkType *types; /* Nature de ces liens */
+ size_t count; /* Nombre de liens présents */
+ size_t i; /* Boucle de parcours */
+ PyObject *dest; /* Destination de lien Python */
+ PyObject *type; /* Nature du lien en Python */
+ int ret; /* Bilan d'une écriture d'arg. */
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+
+ count = g_arch_instruction_get_sources(instr, &dests, &types);
+
+ result = PyTuple_New(count);
+
+ for (i = 0; i < count; i++)
+ {
+ dest = pygobject_new(G_OBJECT(dests[i]));
+ type = PyLong_FromLong(types[i]);
+
+ ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", dest, type));
+ assert(ret == 0);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instruction d'architecture à manipuler. *
+* args = liste d'arguments non utilisée ici. *
+* *
+* Description : Fournit les destinations d'une instruction donnée. *
+* *
+* Retour : Nombre de ces destinations. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_get_destinations(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Instance à retourner */
+ GArchInstruction *instr; /* Version native */
+ GArchInstruction **dests; /* Destination des liens */
+ InstructionLinkType *types; /* Nature de ces liens */
+ size_t count; /* Nombre de liens présents */
+ size_t i; /* Boucle de parcours */
+ PyObject *dest; /* Destination de lien Python */
+ PyObject *type; /* Nature du lien en Python */
+ int ret; /* Bilan d'une écriture d'arg. */
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+
+ count = g_arch_instruction_get_destinations(instr, &dests, &types, NULL);
+
+ result = PyTuple_New(count);
+
+ for (i = 0; i < count; i++)
+ {
+ dest = pygobject_new(G_OBJECT(dests[i]));
+ type = PyLong_FromLong(types[i]);
+
+ ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", dest, type));
+ assert(ret == 0);
+
+ }
+
+ return result;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une instruction. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Fournit la place mémoire d'une instruction. *
+* *
+* Retour : Valeur associée à la propriété consultée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_get_range(PyObject *self, void *closure)
+{
+ PyObject *result; /* Conversion à retourner */
+ GArchInstruction *instr; /* Version native */
+ const mrange_t *range; /* Espace mémoire à exporter */
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+ range = g_arch_instruction_get_range(instr);
+
+ result = build_from_internal_mrange(range);
+
+ return result;
+
+}
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Définit la localisation d'une instruction. *
+* *
+* Retour : Bilan de l'opération pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_arch_instruction_set_range(PyObject *self, PyObject *value, void *closure)
+{
+ int ret; /* Bilan d'analyse */
+ mrange_t *range; /* Espace mémoire à manipuler */
+ GArchInstruction *instr; /* Version native */
+
+ ret = PyObject_IsInstance(value, (PyObject *)get_python_mrange_type());
+ if (!ret) return -1;
+
+ range = get_internal_mrange(value);
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+ g_arch_instruction_set_range(instr, range);
+
+ return 0;
+
+}
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une instruction. *
+* unused = adresse non utilisée ici. *
+* *
+* Description : Fournit le nom humain de l'instruction manipulée. *
+* *
+* Retour : Valeur associée à la propriété consultée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *unused)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ GArchInstruction *instr; /* Version native */
+ const char *kw; /* Valeur récupérée */
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+ kw = g_arch_instruction_get_keyword(instr, 0/* FIXME*/);
+
+ result = PyUnicode_FromString(kw);
+
+ return result;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_arch_instruction_type(void)
+{
+ static PyMethodDef py_arch_instruction_methods[] = {
+ { "get_sources", py_arch_instruction_get_sources,
+ METH_NOARGS,
+ "get_sources(, /)\n--\n\nProvide the instructions list driving to the current instruction."
+ },
+ { "get_destinations", py_arch_instruction_get_destinations,
+ METH_NOARGS,
+ "get_destinations(, /)\n--\n\nProvide the instructions list following the current instruction."
+ },
+ { NULL }
+ };
+
+ static PyGetSetDef py_arch_instruction_getseters[] = {
+ {
+ "range", py_arch_instruction_get_range, py_arch_instruction_set_range,
+ "Give access to the memory range covered by the current instruction.", NULL
+ },
+ {
+ "keyword", (getter)py_arch_instruction_get_keyword, (setter)NULL,
+ "Give le name of the assembly instruction.", NULL
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_arch_instruction_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.arch.ArchInstruction",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide instruction for a given architecture.",
+
+ .tp_methods = py_arch_instruction_methods,
+ .tp_getset = py_arch_instruction_getseters,
+
+ };
+
+ return &py_arch_instruction_type;
+
+}
+
+
+/******************************************************************************
+* *
+* 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)
+{
+ PyTypeObject *py_arch_instruction_type; /* Type Python 'BinContent' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_arch_instruction_type = get_python_arch_instruction_type();
+
+ py_arch_instruction_type->tp_base = &PyGObject_Type;
+ py_arch_instruction_type->tp_basicsize = py_arch_instruction_type->tp_base->tp_basicsize;
+
+ APPLY_ABSTRACT_FLAG(py_arch_instruction_type);
+
+ if (PyType_Ready(py_arch_instruction_type) != 0)
+ return false;
+
+ Py_INCREF(py_arch_instruction_type);
+ ret = PyModule_AddObject(module, "ArchInstruction", (PyObject *)py_arch_instruction_type);
+ if (ret != 0) return false;
+
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "ArchInstruction", G_TYPE_ARCH_INSTRUCTION, py_arch_instruction_type,
+ Py_BuildValue("(O)", py_arch_instruction_type->tp_base));
+
+ return true;
+
+}
+
+
+
+
+
+
+
+#if 0
+
+
#include <pygobject.h>
#include <stdbool.h>
#include <string.h>
@@ -330,34 +708,6 @@ static PyObject *py_arch_instruction_get_location(PyObject *self, char *name)
}
-/******************************************************************************
-* *
-* Paramètres : self = classe représentant une instruction. *
-* unused = adresse non utilisée ici. *
-* *
-* Description : Fournit le nom humain de l'instruction manipulée. *
-* *
-* Retour : Valeur associée à la propriété consultée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *unused)
-{
- PyObject *result; /* Trouvailles à retourner */
- GArchInstruction *instr; /* Version native */
- const char *kw; /* Valeur récupérée */
-
- instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- kw = g_arch_instruction_get_keyword(instr);
-
- result = PyString_FromString(kw);
-
- return result;
-
-}
-
/******************************************************************************
* *
@@ -438,3 +788,6 @@ bool register_python_arch_instruction(PyObject *module)
return (ret == 0);
}
+
+
+#endif