diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-12-04 22:49:03 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-12-04 22:49:03 (GMT) |
commit | e146d7d8c7af50d2592379570c66acaf1dfa73c9 (patch) | |
tree | 31f20677a1a46427383080cba0c8f61652c8f51c /plugins/javadesc | |
parent | 9e58f9ae7208eeaf09a4b0af2f60996341d6af50 (diff) |
Updated the Java descriptor demangling process.
Diffstat (limited to 'plugins/javadesc')
-rw-r--r-- | plugins/javadesc/Makefile.am | 32 | ||||
-rw-r--r-- | plugins/javadesc/context.c | 209 | ||||
-rw-r--r-- | plugins/javadesc/context.h | 52 | ||||
-rw-r--r-- | plugins/javadesc/core.c | 64 | ||||
-rw-r--r-- | plugins/javadesc/core.h | 38 | ||||
-rw-r--r-- | plugins/javadesc/demangler.c | 175 | ||||
-rw-r--r-- | plugins/javadesc/demangler.h | 58 | ||||
-rw-r--r-- | plugins/javadesc/field.c | 344 | ||||
-rw-r--r-- | plugins/javadesc/field.h | 38 | ||||
-rw-r--r-- | plugins/javadesc/method.c | 152 | ||||
-rw-r--r-- | plugins/javadesc/method.h | 38 | ||||
-rw-r--r-- | plugins/javadesc/python/Makefile.am | 19 | ||||
-rw-r--r-- | plugins/javadesc/python/demangler.c | 145 | ||||
-rw-r--r-- | plugins/javadesc/python/demangler.h | 42 | ||||
-rw-r--r-- | plugins/javadesc/python/module.c | 61 | ||||
-rw-r--r-- | plugins/javadesc/python/module.h | 38 |
16 files changed, 1505 insertions, 0 deletions
diff --git a/plugins/javadesc/Makefile.am b/plugins/javadesc/Makefile.am new file mode 100644 index 0000000..bc55192 --- /dev/null +++ b/plugins/javadesc/Makefile.am @@ -0,0 +1,32 @@ + +lib_LTLIBRARIES = libjavadesc.la + +libdir = $(pluginslibdir) + + +libjavadesc_la_SOURCES = \ + context.h context.c \ + core.h core.c \ + demangler.h demangler.c \ + field.h field.c \ + method.h method.c + +libjavadesc_la_LIBADD = \ + python/libjavadescpython.la + +libjavadesc_la_LDFLAGS = \ + -L$(top_srcdir)/src/.libs -lchrysacore \ + -Wl,-rpath,$(abs_top_srcdir)/plugins/pychrysalide/.libs \ + -L$(top_srcdir)/plugins/pychrysalide/.libs -l:pychrysalide.so + + +devdir = $(includedir)/chrysalide-$(subdir) + +dev_HEADERS = $(libjavadesc_la_SOURCES:%c=) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) -I$(top_srcdir)/src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = python diff --git a/plugins/javadesc/context.c b/plugins/javadesc/context.c new file mode 100644 index 0000000..9ed5454 --- /dev/null +++ b/plugins/javadesc/context.c @@ -0,0 +1,209 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * context.c - fourniture de contexte aux phases de décodage Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "context.h" + + +#include <mangling/context-int.h> + + +#include "field.h" +#include "method.h" + + + +/* Contexte de décodage Java (instance) */ +struct _GJavaDemangling +{ + GDemanglingContext parent; /* A laisser en premier */ + +}; + +/* Contexte de décodage Java (classe) */ +struct _GJavaDemanglingClass +{ + GDemanglingContextClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe des contextes de décodage. */ +static void g_java_demangling_class_init(GJavaDemanglingClass *); + +/* Initialise une instance de contexte pour décodage. */ +static void g_java_demangling_init(GJavaDemangling *); + +/* Supprime toutes les références externes. */ +static void g_java_demangling_dispose(GJavaDemangling *); + +/* Procède à la libération totale de la mémoire. */ +static void g_java_demangling_finalize(GJavaDemangling *); + +/* Décode une définition de type pour Java. */ +static GDataType *g_java_demangling_decode_type(GJavaDemangling *); + +/* Décode une définition de routine pour Java. */ +static GBinRoutine *g_java_demangling_decode_routine(GJavaDemangling *); + + + +/* Indique le type défini pour un contexte de décodage. */ +G_DEFINE_TYPE(GJavaDemangling, g_java_demangling, G_TYPE_DEMANGLING_CONTEXT); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des contextes de décodage. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_java_demangling_class_init(GJavaDemanglingClass *klass) +{ + GObjectClass *object; /* Autre version de la classe */ + GDemanglingContextClass *context; /* Version de base du contexte */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_java_demangling_dispose; + object->finalize = (GObjectFinalizeFunc)g_java_demangling_finalize; + + context = G_DEMANGLING_CONTEXT_CLASS(klass); + + context->decode_type = (decode_type_fc)g_java_demangling_decode_type; + context->decode_routine = (decode_routine_fc)g_java_demangling_decode_routine; + +} + + +/****************************************************************************** +* * +* Paramètres : context = instance à initialiser. * +* * +* Description : Initialise une instance de contexte pour décodage. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_java_demangling_init(GJavaDemangling *context) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : context = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_java_demangling_dispose(GJavaDemangling *context) +{ + G_OBJECT_CLASS(g_java_demangling_parent_class)->dispose(G_OBJECT(context)); + +} + + +/****************************************************************************** +* * +* Paramètres : context = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_java_demangling_finalize(GJavaDemangling *context) +{ + G_OBJECT_CLASS(g_java_demangling_parent_class)->finalize(G_OBJECT(context)); + +} + + +/****************************************************************************** +* * +* Paramètres : context = environnement de décodage à manipuler. * +* * +* Description : Décode une définition de type pour Java. * +* * +* Retour : Nouvelle instance créée ou NULL en cas d'erreur fatale. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GDataType *g_java_demangling_decode_type(GJavaDemangling *context) +{ + GDataType *result; /* Type construit à retourner */ + GDemanglingContext *base; /* Autre version du contexte */ + + base = G_DEMANGLING_CONTEXT(context); + + result = jtd_field_descriptor(&base->buffer); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : context = environnement de décodage à manipuler. * +* * +* Description : Décode une définition de routine pour Java. * +* * +* Retour : Nouvelle instance créée ou NULL en cas d'erreur fatale. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GBinRoutine *g_java_demangling_decode_routine(GJavaDemangling *context) +{ + GBinRoutine *result; /* Routine en place à retourner*/ + GDemanglingContext *base; /* Autre version du contexte */ + + base = G_DEMANGLING_CONTEXT(context); + + result = jmd_method_descriptor(&base->buffer); + + return result; + +} diff --git a/plugins/javadesc/context.h b/plugins/javadesc/context.h new file mode 100644 index 0000000..004bbb2 --- /dev/null +++ b/plugins/javadesc/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 Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_JAVADESC_CONTEXT_H +#define _PLUGINS_JAVADESC_CONTEXT_H + + +#include <glib-object.h> + + + +#define G_TYPE_JAVA_DEMANGLING g_java_demangling_get_type() +#define G_JAVA_DEMANGLING(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_JAVA_DEMANGLING, GJavaDemangling)) +#define G_IS_JAVA_DEMANGLING(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_JAVA_DEMANGLING)) +#define G_JAVA_DEMANGLING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_JAVA_DEMANGLING, GJavaDemanglingClass)) +#define G_IS_JAVA_DEMANGLING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_JAVA_DEMANGLING)) +#define G_JAVA_DEMANGLING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_JAVA_DEMANGLING, GJavaDemanglingClass)) + + +/* Contexte de décodage Java (instance) */ +typedef struct _GJavaDemangling GJavaDemangling; + +/* Contexte de décodage Java (classe) */ +typedef struct _GJavaDemanglingClass GJavaDemanglingClass; + + +/* Indique le type défini pour un contexte de décodage Java. */ +GType g_java_demangling_get_type(void); + + + +#endif /* _PLUGINS_JAVADESC_CONTEXT_H */ diff --git a/plugins/javadesc/core.c b/plugins/javadesc/core.c new file mode 100644 index 0000000..e374749 --- /dev/null +++ b/plugins/javadesc/core.c @@ -0,0 +1,64 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * core.c - intégration du décodage pour symboles Java + * + * 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 Chrysalide. 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("javadesc", "Symbol demangler for Java", "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("java", G_TYPE_JAVA_DEMANGLER); + + if (result) + result = add_mangling_javadesc_module_to_python_module(); + + return result; + +} diff --git a/plugins/javadesc/core.h b/plugins/javadesc/core.h new file mode 100644 index 0000000..8938c2e --- /dev/null +++ b/plugins/javadesc/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 Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_JAVADESC_CORE_H +#define _PLUGINS_JAVADESC_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_JAVADESC_CORE_H */ diff --git a/plugins/javadesc/demangler.c b/plugins/javadesc/demangler.c new file mode 100644 index 0000000..78b62f1 --- /dev/null +++ b/plugins/javadesc/demangler.c @@ -0,0 +1,175 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * demangler.c - décodage des noms d'éléments Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "demangler.h" + + +#include <mangling/demangler-int.h> + + +#include "context.h" + + + +/* Décodeur de désignations Java (instance) */ +struct _GJavaDemangler +{ + GCompDemangler parent; /* A laisser en premier */ + +}; + +/* Décodeur de désignations Java (classe) */ +struct _GJavaDemanglerClass +{ + GCompDemanglerClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe des décodeurs de désignations. */ +static void g_java_demangler_class_init(GJavaDemanglerClass *); + +/* Initialise une instance de décodeur de désignations. */ +static void g_java_demangler_init(GJavaDemangler *); + +/* Supprime toutes les références externes. */ +static void g_java_demangler_dispose(GJavaDemangler *); + +/* Procède à la libération totale de la mémoire. */ +static void g_java_demangler_finalize(GJavaDemangler *); + + + +/* Indique le type défini pour un décodeur de désignations. */ +G_DEFINE_TYPE(GJavaDemangler, g_java_demangler, G_TYPE_COMP_DEMANGLER); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des décodeurs de désignations Java. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_java_demangler_class_init(GJavaDemanglerClass *klass) +{ + GObjectClass *object; /* Autre version de la classe */ + GCompDemanglerClass *demangler; /* Version parente basique */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_java_demangler_dispose; + object->finalize = (GObjectFinalizeFunc)g_java_demangler_finalize; + + demangler = G_COMP_DEMANGLER_CLASS(klass); + + demangler->can_demangle = (can_be_demangled_fc)NULL; + + demangler->ns_sep = "."; + demangler->context_type = G_TYPE_JAVA_DEMANGLING; + +} + + +/****************************************************************************** +* * +* Paramètres : demangler = instance à initialiser. * +* * +* Description : Initialise une instance de décodeur de désignations Java. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_java_demangler_init(GJavaDemangler *demangler) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : demangler = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_java_demangler_dispose(GJavaDemangler *demangler) +{ + G_OBJECT_CLASS(g_java_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_java_demangler_finalize(GJavaDemangler *demangler) +{ + G_OBJECT_CLASS(g_java_demangler_parent_class)->finalize(G_OBJECT(demangler)); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place un nouveau décodeur de symboles pour Java. * +* * +* Retour : Instance obtenue ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GCompDemangler *g_java_demangler_new(void) +{ + GJavaDemangler *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_JAVA_DEMANGLER, NULL); + + return G_COMP_DEMANGLER(result); + +} diff --git a/plugins/javadesc/demangler.h b/plugins/javadesc/demangler.h new file mode 100644 index 0000000..965ed51 --- /dev/null +++ b/plugins/javadesc/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 Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_JAVADESC_DEMANGLER_H +#define _PLUGINS_JAVADESC_DEMANGLER_H + + +#include <glib-object.h> + + +#include <mangling/demangler.h> + + + +#define G_TYPE_JAVA_DEMANGLER g_java_demangler_get_type() +#define G_JAVA_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_JAVA_DEMANGLER, GJavaDemangler)) +#define G_IS_JAVA_DEMANGLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_JAVA_DEMANGLER)) +#define G_JAVA_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_JAVA_DEMANGLER, GJavaDemanglerClass)) +#define G_IS_JAVA_DEMANGLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_JAVA_DEMANGLER)) +#define G_JAVA_DEMANGLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_JAVA_DEMANGLER, GJavaDemanglerClass)) + + +/* Décodeur de désignations Java (instance) */ +typedef struct _GJavaDemangler GJavaDemangler; + +/* Décodeur de désignations Java (classe) */ +typedef struct _GJavaDemanglerClass GJavaDemanglerClass; + + +/* Indique le type défini pour un décodeur de désignations Java. */ +GType g_java_demangler_get_type(void); + +/* Met en place un nouveau décodeur de symboles pour Java. */ +GCompDemangler *g_java_demangler_new(void); + + + +#endif /* _PLUGINS_JAVADESC_DEMANGLER_H */ diff --git a/plugins/javadesc/field.c b/plugins/javadesc/field.c new file mode 100644 index 0000000..95b0b8f --- /dev/null +++ b/plugins/javadesc/field.c @@ -0,0 +1,344 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * type.c - décodage de types pour Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "field.h" + + +#include <malloc.h> +#include <string.h> + + +#include <analysis/types/basic.h> +#include <analysis/types/cse.h> +#include <analysis/types/encaps.h> + + + +/* Extrait un type particulier dans un décodage Java. */ +static GDataType *jtd_object_type_descriptor(input_buffer *); + +/* Extrait un type particulier dans un décodage Java. */ +static GDataType *jtd_array_type_descriptor(input_buffer *); + +/* Extrait un type particulier dans un décodage Java. */ +static GDataType *jtd_base_type_descriptor(input_buffer *, char); + + + +/****************************************************************************** +* * +* Paramètres : buffer = tampon contenant les données utiles. * +* * +* Description : Extrait un type particulier dans un décodage Java. * +* * +* Retour : Nouveau type mis en place ou NULL en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GDataType *jtd_object_type_descriptor(input_buffer *buffer) +{ + GDataType *result; /* Classe à retourner */ + char *name; /* Désignation récupérée */ + size_t len; /* Taille de cette désignation */ + char next; /* Prochain caractère obtenu */ + GDataType *root; /* Espace de noms racine */ + GDataType *ns; /* Espace de noms à attribuer */ + GDataType *parent; /* Espace de noms parent */ + + result = NULL; + + name = NULL; + len = 0; + + do + { + next = get_input_buffer_next_char(buffer); + + if (next == ';') + break; + + else if (next == '/' || next == '$') + { + /** + * Il faut obligatoirement avoir déjà traité un nom de paquet ! + */ + if (len == 0) + break; + + name = realloc(name, ++len * sizeof(char)); + + name[len - 1] = '\0'; + + root = g_class_enum_type_new(CET_CLASS, name); + + /** + * Pour éviter les fuites si aucun paquet n'est présent... + */ + name = NULL; + + result = jtd_object_type_descriptor(buffer); + + if (result == NULL) + g_object_unref(G_OBJECT(root)); + + else + { + ns = g_data_type_get_namespace(result); + + if (ns == NULL) + g_data_type_set_namespace(result, root, strdup(".")); + + else + { + while ((parent = g_data_type_get_namespace(ns)) != NULL) + { + g_object_unref(G_OBJECT(ns)); + ns = parent; + } + + g_data_type_set_namespace(ns, root, strdup(".")); + + g_object_unref(G_OBJECT(ns)); + + } + + } + + break; + + } + + else if (next != '\0') + { + name = realloc(name, ++len * sizeof(char)); + + name[len - 1] = next; + + } + + else + { + if (name != NULL) + { + free(name); + name = NULL; + } + + break; + + } + + } + while (1); + + if (name != NULL) + result = g_class_enum_type_new(CET_CLASS, name); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : buffer = tampon contenant les données utiles. * +* * +* Description : Extrait un type particulier dans un décodage Java. * +* * +* Retour : Nouveau type mis en place ou NULL en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GDataType *jtd_array_type_descriptor(input_buffer *buffer) +{ + GDataType *result; /* Type à retourner */ + size_t dim; /* Dimension éventuelle */ + char ahead; /* Caractère déterminant lu */ + GDataType *descriptor; /* (Sous-)type à charger */ + + /** + * La règle traitée est la suivante : + * + * ArrayType: + * [ ComponentType + * + */ + + + dim = 0; + + do + { + dim++; + + ahead = peek_input_buffer_char(buffer); + + if (ahead == '[') + advance_input_buffer(buffer, 1); + else + break; + + } + while (1); + + descriptor = jtd_field_descriptor(buffer); + + if (descriptor == NULL) + result = NULL; + + 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 Java. * +* * +* Retour : Nouveau type mis en place ou NULL en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GDataType *jtd_base_type_descriptor(input_buffer *buffer, char ahead) +{ + GDataType *result; /* Type à retourner */ + + /** + * La règle traitée est la suivante : + * + * BaseType: + * B + * C + * D + * F + * I + * J + * S + * Z + * + */ + + switch (ahead) + { + case 'B': + result = g_basic_type_new(BTP_SCHAR); + break; + + case 'C': + result = g_basic_type_new(BTP_UCHAR); + break; + + case 'D': + result = g_basic_type_new(BTP_DOUBLE); + break; + + case 'F': + result = g_basic_type_new(BTP_FLOAT); + break; + + case 'I': + result = g_basic_type_new(BTP_INT); + break; + + case 'J': + result = g_basic_type_new(BTP_LONG); + break; + + case 'S': + result = g_basic_type_new(BTP_SHORT); + break; + + case 'Z': + result = g_basic_type_new(BTP_BOOL); + break; + + default: + result = NULL; + break; + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : buffer = tampon contenant les données utiles. * +* * +* Description : Extrait un type particulier dans un décodage Java. * +* * +* Retour : Nouveau type mis en place ou NULL en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDataType *jtd_field_descriptor(input_buffer *buffer) +{ + GDataType *result; /* Type à retourner */ + char ahead; /* Caractère déterminant lu */ + + /** + * La règle traitée est la suivante : + * + * FieldType: + * BaseType + * ObjectType + * ArrayType + * + * Cf. § 4.3.2. Field Descriptors + */ + + ahead = get_input_buffer_next_char(buffer); + + if (ahead == 'L') + result = jtd_object_type_descriptor(buffer); + + else if (ahead == '[') + result = jtd_array_type_descriptor(buffer); + + else + result = jtd_base_type_descriptor(buffer, ahead); + + return result; + +} diff --git a/plugins/javadesc/field.h b/plugins/javadesc/field.h new file mode 100644 index 0000000..9a802e7 --- /dev/null +++ b/plugins/javadesc/field.h @@ -0,0 +1,38 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * type.h - prototypes pour le décodage de types pour Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_JAVADESC_TYPE_H +#define _PLUGINS_JAVADESC_TYPE_H + + +#include <analysis/type.h> +#include <common/ibuf.h> + + + +/* Extrait un type particulier dans un décodage Java. */ +GDataType *jtd_field_descriptor(input_buffer *); + + + +#endif /* _PLUGINS_JAVADESC_TYPE_H */ diff --git a/plugins/javadesc/method.c b/plugins/javadesc/method.c new file mode 100644 index 0000000..b78665d --- /dev/null +++ b/plugins/javadesc/method.c @@ -0,0 +1,152 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * shorty.c - décodage de routines pour Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "method.h" + + +#include "field.h" + + + +/* Extrait un type particulier dans un décodage Java. */ +static GDataType *jmd_method_return_type(input_buffer *); + + + +/****************************************************************************** +* * +* Paramètres : buffer = tampon contenant les données utiles. * +* * +* Description : Extrait un type particulier dans un décodage Java. * +* * +* Retour : Nouveau type mis en place ou NULL en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GDataType *jmd_method_return_type(input_buffer *buffer) +{ + GDataType *result; /* Type à retourner */ + char ahead; /* Caractère déterminant lu */ + + /** + * La règle traitée est la suivante : + * + * ReturnDescriptor: + * FieldType + * V + * + */ + + ahead = peek_input_buffer_char(buffer); + + if (ahead == 'V') + { + advance_input_buffer(buffer, 1); + result = g_basic_type_new(BTP_VOID); + } + + else + result = jtd_field_descriptor(buffer); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : buffer = tampon contenant les données utiles. * +* * +* Description : Extrait un routine particulière depuis un codage Java. * +* * +* Retour : Nouveau type mis en place ou NULL en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GBinRoutine *jmd_method_descriptor(input_buffer *buffer) +{ + GBinRoutine *result; /* Type à retourner */ + char ahead; /* Caractère déterminant lu */ + GDataType *type; /* Description de type obtenue */ + GBinVariable *var; /* Argument de routine */ + + /** + * La règle traitée est la suivante : + * + * MethodDescriptor: + * ( {ParameterDescriptor} ) ReturnDescriptor + * + */ + + if (!check_input_buffer_char(buffer, '(')) + goto exit; + + result = g_binary_routine_new(); + + /* Arguments */ + + for (ahead = peek_input_buffer_char(buffer); + ahead != ')'; + ahead = peek_input_buffer_char(buffer)) + { + type = jtd_field_descriptor(buffer); + + if (type == NULL) + goto error; + + else + { + var = g_binary_variable_new(type); + g_binary_routine_add_arg(result, var); + } + + } + + if (!check_input_buffer_char(buffer, ')')) + goto error; + + /* Retour */ + + type = jmd_method_return_type(buffer); + + if (type == NULL) + goto error; + + else + g_binary_routine_set_return_type(result, type); + + return result; + + error: + + g_object_unref(G_OBJECT(result)); + + exit: + + return NULL; + +} diff --git a/plugins/javadesc/method.h b/plugins/javadesc/method.h new file mode 100644 index 0000000..3914c38 --- /dev/null +++ b/plugins/javadesc/method.h @@ -0,0 +1,38 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * shorty.h - prototypes pour le décodage de routines pour Java + * + * 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _PLUGINS_JAVADESC_SHORTY_H +#define _PLUGINS_JAVADESC_SHORTY_H + + +#include <analysis/routine.h> +#include <common/ibuf.h> + + + +/* Extrait un routine particulière depuis un codage Java. */ +GBinRoutine *jmd_method_descriptor(input_buffer *); + + + +#endif /* _PLUGINS_JAVADESC_SHORTY_H */ diff --git a/plugins/javadesc/python/Makefile.am b/plugins/javadesc/python/Makefile.am new file mode 100644 index 0000000..06deb3d --- /dev/null +++ b/plugins/javadesc/python/Makefile.am @@ -0,0 +1,19 @@ + +noinst_LTLIBRARIES = libjavadescpython.la + +libjavadescpython_la_SOURCES = \ + demangler.h demangler.c \ + module.h module.c + +libjavadescpython_la_LDFLAGS = + + +devdir = $(includedir)/chrysalide-$(subdir) + +dev_HEADERS = $(libjavadescpython_la_SOURCES:%c=) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/javadesc/python/demangler.c b/plugins/javadesc/python/demangler.c new file mode 100644 index 0000000..a62ca99 --- /dev/null +++ b/plugins/javadesc/python/demangler.c @@ -0,0 +1,145 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * demangler.c - équivalent Python du fichier "plugins/javadesc/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 'JavaDemangler'. */ +static PyObject *py_java_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 'JavaDemangler'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_java_demangler_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + GCompDemangler *demangler; /* Instance à transposer */ + + demangler = g_java_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_java_demangler_type(void) +{ + static PyMethodDef py_java_demangler_methods[] = { + { NULL } + }; + + static PyGetSetDef py_java_demangler_getseters[] = { + { NULL } + }; + + static PyTypeObject py_java_demangler_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.mangling.JavaDemangler", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide Java demangler", + + .tp_methods = py_java_demangler_methods, + .tp_getset = py_java_demangler_getseters, + .tp_new = py_java_demangler_new + + }; + + return &py_java_demangler_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....JavaDemangler'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_java_demangler(PyObject *module) +{ + PyTypeObject *py_java_demangler_type; /* Type Python 'JavaDemangler' */ + PyObject *dict; /* Dictionnaire du module */ + + py_java_demangler_type = get_python_java_demangler_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_JAVA_DEMANGLER, + py_java_demangler_type, get_python_compiler_demangler_type())) + return false; + + return true; + +} diff --git a/plugins/javadesc/python/demangler.h b/plugins/javadesc/python/demangler.h new file mode 100644 index 0000000..a4b48f1 --- /dev/null +++ b/plugins/javadesc/python/demangler.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * demangler.h - prototypes pour l'équivalent Python du fichier "plugins/javadesc/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_JAVADESC_PYTHON_DEMANGLER_H +#define _PLUGINS_JAVADESC_PYTHON_DEMANGLER_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_java_demangler_type(void); + +/* Prend en charge l'objet 'pychrysalide.format.mangling.JavaDemangler'. */ +bool register_python_java_demangler(PyObject *); + + + +#endif /* _PLUGINS_JAVADESC_PYTHON_DEMANGLER_H */ diff --git a/plugins/javadesc/python/module.c b/plugins/javadesc/python/module.c new file mode 100644 index 0000000..5211ba3 --- /dev/null +++ b/plugins/javadesc/python/module.c @@ -0,0 +1,61 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire javadesc 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 Java. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_mangling_javadesc_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_java_demangler(super); + + return result; + +} diff --git a/plugins/javadesc/python/module.h b/plugins/javadesc/python/module.h new file mode 100644 index 0000000..a3fc190 --- /dev/null +++ b/plugins/javadesc/python/module.h @@ -0,0 +1,38 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire javadesc 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_JAVADESC_PYTHON_MODULE_H +#define _PLUGINS_JAVADESC_PYTHON_MODULE_H + + +#include <stdbool.h> + + + +/* Etend le module 'mangling' avec des compléments pour Java. */ +bool add_mangling_javadesc_module_to_python_module(void); + + + +#endif /* _PLUGINS_JAVADESC_PYTHON_MODULE_H */ |