summaryrefslogtreecommitdiff
path: root/plugins/pyoida
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pyoida')
-rw-r--r--plugins/pyoida/Makefile.am7
-rw-r--r--plugins/pyoida/analysis/Makefile.am11
-rw-r--r--plugins/pyoida/analysis/binary.c279
-rw-r--r--plugins/pyoida/analysis/binary.h44
-rw-r--r--plugins/pyoida/analysis/exporter-int.h53
-rw-r--r--plugins/pyoida/analysis/exporter.c284
-rw-r--r--plugins/pyoida/analysis/exporter.h44
-rw-r--r--plugins/pyoida/analysis/line.c793
-rw-r--r--plugins/pyoida/analysis/line.h61
-rw-r--r--plugins/pyoida/analysis/module.c76
-rw-r--r--plugins/pyoida/analysis/module.h39
-rw-r--r--plugins/pyoida/analysis/roptions.c272
-rw-r--r--plugins/pyoida/analysis/roptions.h45
-rw-r--r--plugins/pyoida/arch/Makefile.am17
-rw-r--r--plugins/pyoida/arch/archbase.c121
-rw-r--r--plugins/pyoida/arch/archbase.h44
-rw-r--r--plugins/pyoida/arch/module.c72
-rw-r--r--plugins/pyoida/arch/module.h39
-rw-r--r--plugins/pyoida/arch/processor.c314
-rw-r--r--plugins/pyoida/arch/processor.h39
-rw-r--r--plugins/pyoida/format/Makefile.am16
-rw-r--r--plugins/pyoida/format/executable.c223
-rw-r--r--plugins/pyoida/format/executable.h47
-rw-r--r--plugins/pyoida/format/module.c68
-rw-r--r--plugins/pyoida/format/module.h39
-rw-r--r--plugins/pyoida/plugin.c555
-rw-r--r--plugins/pyoida/plugin.h88
-rw-r--r--plugins/pyoida/pyoida.c69
28 files changed, 3741 insertions, 18 deletions
diff --git a/plugins/pyoida/Makefile.am b/plugins/pyoida/Makefile.am
index 1dd0d1f..923d8c9 100644
--- a/plugins/pyoida/Makefile.am
+++ b/plugins/pyoida/Makefile.am
@@ -2,11 +2,14 @@
pkglib_LTLIBRARIES = pyoida.la
pyoida_la_SOURCES = \
+ plugin.h plugin.c \
py_log.h py_log.c \
pyoida.h pyoida.c
pyoida_la_LIBADD = \
- analysis/libpyoidaanalysis.la
+ analysis/libpyoidaanalysis.la \
+ arch/libpyoidaarch.la \
+ format/libpyoidaformat.la
pyoida_la_LDFLAGS = -module -avoid-version $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \
-L../../src/panels/ -lpanels -L../../src/.libs -loidadisass -loidagtkext \
@@ -19,4 +22,4 @@ AM_CPPFLAGS =
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = analysis
+SUBDIRS = analysis arch format
diff --git a/plugins/pyoida/analysis/Makefile.am b/plugins/pyoida/analysis/Makefile.am
index df49499..e67f188 100644
--- a/plugins/pyoida/analysis/Makefile.am
+++ b/plugins/pyoida/analysis/Makefile.am
@@ -2,15 +2,18 @@
noinst_LTLIBRARIES = libpyoidaanalysis.la
libpyoidaanalysis_la_SOURCES = \
- py_binary.h py_binary.c \
- py_line.h py_line.c \
- py_line_code.h py_line_code.c
+ 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)
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) -I../../../src
AM_CPPFLAGS =
diff --git a/plugins/pyoida/analysis/binary.c b/plugins/pyoida/analysis/binary.c
new file mode 100644
index 0000000..d378496
--- /dev/null
+++ b/plugins/pyoida/analysis/binary.c
@@ -0,0 +1,279 @@
+
+/* 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
new file mode 100644
index 0000000..1500a06
--- /dev/null
+++ b/plugins/pyoida/analysis/binary.h
@@ -0,0 +1,44 @@
+
+/* 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
new file mode 100644
index 0000000..2498d4b
--- /dev/null
+++ b/plugins/pyoida/analysis/exporter-int.h
@@ -0,0 +1,53 @@
+
+/* 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
new file mode 100644
index 0000000..8c49542
--- /dev/null
+++ b/plugins/pyoida/analysis/exporter.c
@@ -0,0 +1,284 @@
+
+/* 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
new file mode 100644
index 0000000..4668934
--- /dev/null
+++ b/plugins/pyoida/analysis/exporter.h
@@ -0,0 +1,44 @@
+
+/* 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
new file mode 100644
index 0000000..fd697e2
--- /dev/null
+++ b/plugins/pyoida/analysis/line.c
@@ -0,0 +1,793 @@
+
+/* 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
new file mode 100644
index 0000000..e71596c
--- /dev/null
+++ b/plugins/pyoida/analysis/line.h
@@ -0,0 +1,61 @@
+
+/* 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
new file mode 100644
index 0000000..8f07002
--- /dev/null
+++ b/plugins/pyoida/analysis/module.c
@@ -0,0 +1,76 @@
+
+/* 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
new file mode 100644
index 0000000..a8bd329
--- /dev/null
+++ b/plugins/pyoida/analysis/module.h
@@ -0,0 +1,39 @@
+
+/* 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/roptions.c b/plugins/pyoida/analysis/roptions.c
new file mode 100644
index 0000000..57a4f52
--- /dev/null
+++ b/plugins/pyoida/analysis/roptions.c
@@ -0,0 +1,272 @@
+
+/* 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
new file mode 100644
index 0000000..0897211
--- /dev/null
+++ b/plugins/pyoida/analysis/roptions.h
@@ -0,0 +1,45 @@
+
+/* 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 */
diff --git a/plugins/pyoida/arch/Makefile.am b/plugins/pyoida/arch/Makefile.am
new file mode 100644
index 0000000..d0113ec
--- /dev/null
+++ b/plugins/pyoida/arch/Makefile.am
@@ -0,0 +1,17 @@
+
+noinst_LTLIBRARIES = libpyoidaarch.la
+
+libpyoidaarch_la_SOURCES = \
+ archbase.h archbase.c \
+ module.h module.c \
+ processor.h processor.c
+
+
+libpyoidaarch_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/arch/archbase.c b/plugins/pyoida/arch/archbase.c
new file mode 100644
index 0000000..b73e769
--- /dev/null
+++ b/plugins/pyoida/arch/archbase.c
@@ -0,0 +1,121 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * archbase.c - équivalent Python du fichier "arch/archbase.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 "archbase.h"
+
+
+
+
+
+/* Classe 'arch.vmpa' pour Python */
+typedef PyLongObject py_vmpa;
+
+
+
+/* Fournit le type d'objet 'arch.vmpa' pour Python. */
+static PyTypeObject *get_arch_vmpa_type(void);
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : value = adresse à convertir en objet Python. *
+* *
+* Description : Crée un nouvel objet Python de type 'py_vmpa'. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *py_vmpa_new_from_existing(vmpa_t value)
+{
+ return PyLong_FromLongLong(value);
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit le type d'objet 'arch.vmpa' pour Python. *
+* *
+* Retour : Adresse du type vivant à manipuler. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyTypeObject *get_arch_vmpa_type(void)
+{
+ return &PyLong_Type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'arch.vmpa' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_arch_vmpa_to_python_module(PyObject *module)
+{
+ PyTypeObject *py_vmpa_type; /* Type défini pour Python */
+ int ret; /* Bilan d'un appel */
+
+ py_vmpa_type = get_arch_vmpa_type();
+
+ if (PyType_Ready(py_vmpa_type) < 0)
+ return false;
+
+ Py_INCREF(py_vmpa_type);
+ ret = PyModule_AddObject(module, "Vmpa", (PyObject *)py_vmpa_type);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pyoida/arch/archbase.h b/plugins/pyoida/arch/archbase.h
new file mode 100644
index 0000000..ca621aa
--- /dev/null
+++ b/plugins/pyoida/arch/archbase.h
@@ -0,0 +1,44 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * archbase.h - prototypes pour l'équivalent Python du fichier "arch/archbase.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_ARCH_ARCHBASE_H
+#define _PLUGINS_PYOIDA_ARCH_ARCHBASE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+#include <arch/archbase.h>
+
+
+
+/* Crée un nouvel objet Python de type 'py_vmpa'. */
+PyObject *py_vmpa_new_from_existing(vmpa_t);
+
+/* Ajoute l'objet 'arch.vmpa' au module Python. */
+bool add_arch_vmpa_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ARCH_ARCHBASE_H */
diff --git a/plugins/pyoida/arch/module.c b/plugins/pyoida/arch/module.c
new file mode 100644
index 0000000..59b0c2c
--- /dev/null
+++ b/plugins/pyoida/arch/module.c
@@ -0,0 +1,72 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire arch 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 "archbase.h"
+#include "processor.h"
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute le module 'arch' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_arch_module_to_python_module(PyObject *super)
+{
+ bool result;
+ PyObject *module;
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_arch_methods[] = {
+ { NULL }
+ };
+
+ module = Py_InitModule("pyoida.arch", py_arch_methods);
+ if (module == NULL) return false;
+
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "pyoida.arch", module);
+
+ if (ret != 0) /* ... */;
+
+ result = add_arch_vmpa_to_python_module(module);
+ result = add_arch_processor_to_python_module(module);
+
+
+ return true;
+
+}
diff --git a/plugins/pyoida/arch/module.h b/plugins/pyoida/arch/module.h
new file mode 100644
index 0000000..4ae3447
--- /dev/null
+++ b/plugins/pyoida/arch/module.h
@@ -0,0 +1,39 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire arch 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_ARCH_MODULE_H
+#define _PLUGINS_PYOIDA_ARCH_MODULE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute le module 'arch' au module Python. */
+bool add_arch_module_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ARCH_MODULE_H */
diff --git a/plugins/pyoida/arch/processor.c b/plugins/pyoida/arch/processor.c
new file mode 100644
index 0000000..0a3fe95
--- /dev/null
+++ b/plugins/pyoida/arch/processor.c
@@ -0,0 +1,314 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * processor.h - prototypes pour l'équivalent Python du fichier "arch/processor.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 "processor.h"
+
+
+#include "../../../src/arch/processor.h"
+
+
+
+/* ------------------------- TYPAGE DES ENUMERATIONS PYTHON ------------------------- */
+
+
+/* Définit les constantes pour les types de processeur. */
+bool py_arch_processor_type_define_constants(PyObject *);
+
+/* Ajoute l'objet 'arch.processor.ArchProcessorType' au module. */
+bool add_arch_processor_type_to_python_module(PyObject *);
+
+
+
+/* ------------------------- PARTIE STATIQUE DE PROCESSEURS ------------------------- */
+
+
+
+
+
+
+
+/* Classe 'analysis.roptions' pour Python */
+typedef struct _py_processor
+{
+ PyObject_HEAD
+
+} py_processor;
+
+
+
+
+
+
+
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* TYPAGE DES ENUMERATIONS PYTHON */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : dict = dictionnaire à compléter. *
+* *
+* Description : Définit les constantes pour les types de processeur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool py_arch_processor_type_define_constants(PyObject *dict)
+{
+ int ret; /* Bilan d'un ajout */
+
+ ret = PyDict_SetItemString(dict, "APT_JVM", PyInt_FromLong(APT_JVM));
+ if (ret == -1) return false;
+
+ ret = PyDict_SetItemString(dict, "APT_MIPS", PyInt_FromLong(APT_MIPS));
+ if (ret == -1) return false;
+
+ ret = PyDict_SetItemString(dict, "APT_386", PyInt_FromLong(APT_386));
+ if (ret == -1) return false;
+
+ ret = PyDict_SetItemString(dict, "APT_COUNT", PyInt_FromLong(APT_COUNT));
+ if (ret == -1) return false;
+
+ return true;
+
+}
+PyObject *__test;
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'arch.processor.ArchProcessorType' au module. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_arch_processor_type_to_python_module(PyObject *module)
+{
+ int ret; /* Bilan d'un appel */
+
+ static PyTypeObject py_arch_processor_type_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+ .tp_name = "pyoida.arch.processor.ArchProcessorType",
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyOIDA version of the ArchProcessorType enumeration",
+
+ };
+
+ if (PyType_Ready(&py_arch_processor_type_type) < 0)
+ return false;
+
+ py_arch_processor_type_define_constants(py_arch_processor_type_type.tp_dict);
+
+ Py_INCREF(&py_arch_processor_type_type);
+ ret = PyModule_AddObject(module, "ArchProcessorType", (PyObject *)&py_arch_processor_type_type);
+
+ __test = &py_arch_processor_type_type;
+
+ return (ret == 0);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PARTIE STATIQUE DE PROCESSEURS */
+/* ---------------------------------------------------------------------------------- */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PARTIE GRAPHIQUE DES [DE]CHARGEMENTS */
+/* ---------------------------------------------------------------------------------- */
+
+
+
+
+
+
+
+
+
+/* Crée un nouvel objet Python de type 'py_processor'. */
+static PyObject *py_processor_new(PyTypeObject *, 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_processor'. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_processor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ py_processor *result; /* Instance à retourner */
+
+ result = (py_processor *)type->tp_alloc(type, 0);
+
+ return (PyObject *)result;
+
+}
+
+
+
+
+
+
+
+
+
+
+static PyObject *util_FromImport(const char *name, const char *from_item)
+{
+ PyObject *from_list;
+ PyObject *module;
+ PyObject *item;
+
+ /* Make the from list. */
+ from_list = PyList_New(1);
+ PyList_SetItem(from_list, 0, PyString_FromString(from_item));
+
+ /* Attempt the import, with const correctness removed. */
+ module = PyImport_ImportModuleEx((char *)name, NULL, NULL, from_list);
+ Py_DECREF(from_list);
+ if (!module)
+ {
+ return NULL;
+ }
+
+ /* Get the from_item from the module. */
+ item = PyObject_GetAttrString(module, (char *)from_item);
+ Py_DECREF(module);
+
+ return item;
+}
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'analysis.roptions' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_arch_processor_to_python_module(PyObject *module)
+{
+ bool result; /* Bilan à retourner */
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_processor_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_processor_getset[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_processor_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+ .tp_name = "pyoida.arch.Processor",
+ .tp_basicsize = sizeof(py_processor),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyOIDA processor for a given architecture",
+
+ .tp_methods = py_processor_methods,
+ .tp_getset = py_processor_getset,
+ .tp_new = (newfunc)py_processor_new
+
+ };
+
+ if (PyType_Ready(&py_processor_type) < 0)
+ return false;
+
+ //printf("ret import = %p\n", PyImport_ImportModule("pyoida.arch.processor.ArchProcessorType"));
+
+
+
+ Py_INCREF(&py_processor_type);
+ ret = PyModule_AddObject(module, "Processor", (PyObject *)&py_processor_type);
+
+ result = add_arch_processor_type_to_python_module(module);
+
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pyoida/arch/processor.h b/plugins/pyoida/arch/processor.h
new file mode 100644
index 0000000..032d82d
--- /dev/null
+++ b/plugins/pyoida/arch/processor.h
@@ -0,0 +1,39 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * processor.h - prototypes pour l'équivalent Python du fichier "arch/processor.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_ARCH_PROCESSOR_H
+#define _PLUGINS_PYOIDA_ARCH_PROCESSOR_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute l'objet 'arch.processor' au module Python. */
+bool add_arch_processor_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ARCH_PROCESSOR_H */
diff --git a/plugins/pyoida/format/Makefile.am b/plugins/pyoida/format/Makefile.am
new file mode 100644
index 0000000..74d3e3a
--- /dev/null
+++ b/plugins/pyoida/format/Makefile.am
@@ -0,0 +1,16 @@
+
+noinst_LTLIBRARIES = libpyoidaformat.la
+
+libpyoidaformat_la_SOURCES = \
+ executable.h executable.c \
+ module.h module.c
+
+
+libpyoidaformat_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/format/executable.c b/plugins/pyoida/format/executable.c
new file mode 100644
index 0000000..2f10f71
--- /dev/null
+++ b/plugins/pyoida/format/executable.c
@@ -0,0 +1,223 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * executable.c - équivalent Python du fichier "format/executable.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 "executable.h"
+
+
+
+
+
+
+
+/* Classe 'format.executable' pour Python */
+typedef struct _py_executable
+{
+ PyObject_HEAD
+
+ GExeFormat *glib; /* Format d'exécutable GLib */
+
+} py_executable;
+
+
+
+
+/* Crée un nouvel objet Python de type 'py_executable'. */
+static PyObject *py_executable_new(PyTypeObject *, PyObject *, PyObject *);
+
+
+
+
+
+/* Fournit le type d'objet 'format.executable' pour Python. */
+static PyTypeObject *get_format_executable_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_executable'. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_executable_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ py_executable *result; /* Instance à retourner */
+
+ result = (py_executable *)type->tp_alloc(type, 0);
+
+ return (PyObject *)result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : executable = objet GLib existant à transposer. *
+* *
+* Description : Convertit une instance GLib en objet Python 'py_executable'. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *py_executable_convert(GExeFormat *executable)
+{
+ py_executable *result; /* Instance à retourner */
+ PyTypeObject *type; /* Type Python à instancier */
+
+ result = (py_executable *)g_object_get_data(G_OBJECT(executable), "python_object");
+
+ if (result == NULL)
+ {
+ type = get_format_executable_type();
+
+ result = (py_executable *)type->tp_alloc(type, 0);
+
+ result->glib = executable;
+ g_object_ref(executable);
+
+ g_object_set_data(G_OBJECT(executable), "python_object", result);
+
+ }
+ else Py_INCREF((PyObject *)result);
+
+ return (PyObject *)result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : executable = instance Python dont la référence est à donner. *
+* *
+* Description : Fournit l'instance GLib d'une instance Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GExeFormat *py_executable_get_glib_instance(PyObject *executable)
+{
+ return ((py_executable *)executable)->glib;
+
+}
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit le type d'objet 'format.executable' pour Python. *
+* *
+* Retour : Adresse du type vivant à manipuler. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyTypeObject *get_format_executable_type(void)
+{
+ static PyTypeObject *result = NULL; /* Type pour objet à retourner */
+
+ static PyMethodDef py_executable_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_executable_getset[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_executable_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+ .tp_name = "pyoida.format.Executable",
+ .tp_basicsize = sizeof(py_executable),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyOIDA loaded executable to analyse",
+
+ .tp_methods = py_executable_methods,
+ .tp_getset = py_executable_getset,
+ .tp_new = (newfunc)py_executable_new
+
+ };
+
+ if (result == NULL) result = &py_executable_type;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'format.executable' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_format_executable_to_python_module(PyObject *module)
+{
+ PyTypeObject *py_executable_type; /* Type défini pour Python */
+ int ret; /* Bilan d'un appel */
+
+ py_executable_type = get_format_executable_type();
+
+ if (PyType_Ready(py_executable_type) < 0)
+ return false;
+
+ Py_INCREF(py_executable_type);
+ ret = PyModule_AddObject(module, "Executable", (PyObject *)py_executable_type);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pyoida/format/executable.h b/plugins/pyoida/format/executable.h
new file mode 100644
index 0000000..577d1f9
--- /dev/null
+++ b/plugins/pyoida/format/executable.h
@@ -0,0 +1,47 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * executable.h - prototypes pour l'équivalent Python du fichier "format/executable.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_FORMAT_EXECUTABLE_H
+#define _PLUGINS_PYOIDA_FORMAT_EXECUTABLE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+#include <format/executable.h>
+
+
+
+/* Convertit une instance GLib en objet Python 'py_executable'. */
+PyObject *py_executable_convert(GExeFormat *);
+
+/* Fournit l'instance GLib d'une instance Python. */
+GExeFormat *py_executable_get_glib_instance(PyObject *);
+
+/* Ajoute l'objet 'format.executable' au module Python. */
+bool add_format_executable_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_FORMAT_EXECUTABLE_H */
diff --git a/plugins/pyoida/format/module.c b/plugins/pyoida/format/module.c
new file mode 100644
index 0000000..1f15d50
--- /dev/null
+++ b/plugins/pyoida/format/module.c
@@ -0,0 +1,68 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire format 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 "executable.h"
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute le module 'format' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_format_module_to_python_module(PyObject *super)
+{
+ bool result;
+ PyObject *module;
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_format_methods[] = {
+ { NULL }
+ };
+
+ module = Py_InitModule("pyoida.format", py_format_methods);
+ if (module == NULL) return false;
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "pyoida.format", module);
+
+ result = (ret != 0);
+
+ result &= add_format_executable_to_python_module(module);
+
+ return result;
+
+}
diff --git a/plugins/pyoida/format/module.h b/plugins/pyoida/format/module.h
new file mode 100644
index 0000000..4aa95cf
--- /dev/null
+++ b/plugins/pyoida/format/module.h
@@ -0,0 +1,39 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire format 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_FORMAT_MODULE_H
+#define _PLUGINS_PYOIDA_FORMAT_MODULE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute le module 'format' au module Python. */
+bool add_format_module_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_FORMAT_MODULE_H */
diff --git a/plugins/pyoida/plugin.c b/plugins/pyoida/plugin.c
new file mode 100644
index 0000000..23934a9
--- /dev/null
+++ b/plugins/pyoida/plugin.c
@@ -0,0 +1,555 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * plugin.c - interactions avec un greffon Python
+ *
+ * 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 "plugin.h"
+
+
+#include "../../src/analysis/binary.h"
+#include "../../src/plugins/plugin-int.h"
+
+
+#include "analysis/binary.h"
+
+
+
+
+
+
+
+/* --------------------- INTERFACE INTERNE POUR GREFFONS PYTHON --------------------- */
+
+
+/* Ligne de représentation de code binaire (instance) */
+struct _GPythonPlugin
+{
+ GPluginModule parent; /* Instance parente */
+
+ PyObject *module; /* Script Python chargé */
+
+};
+
+
+/* Ligne de représentation de code binaire (classe) */
+struct _GPythonPluginClass
+{
+ GPluginModuleClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des greffons Python. */
+static void g_python_plugin_class_init(GPythonPluginClass *);
+
+/* Initialise l'instance d'un greffon Python. */
+static void g_python_plugin_init(GPythonPlugin *);
+
+/* Exécute une action définie sur un binaire chargé. */
+static bool g_python_plugin_execute(GPythonPlugin *, GOpenidaBinary *, PluginAction);
+
+
+/* ------------------------- MODULE PYTHON POUR LES SCRIPTS ------------------------- */
+
+
+/* Classe plugin pour Python */
+typedef struct _pyoida_plugin
+{
+ PyObject_HEAD
+
+} pyoida_plugin;
+
+
+
+
+
+
+/* Crée un nouveau greffon Python abstrait. */
+static PyObject *pyoida_plugin_new(PyTypeObject *, PyObject *, PyObject *);
+
+/* Exécute une action valide pour le greffon Python. */
+static PyObject *pyoida_plugin_run(PyObject *, PyObject *);
+
+
+
+/* Définit les constantes pour les greffons en Python. */
+static bool pyoida_plugin_define_constants(PyObject *);
+
+
+
+
+
+
+
+
+
+
+
+
+
+int
+main2(const char *filename, const char *method)
+{
+ PyObject *pName, *pModule, *pDict, *pFunc;
+ PyObject *pArgs, *pValue;
+ int i;
+ return 0;
+ pName = PyString_FromString/*PyUnicode_FromString*/(filename);
+ /* Error checking of pName left out */
+
+ pModule = PyImport_Import(pName);
+ Py_DECREF(pName);
+
+ if (pModule != NULL) {
+ pFunc = PyObject_GetAttrString(pModule, method);
+ /* pFunc is a new reference */
+
+ if (pFunc && PyCallable_Check(pFunc)) {
+ pArgs = PyTuple_New(0/*argc - 3*/);
+#if 0
+ for (i = 0; i < argc - 3; ++i) {
+ pValue = PyLong_FromLong(atoi(argv[i + 3]));
+ if (!pValue) {
+ Py_DECREF(pArgs);
+ Py_DECREF(pModule);
+ fprintf(stderr, "Cannot convert argument\n");
+ return 1;
+ }
+ /* pValue reference stolen here: */
+ PyTuple_SetItem(pArgs, i, pValue);
+ }
+#endif
+ pValue = PyObject_CallObject(pFunc, pArgs);
+ Py_DECREF(pArgs);
+ if (pValue != NULL) {
+ printf("Result of call: %ld\n", PyLong_AsLong(pValue));
+ Py_DECREF(pValue);
+ }
+ else {
+ Py_DECREF(pFunc);
+ Py_DECREF(pModule);
+ PyErr_Print();
+ fprintf(stderr,"Call failed\n");
+ return 1;
+ }
+ }
+ else {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ fprintf(stderr, "Cannot find function \"%s\"\n", method);
+ }
+ Py_XDECREF(pFunc);
+ Py_DECREF(pModule);
+ }
+ else {
+ PyErr_Print();
+ fprintf(stderr, "Failed to load \"%s\"\n", filename);
+ return 1;
+ }
+ return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTERFACE INTERNE POUR GREFFONS PYTHON */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type définit par la GLib pour le greffon Python. */
+G_DEFINE_TYPE(GPythonPlugin, g_python_plugin, G_TYPE_PLUGIN_MODULE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des greffons Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_python_plugin_class_init(GPythonPluginClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = instance à initialiser. *
+* *
+* Description : Initialise l'instance d'un greffon Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_python_plugin_init(GPythonPlugin *plugin)
+{
+ GPluginModule *plugin_parent; /* Instance parente */
+
+ plugin_parent = G_PLUGIN_MODULE(plugin);
+
+ plugin_parent->exec_on_bin = (execute_action_on_binary_fc)g_python_plugin_execute;
+
+}
+
+
+
+
+PyObject *run_python_method(PyObject *module, const char *method, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ PyObject *func; /* Fonction visée */
+
+ result = NULL;
+
+ func = PyObject_GetAttrString(module, method);
+ if (func == NULL) return NULL;
+
+ if (PyCallable_Check(func))
+ {
+ result = PyObject_CallObject(func, args);
+ if (result == NULL) PyErr_Print();
+ }
+ else if (PyErr_Occurred()) PyErr_Print();
+
+ Py_DECREF(func);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : filename = chemin d'accès au code Python à charger. *
+* *
+* Description : Crée un greffon à partir de code Python. *
+* *
+* Retour : Adresse de la structure mise en place ou NULL si erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GPluginModule *g_python_plugin_new(const char *filename)
+{
+ GPythonPlugin *result; /* Structure à retourner */
+ PyObject *name; /* Chemin d'accès pour Python */
+ PyObject *module; /* Script Python chargé */
+
+#if PY_VERSION_HEX >= 0x03000000
+ name = PyUnicode_FromString(filename);
+#else
+ name = PyString_FromString(filename);
+#endif
+ name = PyString_FromString/*PyUnicode_FromString*/(filename);
+ if (name == NULL) goto gppn_bad_exit;
+
+ module = PyImport_Import(name);
+ Py_DECREF(name);
+
+ if (module == NULL)
+ {
+ PyErr_Print();
+ goto gppn_bad_exit;
+ }
+
+
+
+ //Py_DECREF(module);
+
+
+
+ result = g_object_new(G_TYPE_PYTHON_PLUGIN, NULL);
+
+ G_PLUGIN_MODULE(result)->action = PGA_CODE_PROCESS;
+
+ result->module = module;
+
+ return G_PLUGIN_MODULE(result);
+
+ gppn_bad_exit:
+
+ return NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon de prise en charge à utiliser. *
+* binary = représentation binaire à traiter. *
+* action = action attendue. *
+* *
+* Description : Exécute une action définie sur un binaire chargé. *
+* *
+* Retour : true si une action a été menée, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_python_plugin_execute(GPythonPlugin *plugin, GOpenidaBinary *binary, PluginAction action)
+{
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *arg; /* Un des arguments de l'appel */
+ PyObject *value; /* Valeur obtenue */
+
+
+
+ printf("I am running !!");
+
+ args = PyTuple_New(1);
+
+
+ arg = Py_BuildValue("O&", py_binary_new_from_existing, binary);
+ PyTuple_SetItem(args, 0, arg);
+
+
+ value = run_python_method(plugin->module, "get_instance", args);
+
+ if (value != NULL)
+ {
+ printf("Result of call: %ld\n", PyLong_AsLong(value));
+ Py_DECREF(value);
+ }
+
+
+ Py_DECREF(args);
+
+
+
+
+
+
+}
+
+
+
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MODULE PYTHON POUR LES SCRIPTS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de l'objet à instancier. *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Crée un nouveau greffon Python abstrait. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *pyoida_plugin_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ pyoida_plugin *result; /* Instance à retourner */
+
+ result = (pyoida_plugin *)type->tp_alloc(type, 0);
+
+ return (PyObject *)result;
+
+}
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : dict = dictionnaire à compléter. *
+* *
+* Description : Définit les constantes pour les greffons en Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool pyoida_plugin_define_constants(PyObject *dict)
+{
+ int ret; /* Bilan d'un ajout */
+
+ ret = PyDict_SetItemString(dict, "PGA_DISASSEMBLE", PyInt_FromLong(PGA_DISASSEMBLE));
+ if (ret == -1) return false;
+
+ ret = PyDict_SetItemString(dict, "PGA_CODE_PROCESS", PyInt_FromLong(PGA_CODE_PROCESS));
+ if (ret == -1) return false;
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe assurant le lien avec l'éditeur de messages. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Exécute une action valide pour le greffon Python. *
+* *
+* Retour : Rien en équivalent Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *pyoida_plugin_run(PyObject *self, PyObject *args)
+{
+ return Py_None;
+
+}
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'plugin' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_plugin_to_python_module(PyObject *module)
+{
+ int ret; /* Bilan d'un appel */
+
+
+static PyMethodDef pyoida_plugin_methods[] = {
+ { "run", (PyCFunction)pyoida_plugin_run, METH_VARARGS,
+ "Run the plugin for a specific action."
+ },
+ NULL
+};
+
+
+static PyTypeObject pyoida_plugin_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+#if PY_VERSION_HEX < 0x03000000
+ 0, /*ob_size*/
+#endif
+
+ "plugin.Plugin", /* tp_name */
+ sizeof(pyoida_plugin), /* 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*/
+ "PyOIDA Plugin objects", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pyoida_plugin_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 */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)pyoida_plugin_new, /* tp_new */
+};
+
+
+
+
+ printf("Adding pyoida pg type...\n");
+
+ if (PyType_Ready(&pyoida_plugin_type) < 0)
+ return false;
+
+ printf("Adding pyoida pg type\n");
+
+
+ if (!pyoida_plugin_define_constants(pyoida_plugin_type.tp_dict))
+ return false;
+
+
+
+
+ Py_INCREF(&pyoida_plugin_type);
+ PyModule_AddObject(module, "Plugin", (PyObject *)&pyoida_plugin_type);
+
+
+ return true; /* FIXME */
+
+
+}
diff --git a/plugins/pyoida/plugin.h b/plugins/pyoida/plugin.h
new file mode 100644
index 0000000..f5d4ab4
--- /dev/null
+++ b/plugins/pyoida/plugin.h
@@ -0,0 +1,88 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * plugin.h - prototypes pour les interactions avec un greffon Python
+ *
+ * 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_PLUGIN_H
+#define _PLUGINS_PYOIDA_PLUGIN_H
+
+
+#include <Python.h>
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "../../src/plugins/plugin.h"
+
+
+
+/* --------------------- INTERFACE INTERNE POUR GREFFONS PYTHON --------------------- */
+
+
+
+
+
+#define G_TYPE_PYTHON_PLUGIN (g_python_plugin_get_type())
+#define G_PYTHON_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PYTHON_PLUGIN, GPythonPlugin))
+#define G_IS_PYTHON_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PYTHON_PLUGIN))
+#define G_PYTHON_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PYTHON_PLUGIN, GPythonPluginClass))
+#define G_IS_PYTHON_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PYTHON_PLUGIN))
+#define G_PYTHON_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PYTHON_PLUGIN, GPythonPluginClass))
+
+
+/* Ligne de représentation de code binaire (instance) */
+typedef struct _GPythonPlugin GPythonPlugin;
+
+/* Ligne de représentation de code binaire (classe) */
+typedef struct _GPythonPluginClass GPythonPluginClass;
+
+
+/* Indique le type définit par la GLib pour le greffon Python. */
+GType g_python_plugin_get_type(void);
+
+/* Crée un greffon à partir de code Python. */
+GPluginModule *g_python_plugin_new(const char *);
+
+
+
+
+
+
+
+
+int
+main2(const char *filename, const char *method);
+
+
+
+
+
+
+/* ------------------------- MODULE PYTHON POUR LES SCRIPTS ------------------------- */
+
+
+/* Ajoute l'objet 'plugin' au module Python. */
+bool add_plugin_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_PLUGIN_H */
diff --git a/plugins/pyoida/pyoida.c b/plugins/pyoida/pyoida.c
index 860da5b..82f9980 100644
--- a/plugins/pyoida/pyoida.c
+++ b/plugins/pyoida/pyoida.c
@@ -24,14 +24,26 @@
#include "pyoida.h"
-
#include <Python.h>
+#include "analysis/module.h"
+#include "arch/module.h"
+#include "format/module.h"
+
+/*
#include "analysis/py_binary.h"
#include "analysis/py_line.h"
#include "analysis/py_line_code.h"
+#include "analysis/roptions.h"
+*/
+#include "plugin.h"
#include "py_log.h"
+#include "../../src/common/environment.h"
+
+
+#include "plugin.h"
+
static GObject *_ref = NULL;
@@ -59,13 +71,6 @@ static PyMethodDef SpamMethods[] = {
-
-
-
-
-
-
-
/******************************************************************************
* *
* Paramètres : ref = espace de référencement global. *
@@ -80,11 +85,44 @@ static PyMethodDef SpamMethods[] = {
bool init_plugin(GObject *ref)
{
+ GPluginModule *plugin;
+ int ret;
printf("Init pyoida\n");
_ref = ref;
+ add_to_env_var("PYTHONPATH", "/home/ocb/prog/openida/plugins/python", ";");
+
+
+ Py_Initialize();
+
+ initpyoida();
+
+
+
+
+ plugin = g_python_plugin_new("lnxsyscalls/lnxsyscalls");
+ add_plugin_to_main_list(plugin);
+
+
+
+#if 0
+
+#if 0
+ //main2("/home/ocb/prog/openida/plugins/pyoida/lnxsyscalls/lnxsyscalls.py", "get_instance");
+ main2("lnxsyscalls", "get_instance");
+#else
+ //main2("/home/ocb/prog/openida/plugins/pyoida/lnxsyscalls/lnxsyscalls.py", "get_instance");
+ main2("lnxsyscalls/lnxsyscalls", "get_instance");
+#endif
+
+#endif
+
+ //Py_Finalize();
+
+ //exit(-1);
+
return true;
}
@@ -114,20 +152,27 @@ PyInit_pyoida(void)
/* Python 2.x code */
+typedef struct {
+ PyObject_HEAD
+ PyObject *md_dict;
+} PyModuleObject;
+
PyMODINIT_FUNC
initpyoida(void)
{
PyObject *module;
-
printf("Passage 2\n");
module = Py_InitModule("pyoida", SpamMethods);
- add_binary_to_python_module(module);
- add_line_to_python_module(module);
- add_pycodeline_to_python_module(module);
+ //add_analysis_roptions_to_python_module(module);
+ add_analysis_module_to_python_module(module);
+ add_arch_module_to_python_module(module);
+ add_format_module_to_python_module(module);
+
add_log_to_python_module(module);
+ add_plugin_to_python_module(module);
}