summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/analysis/routine.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/analysis/routine.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/analysis/routine.c')
-rw-r--r--plugins/pychrysa/analysis/routine.c190
1 files changed, 143 insertions, 47 deletions
diff --git a/plugins/pychrysa/analysis/routine.c b/plugins/pychrysa/analysis/routine.c
index 5cd56f5..2ca3560 100644
--- a/plugins/pychrysa/analysis/routine.c
+++ b/plugins/pychrysa/analysis/routine.c
@@ -25,25 +25,31 @@
#include "routine.h"
+#include <string.h>
#include <pygobject.h>
-#include <analysis/routine.h>
+#include <i18n.h>
+#include <analysis/routine.h>
-/* Crée un nouvel objet Python de type 'BinaryRoutine'. */
-static PyObject *py_binary_routine_new(PyTypeObject *, PyObject *, PyObject *);
+#include "block.h"
-/* Fournit les blocs basiques de la routine. */
-static PyObject *py_binary_routine_get_basic_blocks(PyObject *, void *);
+/* Crée un nouvel objet Python de type 'BinRoutine'. */
+static PyObject *py_binary_routine_new(PyTypeObject *, PyObject *, PyObject *);
-/* Décrit le prototype de la routine sous forme de caractères. */
-static PyObject *py_binary_routine_str(PyObject *);
+/* Fournit le nom humain d'une routine. */
+static PyObject *py_binary_routine_get_name(PyObject *, void *);
+/* Définit le nom humain d'une routine. */
+static int py_binary_routine_set_name(PyObject *, PyObject *, void *);
+
+/* Fournit les blocs basiques de la routine. */
+static PyObject *py_binary_routine_get_basic_blocks(PyObject *, void *);
@@ -72,7 +78,75 @@ static PyObject *py_binary_routine_new(PyTypeObject *type, PyObject *args, PyObj
}
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit le nom humain d'une routine. *
+* *
+* Retour : Désignation humainement lisible ou None si non définie. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_routine_get_name(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GBinRoutine *routine; /* Elément à consulter */
+ const char *name; /* Désignation courante */
+
+ routine = G_BIN_ROUTINE(pygobject_get(self));
+ name = g_binary_routine_get_name(routine);
+
+ if (name != NULL)
+ result = PyUnicode_FromString(name);
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = non utilisé ici. *
+* *
+* Description : Définit le nom humain d'une routine. *
+* *
+* Retour : Bilan de l'opération pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_binary_routine_set_name(PyObject *self, PyObject *value, void *closure)
+{
+ GBinRoutine *routine; /* Elément à consulter */
+
+ if (!PyUnicode_Check(value) && value != Py_None)
+ {
+ PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string."));
+ return -1;
+ }
+
+ routine = G_BIN_ROUTINE(pygobject_get(self));
+
+ if (!PyUnicode_Check(value))
+ g_binary_routine_set_name(routine, strdup(PyUnicode_DATA(value)));
+ else
+ g_binary_routine_set_name(routine, NULL);
+ return 0;
+
+}
/******************************************************************************
@@ -104,78 +178,76 @@ static PyObject *py_binary_routine_get_basic_blocks(PyObject *self, void *closur
}
-
-
-
/******************************************************************************
* *
-* Paramètres : self = classe représentant une routine binaire. *
+* Paramètres : self = objet Python concerné par l'appel. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = non utilisé ici. *
* *
-* Description : Décrit le prototype de la routine sous forme de caractères. *
+* Description : Définit les blocs basiques de la routine. *
* *
-* Retour : Chaîne de caractères. *
+* Retour : Bilan de l'opération pour Python. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_routine_str(PyObject *self)
+static int py_binary_routine_set_basic_blocks(PyObject *self, PyObject *value, void *closure)
{
- PyObject *result; /* Chaîne à retourner */
- GBinRoutine *routine; /* Version native */
- char *string; /* Description à libérer */
+ GBinRoutine *routine; /* Elément à consulter */
+ int ret; /* Bilan de lecture des args. */
+ GInstrBlock *blocks; /* Blocs basiques à intégrer */
- routine = G_BIN_ROUTINE(pygobject_get(self));
- string = g_binary_routine_to_string(routine);
+ ret = PyObject_IsInstance(value, (PyObject *)get_python_instr_block_type());
+ if (!ret) return -1;
- result = PyString_FromString(string);
+ routine = G_BIN_ROUTINE(pygobject_get(self));
+ blocks = G_INSTR_BLOCK(pygobject_get(value));
- free(string);
+ g_binary_routine_set_basic_blocks(routine, blocks);
- return result;
+ return 0;
}
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : - *
* *
-* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.*
+* Description : Fournit un accès à une définition de type à diffuser. *
* *
-* Retour : Bilan de l'opération. *
+* Retour : Définition d'objet pour Python. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool register_python_binary_routine(PyObject *module)
+PyTypeObject *get_python_binary_routine_type(void)
{
- PyObject *pygobj_mod; /* Module Python-GObject */
- int ret; /* Bilan d'un appel */
-
static PyMethodDef py_binary_routine_methods[] = {
{ NULL }
};
static PyGetSetDef py_binary_routine_getseters[] = {
{
- "basic_blocks", (getter)py_binary_routine_get_basic_blocks, (setter)NULL,
- "Provide the basic blocks of the binary routine.", NULL
+ "name", py_binary_routine_get_name, py_binary_routine_set_name,
+ "Name of the current routine.", NULL
+ },
+ {
+ "basic_blocks", py_binary_routine_get_basic_blocks, py_binary_routine_set_basic_blocks,
+ "Basic blocks of the binary routine.", NULL
},
{ NULL }
};
static PyTypeObject py_binary_routine_type = {
- PyObject_HEAD_INIT(NULL)
-
- .tp_name = "pychrysalide.analysis.BinaryRoutine",
- .tp_basicsize = sizeof(PyGObject),
+ PyVarObject_HEAD_INIT(NULL, 0)
- .tp_str = py_binary_routine_str,
+ .tp_name = "pychrysalide.analysis.BinRoutine",
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = "PyChrysalide binary routine",
@@ -185,21 +257,45 @@ bool register_python_binary_routine(PyObject *module)
};
- pygobj_mod = PyImport_ImportModule("gobject");
- if (pygobj_mod == NULL) return false;
+ return &py_binary_routine_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.analysis.BinRoutine'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_binary_routine(PyObject *module)
+{
+ PyTypeObject *py_binary_routine_type; /* Type Python 'BinRoutine' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_binary_routine_type = get_python_binary_routine_type();
- py_binary_routine_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
- Py_DECREF(pygobj_mod);
+ py_binary_routine_type->tp_base = &PyGObject_Type;
+ py_binary_routine_type->tp_basicsize = py_binary_routine_type->tp_base->tp_basicsize;
- if (PyType_Ready(&py_binary_routine_type) < 0)
+ if (PyType_Ready(py_binary_routine_type) != 0)
return false;
- Py_INCREF(&py_binary_routine_type);
- ret = PyModule_AddObject(module, "BinaryRoutine", (PyObject *)&py_binary_routine_type);
+ Py_INCREF(py_binary_routine_type);
+ ret = PyModule_AddObject(module, "BinRoutine", (PyObject *)py_binary_routine_type);
+ if (ret != 0) return false;
- pygobject_register_class(module, "GBinRoutine", G_TYPE_BIN_ROUTINE, &py_binary_routine_type,
- Py_BuildValue("(O)", py_binary_routine_type.tp_base));
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "BinRoutine", G_TYPE_BIN_ROUTINE, py_binary_routine_type,
+ Py_BuildValue("(O)", py_binary_routine_type->tp_base));
- return (ret == 0);
+ return true;
}