diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/analysis/binary-int.h | 4 | ||||
| -rw-r--r-- | src/analysis/binary.c | 315 | ||||
| -rw-r--r-- | src/analysis/binary.h | 7 | ||||
| -rw-r--r-- | src/analysis/disass/disassembler.c | 16 | ||||
| -rw-r--r-- | src/analysis/disass/disassembler.h | 3 | ||||
| -rw-r--r-- | src/analysis/disass/macro.c | 1 | ||||
| -rw-r--r-- | src/arch/processor-int.h | 1 | ||||
| -rw-r--r-- | src/dialogs/Makefile.am | 1 | ||||
| -rw-r--r-- | src/dialogs/binparts.c | 779 | ||||
| -rw-r--r-- | src/dialogs/binparts.h | 40 | ||||
| -rw-r--r-- | src/format/Makefile.am | 1 | ||||
| -rw-r--r-- | src/format/dex/class.c | 4 | ||||
| -rw-r--r-- | src/format/dex/class.h | 2 | ||||
| -rwxr-xr-x | src/format/dex/dex.c | 7 | ||||
| -rw-r--r-- | src/format/dex/method.c | 4 | ||||
| -rw-r--r-- | src/format/dex/method.h | 4 | ||||
| -rw-r--r-- | src/format/elf/elf.c | 102 | ||||
| -rw-r--r-- | src/format/exe_format-int.h | 100 | ||||
| -rw-r--r-- | src/format/exe_format.c | 485 | ||||
| -rw-r--r-- | src/format/exe_format.h | 152 | ||||
| -rw-r--r-- | src/format/executable-int.h | 4 | ||||
| -rw-r--r-- | src/format/executable.c | 27 | ||||
| -rw-r--r-- | src/format/executable.h | 4 | ||||
| -rwxr-xr-x | src/format/java/java.c | 50 | ||||
| -rw-r--r-- | src/format/part.c | 416 | ||||
| -rw-r--r-- | src/format/part.h | 97 | ||||
| -rw-r--r-- | src/format/pe/pe.c | 7 | 
27 files changed, 23 insertions, 2610 deletions
diff --git a/src/analysis/binary-int.h b/src/analysis/binary-int.h index fa06a25..ec98bf9 100644 --- a/src/analysis/binary-int.h +++ b/src/analysis/binary-int.h @@ -67,10 +67,6 @@ struct _GLoadedBinary      GExeFormat *format;                     /* Format du binaire           */      GArchProcessor *proc;                   /* Architecture du binaire     */ -    BinaryPartModel model;                  /* Modèle de sélection         */ -    GBinPart **parts[BPM_COUNT];            /* Parties binaires à analyser */ -    size_t parts_count[BPM_COUNT];          /* Quantité de ces parties     */ -      GArchInstruction *instrs;               /* Instructions d'assemblage   */      GCodeBuffer *disass_buffer;             /* Instructions lisibles       */      GCodeBuffer **dec_buffers;              /* Sources sous forme de texte */ diff --git a/src/analysis/binary.c b/src/analysis/binary.c index 0c7a71c..35f7acd 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -62,12 +62,6 @@ static void g_loaded_binary_dispose(GLoadedBinary *);  /* Procède à la libération totale de la mémoire. */  static void g_loaded_binary_finalize(GLoadedBinary *); -/* Charge les parties intéressantes du binaire à partir d'XML. */ -static bool g_loaded_binary_load_parts_from_xml(GLoadedBinary *, xmlXPathContextPtr, const char *); - -/* Ecrit les parties de valeur du binaire dans un fichier XML. */ -static bool g_loaded_binary_save_parts(const GLoadedBinary *, xmlDocPtr, xmlXPathContextPtr, const char *); -  /* Acquitte la fin d'un désasemblage différé et complet. */  static void ack_completed_disassembly(GDelayedDisassembly *, GLoadedBinary *); @@ -281,11 +275,6 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch -    /* -    if (!g_loaded_binary_load_parts_from_xml(result, context, path)) -        goto glbnfx_error; -    */ -      printf("data :: %p  length :: %d\n", result->bin_data, result->bin_length); @@ -405,229 +394,6 @@ bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathC      result = g_loaded_binary_save_storage(binary, xdoc, context, path); -    /* Parties à désassembler */ - -    result = g_loaded_binary_save_parts(binary, xdoc, context, path); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : context = contexte pour les recherches XPath.                * -*                path    = chemin d'accès au noeud XML à lire.                * -*                                                                             * -*  Description : Charge les parties intéressantes du binaire à partir d'XML.  * -*                                                                             * -*  Retour      : Bilan de l'opération.                                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static bool g_loaded_binary_load_parts_from_xml(GLoadedBinary *binary, xmlXPathContextPtr context, const char *path) -{ -    bool result;                            /* Bilan à retourner           */ -    char *access;                           /* Chemin pour une sous-config.*/ -    xmlXPathObjectPtr xobjects;             /* Cible d'une recherche       */ -    int i;                                  /* Boucle de parcours          */ -    GBinPart *part;                         /* Partie binaire à traiter    */ -    off_t offset;                           /* Position de cette partie    */ -    vmpa_t addr;                            /* Adresse correspondante      */ - -    result = NULL; - -    /* Parties à désassembler : default */ - -    access = strdup(path); -    access = stradd(access, "/BinParts/Default/Part"); - -    xobjects = get_node_xpath_object(context, access); - -    for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobjects); i++) -    { -        part = g_binary_part_load_from_xml(NODE_FROM_PATH_OBJ(xobjects, i)); - -        if (part != NULL) -        { -            g_binary_part_get_values(part, &offset, NULL, NULL); - -            if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr)) -            { -                g_object_unref(G_OBJECT(part)); -                continue; -            } - -            binary->parts_count[BPM_DEFAULT]++; -            binary->parts[BPM_DEFAULT] = (GBinPart **)realloc(binary->parts[BPM_DEFAULT], -                                                              binary->parts_count[BPM_DEFAULT] * sizeof(GBinPart *)); - -            binary->parts[BPM_DEFAULT][binary->parts_count[BPM_DEFAULT] - 1] = part; - -        } - -    } - -    if(xobjects != NULL) -        xmlXPathFreeObject(xobjects); - -    free(access); - -    qsort(binary->parts[BPM_DEFAULT], binary->parts_count[BPM_DEFAULT], -          sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare); - -    /* Parties à désassembler : routines */ - -    access = strdup(path); -    access = stradd(access, "/BinParts/Routines/Part"); - -    xobjects = get_node_xpath_object(context, access); - -    for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobjects); i++) -    { -        part = g_binary_part_load_from_xml(NODE_FROM_PATH_OBJ(xobjects, i)); - -        if (part != NULL) -        { -            g_binary_part_get_values(part, &offset, NULL, NULL); - -            if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr)) -            { -                g_object_unref(G_OBJECT(part)); -                continue; -            } -            else g_binary_part_set_address(part, addr); - -            binary->parts_count[BPM_ROUTINES]++; -            binary->parts[BPM_ROUTINES] = (GBinPart **)realloc(binary->parts[BPM_ROUTINES], -                                                               binary->parts_count[BPM_ROUTINES] * sizeof(GBinPart *)); - -            binary->parts[BPM_ROUTINES][binary->parts_count[BPM_ROUTINES] - 1] = part; - -        } - -    } - -    if(xobjects != NULL) -        xmlXPathFreeObject(xobjects); - -    free(access); - -    qsort(binary->parts[BPM_ROUTINES], binary->parts_count[BPM_ROUTINES], -          sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare); - -    /* Parties à désassembler : utilisateur */ - -    access = strdup(path); -    access = stradd(access, "/BinParts/User/Part"); - -    xobjects = get_node_xpath_object(context, access); - -    for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobjects); i++) -    { -        part = g_binary_part_load_from_xml(NODE_FROM_PATH_OBJ(xobjects, i)); - -        if (part != NULL) -        { -            g_binary_part_get_values(part, &offset, NULL, NULL); - -            if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(binary->format), offset, &addr)) -            { -                g_object_unref(G_OBJECT(part)); -                continue; -            } - -            binary->parts_count[BPM_USER]++; -            binary->parts[BPM_USER] = (GBinPart **)realloc(binary->parts[BPM_USER], -                                                           binary->parts_count[BPM_USER] * sizeof(GBinPart *)); - -            binary->parts[BPM_USER][binary->parts_count[BPM_USER] - 1] = part; - -        } - -    } - -    if(xobjects != NULL) -        xmlXPathFreeObject(xobjects); - -    free(access); - -    qsort(binary->parts[BPM_USER], binary->parts_count[BPM_USER], -          sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary  = élément binaire à traiter.                         * -*                xdoc    = structure XML en cours d'édition.                  * -*                context = contexte à utiliser pour les recherches.           * -*                path    = chemin d'accès réservé au binaire.                 * -*                                                                             * -*  Description : Ecrit les parties de valeur du binaire dans un fichier XML.  * -*                                                                             * -*  Retour      : true si l'opération a bien tourné, false sinon.              * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static bool g_loaded_binary_save_parts(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path) -{ -    bool result;                            /* Bilan à faire remonter      */ -    char *access;                           /* Chemin d'accès à un élément */ -    xmlNodePtr node;                        /* Point d'insertion XML       */ -    size_t i;                               /* Boucle de parcours          */ - -    result = true; - -    if (binary->parts_count[BPM_DEFAULT] > 0) -    { -        access = strdup(path); -        access = stradd(access, "/BinParts/Default"); - -        node = ensure_node_exist(xdoc, context, access); - -        free(access); - -        for (i = 0; i < binary->parts_count[BPM_DEFAULT] && result; i++) -            result &= g_binary_part_save_to_xml(binary->parts[BPM_DEFAULT][i], xdoc, node); - -    } - -    if (binary->parts_count[BPM_ROUTINES] > 0) -    { -        access = strdup(path); -        access = stradd(access, "/BinParts/Routines"); - -        node = ensure_node_exist(xdoc, context, access); - -        free(access); - -        for (i = 0; i < binary->parts_count[BPM_ROUTINES] && result; i++) -            result &= g_binary_part_save_to_xml(binary->parts[BPM_ROUTINES][i], xdoc, node); - -    } - -    if (binary->parts_count[BPM_USER] > 0) -    { -        access = strdup(path); -        access = stradd(access, "/BinParts/User"); - -        node = ensure_node_exist(xdoc, context, access); - -        free(access); - -        for (i = 0; i < binary->parts_count[BPM_USER] && result; i++) -            result &= g_binary_part_save_to_xml(binary->parts[BPM_USER][i], xdoc, node); - -    } -      return result;  } @@ -1085,56 +851,6 @@ bool g_loaded_binary_add_to_collection(GLoadedBinary *binary, DBFeatures feature - -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary = élément binaire à consulter.                        * -*                parts  = liste des zones binaires à analyser.                * -*                model  = modèle de sélection des zones.                      * -*                count  = quantité de zones listées.                          * -*                                                                             * -*  Description : Définit les parties de binaire à analyser.                   * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_loaded_binary_set_parts(GLoadedBinary *binary, BinaryPartModel model, GBinPart **parts, size_t count) -{ -    qsort(parts, count, sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare); - -    binary->parts[model] = parts; -    binary->parts_count[model] = count; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary = élément binaire à consulter.                        * -*                model  = modèle de sélection des zones. [OUT]                * -*                count  = quantité de zones listées. [OUT]                    * -*                                                                             * -*  Description : Fournit les parties de binaire analysées.                    * -*                                                                             * -*  Retour      : Zones binaires à analyser.                                   * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GBinPart ***g_loaded_binary_get_parts(const GLoadedBinary *binary, BinaryPartModel *model, size_t **count) -{ -    *model = binary->model; -    *count = binary->parts_count; - -    return binary->parts; - -} - -  /******************************************************************************  *                                                                             *  *  Paramètres  : binary = élément binaire à traiter.                          * @@ -1149,9 +865,6 @@ GBinPart ***g_loaded_binary_get_parts(const GLoadedBinary *binary, BinaryPartMod  void g_loaded_binary_analyse(GLoadedBinary *binary)  { -    GBinPart **parts;                       /* Parties d'élément binaire   */ -    size_t parts_count;                     /* Nombre de ces parties       */ -      /* Détermination de l'identifiant */      /* déplacé @@ -1165,33 +878,7 @@ void g_loaded_binary_analyse(GLoadedBinary *binary) - -    if (binary->parts_count[BPM_ROUTINES] > 0) -        binary->model = BPM_ROUTINES; - - -    if (binary->parts[binary->model] != NULL) -    { -        parts = binary->parts[binary->model]; -        parts_count = binary->parts_count[binary->model]; -    } -    else -    { -        if (binary->parts[BPM_DEFAULT] != NULL) -        { -            parts = binary->parts[BPM_DEFAULT]; -            parts_count = binary->parts_count[BPM_DEFAULT]; -        } -        else -        { -            parts = g_exe_format_get_parts(binary->format, &parts_count); -            qsort(parts, parts_count, sizeof(GBinPart *), (__compar_fn_t)g_binary_part_compare); -        } -    } - -    disassemble_binary(binary, parts, parts_count, -                       &binary->instrs, &binary->disass_buffer, -                       ack_completed_disassembly); +    disassemble_binary(binary, &binary->instrs, &binary->disass_buffer, ack_completed_disassembly);      /* TODO : remme ! */      //ack_completed_disassembly(NULL, binary); diff --git a/src/analysis/binary.h b/src/analysis/binary.h index 8574f28..8ce64cb 100644 --- a/src/analysis/binary.h +++ b/src/analysis/binary.h @@ -141,13 +141,6 @@ bool g_loaded_binary_add_to_collection(GLoadedBinary *, DBFeatures, GDbItem *); -/* Définit les parties de binaire à analyser. */ - -void g_loaded_binary_set_parts(GLoadedBinary *, BinaryPartModel, GBinPart **, size_t); - -/* Fournit les parties de binaire analysées. */ -GBinPart ***g_loaded_binary_get_parts(const GLoadedBinary *, BinaryPartModel *, size_t **); -  /* Lance l'analyse d'un élément binaire chargé. */  void g_loaded_binary_analyse(GLoadedBinary *); diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c index 126c116..ac6eb5b 100644 --- a/src/analysis/disass/disassembler.c +++ b/src/analysis/disass/disassembler.c @@ -58,9 +58,6 @@ struct _GDelayedDisassembly      GLoadedBinary *binary;                  /* Destinataire final          */      GExeFormat *format;                     /* Format du binaire représenté*/ -    GBinPart **parts;                       /* Parties binaires à traiter  */ -    size_t count;                           /* Nombre de ces parties       */ -      GArchInstruction **instrs;              /* Instructions résultantes    */      GCodeBuffer *buffer;                    /* Tampon pour le rendu        */ @@ -81,7 +78,7 @@ static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *);  static void g_delayed_disassembly_init(GDelayedDisassembly *);  /* Crée une tâche de désassemblage différé. */ -static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *, GBinPart **, size_t, GArchInstruction **, GCodeBuffer *); +static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *, GArchInstruction **, GCodeBuffer *);  /* Assure le désassemblage en différé. */  static void g_delayed_disassembly_process(GDelayedDisassembly *, GtkExtStatusBar *); @@ -146,8 +143,6 @@ static void g_delayed_disassembly_init(GDelayedDisassembly *disass)  *                                                                             *  *  Paramètres  : binary = binaire chargé en attente des résultats.            *  *                format = format du binaire représenté.                       * -*                parts  = parties binaires à désassembler.                    * -*                count  = nombre de parties à traiter.                        *  *                instrs = emplacement pour la liste d'instructions.           *  *                buffer = tampon de sortie pour les instructions.             *  *                                                                             * @@ -159,7 +154,7 @@ static void g_delayed_disassembly_init(GDelayedDisassembly *disass)  *                                                                             *  ******************************************************************************/ -static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *binary, GBinPart **parts, size_t count, GArchInstruction **instrs, GCodeBuffer *buffer) +static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *binary, GArchInstruction **instrs, GCodeBuffer *buffer)  {      GDelayedDisassembly *result;            /* Tâche à retourner           */ @@ -168,9 +163,6 @@ static GDelayedDisassembly *g_delayed_disassembly_new(GLoadedBinary *binary, GBi      result->binary = binary;      result->format = g_loaded_binary_get_format(binary); -    result->parts = parts; -    result->count = count; -      result->instrs = instrs;      result->buffer = buffer; @@ -538,7 +530,7 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con  *                                                                             *  ******************************************************************************/ -void disassemble_binary(GLoadedBinary *binary, GBinPart **parts, size_t parts_count, GArchInstruction **instrs, GCodeBuffer **buffer, disassembly_ack_fc ack) +void disassemble_binary(GLoadedBinary *binary, GArchInstruction **instrs, GCodeBuffer **buffer, disassembly_ack_fc ack)  {      const uint8_t *data;                    /* Données binaires brutes     */      off_t length;                           /* Quantité de ces données     */ @@ -550,7 +542,7 @@ void disassemble_binary(GLoadedBinary *binary, GBinPart **parts, size_t parts_co      data = g_loaded_binary_get_data(binary, &length);      build_disass_prologue(*buffer, g_loaded_binary_get_name(binary, true), data, length); -    disass = g_delayed_disassembly_new(binary, parts, parts_count, instrs, *buffer); +    disass = g_delayed_disassembly_new(binary, instrs, *buffer);      g_signal_connect(disass, "work-completed", G_CALLBACK(ack), binary);      queue = get_work_queue(); diff --git a/src/analysis/disass/disassembler.h b/src/analysis/disass/disassembler.h index 46bd3cc..4e459a1 100644 --- a/src/analysis/disass/disassembler.h +++ b/src/analysis/disass/disassembler.h @@ -26,7 +26,6 @@  #include "../binary.h" -#include "../../format/part.h" @@ -60,7 +59,7 @@ GType g_delayed_disassembly_get_type(void);  typedef void (* disassembly_ack_fc) (GDelayedDisassembly *, GLoadedBinary *);  /* Procède à la décompilation des routines d'un fichier donné. */ -void disassemble_binary(GLoadedBinary *, GBinPart **parts, size_t parts_count, GArchInstruction **, GCodeBuffer **, disassembly_ack_fc); +void disassemble_binary(GLoadedBinary *, GArchInstruction **, GCodeBuffer **, disassembly_ack_fc); diff --git a/src/analysis/disass/macro.c b/src/analysis/disass/macro.c index 9addf1e..3745f25 100644 --- a/src/analysis/disass/macro.c +++ b/src/analysis/disass/macro.c @@ -25,6 +25,7 @@  #include <malloc.h> +#include <stdlib.h>  #include <string.h> diff --git a/src/arch/processor-int.h b/src/arch/processor-int.h index 23a6d60..2b91b36 100644 --- a/src/arch/processor-int.h +++ b/src/arch/processor-int.h @@ -38,7 +38,6 @@  #include "operand.h"        /* TODO: AsmSyntax ? */  #include "instruction.h"  #include "processor.h" -#include "../format/exe_format.h" diff --git a/src/dialogs/Makefile.am b/src/dialogs/Makefile.am index 7be1fd6..9adb0f6 100644 --- a/src/dialogs/Makefile.am +++ b/src/dialogs/Makefile.am @@ -3,7 +3,6 @@ noinst_LTLIBRARIES  = libdialogs.la  libdialogs_la_SOURCES =					\  	about.h about.c						\ -	binparts.h binparts.c				\  	export.h export.c					\  	goto.h goto.c						\  	plugins.h plugins.c					\ diff --git a/src/dialogs/binparts.c b/src/dialogs/binparts.c deleted file mode 100644 index 2d86432..0000000 --- a/src/dialogs/binparts.c +++ /dev/null @@ -1,779 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * binparts.h - boîte de dialogue permettant une sélection des sections - * - * Copyright (C) 2009-2014 Cyrille Bagard - * - *  This file is part of Chrysalide. - * - *  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/>. - */ - - -#include "binparts.h" - - -#include <i18n.h> - - -#include <stdio.h> - - -#include "../format/format.h" -#include "../gtkext/easygtk.h" - - - - -/* Colonnes de la liste des symboles */ -typedef enum _PartsColumn -{ -    PTC_ACTIVE,                             /* Zone de code active ?       */ -    PTC_NAME,                               /* Désignation humaine         */ -    PTC_START,                              /* Adresse de départ           */ -    PTC_END,                                /* Adresse d'arrivée (exclue)  */ - -    PTC_COUNT                               /* Nombre de colonnes          */ - -} PartsColumn; - - -/* Mémoire d'un modèle */ -typedef struct _parts_model -{ -    gboolean *selected;                     /* Sélection ou non de parties */ -    size_t count;                           /* Qté. de prises en compte    */ - -} parts_model; - - -/* Sélectionne ou non tous les éléments de la liste courante. */ -static void select_all_items_or_none(GtkButton *, GObject *); - -/* Sauvegarde l'état courant des sélections et clôt la fenêtre. */ -static void save_current_selection(GtkButton *, GObject *); - -/* Ferme la fenêtre de dialogue. */ -static void close_editor(GtkButton *, GtkWidget *); - -/* Charge les parties courantes d'un binaire donné. */ -static void load_binary_current_parts(GLoadedBinary *binary, GObject *ref); - -/* Affiche les parties désassemblées par défaut. */ -static void load_default_parts(GObject *); - -/* Affiche les parties désassemblées selon les routines. */ -static void load_routines_parts(GObject *); - - - -/* Réagit à un changement de modèle. */ -static void on_model_change(GtkComboBox *, GObject *); - -/* Réagit à un changement de sélection de partie. */ -static void on_part_selection_toggle(GtkCellRendererToggle *, gchar *, GObject *); - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary = informations sur le binaire actuellement ouvert.    * -*                parent = fenêtre parente à surpasser.                        * -*                                                                             * -*  Description : Construit la fenêtre de sélection des sections.              * -*                                                                             * -*  Retour      : Adresse de la fenêtre mise en place.                         * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GtkWidget *create_sections_dialog(GLoadedBinary *binary, GtkWindow *parent) -{ -    GtkWidget *result;                      /* Fenêtre à renvoyer          */ -    GObject *ref;                           /* Espace de référencements    */ - - - - - -  GtkWidget *vbox1; - - - -  GtkWidget *vbox2; -  GtkWidget *hbox2; -    GtkWidget *label;                       /* Etiquette à afficher        */ - -  GtkWidget *comboboxentry; -  GtkWidget *hbox3; -  GtkWidget *scrolledwindow1; - -    GtkTreeStore *store;                    /* Modèle de gestion           */ -    GtkWidget *treeview;                    /* Affichage de la liste       */ -    GtkCellRenderer *renderer;              /* Moteur de rendu de colonne  */ -    GtkTreeViewColumn *column;              /* Colonne de la liste         */ - - -  GtkWidget *vbuttonbox1; -  GtkWidget *hbuttonbox1; - -    GtkWidget *button;                      /* Bouton de commande          */ -    GtkWidget *sep;                         /* Barre de séparation         */ - -    result = gtk_window_new(GTK_WINDOW_TOPLEVEL); -    gtk_widget_set_size_request(result, 600, 400); -    gtk_container_set_border_width(GTK_CONTAINER(result), 8); -    gtk_window_set_title(GTK_WINDOW(result), _("Content to display")); -    gtk_window_set_transient_for(GTK_WINDOW(result), parent); -    gtk_window_set_default_size(GTK_WINDOW(result), 600, 400); -    gtk_window_set_type_hint(GTK_WINDOW(result), GDK_WINDOW_TYPE_HINT_DIALOG); - -    ref= G_OBJECT(result); -    g_object_set_data(ref, "binary", binary); - -  vbox1 = gtk_vbox_new(FALSE, 8); -  gtk_widget_show(vbox1); -  gtk_container_add(GTK_CONTAINER(result), vbox1); - -  vbox2 = gtk_vbox_new(FALSE, 8); -  gtk_widget_show(vbox2); -  gtk_container_add(GTK_CONTAINER(vbox1), vbox2); - - - -  hbox2 = gtk_hbox_new(FALSE, 8); -  gtk_widget_show(hbox2); -  gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0); - -    label = qck_create_label(NULL, NULL, _("Model :")); -    gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0); - -    comboboxentry = qck_create_combobox(ref, "models", G_CALLBACK(NULL), NULL); -    gtk_box_pack_start(GTK_BOX(hbox2), comboboxentry, TRUE, TRUE, 0); - - -    button = qck_create_button_with_img(NULL, NULL, "gtk-add", G_CALLBACK(NULL), NULL); -    gtk_widget_set_sensitive(button, FALSE); -    gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, 0); - -    button = qck_create_button_with_img(NULL, NULL, "gtk-remove", G_CALLBACK(NULL), NULL); -    gtk_widget_set_sensitive(button, FALSE); -    gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, 0); - - - - -  hbox3 = gtk_hbox_new(FALSE, 8); -  gtk_widget_show(hbox3); -  gtk_box_pack_start(GTK_BOX(vbox2), hbox3, TRUE, TRUE, 0); - -  scrolledwindow1 = gtk_scrolled_window_new(NULL, NULL); -  gtk_widget_show(scrolledwindow1); -  gtk_box_pack_start(GTK_BOX(hbox3), scrolledwindow1, TRUE, TRUE, 0); -  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); -  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow1), GTK_SHADOW_IN); - - - - - - -    store = gtk_tree_store_new(PTC_COUNT, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); -    g_object_set_data(ref, "store", store); - -    treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); -    gtk_widget_show(treeview); -    gtk_container_add(GTK_CONTAINER(scrolledwindow1), treeview); - -    g_object_unref(G_OBJECT(store)); -    /* -    column = gtk_tree_view_column_new(); -    gtk_tree_view_column_set_visible(column, FALSE); -    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); -    gtk_tree_view_set_expander_column(GTK_TREE_VIEW(treeview), column); -    */ - -    renderer = gtk_cell_renderer_toggle_new(); -    gtk_cell_renderer_toggle_set_activatable(GTK_CELL_RENDERER_TOGGLE(renderer), TRUE); -    column = gtk_tree_view_column_new_with_attributes(_("Active"), renderer, "active", PTC_ACTIVE, NULL); -    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); -    g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(on_part_selection_toggle), ref); - -    renderer = gtk_cell_renderer_text_new(); -    column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, "text", PTC_NAME, NULL); -    gtk_tree_view_column_set_expand(column, TRUE); -    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - -    renderer = gtk_cell_renderer_text_new(); -    column = gtk_tree_view_column_new_with_attributes(_("Start"), renderer, "text", PTC_START, NULL); -    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - -    renderer = gtk_cell_renderer_text_new(); -    column = gtk_tree_view_column_new_with_attributes(_("End"), renderer, "text", PTC_END, NULL); -    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - - - - - - -    /* Boutons d'édition de la liste */ - -    vbuttonbox1 = gtk_vbutton_box_new(); -    gtk_widget_show(vbuttonbox1); -    gtk_box_pack_start(GTK_BOX(hbox3), vbuttonbox1, FALSE, FALSE, 0); -    gtk_button_box_set_layout(GTK_BUTTON_BOX(vbuttonbox1), GTK_BUTTONBOX_SPREAD); - - -    button = qck_create_button_with_img(NULL, NULL, "gtk-add", G_CALLBACK(select_all_items_or_none), ref); -    gtk_container_add(GTK_CONTAINER(vbuttonbox1), button); - -    g_object_set_data(G_OBJECT(button), "all", button); - -    button = qck_create_button_with_img(NULL, NULL, "gtk-remove", G_CALLBACK(select_all_items_or_none), ref); -    gtk_container_add(GTK_CONTAINER(vbuttonbox1), button); - -    sep = gtk_hseparator_new(); -    gtk_widget_show(sep); -    gtk_container_add(GTK_CONTAINER(vbuttonbox1), sep); - -    button = qck_create_button_with_img(NULL, NULL, "gtk-add", G_CALLBACK(NULL), NULL); -    gtk_widget_set_sensitive(button, FALSE); -    gtk_container_add(GTK_CONTAINER(vbuttonbox1), button); - -    button = qck_create_button_with_img(NULL, NULL, "gtk-remove", G_CALLBACK(NULL), NULL); -    gtk_widget_set_sensitive(button, FALSE); -    gtk_container_add(GTK_CONTAINER(vbuttonbox1), button); - - - - - -  hbuttonbox1 = gtk_hbutton_box_new(); -  gtk_widget_show(hbuttonbox1); -  gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox1, FALSE, FALSE, 0); -  gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1), GTK_BUTTONBOX_END); - - -    /* Boutons de contrôle principaux */ - -    button = qck_create_button(NULL, NULL, _("_Ok"), G_CALLBACK(save_current_selection), ref); -    gtk_container_add(GTK_CONTAINER(hbuttonbox1), button); - -    button = qck_create_button(NULL, NULL, _("_Cancel"), G_CALLBACK(close_editor), result); -    gtk_container_add(GTK_CONTAINER(hbuttonbox1), button); - -    /* Actualisation de l'interface */ - -    g_signal_connect(G_OBJECT(comboboxentry), "changed", G_CALLBACK(on_model_change), ref); - -    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboboxentry), _("Default")); -    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboboxentry), _("Routines")); -    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboboxentry), _("User")); - -    load_binary_current_parts(binary, ref); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : button = bouton d'édition de la sélection.                   * -*                ref    = espace de référencement principal.                  * -*                                                                             * -*  Description : Sélectionne ou non tous les éléments de la liste courante.   * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void select_all_items_or_none(GtkButton *button, GObject *ref) -{ -    gboolean state;                         /* Etat de sélection à donner  */ -    GtkTreeModel *model;                    /* Modèle de représentation    */ -    GtkTreeIter iter;                       /* Point de modification       */ - -    state = (g_object_get_data(G_OBJECT(button), "all") != NULL); - -    model = GTK_TREE_MODEL(g_object_get_data(ref, "store")); - -    if (gtk_tree_model_get_iter_first(model, &iter)) -        do -            gtk_tree_store_set(GTK_TREE_STORE(model), &iter, -                           PTC_ACTIVE, state, -                           -1); -        while (gtk_tree_model_iter_next(model, &iter)); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : button = bouton 'OK'.                                        * -*                ref    = espace de référencement principal.                  * -*                                                                             * -*  Description : Sauvegarde l'état courant des sélections et clôt la fenêtre. * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void save_current_selection(GtkButton *button, GObject *ref) -{ - - - - - - - -    GLoadedBinary *binary;                  /* Binaire à traiter           */ - -    GExeFormat *format;                     /* Format associé au binaire   */ -    GArchProcessor *proc;                   /* Architecture utilisée       */ - - -    GBinPart **parts;                       /* Parcelles à désassembler    */ -    size_t parts_count;                     /* Quantité de ces parcelles   */ -    GBinPart *part;                         /* Nouvelle partie à lister    */ - - -    GBinRoutine **routines;                 /* Liste des routines trouvées */ -    size_t routines_count;                  /* Nombre de ces routines      */ -    parts_model *model;                     /* Mémoire du modèle           */ -    size_t i;                               /* Boucle de parcours          */ -    off_t offset;                           /* Position dans le binaire    */ - - -    binary = G_LOADED_BINARY(g_object_get_data(ref, "binary")); - -    format = g_loaded_binary_get_format(binary); -    proc = get_arch_processor_from_format(format); - - - - -    /* Routines */ - -    parts = NULL; -    parts_count = 0; - -    routines = g_binary_format_get_routines(G_BIN_FORMAT(format), &routines_count); -    qsort(routines, routines_count, sizeof(GBinRoutine *), g_binary_routine_compare); - -    model = (parts_model *)g_object_get_data(ref, "routines_model"); - -    for (i = 0; i < routines_count; i++) -    { -        if (!model->selected[i]) continue; - -        part = g_binary_part_new(); - -        g_binary_part_set_name(part, g_binary_routine_get_name(routines[i])); - -        g_exe_format_translate_address_into_offset(format, -                                                   g_binary_routine_get_address(routines[i]), -                                                   &offset); - -        g_binary_part_set_values(part, offset, -                                 g_binary_routine_get_size(routines[i]), -                                 g_binary_routine_get_address(routines[i])); - -        parts = (GBinPart **)realloc(parts, ++parts_count * sizeof(GBinPart *)); -        parts[parts_count - 1] = part; - -    } - -    g_loaded_binary_set_parts(binary, BPM_ROUTINES, parts, parts_count); - - - - - - - - -    /* Fin */ - -    gtk_widget_destroy(GTK_WIDGET(ref)); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : button = bouton 'Annuler'.                                   * -*                widget = adresse de la fenêtre de l'éditeur à fermer.        * -*                                                                             * -*  Description : Ferme la fenêtre de dialogue.                                * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void close_editor(GtkButton *button, GtkWidget *widget) -{ -    gtk_widget_destroy(widget); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : binary = informations sur le binaire actuellement ouvert.    * -*                ref    = espace de référencement principal.                  * -*                                                                             * -*  Description : Charge les parties courantes d'un binaire donné.             * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void load_binary_current_parts(GLoadedBinary *binary, GObject *ref) -{ -    GtkTreeModel *store;                    /* Modèle de représentation    */ -    GBinPart ***list;                       /* Tableau de parties choisies */ -    BinaryPartModel model;                  /* Sélection courante          */ -    size_t *count;                          /* Taille de chaque liste      */ -    unsigned int i;                         /* Boucle de parcours #1       */ -    parts_model *parts;                     /* Liste de sélection courante */ -    size_t j;                               /* Boucle de parcours #2       */ -    GtkTreeIter iter;                       /* Lieu de lecture d'adresse   */ -    char path[11 /* UINT_MAX */];           /* Chemin d'accès pour GTK     */ -    gchar *value;                           /* Valeur d'adresse présentée  */ -    vmpa_t addr_dlg;                        /* Adresse côté local          */ -    size_t k;                               /* Boucle de parcours #3       */ -    vmpa_t addr_bin;                        /* Adresse côté binaire        */ -    GtkComboBox *combo;                     /* Liste de tous les modèles   */ - -    /* Lecture des sélections courantes */ - -    store = GTK_TREE_MODEL(g_object_get_data(ref, "store")); - -    list = g_loaded_binary_get_parts(binary, &model, &count); - -    for (i = 0; i < (BPM_COUNT - 1 /* TODO*/); i++) -    { -        gtk_tree_store_clear(GTK_TREE_STORE(store)); - -        switch (i) -        { -            case BPM_DEFAULT: -                load_default_parts(ref); -                parts = (parts_model *)g_object_get_data(ref, "default_model"); -                break; -            case BPM_ROUTINES: -                load_routines_parts(ref); -                parts = (parts_model *)g_object_get_data(ref, "routines_model"); -                break; -            case BPM_USER: -                //parts =  -                break; -        } - -        for (j = 0; j < parts->count; j++) -        { -            snprintf(path, 11, "%u", j); - -            gtk_tree_model_get_iter_from_string(store, &iter, path); -            gtk_tree_model_get(store, &iter, PTC_START, &value, -1); -            addr_dlg = strtoll(value, NULL, 16); -            g_free(value); - -            for (k = 0; k < count[i]; k++) -            { -                g_binary_part_get_values(list[i][k], NULL, NULL, &addr_bin); -                if (addr_bin == addr_dlg) break; -            } - -            parts->selected[j] = (count[i] == 0 || k < count[i]); - -        } - -    } - -    /* Sélection courante */ -    combo = GTK_COMBO_BOX(g_object_get_data(ref, "models")); -    gtk_combo_box_set_active(combo, model); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : ref = espace de référencement principal.                     * -*                                                                             * -*  Description : Affiche les parties désassemblées par défaut.                * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void load_default_parts(GObject *ref) -{ -    GLoadedBinary *binary;                  /* Binaire à traiter           */ -    GtkTreeStore *store;                    /* Modèle de gestion           */ -    GExeFormat *format;                     /* Format associé au binaire   */ -    GArchProcessor *proc;                   /* Architecture utilisée       */ -    GBinPart **parts;                       /* Parties d'élément binaire   */ -    size_t parts_count;                     /* Nombre de ces parties       */ -    parts_model *model;                     /* Mémoire du modèle           */ -    bool exist;                             /* Mémoire présente ?          */ -    size_t i;                               /* Boucle de parcours          */ -    off_t size;                             /* Taille de la partie         */ -    vmpa_t addr;                            /* Adresse de départ           */ -    char start[VMPA_MAX_SIZE];              /* Version humainement lisible */ -    char end[VMPA_MAX_SIZE];                /* Version humainement lisible */ -    GtkTreeIter iter;                       /* Point d'insertion           */ - -    binary = G_LOADED_BINARY(g_object_get_data(ref, "binary")); -    store = GTK_TREE_STORE(g_object_get_data(ref, "store")); - -    format = g_loaded_binary_get_format(binary); -    proc = get_arch_processor_from_format(format); - -    parts = g_exe_format_get_parts(format, &parts_count); -    qsort(parts, parts_count, sizeof(GBinPart *), g_binary_part_compare); - -    model = (parts_model *)g_object_get_data(ref, "default_model"); -    exist = (model != NULL); - -    if (!exist) -    { -        model = (parts_model *)calloc(1, sizeof(parts_model)); -        g_object_set_data(ref, "default_model", model); - -        model->selected = (gboolean *)calloc(parts_count, sizeof(gboolean)); -        model->count = parts_count; - -    } - -    for (i = 0; i < parts_count; i++) -    { -        g_binary_part_get_values(parts[i], NULL, &size, &addr); - -        vmpa_to_string(addr, g_arch_processor_get_memory_size(proc), start); -        vmpa_to_string(addr + size, g_arch_processor_get_memory_size(proc), end); - -        if (!exist) -            model->selected[i] = TRUE; - -        gtk_tree_store_append(store, &iter, NULL); -        gtk_tree_store_set(store, &iter, -                           PTC_ACTIVE, model->selected[i], -                           PTC_NAME, g_binary_part_get_name(parts[i]), -                           PTC_START, start, -                           PTC_END, end, -                           -1); - -    } - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : ref = espace de référencement principal.                     * -*                                                                             * -*  Description : Affiche les parties désassemblées selon les routines.        * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void load_routines_parts(GObject *ref) -{ -    GLoadedBinary *binary;                  /* Binaire à traiter           */ -    GtkTreeStore *store;                    /* Modèle de gestion           */ -    GExeFormat *format;                     /* Format associé au binaire   */ -    GArchProcessor *proc;                   /* Architecture utilisée       */ -    GBinRoutine **routines;                 /* Liste des routines trouvées */ -    size_t routines_count;                  /* Nombre de ces routines      */ -    parts_model *model;                     /* Mémoire du modèle           */ -    bool exist;                             /* Mémoire présente ?          */ -    size_t i;                               /* Boucle de parcours          */ -    vmpa_t addr;                            /* Adresse à transcrire        */ -    char start[VMPA_MAX_SIZE];              /* Version humainement lisible */ -    char end[VMPA_MAX_SIZE];                /* Version humainement lisible */ -    GtkTreeIter iter;                       /* Point d'insertion           */ - -    binary = G_LOADED_BINARY(g_object_get_data(ref, "binary")); -    store = GTK_TREE_STORE(g_object_get_data(ref, "store")); - -    format = g_loaded_binary_get_format(binary); -    proc = get_arch_processor_from_format(format); - -    routines = g_binary_format_get_routines(G_BIN_FORMAT(format), &routines_count); -    qsort(routines, routines_count, sizeof(GBinRoutine *), g_binary_routine_compare); - -    model = (parts_model *)g_object_get_data(ref, "routines_model"); -    exist = (model != NULL); - -    if (!exist) -    { -        model = (parts_model *)calloc(1, sizeof(parts_model)); -        g_object_set_data(ref, "routines_model", model); - -        model->selected = (gboolean *)calloc(routines_count, sizeof(gboolean)); -        model->count = routines_count; - -    } - -    for (i = 0; i < routines_count; i++) -    { -        addr = g_binary_routine_get_address(routines[i]); -        vmpa_to_string(addr, g_arch_processor_get_memory_size(proc), start); - -        addr += g_binary_routine_get_size(routines[i]); -        vmpa_to_string(addr, g_arch_processor_get_memory_size(proc), end); - -        if (!exist) -            model->selected[i] = TRUE; - -        gtk_tree_store_append(store, &iter, NULL); -        gtk_tree_store_set(store, &iter, -                           PTC_ACTIVE, model->selected[i], -                           PTC_NAME, g_binary_routine_get_name(routines[i]), -                           PTC_START, start, -                           PTC_END, end, -                           -1); - -    } - -} - - - - - - - - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : combo = liste des modèles proposés.                          * -*                ref   = espace de référencement principal.                   * -*                                                                             * -*  Description : Réagit à un changement de modèle.                            * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void on_model_change(GtkComboBox *combo, GObject *ref) -{ -    gint index;                             /* Indice du nouveau modèle    */ -    GtkTreeStore *store;                    /* Modèle de gestion           */ - -    store = GTK_TREE_STORE(g_object_get_data(ref, "store")); -    gtk_tree_store_clear(store); - -    index = gtk_combo_box_get_active(combo); - -    switch (index) -    { -        case BPM_DEFAULT: -            load_default_parts(ref); -            break; - -        case BPM_ROUTINES: -            load_routines_parts(ref); -            break; - -        case BPM_USER: -            break; - -    } - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : renderer = cellule de rendu à mettre à jour.                 * -*                path     = chemin menant à la ligne concernée.               * -*                ref      = espace de référencement principal.                * -*                                                                             * -*  Description : Réagit à un changement de sélection de partie.               * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void on_part_selection_toggle(GtkCellRendererToggle *renderer, gchar *path, GObject *ref) -{ -    GtkTreeModel *model;                    /* Modèle de représentation    */ -    GtkTreeIter iter;                       /* Lieu de la mise à jour      */ -    gboolean state;                         /* Etat de la sélection        */ -    GtkComboBox *combo;                     /* Liste de tous les modèles   */ -    gint index;                             /* Indice du modèle courant    */ -    parts_model *list;                      /* Mémorisation des sélections */ - - -    printf("path :: %s\n", path); - -    model = GTK_TREE_MODEL(g_object_get_data(ref, "store")); - -    if (gtk_tree_model_get_iter_from_string(model, &iter, path)) -    { -        gtk_tree_model_get(model, &iter, PTC_ACTIVE, &state, -1); - -        combo = GTK_COMBO_BOX(g_object_get_data(ref, "models")); -        index = gtk_combo_box_get_active(combo); - -        switch (index) -        { -            case BPM_DEFAULT: -                list = (parts_model *)g_object_get_data(ref, "default_model"); -                break; - -            case BPM_ROUTINES: -                list = (parts_model *)g_object_get_data(ref, "routines_model"); -                break; - -            case BPM_USER: -                break; - -        } - -        list->selected[atoi(path)] = !state; - -        gtk_tree_store_set(GTK_TREE_STORE(model), &iter, -                           PTC_ACTIVE, !state, -                           -1); - -    } - -} diff --git a/src/dialogs/binparts.h b/src/dialogs/binparts.h deleted file mode 100644 index 6cdb11e..0000000 --- a/src/dialogs/binparts.h +++ /dev/null @@ -1,40 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * binparts.h - prototypes pour la boîte de dialogue permettant une sélection des sections - * - * Copyright (C) 2009-2012 Cyrille Bagard - * - *  This file is part of Chrysalide. - * - *  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 _DIALOGS_BINPARTS_H -#define _DIALOGS_BINPARTS_H - - -#include <gtk/gtk.h> - - -#include "../analysis/binary.h" - - - -/* Construit la fenêtre de sélection des sections. */ -GtkWidget *create_sections_dialog(GLoadedBinary *, GtkWindow *); - - - -#endif  /* _DIALOGS_BINPARTS_H */ diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 1c06de9..b0fda82 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -6,7 +6,6 @@ libformat_la_SOURCES =					\  	executable.h executable.c			\  	format-int.h						\  	format.h format.c					\ -	part.h part.c						\  	symbol.h symbol.c  # libformat_la_SOURCES =					\ diff --git a/src/format/dex/class.c b/src/format/dex/class.c index 19c004a..b866cd7 100644 --- a/src/format/dex/class.c +++ b/src/format/dex/class.c @@ -320,7 +320,7 @@ GDexMethod *g_dex_class_get_method(const GDexClass *class, bool virtual, size_t  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ - +#if 0  GBinPart **g_dex_class_get_parts(const GDexClass *class, GBinPart **parts, size_t *count)  {      size_t i;                               /* Boucle de parcours          */ @@ -347,7 +347,7 @@ GBinPart **g_dex_class_get_parts(const GDexClass *class, GBinPart **parts, size_      return parts;  } - +#endif diff --git a/src/format/dex/class.h b/src/format/dex/class.h index 0eea7b4..8125b91 100644 --- a/src/format/dex/class.h +++ b/src/format/dex/class.h @@ -61,7 +61,7 @@ size_t g_dex_class_count_methods(const GDexClass *, bool);  GDexMethod *g_dex_class_get_method(const GDexClass *, bool, size_t);  /*  Fournit les références aux zones binaires à analyser. */ -GBinPart **g_dex_class_get_parts(const GDexClass *, GBinPart **, size_t *); +//GBinPart **g_dex_class_get_parts(const GDexClass *, GBinPart **, size_t *);  /* Retrouve si possible la méthode associée à une adresse. */  GDexMethod *g_dex_class_find_method_by_address(const GDexClass *, vmpa_t); diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c index 94ec34a..f66f056 100755 --- a/src/format/dex/dex.c +++ b/src/format/dex/dex.c @@ -55,7 +55,7 @@ static void g_dex_format_decompile(const GDexFormat *, GCodeBuffer *, const char  static FormatTargetMachine g_dex_format_get_target_machine(const GDexFormat *);  /* Fournit les références aux zones binaires à analyser. */ -static GBinPart **g_dex_format_get_parts(const GDexFormat *, size_t *); +//static GBinPart **g_dex_format_get_parts(const GDexFormat *, size_t *);  /* Fournit la position correspondant à une adresse virtuelle. */  static bool g_dex_format_translate_address_into_offset(const GDexFormat *, vmpa_t, off_t *); @@ -139,7 +139,6 @@ static void g_dex_format_init(GDexFormat *format)      exe_format = G_EXE_FORMAT(format);      exe_format->get_machine = (get_target_machine_fc)g_dex_format_get_target_machine; -    exe_format->get_parts = (get_parts_fc)g_dex_format_get_parts;      exe_format->translate_addr = (translate_addr_fc)g_dex_format_translate_address_into_offset;      exe_format->translate_off = (translate_off_fc)g_dex_format_translate_offset_into_address; @@ -362,7 +361,7 @@ static FormatTargetMachine g_dex_format_get_target_machine(const GDexFormat *for  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ - +#if 0  static GBinPart **g_dex_format_get_parts(const GDexFormat *format, size_t *count)  {      GBinPart **result;                      /* Tableau à retourner         */ @@ -377,7 +376,7 @@ static GBinPart **g_dex_format_get_parts(const GDexFormat *format, size_t *count      return result;  } - +#endif  /******************************************************************************  *                                                                             * diff --git a/src/format/dex/method.c b/src/format/dex/method.c index 22e7039..c721cea 100644 --- a/src/format/dex/method.c +++ b/src/format/dex/method.c @@ -254,7 +254,7 @@ GBinRoutine *g_dex_method_get_routine(const GDexMethod *method)  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ - +#if 0  GBinPart *g_dex_method_as_part(const GDexMethod *method)  {      GBinPart *result;                       /* Instance à retourner        */ @@ -272,7 +272,7 @@ GBinPart *g_dex_method_as_part(const GDexMethod *method)      return result;  } - +#endif  /******************************************************************************  *                                                                             * diff --git a/src/format/dex/method.h b/src/format/dex/method.h index 472e42d..79e3077 100644 --- a/src/format/dex/method.h +++ b/src/format/dex/method.h @@ -32,8 +32,6 @@  #include "dex_def.h" -#include "../part.h" -  #define G_TYPE_DEX_METHOD                  (g_dex_method_get_type())  #define G_DEX_METHOD(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_DEX_METHOD, GDexMethod)) @@ -81,7 +79,7 @@ const code_item *g_dex_method_get_dex_body(const GDexMethod *);  GBinRoutine *g_dex_method_get_routine(const GDexMethod *);  /* Fournit la zone binaire correspondant à la méthode. */ -GBinPart *g_dex_method_as_part(const GDexMethod *); +//GBinPart *g_dex_method_as_part(const GDexMethod *);  /* Indique la position de la méthode au sein du binaire. */  off_t g_dex_method_get_offset(const GDexMethod *); diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c index 00af26d..b659dd7 100644 --- a/src/format/elf/elf.c +++ b/src/format/elf/elf.c @@ -62,9 +62,6 @@ static FormatTargetMachine g_elf_format_get_target_machine(const GElfFormat *);  /* Etend la définition des portions au sein d'un binaire. */  static void g_elf_format_refine_portions(const GElfFormat *, GBinPortion *); -/* Fournit les références aux zones binaires à analyser. */ -static GBinPart **g_elf_format_get_parts(const GElfFormat *, size_t *); -  /* Fournit la position correspondant à une adresse virtuelle. */  static bool g_elf_format_translate_address_into_offset(const GElfFormat *, vmpa_t, off_t *); @@ -143,7 +140,6 @@ static void g_elf_format_init(GElfFormat *format)      exe_format->get_machine = (get_target_machine_fc)g_elf_format_get_target_machine;      exe_format->refine_portions = (refine_portions_fc)g_elf_format_refine_portions; -    exe_format->get_parts = (get_parts_fc)g_elf_format_get_parts;      exe_format->translate_addr = (translate_addr_fc)g_elf_format_translate_address_into_offset;      exe_format->translate_off = (translate_off_fc)g_elf_format_translate_offset_into_address; @@ -393,104 +389,6 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion *  /******************************************************************************  *                                                                             * -*  Paramètres  : format = informations chargées à consulter.                  * -*                count  = quantité de zones listées. [OUT]                    * -*                                                                             * -*  Description : Fournit les références aux zones binaires à analyser.        * -*                                                                             * -*  Retour      : Zones binaires à analyser.                                   * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static GBinPart **g_elf_format_get_parts(const GElfFormat *format, size_t *count) -{ -    GBinPart **result;                      /* Tableau à retourner         */ -    uint16_t i;                             /* Boucle de parcours          */ -    elf_shdr strings;                       /* Section des descriptions    */ -    bool has_strings;                       /* Section trouvée ?           */ -    elf_shdr section;                       /* En-tête de section ELF      */ -    GBinPart *part;                         /* Partie à intégrer à la liste*/ -    const char *name;                       /* Nom trouvé ou NULL          */ -    off_t offset;                           /* Début de part de programme  */ -    elf_phdr phdr;                          /* En-tête de programme ELF    */ - -    result = NULL; -    *count = 0; - -    has_strings = find_elf_section_by_index(format, ELF_HDR(format, format->header, e_shstrndx), &strings); - -    /* Première tentative : les sections */ - -    for (i = 0; i < ELF_HDR(format, format->header, e_shnum); i++) -    { -        if (!find_elf_section_by_index(format, i, §ion)) -            continue; - -            if (ELF_SHDR(format, section, sh_flags) & SHF_EXECINSTR) -            { -                part = g_binary_part_new(); - -                if (has_strings) -                { -                    name = extract_name_from_elf_string_section(format, &strings, -                                                                ELF_SHDR(format, section, sh_name)); - -                    if (name != NULL) -                        g_binary_part_set_name(part, name); - -                } - -                g_binary_part_set_values(part, -                                         ELF_SHDR(format, section, sh_offset), -                                         ELF_SHDR(format, section, sh_size), -                                         ELF_SHDR(format, section, sh_addr)); - -                result = (GBinPart **)realloc(result, ++(*count) * sizeof(GBinPart *)); -                result[*count - 1] = part; - -            } - -        } - -    /* En désespoir de cause, on se rabbat sur les parties de programme directement */ - -    if (*count == 0) -        for (i = 0; i < ELF_HDR(format, format->header, e_phnum); i++) -        { -            offset = ELF_HDR(format, format->header, e_phoff) -                + ELF_HDR(format, format->header, e_phentsize) * i; - -            if (!read_elf_program_header(format, &offset, &phdr)) -                continue; - -            if (ELF_PHDR(format, phdr, p_flags) & PF_X) -            { -                part = g_binary_part_new(); - -                /* TODO : nom */ - -                g_binary_part_set_values(part, -                                         ELF_PHDR(format, phdr, p_offset), -                                         ELF_PHDR(format, phdr, p_filesz), -                                         ELF_PHDR(format, phdr, p_vaddr)); - -                result = (GBinPart **)realloc(result, ++(*count) * sizeof(GBinPart *)); -                result[*count - 1] = part; - -            } - -        } - - -    return result; - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : format  = description de l'exécutable à consulter.           *  *                addr    = adresse virtuelle à retrouver.                     *  *                pos     = position correspondante. [OUT]                     * diff --git a/src/format/exe_format-int.h b/src/format/exe_format-int.h deleted file mode 100644 index 868e86c..0000000 --- a/src/format/exe_format-int.h +++ /dev/null @@ -1,100 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * exe_format-int.h - prototypes utiles aux formats d'exécutables - * - * Copyright (C) 2008-2012 Cyrille Bagard - * - *  This file is part of Chrysalide. - * - *  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_EXE_FORMAT_INT_H -#define _FORMAT_EXE_FORMAT_INT_H - - -#include "exe_format.h" - - - -/* ------------------------ MANIPULATION DES PARTIES DE CODE ------------------------ */ - - -/* Description d'une partie binaire */ -struct _bin_part -{ -    char *name;                             /* Désignation humaine         */ - -    off_t offset;                           /* Position physique           */ -    off_t size;                             /* Taille de la partie         */ -    uint64_t voffset;                       /* Adresse virtuelle éventuelle*/ - -}; - - - - - - -/* Fournit l'adresse mémoire du point d'entrée du programme. */ -typedef uint64_t (* get_entry_point_fc) (const exe_format *); - -/* Indique le type d'architecture visée par le format. */ -typedef FormatTargetMachine (* get_target_machine_fc) (const exe_format *); - -/* Fournit les références aux zones de code à analyser. */ -typedef bin_part ** (* get_def_parts_fc) (const exe_format *, size_t *); - -/* Recherche une section donnée au sein de binaire. */ -typedef bool (* find_section_fc) (const exe_format *, const char *, off_t *, off_t *, uint64_t *); - -/* Récupère tous les symboles présents dans le contenu binaire. */ -typedef size_t (* get_symbols_fc) (const exe_format *, char ***, SymbolType **, uint64_t **); - -/* Récupère tous les symboles présents dans le contenu binaire. */ -typedef size_t (* get_resolved_fc) (const exe_format *, char ***, ResolvedType **, uint64_t **); - -/* Recherche le symbole correspondant à une adresse. */ -typedef bool (* resolve_symbol_fc) (const exe_format *, char **, SymbolType *, vmpa_t *); - -/* Fournit le prototype de toutes les routines détectées. */ -typedef GBinRoutine ** (* get_all_routines_fc) (const exe_format *, size_t *); - - -/* Support générique d'un format d'exécutable */ -struct _exe_format -{ -    const uint8_t *content;                 /* Contenu binaire à étudier   */ -    off_t length;                           /* Taille de ce contenu        */ - -    get_entry_point_fc get_entry_point;     /* Obtention du point d'entrée */ -    get_target_machine_fc get_target_machine;   /* Architecture ciblée     */ -    get_def_parts_fc get_def_parts;         /* Liste des parties de code   */ -    find_section_fc find_section;           /* Recherche d'une section     */ -    get_symbols_fc get_symbols;             /* Liste des symboles présents */ -    get_resolved_fc get_resolved;           /* Liste des éléments présents */ -    resolve_symbol_fc resolve_symbol;       /* Recherche de symboles       */ -    get_all_routines_fc get_all_routines;   /* Liste de routines détectées */ - -}; - - -#define EXE_FORMAT(f) ((exe_format *)f) - - - - - -#endif  /* _FORMAT_EXE_FORMAT_INT_H */ diff --git a/src/format/exe_format.c b/src/format/exe_format.c deleted file mode 100644 index 14f1541..0000000 --- a/src/format/exe_format.c +++ /dev/null @@ -1,485 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * exe_format.h - support des formats d'exécutables - * - * Copyright (C) 2008-2012 Cyrille Bagard - * - *  This file is part of Chrysalide. - * - *  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/>. - */ - - -#include "exe_format.h" - - -#include <malloc.h> -#include <string.h> - - -#include "exe_format-int.h" -#include "elf/e_elf.h" -#include "java/e_java.h" -#include "pe/e_pe.h" -#include "../panel/log.h" - - - -#define _(str) str - - - - -/* ------------------------ DETECTION DE FORMATS EXECUTABLES ------------------------ */ - - -/* Format d'exécutables enregistré */ -typedef struct _registered_exe_format -{ -    const char *name;                       /* Désignation du format       */ - -    exe_match_fc match;                     /* Procédure de reconnaissance */ -    exe_load_fc load;                       /* Fonction de chargement      */ - -} registered_exe_format; - - -/* Liste des formats d'exécutables enregistrés */ -static registered_exe_format *exe_formats = NULL; -static size_t exe_formats_count = 0; - - -/* Enregistre la disponibilité d'un nouveau format exécutable. */ -void register_exe_format(const char *, exe_match_fc, exe_load_fc); - - - - -/* ---------------------------------------------------------------------------------- */ -/*                          MANIPULATION DES PARTIES DE CODE                          */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : -                                                            * -*                                                                             * -*  Description : Crée une description de partie de code vierge.               * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bin_part *create_bin_part(void) -{ -    bin_part *result;                       /* Structure à renvoyer        */ - -    result = (bin_part *)calloc(1, sizeof(bin_part)); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part = description de partie à mettre à jour.                * -*                name = nom à donner à la partie.                             * -*                                                                             * -*  Description : Attribue une description humaine à une partie de code.       * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void set_bin_part_name(bin_part *part, const char *name) -{ -    if (part->name != NULL) free(part->name); - -    part->name = strdup(name); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part    = description de partie à mettre à jour.             * -*                offset  = position de la section à conserver.                * -*                size    = taille de la section à conserver.                  * -*                voffset = adresse virtuelle de la section à conserver.       * -*                                                                             * -*  Description : Définit les valeurs utiles d'une partie de code.             * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void set_bin_part_values(bin_part *part, off_t offset, off_t size, uint64_t voffset) -{ -    part->offset = offset; -    part->size = size; -    part->voffset = voffset; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part    = description de partie à mettre à jour.             * -*                offset  = position de la section à donner. [OUT]             * -*                size    = taille de la section à donner. [OUT]               * -*                voffset = adresse virtuelle de la section à donner. [OUT]    * -*                                                                             * -*  Description : Fournit les valeurs utiles d'une partie de code.             * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void get_bin_part_values(const bin_part *part, off_t *offset, off_t *size, uint64_t *voffset) -{ -    if (offset != NULL) *offset = part->offset; -    if (size != NULL) *size = part->size; -    if (voffset != NULL) *voffset = part->voffset; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part = description de partie à effacer.                      * -*                                                                             * -*  Description : Supprime de la mémoire une description de partie de code.    * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void delete_bin_part(bin_part *part) -{ -    if (part->name != NULL) free(part->name); - -    free(part); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : a = premières informations à consulter.                      * -*                b = secondes informations à consulter.                       * -*                                                                             * -*  Description : Etablit la comparaison entre deux blocs binaires.            * -*                                                                             * -*  Retour      : Bilan : -1 (a < b), 0 (a == b) ou 1 (a > b).                 * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -int compare_bin_parts(const bin_part **a, const bin_part **b) -{ -    int result;                             /* Bilan à renvoyer            */ - -    if ((*a)->offset < (*b)->offset) result = -1; -    else if((*a)->offset > (*b)->offset) result = 1; -    else result = 0; - -    return result; - -} - - - - - - - - - - - -/* ---------------------------------------------------------------------------------- */ -/*                          DETECTION DE FORMATS EXECUTABLES                          */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : -                                                            * -*                                                                             * -*  Description : Procède au chargement des formats d'exécutables reconnus.    * -*                                                                             * -*  Retour      : true pour indiquer un chargement réussi, false sinon.        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool init_all_exe_formats(void) -{ -    register_exe_format(_("ELF"), elf_is_matching, load_elf); -    register_exe_format(_("Java"), java_is_matching, load_java); -    register_exe_format(_("Portable Executable"), pe_is_matching, load_pe); - -    return true; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : name  = désignation humaine associée.                        * -*                match = procédure de reconnaissance fournie.                 * -*                load  = fonction de chargement fournie.                      * -*                                                                             * -*  Description : Enregistre la disponibilité d'un nouveau format exécutable.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void register_exe_format(const char *name, exe_match_fc match, exe_load_fc load) -{ -    exe_formats = (registered_exe_format *)realloc(exe_formats, -                                                   ++exe_formats_count * sizeof(registered_exe_format)); - -    exe_formats[exe_formats_count - 1].name = name; - -    exe_formats[exe_formats_count - 1].match = match; -    exe_formats[exe_formats_count - 1].load = load; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : content = contenu binaire à parcourir.                       * -*                length  = taille du contenu en question.                     * -*                                                                             * -*  Description : Charge si possible un nouvel exécutable binaire.             * -*                                                                             * -*  Retour      : Adresse du nouveau gestionnaire de format ou NULL si erreur. * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -exe_format *load_new_exe_format(const uint8_t *content, off_t length) -{ -    exe_format *result;                     /* Adresse à retourner         */ -    size_t i;                               /* Boucle de parcours          */ - -    result = NULL; - -    for (i = 0; i < exe_formats_count && result == NULL; i++) -        if (exe_formats[i].match(content, length)) -        { -            log_variadic_message(LMT_INFO, _("%s is matching..."), exe_formats[i].name); - -            result = exe_formats[i].load(content, length); - -        } - -    return result; - -} - - - - - - - -/* ---------------------------------------------------------------------------------- */ -/*                          MANIPULATION DES PARTIES DE CODE                          */ -/* ---------------------------------------------------------------------------------- */ - - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : format = description de l'exécutable à consulter.            * -*                target = nom de la section recherchée.                       * -*                length = taille du contenu à fournir. [OUT]                  * -*                                                                             * -*  Description : Fournit une référence vers le contenu binaire analysé.       * -*                                                                             * -*  Retour      : Adresse du tampon contenant le contenu du binaire.           * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -const uint8_t *get_exe_content(const exe_format *format, off_t *length) -{ -    if (length != NULL) *length = format->length; - -    return format->content; - -} - - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : format = informations chargées à consulter.                  * -*                                                                             * -*  Description : Indique le type d'architecture visée par le format.          * -*                                                                             * -*  Retour      : Identifiant de l'architecture ciblée par le format.          * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -FormatTargetMachine get_exe_target_machine(const exe_format *format) -{ -    return format->get_target_machine(format); - -} - - - - - - - - - - - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : format  = description de l'exécutable à consulter.           * -*                target  = nom de la section recherchée.                      * -*                offset  = position de la section trouvée. [OUT]              * -*                size    = taille de la section trouvée. [OUT]                * -*                voffset = adresse virtuelle de la section trouvée. [OUT]     * -*                                                                             * -*  Description : Recherche une section donnée au sein de binaire.             * -*                                                                             * -*  Retour      : Bilan de l'opération.                                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool find_exe_section(const exe_format *format, const char *target, off_t *offset, off_t *size, uint64_t *voffset) -{ -    return format->find_section(format, target, offset, size, voffset); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : format  = informations chargées à consulter.                 * -*                labels  = liste des commentaires à insérer. [OUT]            * -*                types   = type des symboles listés. [OUT]                    * -*                offsets = liste des indices des commentaires. [OUT]          * -*                                                                             * -*  Description : Récupère tous les symboles présents dans le contenu binaire. * -*                                                                             * -*  Retour      : Nombre d'éléments mis en place.                              * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -size_t get_exe_symbols(const exe_format *format, char ***labels, SymbolType **types, uint64_t **offsets) -{ -    return format->get_symbols(format, labels, types, offsets); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : format  = informations chargées à consulter.                 * -*                labels  = liste des commentaires à insérer. [OUT]            * -*                types   = type des symboles listés. [OUT]                    * -*                offsets = liste des indices des commentaires. [OUT]          * -*                                                                             * -*  Description : Récupère tous les éléments identifiées dans le binaire.      * -*                                                                             * -*  Retour      : Nombre d'éléments mis en place.                              * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -size_t get_exe_resolved_items(const exe_format *format, char ***labels, ResolvedType **types, uint64_t **offsets) -{ -    return format->get_resolved(format, labels, types, offsets); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : format  = informations chargées à consulter.                 * -*                label   = étiquette du symbole si trouvé. [OUT]              * -*                type    = type du symbole trouvé. [OUT]                      * -*                address = adresse à cibler, puis décallage final. [OUT]      * -*                                                                             * -*  Description : Recherche le symbole correspondant à une adresse.            * -*                                                                             * -*  Retour      : true si l'opération a été un succès, false sinon.            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool resolve_exe_symbol(const exe_format *format, char **label, SymbolType *type, vmpa_t *address) -{ -    return format->resolve_symbol(format, label, type, address); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : format = informations chargées à consulter.                  * -*                count  = taille du tableau créé. [OUT]                       * -*                                                                             * -*  Description : Fournit le prototype de toutes les routines détectées.       * -*                                                                             * -*  Retour      : Tableau créé ou NULL si aucun symbole de routine trouvé.     * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GBinRoutine **get_all_exe_routines(const exe_format *format, size_t *count) -{ -    return format->get_all_routines(format, count); - -} diff --git a/src/format/exe_format.h b/src/format/exe_format.h deleted file mode 100644 index b4cecb3..0000000 --- a/src/format/exe_format.h +++ /dev/null @@ -1,152 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * exe_format.h - prototypes pour le support des formats d'exécutables - * - * Copyright (C) 2008-2012 Cyrille Bagard - * - *  This file is part of Chrysalide. - * - *  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_EXE_FORMAT_H -#define _FORMAT_EXE_FORMAT_H - - -#include <stdbool.h> -#include <stdint.h> -#include <sys/types.h> - - -#include "../analysis/routine.h" - -#include "symbol.h" - - -/* ------------------------ MANIPULATION DES PARTIES DE CODE ------------------------ */ - - -/* Description d'une partie binaire */ -typedef struct _bin_part bin_part; - - -/* Crée une description de partie de code vierge. */ -bin_part *create_bin_part(void); - -/* Attribue une description humaine à une partie de code. */ -void set_bin_part_name(bin_part *, const char *); - -/* Définit les valeurs utiles d'une partie de code. */ -void set_bin_part_values(bin_part *, off_t, off_t, uint64_t); - -/* Fournit les valeurs utiles d'une partie de code. */ -void get_bin_part_values(const bin_part *, off_t *, off_t *, uint64_t *); - -/* Supprime de la mémoire une description de partie de code. */ -void delete_bin_part(bin_part *); - -/* Etablit la comparaison entre deux blocs binaires. */ -int compare_bin_parts(const bin_part **, const bin_part **); - - - - -/* FIXME !!!!!!!!!!!! */ - -/* Support générique d'un format d'exécutable */ -typedef struct _exe_format exe_format; - - - -/* ------------------------ DETECTION DE FORMATS EXECUTABLES ------------------------ */ - - -/* Indication à propos du support d'un format */ -typedef bool (* exe_match_fc) (const uint8_t *, off_t); - -/* Méthode de chargement d'un format */ -typedef exe_format * (* exe_load_fc) (const uint8_t *, off_t); - - -/* Procède au chargement des formats d'exécutables reconnus. */ -bool init_all_exe_formats(void); - -/* Charge si possible un nouvel exécutable binaire. */ -exe_format *load_new_exe_format(const uint8_t *, off_t); - - - - -#if 0 -/* Architectures de destination des formats */ -typedef enum _FormatTargetMachine -{ -    FTM_JVM,                                /* Java Virtual Machine        */ -    FTM_MIPS,                               /* Mips 32 ou 64 bits          */ -    FTM_386,                                /* Intel 80386                 */ - -    FTM_COUNT - -} FormatTargetMachine; - - - -/* Types de symbole */ -typedef enum _SymbolType -{ -    STP_SECTION,                            /* Simple morceau de code      */ -    STP_STRING                              /* Chaîne de caractères        */ - -} SymbolType; -#endif - - -/* Types de symbole */ -typedef enum _ResolvedType -{ -    RTP_SECTION,                            /* Simple morceau de code      */ -    RTP_STRING                              /* Chaîne de caractères        */ - -} ResolvedType; - - -/* Fournit une référence vers le contenu binaire analysé. */ -const uint8_t *get_exe_content(const exe_format *, off_t *); - - - -/* Indique le type d'architecture visée par le format. */ -FormatTargetMachine get_exe_target_machine(const exe_format *); - - - -/* Recherche une section donnée au sein de binaire. */ -bool find_exe_section(const exe_format *, const char *, off_t *, off_t *, uint64_t *); - -/* Récupère tous les symboles présents dans le contenu binaire. */ -size_t get_exe_symbols(const exe_format *, char ***, SymbolType **, uint64_t **); - -/* Récupère tous les éléments identifiées dans le binaire. */ -size_t get_exe_resolved_items(const exe_format *, char ***, ResolvedType **, uint64_t **); - -/* Recherche le symbole correspondant à une adresse. */ -bool resolve_exe_symbol(const exe_format *, char **, SymbolType *, vmpa_t *); - -/* Fournit le prototype de toutes les routines détectées. */ -GBinRoutine **get_all_exe_routines(const exe_format *, size_t *); - - - -#endif  /* _FORMAT_EXE_FORMAT_H */ diff --git a/src/format/executable-int.h b/src/format/executable-int.h index 51a2625..119c251 100644 --- a/src/format/executable-int.h +++ b/src/format/executable-int.h @@ -38,9 +38,6 @@ typedef FormatTargetMachine (* get_target_machine_fc) (const GExeFormat *);  /* Etend la définition des portions au sein d'un binaire. */  typedef void (* refine_portions_fc) (const GExeFormat *, GBinPortion *); -/* Fournit les références aux zones de code à analyser. */ -typedef GBinPart ** (* get_parts_fc) (const GExeFormat *, size_t *); -  /* Fournit la position correspondant à une adresse virtuelle. */  typedef bool (* translate_addr_fc) (const GExeFormat *, vmpa_t, off_t *); @@ -57,7 +54,6 @@ struct _GExeFormat      get_target_machine_fc get_machine;      /* Architecture ciblée         */      refine_portions_fc refine_portions;     /* Décrit les portions binaires*/ -    get_parts_fc get_parts;                 /* Liste des parties binaires  */      translate_addr_fc translate_addr;       /* Correspondance addr -> pos  */      translate_off_fc translate_off;         /* Correspondance pos -> addr  */ diff --git a/src/format/executable.c b/src/format/executable.c index db846e2..c1a0a7c 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -24,11 +24,12 @@  #include "executable.h" -#include "executable-int.h" -#include "format.h" +#include <malloc.h> +#include <stdlib.h> -#include <malloc.h> +#include "executable-int.h" +#include "format.h" @@ -255,26 +256,6 @@ mrange_t *g_exe_format_get_x_ranges(GExeFormat *format, size_t *count)  /******************************************************************************  *                                                                             * -*  Paramètres  : format = informations chargées à consulter.                  * -*                count  = quantité de zones listées. [OUT]                    * -*                                                                             * -*  Description : Fournit les références aux zones binaires à analyser.        * -*                                                                             * -*  Retour      : Zones binaires à analyser.                                   * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GBinPart **g_exe_format_get_parts(const GExeFormat *format, size_t *count) -{ -    return format->get_parts(format, count); - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : format  = description de l'exécutable à consulter.           *  *                addr    = adresse virtuelle à retrouver.                     *  *                pos     = position correspondante. [OUT]                     * diff --git a/src/format/executable.h b/src/format/executable.h index 1a3febf..4dc2ddd 100644 --- a/src/format/executable.h +++ b/src/format/executable.h @@ -28,7 +28,6 @@  #include <glib-object.h> -#include "part.h"  #include "../glibext/gbinportion.h" @@ -81,9 +80,6 @@ GBinPortion **g_exe_format_get_portions_at_level(GExeFormat *, unsigned int, siz  /* Fournit les espaces mémoires des portions exécutables. */  mrange_t *g_exe_format_get_x_ranges(GExeFormat *format, size_t *count); -/* Fournit les références aux zones binaires à analyser. */ -GBinPart **g_exe_format_get_parts(const GExeFormat *, size_t *) __attribute__ ((deprecated)); -  /* Fournit la position correspondant à une adresse virtuelle. */  bool g_exe_format_translate_address_into_offset(const GExeFormat *, vmpa_t, off_t *); diff --git a/src/format/java/java.c b/src/format/java/java.c index 3235711..16c9fb7 100755 --- a/src/format/java/java.c +++ b/src/format/java/java.c @@ -48,9 +48,6 @@ static void g_java_format_init(GJavaFormat *);  /* Indique le type d'architecture visée par le format. */  static FormatTargetMachine g_java_format_get_target_machine(const GJavaFormat *); -/* Fournit les références aux zones binaires à analyser. */ -static GBinPart **g_java_format_get_parts(const GJavaFormat *, size_t *); -  /* Fournit la position correspondant à une adresse virtuelle. */  static bool g_java_format_translate_address_into_offset(const GJavaFormat *, vmpa_t, off_t *); @@ -128,7 +125,6 @@ static void g_java_format_init(GJavaFormat *format)      exe_format = G_EXE_FORMAT(format);      exe_format->get_machine = (get_target_machine_fc)g_java_format_get_target_machine; -    exe_format->get_parts = (get_parts_fc)g_java_format_get_parts;      exe_format->translate_addr = (translate_addr_fc)g_java_format_translate_address_into_offset;      exe_format->translate_off = (translate_off_fc)g_java_format_translate_offset_into_address; @@ -217,52 +213,6 @@ static FormatTargetMachine g_java_format_get_target_machine(const GJavaFormat *f  /******************************************************************************  *                                                                             * -*  Paramètres  : format = informations chargées à consulter.                  * -*                count  = quantité de zones listées. [OUT]                    * -*                                                                             * -*  Description : Fournit les références aux zones binaires à analyser.        * -*                                                                             * -*  Retour      : Zones binaires à analyser.                                   * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static GBinPart **g_java_format_get_parts(const GJavaFormat *format, size_t *count) -{ -    GBinPart **result;                      /* Tableau à retourner         */ -    uint16_t i;                             /* Boucle de parcours          */ -    off_t offset;                           /* Position physique           */ -    off_t size;                             /* Taille de la partie         */ -    GBinPart *part;                         /* Partie à intégrer à la liste*/ - -    result = NULL; -    *count = 0; -    /* -    for (i = 0; i < format->header.methods_count; i++) -        if (find_java_method_code_part(&format->header.methods[i], &offset, &size)) -        { -            part = g_binary_part_new(); - -            g_binary_part_set_name(part, "name"); - -            g_binary_part_set_values(part, offset, size, offset); - -            result = (GBinPart **)realloc(result, ++(*count) * sizeof(GBinPart *)); -            result[*count - 1] = part; - -        } - -    } -    */ - -    return result; - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : format = description de l'exécutable à consulter.            *  *                addr   = adresse virtuelle à retrouver.                      *  *                pos    = position correspondante. [OUT]                      * diff --git a/src/format/part.c b/src/format/part.c deleted file mode 100644 index c79c176..0000000 --- a/src/format/part.c +++ /dev/null @@ -1,416 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * part.h - manipulation des parties de code - * - * Copyright (C) 2009-2012 Cyrille Bagard - * - *  This file is part of Chrysalide. - * - *  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/>. - */ - - -#include "part.h" - - -#include <malloc.h> -#include <stdlib.h> -#include <string.h> - - - -/* Bloc de données binaires quelconques (instance) */ -struct _GBinPart -{ -    GObject parent;                         /* A laisser en premier        */ - -    char *name;                             /* Désignation humaine         */ - -    off_t offset;                           /* Position physique           */ -    off_t size;                             /* Taille de la partie         */ -    vmpa_t addr;                            /* Adresse associée            */ - -#ifdef DEBUG -    unsigned int valid;                     /* Instructions reconnues      */ -    unsigned int db;                        /* Instructions non traduites  */ -#endif - -}; - -/* Bloc de données binaires quelconques (classe) */ -struct _GBinPartClass -{ -    GObjectClass parent;                    /* A laisser en premier        */ - -}; - - -/* Initialise la classe des blocs de données binaires. */ -static void g_binary_part_class_init(GBinPartClass *); - -/* Initialise une instance de bloc de données binaires. */ -static void g_binary_part_init(GBinPart *); - - - -/* Indique le type défini par la GLib pour les blocs de doonées. */ -G_DEFINE_TYPE(GBinPart, g_binary_part, G_TYPE_OBJECT); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des blocs de données binaires.          * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_binary_part_class_init(GBinPartClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : line = instance à initialiser.                               * -*                                                                             * -*  Description : Initialise une instance de bloc de données binaires.         * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_binary_part_init(GBinPart *line) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : -                                                            * -*                                                                             * -*  Description : Crée une description de partie de code vierge.               * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GBinPart *g_binary_part_new(void) -{ -    GBinPart *result;                   /* Structure à retourner       */ - -    result = g_object_new(G_TYPE_BIN_PART, NULL); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : src = partie de code à copier.                               * -*                                                                             * -*  Description : Crée une description de partie de code à partir d'une autre. * -*                                                                             * -*  Retour      : Partie de code copiée.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GBinPart *g_binary_part_dump(const GBinPart *src) -{ -    GBinPart *result;                   /* Structure à retourner       */ - -    result = g_object_new(G_TYPE_BIN_PART, NULL); - -    result->name = (src->name != NULL ? strdup(src->name) : NULL); - -    result->offset = result->offset; -    result->size = result->size; -    result->addr = result->addr; - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : node = noeud XML contenant les données à charger.            * -*                                                                             * -*  Description : Crée une description de partie de code vierge à partir d'XML.* -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GBinPart *g_binary_part_load_from_xml(xmlNodePtr node) -{ -    GBinPart *result;                   /* Structure à retourner       */ -    char *value;                        /* Propriété lue depuis le XML */ - -    result = g_binary_part_new(); - -    result->name = qck_get_node_prop_value(node, "name"); -    if (result->name == NULL) goto gbplfx_error; - -    value = qck_get_node_prop_value(node, "offset"); -    if (value == NULL) goto gbplfx_error; - -    result->offset = atoi(value); -    free(value); - -    value = qck_get_node_prop_value(node, "size"); -    if (value == NULL) goto gbplfx_error; - -    result->size = atoi(value); -    free(value); - -    return result; - - gbplfx_error: - -    g_object_unref(G_OBJECT(result)); - -    return NULL; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part   = description de partie à sauvegarder.                * -*                xdoc   = structure XML chargée.                              * -*                parent = noeud XML où rattacher le futur nouveau noeud.      * -*                                                                             * -*  Description : Enregistre les informations d'une partie de code dans du XML.* -*                                                                             * -*  Retour      : Bilan de l'opération.                                        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -bool g_binary_part_save_to_xml(const GBinPart *part, xmlDocPtr xdoc, xmlNodePtr parent) -{ -    bool result;                            /* Bilan à retourner           */ -    xmlNodePtr node;                        /* Nouveau noeud créé          */ - -    result = true; - -    node = add_node_to_node(xdoc, parent, "Part"); -    if (node == NULL) return false; - -    result = _add_string_attribute_to_node(node, "name", part->name); -    result &= add_long_attribute_to_node(node, "offset", part->offset); -    result &= add_long_attribute_to_node(node, "size", part->size); - -    return result; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part = description de partie à mettre à jour.                * -*                name = nom à donner à la partie.                             * -*                                                                             * -*  Description : Attribue une description humaine à une partie de code.       * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_part_set_name(GBinPart *part, const char *name) -{ -    if (part->name != NULL) free(part->name); - -    part->name = strdup(name); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part = description de partie à mettre à jour.                * -*                                                                             * -*  Description : Fournit la description attribuée à une partie de code.       * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -const char *g_binary_part_get_name(const GBinPart *part) -{ -    return part->name; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part   = description de partie à mettre à jour.              * -*                offset = position de la section à conserver.                 * -*                size   = taille de la section à conserver.                   * -*                addr   = adresse de la section à conserver.                  * -*                                                                             * -*  Description : Définit les valeurs utiles d'une partie de code.             * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_part_set_values(GBinPart *part, off_t offset, off_t size, vmpa_t addr) -{ -    part->offset = offset; -    part->size = size; -    part->addr = addr; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part = description de partie à mettre à jour.                * -*                addr = adresse de la section à conserver.                    * -*                                                                             * -*  Description : Définit l'adresse virtuelle d'une partie de code.            * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_part_set_address(GBinPart *part, vmpa_t addr) -{ -    part->addr = addr; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part   = description de partie à consulter.                  * -*                offset = position de la section à donner ou NULL. [OUT]      * -*                size   = taille de la section à donner ou NULL. [OUT]        * -*                addr   = adresse de la section à donner ou NULL. [OUT]       * -*                                                                             * -*  Description : Fournit les valeurs utiles d'une partie de code.             * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_part_get_values(const GBinPart *part, off_t *offset, off_t *size, vmpa_t *addr) -{ -    if (offset != NULL) *offset = part->offset; -    if (size != NULL) *size = part->size; -    if (addr != NULL) *addr = part->addr; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : a = premières informations à consulter.                      * -*                b = secondes informations à consulter.                       * -*                                                                             * -*  Description : Etablit la comparaison entre deux blocs binaires.            * -*                                                                             * -*  Retour      : Bilan : -1 (a < b), 0 (a == b) ou 1 (a > b).                 * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -int g_binary_part_compare(const GBinPart **a, const GBinPart **b) -{ -    int result;                             /* Bilan à renvoyer            */ - -    if ((*a)->offset < (*b)->offset) result = -1; -    else if((*a)->offset > (*b)->offset) result = 1; -    else result = 0; - -    return result; - -} - -#ifdef DEBUG - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part  = description de partie à mettre à jour.               * -*                valid = quantité d'instructions décodées pour cette partie.  * -*                db    = quantité d'instructions non traduites ici.           * -*                                                                             * -*  Description : Mémorise un bilan de désassemblage.                          * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_part_set_checkup(GBinPart *part, unsigned int valid, unsigned int db) -{ -    part->valid = valid; -    part->db = db; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : part  = description de partie à mettre à jour.               * -*                valid = quantité d'instructions décodées ici. [OUT]          * -*                db    = quantité d'instructions non traduites ici. [OUT]     * -*                                                                             * -*  Description : Mémorise un bilan de désassemblage.                          * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_binary_part_get_checkup(const GBinPart *part, unsigned int *valid, unsigned int *db) -{ -    *valid = part->valid; -    *db = part->db; - -} - -#endif diff --git a/src/format/part.h b/src/format/part.h deleted file mode 100644 index e45f234..0000000 --- a/src/format/part.h +++ /dev/null @@ -1,97 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * part.h - prototypes pour la manipulation des parties de code - * - * Copyright (C) 2009-2012 Cyrille Bagard - * - *  This file is part of Chrysalide. - * - *  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_PART_H -#define _FORMAT_PART_H - - -#include <glib-object.h> -#include <sys/types.h> - - -#include "../common/xml.h" -#include "../arch/archbase.h" - - - -#define G_TYPE_BIN_PART                (g_binary_part_get_type()) -#define G_BIN_PART(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BIN_PART, GBinPart)) -#define G_IS_BIN_PART(obj)             (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BIN_PART)) -#define G_BIN_PART_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BIN_PART, GBinPartClass)) -#define G_IS_BIN_PART_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BIN_PART)) -#define G_BIN_PART_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_PART, GBinPartClass)) - - -/* Bloc de données binaires quelconques (instance) */ -typedef struct _GBinPart GBinPart; - -/* Bloc de données binaires quelconques (classe) */ -typedef struct _GBinPartClass GBinPartClass; - - -/* Indique le type défini par la GLib pour les blocs de doonées. */ -GType g_binary_part_get_type(void); - -/* Crée une description de partie de code vierge. */ -GBinPart *g_binary_part_new(void); - -/* Crée une description de partie de code à partir d'une autre. */ -GBinPart *g_binary_part_dump(const GBinPart *); - -/* Crée une description de partie de code vierge à partir d'XML. */ -GBinPart *g_binary_part_load_from_xml(xmlNodePtr); - -/* Enregistre les informations d'une partie de code dans du XML. */ -bool g_binary_part_save_to_xml(const GBinPart *, xmlDocPtr, xmlNodePtr); - -/* Attribue une description humaine à une partie de code. */ -void g_binary_part_set_name(GBinPart *, const char *); - -/* Fournit la description attribuée à une partie de code. */ -const char *g_binary_part_get_name(const GBinPart *); - -/* Définit les valeurs utiles d'une partie de code. */ -void g_binary_part_set_values(GBinPart *, off_t, off_t, vmpa_t); - -/* Définit l'adresse virtuelle d'une partie de code. */ -void g_binary_part_set_address(GBinPart *, vmpa_t); - -/* Fournit les valeurs utiles d'une partie de code. */ -void g_binary_part_get_values(const GBinPart *, off_t *, off_t *, vmpa_t *); - -/* Etablit la comparaison entre deux blocs binaires. */ -int g_binary_part_compare(const GBinPart **, const GBinPart **); - -#ifdef DEBUG - -/* Mémorise un bilan de désassemblage. */ -void g_binary_part_set_checkup(GBinPart *, unsigned int, unsigned int); - -/* Mémorise un bilan de désassemblage. */ -void g_binary_part_get_checkup(const GBinPart *, unsigned int *, unsigned int *); - -#endif - - - -#endif  /* _FORMAT_PART_H */ diff --git a/src/format/pe/pe.c b/src/format/pe/pe.c index 2692560..16a9032 100644 --- a/src/format/pe/pe.c +++ b/src/format/pe/pe.c @@ -43,7 +43,7 @@ static void g_pe_format_init(GPeFormat *);  static FormatTargetMachine g_pe_format_get_target_machine(const GPeFormat *);  /* Fournit les références aux zones binaires à analyser. */ -static GBinPart **g_pe_format_get_parts(const GPeFormat *, size_t *); +//static GBinPart **g_pe_format_get_parts(const GPeFormat *, size_t *);  /* Fournit la position correspondant à une adresse virtuelle. */  static bool g_pe_format_translate_address_into_offset(const GPeFormat *, vmpa_t, off_t *); @@ -137,7 +137,6 @@ static void g_pe_format_init(GPeFormat *format)      exe_format = G_EXE_FORMAT(format);      exe_format->get_machine = (get_target_machine_fc)g_pe_format_get_target_machine; -    exe_format->get_parts = (get_parts_fc)g_pe_format_get_parts;      exe_format->translate_addr = (translate_addr_fc)g_pe_format_translate_address_into_offset;      exe_format->translate_off = (translate_off_fc)g_pe_format_translate_offset_into_address; @@ -263,7 +262,7 @@ static FormatTargetMachine g_pe_format_get_target_machine(const GPeFormat *forma  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ - +#if 0  static GBinPart **g_pe_format_get_parts(const GPeFormat *format, size_t *count)  {      GBinPart **result;                      /* Tableau à retourner         */ @@ -311,7 +310,7 @@ static GBinPart **g_pe_format_get_parts(const GPeFormat *format, size_t *count)      return result;  } - +#endif  /******************************************************************************  *                                                                             *  | 
