summaryrefslogtreecommitdiff
path: root/plugins/pyoida/analysis/py_line_code.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pyoida/analysis/py_line_code.c')
-rw-r--r--plugins/pyoida/analysis/py_line_code.c281
1 files changed, 281 insertions, 0 deletions
diff --git a/plugins/pyoida/analysis/py_line_code.c b/plugins/pyoida/analysis/py_line_code.c
new file mode 100644
index 0000000..26fe513
--- /dev/null
+++ b/plugins/pyoida/analysis/py_line_code.c
@@ -0,0 +1,281 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * py_line_code.h - prototypes pour l'intermédiaire des lignes de code pour Python
+ *
+ * Copyright (C) 2009 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 "py_line_code.h"
+
+
+#include "py_line-int.h"
+
+
+
+typedef struct {
+
+ PyLine base; /* Classe dérivée */
+
+} PyCodeLine;
+
+
+
+
+/* Fournit la description du type 'PyCodeLine' pour Python. */
+static PyTypeObject *pycodeline_get_type(void);
+
+
+
+
+static int
+pycodeline_init(PyCodeLine *self, PyObject *args, PyObject *kwds);
+
+static PyObject *
+pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit la description du type 'PyCodeLine' pour Python. *
+* *
+* Retour : Adresse de la description du type 'PyCodeLine'. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyTypeObject *pycodeline_get_type(void)
+{
+ static PyMethodDef pycodeline_methods[] = {
+#if 0
+ {"name", (PyCFunction)pyline_name, METH_NOARGS,
+ "Return the name, combining the first and last name"
+ },
+#endif
+ { NULL }
+};
+
+ static PyTypeObject result = {
+
+ PyObject_HEAD_INIT(NULL)
+
+#if PY_VERSION_HEX < 0x03000000
+ 0, /*ob_size*/
+#endif
+
+ "pyoida.analysis.PyCodeLine", /* tp_name */
+ sizeof(PyCodeLine), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_reserved / tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "pycodeline objects", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pycodeline_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)pycodeline_init, /* tp_init */
+ 0, /* tp_alloc */
+ pycodeline_new, /* tp_new */
+ };
+
+ return &result;
+
+}
+
+
+
+
+static int
+pycodeline_init(PyCodeLine *self, PyObject *args, PyObject *kwds)
+{
+#if 0
+ PyObject *first=NULL, *last=NULL, *tmp;
+
+ static char *kwlist[] = {"first", "last", "number", NULL};
+
+ printf("pycodeline_init\n");
+
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist,
+ &first, &last,
+ &self->number))
+ return -1;
+
+ if (first) {
+ tmp = self->first;
+ Py_INCREF(first);
+ self->first = first;
+ Py_DECREF(tmp);
+ }
+
+ if (last) {
+ tmp = self->last;
+ Py_INCREF(last);
+ self->last = last;
+ Py_DECREF(tmp);
+ }
+#endif
+ return 0;
+}
+
+
+
+
+
+static PyObject *
+pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyCodeLine *self;
+
+
+ printf("creating a new line\n");
+
+ self = (PyCodeLine *)type->tp_alloc(type, 0);
+ if (self != NULL) {
+#if 0
+ self->first = PyString_FromString("");//PyUnicode_FromString("");
+ if (self->first == NULL)
+ {
+ Py_DECREF(self);
+ return NULL;
+ }
+
+ self->last = PyString_FromString("");//PyUnicode_FromString("");
+ if (self->last == NULL)
+ {
+ Py_DECREF(self);
+ return NULL;
+ }
+
+ self->number = 0;
+#endif
+ }
+
+ return (PyObject *)self;
+}
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : head = ???? *
+* line = modèle à représenter en Python. *
+* *
+* Description : Initialise le greffon permettant l'usage de Python. *
+* *
+* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *pycodeline_new_from_existing(GRenderingLine *head, GCodeLine *line)
+{
+ PyCodeLine *result; /* Nouvelle instance à renvoyer*/
+ PyTypeObject *type; /* Type d'objet à créer */
+
+ result = (PyCodeLine *)g_object_get_data(G_OBJECT(line), "pyobject");
+
+ if (result == NULL)
+ {
+ type = pycodeline_get_type();
+
+ result = (PyCodeLine *)type->tp_alloc(type, 0);
+
+ if (result != NULL)
+ {
+ pyline_init_from_existing((PyLine *)result, head, line);
+
+ g_object_set_data(G_OBJECT(line), "pyobject", result);
+
+ }
+
+ }
+
+ return (PyObject *)result;
+
+}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'line' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_pycodeline_to_python_module(PyObject *module)
+{
+
+
+ pycodeline_get_type()->tp_base = pyline_get_type();
+ if (PyType_Ready(pycodeline_get_type()) < 0)
+ return false;
+
+
+ Py_INCREF(pycodeline_get_type());
+ PyModule_AddObject(module, "codeline", (PyObject *)pycodeline_get_type());
+
+
+
+ return true; /* FIXME */
+
+}