diff options
Diffstat (limited to 'src/analysis/db/items')
| -rw-r--r-- | src/analysis/db/items/bookmark.c | 113 | ||||
| -rw-r--r-- | src/analysis/db/items/switcher.c | 135 | ||||
| -rw-r--r-- | src/analysis/db/items/switcher.h | 23 | 
3 files changed, 239 insertions, 32 deletions
diff --git a/src/analysis/db/items/bookmark.c b/src/analysis/db/items/bookmark.c index c9d7b7a..8512406 100644 --- a/src/analysis/db/items/bookmark.c +++ b/src/analysis/db/items/bookmark.c @@ -44,6 +44,8 @@ struct _GDbBookmark      vmpa2t addr;                            /* Adresse du signet           */      rle_string comment;                     /* Eventuel commentaire associé*/ +    bool prev_state;                        /* Drapeau déjà présent avant ?*/ +  };  /* Signet à l'intérieur d'une zone de texte (classe) */ @@ -75,6 +77,15 @@ static bool g_db_bookmark_recv_from_fd(GDbBookmark *, int, int);  /* Exporte la définition d'un signet dans un flux réseau. */  static bool g_db_bookmark_send_to_fd(const GDbBookmark *, int, int); +/* Exécute un signet sur un tampon de binaire chargé. */ +static bool g_db_bookmark_run(GDbBookmark *, GLoadedBinary *, bool *, bool); + +/* Applique un signet sur un tampon de binaire chargé. */ +static bool g_db_bookmark_apply(GDbBookmark *, GLoadedBinary *); + +/* Annule un signet sur un tampon de binaire chargé. */ +static bool g_db_bookmark_cancel(GDbBookmark *, GLoadedBinary *); +  /* Constitue les champs destinés à une insertion / modification. */  static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *, bound_value **, size_t *); @@ -161,6 +172,8 @@ static void g_db_bookmark_class_init(GDbBookmarkClass *klass)      item->recv = (recv_db_item_fc)g_db_bookmark_recv_from_fd;      item->send = (send_db_item_fc)g_db_bookmark_send_to_fd; +    item->apply = (run_item_fc)g_db_bookmark_apply; +    item->cancel = (run_item_fc)g_db_bookmark_cancel;      item->prepare_stmt = (prepare_db_statement)g_db_bookmark_prepare_db_statement;      item->load = (load_db_item_fc)g_db_bookmark_load; @@ -350,6 +363,106 @@ static bool g_db_bookmark_send_to_fd(const GDbBookmark *bookmark, int fd, int fl  /******************************************************************************  *                                                                             * +*  Paramètres  : bookmark = signet à manipuler.                               * +*                binary   = binaire chargé en mémoire à modifier.             * +*                prev     = état précédent de la présence du drapeau.         * +*                set      = précision quant au nouvel état du drapeau.        * +*                                                                             * +*  Description : Exécute un signet sur un tampon de binaire chargé.           * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_bookmark_run(GDbBookmark *bookmark, GLoadedBinary *binary, bool *prev, bool set) +{ +    bool result;                            /* Bilan à faire remonter      */ +    GCodeBuffer *buffer;                    /* Tampon de lignes à traiter  */ +    GBufferLine *line;                      /* Ligne de tampon à marquer   */ + +    result = true; + +    buffer = g_loaded_binary_get_disassembled_buffer(binary); + +    line = g_code_buffer_find_line_by_addr(buffer, &bookmark->addr, BLF_HAS_CODE, NULL); +    if (line == NULL) +    { +        result = false; +        goto exit; +    } + +    *prev = g_buffer_line_get_flags(line) & BLF_BOOKMARK; + +    if (set) +        g_buffer_line_add_flag(line, BLF_BOOKMARK); + +    else +        g_buffer_line_remove_flag(line, BLF_BOOKMARK); + +    g_object_unref(G_OBJECT(line)); + + exit: + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = signet à manipuler.                               * +*                binary   = binaire chargé en mémoire à modifier.             * +*                                                                             * +*  Description : Applique un signet sur un tampon de binaire chargé.          * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_bookmark_apply(GDbBookmark *bookmark, GLoadedBinary *binary) +{ +    bool result;                            /* Bilan à faire remonter      */ + +    result = g_db_bookmark_run(bookmark, binary, &bookmark->prev_state, true); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = signet à manipuler.                               * +*                binary   = binaire chargé en mémoire à modifier.             * +*                                                                             * +*  Description : Annule un signet sur un tampon de binaire chargé.            * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_bookmark_cancel(GDbBookmark *bookmark, GLoadedBinary *binary) +{ +    bool result;                            /* Bilan à faire remonter      */ + +    if (!bookmark->prev_state) +        result = g_db_bookmark_run(bookmark, binary, (bool []) { 0 }, false); +    else +        result = true; + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : bookmark = base d'éléments sur laquelle s'appuyer.           *  *                values   = couples de champs et de valeurs à lier. [OUT]     *  *                count    = nombre de ces couples. [OUT]                      * diff --git a/src/analysis/db/items/switcher.c b/src/analysis/db/items/switcher.c index 5063a9c..2168e6b 100644 --- a/src/analysis/db/items/switcher.c +++ b/src/analysis/db/items/switcher.c @@ -24,6 +24,7 @@  #include "switcher.h" +#include <assert.h>  #include <stdio.h>  #include <sys/socket.h> @@ -47,7 +48,8 @@ struct _GDbSwitcher      vmpa2t addr;                            /* Adresse de l'instruction    */      size_t index;                           /* Indice de l'opérande visé   */ -    ImmSwitchType type;                     /* Type de bascule             */ +    ImmOperandDisplay display;              /* Type de bascule             */ +    ImmOperandDisplay old;                  /* Type de bascule précédente  */  }; @@ -81,6 +83,15 @@ static bool g_db_switcher_recv_from_fd(GDbSwitcher *, int, int);  /* Exporte la définition d'un signet dans un flux réseau. */  static bool g_db_switcher_send_to_fd(const GDbSwitcher *, int, int); +/* Exécute une bascule d'affichage d'opérande sur un binaire. */ +static bool g_db_switcher_run(GDbSwitcher *, GLoadedBinary *, ImmOperandDisplay *, ImmOperandDisplay); + +/* Applique une bascule d'affichage d'opérande sur un binaire. */ +static bool g_db_switcher_apply(GDbSwitcher *, GLoadedBinary *); + +/* Annule une bascule d'affichage d'opérande sur un binaire. */ +static bool g_db_switcher_cancel(GDbSwitcher *, GLoadedBinary *); +  /* Constitue les champs destinés à une insertion / modification. */  static bool g_db_switcher_prepare_db_statement(const GDbSwitcher *, bound_value **, size_t *); @@ -168,6 +179,8 @@ static void g_db_switcher_class_init(GDbSwitcherClass *klass)      item->recv = (recv_db_item_fc)g_db_switcher_recv_from_fd;      item->send = (send_db_item_fc)g_db_switcher_send_to_fd; +    item->apply = (run_item_fc)g_db_switcher_apply; +    item->cancel = (run_item_fc)g_db_switcher_cancel;      item->prepare_stmt = (prepare_db_statement)g_db_switcher_prepare_db_statement;      item->load = (load_db_item_fc)g_db_switcher_load; @@ -244,7 +257,7 @@ static void g_db_switcher_finalize(GDbSwitcher *switcher)  *                                                                             *  ******************************************************************************/ -GDbSwitcher *g_db_switcher_new(const GArchInstruction *instr, const GImmOperand *imm, ImmSwitchType type) +GDbSwitcher *g_db_switcher_new(const GArchInstruction *instr, const GImmOperand *imm, ImmOperandDisplay display)  {      GDbSwitcher *result;                      /* Instance à retourner        */      size_t count;                           /* Nombre d'opérandes à visiter*/ @@ -271,7 +284,7 @@ GDbSwitcher *g_db_switcher_new(const GArchInstruction *instr, const GImmOperand      result->index = i; -    result->type = type; +    result->display = display;      /* Création d'un intitulé adapté */ @@ -315,10 +328,10 @@ static gint g_db_switcher_cmp(GDbSwitcher *a, GDbSwitcher *b)      if (result == 0)      { -        if (a->type < b->type) +        if (a->display < b->display)              result = -1; -        else if (a->type > b->type) +        else if (a->display > b->display)              result = 1;      } @@ -365,9 +378,9 @@ static bool g_db_switcher_recv_from_fd(GDbSwitcher *switcher, int fd, int flags)      got = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL);      if (got != sizeof(uint32_t)) return false; -    switcher->type = be32toh(val32); +    switcher->display = be32toh(val32); -    if (switcher->type >= IST_COUNT) +    if (switcher->display >= IOD_COUNT)          return false;      return true; @@ -402,7 +415,7 @@ static bool g_db_switcher_send_to_fd(const GDbSwitcher *switcher, int fd, int fl      status = safe_send(fd, (uint32_t []) { htobe32(switcher->index) }, sizeof(uint32_t), MSG_MORE | flags);      if (!status) return false; -    status = safe_send(fd, (uint32_t []) { htobe32(switcher->type) }, sizeof(uint32_t), flags); +    status = safe_send(fd, (uint32_t []) { htobe32(switcher->display) }, sizeof(uint32_t), flags);      if (!status) return false;      return true; @@ -412,6 +425,108 @@ static bool g_db_switcher_send_to_fd(const GDbSwitcher *switcher, int fd, int fl  /******************************************************************************  *                                                                             * +*  Paramètres  : switcher = bascule d'affichage à manipuler.                  * +*                binary   = binaire chargé en mémoire à modifier.             * +*                old      = état précédent à conserver.                       * +*                new      = nouvel état à appliquer.                          * +*                                                                             * +*  Description : Exécute une bascule d'affichage d'opérande sur un binaire.   * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_switcher_run(GDbSwitcher *switcher, GLoadedBinary *binary, ImmOperandDisplay *old, ImmOperandDisplay new) +{ +    bool result;                            /* Bilan à faire remonter      */ +    GArchProcessor *proc;                   /* Propriétaire d'instructions */ +    GArchInstruction *instr;                /* Instruction à traiter       */ +    GArchOperand *op;                       /* Opérande à modifier         */ + +    result = true; + +    proc = g_loaded_binary_get_processor(binary); + +    instr = g_arch_processor_find_instr_by_address(proc, &switcher->addr); +    if (instr == NULL) +    { +        result = false; +        goto exit; +    } + +    op = g_arch_instruction_get_operand(instr, switcher->index); +    if (op == NULL) +    { +        result = false; +        goto exit; +    } + +    result = G_IS_IMM_OPERAND(op); + +    if (result) +        g_imm_operand_set_display(G_IMM_OPERAND(op), new); + + exit: + +    g_object_unref(G_OBJECT(proc)); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : switcher = bascule d'affichage à manipuler.                  * +*                binary   = binaire chargé en mémoire à modifier.             * +*                                                                             * +*  Description : Applique une bascule d'affichage d'opérande sur un binaire.  * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_switcher_apply(GDbSwitcher *switcher, GLoadedBinary *binary) +{ +    bool result;                            /* Bilan à faire remonter      */ + +    result = g_db_switcher_run(switcher, binary, &switcher->old, switcher->display); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : switcher = bascule d'affichage à manipuler.                  * +*                binary   = binaire chargé en mémoire à modifier.             * +*                                                                             * +*  Description : Annule une bascule d'affichage d'opérande sur un binaire.    * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_switcher_cancel(GDbSwitcher *switcher, GLoadedBinary *binary) +{ +    bool result;                            /* Bilan à faire remonter      */ + +    result = g_db_switcher_run(switcher, binary, (ImmOperandDisplay []) { 0 }, switcher->old); + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : switcher = base d'éléments sur laquelle s'appuyer.           *  *                values   = couples de champs et de valeurs à lier. [OUT]     *  *                count    = nombre de ces couples. [OUT]                      * @@ -449,7 +564,7 @@ static bool g_db_switcher_prepare_db_statement(const GDbSwitcher *switcher, boun      value->name = "type";      value->type = SQLITE_INTEGER; -    value->integer = switcher->type; +    value->integer = switcher->display;      value->delete = NULL;      return true; @@ -496,7 +611,7 @@ static bool g_db_switcher_load(GDbSwitcher *switcher, const bound_value *values,          result = (value != NULL && value->type == SQLITE_INTEGER);          if (result) -            switcher->type = value->integer; +            switcher->display = value->integer;      } diff --git a/src/analysis/db/items/switcher.h b/src/analysis/db/items/switcher.h index a839b3a..a2bff7e 100644 --- a/src/analysis/db/items/switcher.h +++ b/src/analysis/db/items/switcher.h @@ -35,30 +35,9 @@ -/* Crée la table des signets dans une base de données. */ -bool create_switcher_db_table(sqlite3 *); - - - - -  /* --------------------- ELABORATION D'UN ELEMENT DE COLLECTION --------------------- */ -/* Basculement d'affichage de valeurs immédiates */ -typedef enum _ImmSwitchType -{ -    IST_DEFAULT,                            /* Impression par défaut       */ -    IST_HEXDECIMAL,                         /* Impression en hexadécimal   */ -    IST_DECIMAL,                            /* Impression en décimal       */ -    IST_OCTAL,                              /* Impression en octal         */ -    IST_BINARY,                             /* Impression en binaire       */ - -    IST_COUNT - -} ImmSwitchType; - -  #define G_TYPE_DB_SWITCHER               g_db_switcher_get_type()  #define G_DB_SWITCHER(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_db_switcher_get_type(), GDbSwitcher))  #define G_IS_DB_SWITCHER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_db_switcher_get_type())) @@ -78,7 +57,7 @@ typedef struct _GDbSwitcherClass GDbSwitcherClass;  GType g_db_switcher_get_type(void);  /* Crée une définition d'un signet dans une zone de texte. */ -GDbSwitcher *g_db_switcher_new(const GArchInstruction *, const GImmOperand *, ImmSwitchType); +GDbSwitcher *g_db_switcher_new(const GArchInstruction *, const GImmOperand *, ImmOperandDisplay);  #if 0  /* Fournit l'adresse associée à un signet. */  | 
