From bbad297e902022ecac9fab21c01dc109560db8eb Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 17 Mar 2012 20:29:47 +0000 Subject: Created the 'pychrysa' Python plugin from the 'pyoida' one. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@240 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 71 +++ configure.ac | 10 +- plugins/Makefile.am | 2 +- plugins/pychrysa/Makefile.am | 28 + plugins/pychrysa/analysis/Makefile.am | 20 + plugins/pychrysa/analysis/binary.c | 279 ++++++++++ plugins/pychrysa/analysis/binary.h | 44 ++ plugins/pychrysa/analysis/exporter-int.h | 53 ++ plugins/pychrysa/analysis/exporter.c | 284 ++++++++++ plugins/pychrysa/analysis/exporter.h | 44 ++ plugins/pychrysa/analysis/line.c | 793 ++++++++++++++++++++++++++++ plugins/pychrysa/analysis/line.h | 61 +++ plugins/pychrysa/analysis/module.c | 76 +++ plugins/pychrysa/analysis/module.h | 39 ++ plugins/pychrysa/analysis/py_binary.c | 363 +++++++++++++ plugins/pychrysa/analysis/py_binary.h | 45 ++ plugins/pychrysa/analysis/py_line-int.h | 53 ++ plugins/pychrysa/analysis/py_line.c | 606 ++++++++++++++++++++++ plugins/pychrysa/analysis/py_line.h | 45 ++ plugins/pychrysa/analysis/py_line_code.c | 281 ++++++++++ plugins/pychrysa/analysis/py_line_code.h | 45 ++ plugins/pychrysa/analysis/roptions.c | 272 ++++++++++ plugins/pychrysa/analysis/roptions.h | 45 ++ plugins/pychrysa/arch/Makefile.am | 17 + plugins/pychrysa/arch/archbase.c | 121 +++++ plugins/pychrysa/arch/archbase.h | 44 ++ plugins/pychrysa/arch/module.c | 72 +++ plugins/pychrysa/arch/module.h | 39 ++ plugins/pychrysa/arch/processor.c | 314 +++++++++++ plugins/pychrysa/arch/processor.h | 39 ++ plugins/pychrysa/debug/Makefile.am | 17 + plugins/pychrysa/debug/debugger.c | 275 ++++++++++ plugins/pychrysa/debug/debugger.h | 45 ++ plugins/pychrysa/debug/module.c | 66 +++ plugins/pychrysa/debug/module.h | 39 ++ plugins/pychrysa/format/Makefile.am | 16 + plugins/pychrysa/format/executable.c | 223 ++++++++ plugins/pychrysa/format/executable.h | 47 ++ plugins/pychrysa/format/module.c | 68 +++ plugins/pychrysa/format/module.h | 39 ++ plugins/pychrysa/linsyscalls/oidapgi.py | 28 + plugins/pychrysa/plugin.c | 861 ++++++++++++++++++++++++++++++ plugins/pychrysa/plugin.h | 88 ++++ plugins/pychrysa/py_log.c | 344 ++++++++++++ plugins/pychrysa/py_log.h | 39 ++ plugins/pychrysa/pychrysa.c | 249 +++++++++ plugins/pychrysa/pychrysa.h | 58 +++ plugins/pychrysa/quirks.c | 148 ++++++ plugins/pychrysa/quirks.h | 42 ++ plugins/pyoida/Makefile.am | 28 - plugins/pyoida/analysis/Makefile.am | 20 - plugins/pyoida/analysis/binary.c | 279 ---------- plugins/pyoida/analysis/binary.h | 44 -- plugins/pyoida/analysis/exporter-int.h | 53 -- plugins/pyoida/analysis/exporter.c | 284 ---------- plugins/pyoida/analysis/exporter.h | 44 -- plugins/pyoida/analysis/line.c | 793 ---------------------------- plugins/pyoida/analysis/line.h | 61 --- plugins/pyoida/analysis/module.c | 76 --- plugins/pyoida/analysis/module.h | 39 -- plugins/pyoida/analysis/py_binary.c | 363 ------------- plugins/pyoida/analysis/py_binary.h | 45 -- plugins/pyoida/analysis/py_line-int.h | 53 -- plugins/pyoida/analysis/py_line.c | 606 ---------------------- plugins/pyoida/analysis/py_line.h | 45 -- plugins/pyoida/analysis/py_line_code.c | 281 ---------- plugins/pyoida/analysis/py_line_code.h | 45 -- plugins/pyoida/analysis/roptions.c | 272 ---------- plugins/pyoida/analysis/roptions.h | 45 -- plugins/pyoida/arch/Makefile.am | 17 - plugins/pyoida/arch/archbase.c | 121 ----- plugins/pyoida/arch/archbase.h | 44 -- plugins/pyoida/arch/module.c | 72 --- plugins/pyoida/arch/module.h | 39 -- plugins/pyoida/arch/processor.c | 314 ----------- plugins/pyoida/arch/processor.h | 39 -- plugins/pyoida/debug/Makefile.am | 17 - plugins/pyoida/debug/debugger.c | 275 ---------- plugins/pyoida/debug/debugger.h | 45 -- plugins/pyoida/debug/module.c | 66 --- plugins/pyoida/debug/module.h | 39 -- plugins/pyoida/format/Makefile.am | 16 - plugins/pyoida/format/executable.c | 223 -------- plugins/pyoida/format/executable.h | 47 -- plugins/pyoida/format/module.c | 68 --- plugins/pyoida/format/module.h | 39 -- plugins/pyoida/linsyscalls/oidapgi.py | 28 - plugins/pyoida/plugin.c | 865 ------------------------------- plugins/pyoida/plugin.h | 88 ---- plugins/pyoida/py_log.c | 344 ------------ plugins/pyoida/py_log.h | 39 -- plugins/pyoida/pyoida.c | 275 ---------- plugins/pyoida/pyoida.h | 38 -- plugins/pyoida/quirks.c | 148 ------ plugins/pyoida/quirks.h | 42 -- plugins/python/apkfiles/apkfiles.py | 2 +- 96 files changed, 6892 insertions(+), 6831 deletions(-) create mode 100644 plugins/pychrysa/Makefile.am create mode 100644 plugins/pychrysa/analysis/Makefile.am create mode 100644 plugins/pychrysa/analysis/binary.c create mode 100644 plugins/pychrysa/analysis/binary.h create mode 100644 plugins/pychrysa/analysis/exporter-int.h create mode 100644 plugins/pychrysa/analysis/exporter.c create mode 100644 plugins/pychrysa/analysis/exporter.h create mode 100644 plugins/pychrysa/analysis/line.c create mode 100644 plugins/pychrysa/analysis/line.h create mode 100644 plugins/pychrysa/analysis/module.c create mode 100644 plugins/pychrysa/analysis/module.h create mode 100644 plugins/pychrysa/analysis/py_binary.c create mode 100644 plugins/pychrysa/analysis/py_binary.h create mode 100644 plugins/pychrysa/analysis/py_line-int.h create mode 100644 plugins/pychrysa/analysis/py_line.c create mode 100644 plugins/pychrysa/analysis/py_line.h create mode 100644 plugins/pychrysa/analysis/py_line_code.c create mode 100644 plugins/pychrysa/analysis/py_line_code.h create mode 100644 plugins/pychrysa/analysis/roptions.c create mode 100644 plugins/pychrysa/analysis/roptions.h create mode 100644 plugins/pychrysa/arch/Makefile.am create mode 100644 plugins/pychrysa/arch/archbase.c create mode 100644 plugins/pychrysa/arch/archbase.h create mode 100644 plugins/pychrysa/arch/module.c create mode 100644 plugins/pychrysa/arch/module.h create mode 100644 plugins/pychrysa/arch/processor.c create mode 100644 plugins/pychrysa/arch/processor.h create mode 100644 plugins/pychrysa/debug/Makefile.am create mode 100644 plugins/pychrysa/debug/debugger.c create mode 100644 plugins/pychrysa/debug/debugger.h create mode 100644 plugins/pychrysa/debug/module.c create mode 100644 plugins/pychrysa/debug/module.h create mode 100644 plugins/pychrysa/format/Makefile.am create mode 100644 plugins/pychrysa/format/executable.c create mode 100644 plugins/pychrysa/format/executable.h create mode 100644 plugins/pychrysa/format/module.c create mode 100644 plugins/pychrysa/format/module.h create mode 100755 plugins/pychrysa/linsyscalls/oidapgi.py create mode 100644 plugins/pychrysa/plugin.c create mode 100644 plugins/pychrysa/plugin.h create mode 100644 plugins/pychrysa/py_log.c create mode 100644 plugins/pychrysa/py_log.h create mode 100644 plugins/pychrysa/pychrysa.c create mode 100644 plugins/pychrysa/pychrysa.h create mode 100644 plugins/pychrysa/quirks.c create mode 100644 plugins/pychrysa/quirks.h delete mode 100644 plugins/pyoida/Makefile.am delete mode 100644 plugins/pyoida/analysis/Makefile.am delete mode 100644 plugins/pyoida/analysis/binary.c delete mode 100644 plugins/pyoida/analysis/binary.h delete mode 100644 plugins/pyoida/analysis/exporter-int.h delete mode 100644 plugins/pyoida/analysis/exporter.c delete mode 100644 plugins/pyoida/analysis/exporter.h delete mode 100644 plugins/pyoida/analysis/line.c delete mode 100644 plugins/pyoida/analysis/line.h delete mode 100644 plugins/pyoida/analysis/module.c delete mode 100644 plugins/pyoida/analysis/module.h delete mode 100644 plugins/pyoida/analysis/py_binary.c delete mode 100644 plugins/pyoida/analysis/py_binary.h delete mode 100644 plugins/pyoida/analysis/py_line-int.h delete mode 100644 plugins/pyoida/analysis/py_line.c delete mode 100644 plugins/pyoida/analysis/py_line.h delete mode 100644 plugins/pyoida/analysis/py_line_code.c delete mode 100644 plugins/pyoida/analysis/py_line_code.h delete mode 100644 plugins/pyoida/analysis/roptions.c delete mode 100644 plugins/pyoida/analysis/roptions.h delete mode 100644 plugins/pyoida/arch/Makefile.am delete mode 100644 plugins/pyoida/arch/archbase.c delete mode 100644 plugins/pyoida/arch/archbase.h delete mode 100644 plugins/pyoida/arch/module.c delete mode 100644 plugins/pyoida/arch/module.h delete mode 100644 plugins/pyoida/arch/processor.c delete mode 100644 plugins/pyoida/arch/processor.h delete mode 100644 plugins/pyoida/debug/Makefile.am delete mode 100644 plugins/pyoida/debug/debugger.c delete mode 100644 plugins/pyoida/debug/debugger.h delete mode 100644 plugins/pyoida/debug/module.c delete mode 100644 plugins/pyoida/debug/module.h delete mode 100644 plugins/pyoida/format/Makefile.am delete mode 100644 plugins/pyoida/format/executable.c delete mode 100644 plugins/pyoida/format/executable.h delete mode 100644 plugins/pyoida/format/module.c delete mode 100644 plugins/pyoida/format/module.h delete mode 100755 plugins/pyoida/linsyscalls/oidapgi.py delete mode 100644 plugins/pyoida/plugin.c delete mode 100644 plugins/pyoida/plugin.h delete mode 100644 plugins/pyoida/py_log.c delete mode 100644 plugins/pyoida/py_log.h delete mode 100644 plugins/pyoida/pyoida.c delete mode 100644 plugins/pyoida/pyoida.h delete mode 100644 plugins/pyoida/quirks.c delete mode 100644 plugins/pyoida/quirks.h diff --git a/ChangeLog b/ChangeLog index 3f9669a..f6a478b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,74 @@ +12-03-17 Cyrille Bagard + + * configure.ac: + * plugins/Makefile.am: + * plugins/pychrysa/analysis/Makefile.am: + * plugins/pychrysa/arch/Makefile.am: + * plugins/pychrysa/debug/Makefile.am: + * plugins/pychrysa/format/Makefile.am: + * plugins/pychrysa/Makefile.am: + Update the new used directories. + + * plugins/pychrysa/plugin.c: + * plugins/pychrysa/pychrysa.c: + * plugins/pychrysa/pychrysa.h: + Remove some gcc warnings. + + * plugins/pychrysa/pyoida.c: + * plugins/pychrysa/pyoida.h: + Renamed entries: see pychrysa.[ch]. + + * plugins/pyoida/analysis/binary.c: + * plugins/pyoida/analysis/binary.h: + * plugins/pyoida/analysis/exporter.c: + * plugins/pyoida/analysis/exporter.h: + * plugins/pyoida/analysis/exporter-int.h: + * plugins/pyoida/analysis/line.c: + * plugins/pyoida/analysis/line.h: + * plugins/pyoida/analysis/Makefile.am: + * plugins/pyoida/analysis/module.c: + * plugins/pyoida/analysis/module.h: + * plugins/pyoida/analysis/py_binary.c: + * plugins/pyoida/analysis/py_binary.h: + * plugins/pyoida/analysis/py_line.c: + * plugins/pyoida/analysis/py_line_code.c: + * plugins/pyoida/analysis/py_line_code.h: + * plugins/pyoida/analysis/py_line.h: + * plugins/pyoida/analysis/py_line-int.h: + * plugins/pyoida/analysis/roptions.c: + * plugins/pyoida/analysis/roptions.h: + * plugins/pyoida/arch/archbase.c: + * plugins/pyoida/arch/archbase.h: + * plugins/pyoida/arch/Makefile.am: + * plugins/pyoida/arch/module.c: + * plugins/pyoida/arch/module.h: + * plugins/pyoida/arch/processor.c: + * plugins/pyoida/arch/processor.h: + * plugins/pyoida/debug/debugger.c: + * plugins/pyoida/debug/debugger.h: + * plugins/pyoida/debug/Makefile.am: + * plugins/pyoida/debug/module.c: + * plugins/pyoida/debug/module.h: + * plugins/pyoida/format/executable.c: + * plugins/pyoida/format/executable.h: + * plugins/pyoida/format/Makefile.am: + * plugins/pyoida/format/module.c: + * plugins/pyoida/format/module.h: + * plugins/pyoida/linsyscalls/oidapgi.py: + * plugins/pyoida/Makefile.am: + * plugins/pyoida/plugin.c: + * plugins/pyoida/plugin.h: + * plugins/pyoida/py_log.c: + * plugins/pyoida/py_log.h: + * plugins/pyoida/pyoida.c: + * plugins/pyoida/pyoida.h: + * plugins/pyoida/quirks.c: + * plugins/pyoida/quirks.h: + Moved entries: welcome to the pychrysa directory ! + + * plugins/python/apkfiles/apkfiles.py: + Update the importation. + 12-03-11 Cyrille Bagard * po/fr.po: diff --git a/configure.ac b/configure.ac index b59f323..d894657 100644 --- a/configure.ac +++ b/configure.ac @@ -236,11 +236,11 @@ AC_CONFIG_FILES([Makefile plugins/Makefile plugins/dexresolver/Makefile plugins/govm/Makefile - plugins/pyoida/Makefile - plugins/pyoida/analysis/Makefile - plugins/pyoida/arch/Makefile - plugins/pyoida/debug/Makefile - plugins/pyoida/format/Makefile + plugins/pychrysa/Makefile + plugins/pychrysa/analysis/Makefile + plugins/pychrysa/arch/Makefile + plugins/pychrysa/debug/Makefile + plugins/pychrysa/format/Makefile plugins/python/Makefile plugins/python/apkfiles/Makefile plugins/python/exectracer/Makefile diff --git a/plugins/Makefile.am b/plugins/Makefile.am index b107964..be5740c 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = dexresolver pyoida python stackvars theseus +SUBDIRS = dexresolver pychrysa python stackvars theseus diff --git a/plugins/pychrysa/Makefile.am b/plugins/pychrysa/Makefile.am new file mode 100644 index 0000000..a339dab --- /dev/null +++ b/plugins/pychrysa/Makefile.am @@ -0,0 +1,28 @@ + +pkglib_LTLIBRARIES = pychrysa.la + +pychrysa_la_SOURCES = \ + plugin.h plugin.c \ + py_log.h py_log.c \ + pychrysa.h pychrysa.c \ + quirks.h quirks.c + +pychrysa_la_LIBADD = \ + analysis/libpychrysaanalysis.la \ + arch/libpychrysaarch.la \ + debug/libpychrysadebug.la \ + format/libpychrysaformat.la + +pychrysa_la_LDFLAGS = -module -avoid-version $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \ + $(LIBPYGOBJECT_LIBS) \ + -L../../src/panels/ -lpanels -L../../src/.libs -loidadisass -loidagtkext \ + -L../../src/plugins/.libs -lplugins + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = analysis arch debug format diff --git a/plugins/pychrysa/analysis/Makefile.am b/plugins/pychrysa/analysis/Makefile.am new file mode 100644 index 0000000..b18d16d --- /dev/null +++ b/plugins/pychrysa/analysis/Makefile.am @@ -0,0 +1,20 @@ + +noinst_LTLIBRARIES = libpychrysaanalysis.la + +libpychrysaanalysis_la_SOURCES = \ + binary.h binary.c \ + exporter-int.h \ + exporter.h exporter.c \ + line.h line.c \ + module.h module.c \ + roptions.h roptions.c + + +libpychrysaanalysis_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/pychrysa/analysis/binary.c b/plugins/pychrysa/analysis/binary.c new file mode 100644 index 0000000..d378496 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/analysis/binary.h b/plugins/pychrysa/analysis/binary.h new file mode 100644 index 0000000..1500a06 --- /dev/null +++ b/plugins/pychrysa/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 +#include + +#include + + + +/* 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/pychrysa/analysis/exporter-int.h b/plugins/pychrysa/analysis/exporter-int.h new file mode 100644 index 0000000..2498d4b --- /dev/null +++ b/plugins/pychrysa/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 + +#include + + + +/* 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/pychrysa/analysis/exporter.c b/plugins/pychrysa/analysis/exporter.c new file mode 100644 index 0000000..8c49542 --- /dev/null +++ b/plugins/pychrysa/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 +#include +#include + + +#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/pychrysa/analysis/exporter.h b/plugins/pychrysa/analysis/exporter.h new file mode 100644 index 0000000..4668934 --- /dev/null +++ b/plugins/pychrysa/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 +#include + +#include + + + +/* 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/pychrysa/analysis/line.c b/plugins/pychrysa/analysis/line.c new file mode 100644 index 0000000..fd697e2 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/analysis/line.h b/plugins/pychrysa/analysis/line.h new file mode 100644 index 0000000..e71596c --- /dev/null +++ b/plugins/pychrysa/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 +#include + +#include + + + +/* 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/pychrysa/analysis/module.c b/plugins/pychrysa/analysis/module.c new file mode 100644 index 0000000..8f07002 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/analysis/module.h b/plugins/pychrysa/analysis/module.h new file mode 100644 index 0000000..a8bd329 --- /dev/null +++ b/plugins/pychrysa/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 +#include + + + +/* 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/pychrysa/analysis/py_binary.c b/plugins/pychrysa/analysis/py_binary.c new file mode 100644 index 0000000..04d4881 --- /dev/null +++ b/plugins/pychrysa/analysis/py_binary.c @@ -0,0 +1,363 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_binary.c - intermédiaire des binaires pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_binary.h" + +#include + + + +#include "py_line.h" + + + +typedef struct { + PyObject_HEAD + + GOpenidaBinary *binary; /* Instance réelle rattachée */ + +} pybinary; + + +#define _(str) str + + + + + +/* Fournit la description du type 'binary' pour Python. */ +PyTypeObject *pybinary_get_type(void); + + + + +/* Fournit les lignes de rendu associé pour Python. */ +static PyObject *pybinary_get_lines(pybinary *); + + + + + + + +static void +pybinary_dealloc(pybinary* self) +{ +#if 0 + Py_XDECREF(self->first); + Py_XDECREF(self->last); +#endif + + //printf("dealloc\n"); + +#if PY_VERSION_HEX < 0x03000000 + self->ob_type->tp_free((PyObject*)self); +#else + Py_TYPE(self)->tp_free((PyObject*)self); +#endif + + //printf("dealloc::end\n"); + +} + +static PyObject * +pybinary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + pybinary *self; + + + printf("creating a new binary\n"); + + self = (pybinary *)type->tp_alloc(type, 0); + if (self != NULL) { +#if 0 + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; +#endif + } + + return (PyObject *)self; +} + + +/****************************************************************************** +* * +* Paramètres : binary = modèle à représenter en Python. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pybinary_new_from_existing(GOpenidaBinary *binary) +{ + pybinary *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + printf("EXISTING :: %p\n", binary); + + type = pybinary_get_type(); + + result = (pybinary *)type->tp_alloc(type, 0); + + if (result != NULL) + result->binary = binary; + + return (PyObject *)result; + +} + + + + +static int +pybinary_init(pybinary *self, PyObject *args, PyObject *kwds) +{ +#if 0 + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pybinary_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } +#endif + return 0; +} + + + + + + + +static PyMemberDef pybinary_members[] = { +#if 0 + {"number", T_INT, offsetof(pybinary, number), 0, + "noddy number"}, +#endif + {NULL} /* Sentinel */ +}; + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = instance manipulée à traiter. * +* * +* Description : Fournit les lignes de rendu associé pour Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pybinary_get_lines(pybinary *self) +{ + PyObject *result; /* Liste à retourner */ + GRenderingLine *lines; /* Liste récupérée à convertir */ + + lines = g_openida_binary_get_lines(self->binary); + + result = pyline_new_from_existing(lines, lines); + + return result; + +} + + + + +#if 0 +static PyObject * +pybinary_name(pybinary* self) +{ + static PyObject *format = NULL; + PyObject *args, *result; + + if (format == NULL) { + format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); + if (format == NULL) + return NULL; + } + + args = Py_BuildValue("OO", self->first, self->last); + if (args == NULL) + return NULL; + + result = PyUnicode_Format(format, args); + Py_DECREF(args); + + return result; +} +#endif + +static PyMethodDef pybinary_methods[] = { +#if 0 + {"name", (PyCFunction)pybinary_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, +#endif + { "lines", (PyCFunction)pybinary_get_lines, METH_NOARGS, + "Provide a list of associated rendering lines." + }, + {NULL} /* Sentinel */ +}; + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'binary' pour Python. * +* * +* Retour : Adresse de la description du type 'binary'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *pybinary_get_type(void) +{ + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "noddy.pybinary", /* tp_name */ + sizeof(pybinary), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pybinary_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "pybinary objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + pybinary_methods, /* tp_methods */ + pybinary_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pybinary_init, /* tp_init */ + 0, /* tp_alloc */ + pybinary_new, /* tp_new */ + }; + + return &result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'binary' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_binary_to_python_module(PyObject *module) +{ + int ret; /* Bilan d'un appel */ + + if (PyType_Ready(pybinary_get_type()) < 0) + return false; + + printf("Adding binary type\n"); + + + + Py_INCREF(pybinary_get_type()); + PyModule_AddObject(module, "binary", (PyObject *)pybinary_get_type()); + + + return true; /* FIXME */ + + +} diff --git a/plugins/pychrysa/analysis/py_binary.h b/plugins/pychrysa/analysis/py_binary.h new file mode 100644 index 0000000..f87d2a5 --- /dev/null +++ b/plugins/pychrysa/analysis/py_binary.h @@ -0,0 +1,45 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_binary.h - prototypes pour l'intermédiaire des binaires pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_BINARY_H +#define _PLUGINS_PYOIDA_PY_BINARY_H + + +#include +#include + + +#include "../../../src/analysis/binary.h" + + + +/* Initialise le greffon permettant l'usage de Python. */ +PyObject *pybinary_new_from_existing(GOpenidaBinary *); + +/* Ajoute l'objet 'binary' au module Python. */ +bool add_binary_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_BINARY_H */ diff --git a/plugins/pychrysa/analysis/py_line-int.h b/plugins/pychrysa/analysis/py_line-int.h new file mode 100644 index 0000000..408eae8 --- /dev/null +++ b/plugins/pychrysa/analysis/py_line-int.h @@ -0,0 +1,53 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line.h - prototypes internes pour les lignes de représentation en Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_LINE_INT_H +#define _PLUGINS_PYOIDA_PY_LINE_INT_H + + +#include "py_line.h" + + + +typedef struct { + PyObject_HEAD + + GRenderingLine *head; + + GRenderingLine *line; /* Instance réelle rattachée */ + + vmpa_t address; /* Adresse mise en cache */ + +} PyLine; + + +/* Fournit la description du type 'PyLine' pour Python. */ +PyTypeObject *pyline_get_type(void); + +/* Initialise le greffon permettant l'usage de Python. */ +void pyline_init_from_existing(PyLine *, GRenderingLine *, GRenderingLine *); + + + +#endif /* _PLUGINS_PYOIDA_PY_LINE_INT_H */ diff --git a/plugins/pychrysa/analysis/py_line.c b/plugins/pychrysa/analysis/py_line.c new file mode 100644 index 0000000..e981dbe --- /dev/null +++ b/plugins/pychrysa/analysis/py_line.c @@ -0,0 +1,606 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line.c - intermédiaire des lignes de représentation pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_line.h" + +#include + + + +#include "../../../src/analysis/line_code.h" + + +#include "py_line-int.h" +#include "py_line_code.h" + + + + + +#define _(str) str + + + + + + + +/* Prépare un parcours de lignes. */ +static PyObject *pyline_get_iter(PyLine *); + + + + + +/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ + + +/* Itérateur pour lignes de rendu */ +typedef struct _PyLineIter +{ + PyObject_HEAD /* A laisser en premier */ + + GRenderingLine *head; /* Liste à parcourir */ + GRenderingLine *cur; /* Point de parcours courant */ + +} PyLineIter; + + +/* Fournit la description de l'itérateur 'PyLine' pour Python. */ +static PyTypeObject *pylineiter_get_type(void); + +/* Prépare l'itérateur pour un parcours de lignes de rendu. */ +static PyObject *pylineiter_new(GRenderingLine *); + +/* Libère la mémoire occupée par un itérateur de 'PyLine'. */ +static void pylineiter_dealloc(PyLineIter *); + +/* Fournit l'élément suivant dans un parcours de lignes. */ +static PyObject *pylineiter_get_next(PyLineIter *); + + + + +/* ---------------------- EQUIVALENT PYTHON DES LIGNES DE CODE ---------------------- */ + + +/* Représentation Python d'une ligne de code */ +typedef struct _PyCodeLine +{ + PyLine base; /* A laisser en premier */ + +} PyCodeLine; + + + + + + + + + + + +static void +pyline_dealloc(PyLine *self) +{ +#if 0 + Py_XDECREF(self->first); + Py_XDECREF(self->last); +#endif + + //printf("dealloc\n"); + + + g_object_set_data(G_OBJECT(self->line), "pyline", NULL); + + +#if PY_VERSION_HEX < 0x03000000 + self->ob_type->tp_free((PyObject*)self); +#else + Py_TYPE(self)->tp_free((PyObject*)self); +#endif + + //printf("dealloc::end\n"); + +} + +static PyObject * +pyline_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyLine *self; + + + printf("creating a new line\n"); + + self = (PyLine *)type->tp_alloc(type, 0); + if (self != NULL) { +#if 0 + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; +#endif + } + + return (PyObject *)self; +} + + +/****************************************************************************** +* * +* Paramètres : head = ???? * +* line = modèle à représenter en Python. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pyline_new_from_existing(GRenderingLine *head, GRenderingLine *line) +{ + PyLine *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + result = (PyLine *)g_object_get_data(G_OBJECT(line), "pyline"); + + if (result == NULL) + { + if (G_IS_CODE_LINE(line)) + result = pycodeline_new_from_existing(head, line); + + else + { + type = pyline_get_type(); + + result = (PyLine *)type->tp_alloc(type, 0); + + if (result != NULL) + { + result->head = head; + result->line = line; + + g_object_set_data(G_OBJECT(line), "pyline", result); + + } + + } + + } + + return (PyObject *)result; + +} + + + + +static int +pyline_init(PyLine *self, PyObject *args, PyObject *kwds) +{ +#if 0 + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pyline_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } +#endif + return 0; +} + + + +/****************************************************************************** +* * +* Paramètres : self = instance à initialiser. * +* head = ???? * +* line = modèle à représenter en Python. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void pyline_init_from_existing(PyLine *self, GRenderingLine *head, GRenderingLine *line) +{ + self->head = head; + self->line = line; + + self->address = get_rendering_line_address(self->line); + +} + + + + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = instance manipulée à traiter. * +* * +* Description : Prépare un parcours de lignes. * +* * +* Retour : Point de départ d'un parcours. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pyline_get_iter(PyLine *self) +{ + return (PyObject *)pylineiter_new(self->head); + +} + + + + + + +#if 0 +static PyObject * +pyline_name(pyline* self) +{ + static PyObject *format = NULL; + PyObject *args, *result; + + if (format == NULL) { + format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); + if (format == NULL) + return NULL; + } + + args = Py_BuildValue("OO", self->first, self->last); + if (args == NULL) + return NULL; + + result = PyUnicode_Format(format, args); + Py_DECREF(args); + + return result; +} +#endif + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'PyLine' pour Python. * +* * +* Retour : Adresse de la description du type 'line'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *pyline_get_type(void) +{ + + static PyMethodDef pyline_methods[] = { +#if 0 + {"name", (PyCFunction)pyline_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, +#endif + { NULL } +}; + + + static PyMemberDef pyline_members[] = { + { "address", T_ULONGLONG, offsetof(PyLine, address), READONLY, + "physical or virtual address relative to the line." }, + { NULL } +}; + + + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "noddy.pyline", /* tp_name */ + sizeof(PyLine), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pyline_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "PyLine objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)pyline_get_iter, /* tp_iter */ + 0, /* tp_iternext */ + pyline_methods, /* tp_methods */ + pyline_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pyline_init, /* tp_init */ + 0, /* tp_alloc */ + pyline_new, /* tp_new */ + }; + + return &result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'line' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_line_to_python_module(PyObject *module) +{ + int ret; /* Bilan d'un appel */ + + if (PyType_Ready(pyline_get_type()) < 0) + return false; + + if (PyType_Ready(pylineiter_get_type()) < 0) + return false; + + + + + printf("Adding line type\n"); + + + + Py_INCREF(pyline_get_type()); + PyModule_AddObject(module, "line", (PyObject *)pyline_get_type()); + + Py_INCREF(pylineiter_get_type()); + PyModule_AddObject(module, "lineiter", (PyObject *)pylineiter_get_type()); + + + return true; /* FIXME */ + + +} + + + + + + +/* ---------------------------------------------------------------------------------- */ +/* ITERATEUR POUR LE PARCOURS DE LIGNES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description de l'itérateur 'PyLine' pour Python. * +* * +* Retour : Adresse de la description du type 'PyLineIter'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyTypeObject *pylineiter_get_type(void) +{ + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /* ob_size */ +#endif + + "pyoida.analysis.PyLineIter", /* tp_name */ + sizeof(PyLineIter), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pylineiter_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + "PyLineIter objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)pylineiter_get_next, /* tp_iternext */ + 0, /* tp_methods */ + }; + + return &result; + +} + + +/****************************************************************************** +* * +* Paramètres : head = liste à parcourir. * +* * +* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * +* * +* Retour : Instance d'itérateur prête à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pylineiter_new(GRenderingLine *head) +{ + PyLineIter *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + type = pylineiter_get_type(); + + result = (PyLineIter *)type->tp_alloc(type, 0); + + if (result != NULL) + { + result->head = head; + result->cur = NULL; + } + + return (PyObject *)result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance d'objet à supprimer. * +* * +* Description : Libère la mémoire occupée par un itérateur de 'PyLine'. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void pylineiter_dealloc(PyLineIter *self) +{ +#if PY_VERSION_HEX < 0x03000000 + self->ob_type->tp_free((PyObject *)self); +#else + Py_TYPE(self)->tp_free((PyObject *)self); +#endif + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance manipulée à traiter. * +* * +* Description : Fournit l'élément suivant dans un parcours de lignes. * +* * +* Retour : Point suivant du parcours ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pylineiter_get_next(PyLineIter *self) +{ + PyObject *result; /* Elément à retourner */ + GRenderingLine *next; /* Elément réel suivant */ + + if (self->cur == NULL) next = self->head; + else next = g_rendering_line_get_next_iter(self->head, self->cur, NULL); + + if (next != NULL) + { + self->cur = next; + result = pyline_new_from_existing(self->head, next); + } + + else result = NULL; + + return (PyObject *)result; + +} diff --git a/plugins/pychrysa/analysis/py_line.h b/plugins/pychrysa/analysis/py_line.h new file mode 100644 index 0000000..681e13b --- /dev/null +++ b/plugins/pychrysa/analysis/py_line.h @@ -0,0 +1,45 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line.h - prototypes pour l'intermédiaire des lignes de représentation pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_LINE_H +#define _PLUGINS_PYOIDA_PY_LINE_H + + +#include +#include + + +#include "../../../src/analysis/line.h" + + + +/* Initialise le greffon permettant l'usage de Python. */ +PyObject *pyline_new_from_existing(GRenderingLine *, GRenderingLine *); + +/* Ajoute l'objet 'line' au module Python. */ +bool add_line_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_LINE_H */ diff --git a/plugins/pychrysa/analysis/py_line_code.c b/plugins/pychrysa/analysis/py_line_code.c new file mode 100644 index 0000000..26fe513 --- /dev/null +++ b/plugins/pychrysa/analysis/py_line_code.c @@ -0,0 +1,281 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line_code.h - prototypes pour l'intermédiaire des lignes de code pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_line_code.h" + + +#include "py_line-int.h" + + + +typedef struct { + + PyLine base; /* Classe dérivée */ + +} PyCodeLine; + + + + +/* Fournit la description du type 'PyCodeLine' pour Python. */ +static PyTypeObject *pycodeline_get_type(void); + + + + +static int +pycodeline_init(PyCodeLine *self, PyObject *args, PyObject *kwds); + +static PyObject * +pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds); + + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'PyCodeLine' pour Python. * +* * +* Retour : Adresse de la description du type 'PyCodeLine'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyTypeObject *pycodeline_get_type(void) +{ + static PyMethodDef pycodeline_methods[] = { +#if 0 + {"name", (PyCFunction)pyline_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, +#endif + { NULL } +}; + + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "pyoida.analysis.PyCodeLine", /* tp_name */ + sizeof(PyCodeLine), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "pycodeline objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + pycodeline_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pycodeline_init, /* tp_init */ + 0, /* tp_alloc */ + pycodeline_new, /* tp_new */ + }; + + return &result; + +} + + + + +static int +pycodeline_init(PyCodeLine *self, PyObject *args, PyObject *kwds) +{ +#if 0 + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pycodeline_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } +#endif + return 0; +} + + + + + +static PyObject * +pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyCodeLine *self; + + + printf("creating a new line\n"); + + self = (PyCodeLine *)type->tp_alloc(type, 0); + if (self != NULL) { +#if 0 + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; +#endif + } + + return (PyObject *)self; +} + + + + + +/****************************************************************************** +* * +* Paramètres : head = ???? * +* line = modèle à représenter en Python. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pycodeline_new_from_existing(GRenderingLine *head, GCodeLine *line) +{ + PyCodeLine *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + result = (PyCodeLine *)g_object_get_data(G_OBJECT(line), "pyobject"); + + if (result == NULL) + { + type = pycodeline_get_type(); + + result = (PyCodeLine *)type->tp_alloc(type, 0); + + if (result != NULL) + { + pyline_init_from_existing((PyLine *)result, head, line); + + g_object_set_data(G_OBJECT(line), "pyobject", result); + + } + + } + + return (PyObject *)result; + +} + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'line' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_pycodeline_to_python_module(PyObject *module) +{ + + + pycodeline_get_type()->tp_base = pyline_get_type(); + if (PyType_Ready(pycodeline_get_type()) < 0) + return false; + + + Py_INCREF(pycodeline_get_type()); + PyModule_AddObject(module, "codeline", (PyObject *)pycodeline_get_type()); + + + + return true; /* FIXME */ + +} diff --git a/plugins/pychrysa/analysis/py_line_code.h b/plugins/pychrysa/analysis/py_line_code.h new file mode 100644 index 0000000..8a67b44 --- /dev/null +++ b/plugins/pychrysa/analysis/py_line_code.h @@ -0,0 +1,45 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line_code.h - prototypes pour l'intermédiaire des lignes de code pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_LINE_CODE_H +#define _PLUGINS_PYOIDA_PY_LINE_CODE_H + + +#include +#include + + +#include "../../../src/analysis/line_code.h" + + + +/* Initialise le greffon permettant l'usage de Python. */ +PyObject *pycodeline_new_from_existing(GRenderingLine *, GCodeLine *); + +/* Ajoute l'objet 'PyCodeLine' au module Python. */ +bool add_pycodeline_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_LINE_CODE_H */ diff --git a/plugins/pychrysa/analysis/roptions.c b/plugins/pychrysa/analysis/roptions.c new file mode 100644 index 0000000..57a4f52 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/analysis/roptions.h b/plugins/pychrysa/analysis/roptions.h new file mode 100644 index 0000000..0897211 --- /dev/null +++ b/plugins/pychrysa/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 +#include + + +#include + + + +/* 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/pychrysa/arch/Makefile.am b/plugins/pychrysa/arch/Makefile.am new file mode 100644 index 0000000..6ab3332 --- /dev/null +++ b/plugins/pychrysa/arch/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES = libpychrysaarch.la + +libpychrysaarch_la_SOURCES = \ + archbase.h archbase.c \ + module.h module.c \ + processor.h processor.c + + +libpychrysaarch_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/pychrysa/arch/archbase.c b/plugins/pychrysa/arch/archbase.c new file mode 100644 index 0000000..b73e769 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/arch/archbase.h b/plugins/pychrysa/arch/archbase.h new file mode 100644 index 0000000..ca621aa --- /dev/null +++ b/plugins/pychrysa/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 +#include + +#include + + + +/* 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/pychrysa/arch/module.c b/plugins/pychrysa/arch/module.c new file mode 100644 index 0000000..59b0c2c --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/arch/module.h b/plugins/pychrysa/arch/module.h new file mode 100644 index 0000000..4ae3447 --- /dev/null +++ b/plugins/pychrysa/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 +#include + + + +/* 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/pychrysa/arch/processor.c b/plugins/pychrysa/arch/processor.c new file mode 100644 index 0000000..0a3fe95 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/arch/processor.h b/plugins/pychrysa/arch/processor.h new file mode 100644 index 0000000..032d82d --- /dev/null +++ b/plugins/pychrysa/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 +#include + + + +/* 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/pychrysa/debug/Makefile.am b/plugins/pychrysa/debug/Makefile.am new file mode 100644 index 0000000..3ed4348 --- /dev/null +++ b/plugins/pychrysa/debug/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES = libpychrysadebug.la + +libpychrysadebug_la_SOURCES = \ + debugger.h debugger.c \ + module.h module.c + + +libpychrysadebug_la_LDFLAGS = + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/debug/debugger.c b/plugins/pychrysa/debug/debugger.c new file mode 100644 index 0000000..3e42ab7 --- /dev/null +++ b/plugins/pychrysa/debug/debugger.c @@ -0,0 +1,275 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * debugger.c - instances Python de débogueurs + * + * Copyright (C) 2012 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 "debugger.h" + + +#include +#include + + +#include "../quirks.h" + + + +/* Fournit les identifiants de tous les threads actifs. */ +static PyObject *py_binary_debugger_list_all_threads(PyObject *, PyObject *); + +/* Fournit la pile d'exécution courante via un débogueur. */ +static PyObject *py_binary_debugger_get_frames_stack(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_binary_debugger_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + DebuggerType dtype; /* Type de débogueur à créer */ + int ret; /* Bilan de lecture des args. */ + GBinaryDebugger *debugger; /* Version GLib du format */ + + ret = PyArg_ParseTuple(args, "l", &dtype); + if (!ret) return Py_None; + + debugger = g_new_binary_debugger(dtype, NULL/* FIXME */); + + result = py_binary_debugger_from_c(debugger); + g_object_unref(debugger); + + return (PyObject *)result; + +} + + +/****************************************************************************** +* * +* Paramètres : debugger = instance existante GLib. * +* * +* Description : Crée un nouvel objet Python de type 'BinaryDebugger'. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *py_binary_debugger_from_c(GBinaryDebugger *debugger) +{ + PyObject *module; /* Module d'appartenance */ + PyTypeObject *type; /* Type Python correspondant */ + + module = PyImport_ImportModule("pyoida.debug"); + type = (PyTypeObject*)PyObject_GetAttrString(module, "BinaryDebugger"); + Py_DECREF(module); + + pychrysalide_set_instance_data(G_OBJECT(debugger), type); + + return pygobject_new(G_OBJECT(debugger)); + +} + + + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un débogueur. * +* args = arguments fournis à l'appel. * +* * +* Description : Fournit les identifiants de tous les threads actifs. * +* * +* Retour : Object Python représentant le résultat de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_list_all_threads(PyObject *self, PyObject *args) +{ + PyObject *result; /* Trouvailles à retourner */ + GBinaryDebugger *debugger; /* Version native */ + char **names; /* Noms associés aux threads */ + size_t count; /* Taille de cette liste */ + pid_t *threads; /* Liste des threads actifs */ + size_t i; /* Boucle de parcours */ + PyObject *thread; /* Détails sur un thread donné */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + + threads = g_binary_debugger_list_all_threads(debugger, &names, &count); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + thread = PyTuple_New(2); + PyTuple_SetItem(result, i, thread); + + PyTuple_SetItem(thread, 0, PyLong_FromLong(threads[i])); + PyTuple_SetItem(thread, 1, PyString_FromString(names[i])); + + free(names[i]); + + } + + if (names != NULL) + free(names); + + if (threads != NULL) + free(threads); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un débogueur. * +* args = arguments fournis à l'appel. * +* * +* Description : Fournit la pile d'exécution courante via un débogueur. * +* * +* Retour : Object Python représentant le résultat de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_get_frames_stack(PyObject *self, PyObject *args) +{ + PyObject *result; /* Trouvailles à retourner */ + GBinaryDebugger *debugger; /* Version native */ + unsigned long thread; /* Identifiant du thread visé */ + size_t count; /* Taille de cette liste */ + dbg_frame_t *frames; /* Frames courantes trouvées */ + size_t i; /* Boucle de parcours */ + PyObject *frame; /* Détails sur une frame */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + + if (!PyArg_ParseTuple(args, "k", &thread)) + return Py_None; + + frames = g_binary_debugger_get_frames_stack(debugger, thread, &count); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + frame = PyTuple_New(1); + PyTuple_SetItem(result, i, frame); + + PyTuple_SetItem(frame, 0, PyLong_FromUnsignedLongLong(frames[i].addr)); + + } + + if (frames != NULL) + free(frames); + + return result; + +} + + + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'pychrysalide.debug.BinaryDebugger' au module.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_binary_debugger(PyObject *module) +{ + PyObject *pygobj_mod; /* Module Python-GObject */ + int ret; /* Bilan d'un appel */ + + static PyMethodDef py_binary_debugger_methods[] = { + { + "list_all_threads", (PyCFunction)py_binary_debugger_list_all_threads, + METH_NOARGS, + "List all current active threads." + }, + { + "get_frames_stack", (PyCFunction)py_binary_debugger_get_frames_stack, + METH_VARARGS, + "Provide the current callstack using a debugger." + }, + { NULL } + }; + + static PyTypeObject py_binary_debugger_type = { + + PyObject_HEAD_INIT(NULL) + + .tp_name = "pychrysalide.debug.BinaryDebugger", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide binary debugger", + + .tp_methods = py_binary_debugger_methods, + .tp_new = (newfunc)py_binary_debugger_new + + }; + + pygobj_mod = PyImport_ImportModule("gobject"); + if (pygobj_mod == NULL) return false; + + py_binary_debugger_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject"); + Py_DECREF(pygobj_mod); + + if (PyType_Ready(&py_binary_debugger_type) < 0) + return false; + + Py_INCREF(&py_binary_debugger_type); + ret = PyModule_AddObject(module, "BinaryDebugger", (PyObject *)&py_binary_debugger_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysa/debug/debugger.h b/plugins/pychrysa/debug/debugger.h new file mode 100644 index 0000000..5e5cc21 --- /dev/null +++ b/plugins/pychrysa/debug/debugger.h @@ -0,0 +1,45 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * debugger.h - prototypes pour les instances Python de débogueurs + * + * Copyright (C) 2012 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_DEBUG_DEBUGGER_H +#define _PLUGINS_PYOIDA_DEBUG_DEBUGGER_H + + +#include +#include + + +#include + + + +/* Crée un nouvel objet Python de type 'BinaryDebugger'. */ +PyObject *py_binary_debugger_from_c(GBinaryDebugger *debugger); + +/* Ajoute l'objet 'pychrysalide.debug.BinaryDebugger' au module. */ +bool register_python_binary_debugger(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_DEBUG_DEBUGGER_H */ diff --git a/plugins/pychrysa/debug/module.c b/plugins/pychrysa/debug/module.c new file mode 100644 index 0000000..7537dc7 --- /dev/null +++ b/plugins/pychrysa/debug/module.c @@ -0,0 +1,66 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire debug en tant que module + * + * Copyright (C) 2012 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 "debugger.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'debug' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_debug_module_to_python_module(PyObject *super) +{ + bool result; + PyObject *module; + int ret; /* Bilan d'un appel */ + + static PyMethodDef py_debug_methods[] = { + { NULL } + }; + + module = Py_InitModule("pyoida.debug", py_debug_methods); + if (module == NULL) return false; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "pyoida.debug", module); + + result = (ret != 0); + + result &= register_python_binary_debugger(module); + + return result; + +} diff --git a/plugins/pychrysa/debug/module.h b/plugins/pychrysa/debug/module.h new file mode 100644 index 0000000..d331621 --- /dev/null +++ b/plugins/pychrysa/debug/module.h @@ -0,0 +1,39 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire debug en tant que module + * + * Copyright (C) 2012 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_DEBUG_MODULE_H +#define _PLUGINS_PYOIDA_DEBUG_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'debug' au module Python. */ +bool add_debug_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_DEBUG_MODULE_H */ diff --git a/plugins/pychrysa/format/Makefile.am b/plugins/pychrysa/format/Makefile.am new file mode 100644 index 0000000..a890385 --- /dev/null +++ b/plugins/pychrysa/format/Makefile.am @@ -0,0 +1,16 @@ + +noinst_LTLIBRARIES = libpychrysaformat.la + +libpychrysaformat_la_SOURCES = \ + executable.h executable.c \ + module.h module.c + + +libpychrysaformat_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/pychrysa/format/executable.c b/plugins/pychrysa/format/executable.c new file mode 100644 index 0000000..2f10f71 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/format/executable.h b/plugins/pychrysa/format/executable.h new file mode 100644 index 0000000..577d1f9 --- /dev/null +++ b/plugins/pychrysa/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 +#include + +#include + + + +/* 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/pychrysa/format/module.c b/plugins/pychrysa/format/module.c new file mode 100644 index 0000000..1f15d50 --- /dev/null +++ b/plugins/pychrysa/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/pychrysa/format/module.h b/plugins/pychrysa/format/module.h new file mode 100644 index 0000000..4aa95cf --- /dev/null +++ b/plugins/pychrysa/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 +#include + + + +/* 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/pychrysa/linsyscalls/oidapgi.py b/plugins/pychrysa/linsyscalls/oidapgi.py new file mode 100755 index 0000000..dd4e010 --- /dev/null +++ b/plugins/pychrysa/linsyscalls/oidapgi.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +import pyoida +#import oidaline +from pyoida import Noddy + + +class OpenIDAPlugin: + """A simple example class""" + + + + + +if __name__ == "__main__": + print "OpenIDA PlugIn" + + + print "Hello World\n", + + pyoida.system("ls -lh") + + test = Noddy("first", "last") + + print test.name() + + #oidaline.echo() + diff --git a/plugins/pychrysa/plugin.c b/plugins/pychrysa/plugin.c new file mode 100644 index 0000000..b04dd09 --- /dev/null +++ b/plugins/pychrysa/plugin.c @@ -0,0 +1,861 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * plugin.c - interactions avec un greffon Python + * + * Copyright (C) 2010-2012 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" +#include "debug/debugger.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é */ + PyObject *instance; /* Instance Python du greffon */ + +}; + + +/* 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 *); + +/* Indique l'utilité pratique du greffon. */ +static PluginAction g_python_plugin_get_action(const GPythonPlugin *); + +/* Indentifie un format à associer à un contenu binaire. */ +static MatchingFormatAction g_python_plugin_is_matching(const GPythonPlugin *, char **, bin_t **, off_t *); + +/* Exécute une action définie sur un binaire chargé. */ +static bool g_python_plugin_execute(GPythonPlugin *, GOpenidaBinary *, PluginAction); + + +/* Exécute une action relative à un débogueur. */ +static bool g_python_plugin_handle_debugger(const GPythonPlugin *, GBinaryDebugger *, PluginAction); + + + +/* ------------------------- MODULE PYTHON POUR LES SCRIPTS ------------------------- */ + + +/* Classe plugin pour Python */ +typedef struct _pychrysa_plugin +{ + PyObject_HEAD + +} pychrysa_plugin; + + + + + + +/* Crée un nouveau greffon Python abstrait. */ +static PyObject *pychrysa_plugin_new(PyTypeObject *, PyObject *, PyObject *); + +/* Exécute une action valide pour le greffon Python. */ +static PyObject *pychrysa_plugin_run(PyObject *, PyObject *); + + + +/* Définit les constantes pour les greffons en Python. */ +static bool pychrysa_plugin_define_constants(PyObject *); + +/* Définit le comportement par défaut d'un greffon Python. */ +static PyObject *pychrysa_plugin_get_action(PyObject *, PyObject *); + +/* Définit l'issue de la recherche d'un format par défaut. */ +static PyObject *pychrysa_plugin_is_matching(PyObject *, PyObject *); + + +/* Exécute une action relative à un débogueur. */ +static PyObject *pychrysa_plugin_handle_debugger(PyObject *, 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; + plugin_parent->handle_debugger = (execute_on_debugger_fc)g_python_plugin_handle_debugger; + +} + + + + +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 : modname = nom du module à charger. * +* 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 *modname, const char *filename) +{ + GPythonPlugin *result; /* Structure à retourner */ + PyObject *name; /* Chemin d'accès pour Python */ + PyObject *module; /* Script Python chargé */ + PyObject *dict; /* Dictionnaire associé */ + PyObject *class; /* Classe à instancier */ + PyObject *instance; /* Instance Python du greffon */ + +#if PY_VERSION_HEX >= 0x03000000 + name = PyUnicode_FromString(filename); +#else + name = PyString_FromString(filename); +#endif + if (name == NULL) goto gppn_bad_exit; + + module = PyImport_Import(name); + Py_DECREF(name); + + if (module == NULL) + { + PyErr_Print(); + goto gppn_bad_exit; + } + + dict = PyModule_GetDict(module); + class = PyDict_GetItemString(dict, modname); + Py_DECREF(dict); + + if (class == NULL) goto gppn_no_class; + if (!PyType_Check(class->ob_type)) goto gppn_no_class; + + instance = PyObject_CallFunction(class, NULL); + if (instance == NULL) goto gppn_no_instance; + + Py_DECREF(class); + + result = g_object_new(G_TYPE_PYTHON_PLUGIN, NULL); + + G_PLUGIN_MODULE(result)->get_action = g_python_plugin_get_action; + + G_PLUGIN_MODULE(result)->is_matching = g_python_plugin_is_matching; + + result->module = module; + result->instance = instance; + + return G_PLUGIN_MODULE(result); + + gppn_no_instance: + + Py_DECREF(class); + + gppn_no_class: + + Py_DECREF(module); + + gppn_bad_exit: + + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon de prise en charge à utiliser. * +* * +* Description : Indique l'utilité pratique du greffon. * +* * +* Retour : Action(s) codifiée(s), PGA_NONE par défaut. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PluginAction g_python_plugin_get_action(const GPythonPlugin *plugin) +{ + PluginAction result; /* Valeur à retourner */ + PyObject *value; /* Valeur obtenue */ + + value = run_python_method(plugin->instance, "get_action", NULL); + + result = PyLong_AsLong(value); + Py_DECREF(value); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon de prise en charge à utiliser. * +* filename = éventuel nom de fichier associé ou NULL. [OUT] * +* data = données chargées. [OUT] * +* length = quantité de ces données. [OUT] * +* * +* Description : Indentifie un format à associer à un contenu binaire. * +* * +* Retour : Bilan de la recherche de correspondances. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static MatchingFormatAction g_python_plugin_is_matching(const GPythonPlugin *plugin, char **filename, bin_t **data, off_t *length) +{ + MatchingFormatAction result; /* Valeur à retourner */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Valeurs obtenues */ + PyObject *action; /* Action à faire suivre */ + PyObject *new_filename; /* Nouveau fichier */ + PyObject *new_data; /* Nouvelles données */ + char *tmp; /* Stockage avant recopie */ + + if (*filename == NULL) + return MFA_NONE; + + args = PyTuple_New(2); + + PyTuple_SetItem(args, 0, PyString_FromString(*filename)); + PyTuple_SetItem(args, 1, PyByteArray_FromStringAndSize(*data, *length)); + + value = run_python_method(plugin->instance, "is_matching", args); + + if (value != NULL && PyTuple_Check(value) && PyTuple_Size(value) == 3) + { + action = PyTuple_GetItem(value, 0); + new_filename = PyTuple_GetItem(value, 1); + new_data = PyTuple_GetItem(value, 2); + + if (action == NULL || new_filename == NULL || new_data == NULL) + goto is_matching_bad; + + if (!PyInt_Check(action) + || (new_filename != Py_None && !PyString_Check(new_filename)) + || (new_data != Py_None && !PyByteArray_Check(new_data))) + goto is_matching_bad; + + result = PyInt_AsLong(action); + if (result >= MFA_COUNT) goto is_matching_bad; + + if (result != MFA_NONE && new_data == Py_None) goto is_matching_bad; + + if (new_filename != Py_None) + *filename = strdup(PyString_AsString(new_filename)); + /** + * La suppression de la part du greffon n'est permise que + * si une prise en charge est assurée. + */ + else if (result != MFA_NONE) + *filename = NULL; + + /** + * Pareil que précédemment. + */ + if (new_data != Py_None) + { + tmp = PyByteArray_AsString(new_data); + *length = PyByteArray_Size(new_data); + + *data = (bin_t *)calloc(*length, sizeof(bin_t)); + memcpy(*data, tmp, *length * sizeof(bin_t)); + + } + + goto is_matching_ok; + + } + + is_matching_bad: + + printf("Bad result from is_matching() plugin function.\n"); + + result = MFA_NONE; + + is_matching_ok: + + Py_XDECREF(value); + Py_DECREF(args); + + return result; + +} + + + + +/****************************************************************************** +* * +* 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); + + + + + + +} + + + + + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* debugger = débogueur à l'origine de l'opération. * +* action = action attendue. * +* * +* Description : Exécute une action relative à un débogueur. * +* * +* Retour : true si une action a été menée, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_python_plugin_handle_debugger(const GPythonPlugin *plugin, GBinaryDebugger *debugger, PluginAction action) +{ + bool result; /* Bilan à remonter */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Valeurs obtenues */ + + args = PyTuple_New(2); + + PyTuple_SetItem(args, 0, py_binary_debugger_from_c(debugger)); + PyTuple_SetItem(args, 1, PyInt_FromLong(action)); + + value = run_python_method(plugin->instance, "handle_debugger", args); + + result = (value == Py_True); + + Py_XDECREF(value); + Py_DECREF(args); + + return result; + +} + + + + + + + +/* ---------------------------------------------------------------------------------- */ +/* 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 *pychrysa_plugin_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + pychrysa_plugin *result; /* Instance à retourner */ + + result = (pychrysa_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 pychrysa_plugin_define_constants(PyObject *dict) +{ + int ret; /* Bilan d'un ajout */ + + ret = PyDict_SetItemString(dict, "PGA_NONE", PyInt_FromLong(PGA_NONE)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "PGA_FORMAT_MATCHER", PyInt_FromLong(PGA_FORMAT_MATCHER)); + if (ret == -1) return false; + + 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; + + ret = PyDict_SetItemString(dict, "PGA_DEBUGGER_ATTACH", PyInt_FromLong(PGA_DEBUGGER_ATTACH)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "PGA_DEBUGGER_DETACH", PyInt_FromLong(PGA_DEBUGGER_DETACH)); + if (ret == -1) return false; + + /* PGA_FORMAT_MATCHER */ + + ret = PyDict_SetItemString(dict, "MFA_NONE", PyInt_FromLong(MFA_NONE)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "MFA_MATCHED", PyInt_FromLong(MFA_MATCHED)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "MFA_RELOAD", PyInt_FromLong(MFA_RELOAD)); + 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 : Définit le comportement par défaut d'un greffon Python. * +* * +* Retour : Rien en équivalent Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pychrysa_plugin_get_action(PyObject *self, PyObject *args) +{ + return PyInt_FromLong(PGA_NONE); + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * +* args = arguments fournis à l'appel. * +* * +* Description : Définit l'issue de la recherche d'un format par défaut. * +* * +* Retour : Rien en équivalent Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pychrysa_plugin_is_matching(PyObject *self, PyObject *args) +{ + PyObject *result; /* Liste à retourner */ + + result = PyTuple_New(3); + + PyTuple_SetItem(result, 0, PyInt_FromLong(MFA_NONE)); + PyTuple_SetItem(result, 1, Py_None); + PyTuple_SetItem(result, 2, Py_None); + + return result; + +} + + + + +/****************************************************************************** +* * +* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * +* args = arguments fournis à l'appel. * +* * +* Description : Exécute une action relative à un débogueur. * +* * +* Retour : True en équivalent Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *pychrysa_plugin_handle_debugger(PyObject *self, PyObject *args) +{ + Py_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 *pychrysa_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 pychrysa_plugin_methods[] = { + { "get_action", (PyCFunction)pychrysa_plugin_get_action, METH_NOARGS, + "Register the plugin for given actions." + }, + { "is_matching", (PyCFunction)pychrysa_plugin_is_matching, METH_VARARGS, + "Define if the given file can be handled." + }, + { "handle_debugger", (PyCFunction)pychrysa_plugin_handle_debugger, METH_VARARGS, + "Be notify about debugger attaching or detaching." + }, + { "run", (PyCFunction)pychrysa_plugin_run, METH_VARARGS, + "Run the plugin for a specific action." + }, + NULL +}; + + +static PyTypeObject pychrysa_plugin_type = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "plugin.Plugin", /* tp_name */ + sizeof(pychrysa_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*/ + "PyCHRYSA Plugin objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + pychrysa_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)pychrysa_plugin_new, /* tp_new */ +}; + + + + + if (PyType_Ready(&pychrysa_plugin_type) < 0) + return false; + + + if (!pychrysa_plugin_define_constants(pychrysa_plugin_type.tp_dict)) + return false; + + + + + Py_INCREF(&pychrysa_plugin_type); + PyModule_AddObject(module, "Plugin", (PyObject *)&pychrysa_plugin_type); + + + return true; /* FIXME */ + + +} diff --git a/plugins/pychrysa/plugin.h b/plugins/pychrysa/plugin.h new file mode 100644 index 0000000..af8445d --- /dev/null +++ b/plugins/pychrysa/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-2011 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 +#include +#include + + +#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 *, 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/pychrysa/py_log.c b/plugins/pychrysa/py_log.c new file mode 100644 index 0000000..fde7ae5 --- /dev/null +++ b/plugins/pychrysa/py_log.c @@ -0,0 +1,344 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_log.c - intermédiaire du panneau de messages pour Python + * + * Copyright (C) 2009-2012 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_log.h" + +#include + + +#include "../../src/gui/panels/log.h" + + +typedef struct { + PyObject_HEAD + PyObject *first; + PyObject *last; + int number; +} pylog; + + +#define _(str) str + + + + +/* Définit les constantes pour les types de message. */ +bool pylog_define_constants(PyObject *); + +/* Affiche un message dans le journal des messages système. */ +PyObject *pylog_simple_message(PyObject *, PyObject *); + + + + +/****************************************************************************** +* * +* Paramètres : dict = dictionnaire à compléter. * +* * +* Description : Définit les constantes pour les types de message. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool pylog_define_constants(PyObject *dict) +{ + int ret; /* Bilan d'un ajout */ + + ret = PyDict_SetItemString(dict, "LMT_INFO", PyInt_FromLong(LMT_INFO)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "LMT_BAD_BINARY", PyInt_FromLong(LMT_BAD_BINARY)); + if (ret == -1) return false; + + ret = PyDict_SetItemString(dict, "LMT_PROCESS", PyInt_FromLong(LMT_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 : Affiche un message dans le journal des messages système. * +* * +* Retour : Rien en équivalent Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *pylog_simple_message(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + LogMessageType type; /* Espèce du message */ + const char *msg; /* Contenu du message */ + + if (!PyArg_ParseTuple(args, "is", &type, &msg)) + return NULL; + + switch (type) + { + case LMT_INFO: + case LMT_BAD_BINARY: + case LMT_PROCESS: + log_simple_message(type, msg); + result = Py_None; + break; + + default: + PyErr_SetString(PyExc_ValueError, + _("Invalid type of message")); + result = NULL; + break; + + } + + return result; + +} + + + + + + + + + + +static void +pylog_dealloc(pylog* self) +{ + Py_XDECREF(self->first); + Py_XDECREF(self->last); + + + //printf("dealloc\n"); + +#if PY_VERSION_HEX < 0x03000000 + self->ob_type->tp_free((PyObject*)self); +#else + Py_TYPE(self)->tp_free((PyObject*)self); +#endif + + //printf("dealloc::end\n"); + +} + +static PyObject * +pylog_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + pylog *self; + + self = (pylog *)type->tp_alloc(type, 0); + if (self != NULL) { + self->first = PyString_FromString("");//PyUnicode_FromString(""); + if (self->first == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->last = PyString_FromString("");//PyUnicode_FromString(""); + if (self->last == NULL) + { + Py_DECREF(self); + return NULL; + } + + self->number = 0; + } + + return (PyObject *)self; +} + +static int +pylog_init(pylog *self, PyObject *args, PyObject *kwds) +{ + PyObject *first=NULL, *last=NULL, *tmp; + + static char *kwlist[] = {"first", "last", "number", NULL}; + + printf("pylog_init\n"); + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, + &first, &last, + &self->number)) + return -1; + + if (first) { + tmp = self->first; + Py_INCREF(first); + self->first = first; + Py_DECREF(tmp); + } + + if (last) { + tmp = self->last; + Py_INCREF(last); + self->last = last; + Py_DECREF(tmp); + } + + return 0; +} + +static PyMemberDef pylog_members[] = { + {"number", T_INT, offsetof(pylog, number), 0, + "noddy number"}, + {NULL} /* Sentinel */ +}; + + + + + + + + + + +static PyObject * +pylog_name(pylog* self) +{ + static PyObject *format = NULL; + PyObject *args, *result; + + if (format == NULL) { + format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); + if (format == NULL) + return NULL; + } + + args = Py_BuildValue("OO", self->first, self->last); + if (args == NULL) + return NULL; + + result = PyUnicode_Format(format, args); + Py_DECREF(args); + + return result; +} + +static PyMethodDef pylog_methods[] = { + {"name", (PyCFunction)pylog_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, + { "log_simple_message", (PyCFunction)pylog_simple_message, METH_VARARGS | METH_STATIC, + "Return the name, combining the first and last name" + }, + {NULL} /* Sentinel */ +}; + + +static PyTypeObject pylog_type = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "noddy.pylog", /* tp_name */ + sizeof(pylog), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)pylog_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved / tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "pylog objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + pylog_methods, /* tp_methods */ + pylog_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)pylog_init, /* tp_init */ + 0, /* tp_alloc */ + pylog_new, /* tp_new */ +}; + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute l'objet 'log' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_log_to_python_module(PyObject *module) +{ + int ret; /* Bilan d'un appel */ + + if (PyType_Ready(&pylog_type) < 0) + return; + + printf("Adding log type\n"); + + + pylog_define_constants(pylog_type.tp_dict); + + + + + Py_INCREF(&pylog_type); + PyModule_AddObject(module, "logger", (PyObject *)&pylog_type); + + + return true; /* FIXME */ + + +} diff --git a/plugins/pychrysa/py_log.h b/plugins/pychrysa/py_log.h new file mode 100644 index 0000000..5274428 --- /dev/null +++ b/plugins/pychrysa/py_log.h @@ -0,0 +1,39 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_log.h - prototypes pour l'intermédiaire du panneau de messages pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYOIDA_PY_LOG_H +#define _PLUGINS_PYOIDA_PY_LOG_H + + +#include +#include + + + +/* Ajoute l'objet 'log' au module Python. */ +bool add_log_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_LOG_H */ diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c new file mode 100644 index 0000000..84400a1 --- /dev/null +++ b/plugins/pychrysa/pychrysa.c @@ -0,0 +1,249 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pychrysa.c - plugin permettant des extensions en Python + * + * Copyright (C) 2009-2012 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 Foobar. If not, see . + */ + + +#include "pychrysa.h" + + +#include +#include + + +#include + + +#include "quirks.h" +#include "analysis/module.h" +#include "arch/module.h" +#include "debug/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 "py_log.h" +#include "../../src/common/environment.h" +#include "../../src/common/extstr.h" +#include "../../src/plugins/plugin-int.h" + + + + + +static PyMethodDef SpamMethods[] = { + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + + + + + +/****************************************************************************** +* * +* Paramètres : ref = espace de référencement global. * +* * +* Description : Initialise le greffon permettant l'usage de Python. * +* * +* Retour : true. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_plugin(GObject *ref) +{ + char *paths; /* Emplacements de greffons */ + char *path; /* Chemin à fouiller */ + char *save; /* Sauvegarde pour ré-entrance */ + DIR *dir; /* Répertoire à parcourir */ + struct dirent entry; /* Elément trouvé */ + struct dirent *next; /* Prochain élément fourni */ + int ret; /* Bilan d'un appel système */ + char *filename; /* Chemin d'accès reconstruit */ + + + + + GPluginModule *plugin; + + + + /* Définition des zones d'influence */ + + add_to_env_var("PYTHONPATH", PLUGINS_DIR G_DIR_SEPARATOR_S "python", ";"); + + paths = get_env_var("PYTHONPATH"); + + /* Intialisations Python */ + + + //return false; + + + Py_Initialize(); + + initpychrysa(); + + + + /* Chargement des greffons */ + + save = NULL; /* gcc... */ + + for (path = strtok_r(paths, ";", &save); + path != NULL; + path = strtok_r(NULL, ";", &save)) + { + dir = opendir(path); + if (dir == NULL) + { + perror("opendir"); + continue; + } + + for (ret = readdir_r(dir, &entry, &next); + ret == 0 && next != NULL; + ret = readdir_r(dir, &entry, &next)) + { + if (entry.d_name[0] == '.') continue; + + filename = strdup(entry.d_name); + filename = stradd(filename, "."); + filename = stradd(filename, "__init__"); + + plugin = g_python_plugin_new(entry.d_name, filename); + + if (plugin == NULL) + printf("No suitable Python plugin found in '%s'\n", filename); /* FIXME : LOG(...) */ + else + { + printf("ok pour %s\n", filename); + add_plugin_to_main_list(plugin); + } + + free(filename); + + } + + closedir(dir); + + } + + //Py_Finalize(); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* * +* Description : Indique les opérations offertes par un greffon donné. * +* * +* Retour : Action(s) offerte(s) par le greffon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PluginAction get_plugin_action(const GPluginModule *plugin) +{ + PluginAction result; /* Combinaison à retourner */ + + result = PGA_NONE; + + return result; + +} + + + + + +#if PY_VERSION_HEX >= 0x03000000 + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Point d'entrée pour l'initialisation de Python. * +* * +* Retour : ? * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyMODINIT_FUNC PyInit_pychrysa(void) +{ + static struct PyModuleDef spammodule = { + PyModuleDef_HEAD_INIT, + "pychrysa", + "pychrysa_doc", + -1, + SpamMethods + }; + + PyModule_Create(&spammodule); + +} + +#else + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Point d'entrée pour l'initialisation de Python. * +* * +* Retour : ? * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyMODINIT_FUNC initpychrysa(void) +{ + PyObject *module; + + pygobject_init(-1, -1, -1); + pychrysalide_init_quirks(); + + module = Py_InitModule("pychrysa", SpamMethods); + + //add_analysis_roptions_to_python_module(module); + add_analysis_module_to_python_module(module); + add_arch_module_to_python_module(module); + add_debug_module_to_python_module(module); + add_format_module_to_python_module(module); + + add_log_to_python_module(module); + add_plugin_to_python_module(module); + +} + +#endif diff --git a/plugins/pychrysa/pychrysa.h b/plugins/pychrysa/pychrysa.h new file mode 100644 index 0000000..e4605e5 --- /dev/null +++ b/plugins/pychrysa/pychrysa.h @@ -0,0 +1,58 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pychrysa.h - prototypes pour le plugin permettant des extensions en Python + * + * Copyright (C) 2009-2012 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 Foobar. If not, see . + */ + + +#ifndef _PLUGINS_PYCHRYSA_H +#define _PLUGINS_PYCHRYSA_H + + +#include +#include +#include + + +#include "plugin.h" + + + +/* Initialise le greffon permettant l'usage de Python. */ +bool init_plugin(GObject *); + +/* Indique les opérations offertes par un greffon donné. */ +PluginAction get_plugin_action(const GPluginModule *); + + +#if PY_VERSION_HEX >= 0x03000000 + +/* Point d'entrée pour l'initialisation de Python. */ +PyMODINIT_FUNC PyInit_pychrysa(void); + +#else + +/* Point d'entrée pour l'initialisation de Python. */ +PyMODINIT_FUNC initpychrysa(void); + +#endif + + + +#endif /* _PLUGINS_PYCHRYSA_H */ diff --git a/plugins/pychrysa/quirks.c b/plugins/pychrysa/quirks.c new file mode 100644 index 0000000..4dcae2c --- /dev/null +++ b/plugins/pychrysa/quirks.c @@ -0,0 +1,148 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * quirks.c - transmission du type Python exact aux instances de PyObject + * + * Copyright (C) 2012 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 "quirks.h" + + + +#include +#include + + + + + + +/* Coordonnées insérées manuellement */ +typedef struct _PyGObjectData_fake +{ + PyTypeObject *type; /* Type précis pour Python */ + GSList *closures; /* Supports d'appel */ + +} PyGObjectData_fake; + + +/* Clef d'accès réservée */ +static GQuark pygobject_instance_data_key_fake = 0; + + + + + +static void pygobject_data_free_fake(PyGObjectData_fake *data) +{ + PyGILState_STATE state; /* Etat interne de Python */ + GSList *iter; /* Boucle de parcours */ + + state = pyglib_gil_state_ensure(); + + Py_DECREF(data->type); + + pyg_begin_allow_threads; + + for (iter = data->closures; iter; ) + { + /** + * On obtient le lien avant la libération via + * pygobject_unwatch_closure()... + */ + iter = iter->next; + + g_closure_invalidate((GClosure *)iter->data); + + } + + pyg_end_allow_threads; + + g_free(data); + + pyglib_gil_state_release(state); + +} + + + +static PyGObjectData_fake *pygobject_data_new_fake(void) +{ + PyGObjectData_fake *result; /* Instance à retourner */ + + result = g_new0(PyGObjectData_fake, 1); + + return result; + +} + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Définit les éléments immuables pour toute association. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void pychrysalide_init_quirks(void) +{ + pygobject_instance_data_key_fake = g_quark_from_static_string("PyGObject::instance-data"); + +} + + +/****************************************************************************** +* * +* Paramètres : obj = instance GLib crée en C. * +* type = type de l'objet Python correspond. * +* * +* Description : Crée l'association précise attendue par Python-GObject. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void pychrysalide_set_instance_data(GObject *obj, PyTypeObject *type) +{ + PyGObjectData_fake *data; + + data = g_object_get_qdata(obj, pygobject_instance_data_key_fake); + + if (data == NULL) + { + data = pygobject_data_new_fake(); + + data->type = type; + Py_INCREF(type); + + g_object_set_qdata_full(obj, pygobject_instance_data_key_fake, + data, (GDestroyNotify)pygobject_data_free_fake); + + } + +} diff --git a/plugins/pychrysa/quirks.h b/plugins/pychrysa/quirks.h new file mode 100644 index 0000000..70e036e --- /dev/null +++ b/plugins/pychrysa/quirks.h @@ -0,0 +1,42 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * quirks.h - prototypes pour la transmission du type Python exact aux instances de PyObject + * + * Copyright (C) 2012 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_QUIRKS_H +#define _PLUGINS_PYOIDA_QUIRKS_H + + +#include +#include + + + +/* Définit les éléments immuables pour toute association. */ +void pychrysalide_init_quirks(void); + +/* Crée l'association précise attendue par Python-GObject. */ +void pychrysalide_set_instance_data(GObject *, PyTypeObject *); + + + +#endif /* _PLUGINS_PYOIDA_QUIRKS_H */ diff --git a/plugins/pyoida/Makefile.am b/plugins/pyoida/Makefile.am deleted file mode 100644 index 42a2fc2..0000000 --- a/plugins/pyoida/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ - -pkglib_LTLIBRARIES = pyoida.la - -pyoida_la_SOURCES = \ - plugin.h plugin.c \ - py_log.h py_log.c \ - pyoida.h pyoida.c \ - quirks.h quirks.c - -pyoida_la_LIBADD = \ - analysis/libpyoidaanalysis.la \ - arch/libpyoidaarch.la \ - debug/libpyoidadebug.la \ - format/libpyoidaformat.la - -pyoida_la_LDFLAGS = -module -avoid-version $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \ - $(LIBPYGOBJECT_LIBS) \ - -L../../src/panels/ -lpanels -L../../src/.libs -loidadisass -loidagtkext \ - -L../../src/plugins/.libs -lplugins - - -INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) - -AM_CPPFLAGS = - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = analysis arch debug format diff --git a/plugins/pyoida/analysis/Makefile.am b/plugins/pyoida/analysis/Makefile.am deleted file mode 100644 index e67f188..0000000 --- a/plugins/pyoida/analysis/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ - -noinst_LTLIBRARIES = libpyoidaanalysis.la - -libpyoidaanalysis_la_SOURCES = \ - binary.h binary.c \ - exporter-int.h \ - exporter.h exporter.c \ - line.h line.c \ - module.h module.c \ - roptions.h roptions.c - - -libpyoidaanalysis_la_LDFLAGS = - - -INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) -I../../../src - -AM_CPPFLAGS = - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pyoida/analysis/binary.c b/plugins/pyoida/analysis/binary.c deleted file mode 100644 index d378496..0000000 --- a/plugins/pyoida/analysis/binary.c +++ /dev/null @@ -1,279 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * binary.c - équivalent Python du fichier "analysis/binary.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "binary.h" - - -#include "line.h" -#include "../format/executable.h" - - - - -/* Classe 'analysis.binary' pour Python */ -typedef struct _py_binary -{ - PyObject_HEAD - - GOpenidaBinary *binary; /* Référence GLib */ - -} py_binary; - - - - -/* Crée un nouvel objet Python de type 'py_binary'. */ -static PyObject *py_binary_new(PyTypeObject *, PyObject *, PyObject *); - - - - -/* Fournit le format de fichier reconnu dans le contenu binaire. */ -static PyObject *py_binary_get_format(py_binary *); - -/* Fournit les lignes de rendu associé pour Python. */ -static PyObject *py_binary_get_lines(py_binary *); - - - -/* Fournit le type d'objet 'analysis.binary' pour Python. */ -static PyTypeObject *get_analysis_binary_type(void); - - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'py_binary'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_binary *result; /* Instance à retourner */ - - result = (py_binary *)type->tp_alloc(type, 0); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : binary = objet GLib existant à transposer. * -* * -* Description : Crée un nouvel objet Python de type 'py_binary'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *py_binary_new_from_existing(GOpenidaBinary *binary) -{ - py_binary *result; /* Instance à retourner */ - PyTypeObject *type; /* Type Python à instancier */ - - result = (py_binary *)g_object_get_data(G_OBJECT(binary), "python_object"); - - if (result == NULL) - { - type = get_analysis_binary_type(); - - result = (py_binary *)type->tp_alloc(type, 0); - - result->binary = binary; - g_object_ref(binary); - - g_object_set_data(G_OBJECT(binary), "python_object", result); - - } - else Py_INCREF((PyObject *)result); - - return (PyObject *)result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit le format de fichier reconnu dans le contenu binaire.* -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_get_format(py_binary *self) -{ - PyObject *result; /* Liste à retourner */ - GExeFormat *format; /* Format récupéré à convertir */ - - format = g_openida_binary_get_format(self->binary); - - result = py_executable_convert(format); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit les lignes de rendu associé pour Python. * -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_get_lines(py_binary *self) -{ - PyObject *result; /* Liste à retourner */ - GRenderingLine *lines; /* Liste récupérée à convertir */ - - lines = g_openida_binary_get_lines(self->binary); - - result = py_line_new_from_existing(lines); - - return result; - -} - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.binary' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_binary_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyMethodDef py_binary_methods[] = { - { - "get_format", (PyCFunction)py_binary_get_format, - METH_NOARGS, - "Give the file format recognized in the binary content." - }, - { - "get_lines", (PyCFunction)py_binary_get_lines, - METH_NOARGS, - "Provide the rendering lines used by the binary." - }, - { NULL } - }; - - static PyGetSetDef py_binary_getset[] = { - { NULL } - }; - - static PyTypeObject py_binary_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.Binary", - .tp_basicsize = sizeof(py_binary), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA loaded binary to analyse", - - .tp_methods = py_binary_methods, - .tp_getset = py_binary_getset, - .tp_new = (newfunc)py_binary_new - - }; - - if (result == NULL) result = &py_binary_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.binary' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_binary_to_python_module(PyObject *module) -{ - PyTypeObject *py_binary_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_binary_type = get_analysis_binary_type(); - - if (PyType_Ready(py_binary_type) < 0) - return false; - - Py_INCREF(py_binary_type); - ret = PyModule_AddObject(module, "Binary", (PyObject *)py_binary_type); - - return (ret == 0); - -} diff --git a/plugins/pyoida/analysis/binary.h b/plugins/pyoida/analysis/binary.h deleted file mode 100644 index 1500a06..0000000 --- a/plugins/pyoida/analysis/binary.h +++ /dev/null @@ -1,44 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * binary.h - prototypes pour l'équivalent Python du fichier "analysis/binary.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_BINARY_H -#define _PLUGINS_PYOIDA_ANALYSIS_BINARY_H - - -#include -#include - -#include - - - -/* Crée un nouvel objet Python de type 'py_binary'. */ -PyObject *py_binary_new_from_existing(GOpenidaBinary *); - -/* Ajoute l'objet 'analysis.binary' au module Python. */ -bool add_analysis_binary_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_BINARY_H */ diff --git a/plugins/pyoida/analysis/exporter-int.h b/plugins/pyoida/analysis/exporter-int.h deleted file mode 100644 index 2498d4b..0000000 --- a/plugins/pyoida/analysis/exporter-int.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * exporter-int.h - prototypes internes pour l'équivalent Python du fichier "analysis/exporter.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_INT_H -#define _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_INT_H - - -#include - -#include - - - -/* Classe 'analysis.exporter' pour Python */ -typedef struct _py_exporter -{ - PyObject_HEAD - - GContentExporter *glib; /* Interface version GLib */ - -} py_exporter; - - -#define PY_EXPORTER(exp) ((py_exporter *)exp) - - -/* Fournit le type d'objet 'analysis.exporter' pour Python. */ -PyTypeObject *get_analysis_exporter_type(void); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_INT_H */ diff --git a/plugins/pyoida/analysis/exporter.c b/plugins/pyoida/analysis/exporter.c deleted file mode 100644 index 8c49542..0000000 --- a/plugins/pyoida/analysis/exporter.c +++ /dev/null @@ -1,284 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * exporter.c - équivalent Python du fichier "analysis/exporter.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "exporter.h" - - -#include -#include -#include - - -#include "exporter-int.h" -#include "../analysis/roptions.h" - - - - -#define PY_EXPORT_TEXT_BUFLEN 64 - - -/* Crée un nouvel objet Python de type 'py_exporter'. */ -static PyObject *py_exporter_new(PyTypeObject *, PyObject *, PyObject *); - - - - -/* Fournit le texte correspondant à un contenu rendu. */ -static PyObject *py_exporter_get_text(py_exporter *, PyObject *); - - - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'py_exporter'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_exporter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_exporter *result; /* Instance à retourner */ - - result = (py_exporter *)type->tp_alloc(type, 0); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : exporter = objet GLib existant à transposer. * -* * -* Description : Crée un nouvel objet Python de type 'py_exporter'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *py_exporter_new_from_existing(GContentExporter *exporter) -{ - py_exporter *result; /* Instance à retourner */ - PyTypeObject *type; /* Type Python à instancier */ - - result = (py_exporter *)g_object_get_data(G_OBJECT(exporter), "python_object"); - - if (result == NULL) - { - type = get_analysis_exporter_type(); - - result = (py_exporter *)type->tp_alloc(type, 0); - - result->glib = exporter; - g_object_ref(exporter); - - g_object_set_data(G_OBJECT(exporter), "python_object", result); - - } - else Py_INCREF((PyObject *)result); - - return (PyObject *)result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* args = arguments fournis à l'appel. * -* * -* Description : Fournit le texte correspondant à un contenu rendu. * -* * -* Retour : Chaîne de caractères Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_exporter_get_text(py_exporter *self, PyObject *args) -{ - PyObject *result; /* Liste à retourner */ - PyObject *roptions; /* Options de rendu jointes */ - int ret; /* Bilan de lecture des args. */ - GRenderingOptions *_roptions; /* Version GLib des options */ - int fd[2]; /* Tube pour récupérer le code */ - FILE *stream; /* Flux (ré)ouvert en écriture */ - char buffer[PY_EXPORT_TEXT_BUFLEN]; /* Tampon pour la lecture */ - ssize_t len; /* Nombre de caractères lus */ - PyObject *src; /* Source ajoutée au résultat */ - - ret = PyArg_ParseTuple(args, "O", &roptions); - if (!ret) return Py_None; - - _roptions = py_rendering_options_get_glib_instance(roptions); - - result = Py_None; - - ret = pipe2(fd, O_NONBLOCK); - //if (ret ... perror("pipe"); goto pegt_pipe_error; - - - stream = fdopen(fd[1], "w"); - if (stream == NULL) - { - perror("stream"); - goto pegt_stream_error; - } - - g_content_exporter_add_text(self->glib, _roptions, MRD_BLOCK/* FIXME*/, stream); - fflush(stream); - - do - { - memset(buffer, 0, PY_EXPORT_TEXT_BUFLEN); - len = read(fd[0], buffer, PY_EXPORT_TEXT_BUFLEN); - - src = PyString_FromString(buffer); - - if (result == Py_None) result = src; - else PyString_ConcatAndDel(&result, src); - - } - while (len > 0); - - fclose(stream); - - pegt_stream_error: - - close(fd[0]); - //close(fd[1]); - - pegt_pipe_error: - - return result; - -} - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.exporter' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_analysis_exporter_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyMethodDef py_exporter_methods[] = { - { - "get_text", (PyCFunction)py_exporter_get_text, - METH_VARARGS, - "Provide the text version of the rendered content." - }, - { NULL } - }; - - static PyGetSetDef py_exporter_getset[] = { - { NULL } - }; - - static PyTypeObject py_exporter_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.Exporter", - .tp_basicsize = sizeof(py_exporter), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA exporter interface", - - .tp_methods = py_exporter_methods, - .tp_getset = py_exporter_getset, - .tp_new = (newfunc)py_exporter_new - - }; - - if (result == NULL) result = &py_exporter_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.exporter' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_exporter_to_python_module(PyObject *module) -{ - PyTypeObject *py_exporter_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_exporter_type = get_analysis_exporter_type(); - - if (PyType_Ready(py_exporter_type) < 0) - return false; - - Py_INCREF(py_exporter_type); - ret = PyModule_AddObject(module, "Exporter", (PyObject *)py_exporter_type); - - return (ret == 0); - -} diff --git a/plugins/pyoida/analysis/exporter.h b/plugins/pyoida/analysis/exporter.h deleted file mode 100644 index 4668934..0000000 --- a/plugins/pyoida/analysis/exporter.h +++ /dev/null @@ -1,44 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * exporter.h - prototypes pour l'équivalent Python du fichier "analysis/exporter.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_H -#define _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_H - - -#include -#include - -#include - - - -/* Crée un nouvel objet Python de type 'py_exporter'. */ -PyObject *py_exporter_new_from_existing(GContentExporter *); - -/* Ajoute l'objet 'analysis.exporter' au module Python. */ -bool add_analysis_exporter_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_EXPORTER_H */ diff --git a/plugins/pyoida/analysis/line.c b/plugins/pyoida/analysis/line.c deleted file mode 100644 index fd697e2..0000000 --- a/plugins/pyoida/analysis/line.c +++ /dev/null @@ -1,793 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * line.c - équivalent Python du fichier "analysis/line.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "line.h" - - -#include "exporter-int.h" -#include "../arch/archbase.h" - - - - - - - -/* Classe 'analysis.line' pour Python */ -typedef struct _py_line -{ - py_exporter parent; /* A laisser en premier */ - - GRenderingLine *line; /* Référence GLib */ - -} py_line; - - - - -/* Crée un nouvel objet Python de type 'py_line'. */ -static PyObject *py_line_new(PyTypeObject *, PyObject *, PyObject *); - - - - - - -/* Fournit le type d'objet 'analysis.line' pour Python. */ -static PyTypeObject *get_analysis_line_type(void); - - - -/* Prépare un parcours de lignes. */ -static PyObject *py_line_get_iter(py_line *); - -/* Prépare un parcours de lignes en sens inverse. */ -static PyObject *py_line_get_riter(py_line *); - - - -/* Fournit l'adresse physique ou en mémoire d'une ligne. */ -static PyObject *py_line_get_address(py_line *, void *); - -/* Fournit le commentaire associé à la ligne s'il existe. */ -static PyObject *py_line_get_comment(py_line *, void *); - -/* Définit ou supprime un commentaire pour la ligne indiquée. */ -static int py_line_set_comment(py_line *, PyObject *, void *); - - - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Itérateur pour lignes de rendu */ -typedef struct _py_line_iter -{ - PyObject_HEAD /* A laisser en premier */ - - GRenderingLine *head; /* Liste à parcourir */ - GRenderingLine *cur; /* Point de parcours courant */ - -} py_line_iter; - - -/* Fournit le type d'objet 'analysis.LineIter' pour Python. */ -static PyTypeObject *get_analysis_line_iter_type(void); - -/* Prépare l'itérateur pour un parcours de lignes de rendu. */ -static PyObject *py_line_iter_new(GRenderingLine *); - -/* Libère la mémoire occupée par un itérateur de 'py_line'. */ -static void py_line_iter_dealloc(py_line_iter *); - -/* Fournit l'élément suivant dans un parcours de lignes. */ -static PyObject *py_line_iter_get_next(py_line_iter *); - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Itérateur pour lignes de rendu */ -typedef py_line_iter py_line_riter; - - -/* Fournit le type d'objet 'analysis.LineRevIter' pour Python. */ -static PyTypeObject *get_analysis_line_riter_type(void); - -/* Prépare l'itérateur pour un parcours de lignes de rendu. */ -static PyObject *py_line_riter_new(GRenderingLine *); - -/* Libère la mémoire occupée par un itérateur de 'py_line'. */ -static void py_line_riter_dealloc(py_line_riter *); - -/* Fournit l'élément précédant dans un parcours de lignes. */ -static PyObject *py_line_riter_get_prev(py_line_riter *); - - - - - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_line *result; /* Instance à retourner */ - - result = (py_line *)type->tp_alloc(type, 0); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : line = objet GLib existant à transposer. * -* * -* Description : Crée un nouvel objet Python de type 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *py_line_new_from_existing(GRenderingLine *line) -{ - py_line *result; /* Instance à retourner */ - PyTypeObject *type; /* Type Python à instancier */ - - result = (py_line *)g_object_get_data(G_OBJECT(line), "python_object"); - - if (result == NULL) - { - type = get_analysis_line_type(); - - result = (py_line *)type->tp_alloc(type, 0); - - PY_EXPORTER(result)->glib = G_CONTENT_EXPORTER(line); /* TODO : move me ! */ - - result->line = line; - g_object_ref(line); - - g_object_set_data(G_OBJECT(line), "python_object", result); - - } - else Py_INCREF((PyObject *)result); - - return (PyObject *)result; - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.line' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_line_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyMethodDef py_line_methods[] = { - { - "__reversed__", (PyCFunction)py_line_get_riter, - METH_NOARGS, - "Return a reverse iterator over the rendering lines." - }, - { NULL } - }; - - static PyGetSetDef py_line_getset[] = { - { - "address", - (getter)py_line_get_address, - (setter)NULL, - "Get the physical or virtual address relative to the line." - }, - { - "comment", - (getter)py_line_get_comment, - (setter)py_line_set_comment, - "Get or set a comment for the rendering line." - }, - { NULL } - }; - - static PyTypeObject py_line_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.Line", - .tp_basicsize = sizeof(py_line), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA rendering line", - - .tp_iter = (getiterfunc)py_line_get_iter, - - .tp_methods = py_line_methods, - .tp_getset = py_line_getset, - .tp_new = (newfunc)py_line_new - - }; - - if (result == NULL) - { - py_line_type.tp_base = get_analysis_exporter_type(); - result = &py_line_type; - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.line' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_line_to_python_module(PyObject *module) -{ - PyTypeObject *py_line_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_line_type = get_analysis_line_type(); - - if (PyType_Ready(py_line_type) < 0) - return false; - - Py_INCREF(py_line_type); - ret = PyModule_AddObject(module, "Line", (PyObject *)py_line_type); - - return (ret == 0); - -} - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Prépare un parcours de lignes. * -* * -* Retour : Point de départ d'un parcours. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_iter(py_line *self) -{ - return (PyObject *)py_line_iter_new(self->line); - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Prépare un parcours de lignes en sens inverse. * -* * -* Retour : Point de départ d'un parcours. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_riter(py_line *self) -{ - return (PyObject *)py_line_riter_new(self->line); - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant une ligne de rendu. * -* data = adresse non utilisée ici. * -* * -* Description : Fournit l'adresse physique ou en mémoire d'une ligne. * -* * -* Retour : Position physique ou en mémoire associée à la ligne. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_address(py_line *self, void *data) -{ - vmpa_t value; /* Adresse à convertir */ - - value = get_rendering_line_address(self->line); - - return py_vmpa_new_from_existing(value); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant une ligne de rendu. * -* data = adresse non utilisée ici. * -* * -* Description : Fournit le commentaire associé à la ligne s'il existe. * -* * -* Retour : Chaîne de caractères ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_get_comment(py_line *self, void *data) -{ - const char *comment; /* Commentaire à transmettre */ - - comment = get_rendering_line_comment(self->line); - - return Py_BuildValue("s", comment); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant des options de représentation. * -* value = nouvelle valeur affectée. * -* data = adresse non utilisée ici. * -* * -* Description : Définit ou supprime un commentaire pour la ligne indiquée. * -* * -* Retour : Bilan de la mise à jour. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_line_set_comment(py_line *self, PyObject *value, void *data) -{ - char *comment; /* Commentaire à définir */ - - comment = PyString_AsString(value); - /* FIXME : nil pour supprimer ? */ - - set_rendering_line_comment(self->line, comment); - - return 0; - -} - - - - - - - - - - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* ITERATEUR POUR LE PARCOURS DE LIGNES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.LineIter' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_line_iter_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyTypeObject py_line_iter_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.LineIter", - .tp_basicsize = sizeof(py_line_iter), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA iterator for rendering lines", - - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)py_line_iter_get_next - - }; - - if (result == NULL) result = &py_line_iter_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.LineIter' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_line_iter_to_python_module(PyObject *module) -{ - PyTypeObject *py_line_iter_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_line_iter_type = get_analysis_line_iter_type(); - - if (PyType_Ready(py_line_iter_type) < 0) - return false; - - Py_INCREF(py_line_iter_type); - ret = PyModule_AddObject(module, "Iter", (PyObject *)py_line_iter_type); - - return (ret == 0); - -} - - -/****************************************************************************** -* * -* Paramètres : head = liste à parcourir. * -* * -* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * -* * -* Retour : Instance d'itérateur prête à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_iter_new(GRenderingLine *head) -{ - py_line_iter *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - type = get_analysis_line_iter_type(); - - result = (py_line_iter *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->cur = NULL; - } - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à supprimer. * -* * -* Description : Libère la mémoire occupée par un itérateur de 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_line_iter_dealloc(py_line_iter *self) -{ -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject *)self); -#else - Py_TYPE(self)->tp_free((PyObject *)self); -#endif - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit l'élément suivant dans un parcours de lignes. * -* * -* Retour : Point suivant du parcours ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_iter_get_next(py_line_iter *self) -{ - PyObject *result; /* Elément à retourner */ - GRenderingLine *next; /* Elément réel suivant */ - - if (self->cur == NULL) next = self->head; - else next = g_rendering_line_get_next_iter(self->head, self->cur, NULL); - - if (next != NULL) - { - self->cur = next; - result = py_line_new_from_existing(next); - Py_INCREF(result); - } - else result = NULL; - - return (PyObject *)result; - -} - -/* ---------------------------------------------------------------------------------- */ -/* ITERATEUR POUR LE PARCOURS DE LIGNES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit le type d'objet 'analysis.LineRevIter' pour Python. * -* * -* Retour : Adresse du type vivant à manipuler. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *get_analysis_line_riter_type(void) -{ - static PyTypeObject *result = NULL; /* Type pour objet à retourner */ - - static PyTypeObject py_line_riter_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.LineRevIter", - .tp_basicsize = sizeof(py_line_riter), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA iterator for rendering lines", - - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)py_line_riter_get_prev - - }; - - if (result == NULL) result = &py_line_riter_type; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.LineRevIter' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_line_riter_to_python_module(PyObject *module) -{ - PyTypeObject *py_line_riter_type; /* Type défini pour Python */ - int ret; /* Bilan d'un appel */ - - py_line_riter_type = get_analysis_line_riter_type(); - - if (PyType_Ready(py_line_riter_type) < 0) - return false; - - Py_INCREF(py_line_riter_type); - ret = PyModule_AddObject(module, "RevIter", (PyObject *)py_line_riter_type); - - return (ret == 0); - -} - - -/****************************************************************************** -* * -* Paramètres : head = liste à parcourir. * -* * -* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * -* * -* Retour : Instance d'itérateur prête à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_riter_new(GRenderingLine *head) -{ - py_line_riter *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - type = get_analysis_line_riter_type(); - - result = (py_line_riter *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->cur = NULL; - } - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à supprimer. * -* * -* Description : Libère la mémoire occupée par un itérateur de 'py_line'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_line_riter_dealloc(py_line_riter *self) -{ -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject *)self); -#else - Py_TYPE(self)->tp_free((PyObject *)self); -#endif - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit l'élément précédant dans un parcours de lignes. * -* * -* Retour : Point suivant du parcours ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_riter_get_prev(py_line_riter *self) -{ - PyObject *result; /* Elément à retourner */ - GRenderingLine *prev; /* Elément réel précédant */ - - if (self->cur == NULL) prev = g_rendering_line_get_last_iter(self->head, NULL); - else prev = g_rendering_line_get_prev_iter(self->head, self->cur, NULL); - - if (prev != NULL) - { - self->cur = prev; - result = py_line_new_from_existing(prev); - Py_INCREF(result); - } - else result = NULL; - - return (PyObject *)result; - -} diff --git a/plugins/pyoida/analysis/line.h b/plugins/pyoida/analysis/line.h deleted file mode 100644 index e71596c..0000000 --- a/plugins/pyoida/analysis/line.h +++ /dev/null @@ -1,61 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * line.h - prototypes pour l'équivalent Python du fichier "analysis/line.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_LINE_H -#define _PLUGINS_PYOIDA_ANALYSIS_LINE_H - - -#include -#include - -#include - - - -/* Crée un nouvel objet Python de type 'py_line'. */ -PyObject *py_line_new_from_existing(GRenderingLine *); - -/* Ajoute l'objet 'analysis.line' au module Python. */ -bool add_analysis_line_to_python_module(PyObject *); - - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Ajoute l'objet 'analysis.LineIter' au module Python. */ -bool add_analysis_line_iter_to_python_module(PyObject *); - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Ajoute l'objet 'analysis.LineRevIter' au module Python. */ -bool add_analysis_line_riter_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_LINE_H */ diff --git a/plugins/pyoida/analysis/module.c b/plugins/pyoida/analysis/module.c deleted file mode 100644 index 8f07002..0000000 --- a/plugins/pyoida/analysis/module.c +++ /dev/null @@ -1,76 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire analysis en tant que module - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "module.h" - - -#include "binary.h" -#include "exporter.h" -#include "line.h" -#include "roptions.h" - - - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'analysis' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_module_to_python_module(PyObject *super) -{ - bool result; - PyObject *module; - int ret; /* Bilan d'un appel */ - - static PyMethodDef py_analysis_methods[] = { - { NULL } - }; - - module = Py_InitModule("pyoida.analysis", py_analysis_methods); - if (module == NULL) return false; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "pyoida.analysis", module); - - result = (ret != 0); - - result &= add_analysis_binary_to_python_module(module); - result &= add_analysis_exporter_to_python_module(module); - result &= add_analysis_line_to_python_module(module); - result &= add_analysis_line_iter_to_python_module(module); - result &= add_analysis_line_riter_to_python_module(module); - result &= add_analysis_roptions_to_python_module(module); - - return result; - -} diff --git a/plugins/pyoida/analysis/module.h b/plugins/pyoida/analysis/module.h deleted file mode 100644 index a8bd329..0000000 --- a/plugins/pyoida/analysis/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire analysis en tant que module - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_MODULE_H -#define _PLUGINS_PYOIDA_ANALYSIS_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'analysis' au module Python. */ -bool add_analysis_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_MODULE_H */ diff --git a/plugins/pyoida/analysis/py_binary.c b/plugins/pyoida/analysis/py_binary.c deleted file mode 100644 index 04d4881..0000000 --- a/plugins/pyoida/analysis/py_binary.c +++ /dev/null @@ -1,363 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_binary.c - intermédiaire des binaires pour Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "py_binary.h" - -#include - - - -#include "py_line.h" - - - -typedef struct { - PyObject_HEAD - - GOpenidaBinary *binary; /* Instance réelle rattachée */ - -} pybinary; - - -#define _(str) str - - - - - -/* Fournit la description du type 'binary' pour Python. */ -PyTypeObject *pybinary_get_type(void); - - - - -/* Fournit les lignes de rendu associé pour Python. */ -static PyObject *pybinary_get_lines(pybinary *); - - - - - - - -static void -pybinary_dealloc(pybinary* self) -{ -#if 0 - Py_XDECREF(self->first); - Py_XDECREF(self->last); -#endif - - //printf("dealloc\n"); - -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject*)self); -#else - Py_TYPE(self)->tp_free((PyObject*)self); -#endif - - //printf("dealloc::end\n"); - -} - -static PyObject * -pybinary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - pybinary *self; - - - printf("creating a new binary\n"); - - self = (pybinary *)type->tp_alloc(type, 0); - if (self != NULL) { -#if 0 - self->first = PyString_FromString("");//PyUnicode_FromString(""); - if (self->first == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->last = PyString_FromString("");//PyUnicode_FromString(""); - if (self->last == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->number = 0; -#endif - } - - return (PyObject *)self; -} - - -/****************************************************************************** -* * -* Paramètres : binary = modèle à représenter en Python. * -* * -* Description : Initialise le greffon permettant l'usage de Python. * -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *pybinary_new_from_existing(GOpenidaBinary *binary) -{ - pybinary *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - printf("EXISTING :: %p\n", binary); - - type = pybinary_get_type(); - - result = (pybinary *)type->tp_alloc(type, 0); - - if (result != NULL) - result->binary = binary; - - return (PyObject *)result; - -} - - - - -static int -pybinary_init(pybinary *self, PyObject *args, PyObject *kwds) -{ -#if 0 - PyObject *first=NULL, *last=NULL, *tmp; - - static char *kwlist[] = {"first", "last", "number", NULL}; - - printf("pybinary_init\n"); - - if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, - &first, &last, - &self->number)) - return -1; - - if (first) { - tmp = self->first; - Py_INCREF(first); - self->first = first; - Py_DECREF(tmp); - } - - if (last) { - tmp = self->last; - Py_INCREF(last); - self->last = last; - Py_DECREF(tmp); - } -#endif - return 0; -} - - - - - - - -static PyMemberDef pybinary_members[] = { -#if 0 - {"number", T_INT, offsetof(pybinary, number), 0, - "noddy number"}, -#endif - {NULL} /* Sentinel */ -}; - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit les lignes de rendu associé pour Python. * -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pybinary_get_lines(pybinary *self) -{ - PyObject *result; /* Liste à retourner */ - GRenderingLine *lines; /* Liste récupérée à convertir */ - - lines = g_openida_binary_get_lines(self->binary); - - result = pyline_new_from_existing(lines, lines); - - return result; - -} - - - - -#if 0 -static PyObject * -pybinary_name(pybinary* self) -{ - static PyObject *format = NULL; - PyObject *args, *result; - - if (format == NULL) { - format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); - if (format == NULL) - return NULL; - } - - args = Py_BuildValue("OO", self->first, self->last); - if (args == NULL) - return NULL; - - result = PyUnicode_Format(format, args); - Py_DECREF(args); - - return result; -} -#endif - -static PyMethodDef pybinary_methods[] = { -#if 0 - {"name", (PyCFunction)pybinary_name, METH_NOARGS, - "Return the name, combining the first and last name" - }, -#endif - { "lines", (PyCFunction)pybinary_get_lines, METH_NOARGS, - "Provide a list of associated rendering lines." - }, - {NULL} /* Sentinel */ -}; - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit la description du type 'binary' pour Python. * -* * -* Retour : Adresse de la description du type 'binary'. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *pybinary_get_type(void) -{ - static PyTypeObject result = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /*ob_size*/ -#endif - - "noddy.pybinary", /* tp_name */ - sizeof(pybinary), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pybinary_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved / tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "pybinary objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - pybinary_methods, /* tp_methods */ - pybinary_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pybinary_init, /* tp_init */ - 0, /* tp_alloc */ - pybinary_new, /* tp_new */ - }; - - return &result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'binary' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_binary_to_python_module(PyObject *module) -{ - int ret; /* Bilan d'un appel */ - - if (PyType_Ready(pybinary_get_type()) < 0) - return false; - - printf("Adding binary type\n"); - - - - Py_INCREF(pybinary_get_type()); - PyModule_AddObject(module, "binary", (PyObject *)pybinary_get_type()); - - - return true; /* FIXME */ - - -} diff --git a/plugins/pyoida/analysis/py_binary.h b/plugins/pyoida/analysis/py_binary.h deleted file mode 100644 index f87d2a5..0000000 --- a/plugins/pyoida/analysis/py_binary.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_binary.h - prototypes pour l'intermédiaire des binaires pour Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_PY_BINARY_H -#define _PLUGINS_PYOIDA_PY_BINARY_H - - -#include -#include - - -#include "../../../src/analysis/binary.h" - - - -/* Initialise le greffon permettant l'usage de Python. */ -PyObject *pybinary_new_from_existing(GOpenidaBinary *); - -/* Ajoute l'objet 'binary' au module Python. */ -bool add_binary_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_PY_BINARY_H */ diff --git a/plugins/pyoida/analysis/py_line-int.h b/plugins/pyoida/analysis/py_line-int.h deleted file mode 100644 index 408eae8..0000000 --- a/plugins/pyoida/analysis/py_line-int.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line.h - prototypes internes pour les lignes de représentation en Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_PY_LINE_INT_H -#define _PLUGINS_PYOIDA_PY_LINE_INT_H - - -#include "py_line.h" - - - -typedef struct { - PyObject_HEAD - - GRenderingLine *head; - - GRenderingLine *line; /* Instance réelle rattachée */ - - vmpa_t address; /* Adresse mise en cache */ - -} PyLine; - - -/* Fournit la description du type 'PyLine' pour Python. */ -PyTypeObject *pyline_get_type(void); - -/* Initialise le greffon permettant l'usage de Python. */ -void pyline_init_from_existing(PyLine *, GRenderingLine *, GRenderingLine *); - - - -#endif /* _PLUGINS_PYOIDA_PY_LINE_INT_H */ diff --git a/plugins/pyoida/analysis/py_line.c b/plugins/pyoida/analysis/py_line.c deleted file mode 100644 index e981dbe..0000000 --- a/plugins/pyoida/analysis/py_line.c +++ /dev/null @@ -1,606 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line.c - intermédiaire des lignes de représentation pour Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "py_line.h" - -#include - - - -#include "../../../src/analysis/line_code.h" - - -#include "py_line-int.h" -#include "py_line_code.h" - - - - - -#define _(str) str - - - - - - - -/* Prépare un parcours de lignes. */ -static PyObject *pyline_get_iter(PyLine *); - - - - - -/* ---------------------- ITERATEUR POUR LE PARCOURS DE LIGNES ---------------------- */ - - -/* Itérateur pour lignes de rendu */ -typedef struct _PyLineIter -{ - PyObject_HEAD /* A laisser en premier */ - - GRenderingLine *head; /* Liste à parcourir */ - GRenderingLine *cur; /* Point de parcours courant */ - -} PyLineIter; - - -/* Fournit la description de l'itérateur 'PyLine' pour Python. */ -static PyTypeObject *pylineiter_get_type(void); - -/* Prépare l'itérateur pour un parcours de lignes de rendu. */ -static PyObject *pylineiter_new(GRenderingLine *); - -/* Libère la mémoire occupée par un itérateur de 'PyLine'. */ -static void pylineiter_dealloc(PyLineIter *); - -/* Fournit l'élément suivant dans un parcours de lignes. */ -static PyObject *pylineiter_get_next(PyLineIter *); - - - - -/* ---------------------- EQUIVALENT PYTHON DES LIGNES DE CODE ---------------------- */ - - -/* Représentation Python d'une ligne de code */ -typedef struct _PyCodeLine -{ - PyLine base; /* A laisser en premier */ - -} PyCodeLine; - - - - - - - - - - - -static void -pyline_dealloc(PyLine *self) -{ -#if 0 - Py_XDECREF(self->first); - Py_XDECREF(self->last); -#endif - - //printf("dealloc\n"); - - - g_object_set_data(G_OBJECT(self->line), "pyline", NULL); - - -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject*)self); -#else - Py_TYPE(self)->tp_free((PyObject*)self); -#endif - - //printf("dealloc::end\n"); - -} - -static PyObject * -pyline_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyLine *self; - - - printf("creating a new line\n"); - - self = (PyLine *)type->tp_alloc(type, 0); - if (self != NULL) { -#if 0 - self->first = PyString_FromString("");//PyUnicode_FromString(""); - if (self->first == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->last = PyString_FromString("");//PyUnicode_FromString(""); - if (self->last == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->number = 0; -#endif - } - - return (PyObject *)self; -} - - -/****************************************************************************** -* * -* Paramètres : head = ???? * -* line = modèle à représenter en Python. * -* * -* Description : Initialise le greffon permettant l'usage de Python. * -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *pyline_new_from_existing(GRenderingLine *head, GRenderingLine *line) -{ - PyLine *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - result = (PyLine *)g_object_get_data(G_OBJECT(line), "pyline"); - - if (result == NULL) - { - if (G_IS_CODE_LINE(line)) - result = pycodeline_new_from_existing(head, line); - - else - { - type = pyline_get_type(); - - result = (PyLine *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->line = line; - - g_object_set_data(G_OBJECT(line), "pyline", result); - - } - - } - - } - - return (PyObject *)result; - -} - - - - -static int -pyline_init(PyLine *self, PyObject *args, PyObject *kwds) -{ -#if 0 - PyObject *first=NULL, *last=NULL, *tmp; - - static char *kwlist[] = {"first", "last", "number", NULL}; - - printf("pyline_init\n"); - - if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, - &first, &last, - &self->number)) - return -1; - - if (first) { - tmp = self->first; - Py_INCREF(first); - self->first = first; - Py_DECREF(tmp); - } - - if (last) { - tmp = self->last; - Py_INCREF(last); - self->last = last; - Py_DECREF(tmp); - } -#endif - return 0; -} - - - -/****************************************************************************** -* * -* Paramètres : self = instance à initialiser. * -* head = ???? * -* line = modèle à représenter en Python. * -* * -* Description : Initialise le greffon permettant l'usage de Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void pyline_init_from_existing(PyLine *self, GRenderingLine *head, GRenderingLine *line) -{ - self->head = head; - self->line = line; - - self->address = get_rendering_line_address(self->line); - -} - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Prépare un parcours de lignes. * -* * -* Retour : Point de départ d'un parcours. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pyline_get_iter(PyLine *self) -{ - return (PyObject *)pylineiter_new(self->head); - -} - - - - - - -#if 0 -static PyObject * -pyline_name(pyline* self) -{ - static PyObject *format = NULL; - PyObject *args, *result; - - if (format == NULL) { - format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); - if (format == NULL) - return NULL; - } - - args = Py_BuildValue("OO", self->first, self->last); - if (args == NULL) - return NULL; - - result = PyUnicode_Format(format, args); - Py_DECREF(args); - - return result; -} -#endif - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit la description du type 'PyLine' pour Python. * -* * -* Retour : Adresse de la description du type 'line'. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *pyline_get_type(void) -{ - - static PyMethodDef pyline_methods[] = { -#if 0 - {"name", (PyCFunction)pyline_name, METH_NOARGS, - "Return the name, combining the first and last name" - }, -#endif - { NULL } -}; - - - static PyMemberDef pyline_members[] = { - { "address", T_ULONGLONG, offsetof(PyLine, address), READONLY, - "physical or virtual address relative to the line." }, - { NULL } -}; - - - static PyTypeObject result = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /*ob_size*/ -#endif - - "noddy.pyline", /* tp_name */ - sizeof(PyLine), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pyline_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved / tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "PyLine objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)pyline_get_iter, /* tp_iter */ - 0, /* tp_iternext */ - pyline_methods, /* tp_methods */ - pyline_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pyline_init, /* tp_init */ - 0, /* tp_alloc */ - pyline_new, /* tp_new */ - }; - - return &result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'line' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_line_to_python_module(PyObject *module) -{ - int ret; /* Bilan d'un appel */ - - if (PyType_Ready(pyline_get_type()) < 0) - return false; - - if (PyType_Ready(pylineiter_get_type()) < 0) - return false; - - - - - printf("Adding line type\n"); - - - - Py_INCREF(pyline_get_type()); - PyModule_AddObject(module, "line", (PyObject *)pyline_get_type()); - - Py_INCREF(pylineiter_get_type()); - PyModule_AddObject(module, "lineiter", (PyObject *)pylineiter_get_type()); - - - return true; /* FIXME */ - - -} - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* ITERATEUR POUR LE PARCOURS DE LIGNES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit la description de l'itérateur 'PyLine' pour Python. * -* * -* Retour : Adresse de la description du type 'PyLineIter'. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *pylineiter_get_type(void) -{ - static PyTypeObject result = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /* ob_size */ -#endif - - "pyoida.analysis.PyLineIter", /* tp_name */ - sizeof(PyLineIter), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pylineiter_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved / tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "PyLineIter objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ - (iternextfunc)pylineiter_get_next, /* tp_iternext */ - 0, /* tp_methods */ - }; - - return &result; - -} - - -/****************************************************************************** -* * -* Paramètres : head = liste à parcourir. * -* * -* Description : Prépare l'itérateur pour un parcours de lignes de rendu. * -* * -* Retour : Instance d'itérateur prête à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pylineiter_new(GRenderingLine *head) -{ - PyLineIter *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - type = pylineiter_get_type(); - - result = (PyLineIter *)type->tp_alloc(type, 0); - - if (result != NULL) - { - result->head = head; - result->cur = NULL; - } - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à supprimer. * -* * -* Description : Libère la mémoire occupée par un itérateur de 'PyLine'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void pylineiter_dealloc(PyLineIter *self) -{ -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject *)self); -#else - Py_TYPE(self)->tp_free((PyObject *)self); -#endif - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance manipulée à traiter. * -* * -* Description : Fournit l'élément suivant dans un parcours de lignes. * -* * -* Retour : Point suivant du parcours ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pylineiter_get_next(PyLineIter *self) -{ - PyObject *result; /* Elément à retourner */ - GRenderingLine *next; /* Elément réel suivant */ - - if (self->cur == NULL) next = self->head; - else next = g_rendering_line_get_next_iter(self->head, self->cur, NULL); - - if (next != NULL) - { - self->cur = next; - result = pyline_new_from_existing(self->head, next); - } - - else result = NULL; - - return (PyObject *)result; - -} diff --git a/plugins/pyoida/analysis/py_line.h b/plugins/pyoida/analysis/py_line.h deleted file mode 100644 index 681e13b..0000000 --- a/plugins/pyoida/analysis/py_line.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line.h - prototypes pour l'intermédiaire des lignes de représentation pour Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_PY_LINE_H -#define _PLUGINS_PYOIDA_PY_LINE_H - - -#include -#include - - -#include "../../../src/analysis/line.h" - - - -/* Initialise le greffon permettant l'usage de Python. */ -PyObject *pyline_new_from_existing(GRenderingLine *, GRenderingLine *); - -/* Ajoute l'objet 'line' au module Python. */ -bool add_line_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_PY_LINE_H */ diff --git a/plugins/pyoida/analysis/py_line_code.c b/plugins/pyoida/analysis/py_line_code.c deleted file mode 100644 index 26fe513..0000000 --- a/plugins/pyoida/analysis/py_line_code.c +++ /dev/null @@ -1,281 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line_code.h - prototypes pour l'intermédiaire des lignes de code pour Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "py_line_code.h" - - -#include "py_line-int.h" - - - -typedef struct { - - PyLine base; /* Classe dérivée */ - -} PyCodeLine; - - - - -/* Fournit la description du type 'PyCodeLine' pour Python. */ -static PyTypeObject *pycodeline_get_type(void); - - - - -static int -pycodeline_init(PyCodeLine *self, PyObject *args, PyObject *kwds); - -static PyObject * -pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds); - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit la description du type 'PyCodeLine' pour Python. * -* * -* Retour : Adresse de la description du type 'PyCodeLine'. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyTypeObject *pycodeline_get_type(void) -{ - static PyMethodDef pycodeline_methods[] = { -#if 0 - {"name", (PyCFunction)pyline_name, METH_NOARGS, - "Return the name, combining the first and last name" - }, -#endif - { NULL } -}; - - static PyTypeObject result = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /*ob_size*/ -#endif - - "pyoida.analysis.PyCodeLine", /* tp_name */ - sizeof(PyCodeLine), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved / tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "pycodeline objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - pycodeline_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pycodeline_init, /* tp_init */ - 0, /* tp_alloc */ - pycodeline_new, /* tp_new */ - }; - - return &result; - -} - - - - -static int -pycodeline_init(PyCodeLine *self, PyObject *args, PyObject *kwds) -{ -#if 0 - PyObject *first=NULL, *last=NULL, *tmp; - - static char *kwlist[] = {"first", "last", "number", NULL}; - - printf("pycodeline_init\n"); - - if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, - &first, &last, - &self->number)) - return -1; - - if (first) { - tmp = self->first; - Py_INCREF(first); - self->first = first; - Py_DECREF(tmp); - } - - if (last) { - tmp = self->last; - Py_INCREF(last); - self->last = last; - Py_DECREF(tmp); - } -#endif - return 0; -} - - - - - -static PyObject * -pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyCodeLine *self; - - - printf("creating a new line\n"); - - self = (PyCodeLine *)type->tp_alloc(type, 0); - if (self != NULL) { -#if 0 - self->first = PyString_FromString("");//PyUnicode_FromString(""); - if (self->first == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->last = PyString_FromString("");//PyUnicode_FromString(""); - if (self->last == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->number = 0; -#endif - } - - return (PyObject *)self; -} - - - - - -/****************************************************************************** -* * -* Paramètres : head = ???? * -* line = modèle à représenter en Python. * -* * -* Description : Initialise le greffon permettant l'usage de Python. * -* * -* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *pycodeline_new_from_existing(GRenderingLine *head, GCodeLine *line) -{ - PyCodeLine *result; /* Nouvelle instance à renvoyer*/ - PyTypeObject *type; /* Type d'objet à créer */ - - result = (PyCodeLine *)g_object_get_data(G_OBJECT(line), "pyobject"); - - if (result == NULL) - { - type = pycodeline_get_type(); - - result = (PyCodeLine *)type->tp_alloc(type, 0); - - if (result != NULL) - { - pyline_init_from_existing((PyLine *)result, head, line); - - g_object_set_data(G_OBJECT(line), "pyobject", result); - - } - - } - - return (PyObject *)result; - -} - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'line' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_pycodeline_to_python_module(PyObject *module) -{ - - - pycodeline_get_type()->tp_base = pyline_get_type(); - if (PyType_Ready(pycodeline_get_type()) < 0) - return false; - - - Py_INCREF(pycodeline_get_type()); - PyModule_AddObject(module, "codeline", (PyObject *)pycodeline_get_type()); - - - - return true; /* FIXME */ - -} diff --git a/plugins/pyoida/analysis/py_line_code.h b/plugins/pyoida/analysis/py_line_code.h deleted file mode 100644 index 8a67b44..0000000 --- a/plugins/pyoida/analysis/py_line_code.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_line_code.h - prototypes pour l'intermédiaire des lignes de code pour Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_PY_LINE_CODE_H -#define _PLUGINS_PYOIDA_PY_LINE_CODE_H - - -#include -#include - - -#include "../../../src/analysis/line_code.h" - - - -/* Initialise le greffon permettant l'usage de Python. */ -PyObject *pycodeline_new_from_existing(GRenderingLine *, GCodeLine *); - -/* Ajoute l'objet 'PyCodeLine' au module Python. */ -bool add_pycodeline_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_PY_LINE_CODE_H */ diff --git a/plugins/pyoida/analysis/roptions.c b/plugins/pyoida/analysis/roptions.c deleted file mode 100644 index 57a4f52..0000000 --- a/plugins/pyoida/analysis/roptions.c +++ /dev/null @@ -1,272 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * roptions.c - équivalent Python du fichier "analysis/roptions.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "roptions.h" - - -#include "../format/executable.h" - - - - -/* Classe 'analysis.roptions' pour Python */ -typedef struct _py_rendering_options -{ - PyObject_HEAD - - GRenderingOptions *glib; /* Options réelles manipulées */ - -} py_rendering_options; - - - - -/* Crée un nouvel objet Python de type 'py_rendering_options'. */ -static PyObject *py_rendering_options_new(PyTypeObject *, PyObject *, PyObject *); - - - -/* Indique si les adresses des instructions sont à afficher. */ -static PyObject *py_rendering_options_get_show_address(PyObject *, void *); - -/* Affiche (ou non) les adresses des instructions. */ -static int py_rendering_options_set_show_address(PyObject *, PyObject *, void *); - - - - -/* Affiche (ou non) le code des instructions. */ -static PyObject *py_rendering_options_show_code(PyObject *, PyObject *); - - - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'py_rendering_options'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_rendering_options_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_rendering_options *result; /* Instance à retourner */ - PyObject *executable; /* Format d'exécutable joint */ - int ret; /* Bilan de lecture des args. */ - GExeFormat *_executable; /* Version GLib du format */ - - ret = PyArg_ParseTuple(args, "O", &executable); - if (!ret) return Py_None; - - result = (py_rendering_options *)type->tp_alloc(type, 0); - - _executable = py_executable_get_glib_instance(executable); - - g_object_ref(G_OBJECT(_executable)); - result->glib = g_rendering_options_new(_executable); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : roptions = instance Python dont la référence est à donner. * -* * -* Description : Fournit l'instance GLib d'une instance Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -GRenderingOptions *py_rendering_options_get_glib_instance(PyObject *roptions) -{ - return ((py_rendering_options *)roptions)->glib; - -} - - - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant des options de représentation. * -* data = adresse non utilisée ici. * -* * -* Description : Indique si les adresses des instructions sont à afficher. * -* * -* Retour : Valeur booléenne indiquant le statut d'une option. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_rendering_options_get_show_address(PyObject *self, void *data) -{ - - printf(" -->> get address\n"); - - return Py_BuildValue("i", true); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe présentant des options de représentation. * -* value = nouvelle valeur affectée. * -* data = adresse non utilisée ici. * -* * -* Description : Affiche (ou non) les adresses des instructions. * -* * -* Retour : Bilan de la mise à jour. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_rendering_options_set_show_address(PyObject *self, PyObject *value, void *data) -{ - printf(" -->> set address\n"); - - return 0; - -} - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * -* args = arguments fournis à l'appel. * -* * -* Description : Affiche (ou non) le code des instructions. * -* * -* Retour : Rien en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_rendering_options_show_code(PyObject *self, PyObject *args) -{ - int state; /* Nouveau statut d'affichage */ - - if (!PyArg_ParseTuple(args, "i", &state)) - return NULL; - - - - - printf("show code :: %d\n", state); - - return Py_None; - -} - - - - - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'analysis.roptions' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_roptions_to_python_module(PyObject *module) -{ - int ret; /* Bilan d'un appel */ - - static PyMethodDef py_rendering_options_methods[] = { - { - "show_code", (PyCFunction)py_rendering_options_show_code, - METH_VARARGS, - "Define if the binary code has to be processed or not." - }, - { NULL } - }; - - static PyGetSetDef py_rendering_options_getset[] = { - { - "show_address", - (getter)py_rendering_options_get_show_address, - (setter)py_rendering_options_set_show_address, - "Define or retrieve if the instruction address need to be shown." - }, - { NULL } - }; - - static PyTypeObject py_rendering_options_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pyoida.analysis.RenderingOptions", - .tp_basicsize = sizeof(py_rendering_options), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyOIDA rendering options", - - .tp_methods = py_rendering_options_methods, - .tp_getset = py_rendering_options_getset, - .tp_new = (newfunc)py_rendering_options_new - - }; - - if (PyType_Ready(&py_rendering_options_type) < 0) - return false; - - Py_INCREF(&py_rendering_options_type); - ret = PyModule_AddObject(module, "RenderingOptions", (PyObject *)&py_rendering_options_type); - - return (ret == 0); - -} diff --git a/plugins/pyoida/analysis/roptions.h b/plugins/pyoida/analysis/roptions.h deleted file mode 100644 index 0897211..0000000 --- a/plugins/pyoida/analysis/roptions.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * roptions.h - prototypes pour l'équivalent Python du fichier "analysis/roptions.h" - * - * Copyright (C) 2010 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_ANALYSIS_ROPTIONS_H -#define _PLUGINS_PYOIDA_ANALYSIS_ROPTIONS_H - - -#include -#include - - -#include - - - -/* 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 deleted file mode 100644 index d0113ec..0000000 --- a/plugins/pyoida/arch/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ - -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 deleted file mode 100644 index b73e769..0000000 --- a/plugins/pyoida/arch/archbase.c +++ /dev/null @@ -1,121 +0,0 @@ - -/* 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 deleted file mode 100644 index ca621aa..0000000 --- a/plugins/pyoida/arch/archbase.h +++ /dev/null @@ -1,44 +0,0 @@ - -/* 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 -#include - -#include - - - -/* 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 deleted file mode 100644 index 59b0c2c..0000000 --- a/plugins/pyoida/arch/module.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* 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 deleted file mode 100644 index 4ae3447..0000000 --- a/plugins/pyoida/arch/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire 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 -#include - - - -/* 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 deleted file mode 100644 index 0a3fe95..0000000 --- a/plugins/pyoida/arch/processor.c +++ /dev/null @@ -1,314 +0,0 @@ - -/* 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 deleted file mode 100644 index 032d82d..0000000 --- a/plugins/pyoida/arch/processor.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* 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 -#include - - - -/* 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/debug/Makefile.am b/plugins/pyoida/debug/Makefile.am deleted file mode 100644 index 4f01701..0000000 --- a/plugins/pyoida/debug/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ - -noinst_LTLIBRARIES = libpyoidadebug.la - -libpyoidadebug_la_SOURCES = \ - debugger.h debugger.c \ - module.h module.c - - -libpyoidadebug_la_LDFLAGS = - - -INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CPPFLAGS = - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pyoida/debug/debugger.c b/plugins/pyoida/debug/debugger.c deleted file mode 100644 index 3e42ab7..0000000 --- a/plugins/pyoida/debug/debugger.c +++ /dev/null @@ -1,275 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * debugger.c - instances Python de débogueurs - * - * Copyright (C) 2012 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 "debugger.h" - - -#include -#include - - -#include "../quirks.h" - - - -/* Fournit les identifiants de tous les threads actifs. */ -static PyObject *py_binary_debugger_list_all_threads(PyObject *, PyObject *); - -/* Fournit la pile d'exécution courante via un débogueur. */ -static PyObject *py_binary_debugger_get_frames_stack(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_binary_debugger_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - DebuggerType dtype; /* Type de débogueur à créer */ - int ret; /* Bilan de lecture des args. */ - GBinaryDebugger *debugger; /* Version GLib du format */ - - ret = PyArg_ParseTuple(args, "l", &dtype); - if (!ret) return Py_None; - - debugger = g_new_binary_debugger(dtype, NULL/* FIXME */); - - result = py_binary_debugger_from_c(debugger); - g_object_unref(debugger); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : debugger = instance existante GLib. * -* * -* Description : Crée un nouvel objet Python de type 'BinaryDebugger'. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *py_binary_debugger_from_c(GBinaryDebugger *debugger) -{ - PyObject *module; /* Module d'appartenance */ - PyTypeObject *type; /* Type Python correspondant */ - - module = PyImport_ImportModule("pyoida.debug"); - type = (PyTypeObject*)PyObject_GetAttrString(module, "BinaryDebugger"); - Py_DECREF(module); - - pychrysalide_set_instance_data(G_OBJECT(debugger), type); - - return pygobject_new(G_OBJECT(debugger)); - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un débogueur. * -* args = arguments fournis à l'appel. * -* * -* Description : Fournit les identifiants de tous les threads actifs. * -* * -* Retour : Object Python représentant le résultat de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_list_all_threads(PyObject *self, PyObject *args) -{ - PyObject *result; /* Trouvailles à retourner */ - GBinaryDebugger *debugger; /* Version native */ - char **names; /* Noms associés aux threads */ - size_t count; /* Taille de cette liste */ - pid_t *threads; /* Liste des threads actifs */ - size_t i; /* Boucle de parcours */ - PyObject *thread; /* Détails sur un thread donné */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - - threads = g_binary_debugger_list_all_threads(debugger, &names, &count); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { - thread = PyTuple_New(2); - PyTuple_SetItem(result, i, thread); - - PyTuple_SetItem(thread, 0, PyLong_FromLong(threads[i])); - PyTuple_SetItem(thread, 1, PyString_FromString(names[i])); - - free(names[i]); - - } - - if (names != NULL) - free(names); - - if (threads != NULL) - free(threads); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un débogueur. * -* args = arguments fournis à l'appel. * -* * -* Description : Fournit la pile d'exécution courante via un débogueur. * -* * -* Retour : Object Python représentant le résultat de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_get_frames_stack(PyObject *self, PyObject *args) -{ - PyObject *result; /* Trouvailles à retourner */ - GBinaryDebugger *debugger; /* Version native */ - unsigned long thread; /* Identifiant du thread visé */ - size_t count; /* Taille de cette liste */ - dbg_frame_t *frames; /* Frames courantes trouvées */ - size_t i; /* Boucle de parcours */ - PyObject *frame; /* Détails sur une frame */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - - if (!PyArg_ParseTuple(args, "k", &thread)) - return Py_None; - - frames = g_binary_debugger_get_frames_stack(debugger, thread, &count); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { - frame = PyTuple_New(1); - PyTuple_SetItem(result, i, frame); - - PyTuple_SetItem(frame, 0, PyLong_FromUnsignedLongLong(frames[i].addr)); - - } - - if (frames != NULL) - free(frames); - - return result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'pychrysalide.debug.BinaryDebugger' au module.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_binary_debugger(PyObject *module) -{ - PyObject *pygobj_mod; /* Module Python-GObject */ - int ret; /* Bilan d'un appel */ - - static PyMethodDef py_binary_debugger_methods[] = { - { - "list_all_threads", (PyCFunction)py_binary_debugger_list_all_threads, - METH_NOARGS, - "List all current active threads." - }, - { - "get_frames_stack", (PyCFunction)py_binary_debugger_get_frames_stack, - METH_VARARGS, - "Provide the current callstack using a debugger." - }, - { NULL } - }; - - static PyTypeObject py_binary_debugger_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pychrysalide.debug.BinaryDebugger", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide binary debugger", - - .tp_methods = py_binary_debugger_methods, - .tp_new = (newfunc)py_binary_debugger_new - - }; - - pygobj_mod = PyImport_ImportModule("gobject"); - if (pygobj_mod == NULL) return false; - - py_binary_debugger_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject"); - Py_DECREF(pygobj_mod); - - if (PyType_Ready(&py_binary_debugger_type) < 0) - return false; - - Py_INCREF(&py_binary_debugger_type); - ret = PyModule_AddObject(module, "BinaryDebugger", (PyObject *)&py_binary_debugger_type); - - return (ret == 0); - -} diff --git a/plugins/pyoida/debug/debugger.h b/plugins/pyoida/debug/debugger.h deleted file mode 100644 index 5e5cc21..0000000 --- a/plugins/pyoida/debug/debugger.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * debugger.h - prototypes pour les instances Python de débogueurs - * - * Copyright (C) 2012 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_DEBUG_DEBUGGER_H -#define _PLUGINS_PYOIDA_DEBUG_DEBUGGER_H - - -#include -#include - - -#include - - - -/* Crée un nouvel objet Python de type 'BinaryDebugger'. */ -PyObject *py_binary_debugger_from_c(GBinaryDebugger *debugger); - -/* Ajoute l'objet 'pychrysalide.debug.BinaryDebugger' au module. */ -bool register_python_binary_debugger(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_DEBUG_DEBUGGER_H */ diff --git a/plugins/pyoida/debug/module.c b/plugins/pyoida/debug/module.c deleted file mode 100644 index 7537dc7..0000000 --- a/plugins/pyoida/debug/module.c +++ /dev/null @@ -1,66 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire debug en tant que module - * - * Copyright (C) 2012 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 "debugger.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'debug' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_debug_module_to_python_module(PyObject *super) -{ - bool result; - PyObject *module; - int ret; /* Bilan d'un appel */ - - static PyMethodDef py_debug_methods[] = { - { NULL } - }; - - module = Py_InitModule("pyoida.debug", py_debug_methods); - if (module == NULL) return false; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "pyoida.debug", module); - - result = (ret != 0); - - result &= register_python_binary_debugger(module); - - return result; - -} diff --git a/plugins/pyoida/debug/module.h b/plugins/pyoida/debug/module.h deleted file mode 100644 index d331621..0000000 --- a/plugins/pyoida/debug/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire debug en tant que module - * - * Copyright (C) 2012 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_DEBUG_MODULE_H -#define _PLUGINS_PYOIDA_DEBUG_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'debug' au module Python. */ -bool add_debug_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_DEBUG_MODULE_H */ diff --git a/plugins/pyoida/format/Makefile.am b/plugins/pyoida/format/Makefile.am deleted file mode 100644 index 74d3e3a..0000000 --- a/plugins/pyoida/format/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ - -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 deleted file mode 100644 index 2f10f71..0000000 --- a/plugins/pyoida/format/executable.c +++ /dev/null @@ -1,223 +0,0 @@ - -/* 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 deleted file mode 100644 index 577d1f9..0000000 --- a/plugins/pyoida/format/executable.h +++ /dev/null @@ -1,47 +0,0 @@ - -/* 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 -#include - -#include - - - -/* 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 deleted file mode 100644 index 1f15d50..0000000 --- a/plugins/pyoida/format/module.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* 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 deleted file mode 100644 index 4aa95cf..0000000 --- a/plugins/pyoida/format/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire 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 -#include - - - -/* 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/linsyscalls/oidapgi.py b/plugins/pyoida/linsyscalls/oidapgi.py deleted file mode 100755 index dd4e010..0000000 --- a/plugins/pyoida/linsyscalls/oidapgi.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python - -import pyoida -#import oidaline -from pyoida import Noddy - - -class OpenIDAPlugin: - """A simple example class""" - - - - - -if __name__ == "__main__": - print "OpenIDA PlugIn" - - - print "Hello World\n", - - pyoida.system("ls -lh") - - test = Noddy("first", "last") - - print test.name() - - #oidaline.echo() - diff --git a/plugins/pyoida/plugin.c b/plugins/pyoida/plugin.c deleted file mode 100644 index 64cf013..0000000 --- a/plugins/pyoida/plugin.c +++ /dev/null @@ -1,865 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * plugin.c - interactions avec un greffon Python - * - * Copyright (C) 2010-2012 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" -#include "debug/debugger.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é */ - PyObject *instance; /* Instance Python du greffon */ - -}; - - -/* 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 *); - -/* Indique l'utilité pratique du greffon. */ -static PluginAction g_python_plugin_get_action(const GPythonPlugin *); - -/* Indentifie un format à associer à un contenu binaire. */ -static MatchingFormatAction g_python_plugin_is_matching(const GPythonPlugin *, char **, bin_t **, off_t *); - -/* Exécute une action définie sur un binaire chargé. */ -static bool g_python_plugin_execute(GPythonPlugin *, GOpenidaBinary *, PluginAction); - - -/* Exécute une action relative à un débogueur. */ -static bool g_python_plugin_handle_debugger(const GPythonPlugin *, GBinaryDebugger *, 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 *); - -/* Définit le comportement par défaut d'un greffon Python. */ -static PyObject *pyoida_plugin_get_action(PyObject *, PyObject *); - -/* Définit l'issue de la recherche d'un format par défaut. */ -static PyObject *pyoida_plugin_is_matching(PyObject *, PyObject *); - - -/* Exécute une action relative à un débogueur. */ -static PyObject *pyoida_plugin_handle_debugger(PyObject *, 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; - plugin_parent->handle_debugger = (execute_on_debugger_fc)g_python_plugin_handle_debugger; - -} - - - - -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 : modname = nom du module à charger. * -* 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 *modname, const char *filename) -{ - GPythonPlugin *result; /* Structure à retourner */ - PyObject *name; /* Chemin d'accès pour Python */ - PyObject *module; /* Script Python chargé */ - PyObject *dict; /* Dictionnaire associé */ - PyObject *class; /* Classe à instancier */ - PyObject *instance; /* Instance Python du greffon */ - -#if PY_VERSION_HEX >= 0x03000000 - name = PyUnicode_FromString(filename); -#else - name = PyString_FromString(filename); -#endif - if (name == NULL) goto gppn_bad_exit; - - module = PyImport_Import(name); - Py_DECREF(name); - - if (module == NULL) - { - PyErr_Print(); - goto gppn_bad_exit; - } - - dict = PyModule_GetDict(module); - class = PyDict_GetItemString(dict, modname); - Py_DECREF(dict); - - if (class == NULL) goto gppn_no_class; - if (!PyType_Check(class->ob_type)) goto gppn_no_class; - - instance = PyObject_CallFunction(class, NULL); - if (instance == NULL) goto gppn_no_instance; - - Py_DECREF(class); - - result = g_object_new(G_TYPE_PYTHON_PLUGIN, NULL); - - G_PLUGIN_MODULE(result)->get_action = g_python_plugin_get_action; - - G_PLUGIN_MODULE(result)->is_matching = g_python_plugin_is_matching; - - result->module = module; - result->instance = instance; - - return G_PLUGIN_MODULE(result); - - gppn_no_instance: - - Py_DECREF(class); - - gppn_no_class: - - Py_DECREF(module); - - gppn_bad_exit: - - return NULL; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon de prise en charge à utiliser. * -* * -* Description : Indique l'utilité pratique du greffon. * -* * -* Retour : Action(s) codifiée(s), PGA_NONE par défaut. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PluginAction g_python_plugin_get_action(const GPythonPlugin *plugin) -{ - PluginAction result; /* Valeur à retourner */ - PyObject *value; /* Valeur obtenue */ - - value = run_python_method(plugin->instance, "get_action", NULL); - - result = PyLong_AsLong(value); - Py_DECREF(value); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon de prise en charge à utiliser. * -* filename = éventuel nom de fichier associé ou NULL. [OUT] * -* data = données chargées. [OUT] * -* length = quantité de ces données. [OUT] * -* * -* Description : Indentifie un format à associer à un contenu binaire. * -* * -* Retour : Bilan de la recherche de correspondances. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static MatchingFormatAction g_python_plugin_is_matching(const GPythonPlugin *plugin, char **filename, bin_t **data, off_t *length) -{ - MatchingFormatAction result; /* Valeur à retourner */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Valeurs obtenues */ - PyObject *action; /* Action à faire suivre */ - PyObject *new_filename; /* Nouveau fichier */ - PyObject *new_data; /* Nouvelles données */ - char *tmp; /* Stockage avant recopie */ - - if (*filename == NULL) - return MFA_NONE; - - args = PyTuple_New(2); - - PyTuple_SetItem(args, 0, PyString_FromString(*filename)); - PyTuple_SetItem(args, 1, PyByteArray_FromStringAndSize(*data, *length)); - - value = run_python_method(plugin->instance, "is_matching", args); - - if (value != NULL && PyTuple_Check(value) && PyTuple_Size(value) == 3) - { - action = PyTuple_GetItem(value, 0); - new_filename = PyTuple_GetItem(value, 1); - new_data = PyTuple_GetItem(value, 2); - - if (action == NULL || new_filename == NULL || new_data == NULL) - goto is_matching_bad; - - if (!PyInt_Check(action) - || (new_filename != Py_None && !PyString_Check(new_filename)) - || (new_data != Py_None && !PyByteArray_Check(new_data))) - goto is_matching_bad; - - result = PyInt_AsLong(action); - if (result >= MFA_COUNT) goto is_matching_bad; - - if (result != MFA_NONE && new_data == Py_None) goto is_matching_bad; - - if (new_filename != Py_None) - *filename = strdup(PyString_AsString(new_filename)); - /** - * La suppression de la part du greffon n'est permise que - * si une prise en charge est assurée. - */ - else if (result != MFA_NONE) - *filename = NULL; - - /** - * Pareil que précédemment. - */ - if (new_data != Py_None) - { - tmp = PyByteArray_AsString(new_data); - *length = PyByteArray_Size(new_data); - - *data = (bin_t *)calloc(*length, sizeof(bin_t)); - memcpy(*data, tmp, *length * sizeof(bin_t)); - - } - - goto is_matching_ok; - - } - - is_matching_bad: - - printf("Bad result from is_matching() plugin function.\n"); - - result = MFA_NONE; - - is_matching_ok: - - Py_XDECREF(value); - Py_DECREF(args); - - return result; - -} - - - - -/****************************************************************************** -* * -* 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); - - - - - - -} - - - - - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à consulter. * -* debugger = débogueur à l'origine de l'opération. * -* action = action attendue. * -* * -* Description : Exécute une action relative à un débogueur. * -* * -* Retour : true si une action a été menée, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_python_plugin_handle_debugger(const GPythonPlugin *plugin, GBinaryDebugger *debugger, PluginAction action) -{ - bool result; /* Bilan à remonter */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Valeurs obtenues */ - - args = PyTuple_New(2); - - PyTuple_SetItem(args, 0, py_binary_debugger_from_c(debugger)); - PyTuple_SetItem(args, 1, PyInt_FromLong(action)); - - value = run_python_method(plugin->instance, "handle_debugger", args); - - result = (value == Py_True); - - Py_XDECREF(value); - Py_DECREF(args); - - return result; - -} - - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* 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_NONE", PyInt_FromLong(PGA_NONE)); - if (ret == -1) return false; - - ret = PyDict_SetItemString(dict, "PGA_FORMAT_MATCHER", PyInt_FromLong(PGA_FORMAT_MATCHER)); - if (ret == -1) return false; - - 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; - - ret = PyDict_SetItemString(dict, "PGA_DEBUGGER_ATTACH", PyInt_FromLong(PGA_DEBUGGER_ATTACH)); - if (ret == -1) return false; - - ret = PyDict_SetItemString(dict, "PGA_DEBUGGER_DETACH", PyInt_FromLong(PGA_DEBUGGER_DETACH)); - if (ret == -1) return false; - - /* PGA_FORMAT_MATCHER */ - - ret = PyDict_SetItemString(dict, "MFA_NONE", PyInt_FromLong(MFA_NONE)); - if (ret == -1) return false; - - ret = PyDict_SetItemString(dict, "MFA_MATCHED", PyInt_FromLong(MFA_MATCHED)); - if (ret == -1) return false; - - ret = PyDict_SetItemString(dict, "MFA_RELOAD", PyInt_FromLong(MFA_RELOAD)); - 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 : Définit le comportement par défaut d'un greffon Python. * -* * -* Retour : Rien en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pyoida_plugin_get_action(PyObject *self, PyObject *args) -{ - return PyInt_FromLong(PGA_NONE); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * -* args = arguments fournis à l'appel. * -* * -* Description : Définit l'issue de la recherche d'un format par défaut. * -* * -* Retour : Rien en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pyoida_plugin_is_matching(PyObject *self, PyObject *args) -{ - PyObject *result; /* Liste à retourner */ - - result = PyTuple_New(3); - - PyTuple_SetItem(result, 0, PyInt_FromLong(MFA_NONE)); - PyTuple_SetItem(result, 1, Py_None); - PyTuple_SetItem(result, 2, Py_None); - - return result; - -} - - - - -/****************************************************************************** -* * -* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * -* args = arguments fournis à l'appel. * -* * -* Description : Exécute une action relative à un débogueur. * -* * -* Retour : True en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *pyoida_plugin_handle_debugger(PyObject *self, PyObject *args) -{ - Py_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[] = { - { "get_action", (PyCFunction)pyoida_plugin_get_action, METH_NOARGS, - "Register the plugin for given actions." - }, - { "is_matching", (PyCFunction)pyoida_plugin_is_matching, METH_VARARGS, - "Define if the given file can be handled." - }, - { "handle_debugger", (PyCFunction)pyoida_plugin_handle_debugger, METH_VARARGS, - "Be notify about debugger attaching or detaching." - }, - { "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 deleted file mode 100644 index af8445d..0000000 --- a/plugins/pyoida/plugin.h +++ /dev/null @@ -1,88 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * plugin.h - prototypes pour les interactions avec un greffon Python - * - * Copyright (C) 2010-2011 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 -#include -#include - - -#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 *, 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/py_log.c b/plugins/pyoida/py_log.c deleted file mode 100644 index fde7ae5..0000000 --- a/plugins/pyoida/py_log.c +++ /dev/null @@ -1,344 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_log.c - intermédiaire du panneau de messages pour Python - * - * Copyright (C) 2009-2012 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "py_log.h" - -#include - - -#include "../../src/gui/panels/log.h" - - -typedef struct { - PyObject_HEAD - PyObject *first; - PyObject *last; - int number; -} pylog; - - -#define _(str) str - - - - -/* Définit les constantes pour les types de message. */ -bool pylog_define_constants(PyObject *); - -/* Affiche un message dans le journal des messages système. */ -PyObject *pylog_simple_message(PyObject *, PyObject *); - - - - -/****************************************************************************** -* * -* Paramètres : dict = dictionnaire à compléter. * -* * -* Description : Définit les constantes pour les types de message. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool pylog_define_constants(PyObject *dict) -{ - int ret; /* Bilan d'un ajout */ - - ret = PyDict_SetItemString(dict, "LMT_INFO", PyInt_FromLong(LMT_INFO)); - if (ret == -1) return false; - - ret = PyDict_SetItemString(dict, "LMT_BAD_BINARY", PyInt_FromLong(LMT_BAD_BINARY)); - if (ret == -1) return false; - - ret = PyDict_SetItemString(dict, "LMT_PROCESS", PyInt_FromLong(LMT_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 : Affiche un message dans le journal des messages système. * -* * -* Retour : Rien en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *pylog_simple_message(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à retourner */ - LogMessageType type; /* Espèce du message */ - const char *msg; /* Contenu du message */ - - if (!PyArg_ParseTuple(args, "is", &type, &msg)) - return NULL; - - switch (type) - { - case LMT_INFO: - case LMT_BAD_BINARY: - case LMT_PROCESS: - log_simple_message(type, msg); - result = Py_None; - break; - - default: - PyErr_SetString(PyExc_ValueError, - _("Invalid type of message")); - result = NULL; - break; - - } - - return result; - -} - - - - - - - - - - -static void -pylog_dealloc(pylog* self) -{ - Py_XDECREF(self->first); - Py_XDECREF(self->last); - - - //printf("dealloc\n"); - -#if PY_VERSION_HEX < 0x03000000 - self->ob_type->tp_free((PyObject*)self); -#else - Py_TYPE(self)->tp_free((PyObject*)self); -#endif - - //printf("dealloc::end\n"); - -} - -static PyObject * -pylog_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - pylog *self; - - self = (pylog *)type->tp_alloc(type, 0); - if (self != NULL) { - self->first = PyString_FromString("");//PyUnicode_FromString(""); - if (self->first == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->last = PyString_FromString("");//PyUnicode_FromString(""); - if (self->last == NULL) - { - Py_DECREF(self); - return NULL; - } - - self->number = 0; - } - - return (PyObject *)self; -} - -static int -pylog_init(pylog *self, PyObject *args, PyObject *kwds) -{ - PyObject *first=NULL, *last=NULL, *tmp; - - static char *kwlist[] = {"first", "last", "number", NULL}; - - printf("pylog_init\n"); - - if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSi", kwlist, - &first, &last, - &self->number)) - return -1; - - if (first) { - tmp = self->first; - Py_INCREF(first); - self->first = first; - Py_DECREF(tmp); - } - - if (last) { - tmp = self->last; - Py_INCREF(last); - self->last = last; - Py_DECREF(tmp); - } - - return 0; -} - -static PyMemberDef pylog_members[] = { - {"number", T_INT, offsetof(pylog, number), 0, - "noddy number"}, - {NULL} /* Sentinel */ -}; - - - - - - - - - - -static PyObject * -pylog_name(pylog* self) -{ - static PyObject *format = NULL; - PyObject *args, *result; - - if (format == NULL) { - format = PyString_FromString("%s %s");//PyUnicode_FromString("%s %s"); - if (format == NULL) - return NULL; - } - - args = Py_BuildValue("OO", self->first, self->last); - if (args == NULL) - return NULL; - - result = PyUnicode_Format(format, args); - Py_DECREF(args); - - return result; -} - -static PyMethodDef pylog_methods[] = { - {"name", (PyCFunction)pylog_name, METH_NOARGS, - "Return the name, combining the first and last name" - }, - { "log_simple_message", (PyCFunction)pylog_simple_message, METH_VARARGS | METH_STATIC, - "Return the name, combining the first and last name" - }, - {NULL} /* Sentinel */ -}; - - -static PyTypeObject pylog_type = { - - PyObject_HEAD_INIT(NULL) - -#if PY_VERSION_HEX < 0x03000000 - 0, /*ob_size*/ -#endif - - "noddy.pylog", /* tp_name */ - sizeof(pylog), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)pylog_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved / tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "pylog objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - pylog_methods, /* tp_methods */ - pylog_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)pylog_init, /* tp_init */ - 0, /* tp_alloc */ - pylog_new, /* tp_new */ -}; - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute l'objet 'log' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_log_to_python_module(PyObject *module) -{ - int ret; /* Bilan d'un appel */ - - if (PyType_Ready(&pylog_type) < 0) - return; - - printf("Adding log type\n"); - - - pylog_define_constants(pylog_type.tp_dict); - - - - - Py_INCREF(&pylog_type); - PyModule_AddObject(module, "logger", (PyObject *)&pylog_type); - - - return true; /* FIXME */ - - -} diff --git a/plugins/pyoida/py_log.h b/plugins/pyoida/py_log.h deleted file mode 100644 index 5274428..0000000 --- a/plugins/pyoida/py_log.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * py_log.h - prototypes pour l'intermédiaire du panneau de messages pour Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _PLUGINS_PYOIDA_PY_LOG_H -#define _PLUGINS_PYOIDA_PY_LOG_H - - -#include -#include - - - -/* Ajoute l'objet 'log' au module Python. */ -bool add_log_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_PY_LOG_H */ diff --git a/plugins/pyoida/pyoida.c b/plugins/pyoida/pyoida.c deleted file mode 100644 index f3051cc..0000000 --- a/plugins/pyoida/pyoida.c +++ /dev/null @@ -1,275 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * pyoida.c - plugin permettant des extensions en Python - * - * Copyright (C) 2009-2012 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 Foobar. If not, see . - */ - - -#include "pyoida.h" - - -#include -#include - - -#include -#include - - -#include "quirks.h" -#include "analysis/module.h" -#include "arch/module.h" -#include "debug/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; - - - -static PyObject *pyoida_get_current_binary(PyObject *self, PyObject *args) -{ - GOpenidaBinary *binary; /* Structure à copier */ - - binary = (GOpenidaBinary *)g_object_get_data(_ref, "current_binary"); - - return pybinary_new_from_existing(binary); - -} - -static PyMethodDef SpamMethods[] = { - {"current_binary", pyoida_get_current_binary, METH_NOARGS, - "Give the current analyzed binary."}, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - - - - -static PyObject *__mod; - - -/****************************************************************************** -* * -* Paramètres : ref = espace de référencement global. * -* * -* Description : Initialise le greffon permettant l'usage de Python. * -* * -* Retour : true. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool init_plugin(GObject *ref) -{ - char *paths; /* Emplacements de greffons */ - char *path; /* Chemin à fouiller */ - char *save; /* Sauvegarde pour ré-entrance */ - DIR *dir; /* Répertoire à parcourir */ - struct dirent entry; /* Elément trouvé */ - struct dirent *next; /* Prochain élément fourni */ - int ret; /* Bilan d'un appel système */ - char *filename; /* Chemin d'accès reconstruit */ - - - - - GPluginModule *plugin; - - - - printf("Init pyoida\n"); - - _ref = ref; - - - /* Définition des zones d'influence */ - - add_to_env_var("PYTHONPATH", PLUGINS_DIR G_DIR_SEPARATOR_S "python", ";"); - - paths = get_env_var("PYTHONPATH"); - - /* Intialisations Python */ - - - //return false; - - - Py_Initialize(); - - initpyoida(); - - - - /* Chargement des greffons */ - - printf("Paths :: '%s'\n", paths); - - for (path = strtok_r(paths, ";", &save); - path != NULL; - path = strtok_r(NULL, ";", &save)) - { - dir = opendir(path); - if (dir == NULL) - { - perror("opendir"); - continue; - } - - printf("CHEMIN :: '%s'\n", path); - - for (ret = readdir_r(dir, &entry, &next); - ret == 0 && next != NULL; - ret = readdir_r(dir, &entry, &next)) - { - if (entry.d_name[0] == '.') continue; - - filename = strdup(entry.d_name); - filename = stradd(filename, "."); - filename = stradd(filename, "__init__"); - - printf(" - entry :: '%s'\n", filename); - - - plugin = g_python_plugin_new(entry.d_name, filename); - - if (plugin == NULL) - printf("No suitable Python plugin found in '%s'\n", filename); /* FIXME : LOG(...) */ - else - { - printf("ok pour %s\n", filename); - add_plugin_to_main_list(plugin); - } - - free(filename); - - } - - closedir(dir); - - break; /* FIXME */ - - } - - //Py_Finalize(); - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à consulter. * -* * -* Description : Indique les opérations offertes par un greffon donné. * -* * -* Retour : Action(s) offerte(s) par le greffon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PluginAction get_plugin_action(const GPluginModule *plugin) -{ - PluginAction result; /* Combinaison à retourner */ - - result = PGA_NONE; - - - - - return result; - -} - - - - - -#if PY_VERSION_HEX >= 0x03000000 - -/* Python 3.x code */ - -static struct PyModuleDef spammodule = { - PyModuleDef_HEAD_INIT, - "pyoida", /* name of module */ - "pyoida_doc", /* module documentation, may be NULL */ - -1, /* size of per-interpreter state of the module, - or -1 if the module keeps state in global variables. */ - SpamMethods -}; - -PyMODINIT_FUNC -PyInit_pyoida(void) -{ - printf("Passage 3\n"); - (void) PyModule_Create(&spammodule); -} - -#else - -/* Python 2.x code */ - -typedef struct { - PyObject_HEAD - PyObject *md_dict; -} PyModuleObject; - - -PyMODINIT_FUNC -initpyoida(void) -{ - PyObject *module; - - pygobject_init(-1, -1, -1); - pychrysalide_init_quirks(); - - printf("Passage 2\n"); - module = Py_InitModule("pyoida", SpamMethods); - - __mod = module; - - //add_analysis_roptions_to_python_module(module); - add_analysis_module_to_python_module(module); - add_arch_module_to_python_module(module); - add_debug_module_to_python_module(module); - add_format_module_to_python_module(module); - - add_log_to_python_module(module); - add_plugin_to_python_module(module); - -} - -#endif diff --git a/plugins/pyoida/pyoida.h b/plugins/pyoida/pyoida.h deleted file mode 100644 index 736db8e..0000000 --- a/plugins/pyoida/pyoida.h +++ /dev/null @@ -1,38 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * pyoida.h - prototypes pour le plugin permettant des extensions en Python - * - * Copyright (C) 2009 Cyrille Bagard - * - * This file is part of OpenIDA. - * - * OpenIDA is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * OpenIDA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Foobar. If not, see . - */ - - -#ifndef _PLUGINS_PYOIDA_H -#define _PLUGINS_PYOIDA_H - - -#include -#include - - - -/* Initialise le greffon permettant l'usage de Python. */ -bool init_plugin(GObject *); - - - -#endif /* _PLUGINS_PYOIDA_H */ diff --git a/plugins/pyoida/quirks.c b/plugins/pyoida/quirks.c deleted file mode 100644 index 4dcae2c..0000000 --- a/plugins/pyoida/quirks.c +++ /dev/null @@ -1,148 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * quirks.c - transmission du type Python exact aux instances de PyObject - * - * Copyright (C) 2012 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 "quirks.h" - - - -#include -#include - - - - - - -/* Coordonnées insérées manuellement */ -typedef struct _PyGObjectData_fake -{ - PyTypeObject *type; /* Type précis pour Python */ - GSList *closures; /* Supports d'appel */ - -} PyGObjectData_fake; - - -/* Clef d'accès réservée */ -static GQuark pygobject_instance_data_key_fake = 0; - - - - - -static void pygobject_data_free_fake(PyGObjectData_fake *data) -{ - PyGILState_STATE state; /* Etat interne de Python */ - GSList *iter; /* Boucle de parcours */ - - state = pyglib_gil_state_ensure(); - - Py_DECREF(data->type); - - pyg_begin_allow_threads; - - for (iter = data->closures; iter; ) - { - /** - * On obtient le lien avant la libération via - * pygobject_unwatch_closure()... - */ - iter = iter->next; - - g_closure_invalidate((GClosure *)iter->data); - - } - - pyg_end_allow_threads; - - g_free(data); - - pyglib_gil_state_release(state); - -} - - - -static PyGObjectData_fake *pygobject_data_new_fake(void) -{ - PyGObjectData_fake *result; /* Instance à retourner */ - - result = g_new0(PyGObjectData_fake, 1); - - return result; - -} - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Définit les éléments immuables pour toute association. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void pychrysalide_init_quirks(void) -{ - pygobject_instance_data_key_fake = g_quark_from_static_string("PyGObject::instance-data"); - -} - - -/****************************************************************************** -* * -* Paramètres : obj = instance GLib crée en C. * -* type = type de l'objet Python correspond. * -* * -* Description : Crée l'association précise attendue par Python-GObject. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void pychrysalide_set_instance_data(GObject *obj, PyTypeObject *type) -{ - PyGObjectData_fake *data; - - data = g_object_get_qdata(obj, pygobject_instance_data_key_fake); - - if (data == NULL) - { - data = pygobject_data_new_fake(); - - data->type = type; - Py_INCREF(type); - - g_object_set_qdata_full(obj, pygobject_instance_data_key_fake, - data, (GDestroyNotify)pygobject_data_free_fake); - - } - -} diff --git a/plugins/pyoida/quirks.h b/plugins/pyoida/quirks.h deleted file mode 100644 index 70e036e..0000000 --- a/plugins/pyoida/quirks.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * quirks.h - prototypes pour la transmission du type Python exact aux instances de PyObject - * - * Copyright (C) 2012 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_QUIRKS_H -#define _PLUGINS_PYOIDA_QUIRKS_H - - -#include -#include - - - -/* Définit les éléments immuables pour toute association. */ -void pychrysalide_init_quirks(void); - -/* Crée l'association précise attendue par Python-GObject. */ -void pychrysalide_set_instance_data(GObject *, PyTypeObject *); - - - -#endif /* _PLUGINS_PYOIDA_QUIRKS_H */ diff --git a/plugins/python/apkfiles/apkfiles.py b/plugins/python/apkfiles/apkfiles.py index fe7deb8..38d0e59 100644 --- a/plugins/python/apkfiles/apkfiles.py +++ b/plugins/python/apkfiles/apkfiles.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from pyoida import Plugin +from pychrysa import Plugin import zipfile -- cgit v0.11.2-87-g4458