diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/analysis/decomp/decompiler.c | 3 | ||||
| -rw-r--r-- | src/analysis/disass/output.c | 32 | ||||
| -rw-r--r-- | src/analysis/routine.c | 50 | ||||
| -rw-r--r-- | src/analysis/routine.h | 6 | ||||
| -rw-r--r-- | src/format/Makefile.am | 1 | ||||
| -rw-r--r-- | src/format/symbol-int.h | 60 | ||||
| -rw-r--r-- | src/format/symbol.c | 202 | ||||
| -rw-r--r-- | src/format/symbol.h | 54 | 
8 files changed, 78 insertions, 330 deletions
diff --git a/src/analysis/decomp/decompiler.c b/src/analysis/decomp/decompiler.c index 0caf4e4..5b2d231 100644 --- a/src/analysis/decomp/decompiler.c +++ b/src/analysis/decomp/decompiler.c @@ -152,7 +152,8 @@ static void prepare_all_routines_for_decomp(const GLoadedBinary *binary, const c      proc = NULL;//get_arch_processor_from_format(G_EXE_FORMAT(format)); -    routines = g_binary_format_get_routines(G_BIN_FORMAT(format), &count); +    routines = NULL; //g_binary_format_get_routines(G_BIN_FORMAT(format), &count); +    count = 0; diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c index 421cfb6..40cd12b 100644 --- a/src/analysis/disass/output.c +++ b/src/analysis/disass/output.c @@ -89,8 +89,6 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,      BufferLineFlags flags;                  /* Propriétés pour la ligne    */      //mrange_t range;                         /* Couverture sans surface     */ -    GDbComment *_comment;                    /* Commentaire à ajouter       */ - @@ -288,33 +286,21 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,              if (g_binary_symbol_get_target_type(symbols[sym_index]) == STP_ENTRY_POINT)                  flags |= BLF_ENTRYPOINT; -            /* Début d'un groupe bien cohérent avec les alignements ? */ - -            if (g_binary_symbol_is_block_start(symbols[sym_index])) -                flags |= BLF_WIDTH_MANAGER; - -        } - -        g_buffer_cache_append(cache, G_LINE_GENERATOR(instr), flags); - +            /** +             * Début d'un groupe bien cohérent avec les alignements ? +             * +             * On décide que, à partir du moment où il y a un symbole, il y a +             * là le début d'un nouveau bloc avec sa propre nouvelle gestion +             * des largeurs, quelque soit le type du symbole en question ! +             */ - -        ////////////////////////////////// -        if (compared == 0) -        { -            /* Commentaire ? */ - -            _comment = g_binary_symbol_get_comment(symbols[sym_index]); - -            if (_comment != NULL) -                g_db_item_apply(G_DB_ITEM(_comment), binary); +            flags |= BLF_WIDTH_MANAGER;              sym_index++;          } -        /////////////////////////////////////// - +        g_buffer_cache_append(cache, G_LINE_GENERATOR(instr), flags);          /* Commentaire en bout de ligne ? */ diff --git a/src/analysis/routine.c b/src/analysis/routine.c index 583e151..c916c66 100644 --- a/src/analysis/routine.c +++ b/src/analysis/routine.c @@ -36,13 +36,14 @@  #include "../arch/raw.h"  #include "../common/extstr.h"  #include "../core/params.h" +#include "../format/symbol-int.h"  /* Représentation générique de routine (instance) */  struct _GBinRoutine  { -    GObject parent;                         /* A laisser en premier        */ +    GBinSymbol parent;                      /* A laisser en premier        */      mrange_t range;                         /* Couverture mémoire          */ @@ -64,7 +65,6 @@ struct _GBinRoutine      GBinVariable **locals;                  /* Variables locales du code   */      size_t locals_count;                    /* Nombre de variables locales */ -    GArchInstruction *instr;                /* Instructions natives        */      GBlockList *blocks;                     /* Blocs basiques d'instruct°  */      //GDecInstruction *dinstr;                /* Instructions décompilées    */ @@ -74,7 +74,7 @@ struct _GBinRoutine  /* Représentation générique de routine (classe) */  struct _GBinRoutineClass  { -    GObjectClass parent;                    /* A laisser en premier        */ +    GBinSymbolClass parent;                 /* A laisser en premier        */  }; @@ -91,7 +91,7 @@ static void g_binary_routine_reset_declarator(GBinRoutine *, bool);  /* Indique le type définit pour une représentation de routine. */ -G_DEFINE_TYPE(GBinRoutine, g_bin_routine, G_TYPE_OBJECT); +G_DEFINE_TYPE(GBinRoutine, g_bin_routine, G_TYPE_BIN_SYMBOL);  /****************************************************************************** @@ -808,48 +808,6 @@ size_t g_binary_routine_get_var_index_from_offset(const GBinRoutine *routine, si  *                                                                             *  *  Paramètres  : routine = routine à consulter.                               *  *                                                                             * -*  Description : Fournit les instructions natives correspondantes.            * -*                                                                             * -*  Retour      : Ensemble d'instructions décompilées ou NULL.                 * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchInstruction *g_binary_routine_get_instructions(const GBinRoutine *routine) -{ -    return routine->instr; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : routine = routine à mettre à jour.                           * -*                instr   = série d'instructions à conserver.                  * -*                                                                             * -*  Description : Définit les instructions natives de la routine.              * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_routine_set_instructions(GBinRoutine *routine, GArchInstruction *instr) -{ -    if (routine->instr != NULL) -        g_object_unref(G_OBJECT(routine->instr)); - -    routine->instr = instr; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : routine = routine à consulter.                               * -*                                                                             *  *  Description : Fournit les blocs basiques de la routine.                    *  *                                                                             *  *  Retour      : Ensemble de blocs déterminés via les instructions.           * diff --git a/src/analysis/routine.h b/src/analysis/routine.h index e880118..b040c6c 100644 --- a/src/analysis/routine.h +++ b/src/analysis/routine.h @@ -158,12 +158,6 @@ void g_binary_routine_register_if_needed(GBinRoutine *, size_t, bool);  /* Donne l'indice d'une variable dans la liste d'une routine. */  size_t g_binary_routine_get_var_index_from_offset(const GBinRoutine *, size_t, bool); -/* Fournit les instructions natives correspondantes. */ -GArchInstruction *g_binary_routine_get_instructions(const GBinRoutine *); - -/* Définit les instructions natives de la routine. */ -void g_binary_routine_set_instructions(GBinRoutine *, GArchInstruction *); -  /* Fournit les blocs basiques de la routine. */  GBlockList *g_binary_routine_get_basic_blocks(const GBinRoutine *); diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 2fef6c6..3501dda 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -10,6 +10,7 @@ libformat_la_SOURCES =					\  	format.h format.c					\  	preload-int.h						\  	preload.h preload.c					\ +	symbol-int.h						\  	symbol.h symbol.c  libformat_la_LIBADD =					\ diff --git a/src/format/symbol-int.h b/src/format/symbol-int.h new file mode 100644 index 0000000..4a79a65 --- /dev/null +++ b/src/format/symbol-int.h @@ -0,0 +1,60 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * symbol-int.h - prototypes pour la définition interne des symboles dans un binaire + * + * Copyright (C) 2017 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _FORMAT_SYMBOL_INT_H +#define _FORMAT_SYMBOL_INT_H + + +#include "symbol.h" + + + +/* Symbole d'exécutable (instance) */ +struct _GBinSymbol +{ +    GObject parent;                         /* A laisser en premier        */ + +    SymbolType type;                        /* Type du symbole             */ + +    char *alt;                              /* Nom alternatif              */ + +    union +    { +        GArchInstruction *instr;            /* Instruction correspondante  */ +        GBinRoutine *routine;               /* Compléments pour fonction   */ + +    } extra; + +}; + +/* Symbole d'exécutable (classe) */ +struct _GBinSymbolClass +{ +    GObjectClass parent;                    /* A laisser en premier        */ + +}; + + + + +#endif  /* _FORMAT_SYMBOL_INT_H */ diff --git a/src/format/symbol.c b/src/format/symbol.c index 16e54ef..2611a40 100644 --- a/src/format/symbol.c +++ b/src/format/symbol.c @@ -28,6 +28,7 @@  #include <string.h> +#include "symbol-int.h"  #include "../glibext/linegen-int.h" @@ -35,35 +36,6 @@  /* --------------------- FONCTIONNALITES BASIQUES POUR SYMBOLES --------------------- */ -/* Symbole d'exécutable (instance) */ -struct _GBinSymbol -{ -    GObject parent;                         /* A laisser en premier        */ - -    SymbolType type;                        /* Type du symbole             */ - -    bool block_start;                       /* Début d'un bloc ?           */ -    char *alt;                              /* Nom alternatif              */ - -    union -    { -        GArchInstruction *instr;            /* Instruction correspondante  */ -        GBinRoutine *routine;               /* Compléments pour fonction   */ - -    } extra; - -    GDbComment *comment;                    /* Eventuel commentaire lié    */ - -}; - -/* Symbole d'exécutable (classe) */ -struct _GBinSymbolClass -{ -    GObjectClass parent;                    /* A laisser en premier        */ - -}; - -  /* Initialise la classe des symboles d'exécutables. */  static void g_binary_symbol_class_init(GBinSymbolClass *); @@ -334,65 +306,6 @@ SymbolType g_binary_symbol_get_target_type(const GBinSymbol *symbol)  /******************************************************************************  *                                                                             * -*  Paramètres  : symbol = symbole à venir compléter.                          * -*                start  = indication quant à la nature du symbole.            * -*                                                                             * -*  Description : Définit si un symbole est susceptible de démarrer un bloc.   * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_symbol_define_as_block_start(GBinSymbol *symbol, bool start) -{ -    symbol->block_start = start; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : symbol = symbole à venir consulter.                          * -*                                                                             * -*  Description : Indique si un symbole est susceptible de démarrer un bloc.   * -*                                                                             * -*  Retour      : Capacité de rassemblement du symbole.                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool g_binary_symbol_is_block_start(GBinSymbol *symbol) -{ -    bool result;                            /* Statut à retourner          */ - -    switch (g_binary_symbol_get_target_type(symbol)) -    { -        case STP_ROUTINE: -        case STP_OBJECT: -        case STP_ENTRY_POINT: -        case STP_STRING: -        case STP_RO_STRING: -            result = true; -            break; - -        default: -            result = false; -            break; - -    } - -    result |= symbol->block_start; - -    return result; - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : symbol = symbole à venir consulter.                          *  *                                                                             *  *  Description : Fournit un étiquette pour viser un symbole.                  * @@ -459,66 +372,6 @@ void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt)  /******************************************************************************  *                                                                             * -*  Paramètres  : symbol = symbole à venir mettre à jour.                      * -*                full   = adresse dont la définition est complète.            * -*                                                                             * -*  Description : Raffine la définition de l'emplacement d'un symbole.         * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_symbol_fix_range(GBinSymbol *symbol, const vmpa2t *full) -{ -    GArchInstruction *instr;                /* Instruction associée        */ -    mrange_t range;                         /* Plage à manipuler           */ -    GBinRoutine *routine;                   /* Routine associée            */ - -    switch (symbol->type) -    { -        case STP_DATA: -        case STP_RO_STRING: - -            instr = g_binary_symbol_get_instruction(symbol); - -            copy_mrange(&range, g_arch_instruction_get_range(instr)); - -            assert(cmp_vmpa(get_mrange_addr(&range), full) == 0); - -            copy_vmpa(get_mrange_addr(&range), full); - -            g_arch_instruction_set_range(instr, &range); - -            break; - -        case STP_ROUTINE: -        case STP_ENTRY_POINT: -        case STP_CODE_LABEL: - -            routine = g_binary_symbol_get_routine(symbol); - -            copy_mrange(&range, g_binary_routine_get_range(routine)); - -            assert(cmp_vmpa(get_mrange_addr(&range), full) == 0); - -            copy_vmpa(get_mrange_addr(&range), full); - -            g_binary_routine_set_range(routine, &range); - -            break; - -        default: -            break; - -    } - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : symbol = symbole à venir consulter.                          *  *                                                                             *  *  Description : Fournit l'emplacement où se situe un symbole.                * @@ -675,59 +528,6 @@ GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *symbol)  } -/****************************************************************************** -*                                                                             * -*  Paramètres  : symbol  = symbole à venir manipuler.                         * -*                comment = commentaire construit à propos du symbole.         * -*                                                                             * -*  Description : Ajoute un commentaire facultatif au symbole.                 * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_symbol_set_comment(GBinSymbol *symbol, GDbComment *comment) -{ -#ifndef NDEBUG -    const vmpa2t *saddr;                    /* Adresse du symbole          */ -    const vmpa2t *caddr;                    /* Adresse du commentaire      */ -#endif - -#ifndef NDEBUG - -    saddr = get_mrange_addr(g_binary_symbol_get_range(symbol)); -    caddr = g_db_comment_get_address(comment); - -    assert(cmp_vmpa(saddr, caddr) == 0); - -#endif - -    symbol->comment = comment; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : symbol = symbole à venir consulter.                          * -*                                                                             * -*  Description : Fournit l'éventuel commentaire associé au symbole.           * -*                                                                             * -*  Retour      : Instance GLib en place ou NULL si aucune.                    * -*                                                                             * -*  Remarques   : Il n'y a pas de transfert de propriété ici !                 * -*                                                                             * -******************************************************************************/ - -GDbComment *g_binary_symbol_get_comment(const GBinSymbol *symbol) -{ -    return symbol->comment; - -} - -  /* ---------------------------------------------------------------------------------- */  /*                          OFFRE DE CAPACITES DE GENERATION                          */ diff --git a/src/format/symbol.h b/src/format/symbol.h index 694a9ee..0d40529 100644 --- a/src/format/symbol.h +++ b/src/format/symbol.h @@ -89,21 +89,12 @@ int g_binary_symbol_cmp_with_vmpa(const GBinSymbol *, const vmpa2t *);  /* Fournit le type du symbole. */  SymbolType g_binary_symbol_get_target_type(const GBinSymbol *); -/* Définit si un symbole est susceptible de démarrer un bloc. */ -void g_binary_symbol_define_as_block_start(GBinSymbol *, bool); - -/* Indique si un symbole est susceptible de démarrer un bloc. */ -bool g_binary_symbol_is_block_start(GBinSymbol *); -  /* Fournit un étiquette pour viser un symbole. */  const char *g_binary_symbol_get_label(const GBinSymbol *);  /* Définit un autre nom pour le symbole. */  void g_binary_symbol_set_alt_label(GBinSymbol *, const char *); -/* Raffine la définition de l'emplacement d'un symbole. */ -void g_binary_symbol_fix_range(GBinSymbol *, const vmpa2t *); -  /* Fournit l'emplacement où se situe un symbole. */  const mrange_t *g_binary_symbol_get_range(const GBinSymbol *); @@ -122,56 +113,13 @@ GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *);  /* Fournit l'éventuelle instruction associée au symbole. */  GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *); -/* Ajoute un commentaire facultatif au symbole. */ -void g_binary_symbol_set_comment(GBinSymbol *, GDbComment *); - -/* Fournit l'éventuel commentaire associé au symbole. */ -GDbComment *g_binary_symbol_get_comment(const GBinSymbol *); -  /**   * Confort pour l'ajout de symboles basés sur des formats.   */ -#define SET_IMM_DISPLAY(_ins, _op, _idx, _dsp)                                      \ -    do                                                                              \ -    {                                                                               \ -        GImmOperand *_imm;                                                          \ -        _imm = G_IMM_OPERAND(g_arch_instruction_get_operand(_ins, _idx));           \ -        g_imm_operand_set_default_display(&_imm, _dsp, G_SHARE_CONTAINER(_ins));    \ -        _op = G_ARCH_OPERAND(_imm);                                                 \ -    }                                                                               \ -    while (0) - -#define ADD_RAW_AS_SYM(_fmt, _sym, _ins, _cmt, _txt)                        \ -    ({                                                                      \ -        bool __result;                                                      \ -        const vmpa2t *__addr;                                               \ -        __addr = get_mrange_addr(g_arch_instruction_get_range(_ins));       \ -        _cmt = g_db_comment_new_inlined(__addr, BLF_HAS_CODE, false);       \ -        g_db_comment_add_static_text(_cmt, strdup(_txt)); /* ! */           \ -        g_db_item_set_volatile(G_DB_ITEM(_cmt), true);                      \ -        _sym = g_binary_symbol_new(STP_DATA);                               \ -        g_binary_symbol_attach_instruction(_sym, _ins);                     \ -        g_binary_symbol_set_comment(_sym, _cmt);                            \ -        __result = g_binary_format_add_symbol(G_BIN_FORMAT(_fmt), _sym);    \ -        __result;                                                           \ -    }) -#define ADD_RAW_AS_SYM_CST(_fmt, _sym, _ins, _cmt, _txt)                    \ -    ({                                                                      \ -        bool __result;                                                      \ -        const vmpa2t *__addr;                                               \ -        __addr = get_mrange_addr(g_arch_instruction_get_range(_ins));       \ -        _cmt = g_db_comment_new_inlined(__addr, BLF_HAS_CODE, false);       \ -        g_db_comment_add_static_text(_cmt, _txt);                           \ -        g_db_item_set_volatile(G_DB_ITEM(_cmt), true);                      \ -        _sym = g_binary_symbol_new(STP_DATA);                               \ -        g_binary_symbol_attach_instruction(_sym, _ins);                     \ -        g_binary_symbol_set_comment(_sym, _cmt);                            \ -        __result = g_binary_format_add_symbol(G_BIN_FORMAT(_fmt), _sym);    \ -        __result;                                                           \ -    }) +  #define ADD_STR_AS_SYM(_fmt, _sym, _ins)                                    \      ({                                                                      \  | 
