summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-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
-rw-r--r--plugins/python/lnxsyscalls/lnxsyscalls.py517
29 files changed, 4258 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);
}
diff --git a/plugins/python/lnxsyscalls/lnxsyscalls.py b/plugins/python/lnxsyscalls/lnxsyscalls.py
new file mode 100644
index 0000000..92d5763
--- /dev/null
+++ b/plugins/python/lnxsyscalls/lnxsyscalls.py
@@ -0,0 +1,517 @@
+#!/usr/bin/python
+
+from pyoida import Plugin
+from pyoida.analysis import RenderingOptions
+from pyoida.arch import ArchProcessorType
+
+
+class SysCallDB():
+ """xxx"""
+
+ def __init__(self):
+
+ self.__syscalls = [
+ "__NR_restart_syscall",
+ "__NR_exit",
+ "__NR_fork",
+ "__NR_read",
+ "__NR_write",
+ "__NR_open",
+ "__NR_close",
+ "__NR_waitpid",
+ "__NR_creat",
+ "__NR_link",
+ "__NR_unlink",
+ "__NR_execve",
+ "__NR_chdir",
+ "__NR_time",
+ "__NR_mknod",
+ "__NR_chmod",
+ "__NR_lchown",
+ "__NR_break",
+ "__NR_oldstat",
+ "__NR_lseek",
+ "__NR_getpid",
+ "__NR_mount",
+ "__NR_umount",
+ "__NR_setuid",
+ "__NR_getuid",
+ "__NR_stime",
+ "__NR_ptrace",
+ "__NR_alarm",
+ "__NR_oldfstat",
+ "__NR_pause",
+ "__NR_utime",
+ "__NR_stty",
+ "__NR_gtty",
+ "__NR_access",
+ "__NR_nice",
+ "__NR_ftime",
+ "__NR_sync",
+ "__NR_kill",
+ "__NR_rename",
+ "__NR_mkdir",
+ "__NR_rmdir",
+ "__NR_dup",
+ "__NR_pipe",
+ "__NR_times",
+ "__NR_prof",
+ "__NR_brk",
+ "__NR_setgid",
+ "__NR_getgid",
+ "__NR_signal",
+ "__NR_geteuid",
+ "__NR_getegid",
+ "__NR_acct",
+ "__NR_umount2",
+ "__NR_lock",
+ "__NR_ioctl",
+ "__NR_fcntl",
+ "__NR_mpx",
+ "__NR_setpgid",
+ "__NR_ulimit",
+ "__NR_oldolduname",
+ "__NR_umask",
+ "__NR_chroot",
+ "__NR_ustat",
+ "__NR_dup2",
+ "__NR_getppid",
+ "__NR_getpgrp",
+ "__NR_setsid",
+ "__NR_sigaction",
+ "__NR_sgetmask",
+ "__NR_ssetmask",
+ "__NR_setreuid",
+ "__NR_setregid",
+ "__NR_sigsuspend",
+ "__NR_sigpending",
+ "__NR_sethostname",
+ "__NR_setrlimit",
+ "__NR_getrlimit",
+ "__NR_getrusage",
+ "__NR_gettimeofday",
+ "__NR_settimeofday",
+ "__NR_getgroups",
+ "__NR_setgroups",
+ "__NR_select",
+ "__NR_symlink",
+ "__NR_oldlstat",
+ "__NR_readlink",
+ "__NR_uselib",
+ "__NR_swapon",
+ "__NR_reboot",
+ "__NR_readdir",
+ "__NR_mmap",
+ "__NR_munmap",
+ "__NR_truncate",
+ "__NR_ftruncate",
+ "__NR_fchmod",
+ "__NR_fchown",
+ "__NR_getpriority",
+ "__NR_setpriority",
+ "__NR_profil",
+ "__NR_statfs",
+ "__NR_fstatfs",
+ "__NR_ioperm",
+ "__NR_socketcall",
+ "__NR_syslog",
+ "__NR_setitimer",
+ "__NR_getitimer",
+ "__NR_stat",
+ "__NR_lstat",
+ "__NR_fstat",
+ "__NR_olduname",
+ "__NR_iopl",
+ "__NR_vhangup",
+ "__NR_idle",
+ "__NR_vm86old",
+ "__NR_wait4",
+ "__NR_swapoff",
+ "__NR_sysinfo",
+ "__NR_ipc",
+ "__NR_fsync",
+ "__NR_sigreturn",
+ "__NR_clone",
+ "__NR_setdomainname",
+ "__NR_uname",
+ "__NR_modify_ldt",
+ "__NR_adjtimex",
+ "__NR_mprotect",
+ "__NR_sigprocmask",
+ "__NR_create_module",
+ "__NR_init_module",
+ "__NR_delete_module",
+ "__NR_get_kernel_syms",
+ "__NR_quotactl",
+ "__NR_getpgid",
+ "__NR_fchdir",
+ "__NR_bdflush",
+ "__NR_sysfs",
+ "__NR_personality",
+ "__NR_afs_syscall",
+ "__NR_setfsuid",
+ "__NR_setfsgid",
+ "__NR__llseek",
+ "__NR_getdents",
+ "__NR__newselect",
+ "__NR_flock",
+ "__NR_msync",
+ "__NR_readv",
+ "__NR_writev",
+ "__NR_getsid",
+ "__NR_fdatasync",
+ "__NR__sysctl",
+ "__NR_mlock",
+ "__NR_munlock",
+ "__NR_mlockall",
+ "__NR_munlockall",
+ "__NR_sched_setparam",
+ "__NR_sched_getparam",
+ "__NR_sched_setscheduler",
+ "__NR_sched_getscheduler",
+ "__NR_sched_yield",
+ "__NR_sched_get_priority_max",
+ "__NR_sched_get_priority_min",
+ "__NR_sched_rr_get_interval",
+ "__NR_nanosleep",
+ "__NR_mremap",
+ "__NR_setresuid",
+ "__NR_getresuid",
+ "__NR_vm86",
+ "__NR_query_module",
+ "__NR_poll",
+ "__NR_nfsservctl",
+ "__NR_setresgid",
+ "__NR_getresgid",
+ "__NR_prctl",
+ "__NR_rt_sigreturn",
+ "__NR_rt_sigaction",
+ "__NR_rt_sigprocmask",
+ "__NR_rt_sigpending",
+ "__NR_rt_sigtimedwait",
+ "__NR_rt_sigqueueinfo",
+ "__NR_rt_sigsuspend",
+ "__NR_pread64",
+ "__NR_pwrite64",
+ "__NR_chown",
+ "__NR_getcwd",
+ "__NR_capget",
+ "__NR_capset",
+ "__NR_sigaltstack",
+ "__NR_sendfile",
+ "__NR_getpmsg",
+ "__NR_putpmsg",
+ "__NR_vfork",
+ "__NR_ugetrlimit",
+ "__NR_mmap2",
+ "__NR_truncate64",
+ "__NR_ftruncate64",
+ "__NR_stat64",
+ "__NR_lstat64",
+ "__NR_fstat64",
+ "__NR_lchown32",
+ "__NR_getuid32",
+ "__NR_getgid32",
+ "__NR_geteuid32",
+ "__NR_getegid32",
+ "__NR_setreuid32",
+ "__NR_setregid32",
+ "__NR_getgroups32",
+ "__NR_setgroups32",
+ "__NR_fchown32",
+ "__NR_setresuid32",
+ "__NR_getresuid32",
+ "__NR_setresgid32",
+ "__NR_getresgid32",
+ "__NR_chown32",
+ "__NR_setuid32",
+ "__NR_setgid32",
+ "__NR_setfsuid32",
+ "__NR_setfsgid32",
+ "__NR_pivot_root",
+ "__NR_mincore",
+ "__NR_madvise",
+ "__NR_madvise1",
+ "__NR_getdents64",
+ "__NR_fcntl64",
+ "__NR_unused",
+ "__NR_gettid",
+ "__NR_readahead",
+ "__NR_setxattr",
+ "__NR_lsetxattr",
+ "__NR_fsetxattr",
+ "__NR_getxattr",
+ "__NR_lgetxattr",
+ "__NR_fgetxattr",
+ "__NR_listxattr",
+ "__NR_llistxattr",
+ "__NR_flistxattr",
+ "__NR_removexattr",
+ "__NR_lremovexattr",
+ "__NR_fremovexattr",
+ "__NR_tkill",
+ "__NR_sendfile64",
+ "__NR_futex",
+ "__NR_sched_setaffinity",
+ "__NR_sched_getaffinity",
+ "__NR_set_thread_area",
+ "__NR_get_thread_area",
+ "__NR_io_setup",
+ "__NR_io_destroy",
+ "__NR_io_getevents",
+ "__NR_io_submit",
+ "__NR_io_cancel",
+ "__NR_fadvise64",
+ "__NR_unused",
+ "__NR_exit_group",
+ "__NR_lookup_dcookie",
+ "__NR_epoll_create",
+ "__NR_epoll_ctl",
+ "__NR_epoll_wait",
+ "__NR_remap_file_pages",
+ "__NR_set_tid_address",
+ "__NR_timer_create",
+ "__NR_timer_settime",
+ "__NR_timer_gettime",
+ "__NR_timer_getoverrun",
+ "__NR_timer_delete",
+ "__NR_clock_settime",
+ "__NR_clock_gettime",
+ "__NR_clock_getres",
+ "__NR_clock_nanosleep",
+ "__NR_statfs64",
+ "__NR_fstatfs64",
+ "__NR_tgkill",
+ "__NR_utimes",
+ "__NR_fadvise64_64",
+ "__NR_vserver",
+ "__NR_mbind",
+ "__NR_get_mempolicy",
+ "__NR_set_mempolicy",
+ "__NR_mq_open",
+ "__NR_mq_unlink",
+ "__NR_mq_timedsend",
+ "__NR_mq_timedreceive",
+ "__NR_mq_notify",
+ "__NR_mq_getsetattr",
+ "__NR_kexec_load",
+ "__NR_waitid",
+ "__NR_sys_setaltroot",
+ "__NR_add_key",
+ "__NR_request_key",
+ "__NR_keyctl",
+ "__NR_ioprio_set",
+ "__NR_ioprio_get",
+ "__NR_inotify_init",
+ "__NR_inotify_add_watch",
+ "__NR_inotify_rm_watch",
+ "__NR_migrate_pages",
+ "__NR_openat",
+ "__NR_mkdirat",
+ "__NR_mknodat",
+ "__NR_fchownat",
+ "__NR_futimesat",
+ "__NR_fstatat64",
+ "__NR_unlinkat",
+ "__NR_renameat",
+ "__NR_linkat",
+ "__NR_symlinkat",
+ "__NR_readlinkat",
+ "__NR_fchmodat",
+ "__NR_faccessat",
+ "__NR_pselect6",
+ "__NR_ppoll",
+ "__NR_unshare",
+ "__NR_set_robust_list",
+ "__NR_get_robust_list",
+ "__NR_splice",
+ "__NR_sync_file_range",
+ "__NR_tee",
+ "__NR_vmsplice",
+ "__NR_move_pages",
+ "__NR_getcpu",
+ "__NR_epoll_pwait",
+ "__NR_utimensat",
+ "__NR_signalfd",
+ "__NR_timerfd_create",
+ "__NR_eventfd",
+ "__NR_fallocate",
+ "__NR_timerfd_settime",
+ "__NR_timerfd_gettime",
+ "__NR_signalfd4",
+ "__NR_eventfd2",
+ "__NR_epoll_create1",
+ "__NR_dup3",
+ "__NR_pipe2",
+ "__NR_inotify_init1",
+ "__NR_preadv",
+ "__NR_pwritev",
+ "__NR_rt_tgsigqueueinfo",
+ "__NR_perf_event_open"
+ ]
+
+ self.__args = {
+ "sys_restart_syscall" : [],
+ "sys_exit" : ["int error_code"],
+ "sys_write" : ["unsigned int fd", "const char __user *buf", "size_t count"]
+ }
+
+ def get_syscall_name(self, index):
+ """Convert a syscall index into a human name."""
+
+ return self.__syscalls[index]
+
+
+ def get_syscall_args(self, name):
+ """Provide the function name, the needed registers and the used arguments of a syscall."""
+
+ name = name.replace("__NR_", "sys_")
+
+ try:
+ args = self.__args[name]
+ except:
+ return None
+
+ targets = {}
+
+ if len(args) >= 4:
+
+ pass
+
+ else:
+
+ registers = ["ebx", "ecx", "edx", "esi", "edi"]
+
+ i = 0
+
+ for val in args:
+ targets[registers[i]] = val
+ i = i + 1
+
+ return [name, targets]
+
+
+
+
+class LinuxSysCallsPlugin(Plugin):
+ """A simple example class"""
+
+
+
+ def __rendering_options(self, binary):
+ """Build the options needed to get the ASM code only."""
+
+ exe = binary.get_format()
+
+ ropts = RenderingOptions(exe)
+
+ ropts.show_code(True)
+ ropts.show_address = False
+
+ return ropts
+
+ def __is_syscall(self, code):
+ """Tell weither the ASM line of code is a syscall or not."""
+
+ result = False
+
+ if code.find("int") != -1:
+
+ list = code.split("\t")
+
+ if len(list) == 2:
+ result = list == ["int", "0x80"]
+
+ return result
+
+ def __find_used_register(self, ropts, start, target):
+ """Look for a given register used to supply argument for a syscall."""
+
+ for found in reversed(start):
+
+ code = found.get_text(ropts)
+ parts = code.expandtabs(1).replace(",", "").split(" ")
+
+ # Next registers are used by a new interruption
+ if parts[0] == "int":
+ continue
+
+ # No operand
+ if len(parts) == 1:
+ continue
+
+ # Only simple cases are processed...
+ if parts[1] == target:
+ if len(parts) == 2:
+ return None
+ else:
+ return [found, parts[2]]
+
+ return None
+
+ def run(self, binary):
+ """Resolve all registers / interruptions involved in a syscall."""
+
+ db = SysCallDB()
+
+ ropts = self.__rendering_options(binary)
+
+ lines = binary.get_lines()
+
+ for line in lines:
+ code = line.get_text(ropts)
+ if self.__is_syscall(code):
+
+ # What kind of syscall ?
+
+ line_eax = self.__find_used_register(ropts, line, "eax")
+
+ if line_eax is None:
+ line.comment = "== UNIX Syscall =="
+ continue
+
+ index = int(line_eax[1], 16)
+ name = db.get_syscall_name(index)
+
+ line_eax[0].comment = name
+
+ # What function / arguments ?
+
+ targets = db.get_syscall_args(name)
+
+ if targets == None:
+
+ line.comment = "== UNIX Syscall =="
+ continue
+
+ else:
+
+ line.comment = "== UNIX Syscall to %s() ==" % (targets[0])
+
+ for reg, arg in targets[1].items():
+
+ found = self.__find_used_register(ropts, line, reg)
+
+ if found != None:
+ found[0].comment = arg
+
+
+
+
+
+
+def get_instance(binary):
+
+ print " --- toto from Python ---"
+
+
+
+ a = LinuxSysCallsPlugin()
+
+ a.run(binary)
+
+ return Plugin.PGA_CODE_PROCESS
+
+
+
+