diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2009-04-25 16:51:41 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2009-04-25 16:51:41 (GMT) |
commit | b9977e00ff9eb6e025e86a15c858183f3f314cf5 (patch) | |
tree | eedacb236b90228d2b4c603fa9875ecaad05ee29 /src/plugins | |
parent | 216a3d0121fabd678e50ea6b4fa2447ae9b921f0 (diff) |
Saved the current work on plugins.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@59 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Makefile.am | 17 | ||||
-rw-r--r-- | src/plugins/pglist.c | 73 | ||||
-rw-r--r-- | src/plugins/pglist.h | 39 | ||||
-rw-r--r-- | src/plugins/plugin.c | 144 | ||||
-rw-r--r-- | src/plugins/plugin.h | 56 | ||||
-rw-r--r-- | src/plugins/pyoida/Makefile.am | 20 | ||||
-rwxr-xr-x | src/plugins/pyoida/linsyscalls/oidapgi.py | 28 | ||||
-rw-r--r-- | src/plugins/pyoida/py_binary.c | 358 | ||||
-rw-r--r-- | src/plugins/pyoida/py_binary.h | 45 | ||||
-rw-r--r-- | src/plugins/pyoida/py_line.c | 802 | ||||
-rw-r--r-- | src/plugins/pyoida/py_line.h | 45 | ||||
-rw-r--r-- | src/plugins/pyoida/py_log.c | 341 | ||||
-rw-r--r-- | src/plugins/pyoida/py_log.h | 39 | ||||
-rw-r--r-- | src/plugins/pyoida/pyoida.c | 131 | ||||
-rw-r--r-- | src/plugins/pyoida/pyoida.h | 38 |
15 files changed, 2176 insertions, 0 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am new file mode 100644 index 0000000..2d480bb --- /dev/null +++ b/src/plugins/Makefile.am @@ -0,0 +1,17 @@ + +lib_LIBRARIES = libplugins.a + +libplugins_a_SOURCES = \ + pglist.h pglist.c \ + plugin.h plugin.c + +libplugins_a_CFLAGS = $(AM_CFLAGS) + + +INCLUDES = $(LIBGTK_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = pyoida diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c new file mode 100644 index 0000000..8301eb3 --- /dev/null +++ b/src/plugins/pglist.c @@ -0,0 +1,73 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pglist.c - gestion de l'ensemble des greffons + * + * 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 "pglist.h" + + +#include "plugin.h" + + + +/* Propriétés de l'ensemble des greffons */ +typedef struct _plugins_list +{ + GObject *ref; /* Référencement global */ + + + + +} plugins_list; + + +/* Liste de l'ensemble des greffons */ +static plugins_list list; + + + +/****************************************************************************** +* * +* Paramètres : ref = espace de référencement global. * +* * +* Description : Procède au chargement des différents greffons trouvés. * +* * +* Retour : Toujours true (même s'il y a des erreurs de chargemet). * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool init_all_plugins(GObject *ref) +{ + GPluginModule *pg; + + list.ref = ref; + + + pg = g_plugin_module_new("/home/ocb/prog/openida.pg/src/plugins/pyoida/pyoidamodule.so", list.ref); + + printf("plug ? %p\n", pg); + + return true; + +} diff --git a/src/plugins/pglist.h b/src/plugins/pglist.h new file mode 100644 index 0000000..89abd51 --- /dev/null +++ b/src/plugins/pglist.h @@ -0,0 +1,39 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pglist.h - prototypes pour la gestion de l'ensemble des greffons + * + * 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_PGLIST_H +#define _PLUGINS_PGLIST_H + + +#include <stdbool.h> +#include <gtk/gtk.h> + + + +/* Procède au chargement des différents greffons trouvés. */ +bool init_all_plugins(GObject *); + + + +#endif /* _PLUGINS_PGLIST_H */ diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c new file mode 100644 index 0000000..f21ac02 --- /dev/null +++ b/src/plugins/plugin.c @@ -0,0 +1,144 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * plugin.h - interactions avec un greffon donné + * + * 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 "plugin.h" + + +#include <gmodule.h> +#include <stdbool.h> + + + +/* Procède à l'initialisation du greffon */ +typedef bool (* init_plugin_fc) (GObject *); + + + +/* Greffon pour OpenIDA (instance) */ +struct _GPluginModule +{ + GObject parent; /* A laisser en premier */ + + GModule *module; /* Abstration de manipulation */ + + init_plugin_fc init; /* Procédure d'initialisation */ + +}; + + +/* Greffon pour OpenIDA (classe) */ +struct _GPluginModuleClass +{ + GObjectClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe des greffons. */ +static void g_plugin_module_class_init(GPluginModuleClass *); + +/* Initialise une instance de greffon. */ +static void g_plugin_module_init(GPluginModule *); + + + +/* Indique le type définit pour un greffon. */ +G_DEFINE_TYPE(GPluginModule, g_plugin_module, G_TYPE_OBJECT); + + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des greffons. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_plugin_module_class_init(GPluginModuleClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : line = instance à initialiser. * +* * +* Description : Initialise une instance de greffon. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_plugin_module_init(GPluginModule *line) +{ + +} + + + +/****************************************************************************** +* * +* Paramètres : filename = nom du fichier à charger. * +* ref = espace de référencement global. * +* * +* Description : Crée un module pour un greffon donné. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref) +{ + GPluginModule *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL); + + + result->module = g_module_open(filename, G_MODULE_BIND_LAZY); + + + if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init)) + { + printf("Err plugin init sym\n"); + /* TODO */ + } + + + + if (!result->init(ref)) + printf("Err loading pg\n"); + + return result; + +} diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h new file mode 100644 index 0000000..6013e21 --- /dev/null +++ b/src/plugins/plugin.h @@ -0,0 +1,56 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * plugin.h - prototypes pour les interactions avec un greffon donné + * + * 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_PLUGIN_H +#define _PLUGINS_PLUGIN_H + + +#include <glib-object.h> + + + +/* Greffon pour OpenIDA (instance) */ +typedef struct _GPluginModule GPluginModule; + +/* Greffon pour OpenIDA (classe) */ +typedef struct _GPluginModuleClass GPluginModuleClass; + + +#define G_TYPE_PLUGIN_MODULE (g_plugin_module_get_type()) +#define G_PLUGIN_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PLUGIN_MODULE, GPluginModule)) +#define G_IS_PLUGIN_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PLUGIN_MODULE)) +#define G_PLUGIN_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PLUGIN_MODULE, GPluginModuleClass)) +#define G_IS_PLUGIN_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PLUGIN_MODULE)) +#define G_PLUGIN_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PLUGIN_MODULE, GPluginModuleClass)) + + +/* Indique le type définit pour un greffon. */ +GType g_plugin_module_get_type(void); + +/* Crée un module pour un greffon donné. */ +GPluginModule *g_plugin_module_new(const gchar *, GObject *); + + + +#endif /* _PLUGINS_PLUGIN_H */ diff --git a/src/plugins/pyoida/Makefile.am b/src/plugins/pyoida/Makefile.am new file mode 100644 index 0000000..4df2820 --- /dev/null +++ b/src/plugins/pyoida/Makefile.am @@ -0,0 +1,20 @@ + +lib_LTLIBRARIES = libpyoida.la + +libpyoida_la_SOURCES = \ + py_binary.h py_binary.c \ + py_line.h py_line.c \ + py_log.h py_log.c \ + pyoida.h pyoida.c + +libpyoida_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \ + -L../../panel/.libs -lpanel + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/src/plugins/pyoida/linsyscalls/oidapgi.py b/src/plugins/pyoida/linsyscalls/oidapgi.py new file mode 100755 index 0000000..dd4e010 --- /dev/null +++ b/src/plugins/pyoida/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/src/plugins/pyoida/py_binary.c b/src/plugins/pyoida/py_binary.c new file mode 100644 index 0000000..eb2a73d --- /dev/null +++ b/src/plugins/pyoida/py_binary.c @@ -0,0 +1,358 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_binary.c - intermédiaire des binaires pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_binary.h" + +#include <structmember.h> + + + +#include "py_line.h" + + + +typedef struct { + PyObject_HEAD + + openida_binary *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"); + + self->ob_type->tp_free((PyObject*)self); + //Py_TYPE(self)->tp_free((PyObject*)self); + + //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(openida_binary *binary) +{ + pybinary *result; /* Nouvelle instance à renvoyer*/ + PyTypeObject *type; /* Type d'objet à créer */ + + 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 = get_openida_binary_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/src/plugins/pyoida/py_binary.h b/src/plugins/pyoida/py_binary.h new file mode 100644 index 0000000..1b9fda4 --- /dev/null +++ b/src/plugins/pyoida/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 <Python.h> +#include <stdbool.h> + + +#include "../../analysis/binary.h" + + + +/* Initialise le greffon permettant l'usage de Python. */ +PyObject *pybinary_new_from_existing(openida_binary *); + +/* Ajoute l'objet 'binary' au module Python. */ +bool add_binary_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_BINARY_H */ diff --git a/src/plugins/pyoida/py_line.c b/src/plugins/pyoida/py_line.c new file mode 100644 index 0000000..303d155 --- /dev/null +++ b/src/plugins/pyoida/py_line.c @@ -0,0 +1,802 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_line.c - intermédiaire des lignes de représentation pour Python + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "py_line.h" + +#include <structmember.h> + + + +#include "../../analysis/line_code.h" + + + + +typedef struct { + PyObject_HEAD + + GRenderingLine *head; + + GRenderingLine *line; /* Instance réelle rattachée */ + +} pyline; + + +#define _(str) str + + + + + +/* Fournit la description du type 'line' pour Python. */ +PyTypeObject *pyline_get_type(void); + + + + +/* 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; + + +/* Fournit la description du type 'PyCodeLine' pour Python. */ +PyTypeObject *pycodeline_get_type(void); + + + +static int +pycodeline_init(pyline *self, PyObject *args, PyObject *kwds); + +static PyObject * +pycodeline_new(PyTypeObject *type, PyObject *args, PyObject *kwds); + + + +PyObject *pycodeline_new_from_existing(GRenderingLine *head, GRenderingLine *line); + + + + + + + + +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); + + + self->ob_type->tp_free((PyObject*)self); + //Py_TYPE(self)->tp_free((PyObject*)self); + + //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; +} + + + + + + + +static PyMemberDef pyline_members[] = { +#if 0 + {"number", T_INT, offsetof(pyline, number), 0, + "noddy number"}, +#endif + {NULL} /* Sentinel */ +}; + + + + + + + +/****************************************************************************** +* * +* 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) +{ + printf(" get iter -- %p\n", self->line); + + 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 + +static PyMethodDef pyline_methods[] = { +#if 0 + {"name", (PyCFunction)pyline_name, METH_NOARGS, + "Return the name, combining the first and last name" + }, +#endif + {NULL} /* Sentinel */ +}; + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'line' pour Python. * +* * +* Retour : Adresse de la description du type 'line'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *pyline_get_type(void) +{ + 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; + + pycodeline_get_type()->tp_base = pyline_get_type(); + if (PyType_Ready(pycodeline_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()); + + Py_INCREF(pycodeline_get_type()); + PyModule_AddObject(module, "codeline", (PyObject *)pycodeline_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.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) +{ + self->ob_type->tp_free((PyObject *)self); + //Py_TYPE(self)->tp_free((PyObject *)self); + +} + + +/****************************************************************************** +* * +* 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); + + printf(" next for %p is :: %p\n", self->cur, next); + + if (next != NULL) + { + self->cur = next; + result = pyline_new_from_existing(self->head, next); + } + + else result = NULL; + + return (PyObject *)result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* EQUIVALENT PYTHON DES LIGNES DE CODE */ +/* ---------------------------------------------------------------------------------- */ + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit la description du type 'PyCodeLine' pour Python. * +* * +* Retour : Adresse de la description du type 'PyCodeLine'. * +* * +* Remarques : - * +* * +******************************************************************************/ + +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} /* Sentinel */ +}; + + static PyTypeObject result = { + + PyObject_HEAD_INIT(NULL) + +#if PY_VERSION_HEX < 0x03000000 + 0, /*ob_size*/ +#endif + + "PyOIDA.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(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; +} + + + + + +static PyObject * +pycodeline_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 *pycodeline_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) + { + type = pycodeline_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; + +} diff --git a/src/plugins/pyoida/py_line.h b/src/plugins/pyoida/py_line.h new file mode 100644 index 0000000..2270de6 --- /dev/null +++ b/src/plugins/pyoida/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 <Python.h> +#include <stdbool.h> + + +#include "../../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/src/plugins/pyoida/py_log.c b/src/plugins/pyoida/py_log.c new file mode 100644 index 0000000..94be1f0 --- /dev/null +++ b/src/plugins/pyoida/py_log.c @@ -0,0 +1,341 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * py_log.c - 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 + */ + + +#include "py_log.h" + +#include <structmember.h> + + +#include "../../panel/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"); + + self->ob_type->tp_free((PyObject*)self); + //Py_TYPE(self)->tp_free((PyObject*)self); + + //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/src/plugins/pyoida/py_log.h b/src/plugins/pyoida/py_log.h new file mode 100644 index 0000000..5274428 --- /dev/null +++ b/src/plugins/pyoida/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 <Python.h> +#include <stdbool.h> + + + +/* Ajoute l'objet 'log' au module Python. */ +bool add_log_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_PY_LOG_H */ diff --git a/src/plugins/pyoida/pyoida.c b/src/plugins/pyoida/pyoida.c new file mode 100644 index 0000000..26624b2 --- /dev/null +++ b/src/plugins/pyoida/pyoida.c @@ -0,0 +1,131 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pyoida.c - 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 <http://www.gnu.org/licenses/>. + */ + + +#include "pyoida.h" + + + +#include <Python.h> + + +#include "py_binary.h" +#include "py_log.h" + + +static GObject *_ref = NULL; + + + +static PyObject *pyoida_get_current_binary(PyObject *self, PyObject *args) +{ + openida_binary *binary; /* Structure à copier */ + + binary = (openida_binary *)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 */ +}; + + + + + + + + + + + + + +/****************************************************************************** +* * +* 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) +{ + + printf("Init pyoida\n"); + + _ref = ref; + + return true; + +} + + +#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 */ + + +PyMODINIT_FUNC +initpyoida(void) +{ + PyObject *module; + + + printf("Passage 2\n"); + module = Py_InitModule("pyoida", SpamMethods); + + add_binary_to_python_module(module); + add_line_to_python_module(module); + add_log_to_python_module(module); + +} + +#endif diff --git a/src/plugins/pyoida/pyoida.h b/src/plugins/pyoida/pyoida.h new file mode 100644 index 0000000..736db8e --- /dev/null +++ b/src/plugins/pyoida/pyoida.h @@ -0,0 +1,38 @@ + +/* 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 <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_PYOIDA_H +#define _PLUGINS_PYOIDA_H + + +#include <glib-object.h> +#include <stdbool.h> + + + +/* Initialise le greffon permettant l'usage de Python. */ +bool init_plugin(GObject *); + + + +#endif /* _PLUGINS_PYOIDA_H */ |