diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2016-12-30 10:38:52 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2016-12-30 10:38:52 (GMT) | 
| commit | 932ea7c83c07d3982fee605c6dd9895fd2753874 (patch) | |
| tree | 766ad53bab9e3e3005334c30e823493de8e84168 /src/format | |
| parent | 1b5d39bfbc48c33a0ea0924b60e48448c8b45dd4 (diff) | |
Rewritten the line buffers using generators and on-demand building to save memory.
Diffstat (limited to 'src/format')
| -rwxr-xr-x | src/format/dex/dex.c | 4 | ||||
| -rw-r--r-- | src/format/dex/pool.h | 1 | ||||
| -rw-r--r-- | src/format/dwarf/v2/dwarf.h | 3 | ||||
| -rw-r--r-- | src/format/dwarf/v3/dwarf.h | 3 | ||||
| -rw-r--r-- | src/format/dwarf/v4/dwarf.h | 3 | ||||
| -rw-r--r-- | src/format/elf/symbols.h | 1 | ||||
| -rw-r--r-- | src/format/format-int.h | 5 | ||||
| -rwxr-xr-x | src/format/java/java.h | 2 | ||||
| -rw-r--r-- | src/format/pe/pe.h | 2 | ||||
| -rw-r--r-- | src/format/symbol.c | 221 | ||||
| -rw-r--r-- | src/format/symbol.h | 12 | 
11 files changed, 245 insertions, 12 deletions
| diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c index df920b2..d93346a 100755 --- a/src/format/dex/dex.c +++ b/src/format/dex/dex.c @@ -79,7 +79,7 @@ static bool g_dex_format_get_section_range_by_name(const GDexFormat *, const cha  //static void g_dex_format_find_all_sources(GDexFormat *);  /* Procède à la décompilation complète du format. */ -static void g_dex_format_decompile(const GDexFormat *, GCodeBuffer *, const char *); +static void g_dex_format_decompile(const GDexFormat *, void/*GCodeBuffer*/ *, const char *); @@ -470,7 +470,7 @@ static void g_dex_format_find_all_sources(GDexFormat *format)  *                                                                             *  ******************************************************************************/ -static void g_dex_format_decompile(const GDexFormat *format, GCodeBuffer *buffer, const char *filename) +static void g_dex_format_decompile(const GDexFormat *format, void/*GCodeBuffer*/ *buffer, const char *filename)  {  #if 0 diff --git a/src/format/dex/pool.h b/src/format/dex/pool.h index 38065fa..b819156 100644 --- a/src/format/dex/pool.h +++ b/src/format/dex/pool.h @@ -29,6 +29,7 @@  #include "dex.h"  #include "method.h"  #include "../../analysis/routine.h" +#include "../../glibext/delayed.h" diff --git a/src/format/dwarf/v2/dwarf.h b/src/format/dwarf/v2/dwarf.h index 54c6b37..867ae39 100644 --- a/src/format/dwarf/v2/dwarf.h +++ b/src/format/dwarf/v2/dwarf.h @@ -28,8 +28,7 @@  #include <glib-object.h> -#include "../../executable.h" -#include "../../format.h" +#include "../../../core/formats.h" diff --git a/src/format/dwarf/v3/dwarf.h b/src/format/dwarf/v3/dwarf.h index e95ed16..bac5ccc 100644 --- a/src/format/dwarf/v3/dwarf.h +++ b/src/format/dwarf/v3/dwarf.h @@ -28,8 +28,7 @@  #include <glib-object.h> -#include "../../executable.h" -#include "../../format.h" +#include "../../../core/formats.h" diff --git a/src/format/dwarf/v4/dwarf.h b/src/format/dwarf/v4/dwarf.h index 29059b5..6eda64e 100644 --- a/src/format/dwarf/v4/dwarf.h +++ b/src/format/dwarf/v4/dwarf.h @@ -28,8 +28,7 @@  #include <glib-object.h> -#include "../../executable.h" -#include "../../format.h" +#include "../../../core/formats.h" diff --git a/src/format/elf/symbols.h b/src/format/elf/symbols.h index d1b0fae..90e2f61 100644 --- a/src/format/elf/symbols.h +++ b/src/format/elf/symbols.h @@ -28,6 +28,7 @@  #include "elf.h" +#include "../../glibext/delayed.h"  #include "../../gtkext/gtkstatusstack.h" diff --git a/src/format/format-int.h b/src/format/format-int.h index e11e378..ea6b770 100644 --- a/src/format/format-int.h +++ b/src/format/format-int.h @@ -28,6 +28,9 @@  #include "format.h" +#include "../gtkext/gtkstatusstack.h" + +  /* ------------------------ TRAITEMENT INDIVIDUEL DE FORMATS ------------------------ */ @@ -36,7 +39,7 @@  typedef SourceEndian (* format_get_endian_fc) (const GBinFormat *);  /* Procède à la décompilation complète du format. */ -typedef void (* format_decompile_fc) (const GBinFormat *, GCodeBuffer *, const char *); +typedef void (* format_decompile_fc) (const GBinFormat *, void/*GCodeBuffer*/ *, const char *);  /* Rythme des allocations pour les entrées de code */ diff --git a/src/format/java/java.h b/src/format/java/java.h index 074c797..a33870f 100755 --- a/src/format/java/java.h +++ b/src/format/java/java.h @@ -30,7 +30,7 @@  #include <sys/types.h> -#include "../format.h" +#include "../../core/formats.h" diff --git a/src/format/pe/pe.h b/src/format/pe/pe.h index 3ac5f49..d6c8dde 100644 --- a/src/format/pe/pe.h +++ b/src/format/pe/pe.h @@ -30,7 +30,7 @@  #include <sys/types.h> -#include "../format.h" +#include "../../core/formats.h" diff --git a/src/format/symbol.c b/src/format/symbol.c index 97ff114..82321c2 100644 --- a/src/format/symbol.c +++ b/src/format/symbol.c @@ -28,6 +28,12 @@  #include <string.h> +#include "../glibext/linegen-int.h" + + + +/* --------------------- FONCTIONNALITES BASIQUES POUR SYMBOLES --------------------- */ +  /* Symbole d'exécutable (instance) */  struct _GBinSymbol @@ -64,6 +70,9 @@ static void g_binary_symbol_class_init(GBinSymbolClass *);  /* Initialise une instance de symbole d'exécutable. */  static void g_binary_symbol_init(GBinSymbol *); +/* Procède à l'initialisation de l'interface de génération. */ +static void g_binary_symbol_interface_init(GLineGeneratorInterface *); +  /* Supprime toutes les références externes. */  static void g_binary_symbol_dispose(GBinSymbol *); @@ -72,8 +81,34 @@ static void g_binary_symbol_finalize(GBinSymbol *); +/* ------------------------ OFFRE DE CAPACITES DE GENERATION ------------------------ */ + + +/* Indique le nombre de ligne prêtes à être générées. */ +static size_t g_binary_symbol_count_lines(const GBinSymbol *); + +/* Retrouve l'emplacement correspondant à une position donnée. */ +static void g_binary_symbol_compute_addr(const GBinSymbol *, gint, vmpa2t *, size_t, size_t); + +/* Détermine si le conteneur s'inscrit dans une plage donnée. */ +static int g_binary_symbol_contains_addr(const GBinSymbol *, const vmpa2t *, size_t, size_t); + +/* Renseigne sur les propriétés liées à un générateur. */ +static BufferLineFlags g_binary_symbol_get_flags(const GBinSymbol *, size_t, size_t); + +/* Imprime dans une ligne de rendu le contenu représenté. */ +static void g_binary_symbol_print(GBinSymbol *, GBufferLine *, size_t, size_t); + + + +/* ---------------------------------------------------------------------------------- */ +/*                       FONCTIONNALITES BASIQUES POUR SYMBOLES                       */ +/* ---------------------------------------------------------------------------------- */ + +  /* Indique le type défini pour un symbole d'exécutable. */ -G_DEFINE_TYPE(GBinSymbol, g_binary_symbol, G_TYPE_OBJECT); +G_DEFINE_TYPE_WITH_CODE(GBinSymbol, g_binary_symbol, G_TYPE_OBJECT, +                        G_IMPLEMENT_INTERFACE(G_TYPE_LINE_GENERATOR, g_binary_symbol_interface_init));  /****************************************************************************** @@ -120,6 +155,29 @@ static void g_binary_symbol_init(GBinSymbol *symbol)  /******************************************************************************  *                                                                             * +*  Paramètres  : iface = interface GLib à initialiser.                        * +*                                                                             * +*  Description : Procède à l'initialisation de l'interface de génération.     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_binary_symbol_interface_init(GLineGeneratorInterface *iface) +{ +    iface->count = (linegen_count_lines_fc)g_binary_symbol_count_lines; +    iface->compute = (linegen_compute_fc)g_binary_symbol_compute_addr; +    iface->contains = (linegen_contains_fc)g_binary_symbol_contains_addr; +    iface->get_flags = (linegen_get_flags_fc)g_binary_symbol_get_flags; +    iface->print = (linegen_print_fc)g_binary_symbol_print; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : symbol = instance d'objet GLib à traiter.                    *  *                                                                             *  *  Description : Supprime toutes les références externes.                     * @@ -665,3 +723,164 @@ GDbComment *g_binary_symbol_get_comment(const GBinSymbol *symbol)      return symbol->comment;  } + + + +/* ---------------------------------------------------------------------------------- */ +/*                          OFFRE DE CAPACITES DE GENERATION                          */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : symbol = générateur à consulter pour futur usage.            * +*                                                                             * +*  Description : Détermine si un symbole pour faire office de générateur.     * +*                                                                             * +*  Retour      : Instance de générateur si les capacités sont là.             * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GLineGenerator *g_binary_symbol_produce_label(GBinSymbol *symbol) +{ +    GLineGenerator *result;                 /* Instance à retourner        */ +    const char *label;                      /* Etiquette à insérer         */ + +    label = g_binary_symbol_get_label(symbol); + +    result = (label != NULL ? G_LINE_GENERATOR(symbol) : NULL); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : symbol = générateur à consulter.                             * +*                                                                             * +*  Description : Indique le nombre de ligne prêtes à être générées.           * +*                                                                             * +*  Retour      : Nombre de lignes devant apparaître au final.                 * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static size_t g_binary_symbol_count_lines(const GBinSymbol *symbol) +{ +    return 1; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : symbol = générateur à consulter.                             * +*                x      = position géographique sur la ligne concernée.       * +*                addr   = position en mémoire à analyser.                     * +*                index  = indice de cette même ligne dans le tampon global.   * +*                repeat = indice d'utilisations successives du générateur.    * +*                                                                             * +*  Description : Retrouve l'emplacement correspondant à une position donnée.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_binary_symbol_compute_addr(const GBinSymbol *symbol, gint x, vmpa2t *addr, size_t index, size_t repeat) +{ +    const mrange_t *range;                  /* Emplacement à manipuler     */ + +    range = g_binary_symbol_get_range(symbol); + +    copy_vmpa(addr, get_mrange_addr(range)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : symbol = générateur à consulter.                             * +*                addr   = position en mémoire à analyser.                     * +*                index  = indice de cette même ligne dans le tampon global.   * +*                repeat = indice d'utilisations successives du générateur.    * +*                                                                             * +*  Description : Détermine si le conteneur s'inscrit dans une plage donnée.   * +*                                                                             * +*  Retour      : Bilan de la détermination, utilisable en comparaisons.       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static int g_binary_symbol_contains_addr(const GBinSymbol *symbol, const vmpa2t *addr, size_t index, size_t repeat) +{ +    int result;                             /* Conclusion à retourner      */ +    const mrange_t *range;                  /* Emplacement à manipuler     */ + +    range = g_binary_symbol_get_range(symbol); + +    result = cmp_mrange_with_vmpa(range, addr); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : symbol = générateur à consulter.                             * +*                index  = indice de cette même ligne dans le tampon global.   * +*                repeat = indice d'utilisations successives du générateur.    * +*                                                                             * +*  Description : Renseigne sur les propriétés liées à un générateur.          * +*                                                                             * +*  Retour      : Propriétés particulières associées.                          * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static BufferLineFlags g_binary_symbol_get_flags(const GBinSymbol *symbol, size_t index, size_t repeat) +{ +    return BLF_IS_LABEL; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : symbol = générateur à utiliser pour l'impression.            * +*                line   = ligne de rendu à compléter.                         * +*                index  = indice de cette même ligne dans le tampon global.   * +*                repeat = indice d'utilisations successives du générateur.    * +*                                                                             * +*  Description : Imprime dans une ligne de rendu le contenu représenté.       * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_binary_symbol_print(GBinSymbol *symbol, GBufferLine *line, size_t index, size_t repeat) +{ +    const mrange_t *range;                  /* Emplacement à manipuler     */ +    const char *label;                      /* Etiquette à insérer         */ + +    range = g_binary_symbol_get_range(symbol); + +    g_buffer_line_fill_vmpa(line, get_mrange_addr(range), MDS_32_BITS_UNSIGNED, MDS_32_BITS_UNSIGNED); + +    label = g_binary_symbol_get_label(symbol); + +    g_buffer_line_start_merge_at(line, BLC_ASSEMBLY_HEAD); +    g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, SL(label), RTT_LABEL, NULL); +    g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, ":", 1, RTT_PUNCT, NULL); + +} diff --git a/src/format/symbol.h b/src/format/symbol.h index 78741cb..e73bb27 100644 --- a/src/format/symbol.h +++ b/src/format/symbol.h @@ -32,9 +32,13 @@  #include "../analysis/db/item.h"  #include "../analysis/db/items/comment.h"  #include "../arch/instruction.h" +#include "../glibext/linegen.h" +/* --------------------- FONCTIONNALITES BASIQUES POUR SYMBOLES --------------------- */ + +  /* Types de symbole */  typedef enum _SymbolType  { @@ -164,4 +168,12 @@ GDbComment *g_binary_symbol_get_comment(const GBinSymbol *); +/* ------------------------ OFFRE DE CAPACITES DE GENERATION ------------------------ */ + + +/* Détermine si un symbole pour faire office de générateur. */ +GLineGenerator *g_binary_symbol_produce_label(GBinSymbol *); + + +  #endif  /* _FORMAT_SYMBOL_H */ | 
