diff options
| -rw-r--r-- | ChangeLog | 19 | ||||
| -rw-r--r-- | src/format/elf/helper_x86.c | 36 | ||||
| -rw-r--r-- | src/format/elf/symbols.c | 22 | ||||
| -rw-r--r-- | src/format/mangling/demangler-int.h | 52 | ||||
| -rw-r--r-- | src/format/mangling/demangler.c | 84 | ||||
| -rw-r--r-- | src/format/mangling/demangler.h | 15 | ||||
| -rw-r--r-- | src/format/mangling/itanium.h | 6 | ||||
| -rw-r--r-- | src/format/mangling/itanium_gram.y | 23 | ||||
| -rw-r--r-- | src/format/mangling/java.h | 2 | ||||
| -rw-r--r-- | src/format/mangling/java_gram.y | 5 | 
10 files changed, 90 insertions, 174 deletions
@@ -1,6 +1,25 @@  10-08-01  Cyrille Bagard <nocbos@gmail.com>  	* src/format/elf/helper_x86.c: +	* src/format/elf/symbols.c: +	Update code. + +	* src/format/mangling/demangler.c: +	* src/format/mangling/demangler.h: +	Clean the code and provide a fast way to demangle strings. + +	* src/format/mangling/demangler-int.h: +	Deleted entry. + +	* src/format/mangling/itanium_gram.y: +	* src/format/mangling/itanium.h: +	* src/format/mangling/java_gram.y: +	* src/format/mangling/java.h: +	Clean the code. + +10-08-01  Cyrille Bagard <nocbos@gmail.com> + +	* src/format/elf/helper_x86.c:  	Print more warnings on decoding failures.  	* src/format/mangling/context.c: diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c index d74c7dd..3b9084c 100644 --- a/src/format/elf/helper_x86.c +++ b/src/format/elf/helper_x86.c @@ -291,27 +291,7 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru                          /* Routine */ -                        //printf("++ routine :: %s\n", "_ZN1N1TIiiE2mfES0_IddE"/*g_binary_symbol_to_string(symbols[j])*/); -                        printf("++ routine :: %s\n", g_binary_symbol_to_string(symbols[j])); -                        fflush(NULL); - -                        //routine = try_to_demangle_routine(get_demangler_by_type(DGT_ITANIUM), "_ZN1N1TIiiE2mfES0_IddE"); -                        routine = try_to_demangle_routine(get_demangler_by_type(DGT_ITANIUM), g_binary_symbol_to_string(symbols[j])); - -                        if (routine == NULL) -                        { -                            routine = g_binary_routine_new(); -                            g_binary_routine_set_name(routine, strdup(g_binary_symbol_to_string(symbols[j]))); -                            printf("++failed\n"); -                            //exit(0); -                        } -                        else printf("++success\n"); - -                        printf(" -->> '%s'\n", g_binary_routine_get_name(routine)); - -                        //if (strcmp(g_binary_symbol_to_string(symbols[j]), "_ZNSt8ios_base4InitC1Ev") == 0) -                        //if (strcmp(g_binary_symbol_to_string(symbols[j]), "_ZNSolsEPFRSoS_E") == 0) -                        //    exit(0); +                        routine = try_to_demangle_routine(g_binary_symbol_to_string(symbols[j]));                          g_binary_routine_set_address(routine, address); @@ -419,19 +399,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru              /* Routine */ -            printf("++ routine :: %s\n", name); -            fflush(NULL); - -            routine = try_to_demangle_routine(get_demangler_by_type(DGT_ITANIUM), name); - -            if (routine == NULL) -            { -                routine = g_binary_routine_new(); -                g_binary_routine_set_name(routine, strdup(name)); -                printf("++failed\n"); -                //exit(0); -            } -            else printf("++success\n"); +            routine = try_to_demangle_routine(name);              g_binary_routine_set_address(routine, address); diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c index 3928c27..8d06c05 100644 --- a/src/format/elf/symbols.c +++ b/src/format/elf/symbols.c @@ -218,27 +218,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)                  /* Routine */ -                printf("routine :: %s\n", name); -                fflush(NULL); - -                if (1/*strcmp(name, "_Z41__static_initialization_and_destruction_0ii") == 0*/) -                { - -                routine = try_to_demangle_routine(get_demangler_by_type(DGT_ITANIUM), name); - -                if (routine == NULL) -                { -                    routine = g_binary_routine_new(); -                    g_binary_routine_set_name(routine, strdup(name)); -                    printf("failed\n"); -                } -                else printf("success\n"); - -                printf(" -->> '%s'\n", g_binary_routine_get_name(routine)); - -                //exit(0); - -                } +                routine = try_to_demangle_routine(name);                  g_binary_routine_set_address(routine, ELF_SYM(format, sym, st_value));                  g_binary_routine_set_size(routine, ELF_SYM(format, sym, st_size)); diff --git a/src/format/mangling/demangler-int.h b/src/format/mangling/demangler-int.h deleted file mode 100644 index 8b8772c..0000000 --- a/src/format/mangling/demangler-int.h +++ /dev/null @@ -1,52 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * demangler-int.h - prototypes internes pour le décodage des noms d'éléments - * - * Copyright (C) 2008 Cyrille Bagard - * - *  This file is part of OpenIDA. - * - *  OpenIDA 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. - * - *  OpenIDA is distributed in the hope that it will be useful, - *  but WITHOUT ANY WARRANTY; without even the implied warranty of - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - *  GNU General Public License for more details. - * - *  You should have received a copy of the GNU General Public License - *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>. - */ - - -#ifndef _FORMAT_MANGLING_DEMANGLER_INT_H -#define _FORMAT_MANGLING_DEMANGLER_INT_H - - -#include "demangler.h" - - - -/* Indique si une chaîne peut être traitée par le décodeur. */ -typedef bool (* can_be_demangled_fc) (name_demangler *, const char *); - -/* Procède au décodage d'une chaîne de caractères. */ -typedef GBinRoutine * (* demangle_routine_fc) (name_demangler *, const char *); - - -/* Décodeur de nom d'éléments */ -struct _name_demangler -{ -    can_be_demangled_fc can_be_demangled;   /* Capacité de traitement      */ -    demangle_routine_fc demangle_routine;   /* Décodage de chaînes         */ - -}; - - -#define NAME_DEMANGLER(dmgl) ((name_demangler *)dmgl) - - - -#endif  /* _FORMAT_MANGLING_DEMANGLER_INT_H */ diff --git a/src/format/mangling/demangler.c b/src/format/mangling/demangler.c index de9fbbb..dec4cb5 100644 --- a/src/format/mangling/demangler.c +++ b/src/format/mangling/demangler.c @@ -25,29 +25,34 @@  #include <malloc.h> +#include <string.h> -#include "demangler-int.h"  #include "itanium.h"  #include "java.h" +/* Indique si une chaîne peut être traitée par le décodeur. */ +typedef bool (* can_be_demangled_fc) (const char *); +  /* Prépare de quoi effectuer un décodage. */  typedef GDemanglingContext * (* create_context_fc) (void);  /* Procède au décodage d'une chaîne de caractères. */ -typedef bool (* demangle_type_fc) (GDemanglingContext *, const char *); +typedef bool (* demangle_fc) (GDemanglingContext *, const char *);  /* Appels liés à un décodeur */  typedef struct _demangling_properties  { +    can_be_demangled_fc can_demangle;       /* Possibilité de traitement   */ +      create_context_fc create_context;       /* Création de contextes       */ -    demangle_type_fc demangle_routine;      /* Décodage d'une routine      */ -    demangle_type_fc demangle_type;         /* Décodage d'un type          */ +    demangle_fc demangle_routine;           /* Décodage d'une routine      */ +    demangle_fc demangle_type;              /* Décodage d'un type          */  } demangling_properties; @@ -56,15 +61,17 @@ typedef struct _demangling_properties  static demangling_properties demanglers[DGT_COUNT] = {      [DGT_ITANIUM] = { +        .can_demangle = (can_be_demangled_fc)can_be_itanium_demangled,          .create_context = (create_context_fc)g_itanium_dcontext_new, -        .demangle_routine = (demangle_type_fc)demangle_itanium_routine, -        .demangle_type = (demangle_type_fc)NULL +        .demangle_routine = (demangle_fc)demangle_itanium_routine, +        .demangle_type = (demangle_fc)NULL      },      [DGT_JAVA] = { +        .can_demangle = (can_be_demangled_fc)NULL,          .create_context = (create_context_fc)g_java_dcontext_new, -        .demangle_routine = (demangle_type_fc)NULL, -        .demangle_type = (demangle_type_fc)demangle_java_type +        .demangle_routine = (demangle_fc)NULL, +        .demangle_type = (demangle_fc)demangle_java_type      }  }; @@ -73,49 +80,54 @@ static demangling_properties demanglers[DGT_COUNT] = {  /******************************************************************************  *                                                                             * -*  Paramètres  : type = identifiant du décodeur visé.                         * +*  Paramètres  : desc = chaîne de caractères à décoder.                       *  *                                                                             * -*  Description : Fournit la référence correspondant à un décodeur donné.      * +*  Description : Tente de décoder une chaîne de caractères donnée.            *  *                                                                             * -*  Retour      : Adresse du décodeur trouvé ou NULL.                          * +*  Retour      : Bilan de l'opération.                                        *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -name_demangler *get_demangler_by_type(DemanglerType type) +GBinRoutine *try_to_demangle_routine(const char *desc)  { -    name_demangler *result;                 /* Adresse à retourner         */ +    GBinRoutine *result;                    /* Construction à remonter     */ +    DemanglerType i;                        /* Boucle de parcours          */ -    result = NULL;//demanglers[0]; +    result = NULL; -    return result; +    for (i = 0; i < DGT_COUNT; i++) +    { +        if (demanglers[i].can_demangle == NULL) +            continue; -} +        if (!demanglers[i].can_demangle(desc)) +            continue; +        printf("++ routine :: %s\n", desc); +        fflush(NULL); -/****************************************************************************** -*                                                                             * -*  Paramètres  : demangler = décodeur à utiliser.                             * -*                name      = chaîne de caractères à décoder.                  * -*                                                                             * -*  Description : Tente de décoder une chaîne de caractères donnée.            * -*                                                                             * -*  Retour      : Bilan de l'opération.                                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +        result = demangle_routine(i, desc); -GBinRoutine *try_to_demangle_routine(name_demangler *demangler, const char *name) -{ -    GBinRoutine *result;                    /* Construction à remonter     */ +        /* FIXME : à supprimer quand mature */ +        if (result == NULL) +        { +            printf("++failed :: %s\n", desc); +            exit(-1); +        } +        else printf(" -->> '%s'\n", g_binary_routine_get_name(result)); + +        if (result != NULL) break; + +    } + +    if (result == NULL) +    { +        result = g_binary_routine_new(); +        g_binary_routine_set_name(result, strdup(desc)); +    } -    result = NULL; -    /* -    if (demangler->can_be_demangled(demangler, name)) -        result = demangler->demangle_routine(demangler, name); -    */      return result;  } diff --git a/src/format/mangling/demangler.h b/src/format/mangling/demangler.h index 54ca0c0..8fd6947 100644 --- a/src/format/mangling/demangler.h +++ b/src/format/mangling/demangler.h @@ -40,21 +40,8 @@ typedef enum _DemanglerType  } DemanglerType; - - - -/* Décodeur de nom d'éléments */ -typedef struct _name_demangler name_demangler; - -/* Fournit la référence correspondant à un décodeur donné. */ -name_demangler *get_demangler_by_type(DemanglerType); -  /* Tente de décoder une chaîne de caractères donnée. */ -GBinRoutine *try_to_demangle_routine(name_demangler *, const char *); - - - - +GBinRoutine *try_to_demangle_routine(const char *);  /* Tente de décoder une chaîne de caractères donnée. */  GBinRoutine *demangle_routine(DemanglerType, const char *); diff --git a/src/format/mangling/itanium.h b/src/format/mangling/itanium.h index 7cdf97e..ed03796 100644 --- a/src/format/mangling/itanium.h +++ b/src/format/mangling/itanium.h @@ -48,15 +48,15 @@ GDemanglingContext *g_itanium_dcontext_new(void); +/* ------------------------ TRAITEMENT DE L'ENCODAGE ITANIUM ------------------------ */ +/* Indique si une chaîne peut être traitée par le décodeur. */ +bool can_be_itanium_demangled(const char *);  /* Procède au décodage d'une chaîne de caractères. */  bool demangle_itanium_routine(GItaniumDContext *, const char *); - - -  #endif  /* _FORMAT_MANGLING_ITANIUM_H */ diff --git a/src/format/mangling/itanium_gram.y b/src/format/mangling/itanium_gram.y index 9291f57..f8c02a2 100644 --- a/src/format/mangling/itanium_gram.y +++ b/src/format/mangling/itanium_gram.y @@ -8,7 +8,6 @@  #include "context-int.h" -#include "demangler-int.h"  #include "itanium.h"  #include "../../common/extstr.h" @@ -808,6 +807,12 @@ static GOpenidaType *g_itanium_dcontext_get_item(GItaniumDContext *context, guin +/* ---------------------------------------------------------------------------------- */ +/*                          TRAITEMENT DE L'ENCODAGE ITANIUM                          */ +/* ---------------------------------------------------------------------------------- */ + + + @@ -850,33 +855,27 @@ int yyerror(/*const YYLTYPE *yyloc, bool hunt, char **ucode, unsigned char *inde -#if 0 +  /******************************************************************************  *                                                                             * -*  Paramètres  : demangler = décodeur à utiliser.                             * -*                name      = chaîne de caractères à analyser.                 * +*  Paramètres  : desc = chaîne de caractères à décoder.                       *  *                                                                             *  *  Description : Indique si une chaîne peut être traitée par le décodeur.     *  *                                                                             * -*  Retour      : Bilan de l'opération.                                        * +*  Retour      : Bilan de l'analyse.                                          *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -bool can_be_itanium_demangled(itanium_demangler *itanium, const char *name) +bool can_be_itanium_demangled(const char *desc)  { -    return (strncmp(name, "_Z", 2) == 0); +    return (strncmp(desc, "_Z", 2) == 0);  } -#endif - - - -  /******************************************************************************  *                                                                             *  *  Paramètres  : context = contexte de décodage à utiliser.                   * diff --git a/src/format/mangling/java.h b/src/format/mangling/java.h index 08dafe3..a6349dc 100644 --- a/src/format/mangling/java.h +++ b/src/format/mangling/java.h @@ -48,7 +48,7 @@ GDemanglingContext *g_java_dcontext_new(void); - +/* ----------------------- TRAITEMENT DE L'ENCODAGE TYPE JAVA ----------------------- */  /* Procède au décodage d'une chaîne de caractères. */ diff --git a/src/format/mangling/java_gram.y b/src/format/mangling/java_gram.y index 859dce4..8b63c5f 100644 --- a/src/format/mangling/java_gram.y +++ b/src/format/mangling/java_gram.y @@ -4,7 +4,6 @@  #include "context-int.h" -#include "demangler-int.h"  #include "java.h" @@ -206,6 +205,10 @@ GDemanglingContext *g_java_dcontext_new(void) +/* ---------------------------------------------------------------------------------- */ +/*                         TRAITEMENT DE L'ENCODAGE TYPE JAVA                         */ +/* ---------------------------------------------------------------------------------- */ +  | 
