diff options
Diffstat (limited to 'plugins/pyoida/analysis')
-rw-r--r-- | plugins/pyoida/analysis/Makefile.am | 20 | ||||
-rw-r--r-- | plugins/pyoida/analysis/binary.c | 279 | ||||
-rw-r--r-- | plugins/pyoida/analysis/binary.h | 44 | ||||
-rw-r--r-- | plugins/pyoida/analysis/exporter-int.h | 53 | ||||
-rw-r--r-- | plugins/pyoida/analysis/exporter.c | 284 | ||||
-rw-r--r-- | plugins/pyoida/analysis/exporter.h | 44 | ||||
-rw-r--r-- | plugins/pyoida/analysis/line.c | 793 | ||||
-rw-r--r-- | plugins/pyoida/analysis/line.h | 61 | ||||
-rw-r--r-- | plugins/pyoida/analysis/module.c | 76 | ||||
-rw-r--r-- | plugins/pyoida/analysis/module.h | 39 | ||||
-rw-r--r-- | plugins/pyoida/analysis/py_binary.c | 363 | ||||
-rw-r--r-- | plugins/pyoida/analysis/py_binary.h | 45 | ||||
-rw-r--r-- | plugins/pyoida/analysis/py_line-int.h | 53 | ||||
-rw-r--r-- | plugins/pyoida/analysis/py_line.c | 606 | ||||
-rw-r--r-- | plugins/pyoida/analysis/py_line.h | 45 | ||||
-rw-r--r-- | plugins/pyoida/analysis/py_line_code.c | 281 | ||||
-rw-r--r-- | plugins/pyoida/analysis/py_line_code.h | 45 | ||||
-rw-r--r-- | plugins/pyoida/analysis/roptions.c | 272 | ||||
-rw-r--r-- | plugins/pyoida/analysis/roptions.h | 45 |
19 files changed, 0 insertions, 3448 deletions
diff --git a/plugins/pyoida/analysis/Makefile.am b/plugins/pyoida/analysis/Makefile.am deleted file mode 100644 index e67f188..0000000 --- a/plugins/pyoida/analysis/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ - -noinst_LTLIBRARIES = libpyoidaanalysis.la - -libpyoidaanalysis_la_SOURCES = \ - binary.h binary.c \ - exporter-int.h \ - exporter.h exporter.c \ - line.h line.c \ - module.h module.c \ - roptions.h roptions.c - - -libpyoidaanalysis_la_LDFLAGS = - - -INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) -I../../../src - -AM_CPPFLAGS = - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pyoida/analysis/binary.c b/plugins/pyoida/analysis/binary.c deleted file mode 100644 index d378496..0000000 --- a/plugins/pyoida/analysis/binary.c +++ /dev/null @@ -1,279 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * binary.c - équivalent Python du fichier "analysis/binary.h" - * - * Copyright (C) 2010 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 "binary.h" - - -#include "line.h" -#include "../format/executable.h" - - - - -/* Classe 'analysis.binary' pour Python */ -typedef struct _py_binary -{ - PyObject_HEAD - - GOpenidaBinary *binary; /* Référence GLib */ - -} py_binary; - - - - -/* Crée un nouvel objet Python de type 'py_binary'. */ -static PyObject *py_binary_new(PyTypeObject *, PyObject *, PyObject *); - - - - -/* Fournit le format de fichier reconnu dans le contenu binaire. */ -static PyObject *py_binary_get_format(py_binary *); - -/* Fournit les lignes de rendu associé pour Python. */ -static PyObject *py_binary_get_lines(py_binary *); - - - -/* Fournit le type d'objet 'analysis.binary' pour Python. */ -static PyTypeObject *get_analysis_binary_type(void); - - - - -/****************************************************************************** -* * -* 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 'py_binary'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_binary *result; /* Instance à retourner */ - - result = (py_binary *)type->tp_alloc(type, 0); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : binary = objet GLib existant à transposer. * -* * -* Description : Crée un nouvel objet Python de type 'py_binary'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *py_binary_new_from_existing(GOpenidaBinary *binary) -{ - py_binary *result; /* Instance à retourner */ - PyTypeObject *type; /* Type Python à instancier */ - - result = (py_binary *)g_object_get_data(G_OBJECT(binary), "python_object"); - - if (result == NULL) - { - type = get_analysis_binary_type(); - - result = (py_binary *)type->tp_alloc(type, 0); - - result->binary = binary; - g_object_ref(binary); - - g_object_set_data(G_OBJECT(binary), "python_object", result); - - } - else Py_INCREF((PyObject *)result); - - return (PyObject *)result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit le format de fichier reconnu dans le contenu binaire.* -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_get_format(py_binary *self) -{ - PyObject *result; /* Liste à retourner */ - GExeFormat *format; /* Format récupéré à convertir */ - - format = g_openida_binary_get_format(self->binary); - - result = py_executable_convert(format); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit les lignes de rendu associé pour Python. * -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_get_lines(py_binary *self) -{ - PyObject *result; /* Liste à retourner */ - GRenderingLine *lines; /* Liste récupérée à convertir */ - - lines = g_openida_binary_get_lines(self->binary); - - result = py_line_new_from_existing(lines); - - return result; - -} - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.binary' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_binary_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyMethodDef py_binary_methods[] = { - { - "get_format", (PyCFunction)py_binary_get_format, - METH_NOARGS, - "Give the file format recognized in the binary content." - }, - { - "get_lines", (PyCFunction)py_binary_get_lines, - METH_NOARGS, - "Provide the rendering lines used by the binary." - }, - { NULL } - }; - - static PyGetSetDef py_binary_getset[] = { - { NULL } - }; - - static PyTypeObject py_binary_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.Binary", - .tp_basicsize = sizeof(py_binary), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA loaded binary to analyse", - - .tp_methods = py_binary_methods, - .tp_getset = py_binary_getset, - .tp_new = (newfunc)py_binary_new - - }; - - if (result == NULL) result = &py_binary_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.binary' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_binary_to_python_module(PyObject *module) -{ - PyTypeObject *py_binary_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_binary_type = get_analysis_binary_type(); - - if (PyType_Ready(py_binary_type) < 0) - return false; - - Py_INCREF(py_binary_type); - ret = PyModule_AddObject(module, "Binary", (PyObject *)py_binary_type); - - return (ret == 0); - -} diff --git a/plugins/pyoida/analysis/binary.h b/plugins/pyoida/analysis/binary.h deleted file mode 100644 index 1500a06..0000000 --- a/plugins/pyoida/analysis/binary.h +++ /dev/null @@ -1,44 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * binary.h - prototypes pour l'équivalent Python du fichier "analysis/binary.h" - * - * Copyright (C) 2010 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 - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_BINARY_H -#define _PLUGINS_PYOIDA_ANALYSIS_BINARY_H - - -#include <Python.h> -#include <stdbool.h> - -#include <analysis/binary.h> - - - -/* Crée un nouvel objet Python de type 'py_binary'. */ -PyObject *py_binary_new_from_existing(GOpenidaBinary *); - -/* Ajoute l'objet 'analysis.binary' au module Python. */ -bool add_analysis_binary_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_BINARY_H */ diff --git a/plugins/pyoida/analysis/exporter-int.h b/plugins/pyoida/analysis/exporter-int.h deleted file mode 100644 index 2498d4b..0000000 --- a/plugins/pyoida/analysis/exporter-int.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * exporter-int.h - prototypes internes pour l'équivalent Python du fichier "analysis/exporter.h" - * - * Copyright (C) 2010 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 - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_INT_H -#define _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_INT_H - - -#include <Python.h> - -#include <analysis/exporter.h> - - - -/* Classe 'analysis.exporter' pour Python */ -typedef struct _py_exporter -{ - PyObject_HEAD - - GContentExporter *glib; /* Interface version GLib */ - -} py_exporter; - - -#define PY_EXPORTER(exp) ((py_exporter *)exp) - - -/* Fournit le type d'objet 'analysis.exporter' pour Python. */ -PyTypeObject *get_analysis_exporter_type(void); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_INT_H */ diff --git a/plugins/pyoida/analysis/exporter.c b/plugins/pyoida/analysis/exporter.c deleted file mode 100644 index 8c49542..0000000 --- a/plugins/pyoida/analysis/exporter.c +++ /dev/null @@ -1,284 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * exporter.c - équivalent Python du fichier "analysis/exporter.h" - * - * Copyright (C) 2010 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 "exporter.h" - - -#include <fcntl.h> -#include <stdio.h> -#include <unistd.h> - - -#include "exporter-int.h" -#include "../analysis/roptions.h" - - - - -#define PY_EXPORT_TEXT_BUFLEN 64 - - -/* Crée un nouvel objet Python de type 'py_exporter'. */ -static PyObject *py_exporter_new(PyTypeObject *, PyObject *, PyObject *); - - - - -/* Fournit le texte correspondant à un contenu rendu. */ -static PyObject *py_exporter_get_text(py_exporter *, PyObject *); - - - - - -/****************************************************************************** -* * -* 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 'py_exporter'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_exporter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_exporter *result; /* Instance à retourner */ - - result = (py_exporter *)type->tp_alloc(type, 0); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : exporter = objet GLib existant à transposer. * -* * -* Description : Crée un nouvel objet Python de type 'py_exporter'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *py_exporter_new_from_existing(GContentExporter *exporter) -{ - py_exporter *result; /* Instance à retourner */ - PyTypeObject *type; /* Type Python à instancier */ - - result = (py_exporter *)g_object_get_data(G_OBJECT(exporter), "python_object"); - - if (result == NULL) - { - type = get_analysis_exporter_type(); - - result = (py_exporter *)type->tp_alloc(type, 0); - - result->glib = exporter; - g_object_ref(exporter); - - g_object_set_data(G_OBJECT(exporter), "python_object", result); - - } - else Py_INCREF((PyObject *)result); - - return (PyObject *)result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* args = arguments fournis à l'appel. * -* * -* Description : Fournit le texte correspondant à un contenu rendu. * -* * -* Retour : Chaîne de caractères Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_exporter_get_text(py_exporter *self, PyObject *args) -{ - PyObject *result; /* Liste à retourner */ - PyObject *roptions; /* Options de rendu jointes */ - int ret; /* Bilan de lecture des args. */ - GRenderingOptions *_roptions; /* Version GLib des options */ - int fd[2]; /* Tube pour récupérer le code */ - FILE *stream; /* Flux (ré)ouvert en écriture */ - char buffer[PY_EXPORT_TEXT_BUFLEN]; /* Tampon pour la lecture */ - ssize_t len; /* Nombre de caractères lus */ - PyObject *src; /* Source ajoutée au résultat */ - - ret = PyArg_ParseTuple(args, "O", &roptions); - if (!ret) return Py_None; - - _roptions = py_rendering_options_get_glib_instance(roptions); - - result = Py_None; - - ret = pipe2(fd, O_NONBLOCK); - //if (ret ... perror("pipe"); goto pegt_pipe_error; - - - stream = fdopen(fd[1], "w"); - if (stream == NULL) - { - perror("stream"); - goto pegt_stream_error; - } - - g_content_exporter_add_text(self->glib, _roptions, MRD_BLOCK/* FIXME*/, stream); - fflush(stream); - - do - { - memset(buffer, 0, PY_EXPORT_TEXT_BUFLEN); - len = read(fd[0], buffer, PY_EXPORT_TEXT_BUFLEN); - - src = PyString_FromString(buffer); - - if (result == Py_None) result = src; - else PyString_ConcatAndDel(&result, src); - - } - while (len > 0); - - fclose(stream); - - pegt_stream_error: - - close(fd[0]); - //close(fd[1]); - - pegt_pipe_error: - - return result; - -} - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.exporter' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_analysis_exporter_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyMethodDef py_exporter_methods[] = { - { - "get_text", (PyCFunction)py_exporter_get_text, - METH_VARARGS, - "Provide the text version of the rendered content." - }, - { NULL } - }; - - static PyGetSetDef py_exporter_getset[] = { - { NULL } - }; - - static PyTypeObject py_exporter_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.Exporter", - .tp_basicsize = sizeof(py_exporter), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA exporter interface", - - .tp_methods = py_exporter_methods, - .tp_getset = py_exporter_getset, - .tp_new = (newfunc)py_exporter_new - - }; - - if (result == NULL) result = &py_exporter_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.exporter' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_exporter_to_python_module(PyObject *module) -{ - PyTypeObject *py_exporter_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_exporter_type = get_analysis_exporter_type(); - - if (PyType_Ready(py_exporter_type) < 0) - return false; - - Py_INCREF(py_exporter_type); - ret = PyModule_AddObject(module, "Exporter", (PyObject *)py_exporter_type); - - return (ret == 0); - -} diff --git a/plugins/pyoida/analysis/exporter.h b/plugins/pyoida/analysis/exporter.h deleted file mode 100644 index 4668934..0000000 --- a/plugins/pyoida/analysis/exporter.h +++ /dev/null @@ -1,44 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * exporter.h - prototypes pour l'équivalent Python du fichier "analysis/exporter.h" - * - * Copyright (C) 2010 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 - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_H -#define _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_H - - -#include <Python.h> -#include <stdbool.h> - -#include <analysis/exporter.h> - - - -/* Crée un nouvel objet Python de type 'py_exporter'. */ -PyObject *py_exporter_new_from_existing(GContentExporter *); - -/* Ajoute l'objet 'analysis.exporter' au module Python. */ -bool add_analysis_exporter_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_H */ diff --git a/plugins/pyoida/analysis/line.c b/plugins/pyoida/analysis/line.c deleted file mode 100644 index fd697e2..0000000 --- a/plugins/pyoida/analysis/line.c +++ /dev/null @@ -1,793 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * line.c - équivalent Python du fichier "analysis/line.h" - * - * Copyright (C) 2010 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 "line.h" - - -#include "exporter-int.h" -#include "../arch/archbase.h" - - - - - - - -/* Classe 'analysis.line' pour Python */ -typedef struct _py_line -{ - py_exporter parent; /* A laisser en premier */ - - GRenderingLine *line; /* Référence GLib */ - -} py_line; - - - - -/* Crée un nouvel objet Python de type 'py_line'. */ -static PyObject *py_line_new(PyTypeObject *, PyObject *, PyObject *); - - - - - - -/* Fournit le type d'objet 'analysis.line' pour Python. */ -static PyTypeObject *get_analysis_line_type(void); - - - -/* Prépare un parcours de lignes. */ -static PyObject *py_line_get_iter(py_line *); - -/* Prépare un parcours de lignes en sens inverse. */ -static PyObject *py_line_get_riter(py_line *); - - - -/* Fournit l'adresse physique ou en mémoire d'une ligne. */ -static PyObject *py_line_get_address(py_line *, void *); - -/* Fournit le commentaire associé à la ligne s'il existe. */ -static PyObject *py_line_get_comment(py_line *, void *); - -/* Définit ou supprime un commentaire pour la ligne indiquée. */ -static int py_line_set_comment(py_line *, PyObject *, void *); - - - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Itérateur pour lignes de rendu */ -typedef struct _py_line_iter -{ - PyObject_HEAD /* A laisser en premier */ - - GRenderingLine *head; /* Liste à parcourir */ - GRenderingLine *cur; /* Point de parcours courant */ - -} py_line_iter; - - -/* Fournit le type d'objet 'analysis.LineIter' pour Python. */ -static PyTypeObject *get_analysis_line_iter_type(void); - -/* Prépare l'itérateur pour un parcours de lignes de rendu. */ -static PyObject *py_line_iter_new(GRenderingLine *); - -/* Libère la mémoire occupée par un itérateur de 'py_line'. */ -static void py_line_iter_dealloc(py_line_iter *); - -/* Fournit l'élément suivant dans un parcours de lignes. */ -static PyObject *py_line_iter_get_next(py_line_iter *); - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Itérateur pour lignes de rendu */ -typedef py_line_iter py_line_riter; - - -/* Fournit le type d'objet 'analysis.LineRevIter' pour Python. */ -static PyTypeObject *get_analysis_line_riter_type(void); - -/* Prépare l'itérateur pour un parcours de lignes de rendu. */ -static PyObject *py_line_riter_new(GRenderingLine *); - -/* Libère la mémoire occupée par un itérateur de 'py_line'. */ -static void py_line_riter_dealloc(py_line_riter *); - -/* Fournit l'élément précédant dans un parcours de lignes. */ -static PyObject *py_line_riter_get_prev(py_line_riter *); - - - - - - - - - - - - - - - - -/****************************************************************************** -* * -* 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 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_line *result; /* Instance à retourner */ - - result = (py_line *)type->tp_alloc(type, 0); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : line = objet GLib existant à transposer. * -* * -* Description : Crée un nouvel objet Python de type 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *py_line_new_from_existing(GRenderingLine *line) -{ - py_line *result; /* Instance à retourner */ - PyTypeObject *type; /* Type Python à instancier */ - - result = (py_line *)g_object_get_data(G_OBJECT(line), "python_object"); - - if (result == NULL) - { - type = get_analysis_line_type(); - - result = (py_line *)type->tp_alloc(type, 0); - - PY_EXPORTER(result)->glib = G_CONTENT_EXPORTER(line); /* TODO : move me ! */ - - result->line = line; - g_object_ref(line); - - g_object_set_data(G_OBJECT(line), "python_object", result); - - } - else Py_INCREF((PyObject *)result); - - return (PyObject *)result; - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.line' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_line_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyMethodDef py_line_methods[] = { - { - "__reversed__", (PyCFunction)py_line_get_riter, - METH_NOARGS, - "Return a reverse iterator over the rendering lines." - }, - { NULL } - }; - - static PyGetSetDef py_line_getset[] = { - { - "address", - (getter)py_line_get_address, - (setter)NULL, - "Get the physical or virtual address relative to the line." - }, - { - "comment", - (getter)py_line_get_comment, - (setter)py_line_set_comment, - "Get or set a comment for the rendering line." - }, - { NULL } - }; - - static PyTypeObject py_line_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.Line", - .tp_basicsize = sizeof(py_line), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA rendering line", - - .tp_iter = (getiterfunc)py_line_get_iter, - - .tp_methods = py_line_methods, - .tp_getset = py_line_getset, - .tp_new = (newfunc)py_line_new - - }; - - if (result == NULL) - { - py_line_type.tp_base = get_analysis_exporter_type(); - result = &py_line_type; - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.line' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_line_to_python_module(PyObject *module) -{ - PyTypeObject *py_line_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_line_type = get_analysis_line_type(); - - if (PyType_Ready(py_line_type) < 0) - return false; - - Py_INCREF(py_line_type); - ret = PyModule_AddObject(module, "Line", (PyObject *)py_line_type); - - return (ret == 0); - -} - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Prépare un parcours de lignes. * -* * -* Retour : Point de départ d'un parcours. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_iter(py_line *self) -{ - return (PyObject *)py_line_iter_new(self->line); - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Prépare un parcours de lignes en sens inverse. * -* * -* Retour : Point de départ d'un parcours. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_riter(py_line *self) -{ - return (PyObject *)py_line_riter_new(self->line); - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant une ligne de rendu. * -* data = adresse non utilisée ici. * -* * -* Description : Fournit l'adresse physique ou en mémoire d'une ligne. * -* * -* Retour : Position physique ou en mémoire associée à la ligne. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_address(py_line *self, void *data) -{ - vmpa_t value; /* Adresse à convertir */ - - value = get_rendering_line_address(self->line); - - return py_vmpa_new_from_existing(value); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant une ligne de rendu. * -* data = adresse non utilisée ici. * -* * -* Description : Fournit le commentaire associé à la ligne s'il existe. * -* * -* Retour : Chaîne de caractères ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_comment(py_line *self, void *data) -{ - const char *comment; /* Commentaire à transmettre */ - - comment = get_rendering_line_comment(self->line); - - return Py_BuildValue("s", comment); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant des options de représentation. * -* value = nouvelle valeur affectée. * -* data = adresse non utilisée ici. * -* * -* Description : Définit ou supprime un commentaire pour la ligne indiquée. * -* * -* Retour : Bilan de la mise à jour. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_line_set_comment(py_line *self, PyObject *value, void *data) -{ - char *comment; /* Commentaire à définir */ - - comment = PyString_AsString(value); - /* FIXME : nil pour supprimer ? */ - - set_rendering_line_comment(self->line, comment); - - return 0; - -} - - - - - - - - - - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* ITERATEUR POUR LE PARCOURS DE LIGNES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.LineIter' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_line_iter_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyTypeObject py_line_iter_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.LineIter", - .tp_basicsize = sizeof(py_line_iter), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA iterator for rendering lines", - - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)py_line_iter_get_next - - }; - - if (result == NULL) result = &py_line_iter_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.LineIter' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_line_iter_to_python_module(PyObject *module) -{ - PyTypeObject *py_line_iter_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_line_iter_type = get_analysis_line_iter_type(); - - if (PyType_Ready(py_line_iter_type) < 0) - return false; - - Py_INCREF(py_line_iter_type); - ret = PyModule_AddObject(module, "Iter", (PyObject *)py_line_iter_type); - - return (ret == 0); - -} - - -/****************************************************************************** -* * -* Paramètres : head = liste à parcourir. * -* * -* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * -* * -* Retour : Instance d'itérateur prête à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_iter_new(GRenderingLine *head) -{ - py_line_iter *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - type = get_analysis_line_iter_type(); - - result = (py_line_iter *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->cur = NULL; - } - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à supprimer. * -* * -* Description : Libère la mémoire occupée par un itérateur de 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_line_iter_dealloc(py_line_iter *self) -{ -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject *)self); -#else - Py_TYPE(self)->tp_free((PyObject *)self); -#endif - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit l'élément suivant dans un parcours de lignes. * -* * -* Retour : Point suivant du parcours ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_iter_get_next(py_line_iter *self) -{ - PyObject *result; /* Elément à retourner */ - GRenderingLine *next; /* Elément réel suivant */ - - if (self->cur == NULL) next = self->head; - else next = g_rendering_line_get_next_iter(self->head, self->cur, NULL); - - if (next != NULL) - { - self->cur = next; - result = py_line_new_from_existing(next); - Py_INCREF(result); - } - else result = NULL; - - return (PyObject *)result; - -} - -/* ---------------------------------------------------------------------------------- */ -/* ITERATEUR POUR LE PARCOURS DE LIGNES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.LineRevIter' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_line_riter_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyTypeObject py_line_riter_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.LineRevIter", - .tp_basicsize = sizeof(py_line_riter), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA iterator for rendering lines", - - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)py_line_riter_get_prev - - }; - - if (result == NULL) result = &py_line_riter_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.LineRevIter' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_line_riter_to_python_module(PyObject *module) -{ - PyTypeObject *py_line_riter_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_line_riter_type = get_analysis_line_riter_type(); - - if (PyType_Ready(py_line_riter_type) < 0) - return false; - - Py_INCREF(py_line_riter_type); - ret = PyModule_AddObject(module, "RevIter", (PyObject *)py_line_riter_type); - - return (ret == 0); - -} - - -/****************************************************************************** -* * -* Paramètres : head = liste à parcourir. * -* * -* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * -* * -* Retour : Instance d'itérateur prête à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_riter_new(GRenderingLine *head) -{ - py_line_riter *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - type = get_analysis_line_riter_type(); - - result = (py_line_riter *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->cur = NULL; - } - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à supprimer. * -* * -* Description : Libère la mémoire occupée par un itérateur de 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_line_riter_dealloc(py_line_riter *self) -{ -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject *)self); -#else - Py_TYPE(self)->tp_free((PyObject *)self); -#endif - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit l'élément précédant dans un parcours de lignes. * -* * -* Retour : Point suivant du parcours ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_riter_get_prev(py_line_riter *self) -{ - PyObject *result; /* Elément à retourner */ - GRenderingLine *prev; /* Elément réel précédant */ - - if (self->cur == NULL) prev = g_rendering_line_get_last_iter(self->head, NULL); - else prev = g_rendering_line_get_prev_iter(self->head, self->cur, NULL); - - if (prev != NULL) - { - self->cur = prev; - result = py_line_new_from_existing(prev); - Py_INCREF(result); - } - else result = NULL; - - return (PyObject *)result; - -} diff --git a/plugins/pyoida/analysis/line.h b/plugins/pyoida/analysis/line.h deleted file mode 100644 index e71596c..0000000 --- a/plugins/pyoida/analysis/line.h +++ /dev/null @@ -1,61 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * line.h - prototypes pour l'équivalent Python du fichier "analysis/line.h" - * - * Copyright (C) 2010 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 - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_LINE_H -#define _PLUGINS_PYOIDA_ANALYSIS_LINE_H - - -#include <Python.h> -#include <stdbool.h> - -#include <analysis/line.h> - - - -/* Crée un nouvel objet Python de type 'py_line'. */ -PyObject *py_line_new_from_existing(GRenderingLine *); - -/* Ajoute l'objet 'analysis.line' au module Python. */ -bool add_analysis_line_to_python_module(PyObject *); - - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Ajoute l'objet 'analysis.LineIter' au module Python. */ -bool add_analysis_line_iter_to_python_module(PyObject *); - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Ajoute l'objet 'analysis.LineRevIter' au module Python. */ -bool add_analysis_line_riter_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_LINE_H */ diff --git a/plugins/pyoida/analysis/module.c b/plugins/pyoida/analysis/module.c deleted file mode 100644 index 8f07002..0000000 --- a/plugins/pyoida/analysis/module.c +++ /dev/null @@ -1,76 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire analysis en tant que module - * - * Copyright (C) 2010 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 "module.h" - - -#include "binary.h" -#include "exporter.h" -#include "line.h" -#include "roptions.h" - - - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'analysis' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_module_to_python_module(PyObject *super) -{ - bool result; - PyObject *module; - int ret; /* Bilan d'un appel */ - - static PyMethodDef py_analysis_methods[] = { - { NULL } - }; - - module = Py_InitModule("pyoida.analysis", py_analysis_methods); - if (module == NULL) return false; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "pyoida.analysis", module); - - result = (ret != 0); - - result &= add_analysis_binary_to_python_module(module); - result &= add_analysis_exporter_to_python_module(module); - result &= add_analysis_line_to_python_module(module); - result &= add_analysis_line_iter_to_python_module(module); - result &= add_analysis_line_riter_to_python_module(module); - result &= add_analysis_roptions_to_python_module(module); - - return result; - -} diff --git a/plugins/pyoida/analysis/module.h b/plugins/pyoida/analysis/module.h deleted file mode 100644 index a8bd329..0000000 --- a/plugins/pyoida/analysis/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire analysis en tant que module - * - * Copyright (C) 2010 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 - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_MODULE_H -#define _PLUGINS_PYOIDA_ANALYSIS_MODULE_H - - -#include <Python.h> -#include <stdbool.h> - - - -/* Ajoute le module 'analysis' au module Python. */ -bool add_analysis_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_MODULE_H */ diff --git a/plugins/pyoida/analysis/py_binary.c b/plugins/pyoida/analysis/py_binary.c deleted file mode 100644 index 04d4881..0000000 --- a/plugins/pyoida/analysis/py_binary.c +++ /dev/null @@ -1,363 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_binary.c - intermédiaire des binaires 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_binary.h" - -#include <structmember.h> - - - -#include "py_line.h" - - - -typedef struct { - PyObject_HEAD - - GOpenidaBinary *binary; /* Instance réelle rattachée */ - -} pybinary; - - -#define _(str) str - - - - - -/* Fournit la description du type 'binary' pour Python. */ -PyTypeObject *pybinary_get_type(void); - - - - -/* Fournit les lignes de rendu associé pour Python. */ -static PyObject *pybinary_get_lines(pybinary *); - - - - - - - -static void -pybinary_dealloc(pybinary* self) -{ -#if 0 - Py_XDECREF(self->first); - Py_XDECREF(self->last); -#endif - - //printf("dealloc\n"); - -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject*)self); -#else - Py_TYPE(self)->tp_free((PyObject*)self); -#endif - - //printf("dealloc::end\n"); - -} - -static PyObject * -pybinary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - pybinary *self; - - - printf("creating a new binary\n"); - - self = (pybinary *)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 : binary = 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 *pybinary_new_from_existing(GOpenidaBinary *binary) -{ - pybinary *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - printf("EXISTING :: %p\n", binary); - - type = pybinary_get_type(); - - result = (pybinary *)type->tp_alloc(type, 0); - - if (result != NULL) - result->binary = binary; - - return (PyObject *)result; - -} - - - - -static int -pybinary_init(pybinary *self, PyObject *args, PyObject *kwds) -{ -#if 0 - PyObject *first=NULL, *last=NULL, *tmp; - - static char *kwlist[] = {"first", "last", "number", NULL}; - - printf("pybinary_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 PyMemberDef pybinary_members[] = { -#if 0 - {"number", T_INT, offsetof(pybinary, number), 0, - "noddy number"}, -#endif - {NULL} /* Sentinel */ -}; - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit les lignes de rendu associé pour Python. * -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pybinary_get_lines(pybinary *self) -{ - PyObject *result; /* Liste à retourner */ - GRenderingLine *lines; /* Liste récupérée à convertir */ - - lines = g_openida_binary_get_lines(self->binary); - - result = pyline_new_from_existing(lines, lines); - - return result; - -} - - - - -#if 0 -static PyObject * -pybinary_name(pybinary* self) -{ - static PyObject *format = NULL; - PyObject *args, *result; - - if (format == NULL) { - format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); - if (format == NULL) - return NULL; - } - - args = Py_BuildValue("OO", self->first, self->last); - if (args == NULL) - return NULL; - - result = PyUnicode_Format(format, args); - Py_DECREF(args); - - return result; -} -#endif - -static PyMethodDef pybinary_methods[] = { -#if 0 - {"name", (PyCFunction)pybinary_name, METH_NOARGS, - "Return the name, combining the first and last name" - }, -#endif - { "lines", (PyCFunction)pybinary_get_lines, METH_NOARGS, - "Provide a list of associated rendering lines." - }, - {NULL} /* Sentinel */ -}; - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit la description du type 'binary' pour Python. * -* * -* Retour : Adresse de la description du type 'binary'. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *pybinary_get_type(void) -{ - static PyTypeObject result = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /*ob_size*/ -#endif - - "noddy.pybinary", /* tp_name */ - sizeof(pybinary), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pybinary_dealloc, /* 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*/ - "pybinary objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - pybinary_methods, /* tp_methods */ - pybinary_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pybinary_init, /* tp_init */ - 0, /* tp_alloc */ - pybinary_new, /* tp_new */ - }; - - return &result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'binary' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_binary_to_python_module(PyObject *module) -{ - int ret; /* Bilan d'un appel */ - - if (PyType_Ready(pybinary_get_type()) < 0) - return false; - - printf("Adding binary type\n"); - - - - Py_INCREF(pybinary_get_type()); - PyModule_AddObject(module, "binary", (PyObject *)pybinary_get_type()); - - - return true; /* FIXME */ - - -} diff --git a/plugins/pyoida/analysis/py_binary.h b/plugins/pyoida/analysis/py_binary.h deleted file mode 100644 index f87d2a5..0000000 --- a/plugins/pyoida/analysis/py_binary.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_binary.h - prototypes pour l'intermédiaire des binaires 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 - */ - - -#ifndef _PLUGINS_PYOIDA_PY_BINARY_H -#define _PLUGINS_PYOIDA_PY_BINARY_H - - -#include <Python.h> -#include <stdbool.h> - - -#include "../../../src/analysis/binary.h" - - - -/* Initialise le greffon permettant l'usage de Python. */ -PyObject *pybinary_new_from_existing(GOpenidaBinary *); - -/* Ajoute l'objet 'binary' au module Python. */ -bool add_binary_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_PY_BINARY_H */ diff --git a/plugins/pyoida/analysis/py_line-int.h b/plugins/pyoida/analysis/py_line-int.h deleted file mode 100644 index 408eae8..0000000 --- a/plugins/pyoida/analysis/py_line-int.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line.h - prototypes internes pour les lignes de représentation en 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 - */ - - -#ifndef _PLUGINS_PYOIDA_PY_LINE_INT_H -#define _PLUGINS_PYOIDA_PY_LINE_INT_H - - -#include "py_line.h" - - - -typedef struct { - PyObject_HEAD - - GRenderingLine *head; - - GRenderingLine *line; /* Instance réelle rattachée */ - - vmpa_t address; /* Adresse mise en cache */ - -} PyLine; - - -/* Fournit la description du type 'PyLine' pour Python. */ -PyTypeObject *pyline_get_type(void); - -/* Initialise le greffon permettant l'usage de Python. */ -void pyline_init_from_existing(PyLine *, GRenderingLine *, GRenderingLine *); - - - -#endif /* _PLUGINS_PYOIDA_PY_LINE_INT_H */ diff --git a/plugins/pyoida/analysis/py_line.c b/plugins/pyoida/analysis/py_line.c deleted file mode 100644 index e981dbe..0000000 --- a/plugins/pyoida/analysis/py_line.c +++ /dev/null @@ -1,606 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line.c - intermédiaire des lignes de représentation 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.h" - -#include <structmember.h> - - - -#include "../../../src/analysis/line_code.h" - - -#include "py_line-int.h" -#include "py_line_code.h" - - - - - -#define _(str) str - - - - - - - -/* Prépare un parcours de lignes. */ -static PyObject *pyline_get_iter(PyLine *); - - - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Itérateur pour lignes de rendu */ -typedef struct _PyLineIter -{ - PyObject_HEAD /* A laisser en premier */ - - GRenderingLine *head; /* Liste à parcourir */ - GRenderingLine *cur; /* Point de parcours courant */ - -} PyLineIter; - - -/* Fournit la description de l'itérateur 'PyLine' pour Python. */ -static PyTypeObject *pylineiter_get_type(void); - -/* Prépare l'itérateur pour un parcours de lignes de rendu. */ -static PyObject *pylineiter_new(GRenderingLine *); - -/* Libère la mémoire occupée par un itérateur de 'PyLine'. */ -static void pylineiter_dealloc(PyLineIter *); - -/* Fournit l'élément suivant dans un parcours de lignes. */ -static PyObject *pylineiter_get_next(PyLineIter *); - - - - -/* ---------------------- EQUIVALENT PYTHON DES LIGNES DE CODE ---------------------- */ - - -/* Représentation Python d'une ligne de code */ -typedef struct _PyCodeLine -{ - PyLine base; /* A laisser en premier */ - -} PyCodeLine; - - - - - - - - - - - -static void -pyline_dealloc(PyLine *self) -{ -#if 0 - Py_XDECREF(self->first); - Py_XDECREF(self->last); -#endif - - //printf("dealloc\n"); - - - g_object_set_data(G_OBJECT(self->line), "pyline", NULL); - - -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject*)self); -#else - Py_TYPE(self)->tp_free((PyObject*)self); -#endif - - //printf("dealloc::end\n"); - -} - -static PyObject * -pyline_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyLine *self; - - - printf("creating a new line\n"); - - self = (PyLine *)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 *pyline_new_from_existing(GRenderingLine *head, GRenderingLine *line) -{ - PyLine *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - result = (PyLine *)g_object_get_data(G_OBJECT(line), "pyline"); - - if (result == NULL) - { - if (G_IS_CODE_LINE(line)) - result = pycodeline_new_from_existing(head, line); - - else - { - type = pyline_get_type(); - - result = (PyLine *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->line = line; - - g_object_set_data(G_OBJECT(line), "pyline", result); - - } - - } - - } - - return (PyObject *)result; - -} - - - - -static int -pyline_init(PyLine *self, PyObject *args, PyObject *kwds) -{ -#if 0 - PyObject *first=NULL, *last=NULL, *tmp; - - static char *kwlist[] = {"first", "last", "number", NULL}; - - printf("pyline_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; -} - - - -/****************************************************************************** -* * -* Paramètres : self = instance à initialiser. * -* head = ???? * -* line = modèle à représenter en Python. * -* * -* Description : Initialise le greffon permettant l'usage de Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void pyline_init_from_existing(PyLine *self, GRenderingLine *head, GRenderingLine *line) -{ - self->head = head; - self->line = line; - - self->address = get_rendering_line_address(self->line); - -} - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Prépare un parcours de lignes. * -* * -* Retour : Point de départ d'un parcours. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pyline_get_iter(PyLine *self) -{ - return (PyObject *)pylineiter_new(self->head); - -} - - - - - - -#if 0 -static PyObject * -pyline_name(pyline* self) -{ - static PyObject *format = NULL; - PyObject *args, *result; - - if (format == NULL) { - format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); - if (format == NULL) - return NULL; - } - - args = Py_BuildValue("OO", self->first, self->last); - if (args == NULL) - return NULL; - - result = PyUnicode_Format(format, args); - Py_DECREF(args); - - return result; -} -#endif - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit la description du type 'PyLine' pour Python. * -* * -* Retour : Adresse de la description du type 'line'. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *pyline_get_type(void) -{ - - static PyMethodDef pyline_methods[] = { -#if 0 - {"name", (PyCFunction)pyline_name, METH_NOARGS, - "Return the name, combining the first and last name" - }, -#endif - { NULL } -}; - - - static PyMemberDef pyline_members[] = { - { "address", T_ULONGLONG, offsetof(PyLine, address), READONLY, - "physical or virtual address relative to the line." }, - { NULL } -}; - - - static PyTypeObject result = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /*ob_size*/ -#endif - - "noddy.pyline", /* tp_name */ - sizeof(PyLine), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pyline_dealloc, /* 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*/ - "PyLine objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)pyline_get_iter, /* tp_iter */ - 0, /* tp_iternext */ - pyline_methods, /* tp_methods */ - pyline_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pyline_init, /* tp_init */ - 0, /* tp_alloc */ - pyline_new, /* tp_new */ - }; - - return &result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'line' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_line_to_python_module(PyObject *module) -{ - int ret; /* Bilan d'un appel */ - - if (PyType_Ready(pyline_get_type()) < 0) - return false; - - if (PyType_Ready(pylineiter_get_type()) < 0) - return false; - - - - - printf("Adding line type\n"); - - - - Py_INCREF(pyline_get_type()); - PyModule_AddObject(module, "line", (PyObject *)pyline_get_type()); - - Py_INCREF(pylineiter_get_type()); - PyModule_AddObject(module, "lineiter", (PyObject *)pylineiter_get_type()); - - - return true; /* FIXME */ - - -} - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* ITERATEUR POUR LE PARCOURS DE LIGNES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit la description de l'itérateur 'PyLine' pour Python. * -* * -* Retour : Adresse de la description du type 'PyLineIter'. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *pylineiter_get_type(void) -{ - static PyTypeObject result = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /* ob_size */ -#endif - - "pyoida.analysis.PyLineIter", /* tp_name */ - sizeof(PyLineIter), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pylineiter_dealloc, /* 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 */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "PyLineIter objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ - (iternextfunc)pylineiter_get_next, /* tp_iternext */ - 0, /* tp_methods */ - }; - - return &result; - -} - - -/****************************************************************************** -* * -* Paramètres : head = liste à parcourir. * -* * -* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * -* * -* Retour : Instance d'itérateur prête à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pylineiter_new(GRenderingLine *head) -{ - PyLineIter *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - type = pylineiter_get_type(); - - result = (PyLineIter *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->cur = NULL; - } - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à supprimer. * -* * -* Description : Libère la mémoire occupée par un itérateur de 'PyLine'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void pylineiter_dealloc(PyLineIter *self) -{ -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject *)self); -#else - Py_TYPE(self)->tp_free((PyObject *)self); -#endif - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit l'élément suivant dans un parcours de lignes. * -* * -* Retour : Point suivant du parcours ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pylineiter_get_next(PyLineIter *self) -{ - PyObject *result; /* Elément à retourner */ - GRenderingLine *next; /* Elément réel suivant */ - - if (self->cur == NULL) next = self->head; - else next = g_rendering_line_get_next_iter(self->head, self->cur, NULL); - - if (next != NULL) - { - self->cur = next; - result = pyline_new_from_existing(self->head, next); - } - - else result = NULL; - - return (PyObject *)result; - -} diff --git a/plugins/pyoida/analysis/py_line.h b/plugins/pyoida/analysis/py_line.h deleted file mode 100644 index 681e13b..0000000 --- a/plugins/pyoida/analysis/py_line.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line.h - prototypes pour l'intermédiaire des lignes de représentation 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 - */ - - -#ifndef _PLUGINS_PYOIDA_PY_LINE_H -#define _PLUGINS_PYOIDA_PY_LINE_H - - -#include <Python.h> -#include <stdbool.h> - - -#include "../../../src/analysis/line.h" - - - -/* Initialise le greffon permettant l'usage de Python. */ -PyObject *pyline_new_from_existing(GRenderingLine *, GRenderingLine *); - -/* Ajoute l'objet 'line' au module Python. */ -bool add_line_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_PY_LINE_H */ diff --git a/plugins/pyoida/analysis/py_line_code.c b/plugins/pyoida/analysis/py_line_code.c deleted file mode 100644 index 26fe513..0000000 --- a/plugins/pyoida/analysis/py_line_code.c +++ /dev/null @@ -1,281 +0,0 @@ - -/* 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 */ - -} diff --git a/plugins/pyoida/analysis/py_line_code.h b/plugins/pyoida/analysis/py_line_code.h deleted file mode 100644 index 8a67b44..0000000 --- a/plugins/pyoida/analysis/py_line_code.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* 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 - */ - - -#ifndef _PLUGINS_PYOIDA_PY_LINE_CODE_H -#define _PLUGINS_PYOIDA_PY_LINE_CODE_H - - -#include <Python.h> -#include <stdbool.h> - - -#include "../../../src/analysis/line_code.h" - - - -/* Initialise le greffon permettant l'usage de Python. */ -PyObject *pycodeline_new_from_existing(GRenderingLine *, GCodeLine *); - -/* Ajoute l'objet 'PyCodeLine' au module Python. */ -bool add_pycodeline_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_PY_LINE_CODE_H */ diff --git a/plugins/pyoida/analysis/roptions.c b/plugins/pyoida/analysis/roptions.c deleted file mode 100644 index 57a4f52..0000000 --- a/plugins/pyoida/analysis/roptions.c +++ /dev/null @@ -1,272 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * roptions.c - équivalent Python du fichier "analysis/roptions.h" - * - * Copyright (C) 2010 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 "roptions.h" - - -#include "../format/executable.h" - - - - -/* Classe 'analysis.roptions' pour Python */ -typedef struct _py_rendering_options -{ - PyObject_HEAD - - GRenderingOptions *glib; /* Options réelles manipulées */ - -} py_rendering_options; - - - - -/* Crée un nouvel objet Python de type 'py_rendering_options'. */ -static PyObject *py_rendering_options_new(PyTypeObject *, PyObject *, PyObject *); - - - -/* Indique si les adresses des instructions sont à afficher. */ -static PyObject *py_rendering_options_get_show_address(PyObject *, void *); - -/* Affiche (ou non) les adresses des instructions. */ -static int py_rendering_options_set_show_address(PyObject *, PyObject *, void *); - - - - -/* Affiche (ou non) le code des instructions. */ -static PyObject *py_rendering_options_show_code(PyObject *, PyObject *); - - - - - -/****************************************************************************** -* * -* 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 'py_rendering_options'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_rendering_options_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_rendering_options *result; /* Instance à retourner */ - PyObject *executable; /* Format d'exécutable joint */ - int ret; /* Bilan de lecture des args. */ - GExeFormat *_executable; /* Version GLib du format */ - - ret = PyArg_ParseTuple(args, "O", &executable); - if (!ret) return Py_None; - - result = (py_rendering_options *)type->tp_alloc(type, 0); - - _executable = py_executable_get_glib_instance(executable); - - g_object_ref(G_OBJECT(_executable)); - result->glib = g_rendering_options_new(_executable); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : roptions = instance Python dont la référence est à donner. * -* * -* Description : Fournit l'instance GLib d'une instance Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -GRenderingOptions *py_rendering_options_get_glib_instance(PyObject *roptions) -{ - return ((py_rendering_options *)roptions)->glib; - -} - - - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant des options de représentation. * -* data = adresse non utilisée ici. * -* * -* Description : Indique si les adresses des instructions sont à afficher. * -* * -* Retour : Valeur booléenne indiquant le statut d'une option. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_rendering_options_get_show_address(PyObject *self, void *data) -{ - - printf(" -->> get address\n"); - - return Py_BuildValue("i", true); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant des options de représentation. * -* value = nouvelle valeur affectée. * -* data = adresse non utilisée ici. * -* * -* Description : Affiche (ou non) les adresses des instructions. * -* * -* Retour : Bilan de la mise à jour. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_rendering_options_set_show_address(PyObject *self, PyObject *value, void *data) -{ - printf(" -->> set address\n"); - - return 0; - -} - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * -* args = arguments fournis à l'appel. * -* * -* Description : Affiche (ou non) le code des instructions. * -* * -* Retour : Rien en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_rendering_options_show_code(PyObject *self, PyObject *args) -{ - int state; /* Nouveau statut d'affichage */ - - if (!PyArg_ParseTuple(args, "i", &state)) - return NULL; - - - - - printf("show code :: %d\n", state); - - return Py_None; - -} - - - - - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.roptions' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_roptions_to_python_module(PyObject *module) -{ - int ret; /* Bilan d'un appel */ - - static PyMethodDef py_rendering_options_methods[] = { - { - "show_code", (PyCFunction)py_rendering_options_show_code, - METH_VARARGS, - "Define if the binary code has to be processed or not." - }, - { NULL } - }; - - static PyGetSetDef py_rendering_options_getset[] = { - { - "show_address", - (getter)py_rendering_options_get_show_address, - (setter)py_rendering_options_set_show_address, - "Define or retrieve if the instruction address need to be shown." - }, - { NULL } - }; - - static PyTypeObject py_rendering_options_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.RenderingOptions", - .tp_basicsize = sizeof(py_rendering_options), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA rendering options", - - .tp_methods = py_rendering_options_methods, - .tp_getset = py_rendering_options_getset, - .tp_new = (newfunc)py_rendering_options_new - - }; - - if (PyType_Ready(&py_rendering_options_type) < 0) - return false; - - Py_INCREF(&py_rendering_options_type); - ret = PyModule_AddObject(module, "RenderingOptions", (PyObject *)&py_rendering_options_type); - - return (ret == 0); - -} diff --git a/plugins/pyoida/analysis/roptions.h b/plugins/pyoida/analysis/roptions.h deleted file mode 100644 index 0897211..0000000 --- a/plugins/pyoida/analysis/roptions.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * roptions.h - prototypes pour l'équivalent Python du fichier "analysis/roptions.h" - * - * Copyright (C) 2010 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 - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_ROPTIONS_H -#define _PLUGINS_PYOIDA_ANALYSIS_ROPTIONS_H - - -#include <Python.h> -#include <stdbool.h> - - -#include <analysis/roptions.h> - - - -/* Fournit l'instance GLib d'une instance Python. */ -GRenderingOptions *py_rendering_options_get_glib_instance(PyObject *); - -/* Ajoute l'objet 'analysis.roptions' au module Python. */ -bool add_analysis_roptions_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_ROPTIONS_H */ |