diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2012-03-17 20:29:47 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2012-03-17 20:29:47 (GMT) |
commit | bbad297e902022ecac9fab21c01dc109560db8eb (patch) | |
tree | 6d9703e7dda8c0a61b0a3a015be89612df3bf198 /plugins/pychrysa/pychrysa.c | |
parent | d1f5881c1f4ad53781fdadfe5ce6cac24cee3bab (diff) |
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
Diffstat (limited to 'plugins/pychrysa/pychrysa.c')
-rw-r--r-- | plugins/pychrysa/pychrysa.c | 249 |
1 files changed, 249 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. + */ + + +#include "pychrysa.h" + + +#include <dirent.h> +#include <pygobject.h> + + +#include <config.h> + + +#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 |