diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-01-16 21:12:08 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-01-16 21:12:08 (GMT) |
commit | 52ac5b1b340335f56ceb599dba63164a26f10b10 (patch) | |
tree | 275104896dffa65e7887284857fa8fed831e9ea8 /src/analysis/db | |
parent | 2ddb5c26af896b10517a89abf0c9498c598b7697 (diff) |
Changed the display of a segment containing the value of an immediate.
Diffstat (limited to 'src/analysis/db')
-rw-r--r-- | src/analysis/db/collection.c | 46 | ||||
-rw-r--r-- | src/analysis/db/items/bookmark.c | 52 | ||||
-rw-r--r-- | src/analysis/db/items/comment.c | 4 | ||||
-rw-r--r-- | src/analysis/db/items/switcher.c | 138 | ||||
-rw-r--r-- | src/analysis/db/misc/rlestr.c | 6 | ||||
-rw-r--r-- | src/analysis/db/misc/timestamp.c | 6 |
6 files changed, 194 insertions, 58 deletions
diff --git a/src/analysis/db/collection.c b/src/analysis/db/collection.c index 117a2d5..d5518dd 100644 --- a/src/analysis/db/collection.c +++ b/src/analysis/db/collection.c @@ -559,12 +559,8 @@ bool g_db_collection_has_item(GDbCollection *collec, GDbItem *item) * Il n'y a pas d'assert() possible pour le vérifier... */ - printf(" --- has\n"); - found = g_list_find_custom(collec->items, item, (GCompareFunc)g_db_item_compare_with_timestamp); - printf(" --- has: %p\n", found); - result = (found != NULL); return result; @@ -950,6 +946,7 @@ bool g_db_collection_load_all_items(GDbCollection *collec, sqlite3 *db) size_t i; /* Boucle de parcours */ sqlite3_stmt *stmt; /* Déclaration mise en place */ int ret; /* Bilan d'un appel à SQLite */ + int native_type; /* Type de valeur dans la base */ GDbItem *new; /* Nouvel élément à insérer */ if (!g_db_collection_setup_load(collec, &values, &count)) @@ -990,12 +987,39 @@ bool g_db_collection_load_all_items(GDbCollection *collec, sqlite3 *db) for (i = 0; i < count; i++) { - values[i].type = sqlite3_column_type(stmt, i); + native_type = sqlite3_column_type(stmt, i); + + /** + * On réalise une petite conversion selon le champ. + * + * Le filtre SQLITE_NATIVE est destiné à conserver un champ sur 32 bits + * quand il s'agit du format utilisé, même si toutes les valeurs sont + * enregistrées en 64 bits. + * + * C'est par exemple le cas dans les bascules d'affichage. + * + * D'autres éléments, comme les localisations en mémoire, peuvent + * avoir un champ éventuellement nul, donc la définition à partir des + * indications de la base de données reste importante. + */ + + if (native_type == SQLITE_INTEGER) + native_type = SQLITE_INT64; + + if (values[i].type == SQLITE_NATIVE) + values[i].type = native_type; + + else + assert(values[i].type == native_type || values[i].type == SQLITE_INTEGER); + switch (values[i].type) { case SQLITE_INTEGER: - values[i].type = SQLITE_INT64; + values[i].integer = (int)sqlite3_column_int64(stmt, i); + break; + + case SQLITE_INT64: values[i].integer64 = sqlite3_column_int64(stmt, i); break; @@ -1118,6 +1142,11 @@ static bool g_db_collection_store_item(const GDbCollection *collec, const GDbIte { switch (values[i].type) { + case SQLITE_INTEGER: + ret = sqlite3_bind_int(stmt, index, values[i].integer); + index++; + break; + case SQLITE_INT64: ret = sqlite3_bind_int64(stmt, index, values[i].integer64); index++; @@ -1272,6 +1301,11 @@ static bool g_db_collection_store_updated_item(const GDbCollection *collec, cons switch (values[i].type) { + case SQLITE_INTEGER: + ret = sqlite3_bind_int(stmt, index, values[i].integer); + index++; + break; + case SQLITE_INT64: ret = sqlite3_bind_int64(stmt, index, values[i].integer64); index++; diff --git a/src/analysis/db/items/bookmark.c b/src/analysis/db/items/bookmark.c index ba64491..6914bc3 100644 --- a/src/analysis/db/items/bookmark.c +++ b/src/analysis/db/items/bookmark.c @@ -80,12 +80,12 @@ 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); - /* Construit la description humaine d'un signet sur un tampon. */ static void g_db_bookmark_build_label(GDbBookmark *); +/* 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 *); @@ -179,7 +179,7 @@ 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->build_label = (build_item_label_fc)g_db_bookmark_build_label; + item->build_label = (build_item_label_fc)g_db_bookmark_build_label; item->apply = (run_item_fc)g_db_bookmark_apply; item->cancel = (run_item_fc)g_db_bookmark_cancel; @@ -373,6 +373,25 @@ static bool g_db_bookmark_send_to_fd(const GDbBookmark *bookmark, int fd, int fl /****************************************************************************** * * * Paramètres : bookmark = signet à manipuler. * +* * +* Description : Construit la description humaine d'un signet sur un tampon. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_db_bookmark_build_label(GDbBookmark *bookmark) +{ + asprintf(&G_DB_ITEM(bookmark)->label, _("Bookmark \"%s\""), get_rle_string(&bookmark->comment)); + +} + + +/****************************************************************************** +* * +* 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. * @@ -422,25 +441,6 @@ static bool g_db_bookmark_run(GDbBookmark *bookmark, GLoadedBinary *binary, bool /****************************************************************************** * * * Paramètres : bookmark = signet à manipuler. * -* * -* Description : Construit la description humaine d'un signet sur un tampon. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_db_bookmark_build_label(GDbBookmark *bookmark) -{ - asprintf(&G_DB_ITEM(bookmark)->label, _("Bookmark \"%s\""), get_rle_string(&bookmark->comment)); - -} - - -/****************************************************************************** -* * -* Paramètres : bookmark = signet à manipuler. * * binary = binaire chargé en mémoire à modifier. * * * * Description : Applique un signet sur un tampon de binaire chargé. * @@ -663,14 +663,10 @@ static void g_bookmark_collection_class_init(GBookmarkCollectionClass *klass) static void g_bookmark_collection_init(GBookmarkCollection *collec) { - - - G_DB_COLLECTION(collec)->featuring = 0; + G_DB_COLLECTION(collec)->featuring = DBF_BOOKMARKS; G_DB_COLLECTION(collec)->type = G_TYPE_DB_BOOKMARK; G_DB_COLLECTION(collec)->name = "Bookmarks"; - - } diff --git a/src/analysis/db/items/comment.c b/src/analysis/db/items/comment.c index 249620b..9212cae 100644 --- a/src/analysis/db/items/comment.c +++ b/src/analysis/db/items/comment.c @@ -526,14 +526,10 @@ static void g_comment_collection_class_init(GCommentCollectionClass *klass) static void g_comment_collection_init(GCommentCollection *collec) { - - G_DB_COLLECTION(collec)->featuring = 0; G_DB_COLLECTION(collec)->type = G_TYPE_DB_COMMENT; G_DB_COLLECTION(collec)->name = "Comments"; - - } diff --git a/src/analysis/db/items/switcher.c b/src/analysis/db/items/switcher.c index 67187aa..7b72cf2 100644 --- a/src/analysis/db/items/switcher.c +++ b/src/analysis/db/items/switcher.c @@ -29,6 +29,9 @@ #include <sys/socket.h> +#include <i18n.h> + + #include "../collection-int.h" #include "../item-int.h" #include "../../../common/io.h" @@ -83,6 +86,9 @@ 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); +/* Construit la description humaine d'un signet sur un tampon. */ +static void g_db_switcher_build_label(GDbSwitcher *); + /* Exécute une bascule d'affichage d'opérande sur un binaire. */ static bool g_db_switcher_run(GDbSwitcher *, GLoadedBinary *, ImmOperandDisplay *, ImmOperandDisplay); @@ -180,6 +186,7 @@ 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->build_label = (build_item_label_fc)g_db_switcher_build_label; item->apply = (run_item_fc)g_db_switcher_apply; item->cancel = (run_item_fc)g_db_switcher_cancel; @@ -364,7 +371,6 @@ static bool g_db_switcher_recv_from_fd(GDbSwitcher *switcher, int fd, int flags) { bool status; /* Bilan d'opération initiale */ uint32_t val32; /* Valeur sur 32 bits */ - ssize_t got; /* Quantité de données reçues */ status = G_DB_ITEM_CLASS(g_db_switcher_parent_class)->recv(G_DB_ITEM(switcher), fd, flags); if (!status) return false; @@ -372,17 +378,17 @@ static bool g_db_switcher_recv_from_fd(GDbSwitcher *switcher, int fd, int flags) if (!recv_vmpa(&switcher->addr, fd, flags)) return false; - got = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL); - if (got != sizeof(uint32_t)) return false; + status = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL | flags); + if (!status) return false; switcher->index = be32toh(val32); - got = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL); - if (got != sizeof(uint32_t)) return false; + status = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL | flags); + if (!status) return false; switcher->display = be32toh(val32); - if (switcher->display >= IOD_COUNT) + if (switcher->display > IOD_COUNT) return false; return true; @@ -428,6 +434,52 @@ static bool g_db_switcher_send_to_fd(const GDbSwitcher *switcher, int fd, int fl /****************************************************************************** * * * Paramètres : switcher = bascule d'affichage à manipuler. * +* * +* Description : Construit la description humaine d'un signet sur un tampon. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_db_switcher_build_label(GDbSwitcher *switcher) +{ + VMPA_BUFFER(loc); /* Indication de position */ + + if (has_virt_addr(&switcher->addr)) + vmpa2_virt_to_string(&switcher->addr, MDS_UNDEFINED, loc, NULL); + else + vmpa2_phys_to_string(&switcher->addr, MDS_UNDEFINED, loc, NULL); + + switch (switcher->display) + { + case IOD_BIN: + asprintf(&G_DB_ITEM(switcher)->label, _("Switch to binary display at %s"), loc); + break; + case IOD_OCT: + asprintf(&G_DB_ITEM(switcher)->label, _("Switch to octal display at %s"), loc); + break; + case IOD_DEC: + asprintf(&G_DB_ITEM(switcher)->label, _("Switch to octal display at %s"), loc); + break; + case IOD_HEX: + asprintf(&G_DB_ITEM(switcher)->label, _("Switch to octal display at %s"), loc); + break; + case IOD_COUNT: + asprintf(&G_DB_ITEM(switcher)->label, _("Reset to default display at %s"), loc); + break; + default: + assert(false); + break; + } + +} + + +/****************************************************************************** +* * +* Paramètres : switcher = bascule d'affichage à manipuler. * * binary = binaire chargé en mémoire à modifier. * * old = état précédent à conserver. * * new = nouvel état à appliquer. * @@ -446,31 +498,78 @@ static bool g_db_switcher_run(GDbSwitcher *switcher, GLoadedBinary *binary, ImmO GArchProcessor *proc; /* Propriétaire d'instructions */ GArchInstruction *instr; /* Instruction à traiter */ GArchOperand *op; /* Opérande à modifier */ + GCodeBuffer *buffer; /* Tampon de lignes à traiter */ + GBufferLine *line; /* Ligne de tampon à marquer */ + GBufferSegment *segment; /* Segment de texte à modifier*/ + GImmOperand *operand; /* Opérande de valeur immédiate*/ + char value[IMM_MAX_SIZE]; /* Chaîne à imprimer */ + size_t len; /* Taille de l'élément inséré */ result = true; + /* Traitement au niveau des instructions */ + 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; + goto exit_instr; } op = g_arch_instruction_get_operand(instr, switcher->index); if (op == NULL) { result = false; - goto exit; + goto exit_instr; } result = G_IS_IMM_OPERAND(op); + if (!result) goto exit_instr; + + /* Traitement au niveau du rendu graphique */ + + buffer = g_loaded_binary_get_disassembled_buffer(binary); + + line = g_code_buffer_find_line_by_addr(buffer, &switcher->addr, BLF_HAS_CODE, NULL); + if (line == NULL) + { + result = false; + goto exit_gui; + } + + segment = g_buffer_line_find_segment_from_creator(line, G_OBJECT(op)); + result = (segment != NULL); + + /* Applications globales finales */ if (result) - g_imm_operand_set_display(G_IMM_OPERAND(op), new); + { + operand = G_IMM_OPERAND(op); + + *old = g_imm_operand_get_display(operand); + + if (new == IOD_COUNT) + new = g_imm_operand_get_default_display(operand); + + g_imm_operand_set_display(operand, new); + + len = g_imm_operand_to_string(operand, ASX_INTEL, value); + + g_buffer_segment_update_text(segment, value, len); + + g_object_unref(G_OBJECT(segment)); + + } - exit: + g_object_unref(G_OBJECT(line)); + + exit_gui: + + /* TODO g_object_unref(G_OBJECT(buffer));*/ + + exit_instr: g_object_unref(G_OBJECT(proc)); @@ -562,7 +661,7 @@ static bool g_db_switcher_prepare_db_statement(const GDbSwitcher *switcher, boun value->integer = switcher->index; value->delete = NULL; - value = &(*values)[*count - 2]; + value = &(*values)[*count - 1]; value->name = "type"; value->type = SQLITE_INTEGER; @@ -677,14 +776,10 @@ static void g_switcher_collection_class_init(GSwitcherCollectionClass *klass) static void g_switcher_collection_init(GSwitcherCollection *collec) { - - - G_DB_COLLECTION(collec)->featuring = 0; + G_DB_COLLECTION(collec)->featuring = DBF_DISPLAY_SWITCHERS; G_DB_COLLECTION(collec)->type = G_TYPE_DB_SWITCHER; G_DB_COLLECTION(collec)->name = "Switchers"; - - } @@ -804,6 +899,7 @@ static bool g_switcher_collection_create_db_table(const GSwitcherCollection *col static bool g_switcher_collection_setup_load(GSwitcherCollection *collec, bound_value **values, size_t *count) { bool status; /* Bilan d'une préparation */ + bound_value *value; /* Valeur à éditer / définir */ status = G_DB_COLLECTION_CLASS(g_switcher_collection_parent_class)->setup_load(G_DB_COLLECTION(collec), \ values, count); @@ -815,9 +911,15 @@ static bool g_switcher_collection_setup_load(GSwitcherCollection *collec, bound_ *count += 2; *values = (bound_value *)realloc(*values, *count * sizeof(bound_value)); - (*values)[*count - 2].name = "op_index"; + value = &(*values)[*count - 2]; + + value->name = "op_index"; + value->type = SQLITE_INTEGER; + + value = &(*values)[*count - 1]; - (*values)[*count - 1].name = "type"; + value->name = "type"; + value->type = SQLITE_INTEGER; return true; diff --git a/src/analysis/db/misc/rlestr.c b/src/analysis/db/misc/rlestr.c index cbf9291..3f45df6 100644 --- a/src/analysis/db/misc/rlestr.c +++ b/src/analysis/db/misc/rlestr.c @@ -294,9 +294,13 @@ bool prepare_db_statement_for_rle_string(const rle_string *str, const char *name bool setup_load_of_rle_string(const rle_string *str, const char *name, bound_value **values, size_t *count) { + bound_value *value; /* Valeur à éditer / définir */ + *values = (bound_value *)realloc(*values, ++(*count) * sizeof(bound_value)); + value = &(*values)[*count - 1]; - (*values)[*count - 1].name = name; + value->name = name; + value->type = SQLITE_NATIVE; return true; diff --git a/src/analysis/db/misc/timestamp.c b/src/analysis/db/misc/timestamp.c index 624c811..d3ff474 100644 --- a/src/analysis/db/misc/timestamp.c +++ b/src/analysis/db/misc/timestamp.c @@ -223,9 +223,13 @@ bool prepare_db_statement_for_timestamp(const timestamp_t *timestamp, const char bool setup_load_of_timestamp(const timestamp_t *timestamp, const char *name, bound_value **values, size_t *count) { + bound_value *value; /* Valeur à éditer / définir */ + *values = (bound_value *)realloc(*values, ++(*count) * sizeof(bound_value)); + value = &(*values)[*count - 1]; - (*values)[*count - 1].name = name; + value->name = name; + value->type = SQLITE_INT64; return true; |