summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-03-11 21:57:05 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-03-11 21:57:05 (GMT)
commit8088f1cbb4304c686ff41520099707a333084a4e (patch)
tree147411c3f90097dc1ae950ec390df2dfccf07ad7
parenta33dd28e763e3a8b04145fb549aca9320e100a4b (diff)
Defined a new Dex demangler with MUTF-8 support as plugin.
-rw-r--r--ChangeLog148
-rw-r--r--configure.ac4
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/dex/core.c2
-rwxr-xr-xplugins/dex/format.c5
-rw-r--r--plugins/dex/pool.c5
-rw-r--r--plugins/dexbnf/Makefile.am27
-rw-r--r--plugins/dexbnf/context.c209
-rw-r--r--plugins/dexbnf/context.h52
-rw-r--r--plugins/dexbnf/core.c64
-rw-r--r--plugins/dexbnf/core.h38
-rw-r--r--plugins/dexbnf/demangler.c (renamed from src/mangling/dex/context.c)70
-rw-r--r--plugins/dexbnf/demangler.h58
-rw-r--r--plugins/dexbnf/python/Makefile.am15
-rw-r--r--plugins/dexbnf/python/demangler.c145
-rw-r--r--plugins/dexbnf/python/demangler.h42
-rw-r--r--plugins/dexbnf/python/module.c61
-rw-r--r--plugins/dexbnf/python/module.h38
-rw-r--r--plugins/dexbnf/shorty.c227
-rw-r--r--plugins/dexbnf/shorty.h38
-rw-r--r--plugins/dexbnf/simple.c163
-rw-r--r--plugins/dexbnf/simple.h37
-rw-r--r--plugins/dexbnf/type.c316
-rw-r--r--plugins/dexbnf/type.h38
-rw-r--r--plugins/pychrysalide/Makefile.am5
-rw-r--r--plugins/pychrysalide/analysis/Makefile.am3
-rw-r--r--plugins/pychrysalide/analysis/module.c2
-rw-r--r--plugins/pychrysalide/analysis/routine.c36
-rw-r--r--plugins/pychrysalide/analysis/type.c145
-rw-r--r--plugins/pychrysalide/analysis/type.h42
-rw-r--r--plugins/pychrysalide/core/Makefile.am1
-rw-r--r--plugins/pychrysalide/core/demanglers.c160
-rw-r--r--plugins/pychrysalide/core/demanglers.h42
-rw-r--r--plugins/pychrysalide/core/formats.c2
-rw-r--r--plugins/pychrysalide/core/logs.c2
-rw-r--r--plugins/pychrysalide/core/module.c2
-rw-r--r--plugins/pychrysalide/mangling/Makefile.am18
-rw-r--r--plugins/pychrysalide/mangling/demangler.c219
-rw-r--r--plugins/pychrysalide/mangling/demangler.h42
-rw-r--r--plugins/pychrysalide/mangling/module.c91
-rw-r--r--plugins/pychrysalide/mangling/module.h39
-rw-r--r--plugins/pychrysalide/pychrysa.c2
-rw-r--r--src/analysis/routine.c6
-rw-r--r--src/analysis/types/cse.c4
-rw-r--r--src/analysis/types/cse.h2
-rw-r--r--src/analysis/types/encaps.c47
-rw-r--r--src/analysis/types/encaps.h7
-rwxr-xr-xsrc/common/Makefile.am2
-rw-r--r--src/common/ibuf.c173
-rw-r--r--src/common/ibuf.h71
-rw-r--r--src/common/packed.c2
-rw-r--r--src/common/packed.h2
-rw-r--r--src/common/utf8.c150
-rw-r--r--src/common/utf8.h55
-rwxr-xr-xsrc/core/Makefile.am1
-rw-r--r--src/core/core.c3
-rw-r--r--src/core/demanglers.c191
-rw-r--r--src/core/demanglers.h46
-rw-r--r--src/core/processors.h2
-rw-r--r--src/format/format-int.h3
-rw-r--r--src/format/format.c3
-rw-r--r--src/mangling/Makefile.am4
-rw-r--r--src/mangling/context-int.h20
-rw-r--r--src/mangling/context.c86
-rw-r--r--src/mangling/context.h6
-rw-r--r--src/mangling/demangler-int.h57
-rw-r--r--src/mangling/demangler.c189
-rw-r--r--src/mangling/demangler.h46
-rw-r--r--src/mangling/dex/Makefile.am46
-rw-r--r--src/mangling/dex/context.h52
-rw-r--r--src/mangling/dex/shorty_gram.y138
-rw-r--r--src/mangling/dex/shorty_tok.l28
-rw-r--r--src/mangling/dex/type_gram.y159
-rw-r--r--src/mangling/dex/type_tok.l150
-rw-r--r--tests/mangling/dex.py66
75 files changed, 3851 insertions, 623 deletions
diff --git a/ChangeLog b/ChangeLog
index efb168a..96cf6a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,151 @@
+18-03-11 Cyrille Bagard <nocbos@gmail.com>
+
+ * configure.ac:
+ Add the new Makefiles from the 'plugins/dexbnf', 'plugins/dexbnf/python'
+ and 'plugins/pychrysalide/mangling' directories, and remove the one from
+ the 'src/mangling/dex' directory.
+
+ * plugins/Makefile.am:
+ Add dexbnf to SUBDIRS.
+
+ * plugins/dex/core.c:
+ Update depedencies.
+
+ * plugins/dex/format.c:
+ * plugins/dex/pool.c:
+ Update code.
+
+ * plugins/dexbnf/Makefile.am:
+ * plugins/dexbnf/context.c:
+ * plugins/dexbnf/context.h:
+ * plugins/dexbnf/core.c:
+ * plugins/dexbnf/core.h:
+ * plugins/dexbnf/demangler.c:
+ * plugins/dexbnf/demangler.h:
+ * plugins/dexbnf/python/Makefile.am:
+ * plugins/dexbnf/python/demangler.c:
+ * plugins/dexbnf/python/demangler.h:
+ * plugins/dexbnf/python/module.c:
+ * plugins/dexbnf/python/module.h:
+ * plugins/dexbnf/shorty.c:
+ * plugins/dexbnf/shorty.h:
+ * plugins/dexbnf/simple.c:
+ * plugins/dexbnf/simple.h:
+ * plugins/dexbnf/type.c:
+ * plugins/dexbnf/type.h:
+ New entries: define a new Dex demangler with MUTF-8 support as plugin.
+
+ * plugins/pychrysalide/Makefile.am:
+ Add mangling/libpychrysamangling.la to pychrysalide_la_LIBADD and
+ mangling to SUBDIRS.
+
+ * plugins/pychrysalide/analysis/Makefile.am:
+ Add the 'type.[ch]' files to libpychrysaanalysis_la_SOURCES.
+
+ * plugins/pychrysalide/analysis/module.c:
+ Update code.
+
+ * plugins/pychrysalide/analysis/routine.c:
+ Convert routines with str() calls from Python.
+
+ * plugins/pychrysalide/analysis/type.c:
+ * plugins/pychrysalide/analysis/type.h:
+ New entries: define data types for Python.
+
+ * plugins/pychrysalide/core/Makefile.am:
+ Add the 'demanglers.[ch]' files to libpychrysacore_la_SOURCES.
+
+ * plugins/pychrysalide/core/demanglers.c:
+ * plugins/pychrysalide/core/demanglers.h:
+ New entries: provide demanglers.
+
+ * plugins/pychrysalide/core/formats.c:
+ * plugins/pychrysalide/core/logs.c:
+ Typo.
+
+ * plugins/pychrysalide/core/module.c:
+ Update code.
+
+ * plugins/pychrysalide/mangling/Makefile.am:
+ * plugins/pychrysalide/mangling/demangler.c:
+ * plugins/pychrysalide/mangling/demangler.h:
+ * plugins/pychrysalide/mangling/module.c:
+ * plugins/pychrysalide/mangling/module.h:
+ New entries: give Python access to demanglers.
+
+ * plugins/pychrysalide/pychrysa.c:
+ Update code.
+
+ * src/analysis/routine.c:
+ Handle routines without names.
+
+ * src/analysis/types/cse.c:
+ * src/analysis/types/cse.h:
+ Update prototypes providing class names.
+
+ * src/analysis/types/encaps.c:
+ * src/analysis/types/encaps.h:
+ Handle arrays.
+
+ * src/common/Makefile.am:
+ Add the 'ibuf.[ch]' and 'utf8.[ch]' files to libcommon_la_SOURCES.
+
+ * src/common/ibuf.c:
+ * src/common/ibuf.h:
+ New entries: create input buffers.
+
+ * src/common/packed.c:
+ * src/common/packed.h:
+ Typo.
+
+ * src/common/utf8.c:
+ * src/common/utf8.h:
+ New entries: handle partial UTF-8 decoding.
+
+ * src/core/Makefile.am:
+ Add the 'demanglers.[ch]' files to libcore_la_SOURCES.
+
+ * src/core/core.c:
+ Update code.
+
+ * src/core/demanglers.c:
+ * src/core/demanglers.h:
+ New entries: register and provide demanglers.
+
+ * src/core/processors.h:
+ Typo.
+
+ * src/format/format-int.h:
+ * src/format/format.c:
+ Link each binary format with a dedicated demangler.
+
+ * src/mangling/Makefile.am:
+ Add the 'demangler-int.h' file to libmangling_la_SOURCES and remove
+ dex/libmanglingdex.la from libmangling_la_LIBADD and dex from SUBDIRS.
+
+ * src/mangling/context-int.h:
+ * src/mangling/context.c:
+ * src/mangling/context.h:
+ Update code for type and routine demangling.
+
+ * src/mangling/demangler-int.h:
+ New entry: allow demangler inheritance.
+
+ * src/mangling/demangler.c:
+ * src/mangling/demangler.h:
+ Update code for type and routine demangling.
+
+ * src/mangling/dex/Makefile.am:
+ * src/mangling/dex/context.h:
+ * src/mangling/dex/shorty_gram.y:
+ * src/mangling/dex/shorty_tok.l:
+ * src/mangling/dex/type_gram.y:
+ * src/mangling/dex/type_tok.l:
+ Removed files.
+
+ * tests/mangling/dex.py:
+ New entry: extend the test suite with Dex demangling checking.
+
18-03-08 Cyrille Bagard <nocbos@gmail.com>
* plugins/arm/v7/instruction.c:
diff --git a/configure.ac b/configure.ac
index d3b9f1f..84f12df 100644
--- a/configure.ac
+++ b/configure.ac
@@ -336,6 +336,8 @@ AC_CONFIG_FILES([Makefile
plugins/devdbg/Makefile
plugins/dex/Makefile
plugins/dex/python/Makefile
+ plugins/dexbnf/Makefile
+ plugins/dexbnf/python/Makefile
plugins/elf/Makefile
plugins/elf/python/Makefile
plugins/fmtp/Makefile
@@ -356,6 +358,7 @@ AC_CONFIG_FILES([Makefile
plugins/pychrysalide/gtkext/Makefile
plugins/pychrysalide/gui/Makefile
plugins/pychrysalide/gui/panels/Makefile
+ plugins/pychrysalide/mangling/Makefile
plugins/python/Makefile
plugins/python/apkfiles/Makefile
plugins/python/samples/Makefile
@@ -396,7 +399,6 @@ AC_CONFIG_FILES([Makefile
src/gui/panels/Makefile
src/gui/tb/Makefile
src/mangling/Makefile
- src/mangling/dex/Makefile
src/mangling/itanium/Makefile
src/plugins/Makefile
tools/Makefile
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 6bb44fa..25774db 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -4,4 +4,4 @@ if HAVE_PYTHON3_CONFIG
endif
# androhelpers
-SUBDIRS = arm dalvik devdbg dex elf fmtp libcsem mobicore $(PYTHON3_SUBDIRS) readdex readelf readmc ropgadgets
+SUBDIRS = arm dalvik devdbg dex dexbnf elf fmtp libcsem mobicore $(PYTHON3_SUBDIRS) readdex readelf readmc ropgadgets
diff --git a/plugins/dex/core.c b/plugins/dex/core.c
index b163be9..c7f9aa4 100644
--- a/plugins/dex/core.c
+++ b/plugins/dex/core.c
@@ -34,7 +34,7 @@
DEFINE_CHRYSALIDE_PLUGIN("dex", "Add suport for the DEX format", "0.1.0",
- RL("PyChrysalide"), AL(PGA_PLUGIN_INIT));
+ RL("PyChrysalide", "dexbnf"), AL(PGA_PLUGIN_INIT));
diff --git a/plugins/dex/format.c b/plugins/dex/format.c
index 72d0dd5..fc49a15 100755
--- a/plugins/dex/format.c
+++ b/plugins/dex/format.c
@@ -24,10 +24,12 @@
#include "format.h"
+#include <assert.h>
#include <string.h>
#include <i18n.h>
+#include <core/demanglers.h>
#include <core/global.h>
#include <plugins/pglist.h>
@@ -189,6 +191,9 @@ static void g_dex_format_init(GDexFormat *format)
bin_format = G_BIN_FORMAT(format);
+ bin_format->demangler = get_compiler_demangler_for_type("dex");
+ assert(bin_format->demangler != NULL);
+
bin_format->decompile = (format_decompile_fc)g_dex_format_decompile;
}
diff --git a/plugins/dex/pool.c b/plugins/dex/pool.c
index 19e9e36..46c431e 100644
--- a/plugins/dex/pool.c
+++ b/plugins/dex/pool.c
@@ -31,7 +31,6 @@
#include <i18n.h>
#include <core/global.h>
#include <mangling/demangler.h>
-#include <mangling/dex/context.h>
#include "dex-int.h"
@@ -235,6 +234,7 @@ GDataType *get_type_from_dex_pool(GDexFormat *format, uint32_t index)
type_id_item type_id; /* Définition de la classe */
string_id_item str_id; /* Identifiant de chaîne */
string_data_item str_data; /* Description de chaîne */
+ GCompDemangler *demangler; /* Accès plus lisible */
result = NULL;
@@ -261,7 +261,8 @@ GDataType *get_type_from_dex_pool(GDexFormat *format, uint32_t index)
if (!read_dex_string_data_item(format, &addr, &str_data))
goto gtfdp_error;
- format->types[index] = demangle_type(G_TYPE_DEX_DEMANGLER, (char *)str_data.data);
+ demangler = G_BIN_FORMAT(format)->demangler;
+ format->types[index] = g_compiler_demangler_decode_type(demangler, (char *)str_data.data);
}
diff --git a/plugins/dexbnf/Makefile.am b/plugins/dexbnf/Makefile.am
new file mode 100644
index 0000000..08e0680
--- /dev/null
+++ b/plugins/dexbnf/Makefile.am
@@ -0,0 +1,27 @@
+
+lib_LTLIBRARIES = libdexbnf.la
+
+libdir = $(pluginsdir)
+
+libdexbnf_la_SOURCES = \
+ context.h context.c \
+ core.h core.c \
+ demangler.h demangler.c \
+ simple.h simple.c \
+ shorty.h shorty.c \
+ type.h type.c
+
+libdexbnf_la_CFLAGS = $(AM_CFLAGS)
+
+libdexbnf_la_LIBADD = \
+ python/libdexbnfpython.la
+
+libdexbnf_la_LDFLAGS = \
+ $(LIBPYTHON_LIBS) $(LIBPYGOBJECT_LIBS)
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) -I$(top_srcdir)/src
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+SUBDIRS = python
diff --git a/plugins/dexbnf/context.c b/plugins/dexbnf/context.c
new file mode 100644
index 0000000..9a6037a
--- /dev/null
+++ b/plugins/dexbnf/context.c
@@ -0,0 +1,209 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * context.c - fourniture de contexte aux phases de décodage Dex
+ *
+ * Copyright (C) 2018 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 "context.h"
+
+
+#include <mangling/context-int.h>
+
+
+#include "shorty.h"
+#include "type.h"
+
+
+
+/* Contexte de décodage Dex (instance) */
+struct _GDexDemangling
+{
+ GDemanglingContext parent; /* A laisser en premier */
+
+};
+
+/* Contexte de décodage Dex (classe) */
+struct _GDexDemanglingClass
+{
+ GDemanglingContextClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des contextes de décodage. */
+static void g_dex_demangling_class_init(GDexDemanglingClass *);
+
+/* Initialise une instance de contexte pour décodage. */
+static void g_dex_demangling_init(GDexDemangling *);
+
+/* Supprime toutes les références externes. */
+static void g_dex_demangling_dispose(GDexDemangling *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_dex_demangling_finalize(GDexDemangling *);
+
+/* Décode une définition de type pour Dex. */
+static GDataType *g_dex_demangling_decode_type(GDexDemangling *);
+
+/* Décode une définition de routine pour Dex. */
+static GBinRoutine *g_dex_demangling_decode_routine(GDexDemangling *);
+
+
+
+/* Indique le type défini pour un contexte de décodage. */
+G_DEFINE_TYPE(GDexDemangling, g_dex_demangling, G_TYPE_DEMANGLING_CONTEXT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des contextes de décodage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_demangling_class_init(GDexDemanglingClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GDemanglingContextClass *context; /* Version de base du contexte */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_dex_demangling_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_dex_demangling_finalize;
+
+ context = G_DEMANGLING_CONTEXT_CLASS(klass);
+
+ context->decode_type = (decode_type_fc)g_dex_demangling_decode_type;
+ context->decode_routine = (decode_routine_fc)g_dex_demangling_decode_routine;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : context = instance à initialiser. *
+* *
+* Description : Initialise une instance de contexte pour décodage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_demangling_init(GDexDemangling *context)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : demangler = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_demangling_dispose(GDexDemangling *context)
+{
+ G_OBJECT_CLASS(g_dex_demangling_parent_class)->dispose(G_OBJECT(context));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : demangler = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dex_demangling_finalize(GDexDemangling *context)
+{
+ G_OBJECT_CLASS(g_dex_demangling_parent_class)->finalize(G_OBJECT(context));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : context = environnement de décodage à manipuler. *
+* *
+* Description : Décode une définition de type pour Dex. *
+* *
+* Retour : Nouvelle instance créée ou NULL en cas d'erreur fatale. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *g_dex_demangling_decode_type(GDexDemangling *context)
+{
+ GDataType *result; /* Type construit à retourner */
+ GDemanglingContext *base; /* Autre version du contexte */
+
+ base = G_DEMANGLING_CONTEXT(context);
+
+ result = dtd_type_descriptor(&base->buffer);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : context = environnement de décodage à manipuler. *
+* *
+* Description : Décode une définition de routine pour Dex. *
+* *
+* Retour : Nouvelle instance créée ou NULL en cas d'erreur fatale. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBinRoutine *g_dex_demangling_decode_routine(GDexDemangling *context)
+{
+ GBinRoutine *result; /* Routine en place à retourner */
+ GDemanglingContext *base; /* Autre version du contexte */
+
+ base = G_DEMANGLING_CONTEXT(context);
+
+ result = dsd_shorty_descriptor(&base->buffer);
+
+ return result;
+
+}
diff --git a/plugins/dexbnf/context.h b/plugins/dexbnf/context.h
new file mode 100644
index 0000000..6ac8674
--- /dev/null
+++ b/plugins/dexbnf/context.h
@@ -0,0 +1,52 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * context.h - prototypes pour la fourniture de contexte aux phases de décodage Dex
+ *
+ * Copyright (C) 2018 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_DEXBNF_CONTEXT_H
+#define _PLUGINS_DEXBNF_CONTEXT_H
+
+
+#include <glib-object.h>
+
+
+
+#define G_TYPE_DEX_DEMANGLING g_dex_demangling_get_type()
+#define G_DEX_DEMANGLING(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_DEX_DEMANGLING, GDexDemangling))
+#define G_IS_DEX_DEMANGLING(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_DEX_DEMANGLING))
+#define G_DEX_DEMANGLING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEX_DEMANGLING, GDexDemanglingClass))
+#define G_IS_DEX_DEMANGLING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEX_DEMANGLING))
+#define G_DEX_DEMANGLING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEX_DEMANGLING, GDexDemanglingClass))
+
+
+/* Contexte de décodage Dex (instance) */
+typedef struct _GDexDemangling GDexDemangling;
+
+/* Contexte de décodage Dex (classe) */
+typedef struct _GDexDemanglingClass GDexDemanglingClass;
+
+
+/* Indique le type défini pour un contexte de décodage Dex. */
+GType g_dex_demangling_get_type(void);
+
+
+
+#endif /* _PLUGINS_DEXBNF_CONTEXT_H */
diff --git a/plugins/dexbnf/core.c b/plugins/dexbnf/core.c
new file mode 100644
index 0000000..837c4c1
--- /dev/null
+++ b/plugins/dexbnf/core.c
@@ -0,0 +1,64 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * core.c - intégration du décodage pour symboles Dex
+ *
+ * Copyright (C) 2018 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/demanglers.h>
+#include <plugins/plugin-def.h>
+
+
+#include "demangler.h"
+#include "python/module.h"
+
+
+
+DEFINE_CHRYSALIDE_PLUGIN("dexbnf", "Symbol demangler for Dex", "0.1.0",
+ RL("PyChrysalide"), AL(PGA_PLUGIN_INIT));
+
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à manipuler. *
+* *
+* Description : Prend acte du chargement du greffon. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin)
+{
+ bool result; /* Bilan à retourner */
+
+ result = register_demangler_type("dex", G_TYPE_DEX_DEMANGLER);
+
+ if (result)
+ result = add_mangling_dexbnf_module_to_python_module();
+
+ return result;
+
+}
diff --git a/plugins/dexbnf/core.h b/plugins/dexbnf/core.h
new file mode 100644
index 0000000..9e26faf
--- /dev/null
+++ b/plugins/dexbnf/core.h
@@ -0,0 +1,38 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * core.h - prototypes pour l'intégration du décodage pour symboles Dex
+ *
+ * Copyright (C) 2018 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_DEXBNF_CORE_H
+#define _PLUGINS_DEXBNF_CORE_H
+
+
+#include <plugins/plugin.h>
+#include <plugins/plugin-int.h>
+
+
+
+/* Prend acte du chargement du greffon. */
+G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *);
+
+
+
+#endif /* _PLUGINS_DEXBNF_CORE_H */
diff --git a/src/mangling/dex/context.c b/plugins/dexbnf/demangler.c
index 9dd9b9c..e021b45 100644
--- a/src/mangling/dex/context.c
+++ b/plugins/dexbnf/demangler.c
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * context.c - contextes de décodage DEX
+ * demangler.c - décodage des noms d'éléments
*
- * Copyright (C) 2015-2017 Cyrille Bagard
+ * Copyright (C) 2018 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -21,32 +21,35 @@
*/
-#include "context.h"
+#include "demangler.h"
+
+
+#include <mangling/demangler-int.h>
-#include "../context-int.h"
+#include "context.h"
-/* Contexte de décodage DEX (instance) */
+/* Décodeur de désignations Dex (instance) */
struct _GDexDemangler
{
- GDemanglingContext parent; /* A laisser en premier */
+ GCompDemangler parent; /* A laisser en premier */
};
-/* Contexte de décodage DEX (classe) */
+/* Décodeur de désignations Dex (classe) */
struct _GDexDemanglerClass
{
- GDemanglingContextClass parent; /* A laisser en premier */
+ GCompDemanglerClass parent; /* A laisser en premier */
};
-/* Initialise la classe des contextes de décodage DEX. */
+/* Initialise la classe des décodeurs de désignations. */
static void g_dex_demangler_class_init(GDexDemanglerClass *);
-/* Initialise une instance de contexte pour décodage DEX. */
+/* Initialise une instance de décodeur de désignations. */
static void g_dex_demangler_init(GDexDemangler *);
/* Supprime toutes les références externes. */
@@ -56,23 +59,16 @@ static void g_dex_demangler_dispose(GDexDemangler *);
static void g_dex_demangler_finalize(GDexDemangler *);
-/* Procède au décodage d'une chaîne de caractères. */
-extern bool demangle_dex_routine(GDexDemangler *, const char *);
-
-/* Procède au décodage d'une chaîne de caractères. */
-extern bool demangle_dex_type(GDexDemangler *, const char *);
-
-
-/* Indique le type défini pour un contexte de décodage DEX. */
-G_DEFINE_TYPE(GDexDemangler, g_dex_demangler, G_TYPE_DEMANGLING_CONTEXT);
+/* Indique le type défini pour un décodeur de désignations. */
+G_DEFINE_TYPE(GDexDemangler, g_dex_demangler, G_TYPE_COMP_DEMANGLER);
/******************************************************************************
* *
* Paramètres : klass = classe à initialiser. *
* *
-* Description : Initialise la classe des contextes de décodage DEX. *
+* Description : Initialise la classe des décodeurs de désignations Dex. *
* *
* Retour : - *
* *
@@ -83,17 +79,18 @@ G_DEFINE_TYPE(GDexDemangler, g_dex_demangler, G_TYPE_DEMANGLING_CONTEXT);
static void g_dex_demangler_class_init(GDexDemanglerClass *klass)
{
GObjectClass *object; /* Autre version de la classe */
- GDemanglingContextClass *context; /* Version parente */
+ GCompDemanglerClass *demangler; /* Version parente basique */
object = G_OBJECT_CLASS(klass);
object->dispose = (GObjectFinalizeFunc/* ! */)g_dex_demangler_dispose;
object->finalize = (GObjectFinalizeFunc)g_dex_demangler_finalize;
- context = G_DEMANGLING_CONTEXT_CLASS(klass);
+ demangler = G_COMP_DEMANGLER_CLASS(klass);
+
+ demangler->can_demangle = (can_be_demangled_fc)NULL;
- context->demangle_type = (demangle_fc)demangle_dex_type;
- context->demangle_routine = (demangle_fc)demangle_dex_routine;
+ demangler->context_type = G_TYPE_DEX_DEMANGLING;
}
@@ -102,7 +99,7 @@ static void g_dex_demangler_class_init(GDexDemanglerClass *klass)
* *
* Paramètres : demangler = instance à initialiser. *
* *
-* Description : Initialise une instance de contexte pour décodage DEX. *
+* Description : Initialise une instance de décodeur de désignations Dex. *
* *
* Retour : - *
* *
@@ -152,3 +149,26 @@ static void g_dex_demangler_finalize(GDexDemangler *demangler)
G_OBJECT_CLASS(g_dex_demangler_parent_class)->finalize(G_OBJECT(demangler));
}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Met en place un nouveau décodeur de symboles pour Dex. *
+* *
+* Retour : Instance obtenue ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GCompDemangler *g_dex_demangler_new(void)
+{
+ GDexDemangler *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_DEX_DEMANGLER, NULL);
+
+ return G_COMP_DEMANGLER(result);
+
+}
diff --git a/plugins/dexbnf/demangler.h b/plugins/dexbnf/demangler.h
new file mode 100644
index 0000000..9d997da
--- /dev/null
+++ b/plugins/dexbnf/demangler.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demangler.h - prototypes pour le décodage des noms d'éléments Dex
+ *
+ * Copyright (C) 2018 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_DEXBNF_DEMANGLER_H
+#define _PLUGINS_DEXBNF_DEMANGLER_H
+
+
+#include <glib-object.h>
+
+
+#include <mangling/demangler.h>
+
+
+
+#define G_TYPE_DEX_DEMANGLER g_dex_demangler_get_type()
+#define G_DEX_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_DEX_DEMANGLER, GDexDemangler))
+#define G_IS_DEX_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_DEX_DEMANGLER))
+#define G_DEX_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEX_DEMANGLER, GDexDemanglerClass))
+#define G_IS_DEX_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEX_DEMANGLER))
+#define G_DEX_DEMANGLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEX_DEMANGLER, GDexDemanglerClass))
+
+
+/* Décodeur de désignations Dex (instance) */
+typedef struct _GDexDemangler GDexDemangler;
+
+/* Décodeur de désignations Dex (classe) */
+typedef struct _GDexDemanglerClass GDexDemanglerClass;
+
+
+/* Indique le type défini pour un décodeur de désignations Dex. */
+GType g_dex_demangler_get_type(void);
+
+/* Met en place un nouveau décodeur de symboles pour Dex. */
+GCompDemangler *g_dex_demangler_new(void);
+
+
+
+#endif /* _PLUGINS_DEXBNF_DEMANGLER_H */
diff --git a/plugins/dexbnf/python/Makefile.am b/plugins/dexbnf/python/Makefile.am
new file mode 100644
index 0000000..4d60a1c
--- /dev/null
+++ b/plugins/dexbnf/python/Makefile.am
@@ -0,0 +1,15 @@
+
+noinst_LTLIBRARIES = libdexbnfpython.la
+
+libdexbnfpython_la_SOURCES = \
+ demangler.h demangler.c \
+ module.h module.c
+
+
+libdexbnfpython_la_LDFLAGS =
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+ -I$(top_srcdir)/src
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/plugins/dexbnf/python/demangler.c b/plugins/dexbnf/python/demangler.c
new file mode 100644
index 0000000..f47eefe
--- /dev/null
+++ b/plugins/dexbnf/python/demangler.c
@@ -0,0 +1,145 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demangler.c - équivalent Python du fichier "plugins/dexbnf/demangler.c"
+ *
+ * Copyright (C) 2018 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 "demangler.h"
+
+
+#include <pygobject.h>
+
+
+#include <plugins/pychrysalide/helpers.h>
+#include <plugins/pychrysalide/mangling/demangler.h>
+
+
+#include "../demangler.h"
+
+
+
+/* Crée un nouvel objet Python de type 'DexDemangler'. */
+static PyObject *py_dex_demangler_new(PyTypeObject *, PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de l'objet à instancier. *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Crée un nouvel objet Python de type 'DexDemangler'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_dex_demangler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Instance à retourner */
+ GCompDemangler *demangler; /* Instance à transposer */
+
+ demangler = g_dex_demangler_new();
+
+ result = pygobject_new(G_OBJECT(demangler));
+
+ g_object_unref(G_OBJECT(demangler));
+
+ return (PyObject *)result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_dex_demangler_type(void)
+{
+ static PyMethodDef py_dex_demangler_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_dex_demangler_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_dex_demangler_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.mangling.DexDemangler",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "PyChrysalide Dex demangler",
+
+ .tp_methods = py_dex_demangler_methods,
+ .tp_getset = py_dex_demangler_getseters,
+ .tp_new = (newfunc)py_dex_demangler_new
+
+ };
+
+ return &py_dex_demangler_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.mangling.DexDemangler'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_dex_demangler(PyObject *module)
+{
+ PyTypeObject *py_dex_demangler_type; /* Type Python 'ElfFormat' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_dex_demangler_type = get_python_dex_demangler_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_DEX_DEMANGLER,
+ py_dex_demangler_type, get_python_compiler_demangler_type()))
+ return false;
+
+ return true;
+
+}
diff --git a/plugins/dexbnf/python/demangler.h b/plugins/dexbnf/python/demangler.h
new file mode 100644
index 0000000..af56289
--- /dev/null
+++ b/plugins/dexbnf/python/demangler.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demangler.h - prototypes pour l'équivalent Python du fichier "plugins/dexbnf/demangler.h"
+ *
+ * Copyright (C) 2018 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_DEXBNF_PYTHON_DEMANGLER_H
+#define _PLUGINS_DEXBNF_PYTHON_DEMANGLER_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_dex_demangler_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.format.elf.ElfFormat'. */
+bool register_python_dex_demangler(PyObject *);
+
+
+
+#endif /* _PLUGINS_DEXBNF_PYTHON_DEMANGLER_H */
diff --git a/plugins/dexbnf/python/module.c b/plugins/dexbnf/python/module.c
new file mode 100644
index 0000000..07c6ad6
--- /dev/null
+++ b/plugins/dexbnf/python/module.c
@@ -0,0 +1,61 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire dexbnf en tant que module
+ *
+ * Copyright (C) 2018 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 <Python.h>
+
+
+#include <plugins/pychrysalide/access.h>
+
+
+#include "demangler.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Etend le module 'mangling' avec des compléments pour Dex. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_mangling_dexbnf_module_to_python_module(void)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *super; /* Module à compléter */
+
+ super = get_access_to_python_module("pychrysalide.mangling");
+
+ result = register_python_dex_demangler(super);
+
+ return result;
+
+}
diff --git a/plugins/dexbnf/python/module.h b/plugins/dexbnf/python/module.h
new file mode 100644
index 0000000..bfc3525
--- /dev/null
+++ b/plugins/dexbnf/python/module.h
@@ -0,0 +1,38 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire dexbnf en tant que module
+ *
+ * Copyright (C) 2018 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_DEXBNF_PYTHON_MODULE_H
+#define _PLUGINS_DEXBNF_PYTHON_MODULE_H
+
+
+#include <stdbool.h>
+
+
+
+/* Etend le module 'mangling' avec des compléments pour Dex. */
+bool add_mangling_dexbnf_module_to_python_module(void);
+
+
+
+#endif /* _PLUGINS_DEXBNF_PYTHON_MODULE_H */
diff --git a/plugins/dexbnf/shorty.c b/plugins/dexbnf/shorty.c
new file mode 100644
index 0000000..0b452df
--- /dev/null
+++ b/plugins/dexbnf/shorty.c
@@ -0,0 +1,227 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * shorty.c - décodage de routines pour Dex
+ *
+ * Copyright (C) 2018 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 "shorty.h"
+
+
+#include <analysis/types/basic.h>
+#include <analysis/types/cse.h>
+
+
+
+/* Extrait un type particulier dans un décodage Dex. */
+static GDataType *dsd_shorty_return_type(input_buffer *);
+
+/* Extrait un type particulier dans un décodage Dex. */
+static GDataType *dsd_shorty_field_type(input_buffer *, char);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* *
+* Description : Extrait un routine particulière depuis un codage Dex. *
+* *
+* Retour : Nouveau type mis en place ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinRoutine *dsd_shorty_descriptor(input_buffer *buffer)
+{
+ GBinRoutine *result; /* Type à retourner */
+ GDataType *type; /* Description de type obtenue */
+ char ahead; /* Caractère déterminant lu */
+ GBinVariable *var; /* Argument de routine */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * ShortyDescriptor →
+ * ShortyReturnType (ShortyFieldType)*
+ *
+ */
+
+ result = g_binary_routine_new();
+
+ /* Retour */
+
+ type = dsd_shorty_return_type(buffer);
+
+ if (type == NULL)
+ goto dsd_error;
+
+ else
+ g_binary_routine_set_return_type(result, type);
+
+ /* Arguments */
+
+ for (ahead = text_input_buffer_next_char(buffer);
+ ahead != '\0';
+ ahead = text_input_buffer_next_char(buffer))
+ {
+ type = dsd_shorty_field_type(buffer, ahead);
+
+ if (type == NULL)
+ goto dsd_error;
+
+ else
+ {
+ var = g_binary_variable_new(type);
+ g_binary_routine_add_arg(result, var);
+ }
+
+ }
+
+ return result;
+
+ dsd_error:
+
+ g_object_unref(G_OBJECT(result));
+
+ return NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* *
+* Description : Extrait un type particulier dans un décodage Dex. *
+* *
+* Retour : Nouveau type mis en place ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *dsd_shorty_return_type(input_buffer *buffer)
+{
+ GDataType *result; /* Type à retourner */
+ char ahead; /* Caractère déterminant lu */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * ShortyReturnType →
+ * 'V'
+ * | ShortyFieldType
+ *
+ */
+
+ ahead = text_input_buffer_next_char(buffer);
+
+ if (ahead == 'V')
+ result = g_basic_type_new(BTP_VOID);
+
+ else
+ result = dsd_shorty_field_type(buffer, ahead);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* ahead = caractère déjà dépilé de ces données. *
+* *
+* Description : Extrait un type particulier dans un décodage Dex. *
+* *
+* Retour : Nouveau type mis en place ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *dsd_shorty_field_type(input_buffer *buffer, char ahead)
+{
+ GDataType *result; /* Type à retourner */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * ShortyFieldType →
+ * 'Z'
+ * | 'B'
+ * | 'S'
+ * | 'C'
+ * | 'I'
+ * | 'J'
+ * | 'F'
+ * | 'D'
+ * | 'L'
+ *
+ */
+
+ switch (ahead)
+ {
+ case 'Z':
+ result = g_basic_type_new(BTP_BOOL);
+ break;
+
+ case 'B':
+ result = g_basic_type_new(BTP_UCHAR);
+ break;
+
+ case 'S':
+ result = g_basic_type_new(BTP_SHORT);
+ break;
+
+ case 'C':
+ result = g_basic_type_new(BTP_CHAR);
+ break;
+
+ case 'I':
+ result = g_basic_type_new(BTP_INT);
+ break;
+
+ case 'J':
+ result = g_basic_type_new(BTP_LONG);
+ break;
+
+ case 'F':
+ result = g_basic_type_new(BTP_FLOAT);
+ break;
+
+ case 'D':
+ result = g_basic_type_new(BTP_DOUBLE);
+ break;
+
+ case 'L':
+ result = g_class_enum_type_new(CET_CLASS, NULL);
+ break;
+
+ default:
+ result = NULL;
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/dexbnf/shorty.h b/plugins/dexbnf/shorty.h
new file mode 100644
index 0000000..0f91a79
--- /dev/null
+++ b/plugins/dexbnf/shorty.h
@@ -0,0 +1,38 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * shorty.h - prototypes pour le décodage de routines pour Dex
+ *
+ * Copyright (C) 2018 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_DEXBNF_SHORTY_H
+#define _PLUGINS_DEXBNF_SHORTY_H
+
+
+#include <analysis/routine.h>
+#include <common/ibuf.h>
+
+
+
+/* Extrait un routine particulière depuis un codage Dex. */
+GBinRoutine *dsd_shorty_descriptor(input_buffer *);
+
+
+
+#endif /* _PLUGINS_DEXBNF_SHORTY_H */
diff --git a/plugins/dexbnf/simple.c b/plugins/dexbnf/simple.c
new file mode 100644
index 0000000..43bd467
--- /dev/null
+++ b/plugins/dexbnf/simple.c
@@ -0,0 +1,163 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * simple.c - décodage de simples chaînes de caractères Dex
+ *
+ * Copyright (C) 2018 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 "simple.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include <common/utf8.h>
+
+
+
+/* Extrait un simple caractère depuis un codage Dex. */
+static size_t dcd_simple_name_char(input_buffer *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* *
+* Description : Extrait une simple chaîne de caractères depuis un codage Dex.*
+* *
+* Retour : Chaîne MUTF-8 terminée par un octet nul ou NULL si erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *dcd_simple_name(input_buffer *buffer)
+{
+ char *result; /* Nom extrait à renvoyer */
+ const char *start; /* Conservation du départ */
+ size_t count; /* Taille du nom constitué */
+ size_t extra; /* Taille de nouveau caractère */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * SimpleName →
+ * SimpleNameChar (SimpleNameChar)*
+ *
+ */
+
+ start = get_input_buffer_text_access(buffer);
+
+ count = 0;
+
+ do
+ {
+ extra = dcd_simple_name_char(buffer);
+ count += extra;
+ }
+ while (extra > 0);
+
+ if (count == 0)
+ result = NULL;
+
+ else
+ {
+ result = malloc((count + 1) * sizeof(char));
+
+ memcpy(result, start, count);
+ result[count] = '\0';
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* *
+* Description : Extrait un simple caractère depuis un codage Dex. *
+* *
+* Retour : quantité de données consommées, 0 en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static size_t dcd_simple_name_char(input_buffer *buffer)
+{
+ size_t result; /* Avancée à retourner */
+ const char *text; /* Accès au texte à relire */
+ size_t remaining; /* Quantité restante */
+ unichar_t wc; /* Caractère étendu lu */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * SimpleNameChar →
+ * 'A' … 'Z'
+ * | 'a' … 'z'
+ * | '0' … '9'
+ * | '$'
+ * | '-'
+ * | '_'
+ * | U+00a1 … U+1fff
+ * | U+2010 … U+2027
+ * | U+2030 … U+d7ff
+ * | U+e000 … U+ffef
+ * | U+10000 … U+10ffff
+ *
+ */
+
+ text = get_input_buffer_text_access(buffer);
+ remaining = count_input_buffer_remaining(buffer);
+
+ wc = decode_utf8_char(text, remaining, &result);
+
+ if (IS_UTF8_ERROR(wc))
+ return 0;
+
+ switch (wc)
+ {
+ case 'A' ... 'Z':
+ case 'a' ... 'z':
+ case '0' ... '9':
+ case '$':
+ case '-':
+ case '_':
+ case 0x00a1 ... 0x1fff:
+ case 0x2010 ... 0x2027:
+ case 0x2030 ... 0xd7ff:
+ case 0xe000 ... 0xffef:
+ case 0x10000 ... 0x10ffff:
+ advance_input_buffer(buffer, result);
+ break;
+
+ default:
+ result = 0;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/dexbnf/simple.h b/plugins/dexbnf/simple.h
new file mode 100644
index 0000000..d583515
--- /dev/null
+++ b/plugins/dexbnf/simple.h
@@ -0,0 +1,37 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * simple.h - prototypes pour le décodage de simples chaînes de caractères Dex
+ *
+ * Copyright (C) 2018 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_DEXBNF_SIMPLE_H
+#define _PLUGINS_DEXBNF_SIMPLE_H
+
+
+#include <common/ibuf.h>
+
+
+
+/* Extrait une simple chaîne de caractères depuis un codage Dex. */
+char *dcd_simple_name(input_buffer *);
+
+
+
+#endif /* _PLUGINS_DEXBNF_SIMPLE_H */
diff --git a/plugins/dexbnf/type.c b/plugins/dexbnf/type.c
new file mode 100644
index 0000000..f77f0e5
--- /dev/null
+++ b/plugins/dexbnf/type.c
@@ -0,0 +1,316 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.c - décodage de types pour Dex
+ *
+ * Copyright (C) 2018 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 "type.h"
+
+
+#include <analysis/types/basic.h>
+#include <analysis/types/cse.h>
+#include <analysis/types/encaps.h>
+
+
+#include "simple.h"
+
+
+
+/* Extrait un type particulier dans un décodage Dex. */
+static GDataType *dtd_full_class_name(input_buffer *);
+
+/* Extrait un type particulier dans un décodage Dex. */
+static GDataType *dtd_field_type_descriptor(input_buffer *, char);
+
+/* Extrait un type particulier dans un décodage Dex. */
+static GDataType *dtd_non_array_field_type_descriptor(input_buffer *, char);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* *
+* Description : Extrait un type particulier dans un décodage Dex. *
+* *
+* Retour : Nouveau type mis en place ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *dtd_full_class_name(input_buffer *buffer)
+{
+ GDataType *result; /* Classe à retourner */
+ char *name; /* Désignation récupérée */
+ size_t saved; /* Point de sauvegarde */
+ char next; /* Prochain caractère obtenu */
+ GDataType *ns; /* Espace de nom à attribuer */
+
+ /**
+ * Les règles traitées sont les suivantes :
+ *
+ * FullClassName →
+ * OptionalPackagePrefix SimpleName
+ * OptionalPackagePrefix →
+ * (SimpleName '/')*
+ *
+ */
+
+ /* Premier étage... */
+
+ name = dcd_simple_name(buffer);
+
+ if (name == NULL)
+ {
+ result = NULL;
+ goto dfcn_exit;
+ }
+
+ else
+ result = g_class_enum_type_new(CET_CLASS, name);
+
+ /* Eventuels autres étages précédents */
+
+ do
+ {
+ save_input_buffer_pos(buffer, &saved);
+
+ next = text_input_buffer_next_char(buffer);
+
+ if (next != '/')
+ {
+ restore_input_buffer_pos(buffer, saved);
+ goto dfcn_exit;
+ }
+
+ name = dcd_simple_name(buffer);
+
+ if (name == NULL)
+ {
+ restore_input_buffer_pos(buffer, saved);
+ goto dfcn_exit;
+ }
+
+ ns = result;
+
+ result = g_class_enum_type_new(CET_CLASS, name);
+
+ g_data_type_set_namespace(result, ns);
+ g_object_unref(ns);
+
+ }
+ while (1);
+
+ dfcn_exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* *
+* Description : Extrait un type particulier dans un décodage Dex. *
+* *
+* Retour : Nouveau type mis en place ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *dtd_type_descriptor(input_buffer *buffer)
+{
+ GDataType *result; /* Type à retourner */
+ char ahead; /* Caractère déterminant lu */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * TypeDescriptor →
+ * 'V'
+ * | FieldTypeDescriptor
+ *
+ */
+
+ ahead = text_input_buffer_next_char(buffer);
+
+ if (ahead == 'V')
+ result = g_basic_type_new(BTP_VOID);
+
+ else
+ result = dtd_field_type_descriptor(buffer, ahead);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* ahead = caractère déjà dépilé de ces données. *
+* *
+* Description : Extrait un type particulier dans un décodage Dex. *
+* *
+* Retour : Nouveau type mis en place ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *dtd_field_type_descriptor(input_buffer *buffer, char ahead)
+{
+ GDataType *result; /* Type à retourner */
+ size_t dim; /* Dimension éventuelle */
+ GDataType *descriptor; /* (Sous-)type à charger */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * FieldTypeDescriptor →
+ * NonArrayFieldTypeDescriptor
+ * | ('[' * 1…255) NonArrayFieldTypeDescriptor
+ *
+ */
+
+ dim = 0;
+
+ while (ahead == '[')
+ {
+ dim++;
+ ahead = text_input_buffer_next_char(buffer);
+ }
+
+ descriptor = dtd_non_array_field_type_descriptor(buffer, ahead);
+
+ if (dim == 0)
+ result = descriptor;
+
+ else
+ {
+ result = g_encapsulated_type_new(ECT_ARRAY, descriptor);
+
+ g_encapsulated_type_set_dimension(G_ENCAPSULATED_TYPE(result), dim);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon contenant les données utiles. *
+* ahead = caractère déjà dépilé de ces données. *
+* *
+* Description : Extrait un type particulier dans un décodage Dex. *
+* *
+* Retour : Nouveau type mis en place ou NULL en cas d'erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *dtd_non_array_field_type_descriptor(input_buffer *buffer, char ahead)
+{
+ GDataType *result; /* Type à retourner */
+ char check; /* Vérification de conformité */
+
+ /**
+ * La règle traitée est la suivante :
+ *
+ * NonArrayFieldTypeDescriptor →
+ * 'Z'
+ * | 'B'
+ * | 'S'
+ * | 'C'
+ * | 'I'
+ * | 'J'
+ * | 'F'
+ * | 'D'
+ * | 'L' FullClassName ';'
+ *
+ */
+
+ switch (ahead)
+ {
+ case 'Z':
+ result = g_basic_type_new(BTP_BOOL);
+ break;
+
+ case 'B':
+ result = g_basic_type_new(BTP_UCHAR);
+ break;
+
+ case 'S':
+ result = g_basic_type_new(BTP_SHORT);
+ break;
+
+ case 'C':
+ result = g_basic_type_new(BTP_CHAR);
+ break;
+
+ case 'I':
+ result = g_basic_type_new(BTP_INT);
+ break;
+
+ case 'J':
+ result = g_basic_type_new(BTP_LONG);
+ break;
+
+ case 'F':
+ result = g_basic_type_new(BTP_FLOAT);
+ break;
+
+ case 'D':
+ result = g_basic_type_new(BTP_DOUBLE);
+ break;
+
+ case 'L':
+
+ result = dtd_full_class_name(buffer);
+
+ if (result != NULL)
+ {
+ check = text_input_buffer_next_char(buffer);
+
+ if (check != ';')
+ {
+ g_object_unref(G_OBJECT(result));
+ result = NULL;
+ }
+
+ }
+
+ break;
+
+ default:
+ result = NULL;
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/dexbnf/type.h b/plugins/dexbnf/type.h
new file mode 100644
index 0000000..045a5fe
--- /dev/null
+++ b/plugins/dexbnf/type.h
@@ -0,0 +1,38 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.h - prototypes pour le décodage de types pour Dex
+ *
+ * Copyright (C) 2018 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_DEXBNF_TYPE_H
+#define _PLUGINS_DEXBNF_TYPE_H
+
+
+#include <analysis/type.h>
+#include <common/ibuf.h>
+
+
+
+/* Extrait un type particulier dans un décodage Dex. */
+GDataType *dtd_type_descriptor(input_buffer *);
+
+
+
+#endif /* _PLUGINS_DEXBNF_TYPE_H */
diff --git a/plugins/pychrysalide/Makefile.am b/plugins/pychrysalide/Makefile.am
index 0648bb3..3e6f0cd 100644
--- a/plugins/pychrysalide/Makefile.am
+++ b/plugins/pychrysalide/Makefile.am
@@ -20,7 +20,8 @@ pychrysalide_la_LIBADD = \
format/libpychrysaformat.la \
glibext/libpychrysaglibext.la \
gtkext/libpychrysagtkext.la \
- gui/libpychrysagui.la
+ gui/libpychrysagui.la \
+ mangling/libpychrysamangling.la
pychrysalide_la_LDFLAGS = -module -avoid-version \
$(LIBPYTHON_LIBS) $(LIBPYGOBJECT_LIBS) \
@@ -33,4 +34,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
+SUBDIRS = analysis arch common core debug format glibext gtkext gui mangling
diff --git a/plugins/pychrysalide/analysis/Makefile.am b/plugins/pychrysalide/analysis/Makefile.am
index c1639e7..2379b19 100644
--- a/plugins/pychrysalide/analysis/Makefile.am
+++ b/plugins/pychrysalide/analysis/Makefile.am
@@ -7,7 +7,8 @@ libpychrysaanalysis_la_SOURCES = \
content.h content.c \
loaded.h loaded.c \
module.h module.c \
- routine.h routine.c
+ routine.h routine.c \
+ type.h type.c
libpychrysaanalysis_la_LIBADD = \
contents/libpychrysaanalysiscontents.la \
diff --git a/plugins/pychrysalide/analysis/module.c b/plugins/pychrysalide/analysis/module.c
index f4a0f5b..c9a9276 100644
--- a/plugins/pychrysalide/analysis/module.c
+++ b/plugins/pychrysalide/analysis/module.c
@@ -33,6 +33,7 @@
#include "content.h"
#include "loaded.h"
#include "routine.h"
+#include "type.h"
#include "contents/module.h"
#include "db/module.h"
#include "../access.h"
@@ -91,6 +92,7 @@ bool add_analysis_module_to_python_module(PyObject *super)
result &= register_python_instr_block(module);
//result &= register_python_binary_content(module);
result &= register_python_binary_routine(module);
+ result &= register_python_data_type(module);
result &= add_analysis_contents_module_to_python_module(module);
result &= add_analysis_db_module_to_python_module(module);
diff --git a/plugins/pychrysalide/analysis/routine.c b/plugins/pychrysalide/analysis/routine.c
index 37f36a7..d0abd72 100644
--- a/plugins/pychrysalide/analysis/routine.c
+++ b/plugins/pychrysalide/analysis/routine.c
@@ -42,6 +42,9 @@
+/* Décrit la routine fournie sous forme de caractères. */
+static PyObject *py_binary_routine_to_str(PyObject *);
+
/* Crée un nouvel objet Python de type 'BinRoutine'. */
static PyObject *py_binary_routine_new(PyTypeObject *, PyObject *, PyObject *);
@@ -58,6 +61,37 @@ static PyObject *py_binary_routine_get_basic_blocks(PyObject *, void *);
/******************************************************************************
* *
+* Paramètres : self = instance d'une routine version Python à traiter. *
+* *
+* Description : Décrit la routine fournie sous forme de caractères. *
+* *
+* Retour : Chaîne de caractère construite pour l'occasion. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_routine_to_str(PyObject *self)
+{
+ PyObject *result; /* Représentation à retourner */
+ GBinRoutine *routine; /* Version native de l'objet */
+ char *desc; /* Description du type */
+
+ routine = G_BIN_ROUTINE(pygobject_get(self));
+
+ desc = g_binary_routine_to_string(routine);
+
+ result = PyUnicode_FromString(desc);
+
+ free(desc);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : type = type de l'objet à instancier. *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
@@ -250,6 +284,8 @@ PyTypeObject *get_python_binary_routine_type(void)
.tp_name = "pychrysalide.analysis.BinRoutine",
+ .tp_str = py_binary_routine_to_str,
+
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = "PyChrysalide binary routine",
diff --git a/plugins/pychrysalide/analysis/type.c b/plugins/pychrysalide/analysis/type.c
new file mode 100644
index 0000000..eea9596
--- /dev/null
+++ b/plugins/pychrysalide/analysis/type.c
@@ -0,0 +1,145 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.c - équivalent Python du fichier "analysis/type.c"
+ *
+ * Copyright (C) 2018 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 "type.h"
+
+
+#include <malloc.h>
+#include <pygobject.h>
+
+
+#include <analysis/type.h>
+
+
+#include "../helpers.h"
+
+
+
+/* Décrit le type fourni sous forme de caractères. */
+static PyObject *py_data_type_to_str(PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instance d'un type version Python à traiter. *
+* *
+* Description : Décrit le type fourni sous forme de caractères. *
+* *
+* Retour : Chaîne de caractère construite pour l'occasion. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_data_type_to_str(PyObject *self)
+{
+ PyObject *result; /* Représentation à retourner */
+ GDataType *type; /* Version native de l'objet */
+ char *desc; /* Description du type */
+
+ type = G_DATA_TYPE(pygobject_get(self));
+
+ desc = g_data_type_to_string(type);
+
+ result = PyUnicode_FromString(desc);
+
+ free(desc);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_data_type_type(void)
+{
+ static PyMethodDef py_data_type_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_data_type_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_data_type_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.DataType",
+
+ .tp_str = py_data_type_to_str,
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide data type",
+
+ .tp_methods = py_data_type_methods,
+ .tp_getset = py_data_type_getseters
+
+ };
+
+ return &py_data_type_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.analysis.DataType'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_data_type(PyObject *module)
+{
+ PyTypeObject *py_data_type_type; /* Type Python 'DataType' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_data_type_type = get_python_data_type_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_DATA_TYPE, py_data_type_type, &PyGObject_Type))
+ return false;
+
+ return true;
+
+}
diff --git a/plugins/pychrysalide/analysis/type.h b/plugins/pychrysalide/analysis/type.h
new file mode 100644
index 0000000..b6b8b95
--- /dev/null
+++ b/plugins/pychrysalide/analysis/type.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.h - prototypes pour l'équivalent Python du fichier "analysis/type.h"
+ *
+ * Copyright (C) 2018 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_PYOIDA_ANALYSIS_TYPE_H
+#define _PLUGINS_PYOIDA_ANALYSIS_TYPE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_data_type_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.DataType'. */
+bool register_python_data_type(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ANALYSIS_TYPE_H */
diff --git a/plugins/pychrysalide/core/Makefile.am b/plugins/pychrysalide/core/Makefile.am
index 71abfa4..d5fdb9f 100644
--- a/plugins/pychrysalide/core/Makefile.am
+++ b/plugins/pychrysalide/core/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libpychrysacore.la
libpychrysacore_la_SOURCES = \
+ demanglers.h demanglers.c \
formats.h formats.c \
logs.h logs.c \
module.h module.c \
diff --git a/plugins/pychrysalide/core/demanglers.c b/plugins/pychrysalide/core/demanglers.c
new file mode 100644
index 0000000..c3c1881
--- /dev/null
+++ b/plugins/pychrysalide/core/demanglers.c
@@ -0,0 +1,160 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demanglers.c - équivalent Python du fichier "core/demanglers.c"
+ *
+ * Copyright (C) 2018 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 "demanglers.h"
+
+
+#include <pygobject.h>
+
+
+#include <core/demanglers.h>
+
+
+#include "../helpers.h"
+
+
+
+/* Fournit le décodeur de désignations correspondant à un type. */
+static PyObject *py_demanglers_get_for_type(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = NULL car méthode statique. *
+* key = nom technique du décodeur recherché. *
+* *
+* Description : Fournit le décodeur de désignations correspondant à un type. *
+* *
+* Retour : Décodeur trouvé et mis en place ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_demanglers_get_for_type(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Désignation à retourner */
+ const char *key; /* Nom court du format */
+ int ret; /* Bilan de lecture des args. */
+ GCompDemangler *demangler; /* Décodeur mis en place */
+
+ ret = PyArg_ParseTuple(args, "s", &key);
+ if (!ret) return NULL;
+
+ demangler = get_compiler_demangler_for_type(key);
+
+ if (demangler != NULL)
+ {
+ result = pygobject_new(G_OBJECT(demangler));
+ Py_INCREF(result);
+
+ g_object_unref(G_OBJECT(demangler));
+
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_demanglers_type(void)
+{
+ static PyMethodDef py_demanglers_methods[] = {
+
+ { "get_for_type", py_demanglers_get_for_type,
+ METH_VARARGS | METH_STATIC,
+ "get_for_type(key, /)\n--\n\nCreate a new demangler for a given type of encoding."
+ },
+ { NULL }
+
+ };
+
+ static PyTypeObject py_demanglers_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.core.demanglers",
+ .tp_basicsize = sizeof(PyObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "Access to the code demanglers",
+
+ .tp_methods = py_demanglers_methods
+
+ };
+
+ return &py_demanglers_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.core.demanglers'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_demanglers(PyObject *module)
+{
+ PyTypeObject *py_demanglers_type; /* Type Python de 'demanglers' */
+ int ret; /* Bilan d'un appel */
+
+ py_demanglers_type = get_python_demanglers_type();
+
+ py_demanglers_type->tp_new = PyType_GenericNew;
+
+ if (PyType_Ready(py_demanglers_type) != 0)
+ return false;
+
+ Py_INCREF(py_demanglers_type);
+ ret = PyModule_AddObject(module, "demanglers", (PyObject *)py_demanglers_type);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pychrysalide/core/demanglers.h b/plugins/pychrysalide/core/demanglers.h
new file mode 100644
index 0000000..b17c4cb
--- /dev/null
+++ b/plugins/pychrysalide/core/demanglers.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demanglers.h - prototypes pour l'équivalent Python du fichier "core/demanglers.h"
+ *
+ * Copyright (C) 2018 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_CORE_DEMANGLERS_H
+#define _PLUGINS_PYCHRYSALIDE_CORE_DEMANGLERS_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_demanglers_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.core.demanglers'. */
+bool register_python_demanglers(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_CORE_DEMANGLERS_H */
diff --git a/plugins/pychrysalide/core/formats.c b/plugins/pychrysalide/core/formats.c
index 621277a..4f7c33a 100644
--- a/plugins/pychrysalide/core/formats.c
+++ b/plugins/pychrysalide/core/formats.c
@@ -115,7 +115,7 @@ PyTypeObject *get_python_formats_type(void)
.tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = "Python object for parameters",
+ .tp_doc = "Access to the code formats",
.tp_methods = py_formats_methods
diff --git a/plugins/pychrysalide/core/logs.c b/plugins/pychrysalide/core/logs.c
index 8a922c1..6476ed0 100644
--- a/plugins/pychrysalide/core/logs.c
+++ b/plugins/pychrysalide/core/logs.c
@@ -201,7 +201,7 @@ PyTypeObject *get_python_logs_type(void)
.tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = "Python object for logs",
+ .tp_doc = "Access to the core log facilities",
.tp_methods = py_logs_methods,
.tp_getset = py_logs_getseters
diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c
index ff7f828..dd89ea0 100644
--- a/plugins/pychrysalide/core/module.c
+++ b/plugins/pychrysalide/core/module.c
@@ -28,6 +28,7 @@
#include <assert.h>
+#include "demanglers.h"
#include "formats.h"
#include "logs.h"
#include "params.h"
@@ -81,6 +82,7 @@ bool add_core_module_to_python_module(PyObject *super)
result = true;
+ result &= register_python_demanglers(module);
result &= register_python_formats(module);
result &= register_python_logs(module);
result &= register_python_params(module);
diff --git a/plugins/pychrysalide/mangling/Makefile.am b/plugins/pychrysalide/mangling/Makefile.am
new file mode 100644
index 0000000..e4f5db6
--- /dev/null
+++ b/plugins/pychrysalide/mangling/Makefile.am
@@ -0,0 +1,18 @@
+
+noinst_LTLIBRARIES = libpychrysamangling.la
+
+libpychrysamangling_la_SOURCES = \
+ demangler.h demangler.c \
+ module.h module.c
+
+libpychrysamangling_la_LIBADD =
+
+libpychrysamangling_la_LDFLAGS =
+
+
+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/mangling/demangler.c b/plugins/pychrysalide/mangling/demangler.c
new file mode 100644
index 0000000..37935c9
--- /dev/null
+++ b/plugins/pychrysalide/mangling/demangler.c
@@ -0,0 +1,219 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demangler.c - équivalent Python du fichier "mangling/demangler.c"
+ *
+ * Copyright (C) 2018 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 "demangler.h"
+
+
+#include <pygobject.h>
+
+
+#include <mangling/demangler.h>
+
+
+#include "../helpers.h"
+
+
+
+/* Tente de décoder une chaîne de caractères donnée en type. */
+static PyObject *py_compiler_demangler_decode_type(PyObject *, PyObject *);
+
+/* Tente de décoder une chaîne de caractères donnée en routine. */
+static PyObject *py_compiler_demangler_decode_routine(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = décodeur à solliciter pour l'opération. *
+* args = chaîne de caractères à décoder. *
+* *
+* Description : Tente de décoder une chaîne de caractères donnée en type. *
+* *
+* Retour : Instance obtenue ou None en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_compiler_demangler_decode_type(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Désignation à retourner */
+ const char *desc; /* Description à traiter */
+ int ret; /* Bilan de lecture des args. */
+ GCompDemangler *demangler; /* Décodeur mis en place */
+ GDataType *type; /* Type de données obtenu */
+
+ ret = PyArg_ParseTuple(args, "s", &desc);
+ if (!ret) return NULL;
+
+ demangler = G_COMP_DEMANGLER(pygobject_get(self));
+
+ type = g_compiler_demangler_decode_type(demangler, desc);
+
+ if (type != NULL)
+ {
+ result = pygobject_new(G_OBJECT(type));
+ Py_INCREF(result);
+
+ g_object_unref(G_OBJECT(type));
+
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = décodeur à solliciter pour l'opération. *
+* args = chaîne de caractères à décoder. *
+* *
+* Description : Tente de décoder une chaîne de caractères donnée en routine. *
+* *
+* Retour : Instance obtenue ou None en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_compiler_demangler_decode_routine(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Désignation à retourner */
+ const char *desc; /* Description à traiter */
+ int ret; /* Bilan de lecture des args. */
+ GCompDemangler *demangler; /* Décodeur mis en place */
+ GBinRoutine *routine; /* Routine obtenue */
+
+ ret = PyArg_ParseTuple(args, "s", &desc);
+ if (!ret) return NULL;
+
+ demangler = G_COMP_DEMANGLER(pygobject_get(self));
+
+ routine = g_compiler_demangler_decode_routine(demangler, desc);
+
+ if (routine != NULL)
+ {
+ result = pygobject_new(G_OBJECT(routine));
+ Py_INCREF(result);
+
+ g_object_unref(G_OBJECT(routine));
+
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_compiler_demangler_type(void)
+{
+ static PyMethodDef py_comp_demangler_methods[] = {
+ {
+ "decode_type", py_compiler_demangler_decode_type,
+ METH_VARARGS,
+ "decode_type(self, desc/)\n--\n\nDemangle a type definition from its string mangled description."
+ },
+ {
+ "decode_routine", py_compiler_demangler_decode_routine,
+ METH_VARARGS,
+ "decode_routine(self, desc/)\n--\n\nDemangle a routine definition from its string mangled description."
+ },
+ { NULL }
+ };
+
+ static PyGetSetDef py_comp_demangler_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_comp_demangler_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.mangling.CompDemangler",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "PyChrysalide generic demangler",
+
+ .tp_methods = py_comp_demangler_methods,
+ .tp_getset = py_comp_demangler_getseters,
+
+ };
+
+ return &py_comp_demangler_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.mangling.DexDemangler'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_compiler_demangler(PyObject *module)
+{
+ PyTypeObject *py_comp_demangler_type; /* Type Python 'CompDemangler' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_comp_demangler_type = get_python_compiler_demangler_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_COMP_DEMANGLER, py_comp_demangler_type, &PyGObject_Type))
+ return false;
+
+ return true;
+
+}
diff --git a/plugins/pychrysalide/mangling/demangler.h b/plugins/pychrysalide/mangling/demangler.h
new file mode 100644
index 0000000..c2094b7
--- /dev/null
+++ b/plugins/pychrysalide/mangling/demangler.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demangler.h - prototypes pour l'équivalent Python du fichier "mangling/demangler.h"
+ *
+ * Copyright (C) 2018 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_MANGLING_DEMANGLER_H
+#define _PLUGINS_PYCHRYSALIDE_MANGLING_DEMANGLER_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_compiler_demangler_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.format.elf.ElfFormat'. */
+bool register_python_compiler_demangler(PyObject *);
+
+
+
+#endif /* _PLUGINS_DEXBNF_PYTHON_DEMANGLER_H */
diff --git a/plugins/pychrysalide/mangling/module.c b/plugins/pychrysalide/mangling/module.c
new file mode 100644
index 0000000..a462e3e
--- /dev/null
+++ b/plugins/pychrysalide/mangling/module.c
@@ -0,0 +1,91 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire mangling en tant que module
+ *
+ * Copyright (C) 2018 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 "demangler.h"
+#include "../access.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute le module 'mangling' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_mangling_module_to_python_module(PyObject *super)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
+ int ret; /* Bilan d'un appel */
+
+ static PyModuleDef py_chrysalide_mangling_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.mangling",
+ .m_doc = "Python module for Chrysalide.mangling",
+
+ .m_size = -1,
+
+ };
+
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_mangling_module);
+ if (module == NULL) return false;
+
+ ret = PyState_AddModule(super, &py_chrysalide_mangling_module);
+ if (ret != 0) goto loading_failed;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.mangling");
+ if (ret != 0) goto loading_failed;
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "mangling", module);
+ if (ret != 0) goto loading_failed;
+
+ result = register_python_compiler_demangler(module);
+
+ if (result)
+ register_access_to_python_module("pychrysalide.mangling", module);
+
+ loading_failed:
+
+ assert(result);
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/mangling/module.h b/plugins/pychrysalide/mangling/module.h
new file mode 100644
index 0000000..126aa7e
--- /dev/null
+++ b/plugins/pychrysalide/mangling/module.h
@@ -0,0 +1,39 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire mangling en tant que module
+ *
+ * Copyright (C) 2012-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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSALIDE_MANGLING_MODULE_H
+#define _PLUGINS_PYCHRYSALIDE_MANGLING_MODULE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute le module 'mangling' au module Python. */
+bool add_mangling_module_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_MANGLING_MODULE_H */
diff --git a/plugins/pychrysalide/pychrysa.c b/plugins/pychrysalide/pychrysa.c
index 35d14f4..70cce2a 100644
--- a/plugins/pychrysalide/pychrysa.c
+++ b/plugins/pychrysalide/pychrysa.c
@@ -55,6 +55,7 @@
#include "glibext/module.h"
#include "gtkext/module.h"
#include "gui/module.h"
+#include "mangling/module.h"
@@ -403,6 +404,7 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
if (status) status = add_debug_module_to_python_module(result);
if (status) status = add_gtkext_module_to_python_module(result);
if (status) status = add_gui_module_to_python_module(result);
+ if (status) status = add_mangling_module_to_python_module(result);
if (!status)
{
diff --git a/src/analysis/routine.c b/src/analysis/routine.c
index 557e9aa..bf2b589 100644
--- a/src/analysis/routine.c
+++ b/src/analysis/routine.c
@@ -857,6 +857,7 @@ char *_g_binary_routine_to_string(const GBinRoutine *routine, Routine2StringOpti
{
char *result; /* Chaîne à renvoyer */
char *namespace; /* Groupe d'appartenance */
+ const char *name; /* Désignation de la routine */
size_t i; /* Boucle de parcours */
char *typestr; /* Stockage de nom temporaire */
@@ -900,7 +901,10 @@ char *_g_binary_routine_to_string(const GBinRoutine *routine, Routine2StringOpti
}
- result = stradd(result, g_binary_routine_get_name(routine));
+ name = g_binary_routine_get_name(routine);
+
+ if (name != NULL)
+ result = stradd(result, name);
/* Liste des arguments */
diff --git a/src/analysis/types/cse.c b/src/analysis/types/cse.c
index 1421112..8e2e021 100644
--- a/src/analysis/types/cse.c
+++ b/src/analysis/types/cse.c
@@ -102,14 +102,14 @@ static void g_class_enum_type_init(GClassEnumType *type)
* *
******************************************************************************/
-GDataType *g_class_enum_type_new(ClassEnumType type, const char *name)
+GDataType *g_class_enum_type_new(ClassEnumType type, char *name)
{
GClassEnumType *result; /* Structure à retourner */
result = g_object_new(G_TYPE_CLASS_ENUM_TYPE, NULL);
result->type = type;
- result->name = strdup(name);
+ result->name = name;
return G_DATA_TYPE(result);
diff --git a/src/analysis/types/cse.h b/src/analysis/types/cse.h
index dde91a2..0d59743 100644
--- a/src/analysis/types/cse.h
+++ b/src/analysis/types/cse.h
@@ -62,7 +62,7 @@ typedef enum _ClassEnumType
GType g_class_enum_type_get_type(void);
/* Crée une représentation de classe, structure ou énumération. */
-GDataType *g_class_enum_type_new(ClassEnumType, const char *);
+GDataType *g_class_enum_type_new(ClassEnumType, char *);
diff --git a/src/analysis/types/encaps.c b/src/analysis/types/encaps.c
index c3cf3ce..0dfc3af 100644
--- a/src/analysis/types/encaps.c
+++ b/src/analysis/types/encaps.c
@@ -39,6 +39,8 @@ struct _GEncapsulatedType
GDataType *child; /* Sous-type encadré */
GBinRoutine *routine; /* Routine pointée */
+ size_t dimension; /* Dimension quand applicable */
+
};
/* Description de type encapsulé (classe) */
@@ -208,6 +210,7 @@ static GDataType *g_encapsulated_type_dup(const GEncapsulatedType *type)
static char *g_encapsulated_type_to_string(const GEncapsulatedType *type)
{
char *result; /* Chaîne finale à renvoyer */
+ size_t i; /* Boucle de parcours */
switch (type->type)
{
@@ -234,6 +237,11 @@ static char *g_encapsulated_type_to_string(const GEncapsulatedType *type)
break;
+ case ECT_ARRAY:
+ result = stradd(result, " ");
+ for (i = 0; i < type->dimension; i++)
+ result = stradd(result, "[]");
+ break;
case ECT_REFERENCE:
result = stradd(result, " &");
break;
@@ -339,3 +347,42 @@ void g_encapsulated_type_get_item(const GEncapsulatedType *type, ...)
va_end(ap);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à consulter. *
+* *
+* Description : Fournit la dimension éventuellement associée au type. *
+* *
+* Retour : Dimension positive ou nulle. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_encapsulated_type_get_dimension(const GEncapsulatedType *type)
+{
+ return type->dimension;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à consulter. *
+* dim = dimension positive ou nulle. *
+* *
+* Description : Définit la dimension éventuellement associée au type. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_encapsulated_type_set_dimension(GEncapsulatedType *type, size_t dim)
+{
+ type->dimension = dim;
+
+}
diff --git a/src/analysis/types/encaps.h b/src/analysis/types/encaps.h
index d677e56..4cd74d2 100644
--- a/src/analysis/types/encaps.h
+++ b/src/analysis/types/encaps.h
@@ -51,6 +51,7 @@ typedef struct _GEncapsulatedTypeClass GEncapsulatedTypeClass;
typedef enum _EncapsulationType
{
ECT_POINTER, /* Pointeur */
+ ECT_ARRAY, /* Tableau */
ECT_REFERENCE, /* Référence */
ECT_RVALUE_REF, /* Référence ?? (C++0x) */
ECT_COMPLEX, /* Complexe (C 2000) */
@@ -73,6 +74,12 @@ EncapsulationType g_encapsulated_type_get_etype(const GEncapsulatedType *);
/* Fournit la routine encapsulée dans le type. */
void g_encapsulated_type_get_item(const GEncapsulatedType *, ...);
+/* Fournit la dimension éventuellement associée au type. */
+size_t g_encapsulated_type_get_dimension(const GEncapsulatedType *);
+
+/* Définit la dimension éventuellement associée au type. */
+void g_encapsulated_type_set_dimension(GEncapsulatedType *, size_t);
+
#endif /* _ANALYSIS_TYPES_ENCAPS_H */
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 94faa59..d2f6186 100755
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -11,6 +11,7 @@ libcommon_la_SOURCES = \
endianness.h endianness.c \
environment.h environment.c \
extstr.h extstr.c \
+ ibuf.h ibuf.c \
io.h io.c \
fnv1a.h fnv1a.c \
leb128.h leb128.c \
@@ -21,6 +22,7 @@ libcommon_la_SOURCES = \
shuffle.h shuffle.c \
sort.h sort.c \
sqlite.h sqlite.c \
+ utf8.h utf8.c \
xdg.h xdg.c \
xml.h xml.c
diff --git a/src/common/ibuf.c b/src/common/ibuf.c
new file mode 100644
index 0000000..6eb04e6
--- /dev/null
+++ b/src/common/ibuf.c
@@ -0,0 +1,173 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * ibuf.c - lecture progressive d'un tampon de données
+ *
+ * Copyright (C) 2018 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 "ibuf.h"
+
+
+#include <assert.h>
+#include <string.h>
+
+
+
+/******************************************************************************
+* *
+* Paramètres : ibuf = tampon de données à initialiser. [OUT] *
+* *
+* Description : Initialise un contenu textuel pour une lecture ultérieure. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void init_text_input_buffer(input_buffer *ibuf, const char *text)
+{
+ ibuf->text = text;
+
+ ibuf->len = strlen(text);
+ ibuf->pos = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ibuf = tampon de données à consulter. *
+* *
+* Description : Compte le nombre d'octets encore non lus. *
+* *
+* Retour : Nombre d'octets encore disponibles pour un traitement. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t count_input_buffer_remaining(const input_buffer *ibuf)
+{
+ return ibuf->len - ibuf->pos;
+
+}
+
+/******************************************************************************
+* *
+* Paramètres : ibuf = tampon de données à modifier. *
+* count = progression de la tête de lecture à marquer. *
+* *
+* Description : Avance la tête de lecture dans le tampon de données. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void advance_input_buffer(input_buffer *ibuf, size_t count)
+{
+ assert((ibuf->pos + count) <= ibuf->len);
+
+ ibuf->pos += count;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ibuf = tampon de données à consulter. *
+* *
+* Description : Fournit un accès brut au niveau de la tête de lecture. *
+* *
+* Retour : Référence au texte brut courant. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const char *get_input_buffer_text_access(const input_buffer *ibuf)
+{
+ return ibuf->text + ibuf->pos;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ibuf = tampon de données à parcourir. *
+* *
+* Description : Fournit et avance la tête de lecture courante. *
+* *
+* Retour : Caractère courant. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char text_input_buffer_next_char(input_buffer *ibuf)
+{
+ assert(ibuf->pos <= ibuf->len);
+
+ return *(ibuf->text + ibuf->pos++);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ibuf = tampon de données à consulter. *
+* pos = sauvegarde de la tête de lecture. [OUT] *
+* *
+* Description : Note la position courante de la tête de lecture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void save_input_buffer_pos(const input_buffer *ibuf, size_t *pos)
+{
+ *pos = ibuf->pos;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ibuf = tampon de données à consulter. *
+* pos = tête de lecture à définir pour le tampon courant. *
+* *
+* Description : Restaure la position de la tête de lecture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void restore_input_buffer_pos(input_buffer *ibuf, size_t pos)
+{
+ assert(pos <= ibuf->len);
+
+ ibuf->pos = pos;
+
+}
diff --git a/src/common/ibuf.h b/src/common/ibuf.h
new file mode 100644
index 0000000..b57e374
--- /dev/null
+++ b/src/common/ibuf.h
@@ -0,0 +1,71 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * ibuf.h - prototypes pour la lecture progressive d'un tampon de données
+ *
+ * Copyright (C) 2018 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 _COMMON_IBUF_H
+#define _COMMON_IBUF_H
+
+
+#include <stdint.h>
+#include <sys/types.h>
+
+
+
+/* Rassemblement de données d'un tampon */
+typedef struct _input_buffer
+{
+ union
+ {
+ const char *text; /* Contenu textuel disponible */
+ const uint8_t *data; /* Données brutes à traiter */
+ };
+
+ size_t len; /* Quantité d'octets présents */
+ size_t pos; /* Position de tête de lecture */
+
+} input_buffer;
+
+
+/* Initialise un contenu textuel pour une lecture ultérieure. */
+void init_text_input_buffer(input_buffer *, const char *);
+
+/* Compte le nombre d'octets encore non lus. */
+size_t count_input_buffer_remaining(const input_buffer *);
+
+/* Avance la tête de lecture dans le tampon de données. */
+void advance_input_buffer(input_buffer *, size_t);
+
+/* Fournit un accès brut au niveau de la tête de lecture. */
+const char *get_input_buffer_text_access(const input_buffer *);
+
+/* Fournit et avance la tête de lecture courante. */
+char text_input_buffer_next_char(input_buffer *);
+
+/* Note la position courante de la tête de lecture. */
+void save_input_buffer_pos(const input_buffer *, size_t *);
+
+/* Restaure la position de la tête de lecture. */
+void restore_input_buffer_pos(input_buffer *, size_t);
+
+
+
+#endif /* _COMMON_IBUF_H */
diff --git a/src/common/packed.c b/src/common/packed.c
index 03796b1..d09feea 100644
--- a/src/common/packed.c
+++ b/src/common/packed.c
@@ -40,7 +40,7 @@
* *
* Paramètres : pbuf = paquet de données à initialiser. [OUT] *
* *
-* Description : Intialise un paquet réseau pour une constitution. *
+* Description : Initialise un paquet réseau pour une constitution. *
* *
* Retour : - *
* *
diff --git a/src/common/packed.h b/src/common/packed.h
index bb12a1f..b1f9d73 100644
--- a/src/common/packed.h
+++ b/src/common/packed.h
@@ -46,7 +46,7 @@ typedef struct _packed_buffer
} packed_buffer;
-/* Intialise un paquet réseau pour une constitution. */
+/* Initialise un paquet réseau pour une constitution. */
void init_packed_buffer(packed_buffer *);
/* Efface les données contenues par un paquet réseau. */
diff --git a/src/common/utf8.c b/src/common/utf8.c
new file mode 100644
index 0000000..401b0a3
--- /dev/null
+++ b/src/common/utf8.c
@@ -0,0 +1,150 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * utf8.c - support minimaliste mais adapté de l'encodage UTF-8
+ *
+ * Copyright (C) 2018 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 "utf8.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : text = position courante dans une chaîne de caractères. *
+* len = nombre d'octets de cette même chaîne. *
+* consumed = nombre d'octets lus pendant l'opération. [OUT] *
+* *
+* Description : Procède à la lecture d'un caractère dans une chaîne en UTF-8.*
+* *
+* Retour : Caractère sur 32 bits lu ou code d'erreur en cas de soucis. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+unichar_t decode_utf8_char(const char *text, size_t len, size_t *consumed)
+{
+ unichar_t result; /* Valeur à retourner */
+ size_t expected; /* Quantité à traiter */
+ unichar_t minval; /* Valeur codée minimale */
+ size_t i; /* Boucle de parcours */
+
+ result = text[0];
+
+ /**
+ * ASCII ?
+ */
+ if (result < 0x80)
+ {
+ *consumed = 1;
+ goto duc_done;
+ }
+
+ /**
+ * Deux caractères (au moins) doivent être présents.
+ * Le premier mot doit donc au moins commencer par 0b1100 = 0xc.
+ */
+ else if (result < 0xc0)
+ {
+ result = UTF8_ERROR_MALFORMED;
+ goto duc_done;
+ }
+
+ /**
+ * Valeur inférieure à 0xe, donc taille inférieure à 3 (0b1110).
+ */
+ else if (result < 0xe0)
+ {
+ expected = 2;
+ result &= 0x1f;
+ minval = 1 << 7;
+ }
+
+ /**
+ * Valeur inférieure à 0xf0, donc taille inférieure à 4 (0b11110000).
+ */
+ else if (result < 0xf0)
+ {
+ expected = 3;
+ result &= 0x0f;
+ minval = 1 << 11;
+ }
+
+ /**
+ * Valeur inférieure à 0xf8, donc taille inférieure à 5 (0b11111000).
+ */
+ else if (result < 0xf8)
+ {
+ expected = 4;
+ result &= 0x07;
+ minval = 1 << 16;
+ }
+
+ /**
+ * Erreur : l'encodage UTF-8 ne dépasse pas 4 octets.
+ */
+ else
+ {
+ result = UTF8_ERROR_TOO_LONG;
+ goto duc_done;
+ }
+
+ /**
+ * Erreur : pas assez de données.
+ */
+ if (expected > len)
+ {
+ result = UTF8_ERROR_TOO_LONG;
+ goto duc_done;
+ }
+
+ /**
+ * Intégration des octets restants, avec vérifications qu'ils participent
+ * bien à la constitution de la valeur finale.
+ */
+ for (i = 1; i < expected; i++)
+ {
+ if ((text[i] & 0xc0) != 0x80)
+ {
+ result = UTF8_ERROR_MISSING;
+ goto duc_done;
+ }
+
+ result <<= 6;
+ result |= (text[i] & 0x3f);
+
+ }
+
+ /**
+ * Validation finale.
+ */
+ if (result < minval)
+ {
+ result = UTF8_ERROR_WASTING;
+ goto duc_done;
+ }
+
+ *consumed = expected;
+
+ duc_done:
+
+ return result;
+
+}
diff --git a/src/common/utf8.h b/src/common/utf8.h
new file mode 100644
index 0000000..b312cd5
--- /dev/null
+++ b/src/common/utf8.h
@@ -0,0 +1,55 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * utf8.h - prototypes pour un support minimaliste mais adapté de l'encodage UTF-8
+ *
+ * Copyright (C) 2018 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 _COMMON_UTF8_H
+#define _COMMON_UTF8_H
+
+
+#include <stdint.h>
+#include <sys/types.h>
+
+
+
+/* Représentation d'un caractère */
+typedef uint32_t unichar_t;
+
+
+/**
+ * Erreurs qu'il est possible de rencontrer.
+ */
+
+#define UTF8_ERROR_MALFORMED ((unichar_t)-1)
+#define UTF8_ERROR_TOO_LONG ((unichar_t)-2)
+#define UTF8_ERROR_TRUNCATED ((unichar_t)-3)
+#define UTF8_ERROR_MISSING ((unichar_t)-4)
+#define UTF8_ERROR_WASTING ((unichar_t)-5)
+
+#define IS_UTF8_ERROR(v) (v & (1u << 31))
+
+
+/* Procède à la lecture d'un caractère dans une chaîne en UTF-8. */
+unichar_t decode_utf8_char(const char *, size_t, size_t *);
+
+
+
+#endif /* _COMMON_UTF8_H */
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index c7700a6..e1dade0 100755
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -4,6 +4,7 @@ noinst_LTLIBRARIES = libcore.la
libcore_la_SOURCES = \
collections.h collections.c \
core.h core.c \
+ demanglers.h demanglers.c \
formats.h formats.c \
global.h global.c \
logs.h logs.c \
diff --git a/src/core/core.c b/src/core/core.c
index 5b60384..1d01c7c 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -34,6 +34,7 @@
#include "collections.h"
+#include "demanglers.h"
#include "formats.h"
#include "global.h"
#include "params.h"
@@ -127,6 +128,8 @@ void unload_all_basic_components(void)
{
unload_collection_definitions();
+ unload_demanglers_definitions();
+
unload_formats_definitions();
unload_processors_definitions();
diff --git a/src/core/demanglers.c b/src/core/demanglers.c
new file mode 100644
index 0000000..409018e
--- /dev/null
+++ b/src/core/demanglers.c
@@ -0,0 +1,191 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demanglers.c - enregistrement et fourniture des décodeurs proprosés
+ *
+ * Copyright (C) 2018 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 "demanglers.h"
+
+
+#include <string.h>
+
+
+
+/* Caractéristiques d'un processeur */
+typedef struct _demangler_t
+{
+ char *key; /* Clef pour un accès rapide */
+ GType instance; /* Type à manipuler en interne */
+
+} demangler_t;
+
+
+/* Mémorisation des types de décodeurs enregistrés */
+static demangler_t *_demanglers_definitions = NULL;
+static size_t _demanglers_definitions_count = 0;
+
+/* Verrou pour des accès atomiques */
+G_LOCK_DEFINE_STATIC(_ddef_access);
+
+
+/* Retrouve l'enregistrement correspondant à un décodeur. */
+static demangler_t *find_demangler_by_key(const char *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : key = désignation rapide et interne d'un décodeur. *
+* instance = type GLib représentant le type à instancier. *
+* *
+* Description : Enregistre un décodeur répondant à une appellation donnée. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_demangler_type(const char *key, GType instance)
+{
+ bool result; /* Bilan à retourner */
+ demangler_t *new; /* Nouvel élément à définir */
+
+ G_LOCK(_ddef_access);
+
+ new = find_demangler_by_key(key);
+
+ result = (new == NULL);
+
+ if (result)
+ {
+ _demanglers_definitions = (demangler_t *)realloc(_demanglers_definitions,
+ ++_demanglers_definitions_count * sizeof(demangler_t));
+
+ new = &_demanglers_definitions[_demanglers_definitions_count - 1];
+
+ new->key = strdup(key);
+ new->instance = instance;
+
+ }
+
+ G_UNLOCK(_ddef_access);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Décharge toutes les définitions de décodeurs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void unload_demanglers_definitions(void)
+{
+ size_t i; /* Boucle de parcours */
+
+ G_LOCK(_ddef_access);
+
+ for (i = 0; i < _demanglers_definitions_count; i++)
+ free(_demanglers_definitions[i].key);
+
+ if (_demanglers_definitions != NULL)
+ free(_demanglers_definitions);
+
+ _demanglers_definitions = NULL;
+ _demanglers_definitions_count = 0;
+
+ G_UNLOCK(_ddef_access);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : key = nom technique du décodeur recherché. *
+* *
+* Description : Retrouve l'enregistrement correspondant à un décodeur. *
+* *
+* Retour : Définition trouvée ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static demangler_t *find_demangler_by_key(const char *key)
+{
+ demangler_t *result; /* Trouvaille à retourner */
+ size_t i; /* Boucle de parcours */
+
+ /**
+ * Le verrou d'accès global doit être posé !
+ */
+
+ result = NULL;
+
+ if (key != NULL)
+ for (i = 0; i < _demanglers_definitions_count; i++)
+ if (strcmp(_demanglers_definitions[i].key, key) == 0)
+ result = &_demanglers_definitions[i];
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : key = nom technique du décodeur recherché. *
+* *
+* Description : Fournit le décodeur de désignations correspondant à un type. *
+* *
+* Retour : Décodeur trouvé et mis en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GCompDemangler *get_compiler_demangler_for_type(const char *key)
+{
+ GCompDemangler *result; /* Instance à retourner */
+ demangler_t *def; /* Définition de décodeur */
+
+ G_LOCK(_ddef_access);
+
+ def = find_demangler_by_key(key);
+
+ if (def == NULL)
+ result = NULL;
+ else
+ result = g_object_new(def->instance, NULL);
+
+ G_UNLOCK(_ddef_access);
+
+ return result;
+
+}
diff --git a/src/core/demanglers.h b/src/core/demanglers.h
new file mode 100644
index 0000000..b3ff985
--- /dev/null
+++ b/src/core/demanglers.h
@@ -0,0 +1,46 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demanglers.h - prototypes pour l'enregistrement et la fourniture des décodeurs proprosés
+ *
+ * Copyright (C) 2018 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 _CORE_DEMANGLERS_H
+#define _CORE_DEMANGLERS_H
+
+
+#include <stdbool.h>
+
+
+#include "../mangling/demangler.h"
+
+
+
+/* Enregistre un décodeur répondant à une appellation donnée. */
+bool register_demangler_type(const char *, GType);
+
+/* Décharge toutes les définitions de décodeurs. */
+void unload_demanglers_definitions(void);
+
+/* Fournit le décodeur de désignations correspondant à un type. */
+GCompDemangler *get_compiler_demangler_for_type(const char *);
+
+
+
+#endif /* _CORE_DEMANGLERS_H */
diff --git a/src/core/processors.h b/src/core/processors.h
index 83f7466..0b4841a 100644
--- a/src/core/processors.h
+++ b/src/core/processors.h
@@ -57,4 +57,4 @@ GArchProcessor *get_arch_processor_for_type(const char *);
-#endif /* _ANALYSIS_DB_COLLECTION_H */
+#endif /* _CORE_PROCESSORS_H */
diff --git a/src/format/format-int.h b/src/format/format-int.h
index 5c1ae07..e01b597 100644
--- a/src/format/format-int.h
+++ b/src/format/format-int.h
@@ -30,6 +30,7 @@
#include "preload.h"
#include "../gtkext/gtkstatusstack.h"
+#include "../mangling/demangler.h"
@@ -68,6 +69,8 @@ struct _GBinFormat
GBinContent *content; /* Contenu binaire à étudier */
+ GCompDemangler *demangler; /* Décodage de noms privilégié */
+
virt_t *entry_points; /* Points d'entrée du code */
size_t ep_count; /* Nombre de ces points */
diff --git a/src/format/format.c b/src/format/format.c
index 89db51d..f71cc8f 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -144,6 +144,9 @@ static void g_binary_format_init(GBinFormat *format)
static void g_binary_format_dispose(GBinFormat *format)
{
+ if (format->demangler != NULL)
+ g_object_unref(format->demangler);
+
g_object_unref(format->info);
g_rw_lock_clear(&format->syms_lock);
diff --git a/src/mangling/Makefile.am b/src/mangling/Makefile.am
index 63b25c7..075a634 100644
--- a/src/mangling/Makefile.am
+++ b/src/mangling/Makefile.am
@@ -8,13 +8,13 @@ noinst_LTLIBRARIES = libjavamangling.la libmangling.la
libmangling_la_SOURCES = \
context-int.h \
context.h context.c \
+ demangler-int.h \
demangler.h demangler.c
libmangling_la_LDFLAGS =
libmangling_la_LIBADD = \
libjavamangling.la \
- dex/libmanglingdex.la \
itanium/libmanglingitanium.la
@@ -40,4 +40,4 @@ AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
# Automake fait les choses à moitié
CLEANFILES = java_gram.h java_gram.c libjavamangling_la-java_tok.c
-SUBDIRS = dex itanium
+SUBDIRS = itanium
diff --git a/src/mangling/context-int.h b/src/mangling/context-int.h
index d361ff7..e34842c 100644
--- a/src/mangling/context-int.h
+++ b/src/mangling/context-int.h
@@ -21,23 +21,34 @@
*/
-#ifndef _FORMAT_MANGLING_CONTEXT_INT_H
-#define _FORMAT_MANGLING_CONTEXT_INT_H
+#ifndef _MANGLING_CONTEXT_INT_H
+#define _MANGLING_CONTEXT_INT_H
#include "context.h"
+#include "../common/ibuf.h"
+
+
/* Procède au décodage d'une chaîne de caractères. */
typedef bool (* demangle_fc) (GDemanglingContext *, const char *);
+/* Décode une définition de routine. */
+typedef GBinRoutine * (* decode_routine_fc) (GDemanglingContext *);
+
+/* Décode une définition de type. */
+typedef GDataType * (* decode_type_fc) (GDemanglingContext *);
+
/* Contexte de décodage (instance) */
struct _GDemanglingContext
{
GObject parent; /* A laisser en premier */
+ input_buffer buffer; /* Tampon de lecture */
+
union
{
GObject *gobj; /* Utile pour le nettoyage ! */
@@ -55,8 +66,11 @@ struct _GDemanglingContextClass
demangle_fc demangle_type; /* Décodage de type */
demangle_fc demangle_routine; /* Décodage de routine */
+ decode_type_fc decode_type; /* Décodage de type */
+ decode_routine_fc decode_routine; /* Décodage de routine */
+
};
-#endif /* _FORMAT_MANGLING_CONTEXT_INT_H */
+#endif /* _MANGLING_CONTEXT_INT_H */
diff --git a/src/mangling/context.c b/src/mangling/context.c
index 7a798ac..65a8874 100644
--- a/src/mangling/context.c
+++ b/src/mangling/context.c
@@ -24,6 +24,9 @@
#include "context.h"
+#include <assert.h>
+
+
#include "context-int.h"
@@ -165,6 +168,7 @@ GBinRoutine *g_demangling_context_get_decoded_routine(GDemanglingContext *contex
/******************************************************************************
* *
* Paramètres : context = instance à consulter. *
+* desc = chaîne de caractères à décoder. *
* *
* Description : Fournit le type créé à l'issue du codage. *
* *
@@ -190,3 +194,85 @@ GDataType *g_demangling_context_get_decoded_type(GDemanglingContext *context, co
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : context = environnement de décodage à manipuler. *
+* desc = chaîne de caractères à décoder. *
+* *
+* Description : Décode une définition de type. *
+* *
+* Retour : Nouvelle instance créée ou NULL en cas d'erreur fatale. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_demangling_context_decode_type(GDemanglingContext *context, const char *desc)
+{
+ GDataType *result; /* Construction à remonter */
+
+ if (context->type != NULL)
+ result = context->type;
+
+ else
+ {
+ assert(context->buffer.text == NULL);
+
+ init_text_input_buffer(&context->buffer, desc);
+
+ result = G_DEMANGLING_CONTEXT_GET_CLASS(context)->decode_type(context);
+
+ if (result != NULL)
+ context->type = result;
+
+ }
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : context = environnement de décodage à manipuler. *
+* desc = chaîne de caractères à décoder. *
+* *
+* Description : Décode une définition de routine. *
+* *
+* Retour : Nouvelle instance créée ou NULL en cas d'erreur fatale. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinRoutine *g_demangling_context_decode_routine(GDemanglingContext *context, const char *desc)
+{
+ GBinRoutine *result; /* Construction à remonter */
+
+ if (context->routine != NULL)
+ result = context->routine;
+
+ else
+ {
+ assert(context->buffer.text == NULL);
+
+ init_text_input_buffer(&context->buffer, desc);
+
+ result = G_DEMANGLING_CONTEXT_GET_CLASS(context)->decode_routine(context);
+
+ if (result != NULL)
+ context->routine = result;
+
+ }
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
diff --git a/src/mangling/context.h b/src/mangling/context.h
index 705ef83..1f516d3 100644
--- a/src/mangling/context.h
+++ b/src/mangling/context.h
@@ -56,6 +56,12 @@ GBinRoutine *g_demangling_context_get_decoded_routine(GDemanglingContext *, cons
/* Fournit le type créé à l'issue du codage. */
GDataType *g_demangling_context_get_decoded_type(GDemanglingContext *, const char *);
+/* Décode une définition de type. */
+GDataType *g_demangling_context_decode_type(GDemanglingContext *, const char *);
+
+/* Décode une définition de routine. */
+GBinRoutine *g_demangling_context_decode_routine(GDemanglingContext *, const char *);
+
#endif /* _FORMAT_MANGLING_CONTEXT_H */
diff --git a/src/mangling/demangler-int.h b/src/mangling/demangler-int.h
new file mode 100644
index 0000000..55fb27d
--- /dev/null
+++ b/src/mangling/demangler-int.h
@@ -0,0 +1,57 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * demangler-int.h - prototypes internes utiles aux décodeurs de désignations de symboles
+ *
+ * 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 _MANGLING_DEMANGLER_INT_H
+#define _MANGLING_DEMANGLER_INT_H
+
+
+#include "context.h"
+#include "demangler.h"
+
+
+
+/* Indique si une chaîne peut être traitée par le décodeur. */
+typedef bool (* can_be_demangled_fc) (const char *);
+
+
+/* Décodeur de désignations générique (instance) */
+struct _GCompDemangler
+{
+ GObject parent; /* A laisser en premier */
+
+};
+
+/* Décodeur de désignations générique (classe) */
+struct _GCompDemanglerClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+ can_be_demangled_fc can_demangle; /* Possibilité de traitement */
+
+ GType context_type; /* Contexte de décodage */
+
+};
+
+
+
+#endif /* _FORMAT_MANGLING_DEMANGLER_H */
diff --git a/src/mangling/demangler.c b/src/mangling/demangler.c
index f673a01..299da9c 100644
--- a/src/mangling/demangler.c
+++ b/src/mangling/demangler.c
@@ -24,6 +24,195 @@
#include "demangler.h"
+#include "demangler-int.h"
+
+
+
+/* Initialise la classe des décodeurs de désignations. */
+static void g_compiler_demangler_class_init(GCompDemanglerClass *);
+
+/* Initialise une instance de décodeur de désignations. */
+static void g_compiler_demangler_init(GCompDemangler *);
+
+/* Supprime toutes les références externes. */
+static void g_compiler_demangler_dispose(GCompDemangler *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_compiler_demangler_finalize(GCompDemangler *);
+
+
+
+/* Indique le type défini pour un décodeur de désignations. */
+G_DEFINE_TYPE(GCompDemangler, g_compiler_demangler, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des décodeurs de désignations. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_compiler_demangler_class_init(GCompDemanglerClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_compiler_demangler_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_compiler_demangler_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : demangler = instance à initialiser. *
+* *
+* Description : Initialise une instance de décodeur de désignations. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_compiler_demangler_init(GCompDemangler *demangler)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : demangler = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_compiler_demangler_dispose(GCompDemangler *demangler)
+{
+ G_OBJECT_CLASS(g_compiler_demangler_parent_class)->dispose(G_OBJECT(demangler));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : demangler = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_compiler_demangler_finalize(GCompDemangler *demangler)
+{
+ G_OBJECT_CLASS(g_compiler_demangler_parent_class)->finalize(G_OBJECT(demangler));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : demangler = décodeur à solliciter pour l'opération. *
+* desc = chaîne de caractères à décoder. *
+* *
+* Description : Tente de décoder une chaîne de caractères donnée en type. *
+* *
+* Retour : Instance obtenue ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_compiler_demangler_decode_type(const GCompDemangler *demangler, const char *desc)
+{
+ GDataType *result; /* Construction à remonter */
+ GType ctx_type; /* Type de contexte adapté */
+ GDemanglingContext *context; /* Espace de travail dédié */
+
+ ctx_type = G_COMP_DEMANGLER_GET_CLASS(demangler)->context_type;
+
+ context = g_object_new(ctx_type, NULL);
+
+ result = g_demangling_context_decode_type(context, desc);
+
+ g_object_unref(G_OBJECT(context));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : demangler = décodeur à solliciter pour l'opération. *
+* desc = chaîne de caractères à décoder. *
+* *
+* Description : Tente de décoder une chaîne de caractères donnée en routine. *
+* *
+* Retour : Instance obtenue ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinRoutine *g_compiler_demangler_decode_routine(const GCompDemangler *demangler, const char *desc)
+{
+ GBinRoutine *result; /* Construction à remonter */
+ GType ctx_type; /* Type de contexte adapté */
+ GDemanglingContext *context; /* Espace de travail dédié */
+
+ ctx_type = G_COMP_DEMANGLER_GET_CLASS(demangler)->context_type;
+
+ context = g_object_new(ctx_type, NULL);
+
+ result = g_demangling_context_decode_routine(context, desc);
+
+ g_object_unref(G_OBJECT(context));
+
+ return result;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////
+
+
+
+
+
#include <malloc.h>
#include <string.h>
diff --git a/src/mangling/demangler.h b/src/mangling/demangler.h
index 00218e4..4a4b9fa 100644
--- a/src/mangling/demangler.h
+++ b/src/mangling/demangler.h
@@ -21,14 +21,54 @@
*/
-#ifndef _FORMAT_MANGLING_DEMANGLER_H
-#define _FORMAT_MANGLING_DEMANGLER_H
+#ifndef _MANGLING_DEMANGLER_H
+#define _MANGLING_DEMANGLER_H
#include "../analysis/routine.h"
+#define G_TYPE_COMP_DEMANGLER g_compiler_demangler_get_type()
+#define G_COMP_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_COMP_DEMANGLER, GCompDemangler))
+#define G_IS_COMP_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_COMP_DEMANGLER))
+#define G_COMP_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_COMP_DEMANGLER, GCompDemanglerClass))
+#define G_IS_COMP_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_COMP_DEMANGLER))
+#define G_COMP_DEMANGLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_COMP_DEMANGLER, GCompDemanglerClass))
+
+
+/* Décodeur de désignations générique (instance) */
+typedef struct _GCompDemangler GCompDemangler;
+
+/* Décodeur de désignations générique (classe) */
+typedef struct _GCompDemanglerClass GCompDemanglerClass;
+
+
+/* Indique le type défini pour un décodeur de désignations. */
+GType g_compiler_demangler_get_type(void);
+
+/* Tente de décoder une chaîne de caractères donnée en type. */
+GDataType *g_compiler_demangler_decode_type(const GCompDemangler *, const char *);
+
+/* Tente de décoder une chaîne de caractères donnée en routine. */
+GBinRoutine *g_compiler_demangler_decode_routine(const GCompDemangler *, const char *);
+
+
+
+
+
+
+
+
+
+
+
+/////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////
+
+
/* Tente de décoder une chaîne de caractères donnée. */
GBinRoutine *try_to_demangle_routine(const char *);
@@ -47,4 +87,4 @@ void test_itanium_demangling(void);
-#endif /* _FORMAT_MANGLING_DEMANGLER_H */
+#endif /* _MANGLING_DEMANGLER_H */
diff --git a/src/mangling/dex/Makefile.am b/src/mangling/dex/Makefile.am
deleted file mode 100644
index 547d686..0000000
--- a/src/mangling/dex/Makefile.am
+++ /dev/null
@@ -1,46 +0,0 @@
-
-BUILT_SOURCES = libmanglingdexshorty_la-shorty_gram.h libmanglingdextype_la-type_gram.h
-
-AM_YFLAGS = -d
-
-noinst_LTLIBRARIES = libmanglingdex.la libmanglingdexshorty.la libmanglingdextype.la
-
-libmanglingdex_la_SOURCES = \
- context.h context.c
-
-libmanglingdex_la_LDFLAGS =
-
-libmanglingdex_la_LIBADD = \
- libmanglingdexshorty.la \
- libmanglingdextype.la
-
-
-libmanglingdexshorty_la_SOURCES = \
- shorty_gram.y \
- shorty_tok.l
-
-libmanglingdexshorty_la_YFLAGS = -d -p shorty_ -o y.tab.c
-
-libmanglingdexshorty_la_LFLAGS = -P shorty_ -o lex.yy.c
-
-
-libmanglingdextype_la_SOURCES = \
- type_gram.y \
- type_tok.l
-
-libmanglingdextype_la_YFLAGS = -d -p type_ -o y.tab.c
-
-libmanglingdextype_la_LFLAGS = -P type_ -o lex.yy.c
-
-
-AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
-
-AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-
-
-# Automake fait les choses à moitié
-CLEANFILES = \
- libmanglingdexshorty_la-shorty_gram.h libmanglingdexshorty_la-shorty_gram.c \
- libmanglingdexshorty_la-shorty_tok.c \
- libmanglingdextype_la-type_gram.h libmanglingdextype_la-type_gram.c \
- libmanglingdextype_la-type_tok.c
diff --git a/src/mangling/dex/context.h b/src/mangling/dex/context.h
deleted file mode 100644
index 1af7a9d..0000000
--- a/src/mangling/dex/context.h
+++ /dev/null
@@ -1,52 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * context.h - prototypes internes liés aux contextes de décodage DEX
- *
- * Copyright (C) 2015-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_MANGLING_DEX_CONTEXT_H
-#define _FORMAT_MANGLING_DEX_CONTEXT_H
-
-
-#include <glib-object.h>
-
-
-
-#define G_TYPE_DEX_DEMANGLER g_dex_demangler_get_type()
-#define G_DEX_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dex_demangler_get_type(), GDexDemangler))
-#define G_IS_DEX_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dex_demangler_get_type()))
-#define G_DEX_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEX_DEMANGLER, GDexDemanglerClass))
-#define G_IS_DEX_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEX_DEMANGLER))
-#define G_DEX_DEMANGLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEX_DEMANGLER, GDexDemanglerClass))
-
-
-/* Contexte de décodage DEX (instance) */
-typedef struct _GDexDemangler GDexDemangler;
-
-/* Contexte de décodage DEX (classe) */
-typedef struct _GDexDemanglerClass GDexDemanglerClass;
-
-
-/* Indique le type défini pour un contexte de décodage DEX. */
-GType g_dex_demangler_get_type(void);
-
-
-
-#endif /* _FORMAT_MANGLING_DEX_CONTEXT_H */
diff --git a/src/mangling/dex/shorty_gram.y b/src/mangling/dex/shorty_gram.y
deleted file mode 100644
index b688896..0000000
--- a/src/mangling/dex/shorty_gram.y
+++ /dev/null
@@ -1,138 +0,0 @@
-
-%{
-
-#include <stdbool.h>
-
-
-#include "context.h"
-#include "../context-int.h"
-
-
-
-/* Affiche un message d'erreur concernant l'analyse. */
-static int shorty_error(GDexDemangler *, char *);
-
-/* Procède au décodage d'une chaîne de caractères. */
-bool demangle_dex_routine(GDexDemangler *, const char *);
-
-
-%}
-
-
-%code requires {
-
-#include "../../analysis/types/basic.h"
-#include "../../analysis/types/cse.h"
-
-}
-
-%union {
-
- GDataType *type; /* Type reconstruit */
-
-}
-
-
-%parse-param { GDexDemangler *demangler }
-
-%token V Z B S C I J F D L
-
-%type <type> shorty_return_type shorty_field_type
-
-
-%{
-
-/* Déclarations issues de l'analyseur syntaxique... */
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-
-extern YY_BUFFER_STATE shorty__scan_string(const char *);
-extern void shorty__delete_buffer(YY_BUFFER_STATE);
-extern int shorty_lex(void);
-
-%}
-
-
-%%
-
-
-shorty_descriptor:
- shorty_return_type shorty_field_type_list {
- GBinRoutine *routine;
- routine = G_DEMANGLING_CONTEXT(demangler)->routine;
- g_binary_routine_set_return_type(routine, $1);
- }
-
-shorty_field_type_list:
- /* empty */
- | shorty_field_type shorty_field_type_list {
- GBinRoutine *routine;
- GBinVariable *var;
- routine = G_DEMANGLING_CONTEXT(demangler)->routine;
- var = g_binary_variable_new($1);
- g_binary_routine_add_arg(routine, var);
- }
-
-shorty_return_type:
- V { $$ = g_basic_type_new(BTP_VOID); }
- | shorty_field_type { $$ = $1; }
-
-shorty_field_type:
- Z { $$ = g_basic_type_new(BTP_BOOL); }
- | B { $$ = g_basic_type_new(BTP_UCHAR); }
- | S { $$ = g_basic_type_new(BTP_SHORT); }
- | C { $$ = g_basic_type_new(BTP_CHAR); }
- | I { $$ = g_basic_type_new(BTP_INT); }
- | J { $$ = g_basic_type_new(BTP_LONG); }
- | F { $$ = g_basic_type_new(BTP_FLOAT); }
- | D { $$ = g_basic_type_new(BTP_DOUBLE); }
- | L { $$ = g_class_enum_type_new(CET_CLASS, ""); }
-
-
-%%
-
-
-/******************************************************************************
-* *
-* Paramètres : demangler = contexte associé à la procédure de décodage. *
-* msg = indications humaines sur l'événement. *
-* *
-* Description : Affiche un message d'erreur concernant l'analyse. *
-* *
-* Retour : Valeur historique, ignorée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-static int shorty_error(GDexDemangler *demangler, char *msg)
-{
- return -1;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : demangler = contexte de décodage à utiliser. *
-* desc = chaîne de caractères à décoder. *
-* *
-* Description : Procède au décodage d'une chaîne de caractères. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool demangle_dex_routine(GDexDemangler *demangler, const char *desc)
-{
- YY_BUFFER_STATE buffer; /* Tampon pour bison */
- int ret; /* Bilan de l'appel */
-
- buffer = shorty__scan_string(desc);
- ret = yyparse(demangler);
- shorty__delete_buffer(buffer);
-
- return (ret == 0);
-
-}
diff --git a/src/mangling/dex/shorty_tok.l b/src/mangling/dex/shorty_tok.l
deleted file mode 100644
index a3545a2..0000000
--- a/src/mangling/dex/shorty_tok.l
+++ /dev/null
@@ -1,28 +0,0 @@
-
-%{
-
-#include "context.h"
-#include "libmanglingdexshorty_la-shorty_gram.h"
-
-%}
-
-
-%option noyywrap
-%option yylineno
-%option nounput
-%option noinput
-
-%%
-
-"V" { return V; }
-"Z" { return Z; }
-"B" { return B; }
-"S" { return S; }
-"C" { return C; }
-"I" { return I; }
-"J" { return J; }
-"F" { return F; }
-"D" { return D; }
-"L" { return L; }
-
-%%
diff --git a/src/mangling/dex/type_gram.y b/src/mangling/dex/type_gram.y
deleted file mode 100644
index 79c9320..0000000
--- a/src/mangling/dex/type_gram.y
+++ /dev/null
@@ -1,159 +0,0 @@
-
-%{
-
-#include <stdbool.h>
-
-
-#include "context.h"
-#include "../context-int.h"
-
-typedef void *yyscan_t;
-
-/* Affiche un message d'erreur concernant l'analyse. */
-static int type_error(GDexDemangler *, yyscan_t, char *);
-
-/* Procède au décodage d'une chaîne de caractères. */
-bool demangle_dex_type(GDexDemangler *, const char *);
-
-
-%}
-
-
-%code requires {
-
-#include "../../analysis/types/basic.h"
-#include "../../analysis/types/cse.h"
-#include "../../common/extstr.h"
-
-}
-
-%union {
-
- GDataType *type; /* Type reconstruit */
- size_t adeep; /* Dimension d'un tableau */
- char *text; /* Chaîne de caractères */
-
-}
-
-
-
-%define api.pure full
-%parse-param { GDexDemangler *demangler } { yyscan_t scanner }
-%lex-param { yyscan_t scanner }
-
-
-%token V Z B S C I J F D
-%token ARRAY
-%token L SEMICOLON
-%token SLASH DOLLAR
-%token TEXT
-
-%type <type> type_descriptor field_type_descriptor non_array_field_type_descriptor full_class_name
-
-%type <text> TEXT simple_name
-
-
-%{
-
-/* Déclarations issues de l'analyseur syntaxique... */
-
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-
-extern int type_lex_init(yyscan_t *scanner);
-extern YY_BUFFER_STATE type__scan_string(const char *, yyscan_t);
-extern void type__delete_buffer(YY_BUFFER_STATE, yyscan_t);
-extern int type_lex(YYSTYPE *, yyscan_t);
-extern int type_lex_destroy(yyscan_t);
-
-%}
-
-
-%%
-
-
-input:
- type_descriptor { G_DEMANGLING_CONTEXT(demangler)->type = $1; }
-
-type_descriptor:
- V { $$ = g_basic_type_new(BTP_VOID); }
- | field_type_descriptor { $$ = $1; }
-
-field_type_descriptor:
- non_array_field_type_descriptor { $$ = $1; }
- | ARRAY non_array_field_type_descriptor { $$ = $2; }
-
-non_array_field_type_descriptor:
- Z { $$ = g_basic_type_new(BTP_BOOL); }
- | B { $$ = g_basic_type_new(BTP_UCHAR); }
- | S { $$ = g_basic_type_new(BTP_SHORT); }
- | C { $$ = g_basic_type_new(BTP_CHAR); }
- | I { $$ = g_basic_type_new(BTP_INT); }
- | J { $$ = g_basic_type_new(BTP_LONG); }
- | F { $$ = g_basic_type_new(BTP_FLOAT); }
- | D { $$ = g_basic_type_new(BTP_DOUBLE); }
- | L full_class_name SEMICOLON { $$ = $2; }
-
-full_class_name:
- simple_name { $$ = g_class_enum_type_new(CET_CLASS, $1); }
- | full_class_name SLASH simple_name {
- $$ = g_class_enum_type_new(CET_CLASS, $3);
- g_data_type_set_namespace($$, $1);
- g_object_unref($1);
- }
-simple_name:
- TEXT { $$ = strdup($1); }
- | simple_name TEXT { $$ = stradd($1, $2); }
-
-%%
-
-
-/******************************************************************************
-* *
-* Paramètres : demangler = contexte associé à la procédure de décodage. *
-* scanner = données internes aux analyseurs. *
-* msg = indications humaines sur l'événement. *
-* *
-* Description : Affiche un message d'erreur concernant l'analyse. *
-* *
-* Retour : Valeur historique, ignorée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-static int type_error(GDexDemangler *demangler, yyscan_t scanner, char *msg)
-{
- return -1;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : demangler = contexte de décodage à utiliser. *
-* desc = chaîne de caractères à décoder. *
-* *
-* Description : Procède au décodage d'une chaîne de caractères. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool demangle_dex_type(GDexDemangler *demangler, const char *desc)
-{
- yyscan_t scanner; /* Données internes */
- YY_BUFFER_STATE buffer; /* Tampon pour bison */
- int ret; /* Bilan de l'appel */
-
- type_lex_init(&scanner);
-
- buffer = type__scan_string(desc, scanner);
- ret = yyparse(demangler, scanner);
- type__delete_buffer(buffer, scanner);
-
- type_lex_destroy(scanner);
-
- return (ret == 0);
-
-}
diff --git a/src/mangling/dex/type_tok.l b/src/mangling/dex/type_tok.l
deleted file mode 100644
index 7e85d43..0000000
--- a/src/mangling/dex/type_tok.l
+++ /dev/null
@@ -1,150 +0,0 @@
-
-%{
-
-#include "context.h"
-#include "libmanglingdextype_la-type_gram.h"
-
-/* See lemoda.net/c/reentrant-parser */
-
-%}
-
-
-%option noyywrap
-%option yylineno
-%option nounput
-/*%option noinput*/
-%option reentrant
-%option bison-bridge
-
-%x string
-
-ASCII [A-Za-z0-9]
-SIMPLE {ASCII}|"$"|"-"|"_"
-
-%%
-
-"V" { return V; }
-"Z" { return Z; }
-"B" { return B; }
-"S" { return S; }
-"C" { return C; }
-"I" { return I; }
-"J" { return J; }
-"F" { return F; }
-"D" { return D; }
-"L" { BEGIN(string); return L; }
-"["* { yylval->adeep = strlen(yytext); return ARRAY; }
-<string>"/" { return SLASH; }
-<string>";" { BEGIN(INITIAL); return SEMICOLON; }
-
-<string>{SIMPLE}* { yylval->text = yytext; return TEXT; }
-
-<string>. {
- unsigned char next;
- char mutf8[4];
-
- switch ((unsigned char)yytext[0])
- {
- /* U+00a1 ... U+1fff */
- case 0x00 ... 0x1f:
-
- next = input(yyscanner);
-
- if (yytext[0] == 0x00 && next < 0xa1)
- {
- REJECT;
- }
-
- else
- {
- mutf8[0] = yytext[0];
- mutf8[1] = next;
- mutf8[2] = '\0';
-
- strcpy(yylval->text, mutf8); return TEXT;
-
- }
-
- break;
-
- /* U+2010 ... U+2027 / U+2030 ... U+d7ff */
- case 0x20:
-
- next = input(yyscanner);
-
- switch (next)
- {
- case 0x10 ... 0x27:
- case 0x30 ... 0xff:
-
- mutf8[0] = yytext[0];
- mutf8[1] = next;
- mutf8[2] = '\0';
-
- strcpy(yylval->text, mutf8); return TEXT;
- break;
-
- default:
- REJECT;
- break;
-
- }
-
- break;
-
- /* ~ U+2030 ... U+d7ff */
- case 0x21 ... 0xd7:
-
- next = input(yyscanner);
-
- mutf8[0] = yytext[0];
- mutf8[1] = next;
- mutf8[2] = '\0';
-
- strcpy(yylval->text, mutf8); return TEXT;
- break;
-
- /* U+e000 ... U+ffef */
- case 0xe0 ... 0xff:
-
- next = input(yyscanner);
-
- if (yytext[0] == 0xff && next > 0xef)
- {
- REJECT;
- }
-
- else
- {
- mutf8[0] = yytext[0];
- mutf8[1] = next;
- mutf8[2] = '\0';
-
- strcpy(yylval->text, mutf8); return TEXT;
-
- }
-
- break;
-
- /* U+10000 ... U+10ffff */
- /*
- case 0x10:
-
- mutf8[0] = yytext[0];
- mutf8[1] = input(yyscanner);
- mutf8[2] = input(yyscanner);
- mutf8[3] = '\0';
-
- strcpy(yylval->text, mutf8); return TEXT;
- break;
- */
-
- default:
- REJECT;
- break;
-
- }
-
- }
-
-%%
diff --git a/tests/mangling/dex.py b/tests/mangling/dex.py
new file mode 100644
index 0000000..ad60953
--- /dev/null
+++ b/tests/mangling/dex.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python3-dbg
+# -*- coding: utf-8 -*-
+
+
+# Tests validant le décodage des types et des routines pour le format Dex
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.mangling import DexDemangler
+
+
+class TestDexMangling(ChrysalideTestCase):
+ """TestCase for pychrysalide.mangling.DexDemangler."""
+
+ def check_demangling(self, got, expected):
+ """Check a given demangling result."""
+
+ self.assertTrue(str(got) == expected)
+
+
+ def testDexTypeMangling(self):
+ """Check Dex type demangling."""
+
+ demangler = DexDemangler()
+
+ demangled = demangler.decode_type('V')
+ self.check_demangling(demangled, 'void')
+
+ demangled = demangler.decode_type('[I')
+ self.check_demangling(demangled, 'int []')
+
+ demangled = demangler.decode_type('[[I')
+ self.check_demangling(demangled, 'int [][]')
+
+ demangled = demangler.decode_type('Ltoto;')
+ self.check_demangling(demangled, 'toto')
+
+ demangled = demangler.decode_type('Ltiti/toto/tata;')
+ self.check_demangling(demangled, 'tata')
+
+
+ def testDexBadTypeMangling(self):
+ """Check Dex malformed type mangling."""
+
+ demangler = DexDemangler()
+
+ demangled = demangler.decode_type('Ltiti/toto/tata/;')
+ self.assertIsNone(demangled)
+
+
+ def testDexRoutineMangling(self):
+ """Check Dex routine demangling."""
+
+ demangler = DexDemangler()
+
+ demangled = demangler.decode_routine('I')
+ self.check_demangling(demangled, 'int ()')
+
+
+ def testDexBadRoutineMangling(self):
+ """Check Dex malformed routine mangling."""
+
+ demangler = DexDemangler()
+
+ demangled = demangler.decode_routine('IX')
+ self.assertIsNone(demangled)