diff options
Diffstat (limited to 'plugins/dexbnf')
-rw-r--r-- | plugins/dexbnf/Makefile.am | 27 | ||||
-rw-r--r-- | plugins/dexbnf/context.c | 209 | ||||
-rw-r--r-- | plugins/dexbnf/context.h | 52 | ||||
-rw-r--r-- | plugins/dexbnf/core.c | 64 | ||||
-rw-r--r-- | plugins/dexbnf/core.h | 38 | ||||
-rw-r--r-- | plugins/dexbnf/demangler.c | 174 | ||||
-rw-r--r-- | plugins/dexbnf/demangler.h | 58 | ||||
-rw-r--r-- | plugins/dexbnf/python/Makefile.am | 15 | ||||
-rw-r--r-- | plugins/dexbnf/python/demangler.c | 145 | ||||
-rw-r--r-- | plugins/dexbnf/python/demangler.h | 42 | ||||
-rw-r--r-- | plugins/dexbnf/python/module.c | 61 | ||||
-rw-r--r-- | plugins/dexbnf/python/module.h | 38 | ||||
-rw-r--r-- | plugins/dexbnf/shorty.c | 227 | ||||
-rw-r--r-- | plugins/dexbnf/shorty.h | 38 | ||||
-rw-r--r-- | plugins/dexbnf/simple.c | 163 | ||||
-rw-r--r-- | plugins/dexbnf/simple.h | 37 | ||||
-rw-r--r-- | plugins/dexbnf/type.c | 316 | ||||
-rw-r--r-- | plugins/dexbnf/type.h | 38 |
18 files changed, 1742 insertions, 0 deletions
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/plugins/dexbnf/demangler.c b/plugins/dexbnf/demangler.c new file mode 100644 index 0000000..e021b45 --- /dev/null +++ b/plugins/dexbnf/demangler.c @@ -0,0 +1,174 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * demangler.c - décodage des noms d'éléments + * + * 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 "demangler.h" + + +#include <mangling/demangler-int.h> + + +#include "context.h" + + + +/* Décodeur de désignations Dex (instance) */ +struct _GDexDemangler +{ + GCompDemangler parent; /* A laisser en premier */ + +}; + +/* Décodeur de désignations Dex (classe) */ +struct _GDexDemanglerClass +{ + GCompDemanglerClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe des décodeurs de désignations. */ +static void g_dex_demangler_class_init(GDexDemanglerClass *); + +/* Initialise une instance de décodeur de désignations. */ +static void g_dex_demangler_init(GDexDemangler *); + +/* Supprime toutes les références externes. */ +static void g_dex_demangler_dispose(GDexDemangler *); + +/* Procède à la libération totale de la mémoire. */ +static void g_dex_demangler_finalize(GDexDemangler *); + + + +/* 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 décodeurs de désignations Dex. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dex_demangler_class_init(GDexDemanglerClass *klass) +{ + GObjectClass *object; /* Autre version de la classe */ + GCompDemanglerClass *demangler; /* Version parente basique */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_dex_demangler_dispose; + object->finalize = (GObjectFinalizeFunc)g_dex_demangler_finalize; + + demangler = G_COMP_DEMANGLER_CLASS(klass); + + demangler->can_demangle = (can_be_demangled_fc)NULL; + + demangler->context_type = G_TYPE_DEX_DEMANGLING; + +} + + +/****************************************************************************** +* * +* Paramètres : demangler = instance à initialiser. * +* * +* Description : Initialise une instance de décodeur de désignations Dex. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dex_demangler_init(GDexDemangler *demangler) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : demangler = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dex_demangler_dispose(GDexDemangler *demangler) +{ + G_OBJECT_CLASS(g_dex_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_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 */ |