diff options
-rw-r--r-- | ChangeLog | 98 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | plugins/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/elf/Makefile.am (renamed from src/format/elf/Makefile.am) | 16 | ||||
-rw-r--r-- | plugins/elf/core.c | 68 | ||||
-rw-r--r-- | plugins/elf/core.h (renamed from src/format/elf/helper_mips.h) | 21 | ||||
-rw-r--r-- | plugins/elf/dynamic.c (renamed from src/format/elf/dynamic.c) | 0 | ||||
-rw-r--r-- | plugins/elf/dynamic.h (renamed from src/format/elf/dynamic.h) | 0 | ||||
-rw-r--r-- | plugins/elf/elf-int.c (renamed from src/format/elf/elf-int.c) | 0 | ||||
-rw-r--r-- | plugins/elf/elf-int.h (renamed from src/format/elf/elf-int.h) | 6 | ||||
-rw-r--r-- | plugins/elf/elf.c (renamed from src/format/elf/elf.c) | 8 | ||||
-rw-r--r-- | plugins/elf/elf.h (renamed from src/format/elf/elf.h) | 4 | ||||
-rw-r--r-- | plugins/elf/elf_def.h (renamed from src/format/elf/elf_def.h) | 0 | ||||
-rw-r--r-- | plugins/elf/elf_def_arm.h (renamed from src/format/elf/elf_def_arm.h) | 0 | ||||
-rw-r--r-- | plugins/elf/helper_arm.c (renamed from src/format/elf/helper_arm.c) | 9 | ||||
-rw-r--r-- | plugins/elf/helper_arm.h (renamed from src/format/elf/helper_arm.h) | 0 | ||||
-rw-r--r-- | plugins/elf/loading.c (renamed from src/format/elf/loading.c) | 4 | ||||
-rw-r--r-- | plugins/elf/loading.h (renamed from src/format/elf/loading.h) | 4 | ||||
-rw-r--r-- | plugins/elf/program.c (renamed from src/format/elf/program.c) | 0 | ||||
-rw-r--r-- | plugins/elf/program.h (renamed from src/format/elf/program.h) | 0 | ||||
-rw-r--r-- | plugins/elf/python/Makefile.am (renamed from plugins/pychrysa/format/elf/Makefile.am) | 8 | ||||
-rw-r--r-- | plugins/elf/python/elf.c (renamed from plugins/pychrysa/format/elf/elf.c) | 22 | ||||
-rw-r--r-- | plugins/elf/python/elf.h (renamed from plugins/pychrysa/format/elf/elf.h) | 0 | ||||
-rw-r--r-- | plugins/elf/python/module.c (renamed from plugins/pychrysa/format/elf/module.c) | 17 | ||||
-rw-r--r-- | plugins/elf/python/module.h (renamed from plugins/pychrysa/format/elf/module.h) | 3 | ||||
-rw-r--r-- | plugins/elf/section.c (renamed from src/format/elf/section.c) | 0 | ||||
-rw-r--r-- | plugins/elf/section.h (renamed from src/format/elf/section.h) | 0 | ||||
-rw-r--r-- | plugins/elf/strings.c (renamed from src/format/elf/strings.c) | 4 | ||||
-rw-r--r-- | plugins/elf/strings.h (renamed from src/format/elf/strings.h) | 0 | ||||
-rw-r--r-- | plugins/elf/symbols.c (renamed from src/format/elf/symbols.c) | 77 | ||||
-rw-r--r-- | plugins/elf/symbols.h (renamed from src/format/elf/symbols.h) | 4 | ||||
-rw-r--r-- | plugins/libcsem/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/libcsem/semantic.c | 1 | ||||
-rw-r--r-- | plugins/libcsem/semantic.h | 1 | ||||
-rw-r--r-- | plugins/pychrysa/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/pychrysa/access.c | 137 | ||||
-rw-r--r-- | plugins/pychrysa/access.h | 40 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/contents/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/db/items/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/db/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/arch/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/common/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/core/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/debug/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/format/Makefile.am | 5 | ||||
-rw-r--r-- | plugins/pychrysa/format/module.c | 6 | ||||
-rw-r--r-- | plugins/pychrysa/glibext/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/gui/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/gui/panels/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/helpers.h | 6 | ||||
-rw-r--r-- | plugins/pychrysa/pychrysa.c | 9 | ||||
-rw-r--r-- | plugins/readelf/header.c | 2 | ||||
-rw-r--r-- | plugins/readelf/program.c | 2 | ||||
-rw-r--r-- | plugins/readelf/program.h | 2 | ||||
-rw-r--r-- | plugins/readelf/reader.c | 2 | ||||
-rw-r--r-- | plugins/readelf/section.c | 4 | ||||
-rw-r--r-- | plugins/readelf/section.h | 2 | ||||
-rw-r--r-- | plugins/readelf/strtab.c | 2 | ||||
-rw-r--r-- | plugins/readelf/strtab.h | 2 | ||||
-rw-r--r-- | plugins/ropgadgets/plugin.c | 3 | ||||
-rw-r--r-- | src/core/formats.c | 5 | ||||
-rw-r--r-- | src/format/Makefile.am | 3 | ||||
-rw-r--r-- | src/format/elf/helper_mips.c | 85 | ||||
-rw-r--r-- | src/format/elf/helper_x86.c | 451 | ||||
-rw-r--r-- | src/format/elf/helper_x86.h | 40 | ||||
-rw-r--r-- | src/format/format.c | 5 |
67 files changed, 498 insertions, 743 deletions
@@ -1,4 +1,98 @@ -17-08-30 Cyrille Bagard <nocbos@gmail.com> +17-10-01 Cyrille Bagard <nocbos@gmail.com> + + * configure.ac: + Add the new Makefiles from the 'plugins/elf' and 'plugins/elf/python' + directories, and remove those from the 'plugins/pychrysa/format/elf' + and 'src/format/elf' ones. + + * plugins/Makefile.am: + Add elf to SUBDIRS. + + * plugins/elf/Makefile.am: + * plugins/elf/core.c: + * plugins/elf/core.h: + New entries: define the ELF support as plugin. + + * plugins/elf/dynamic.c: + * plugins/elf/dynamic.h: + * plugins/elf/elf-int.c: + * plugins/elf/elf-int.h: + * plugins/elf/elf.c: + * plugins/elf/elf.h: + * plugins/elf/elf_def.h: + * plugins/elf/elf_def_arm.h: + * plugins/elf/helper_arm.c: + * plugins/elf/helper_arm.h: + * plugins/elf/loading.c: + * plugins/elf/loading.h: + * plugins/elf/program.c: + * plugins/elf/program.h: + Moved entries. + + * plugins/elf/python/Makefile.am: + * plugins/elf/python/elf.c: + * plugins/elf/python/elf.h: + * plugins/elf/python/module.c: + * plugins/elf/python/module.h: + New entries: support Python for the ELF format here. + + * plugins/elf/section.c: + * plugins/elf/section.h: + * plugins/elf/strings.c: + * plugins/elf/strings.h: + * plugins/elf/symbols.c: + * plugins/elf/symbols.h: + Moved entries. + + * plugins/libcsem/Makefile.am: + * plugins/libcsem/semantic.c: + * plugins/libcsem/semantic.h: + Update code. + + * plugins/pychrysa/Makefile.am: + Add the 'access.[ch]' files to pychrysalide_la_SOURCES. + + * plugins/pychrysa/access.c: + * plugins/pychrysa/access.h: + New entries: provide a direct access to Python modules to be loaded. + + * plugins/pychrysa/analysis/contents/module.c: + * plugins/pychrysa/analysis/db/items/module.c: + * plugins/pychrysa/analysis/db/module.c: + * plugins/pychrysa/analysis/module.c: + * plugins/pychrysa/arch/module.c: + * plugins/pychrysa/common/module.c: + * plugins/pychrysa/core/module.c: + * plugins/pychrysa/debug/module.c: + * plugins/pychrysa/format/Makefile.am: + * plugins/pychrysa/format/module.c: + * plugins/pychrysa/glibext/module.c: + * plugins/pychrysa/gui/module.c: + * plugins/pychrysa/gui/panels/module.c: + * plugins/pychrysa/helpers.h: + * plugins/pychrysa/pychrysa.c: + * plugins/readelf/header.c: + * plugins/readelf/program.c: + * plugins/readelf/program.h: + * plugins/readelf/reader.c: + * plugins/readelf/section.c: + * plugins/readelf/section.h: + * plugins/readelf/strtab.c: + * plugins/readelf/strtab.h: + * plugins/ropgadgets/plugin.c: + * src/core/formats.c: + * src/format/Makefile.am: + Update code. + + * src/format/elf/helper_mips.c: + * src/format/elf/helper_x86.c: + * src/format/elf/helper_x86.h: + Deleted entries. + + * src/format/format.c: + Update code. + +17-09-30 Cyrille Bagard <nocbos@gmail.com> * src/plugins/plugin-def.h: Typo. @@ -6,7 +100,7 @@ * src/plugins/plugin.c: Check the ABI version before loading plugins. -17-08-30 Cyrille Bagard <nocbos@gmail.com> +17-09-30 Cyrille Bagard <nocbos@gmail.com> * plugins/pychrysa/plugin.c: * plugins/pychrysa/pychrysa.c: diff --git a/configure.ac b/configure.ac index 98923d6..80afa2e 100644 --- a/configure.ac +++ b/configure.ac @@ -320,6 +320,8 @@ AC_CONFIG_FILES([Makefile pixmaps/Makefile plugins/Makefile plugins/devdbg/Makefile + plugins/elf/Makefile + plugins/elf/python/Makefile plugins/fmtp/Makefile plugins/libcsem/Makefile plugins/mobicore/Makefile @@ -337,7 +339,6 @@ AC_CONFIG_FILES([Makefile plugins/pychrysa/debug/gdbrsp/Makefile plugins/pychrysa/format/Makefile plugins/pychrysa/format/dex/Makefile - plugins/pychrysa/format/elf/Makefile plugins/pychrysa/glibext/Makefile plugins/pychrysa/gtkext/Makefile plugins/pychrysa/gui/Makefile @@ -380,7 +381,6 @@ AC_CONFIG_FILES([Makefile src/format/dwarf/v2/Makefile src/format/dwarf/v3/Makefile src/format/dwarf/v4/Makefile - src/format/elf/Makefile src/format/java/Makefile src/format/mangling/Makefile src/format/mangling/dex/Makefile diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 2ad0ae2..d8d771f 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -4,4 +4,4 @@ if HAVE_PYTHON3_CONFIG endif # androhelpers -SUBDIRS = devdbg fmtp libcsem mobicore $(PYTHON3_SUBDIRS) readdex readelf readmc ropgadgets +SUBDIRS = devdbg elf fmtp libcsem mobicore $(PYTHON3_SUBDIRS) readdex readelf readmc ropgadgets diff --git a/src/format/elf/Makefile.am b/plugins/elf/Makefile.am index 53139d4..d3cfe05 100644 --- a/src/format/elf/Makefile.am +++ b/plugins/elf/Makefile.am @@ -1,25 +1,29 @@ -noinst_LTLIBRARIES = libformatelf.la +lib_LTLIBRARIES = libelf.la -libformatelf_la_SOURCES = \ +libelf_la_SOURCES = \ + core.h core.c \ elf-int.h elf-int.c \ elf.h elf.c \ elf_def.h \ elf_def_arm.h \ dynamic.h dynamic.c \ helper_arm.h helper_arm.c \ - helper_x86.h helper_x86.c \ loading.h loading.c \ program.h program.c \ section.h section.c \ strings.h strings.c \ symbols.h symbols.c -# helper_mips.h helper_mips.c +libelf_la_LIBADD = \ + python/libelfpython.la -libformatelf_la_LDFLAGS = +libelf_la_LDFLAGS = \ + $(LIBPYTHON_LIBS) $(LIBPYGOBJECT_LIBS) -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) $(LIBXML_CFLAGS) -I../../src AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = python diff --git a/plugins/elf/core.c b/plugins/elf/core.c new file mode 100644 index 0000000..5e2e19c --- /dev/null +++ b/plugins/elf/core.c @@ -0,0 +1,68 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * core.c - intégration du support du format ELF + * + * Copyright (C) 2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "core.h" + + +#include <core/formats.h> +#include <plugins/plugin-def.h> + + +#include "elf.h" +#include "python/module.h" + + + +DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("elf", "Add suport for the ELF format", "0.1.0", + PGA_PLUGIN_INIT); + + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à manipuler. * +* ref = espace de référencement global. * +* * +* Description : Prend acte du chargement du greffon. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) +{ + bool result; /* Bilan à retourner */ + + result = register_format_matcher(elf_is_matching, NULL); + + if (result) + result = register_format_loader("elf", "Executable and Linkable Format", g_elf_format_new); + + if (result) + result = add_format_elf_module_to_python_module(); + + return result; + +} diff --git a/src/format/elf/helper_mips.h b/plugins/elf/core.h index 2946f15..9702b74 100644 --- a/src/format/elf/helper_mips.h +++ b/plugins/elf/core.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * helper_mips.h - prototypes pour la gestion auxiliaire de l'architecture MIPS + * core.h - prototypes pour l'intégration du support du format ELF * - * Copyright (C) 2009-2017 Cyrille Bagard + * Copyright (C) 2017 Cyrille Bagard * * This file is part of Chrysalide. * @@ -21,21 +21,18 @@ */ -#ifndef _FORMAT_ELF_HELPER_MIPS_H -#define _FORMAT_ELF_HELPER_MIPS_H +#ifndef _PLUGINS_ELF_CORE_H +#define _PLUGINS_ELF_CORE_H -#include <stdbool.h> -#include <sys/types.h> +#include <plugins/plugin.h> +#include <plugins/plugin-int.h> -#include "e_elf.h" +/* Prend acte du chargement du greffon. */ +G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *); -/* Déduit les adresses effectives des appels externes. */ -bool g_elf_format_find_mips_dynamic_symbols(elf_format *, off_t, off_t, off_t, off_t); - - -#endif /* _FORMAT_ELF_HELPER_MIPS_H */ +#endif /* _PLUGINS_ELF_CORE_H */ diff --git a/src/format/elf/dynamic.c b/plugins/elf/dynamic.c index 782167c..782167c 100644 --- a/src/format/elf/dynamic.c +++ b/plugins/elf/dynamic.c diff --git a/src/format/elf/dynamic.h b/plugins/elf/dynamic.h index 7fce1d4..7fce1d4 100644 --- a/src/format/elf/dynamic.h +++ b/plugins/elf/dynamic.h diff --git a/src/format/elf/elf-int.c b/plugins/elf/elf-int.c index 36a0f93..36a0f93 100644 --- a/src/format/elf/elf-int.c +++ b/plugins/elf/elf-int.c diff --git a/src/format/elf/elf-int.h b/plugins/elf/elf-int.h index ddaebb4..34f15cb 100644 --- a/src/format/elf/elf-int.h +++ b/plugins/elf/elf-int.h @@ -25,10 +25,12 @@ #define _FORMAT_ELF_ELF_INT_H +#include <common/endianness.h> +#include <format/executable-int.h> + + #include "elf.h" #include "elf_def.h" -#include "../executable-int.h" -#include "../../common/endianness.h" diff --git a/src/format/elf/elf.c b/plugins/elf/elf.c index acdd01f..04ee031 100644 --- a/src/format/elf/elf.c +++ b/plugins/elf/elf.c @@ -31,6 +31,8 @@ #include <i18n.h> +#include <gui/panels/log.h> +#include <plugins/pglist.h> #include "elf-int.h" @@ -38,11 +40,6 @@ #include "section.h" #include "strings.h" #include "symbols.h" -#include "../../gui/panels/log.h" -#include "../../plugins/pglist.h" - - - @@ -50,7 +47,6 @@ #define MAX_PORTION_DESC 256 - /* Initialise la classe des formats d'exécutables ELF. */ static void g_elf_format_class_init(GElfFormatClass *); diff --git a/src/format/elf/elf.h b/plugins/elf/elf.h index 31dd6a2..7e1895b 100644 --- a/src/format/elf/elf.h +++ b/plugins/elf/elf.h @@ -30,8 +30,10 @@ #include <sys/types.h> +#include <core/formats.h> + + #include "elf_def.h" -#include "../../core/formats.h" diff --git a/src/format/elf/elf_def.h b/plugins/elf/elf_def.h index 0d91e00..0d91e00 100644 --- a/src/format/elf/elf_def.h +++ b/plugins/elf/elf_def.h diff --git a/src/format/elf/elf_def_arm.h b/plugins/elf/elf_def_arm.h index 5b0191e..5b0191e 100644 --- a/src/format/elf/elf_def_arm.h +++ b/plugins/elf/elf_def_arm.h diff --git a/src/format/elf/helper_arm.c b/plugins/elf/helper_arm.c index 5b510b9..737e4ac 100644 --- a/src/format/elf/helper_arm.c +++ b/plugins/elf/helper_arm.c @@ -24,10 +24,15 @@ #include "helper_arm.h" +#include <assert.h> + + +#include <format/mangling/demangler.h> + + #include "elf_def_arm.h" #include "elf-int.h" #include "symbols.h" -#include "../mangling/demangler.h" @@ -152,7 +157,7 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx, break; default: - printf("Relocation not supported (%lld) !\n", ELF_REL_TYPE(format, reloc)); + assert(false); symbol = NULL; break; diff --git a/src/format/elf/helper_arm.h b/plugins/elf/helper_arm.h index e971ed6..e971ed6 100644 --- a/src/format/elf/helper_arm.h +++ b/plugins/elf/helper_arm.h diff --git a/src/format/elf/loading.c b/plugins/elf/loading.c index ca8832e..168c9c6 100644 --- a/src/format/elf/loading.c +++ b/plugins/elf/loading.c @@ -25,12 +25,12 @@ #include <i18n.h> +#include <glibext/delayed-int.h> +#include <gui/panels/log.h> #include "elf-int.h" #include "section.h" -#include "../../glibext/delayed-int.h" -#include "../../gui/panels/log.h" diff --git a/src/format/elf/loading.h b/plugins/elf/loading.h index 97d6987..ff5d7bb 100644 --- a/src/format/elf/loading.h +++ b/plugins/elf/loading.h @@ -25,8 +25,10 @@ #define _FORMAT_ELF_LOADING_H +#include <gtkext/gtkstatusstack.h> + + #include "elf.h" -#include "../../gtkext/gtkstatusstack.h" diff --git a/src/format/elf/program.c b/plugins/elf/program.c index 3016feb..3016feb 100644 --- a/src/format/elf/program.c +++ b/plugins/elf/program.c diff --git a/src/format/elf/program.h b/plugins/elf/program.h index bf05d2a..bf05d2a 100644 --- a/src/format/elf/program.h +++ b/plugins/elf/program.h diff --git a/plugins/pychrysa/format/elf/Makefile.am b/plugins/elf/python/Makefile.am index b8f9074..4de3e3c 100644 --- a/plugins/pychrysa/format/elf/Makefile.am +++ b/plugins/elf/python/Makefile.am @@ -1,15 +1,15 @@ -noinst_LTLIBRARIES = libpychrysaformatelf.la +noinst_LTLIBRARIES = libelfpython.la -libpychrysaformatelf_la_SOURCES = \ +libelfpython_la_SOURCES = \ elf.h elf.c \ module.h module.c -libpychrysaformatelf_la_LDFLAGS = +libelfpython_la_LDFLAGS = AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../../src + -I../../../src -I../../.. AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/format/elf/elf.c b/plugins/elf/python/elf.c index 102c60d..1f5ddb2 100644 --- a/plugins/pychrysa/format/elf/elf.c +++ b/plugins/elf/python/elf.c @@ -29,14 +29,14 @@ #include <i18n.h> +#include <format/executable.h> +#include <analysis/content.h> +#include <plugins/pychrysa/helpers.h> +#include <plugins/pychrysa/analysis/content.h> +#include <plugins/pychrysa/format/executable.h> -#include <format/elf/elf.h> - - -#include "../executable.h" -#include "../../analysis/content.h" -#include "../../helpers.h" +#include "../elf.h" @@ -71,17 +71,9 @@ static PyObject *py_elf_format_new(PyTypeObject *type, PyObject *args, PyObject GtkStatusStack *status; /* Instance GTK de suivi */ GBinFormat *format; /* Création GLib à transmettre */ - - ret = PyArg_ParseTuple(args, "OOO", &content_obj, &parent_obj, &status_obj); + ret = PyArg_ParseTuple(args, "O!OO", get_python_binary_content_type(), &content_obj, &parent_obj, &status_obj); if (!ret) return NULL; - ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type()); - if (!ret) - { - PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of BinContent.")); - return NULL; - } - content = G_BIN_CONTENT(pygobject_get(content_obj)); if (parent_obj == Py_None) diff --git a/plugins/pychrysa/format/elf/elf.h b/plugins/elf/python/elf.h index cf6a706..cf6a706 100644 --- a/plugins/pychrysa/format/elf/elf.h +++ b/plugins/elf/python/elf.h diff --git a/plugins/pychrysa/format/elf/module.c b/plugins/elf/python/module.c index 421e4d2..faf0458 100644 --- a/plugins/pychrysa/format/elf/module.c +++ b/plugins/elf/python/module.c @@ -25,13 +25,19 @@ #include "module.h" +#include <Python.h> + + +#include <plugins/pychrysa/access.h> + + #include "elf.h" /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * * Description : Ajoute le module 'format.elf' au module Python. * * * @@ -41,9 +47,10 @@ * * ******************************************************************************/ -bool add_format_elf_module_to_python_module(PyObject *super) +bool add_format_elf_module_to_python_module(void) { bool result; /* Bilan à retourner */ + PyObject *super; /* Module à compléter */ PyObject *module; /* Sous-module mis en place */ int ret; /* Bilan d'un appel */ @@ -60,6 +67,8 @@ bool add_format_elf_module_to_python_module(PyObject *super) result = false; + super = get_access_to_python_module("pychrysalide.format"); + module = PyModule_Create(&py_chrysalide_elf_module); if (module == NULL) return false; @@ -73,9 +82,7 @@ bool add_format_elf_module_to_python_module(PyObject *super) ret = PyModule_AddObject(super, "elf", module); if (ret != 0) goto loading_failed; - result = true; - - result &= register_python_elf_format(module); + result = register_python_elf_format(module); loading_failed: diff --git a/plugins/pychrysa/format/elf/module.h b/plugins/elf/python/module.h index 998674f..de3ce42 100644 --- a/plugins/pychrysa/format/elf/module.h +++ b/plugins/elf/python/module.h @@ -26,13 +26,12 @@ #define _PLUGINS_PYCHRYSA_FORMAT_ELF_MODULE_H -#include <Python.h> #include <stdbool.h> /* Ajoute le module 'format.elf' au module Python. */ -bool add_format_elf_module_to_python_module(PyObject *); +bool add_format_elf_module_to_python_module(void); diff --git a/src/format/elf/section.c b/plugins/elf/section.c index 556c0ed..556c0ed 100644 --- a/src/format/elf/section.c +++ b/plugins/elf/section.c diff --git a/src/format/elf/section.h b/plugins/elf/section.h index f3be0f4..f3be0f4 100644 --- a/src/format/elf/section.h +++ b/plugins/elf/section.h diff --git a/src/format/elf/strings.c b/plugins/elf/strings.c index 2af08b2..3bec414 100644 --- a/src/format/elf/strings.c +++ b/plugins/elf/strings.c @@ -31,9 +31,11 @@ #include <sys/param.h> +#include <arch/raw.h> + + #include "elf-int.h" #include "section.h" -#include "../../arch/raw.h" diff --git a/src/format/elf/strings.h b/plugins/elf/strings.h index bea52da..bea52da 100644 --- a/src/format/elf/strings.h +++ b/plugins/elf/strings.h diff --git a/src/format/elf/symbols.c b/plugins/elf/symbols.c index c6056ca..292913b 100644 --- a/src/format/elf/symbols.c +++ b/plugins/elf/symbols.c @@ -30,21 +30,20 @@ #include <i18n.h> +#include <arch/raw.h> +#include <common/extstr.h> +#include <core/global.h> +#include <core/params.h> +#include <format/mangling/demangler.h> +#include <gui/panels/log.h> #include "dynamic.h" #include "elf-int.h" #include "helper_arm.h" -#include "helper_x86.h" #include "loading.h" #include "program.h" #include "section.h" -#include "../mangling/demangler.h" -#include "../../arch/raw.h" -#include "../../common/extstr.h" -#include "../../core/global.h" -#include "../../core/params.h" -#include "../../gui/panels/log.h" @@ -134,7 +133,7 @@ bool load_elf_symbols(GElfFormat *format, GtkStatusStack *status) /* Symboles externes */ -#if 1 + if (find_elf_sections_by_type(format, SHT_DYNAMIC, §ions, &count)) { log_variadic_message(LMT_INFO, _("Binary is dynamically linked")); @@ -145,9 +144,7 @@ bool load_elf_symbols(GElfFormat *format, GtkStatusStack *status) } else log_variadic_message(LMT_INFO, _("Binary is statically linked")); -#endif - /* Symboles internes */ - //result &= load_elf_internal_symbols(format); + @@ -857,20 +854,13 @@ static bool find_elf_dynamic_item(const GElfFormat *format, const elf_shdr *sect static bool load_elf_external_symbols(GElfFormat *format, const elf_shdr *section) { bool result; /* Bilan à retourner */ - elf_dyn item; /* Elément dynamique */ elf_shdr relxxx; /* Section .rel.xxx trouvée */ elf_shdr dynsym; /* Section .dynsym trouvée */ elf_shdr dynstr; /* Section .dynstr trouvée */ - elf_shdr plt; /* Section .plt trouvée */ result = true; - - - - - /* Section .rel.plt */ if (find_elf_dynamic_item(format, section, DT_JMPREL, &item)) { @@ -889,55 +879,6 @@ static bool load_elf_external_symbols(GElfFormat *format, const elf_shdr *sectio result = load_elf_arm_relocated_symbols(format, &relxxx, &dynsym, &dynstr); break; - case EM_386: - result = load_elf_x86_relocated_symbols(format, &relxxx, &dynsym, &dynstr); - break; - - default: - break; - - } - - } - -#if 0 - - /* Entrées équivalentes dans le binaire */ - if (find_elf_dynamic_item(format, section, DT_SYMTAB, &item)) - { - result &= find_elf_section_by_virtual_address(format, ELF_DYN(format, item, d_un.d_ptr), &dynsym); - - if (result) - result = find_elf_section_by_index(format, ELF_SHDR(format, dynsym, sh_link), &dynstr); - - if (result) - switch (g_exe_format_get_target_machine(G_EXE_FORMAT(format))) - { - case FTM_MIPS: - //result = find_elf_mips_dynamic_symbols(format, &dynsym, &dynstr); - break; - - case FTM_386: - - if (find_elf_dynamic_item(format, section, DT_JMPREL, &item)) - { - result &= find_elf_section_by_virtual_address(format, ELF_DYN(format, item, d_un.d_ptr), &relxxx); - - - printf("VMA :: 0x%08llx\n", ELF_DYN(format, item, d_un.d_ptr)); - - - - if (result) - result = find_elf_section_by_index(format, ELF_SHDR(format, relxxx, sh_info), &plt); - - if (result) - result = find_elf_x86_dynamic_symbols(format, &plt, &relxxx, &dynsym, &dynstr); - - } - - break; - default: break; @@ -945,8 +886,6 @@ static bool load_elf_external_symbols(GElfFormat *format, const elf_shdr *sectio } -#endif - return result; } diff --git a/src/format/elf/symbols.h b/plugins/elf/symbols.h index 03be46c..f0bfa0d 100644 --- a/src/format/elf/symbols.h +++ b/plugins/elf/symbols.h @@ -28,8 +28,8 @@ #include "elf.h" -#include "../../glibext/delayed.h" -#include "../../gtkext/gtkstatusstack.h" +#include <glibext/delayed.h> +#include <gtkext/gtkstatusstack.h> diff --git a/plugins/libcsem/Makefile.am b/plugins/libcsem/Makefile.am index c09ba86..3759070 100644 --- a/plugins/libcsem/Makefile.am +++ b/plugins/libcsem/Makefile.am @@ -10,6 +10,6 @@ liblibcsem_la_SOURCES = \ liblibcsem_la_CFLAGS = $(AM_CFLAGS) -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) -I../../src +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) -I../../src -I../.. AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/libcsem/semantic.c b/plugins/libcsem/semantic.c index 355bc9b..8fdc549 100644 --- a/plugins/libcsem/semantic.c +++ b/plugins/libcsem/semantic.c @@ -24,6 +24,7 @@ #include "semantic.h" +#include <plugins/elf/elf.h> #include <plugins/plugin-def.h> diff --git a/plugins/libcsem/semantic.h b/plugins/libcsem/semantic.h index 0fa79cf..2f8d70d 100644 --- a/plugins/libcsem/semantic.h +++ b/plugins/libcsem/semantic.h @@ -25,7 +25,6 @@ #define _PLUGINS_LIBCSEM_SEMANTIC_H -#include <format/elf/elf.h> #include <plugins/plugin.h> #include <plugins/plugin-int.h> diff --git a/plugins/pychrysa/Makefile.am b/plugins/pychrysa/Makefile.am index fe23e99..e8c2bed 100644 --- a/plugins/pychrysa/Makefile.am +++ b/plugins/pychrysa/Makefile.am @@ -4,6 +4,7 @@ pkglib_LTLIBRARIES = pychrysalide.la libdir = $(pluginsdir) pychrysalide_la_SOURCES = \ + access.h access.c \ helpers.h helpers.c \ plugin.h plugin.c \ pychrysa.h pychrysa.c \ diff --git a/plugins/pychrysa/access.c b/plugins/pychrysa/access.c new file mode 100644 index 0000000..21ff68f --- /dev/null +++ b/plugins/pychrysa/access.c @@ -0,0 +1,137 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * access.c - accès aux modules Python en cours d'enregistrement + * + * Copyright (C) 2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "access.h" + + +#include <stdlib.h> +#include <string.h> + + +#include <common/sort.h> + + + +/* Lien entre un module et sa désignation */ +typedef struct _module_access +{ + const char *path; /* Chemin d'accès */ + PyObject *mod; /* Module Python en place */ + +} module_access; + + +/* Conservation de tous les accès */ +static module_access *_pychrysalide_modules = NULL; +static size_t _pychrysalide_count = 0; + + +/* Effectue la comparaison entre deux accès à des modules. */ +static int compare_python_module_accesses(const module_access *, const module_access *); + + + +/****************************************************************************** +* * +* Paramètres : a = premier accès à analyser. * +* b = second accès à analyser. * +* * +* Description : Effectue la comparaison entre deux accès à des modules. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int compare_python_module_accesses(const module_access *a, const module_access *b) +{ + int result; /* Bilan à retourner */ + + result = strcmp(a->path, b->path); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : path = chemin d'accès à un module Python. * +* mod = module Python en question. * +* * +* Description : Enregistre une référence à un module Python en chargement. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void register_access_to_python_module(const char *path, PyObject *mod) +{ + module_access access; /* Nouvel enregistrement */ + + access.path = path; + access.mod = mod; + + Py_INCREF(mod); + + _pychrysalide_modules = qinsert(_pychrysalide_modules, &_pychrysalide_count, + sizeof(module_access), (__compar_fn_t)compare_python_module_accesses, + &access); + +} + + +/****************************************************************************** +* * +* Paramètres : path = chemin d'accès à un module Python. * +* * +* Description : Fournit la référence à un module Python défini. * +* * +* Retour : Module Python correspondant, ou NULL si aucun de trouvé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *get_access_to_python_module(const char *path) +{ + PyObject *result; /* Référence à renvoyer */ + module_access key; /* Définition à retrouver */ + module_access *access; /* Accès trouvé à consulter */ + + key.path = path; + + access = bsearch(&key, _pychrysalide_modules, _pychrysalide_count, + sizeof(module_access), (__compar_fn_t)compare_python_module_accesses); + + if (access != NULL) + result = access->mod; + else + result = NULL; + + return result; + +} diff --git a/plugins/pychrysa/access.h b/plugins/pychrysa/access.h new file mode 100644 index 0000000..52883ec --- /dev/null +++ b/plugins/pychrysa/access.h @@ -0,0 +1,40 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * access.h - prototypes pour l'accès aux modules Python en cours d'enregistrement + * + * Copyright (C) 2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_PYCHRYSA_ACCESS_H +#define _PLUGINS_PYCHRYSA_ACCESS_H + + +#include <Python.h> + + + +/* Enregistre une référence à un module Python en chargement. */ +void register_access_to_python_module(const char *, PyObject *); + +/* Fournit la référence à un module Python défini. */ +PyObject *get_access_to_python_module(const char *path); + + + +#endif /* _PLUGINS_PYCHRYSA_ACCESS_H */ diff --git a/plugins/pychrysa/analysis/contents/module.c b/plugins/pychrysa/analysis/contents/module.c index d504534..2daa62c 100644 --- a/plugins/pychrysa/analysis/contents/module.c +++ b/plugins/pychrysa/analysis/contents/module.c @@ -30,6 +30,7 @@ #include "file.h" #include "restricted.h" +#include "../../access.h" @@ -84,6 +85,9 @@ bool add_analysis_contents_module_to_python_module(PyObject *super) result &= register_python_file_content(module); result &= register_python_restricted_content(module); + if (result) + register_access_to_python_module("pychrysalide.analysis.contents", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/analysis/db/items/module.c b/plugins/pychrysa/analysis/db/items/module.c index 73ea3d3..cf0fe56 100644 --- a/plugins/pychrysa/analysis/db/items/module.c +++ b/plugins/pychrysa/analysis/db/items/module.c @@ -29,6 +29,7 @@ #include "comment.h" +#include "../../../access.h" @@ -80,6 +81,9 @@ bool add_analysis_db_items_module_to_python_module(PyObject *super) result &= register_python_db_comment(module); + if (result) + register_access_to_python_module("pychrysalide.analysis.db.items", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/analysis/db/module.c b/plugins/pychrysa/analysis/db/module.c index eac3641..1c4da25 100644 --- a/plugins/pychrysa/analysis/db/module.c +++ b/plugins/pychrysa/analysis/db/module.c @@ -32,6 +32,7 @@ #include "collection.h" #include "item.h" #include "items/module.h" +#include "../../access.h" @@ -87,6 +88,9 @@ bool add_analysis_db_module_to_python_module(PyObject *super) result &= add_analysis_db_items_module_to_python_module(module); + if (result) + register_access_to_python_module("pychrysalide.analysis.db", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/analysis/module.c b/plugins/pychrysa/analysis/module.c index ecae63c..253fe76 100644 --- a/plugins/pychrysa/analysis/module.c +++ b/plugins/pychrysa/analysis/module.c @@ -34,6 +34,7 @@ #include "routine.h" #include "contents/module.h" #include "db/module.h" +#include "../access.h" @@ -91,6 +92,9 @@ bool add_analysis_module_to_python_module(PyObject *super) result &= add_analysis_contents_module_to_python_module(module); result &= add_analysis_db_module_to_python_module(module); + if (result) + register_access_to_python_module("pychrysalide.analysis", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/arch/module.c b/plugins/pychrysa/arch/module.c index d9eabed..ae90b5d 100644 --- a/plugins/pychrysa/arch/module.c +++ b/plugins/pychrysa/arch/module.c @@ -39,6 +39,7 @@ #include "raw.h" #include "vmpa.h" #include "arm/module.h" +#include "../access.h" #include "../helpers.h" @@ -155,6 +156,9 @@ bool add_arch_module_to_python_module(PyObject *super) result &= add_arch_arm_module_to_python_module(module); + if (result) + register_access_to_python_module("pychrysalide.arch", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/common/module.c b/plugins/pychrysa/common/module.c index cc2623a..7ff7528 100644 --- a/plugins/pychrysa/common/module.c +++ b/plugins/pychrysa/common/module.c @@ -28,6 +28,7 @@ #include "bits.h" #include "fnv1a.h" #include "pathname.h" +#include "../access.h" @@ -81,6 +82,9 @@ bool add_common_module_to_python_module(PyObject *super) result &= register_python_fnv1a(module); result &= register_python_pathname(module); + if (result) + register_access_to_python_module("pychrysalide.common", module); + acmtpm_exit: if (!result) diff --git a/plugins/pychrysa/core/module.c b/plugins/pychrysa/core/module.c index f42f08f..6c44197 100644 --- a/plugins/pychrysa/core/module.c +++ b/plugins/pychrysa/core/module.c @@ -30,6 +30,7 @@ #include "formats.h" #include "params.h" +#include "../access.h" @@ -82,6 +83,9 @@ bool add_core_module_to_python_module(PyObject *super) result &= register_python_formats(module); result &= register_python_params(module); + if (result) + register_access_to_python_module("pychrysalide.core", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/debug/module.c b/plugins/pychrysa/debug/module.c index db33a13..ea586be 100644 --- a/plugins/pychrysa/debug/module.c +++ b/plugins/pychrysa/debug/module.c @@ -27,6 +27,7 @@ #include "debugger.h" #include "gdbrsp/module.h" +#include "../access.h" @@ -80,6 +81,9 @@ bool add_debug_module_to_python_module(PyObject *super) result &= add_debug_gdbrsp_module_to_python_module(module); + if (result) + register_access_to_python_module("pychrysalide.debug", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/format/Makefile.am b/plugins/pychrysa/format/Makefile.am index bef87ca..71f0022 100644 --- a/plugins/pychrysa/format/Makefile.am +++ b/plugins/pychrysa/format/Makefile.am @@ -8,8 +8,7 @@ libpychrysaformat_la_SOURCES = \ symbol.h symbol.c libpychrysaformat_la_LIBADD = \ - dex/libpychrysaformatdex.la \ - elf/libpychrysaformatelf.la + dex/libpychrysaformatdex.la libpychrysaformat_la_LDFLAGS = @@ -19,4 +18,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJE AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = dex elf +SUBDIRS = dex diff --git a/plugins/pychrysa/format/module.c b/plugins/pychrysa/format/module.c index 29170b1..d15fea8 100644 --- a/plugins/pychrysa/format/module.c +++ b/plugins/pychrysa/format/module.c @@ -32,7 +32,7 @@ #include "format.h" #include "symbol.h" #include "dex/module.h" -#include "elf/module.h" +#include "../access.h" @@ -88,7 +88,9 @@ bool add_format_module_to_python_module(PyObject *super) result &= register_python_binary_symbol(module); result &= add_format_dex_module_to_python_module(module); - result &= add_format_elf_module_to_python_module(module); + + if (result) + register_access_to_python_module("pychrysalide.format", module); loading_failed: diff --git a/plugins/pychrysa/glibext/module.c b/plugins/pychrysa/glibext/module.c index f62b17b..01a2cc8 100644 --- a/plugins/pychrysa/glibext/module.c +++ b/plugins/pychrysa/glibext/module.c @@ -32,6 +32,7 @@ #include "bufferline.h" #include "configuration.h" #include "linegen.h" +#include "../access.h" @@ -88,6 +89,9 @@ bool add_glibext_module_to_python_module(PyObject *super) result &= register_python_generic_config(module); result &= register_python_line_generator(module); + if (result) + register_access_to_python_module("pychrysalide.glibext", module); + agmtpm_exit: assert(result); diff --git a/plugins/pychrysa/gui/module.c b/plugins/pychrysa/gui/module.c index 6a55151..192b1e6 100644 --- a/plugins/pychrysa/gui/module.c +++ b/plugins/pychrysa/gui/module.c @@ -31,6 +31,7 @@ #include "editem.h" #include "panels/module.h" +#include "../access.h" @@ -84,6 +85,9 @@ bool add_gui_module_to_python_module(PyObject *super) result &= add_gui_panels_module_to_python_module(module); + if (result) + register_access_to_python_module("pychrysalide.gui", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/gui/panels/module.c b/plugins/pychrysa/gui/panels/module.c index ea0e234..d5040e3 100644 --- a/plugins/pychrysa/gui/panels/module.c +++ b/plugins/pychrysa/gui/panels/module.c @@ -30,6 +30,7 @@ #include "log.h" #include "panel.h" +#include "../../access.h" @@ -82,6 +83,9 @@ bool add_gui_panels_module_to_python_module(PyObject *super) result &= register_python_panel_item(module); result &= register_python_log_panel(module); + if (result) + register_access_to_python_module("pychrysalide.gui.panels", module); + loading_failed: assert(result); diff --git a/plugins/pychrysa/helpers.h b/plugins/pychrysa/helpers.h index 3eee6a0..295ec28 100644 --- a/plugins/pychrysa/helpers.h +++ b/plugins/pychrysa/helpers.h @@ -21,8 +21,8 @@ */ -#ifndef _PLUGINS_HELPERS_H -#define _PLUGINS_HELPERS_H +#ifndef _PLUGINS_PYCHRYSA_HELPERS_H +#define _PLUGINS_PYCHRYSA_HELPERS_H #include <glib-object.h> @@ -90,4 +90,4 @@ bool _register_class_for_pygobject(PyObject *, GType, PyTypeObject *, PyTypeObje -#endif /* _PLUGINS_HELPERS_H */ +#endif /* _PLUGINS_PYCHRYSA_HELPERS_H */ diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c index 4d32ee1..7c082d6 100644 --- a/plugins/pychrysa/pychrysa.c +++ b/plugins/pychrysa/pychrysa.c @@ -59,6 +59,10 @@ DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("PyChrysalide", "Provides bindings to Python", "0.1.0", PGA_PLUGIN_INIT); +/* Note la nature du chargement */ +static bool _standalone = true; + + /* Fournit la révision du programme global. */ static PyObject *py_chrysalide_revision(PyObject *, PyObject *); @@ -395,6 +399,9 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) return NULL; } + if (_standalone) + init_all_plugins(); + return result; } @@ -533,6 +540,8 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) /* Chargement du module pour Python */ + _standalone = false; + ret = PyImport_AppendInittab("pychrysalide", &PyInit_pychrysalide); if (ret == -1) diff --git a/plugins/readelf/header.c b/plugins/readelf/header.c index 33cf107..8b124a4 100644 --- a/plugins/readelf/header.c +++ b/plugins/readelf/header.c @@ -24,7 +24,7 @@ #include "header.h" -#include <format/elf/elf.h> +#include <plugins/elf/elf.h> #include <plugins/fmtp/parser.h> diff --git a/plugins/readelf/program.c b/plugins/readelf/program.c index 107f048..f63d10e 100644 --- a/plugins/readelf/program.c +++ b/plugins/readelf/program.c @@ -30,7 +30,7 @@ #include <i18n.h> #include <common/cpp.h> #include <common/extstr.h> -#include <format/elf/elf-int.h> +#include <plugins/elf/elf-int.h> #include <plugins/fmtp/parser.h> diff --git a/plugins/readelf/program.h b/plugins/readelf/program.h index 0710577..4c4cde4 100644 --- a/plugins/readelf/program.h +++ b/plugins/readelf/program.h @@ -26,7 +26,7 @@ #include <format/preload.h> -#include <format/elf/elf.h> +#include <plugins/elf/elf.h> diff --git a/plugins/readelf/reader.c b/plugins/readelf/reader.c index 6f81b3f..4d766da 100644 --- a/plugins/readelf/reader.c +++ b/plugins/readelf/reader.c @@ -24,7 +24,7 @@ #include "reader.h" -#include <format/elf/elf.h> +#include <plugins/elf/elf.h> #include <plugins/plugin-def.h> diff --git a/plugins/readelf/section.c b/plugins/readelf/section.c index 3a71225..ae3bd6f 100644 --- a/plugins/readelf/section.c +++ b/plugins/readelf/section.c @@ -30,8 +30,8 @@ #include <i18n.h> #include <common/cpp.h> #include <common/extstr.h> -#include <format/elf/elf-int.h> -#include <format/elf/section.h> +#include <plugins/elf/elf-int.h> +#include <plugins/elf/section.h> #include <plugins/fmtp/parser.h> diff --git a/plugins/readelf/section.h b/plugins/readelf/section.h index 60e8f34..33be014 100644 --- a/plugins/readelf/section.h +++ b/plugins/readelf/section.h @@ -26,7 +26,7 @@ #include <format/preload.h> -#include <format/elf/elf.h> +#include <plugins/elf/elf.h> diff --git a/plugins/readelf/strtab.c b/plugins/readelf/strtab.c index dc022cf..d8133fc 100644 --- a/plugins/readelf/strtab.c +++ b/plugins/readelf/strtab.c @@ -29,7 +29,7 @@ #include <arch/raw.h> -#include <format/elf/section.h> +#include <plugins/elf/section.h> diff --git a/plugins/readelf/strtab.h b/plugins/readelf/strtab.h index 89c178d..9adcd46 100644 --- a/plugins/readelf/strtab.h +++ b/plugins/readelf/strtab.h @@ -26,7 +26,7 @@ #include <format/preload.h> -#include <format/elf/elf.h> +#include <plugins/elf/elf.h> diff --git a/plugins/ropgadgets/plugin.c b/plugins/ropgadgets/plugin.c index 8b35647..11d1715 100644 --- a/plugins/ropgadgets/plugin.c +++ b/plugins/ropgadgets/plugin.c @@ -65,7 +65,8 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) GtkContainer *menubar; /* Support pour éléments */ GtkWidget *submenuitem; /* Sous-élément de menu */ - ref = G_OBJECT(get_editor_window()); /* FIXME */ + ref = G_OBJECT(get_editor_window()); + if (ref == NULL) return false; menubar = GTK_CONTAINER(g_object_get_data(ref, "menubar_plugins")); if (menubar == NULL) return false; diff --git a/src/core/formats.c b/src/core/formats.c index bf58c2e..0e1e8e7 100644 --- a/src/core/formats.c +++ b/src/core/formats.c @@ -34,7 +34,6 @@ #include "../format/dwarf/v2/dwarf.h" #include "../format/dwarf/v3/dwarf.h" #include "../format/dwarf/v4/dwarf.h" -#include "../format/elf/elf.h" @@ -200,8 +199,6 @@ bool load_hard_coded_formats_definitions(void) result &= register_format_matcher(dwarf_is_matching, NULL); - result &= register_format_matcher(elf_is_matching, NULL); - /* Chargements */ result &= register_format_loader("dex", "Dalvik Executable format", g_dex_format_new); @@ -215,8 +212,6 @@ bool load_hard_coded_formats_definitions(void) result &= register_format_loader("dwarf_v4", "Debugging With Arbitrary Record Formats (v4)", g_dwarfv4_format_new); - result &= register_format_loader("elf", "Executable and Linkable Format", g_elf_format_new); - return result; } diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 3501dda..3a63fbf 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -16,7 +16,6 @@ libformat_la_SOURCES = \ libformat_la_LIBADD = \ dex/libformatdex.la \ dwarf/libformatdwarf.la \ - elf/libformatelf.la \ java/libformatjava.la \ mangling/libformatmangling.la \ pe/libformatpe.la @@ -28,4 +27,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = dex dwarf elf java mangling pe +SUBDIRS = dex dwarf java mangling pe diff --git a/src/format/elf/helper_mips.c b/src/format/elf/helper_mips.c deleted file mode 100644 index e71c69e..0000000 --- a/src/format/elf/helper_mips.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * helper_mips.c - gestion auxiliaire de l'architecture MIPS - * - * Copyright (C) 2009-2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "helper_mips.h" - - -#include <string.h> - - -#include "elf-int.h" - - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* dyn_start = début des informations dynamiques associées. * -* dyn_size = taille de la zone associée. * -* str_start = début de la zone de chaîne de caractères. * -* str_size = taille de la zone de chaînes de caractères. * -* * -* Description : Déduit les adresses effectives des appels externes. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_elf_format_find_mips_dynamic_symbols(elf_format *format, off_t dyn_start, off_t dyn_size, off_t str_start, off_t str_size) -{ - off_t iter; /* Boucle de parcours */ - Elf_Sym symbol; /* Symbole ELF lu */ - off_t name_pos; /* Localisation du nom */ - - if (dyn_size % ELF_SIZEOF_SYM(format) != 0) return false; - - for (iter = dyn_start; iter < (dyn_start + dyn_size); iter += ELF_SIZEOF_SYM(format)) - { - memcpy(&symbol, &EXE_FORMAT(format)->content[iter], ELF_SIZEOF_SYM(format)); - - if (ELF_ST_TYPE(ELF_SYM(format, symbol, st_info)) != STT_FUNC) continue; - - if (ELF_SYM(format, symbol, st_value) == 0) continue; - - name_pos = ELF_SYM(format, symbol, st_name); - - /* Sécurité anti-débordements */ - if (name_pos >= str_size) continue; - - /* Si le symbole possède un nom... */ - if (strlen(&EXE_FORMAT(format)->content[str_start + name_pos]) > 0) - { - format->symbols = (elf_symbol *)realloc(format->symbols, ++format->sym_count * sizeof(elf_symbol)); - - format->symbols[format->sym_count - 1].name = &EXE_FORMAT(format)->content[str_start + name_pos]; - format->symbols[format->sym_count - 1].address = ELF_SYM(format, symbol, st_value); - - } - - } - - return true; - -} diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c deleted file mode 100644 index ba37bcb..0000000 --- a/src/format/elf/helper_x86.c +++ /dev/null @@ -1,451 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * helper_x86.c - gestion auxiliaire de l'architecture x86 - * - * Copyright (C) 2009-2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "helper_x86.h" - - - -bool load_elf_x86_relocated_symbols(GElfFormat *a, const elf_shdr *b, const elf_shdr *c, const elf_shdr *d) -{ - return false; -} - -/* Déduit les adresses effectives des appels externes. */ -bool find_elf_x86_dynamic_symbols(GElfFormat *a, const elf_shdr *b, const elf_shdr *c, const elf_shdr *d, const elf_shdr *e) -{ - return false; -} - - - - - - -#if 0 - -#include <malloc.h> -#include <stdio.h> -#include <string.h> - - -#include "elf-int.h" -#include "../symbol.h" -#include "../mangling/demangler.h" -#include "../../arch/immediate.h" -#include "../../arch/processor.h" -#include "../../arch/x86/instruction.h" - - -// Désactivation -#define g_x86_instruction_get_opcode(i) 0 - - -/* symbols.c : Récupère la désignation d'un symbole donné. */ -extern const char *get_elf_symbol_name(GElfFormat *, const elf_shdr *, const elf_shdr *, off_t); - - -/* Décode les instructions liées à la relocalisation. */ -GArchInstruction **decode_elf_relocations(GElfFormat *, const elf_shdr *, size_t *); - -/* Déduit les adresses effectives des relocalisations. */ -void translate_exe_elf_relocations(GElfFormat *, GArchInstruction **, size_t); - -/* Déduit les adresses effectives des relocalisations. */ -void translate_dyn_elf_relocations(GElfFormat *, GArchInstruction **, size_t, const elf_shdr *, const elf_shdr *, const elf_shdr *); - - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* relxxx = section .rel.xxx trouvée (zone à traiter). * -* dynsym = section .dynsym trouvée (info. dynamiques). * -* dynstr = section .dynstr trouvée (chaînes de caractères). * -* * -* Description : Charge en mémoire la liste des symboles dynamiques. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool load_elf_x86_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx, const elf_shdr *dynsym, const elf_shdr *dynstr) -{ - bool result; /* Bilan à retourner */ - off_t rel_start; /* Début de la zone à traiter */ - off_t rel_size; /* Taille de cette même zone */ - off_t iter; /* Boucle de parcours */ - elf_rel reloc; /* Infos de relocalisation */ - off_t index; /* Indice de la portion visée */ - const char *name; /* Nom du symbole trouvé */ - GBinSymbol *symbol; /* Nouveau symbole construit */ - - - - - result = true; - - - - get_elf_section_content(format, relxxx, &rel_start, &rel_size, NULL); - - - printf("rel :: %d -> %d\n", rel_start, rel_start + rel_size); - - - - for (iter = rel_start; iter < (rel_start + rel_size); ) - { - result = false;//read_elf_relocation(format, &iter, &reloc); - if (!result) break; - - switch (ELF_REL_TYPE(format, reloc)) - { - case R_386_NONE: - break; - - case R_386_JMP_SLOT: - - index = ELF_REL_SYM(format, reloc); - name = get_elf_symbol_name(format, dynsym, dynstr, index); - - - //printf("got a jump ! >> %d - %s\n", index, name); - - - if (name == NULL) - { - /* FIXME */ - name = "unknown"; - } - - symbol = g_binary_symbol_new(NULL, STP_ROUTINE); - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); - - break; - - default: - printf("Relocation not supported (%lld) !\n", ELF_REL_TYPE(format, reloc)); - break; - - } - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* plt = section .plt trouvée (points d'entrées dynamiques). * -* rel = section .rel.plt présentant la table des symboles. * -* dynsym = section listant tous les symboles. * -* dynstr = section contenant le nom de ces symboles. * -* * -* Description : Déduit les adresses effectives des appels externes. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool find_elf_x86_dynamic_symbols(GElfFormat *format, const elf_shdr *plt, const elf_shdr *rel, const elf_shdr *dynsym, const elf_shdr *dynstr) -{ - GArchInstruction **instructions; /* Instructions décodées */ - size_t count; /* Quantité d'instructions */ - size_t i; /* Boucle de parcours */ - - instructions = decode_elf_relocations(format, plt, &count); - - switch (ELF_HDR(format, format->header, e_type)) - { - case ET_EXEC: - translate_exe_elf_relocations(format, instructions, count); - break; - - case ET_DYN: - translate_dyn_elf_relocations(format, instructions, count, rel, dynsym, dynstr); - break; - - } - - for (i = 0; i < count; i++) - /* TODO : free instructions[i] */; - - if (instructions != NULL) - free(instructions); - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* plt = section .plt trouvée (points d'entrées dynamiques). * -* count = nombre d'instructions lues. [OUT] * -* * -* Description : Décode les instructions liées à la relocalisation. * -* * -* Retour : Liste des instructions décodées ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchInstruction **decode_elf_relocations(GElfFormat *format, const elf_shdr *plt, size_t *count) -{ - GArchInstruction **result; /* Liste à renvoyer */ - off_t plt_start; /* Début de section */ - off_t plt_size; /* Taille de section */ - vmpa_t plt_address; /* Adresse virtuelle associée */ - GArchProcessor *proc; /* Processeur pour le décodage */ - off_t pos; /* Tête de lecture */ - vmpa_t address; /* Adresse virtuelle courante */ - GArchInstruction *instr; /* Instruction décodée */ - - result = NULL; - *count = 0; - - get_elf_section_content(format, plt, &plt_start, &plt_size, &plt_address); - - proc = NULL;//get_arch_processor_for_type(APT_386); - - for (pos = 0; pos < plt_size; ) - { - address = plt_address + pos; - -#if 0 - instr = g_arch_processor_decode_instruction(proc, NULL /*FIXME*/, &G_BIN_FORMAT(format)->content[plt_start], - &pos, plt_size, address, NULL /*FIXME*/); -#endif - - result = (GArchInstruction **)realloc(result, ++(*count) * sizeof(GArchInstruction *)); - result[*count - 1] = instr; - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* instructions = listes des instructions à interpréter. * -* count = nombre d'instructions lues. * -* * -* Description : Déduit les adresses effectives des relocalisations. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instructions, size_t count) -{ - size_t i; /* Boucle de parcours #1 */ - X86Opcodes opcode_n0; /* Opcode de l'instruction n */ - X86Opcodes opcode_n1; /* Opcode de l'instruction n+1 */ - X86Opcodes opcode_n2; /* Opcode de l'instruction n+2 */ - const GArchOperand *operand; /* Valeur du saut */ - vmpa_t address; /* Adresse virtuelle finale */ - GBinSymbol **symbols; /* Liste des symboles existants*/ - size_t symbols_count; /* Taille de cette liste */ - size_t j; /* Boucle de parcours #2 */ - size_t new_len; /* Taille du nouveau nom */ - char *new_name; /* Nom avec suffixe @plt */ - GBinRoutine *routine; /* Nouvelle routine déduite */ - GBinSymbol *symbol; /* Nouveau symbole construit */ - - for (i = 0; (i + 2) < count; ) - { - opcode_n0 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i])); - opcode_n1 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 1])); - opcode_n2 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 2])); - - if (opcode_n0 == XOP_JMP_RM1632 - && opcode_n1 == XOP_PUSH_IMM1632 - && opcode_n2 == XOP_JMP_REL1632) - { - operand = g_arch_instruction_get_operand(instructions[i], 0); - - if (g_imm_operand_to_vmpa_t(G_IMM_OPERAND(operand), &address)) - { - symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &symbols_count); - - for (j = 0; j < symbols_count; j++) - if (0 /* FIXME g_binary_symbol_get_address(symbols[j]) == address*/) - { - /* Nom final */ - - new_len = strlen(g_binary_symbol_get_label(symbols[j])) + 4 + 1; - new_name = calloc(new_len, sizeof(char)); - snprintf(new_name, new_len, "%s@plt", g_binary_symbol_get_label(symbols[j])); - - g_arch_instruction_get_location(instructions[i], NULL, NULL, &address); - - /* Routine */ - - routine = try_to_demangle_routine(g_binary_symbol_get_label(symbols[j])); - - ///g_binary_routine_set_address(routine, address); - - ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine); - - /* Symbole uniquement */ - - symbol = g_binary_symbol_new(NULL, STP_ROUTINE); - - g_binary_symbol_attach_routine(symbol, routine); - - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); - - break; - - } - - } - - i += 3; - - } - else i++; - - } - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* instructions = listes des instructions à interpréter. * -* count = nombre d'instructions lues. * -* * -* Description : Déduit les adresses effectives des relocalisations. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instructions, size_t count, const elf_shdr *rel, const elf_shdr *dynsym, const elf_shdr *dynstr) -{ - off_t rel_start; /* Début de la zone à traiter */ - off_t rel_size; /* Taille de cette même zone */ - size_t i; /* Boucle de parcours #1 */ - X86Opcodes opcode_n0; /* Opcode de l'instruction n */ - X86Opcodes opcode_n1; /* Opcode de l'instruction n+1 */ - X86Opcodes opcode_n2; /* Opcode de l'instruction n+2 */ - const GArchOperand *operand; /* Valeur du saut */ - off_t pos; /* Tête de lecture */ - bool negative; /* Tête de lecture invalide ? */ - elf_rel reloc; /* Infos de relocalisation */ - off_t index; /* Indice de la portion visée */ - const char *name; /* Nom du symbole trouvé */ - size_t new_len; /* Taille du nouveau nom */ - char *new_name; /* Nom avec suffixe @plt */ - vmpa_t address; /* Adresse virtuelle finale */ - GBinRoutine *routine; /* Nouvelle routine déduite */ - GBinSymbol *symbol; /* Nouveau symbole construit */ - - get_elf_section_content(format, rel, &rel_start, &rel_size, NULL); - - for (i = 0; (i + 2) < count; ) - { - opcode_n0 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i])); - opcode_n1 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 1])); - opcode_n2 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 2])); - - if (opcode_n0 == XOP_JMP_RM1632 - && opcode_n1 == XOP_PUSH_IMM1632 - && opcode_n2 == XOP_JMP_REL1632) - { - operand = g_arch_instruction_get_operand(instructions[i + 1], 0); - - if (!g_imm_operand_to_off_t(G_IMM_OPERAND(operand), &pos, &negative)) - goto next_op; - - if ((pos + ELF_SIZEOF_REL(format)) > rel_size) - goto next_op; - - pos += rel_start; - - if (!false/*read_elf_relocation(format, &pos, &reloc)*/) - goto next_op; - - index = ELF_REL_SYM(format, reloc); - name = get_elf_symbol_name(format, dynsym, dynstr, index); - - if (name == NULL) - { - /* FIXME */ - name = "unknown"; - } - - /* Nom final */ - - new_len = strlen(name) + 4 + 1; - new_name = calloc(new_len, sizeof(char)); - snprintf(new_name, new_len, "%s@plt", name); - - g_arch_instruction_get_location(instructions[i], NULL, NULL, &address); - - /* Routine */ - - routine = try_to_demangle_routine(name); - - ////g_binary_routine_set_address(routine, address); - - ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine); - - /* Symbole uniquement */ - - symbol = g_binary_symbol_new(NULL, STP_ROUTINE); - - g_binary_symbol_attach_routine(symbol, routine); - - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); - - next_op: - - i += 3; - - } - else i++; - - } - -} - -#endif diff --git a/src/format/elf/helper_x86.h b/src/format/elf/helper_x86.h deleted file mode 100644 index 4d61fac..0000000 --- a/src/format/elf/helper_x86.h +++ /dev/null @@ -1,40 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * helper_x86.h - prototypes pour la gestion auxiliaire de l'architecture x86 - * - * Copyright (C) 2009-2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef _FORMAT_ELF_HELPER_X86_H -#define _FORMAT_ELF_HELPER_X86_H - - -#include "section.h" - - - -/* Charge en mémoire la liste des symboles dynamiques. */ -bool load_elf_x86_relocated_symbols(GElfFormat *, const elf_shdr *, const elf_shdr *, const elf_shdr *); - -/* Déduit les adresses effectives des appels externes. */ -bool find_elf_x86_dynamic_symbols(GElfFormat *, const elf_shdr *, const elf_shdr *, const elf_shdr *, const elf_shdr *); - - - -#endif /* _FORMAT_ELF_HELPER_X86_H */ diff --git a/src/format/format.c b/src/format/format.c index 293e5da..8b1bf0a 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -32,11 +32,6 @@ #include "format-int.h" #include "preload.h" -#include "dex/dex.h" -#include "dwarf/dwarf.h" -#include "elf/elf.h" -#include "java/java.h" -#include "pe/pe.h" #include "../arch/processor.h" #include "../common/sort.h" #include "../gui/panels/log.h" |