diff options
Diffstat (limited to 'src/analysis/db/items/switcher.c')
-rw-r--r-- | src/analysis/db/items/switcher.c | 135 |
1 files changed, 125 insertions, 10 deletions
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; } |