diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2010-03-21 18:54:20 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2010-03-21 18:54:20 (GMT) |
commit | 8123d9342f92a2cf6fd999b350252c001f403092 (patch) | |
tree | 5030aa5d40fa8551937649cdd3377062ec8991d0 /src/analysis/line_code.c | |
parent | a6acb5629572e6da4d72f4419b01672c2ea5ddf2 (diff) |
Allowed a simple export of an assembly content.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@144 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/line_code.c')
-rw-r--r-- | src/analysis/line_code.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/analysis/line_code.c b/src/analysis/line_code.c index 5787e2a..24f3ec9 100644 --- a/src/analysis/line_code.c +++ b/src/analysis/line_code.c @@ -58,6 +58,9 @@ static void g_code_line_class_init(GCodeLineClass *); /* Initialise la classe des lignes de code binaire. */ static void g_code_line_init(GCodeLine *); +/* Ajoute du texte simple à un fichier ouvert en écriture. */ +static void g_code_line_add_text(GCodeLine *, GRenderingOptions *, MainRendering, FILE *); + /* Ajoute à un texte GTK le contenu de la ligne de code. */ static void g_code_line_add_to_gtk_buffer(GCodeLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, size_t [SAR_COUNT]); @@ -105,6 +108,7 @@ static void g_code_line_init(GCodeLine *line) exporter_parent = G_CONTENT_EXPORTER(line); + exporter_parent->add_text = (add_text_fc)g_code_line_add_text; exporter_parent->add_to_gtk_buffer = (add_to_gtk_buffer_fc)g_code_line_add_to_gtk_buffer; line_parent = G_RENDERING_LINE(line); @@ -114,6 +118,86 @@ static void g_code_line_init(GCodeLine *line) } + +/****************************************************************************** +* * +* Paramètres : line = ligne de représentation à actualiser. * +* options = options de rendu. * +* rendering = support effectif final des lignes de code. * +* stream = flux ouvert en écriture. * +* * +* Description : Ajoute du texte simple à un fichier ouvert en écriture. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_code_line_add_text(GCodeLine *line, GRenderingOptions *options, MainRendering rendering, FILE *stream) +{ + GContentExporter *exporter; /* Autre vision de la ligne */ + bool show_address; /* Affichage de l'adresse ? */ + bool show_code; /* Affichage du code brut ? */ + MemoryDataSize msize; /* Taille du bus d'adresses */ + char address[VMPA_MAX_SIZE]; /* Adresse au format texte */ + size_t len; /* Taille de l'élément inséré */ + const bin_t *content; /* Contenu binaire global */ + off_t bin_offset; /* Début de l'instruction */ + off_t bin_len; /* Taille d'instruction */ + char *bin_code; /* Tampon du code binaire */ + off_t i; /* Boucle de parcours */ + + exporter = G_CONTENT_EXPORTER(line); + + show_address = g_rendering_options_has_to_show_address(options, rendering); + show_code = g_rendering_options_has_to_show_code(options, rendering); + + /* Eventuelle adresse virtuelle ou physique */ + + if (show_address) + { + msize = g_arch_processor_get_memory_size(g_rendering_options_get_processor(options)); + + len = vmpa_to_string(G_RENDERING_LINE(line)->offset, msize, address); + + g_content_exporter_insert_text(exporter, stream, address, len, RTT_NONE); + g_content_exporter_insert_text(exporter, stream, "\t", 1, RTT_NONE); + + } + + /* Eventuel code brut */ + + if (show_code) + { + content = g_binary_format_get_content(G_BIN_FORMAT(g_rendering_options_get_format(options)), NULL); + g_arch_instruction_get_location(line->instr, &bin_offset, &bin_len, NULL); + + bin_code = (char *)calloc(bin_len * 3, sizeof(char)); + + for (i = 0; i < bin_len; i++) + { + if ((i + 1) < bin_len) + snprintf(&bin_code[i * (2 + 1)], 4, "%02hhx ", content[bin_offset + i]); + else + snprintf(&bin_code[i * (2 + 1)], 3, "%02hhx", content[bin_offset + i]); + } + + g_content_exporter_insert_text(exporter, stream, bin_code, bin_len * 3 - 1, RTT_RAW_CODE); + + free(bin_code); + + g_content_exporter_insert_text(exporter, stream, "\t", 1, RTT_NONE); + + } + + /* Instruction proprement dite */ + + g_content_exporter_add_text(G_CONTENT_EXPORTER(line->instr), options, rendering, stream); + +} + + /****************************************************************************** * * * Paramètres : line = ligne de représentation à actualiser. * |