diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2021-02-07 20:30:07 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2021-02-07 20:30:07 (GMT) |
commit | 42540e681161aab0a1c27c66541ed5dc833ca411 (patch) | |
tree | a7a1329435252b7b1ac8981b6ab3a3abddcfe457 | |
parent | 7c17177918f1bb94be7c84ca9b839155623ff05f (diff) |
Created the right place for plugins in the Python API.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | plugins/pychrysalide/Makefile.am | 9 | ||||
-rw-r--r-- | plugins/pychrysalide/core.c | 55 | ||||
-rw-r--r-- | plugins/pychrysalide/plugins/Makefile.am | 24 | ||||
-rw-r--r-- | plugins/pychrysalide/plugins/constants.c (renamed from plugins/pychrysalide/constants.c) | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/plugins/constants.h (renamed from plugins/pychrysalide/constants.h) | 6 | ||||
-rw-r--r-- | plugins/pychrysalide/plugins/module.c | 104 | ||||
-rw-r--r-- | plugins/pychrysalide/plugins/module.h | 42 | ||||
-rw-r--r-- | plugins/pychrysalide/plugins/plugin.c (renamed from plugins/pychrysalide/plugin.c) | 13 | ||||
-rw-r--r-- | plugins/pychrysalide/plugins/plugin.h (renamed from plugins/pychrysalide/plugin.h) | 6 | ||||
-rw-r--r-- | plugins/python/abackup/plugin.py | 2 | ||||
-rw-r--r-- | plugins/python/apkfiles/apkfiles.py | 2 | ||||
-rw-r--r-- | plugins/python/cglimpse/core.py | 2 | ||||
-rw-r--r-- | plugins/python/checksec/plugin.py | 2 | ||||
-rw-r--r-- | plugins/python/liveconv/plugin.py | 2 | ||||
-rw-r--r-- | plugins/python/scripting/core.py | 2 |
16 files changed, 200 insertions, 74 deletions
diff --git a/configure.ac b/configure.ac index 1ee20a4..5f10574 100644 --- a/configure.ac +++ b/configure.ac @@ -502,6 +502,7 @@ AC_CONFIG_FILES([Makefile plugins/pychrysalide/gui/core/Makefile plugins/pychrysalide/gui/panels/Makefile plugins/pychrysalide/mangling/Makefile + plugins/pychrysalide/plugins/Makefile plugins/python/Makefile plugins/python/abackup/Makefile plugins/python/apkfiles/Makefile diff --git a/plugins/pychrysalide/Makefile.am b/plugins/pychrysalide/Makefile.am index d3b5483..b4b20ad 100644 --- a/plugins/pychrysalide/Makefile.am +++ b/plugins/pychrysalide/Makefile.am @@ -1,4 +1,6 @@ +DEFAULT_INCLUDES = -I$(top_builddir) -idirafter. + lib_LTLIBRARIES = pychrysalide.la libdir = $(pluginslibdir) @@ -6,10 +8,8 @@ libdir = $(pluginslibdir) pychrysalide_la_SOURCES = \ access.h access.c \ - constants.h constants.c \ core.h core.c \ helpers.h helpers.c \ - plugin.h plugin.c \ star.h star.c \ strenum.h strenum.c \ struct.h struct.c \ @@ -25,7 +25,8 @@ pychrysalide_la_LIBADD = \ glibext/libpychrysaglibext.la \ gtkext/libpychrysagtkext.la \ gui/libpychrysagui.la \ - mangling/libpychrysamangling.la + mangling/libpychrysamangling.la \ + plugins/libpychrysaplugins.la pychrysalide_la_LDFLAGS = \ -module -avoid-version \ @@ -43,4 +44,4 @@ AM_CPPFLAGS = $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) $(LIBGTK_CFLAGS) $(LIBX AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = analysis arch common core debug format glibext gtkext gui mangling +SUBDIRS = analysis arch common core debug format glibext gtkext gui mangling plugins diff --git a/plugins/pychrysalide/core.c b/plugins/pychrysalide/core.c index 7bc46e4..30d4259 100644 --- a/plugins/pychrysalide/core.c +++ b/plugins/pychrysalide/core.c @@ -49,7 +49,6 @@ #include "access.h" #include "helpers.h" -#include "plugin.h" #include "star.h" #include "strenum.h" #include "struct.h" @@ -63,6 +62,8 @@ #include "gtkext/module.h" #include "gui/module.h" #include "mangling/module.h" +#include "plugins/module.h" +#include "plugins/plugin.h" @@ -100,9 +101,6 @@ static bool set_version_for_gtk_namespace(const char *); /* Point de sortie pour l'initialisation de Python. */ static void PyExit_pychrysalide(void); -/* Ajoute le module 'plugins' au module Python. */ -static bool add_plugin_module_to_python_module(PyObject *); - /* Complète les chemins de recherches de Python. */ static void extend_python_path(const char *); @@ -371,50 +369,6 @@ static void PyExit_pychrysalide(void) /****************************************************************************** * * -* Paramètres : super = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'plugins' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool add_plugin_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - -#define PYCHRYSALIDE_PLUGINS_DOC \ - "Home for all plugins without another home." - - static PyModuleDef py_chrysalide_deguard_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.plugins", - .m_doc = PYCHRYSALIDE_PLUGINS_DOC, - - .m_size = -1, - - }; - - result = false; - - module = build_python_module(super, &py_chrysalide_deguard_module); - - result = (module != NULL); - - assert(result); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : - * * * * Description : Point d'entrée pour l'initialisation de Python. * @@ -514,8 +468,6 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) if (status) status = add_features_module(result); - if (status) add_plugin_module_to_python_module(result); - if (status) status = add_analysis_module(result); if (status) status = add_arch_module(result); if (status) status = add_common_module(result); @@ -526,8 +478,8 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) if (status) status = add_gtkext_module(result); if (status) status = add_gui_module(result); if (status) status = add_mangling_module(result); + if (status) status = add_plugins_module(result); - if (status) status = ensure_python_plugin_module_is_registered(); if (status) status = ensure_python_string_enum_is_registered(); if (status) status = ensure_python_py_struct_is_registered(); @@ -541,6 +493,7 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) if (status) status = populate_gtkext_module(); if (status) status = populate_gui_module(); if (status) status = populate_mangling_module(); + if (status) status = populate_plugins_module(); if (!status) { diff --git a/plugins/pychrysalide/plugins/Makefile.am b/plugins/pychrysalide/plugins/Makefile.am new file mode 100644 index 0000000..0ab8c15 --- /dev/null +++ b/plugins/pychrysalide/plugins/Makefile.am @@ -0,0 +1,24 @@ + +noinst_LTLIBRARIES = libpychrysaplugins.la + +libpychrysaplugins_la_SOURCES = \ + constants.h constants.c \ + plugin.h plugin.c \ + module.h module.c + +libpychrysaplugins_la_LIBADD = + +libpychrysaplugins_la_LDFLAGS = + + +devdir = $(includedir)/chrysalide/$(subdir) + +dev_HEADERS = $(libpychrysaplugins_la_SOURCES:%c=) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I$(top_srcdir)/src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/plugins/pychrysalide/constants.c b/plugins/pychrysalide/plugins/constants.c index 97cf43b..9de044a 100644 --- a/plugins/pychrysalide/constants.c +++ b/plugins/pychrysalide/plugins/constants.c @@ -28,7 +28,7 @@ #include <plugins/plugin-def.h> -#include "helpers.h" +#include "../helpers.h" diff --git a/plugins/pychrysalide/constants.h b/plugins/pychrysalide/plugins/constants.h index 21f9d0e..71abcff 100644 --- a/plugins/pychrysalide/constants.h +++ b/plugins/pychrysalide/plugins/constants.h @@ -22,8 +22,8 @@ */ -#ifndef _PLUGINS_PYCHRYSALIDE_CONSTANTS_H -#define _PLUGINS_PYCHRYSALIDE_CONSTANTS_H +#ifndef _PLUGINS_PYCHRYSALIDE_PLUGINS_CONSTANTS_H +#define _PLUGINS_PYCHRYSALIDE_PLUGINS_CONSTANTS_H #include <Python.h> @@ -35,4 +35,4 @@ bool define_plugin_module_constants(PyTypeObject *); -#endif /* _PLUGINS_PYCHRYSALIDE_CONSTANTS_H */ +#endif /* _PLUGINS_PYCHRYSALIDE_PLUGINS_CONSTANTS_H */ diff --git a/plugins/pychrysalide/plugins/module.c b/plugins/pychrysalide/plugins/module.c new file mode 100644 index 0000000..c38caa3 --- /dev/null +++ b/plugins/pychrysalide/plugins/module.c @@ -0,0 +1,104 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire plugins en tant que module + * + * Copyright (C) 2021 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide 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. + * + * Chrysalide 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 <assert.h> + + +#include "plugin.h" +#include "../helpers.h" + + + +/****************************************************************************** +* * +* Paramètres : super = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'plugins' à un module Python. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_plugins_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + +#define PYCHRYSALIDE_PLUGINS_DOC \ + "This module provides features to deal with plugins: the definitions" \ + " required to build new Python plugins as well as functions to" \ + " interact with existing plugins.\n" \ + "\n" \ + "The module is also the place for all plugins without another home." + + static PyModuleDef py_chrysalide_plugins_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.plugins", + .m_doc = PYCHRYSALIDE_PLUGINS_DOC, + + .m_size = -1, + + }; + + module = build_python_module(super, &py_chrysalide_plugins_module); + + result = (module != NULL); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'plugins'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool populate_plugins_module(void) +{ + bool result; /* Bilan à retourner */ + + result = true; + + if (result) result = ensure_python_plugin_module_is_registered(); + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/plugins/module.h b/plugins/pychrysalide/plugins/module.h new file mode 100644 index 0000000..e2b10b9 --- /dev/null +++ b/plugins/pychrysalide/plugins/module.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire plugins en tant que module + * + * Copyright (C) 2021 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide 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. + * + * Chrysalide 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_PYCHRYSALIDE_PLUGINS_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_PLUGINS_MODULE_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Ajoute le module 'plugins' à un module Python. */ +bool add_plugins_module(PyObject *); + +/* Intègre les objets du module 'plugins'. */ +bool populate_plugins_module(void); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_PLUGINS_MODULE_H */ diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugins/plugin.c index 88b20de..e5ee1ad 100644 --- a/plugins/pychrysalide/plugin.c +++ b/plugins/pychrysalide/plugins/plugin.c @@ -34,15 +34,16 @@ #include <common/extstr.h> #include <plugins/dt.h> +#include <plugins/plugin-int.h> #include <plugins/pglist.h> #include <plugins/self.h> -#include "access.h" #include "constants.h" -#include "core.h" -#include "helpers.h" -#include "core/constants.h" +#include "../access.h" +#include "../core.h" +#include "../helpers.h" +#include "../core/constants.h" @@ -1824,7 +1825,7 @@ PyTypeObject *get_python_plugin_module_type(void) PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pychrysalide.PluginModule", + .tp_name = "pychrysalide.plugins.PluginModule", .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, @@ -1866,7 +1867,7 @@ bool ensure_python_plugin_module_is_registered(void) if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) { - module = get_access_to_python_module("pychrysalide"); + module = get_access_to_python_module("pychrysalide.plugins"); dict = PyModule_GetDict(module); diff --git a/plugins/pychrysalide/plugin.h b/plugins/pychrysalide/plugins/plugin.h index 183ae4a..2a31cf2 100644 --- a/plugins/pychrysalide/plugin.h +++ b/plugins/pychrysalide/plugins/plugin.h @@ -22,8 +22,8 @@ */ -#ifndef _PLUGINS_PYCHRYSALIDE_PLUGIN_H -#define _PLUGINS_PYCHRYSALIDE_PLUGIN_H +#ifndef _PLUGINS_PYCHRYSALIDE_PLUGINS_PLUGIN_H +#define _PLUGINS_PYCHRYSALIDE_PLUGINS_PLUGIN_H #include <Python.h> @@ -72,4 +72,4 @@ bool ensure_python_plugin_module_is_registered(void); -#endif /* _PLUGINS_PYCHRYSALIDE_PLUGIN_H */ +#endif /* _PLUGINS_PYCHRYSALIDE_PLUGINS_PLUGIN_H */ diff --git a/plugins/python/abackup/plugin.py b/plugins/python/abackup/plugin.py index aea9a9c..a3222c9 100644 --- a/plugins/python/abackup/plugin.py +++ b/plugins/python/abackup/plugin.py @@ -23,10 +23,10 @@ import io import tarfile -from pychrysalide import PluginModule from pychrysalide import core from pychrysalide.analysis.contents import EncapsulatedContent from pychrysalide.analysis.contents import MemoryContent +from pychrysalide.plugins import PluginModule from .backup import AndroidBackup from .password import PasswordReader diff --git a/plugins/python/apkfiles/apkfiles.py b/plugins/python/apkfiles/apkfiles.py index 98d31c7..d0fe5b4 100644 --- a/plugins/python/apkfiles/apkfiles.py +++ b/plugins/python/apkfiles/apkfiles.py @@ -1,10 +1,10 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from pychrysalide import PluginModule from pychrysalide import core from pychrysalide.analysis.contents import EncapsulatedContent from pychrysalide.analysis.contents import MemoryContent +from pychrysalide.plugins import PluginModule import io import zipfile diff --git a/plugins/python/cglimpse/core.py b/plugins/python/cglimpse/core.py index 29fb535..145d41d 100644 --- a/plugins/python/cglimpse/core.py +++ b/plugins/python/cglimpse/core.py @@ -1,7 +1,7 @@ -from pychrysalide import PluginModule from pychrysalide.glibext import ConfigParam from pychrysalide.gui import core +from pychrysalide.plugins import PluginModule from .panel import CGlimpsePanel diff --git a/plugins/python/checksec/plugin.py b/plugins/python/checksec/plugin.py index 6ab213f..7471681 100644 --- a/plugins/python/checksec/plugin.py +++ b/plugins/python/checksec/plugin.py @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- from .mitigations import ElfMitigations -from pychrysalide import PluginModule from pychrysalide.core import log_message, LogMessageType from pychrysalide.format.elf import ElfFormat +from pychrysalide.plugins import PluginModule class CheckSec(PluginModule): diff --git a/plugins/python/liveconv/plugin.py b/plugins/python/liveconv/plugin.py index 8caeb17..cacdf09 100644 --- a/plugins/python/liveconv/plugin.py +++ b/plugins/python/liveconv/plugin.py @@ -1,6 +1,6 @@ -from pychrysalide import PluginModule from pychrysalide.gui import core +from pychrysalide.plugins import PluginModule from .panel import ConvPanel diff --git a/plugins/python/scripting/core.py b/plugins/python/scripting/core.py index 1b91688..ff912ed 100644 --- a/plugins/python/scripting/core.py +++ b/plugins/python/scripting/core.py @@ -2,11 +2,11 @@ from gi.repository import GLib, Gtk import os -from pychrysalide import PluginModule from pychrysalide import core from pychrysalide.gui import core as gcore from pychrysalide.gui import MenuBar from pychrysalide.gtkext import EasyGtk +from pychrysalide.plugins import PluginModule from .panel import ScriptPanel |