summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext/linegen.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-01-16 19:02:56 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-01-16 19:02:56 (GMT)
commit9da8f8b37e3edebc917b4e223dd2447cd7cbc818 (patch)
tree3f330b13e7ca2a0a163882be3043ca9571f25211 /plugins/pychrysalide/glibext/linegen.c
parenteb9b7fd76451db5c9f07a800c0394480e4b88c9c (diff)
Changed the Python bindings source directory and updated code.
Diffstat (limited to 'plugins/pychrysalide/glibext/linegen.c')
-rw-r--r--plugins/pychrysalide/glibext/linegen.c404
1 files changed, 404 insertions, 0 deletions
diff --git a/plugins/pychrysalide/glibext/linegen.c b/plugins/pychrysalide/glibext/linegen.c
new file mode 100644
index 0000000..b6aad6b
--- /dev/null
+++ b/plugins/pychrysalide/glibext/linegen.c
@@ -0,0 +1,404 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * linegen.c - équivalent Python du fichier "glibext/linegen.h"
+ *
+ * Copyright (C) 2017 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "linegen.h"
+
+
+#include <pygobject.h>
+
+
+#include <common/cpp.h>
+#include <glibext/linegen.h>
+
+
+#include "../helpers.h"
+#include "../analysis/content.h"
+#include "../arch/vmpa.h"
+#include "../glibext/bufferline.h"
+
+
+
+/* Indique le nombre de ligne prêtes à être générées. */
+static PyObject *py_line_generator_count_lines(PyObject *, PyObject *);
+
+/* Retrouve l'emplacement correspondant à une position donnée. */
+static PyObject *py_line_generator_compute_addr(PyObject *, PyObject *);
+
+/* Détermine si le conteneur s'inscrit dans une plage donnée. */
+static PyObject *py_line_generator_contains_addr(PyObject *, PyObject *);
+
+/* Renseigne sur les propriétés liées à un générateur. */
+static PyObject *py_line_generator_get_flags(PyObject *, PyObject *);
+
+/* Imprime dans une ligne de rendu le contenu représenté. */
+static PyObject *py_line_generator_print(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un générateur à manipuler. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Indique le nombre de ligne prêtes à être générées. *
+* *
+* Retour : Nombre de lignes devant apparaître au final. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_line_generator_count_lines(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Décompte à retourner */
+ GLineGenerator *generator; /* Version native */
+ size_t count; /* Nombre de lignes présentes */
+
+ generator = G_LINE_GENERATOR(pygobject_get(self));
+
+ count = g_line_generator_count_lines(generator);
+
+ result = Py_BuildValue("k", count);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un générateur à manipuler. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Retrouve l'emplacement correspondant à une position donnée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_line_generator_compute_addr(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Localisation à retourner */
+ GLineGenerator *generator; /* Version native */
+ gint x; /* Position géographique */
+ size_t index; /* Indice dans le tampon */
+ size_t repeat; /* Utilisations successives */
+ int ret; /* Bilan de lecture des args. */
+ vmpa2t addr; /* Adresse visée par l'opérat° */
+
+ generator = G_LINE_GENERATOR(pygobject_get(self));
+
+ ret = PyArg_ParseTuple(args, "ikk", &x, &index, &repeat);
+ if (!ret) return NULL;
+
+ g_line_generator_compute_addr(generator, x, &addr, index, repeat);
+
+ result = build_from_internal_vmpa(&addr);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un générateur à manipuler. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Détermine si le conteneur s'inscrit dans une plage donnée. *
+* *
+* Retour : Bilan de la détermination, utilisable en comparaisons. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_line_generator_contains_addr(PyObject *self, PyObject *args)
+{
+ GLineGenerator *generator; /* Version native */
+ PyObject *py_vmpa; /* Localisation version Python */
+ size_t index; /* Indice dans le tampon */
+ size_t repeat; /* Utilisations successives */
+ int ret; /* Bilan de lecture des args. */
+ vmpa2t *addr; /* Adresse visée par l'opérat° */
+
+ generator = G_LINE_GENERATOR(pygobject_get(self));
+
+ ret = PyArg_ParseTuple(args, "O!kk", get_python_vmpa_type(), &py_vmpa, &index, &repeat);
+ if (!ret) return NULL;
+
+ addr = get_internal_vmpa(py_vmpa);
+ if (addr == NULL) return NULL;
+
+ g_line_generator_contains_addr(generator, addr, index, repeat);
+
+ Py_RETURN_NONE;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un générateur à manipuler. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Renseigne sur les propriétés liées à un générateur. *
+* *
+* Retour : Propriétés particulières associées. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_line_generator_get_flags(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Propriétés à retourner */
+ GLineGenerator *generator; /* Version native */
+ size_t index; /* Indice dans le tampon */
+ size_t repeat; /* Utilisations successives */
+ int ret; /* Bilan de lecture des args. */
+ BufferLineFlags flags; /* Propriétés courantes */
+
+ generator = G_LINE_GENERATOR(pygobject_get(self));
+
+ ret = PyArg_ParseTuple(args, "kk", &index, &repeat);
+ if (!ret) return NULL;
+
+ flags = g_line_generator_get_flags(generator, index, repeat);
+
+ result = Py_BuildValue("I", flags);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un générateur à manipuler. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Imprime dans une ligne de rendu le contenu représenté. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_line_generator_print(PyObject *self, PyObject *args)
+{
+ GLineGenerator *generator; /* Version native */
+ PyObject *py_line; /* Ligne version Python */
+ size_t index; /* Indice dans le tampon */
+ size_t repeat; /* Utilisations successives */
+ PyObject *py_content; /* Contenu version Python */
+ int ret; /* Bilan de lecture des args. */
+ GBufferLine *line; /* Ligne de rendu à compléter */
+ GBinContent *content; /* Contenu binaire associé */
+
+ generator = G_LINE_GENERATOR(pygobject_get(self));
+
+ ret = PyArg_ParseTuple(args, "O!kkO!", get_python_buffer_line_type(), &py_line, &index,
+ &repeat, get_python_binary_content_type(), &py_content);
+ if (!ret) return NULL;
+
+ line = G_BUFFER_LINE(pygobject_get(py_line));
+
+ content = G_BIN_CONTENT(pygobject_get(py_content));
+
+ g_line_generator_print(generator, line, index, repeat, content);
+
+ Py_RETURN_NONE;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void python_line_generator_interface_init(GLineGeneratorIface *iface, PyTypeObject *type)
+{
+ GLineGeneratorIface *parent; /* Défintion parente */
+ size_t i; /* Boucle de parcours */
+ PyObject *method; /* Méthode à associer */
+
+ static const char *meth_names[] = {
+ "count_lines",
+ "compute_addr",
+ "contains_addr",
+ "get_flags",
+ "print"
+ };
+
+ parent = g_type_interface_peek_parent(iface);
+
+ for (i = 0; i < ARRAY_SIZE(meth_names); i++)
+ {
+ method = NULL;
+
+ if (type != NULL)
+ method = PyObject_GetAttrString((PyObject *)type, meth_names[i]);
+
+ if (method != NULL && PyObject_TypeCheck(method, &PyCFunction_Type) == 0)
+ /*iface->iface_method = _wrap_TestInterface__proxy_do_iface_method*/;
+
+ else
+ {
+ PyErr_Clear();
+
+ if (parent != NULL)
+ /*iface->iface_method = parent->iface_method*/;
+
+ }
+
+ Py_XDECREF(method);
+
+ }
+
+}
+
+
+#endif
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_line_generator_type(void)
+{
+ static PyMethodDef py_line_generator_methods[] = {
+ {
+ "count_lines", py_line_generator_count_lines,
+ METH_NOARGS,
+ "count_lines($self, /)\n--\n\nCount the number of lines which can be displayed."
+ },
+ {
+ "compute_addr", py_line_generator_compute_addr,
+ METH_VARARGS,
+ "compute_addr($self, x, index, repeat, /)\n--\n\nReturn the position at a given location."
+ },
+ {
+ "contains_addr", py_line_generator_contains_addr,
+ METH_VARARGS,
+ "contains_addr($self, addr, index, repeat, /)\n--\n\nTell if the generator contains an address."
+ },
+ {
+ "get_flags", py_line_generator_get_flags,
+ METH_VARARGS,
+ "get_flags($self, index, repeat, /)\n--\n\nGet the flags of a position from the generator."
+ },
+ {
+ "print", py_line_generator_print,
+ METH_VARARGS,
+ "print($self, line, index, repeat, content, /)\n--\n\nProduce output into a line from content."
+ },
+ { NULL }
+ };
+
+ static PyGetSetDef py_line_generator_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_line_generator_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.glibext.LineGenerator",
+ //.tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide line content generator",
+
+ .tp_methods = py_line_generator_methods,
+ .tp_getset = py_line_generator_getseters,
+
+ };
+
+ return &py_line_generator_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_line_generator(PyObject *module)
+{
+ PyTypeObject *py_line_generator_type; /* Type Python 'LineGenerator' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_line_generator_type = get_python_line_generator_type();
+
+ dict = PyModule_GetDict(module);
+ pyg_register_interface(dict, "LineGenerator", G_TYPE_LINE_GENERATOR, py_line_generator_type);
+
+ return true;
+
+}