diff options
Diffstat (limited to 'src/analysis')
-rwxr-xr-x | src/analysis/Makefile.am | 4 | ||||
-rw-r--r-- | src/analysis/exporter-int.h | 67 | ||||
-rw-r--r-- | src/analysis/exporter.c | 253 | ||||
-rw-r--r-- | src/analysis/exporter.h | 92 | ||||
-rw-r--r-- | src/analysis/line-int.h | 12 | ||||
-rw-r--r-- | src/analysis/line.c | 26 | ||||
-rw-r--r-- | src/analysis/line_code.c | 136 | ||||
-rw-r--r-- | src/analysis/line_comment.c | 130 | ||||
-rw-r--r-- | src/analysis/line_prologue.c | 39 | ||||
-rw-r--r-- | src/analysis/roptions.h | 12 |
10 files changed, 530 insertions, 241 deletions
diff --git a/src/analysis/Makefile.am b/src/analysis/Makefile.am index 2a456ff..d7c694b 100755 --- a/src/analysis/Makefile.am +++ b/src/analysis/Makefile.am @@ -4,8 +4,10 @@ noinst_LTLIBRARIES = libanalysis.la libanalysis_la_SOURCES = \ binary.h binary.c \ delayed.h delayed.c \ - line.h line.c \ + exporter-int.h \ + exporter.h exporter.c \ line-int.h \ + line.h line.c \ line_code.h line_code.c \ line_comment.h line_comment.c \ line_prologue.h line_prologue.c \ diff --git a/src/analysis/exporter-int.h b/src/analysis/exporter-int.h new file mode 100644 index 0000000..0c93980 --- /dev/null +++ b/src/analysis/exporter-int.h @@ -0,0 +1,67 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * line-int.h - prototypes pour la traduction humaine des lignes de rendus + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * 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 _ANALYSIS_EXPORTER_INT_H +#define _ANALYSIS_EXPORTER_INT_H + + +#include "exporter.h" + + + +/* Ajoute à un texte GTK le contenu de la ligne de rendu. */ +typedef void (* add_to_gtk_buffer_fc) (GContentExporter *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); + +/* Traduit une instruction en version humainement lisible. */ +typedef void (* add_arch_to_gtk_buffer_fc) (const GContentExporter *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *); + + + +/* Exportation de contenu (instance) */ +struct _GContentExporter +{ + GObject parent; /* A laisser en premier */ + + add_to_gtk_buffer_fc add_to_gtk_buffer; /* Constitution du texte GTK */ + + add_arch_to_gtk_buffer_fc add_arch_to_gtk_buffer; /* Constitution... */ + +}; + + +/* Exportation de contenu (classe) */ +struct _GContentExporterClass +{ + GObjectClass parent; /* A laisser en premier */ + + GtkTextTag *tags[RTT_COUNT]; /* Décorateurs pour les textes */ + +}; + + +/* Ajoute du texte à un texte GTK via l'instance spécifiée. */ +void g_content_exporter_insert_with_gtk_tag(GContentExporter *, GtkTextBuffer *, GtkTextIter *, const char *, size_t, RenderingTagType); + + + +#endif /* _ANALYSIS_EXPORTER_INT_H */ diff --git a/src/analysis/exporter.c b/src/analysis/exporter.c new file mode 100644 index 0000000..dd0f6c0 --- /dev/null +++ b/src/analysis/exporter.c @@ -0,0 +1,253 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * exporter.c - traduction humaine des lignes de rendus + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * 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 "exporter.h" + + +#include "exporter-int.h" + + + +/* Indique le type défini pour une exportation de contenu. */ +G_DEFINE_TYPE(GContentExporter, g_content_exporter, G_TYPE_OBJECT); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des lignes de représentation. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_content_exporter_class_init(GContentExporterClass *klass) +{ + GtkTextTagTable *table; /* Seule table globale valable */ + GtkTextTag *tag; + + /* Décorateurs GTK */ + + table = get_gtk_tag_table(); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "green", NULL); + + klass->tags[RTT_COMMENT] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "gray", NULL); + + klass->tags[RTT_RAW_CODE] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "red", NULL); + + klass->tags[RTT_INSTRUCTION] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "purple", NULL); + + klass->tags[RTT_IMMEDIATE] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "blue", NULL); + + klass->tags[RTT_REGISTER] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "blue", "background", "black", NULL); + + klass->tags[RTT_HOOK] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "white", "background", "black", NULL); + + klass->tags[RTT_SIGNS] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "red", "background", "black", NULL); + + klass->tags[RTT_LTGT] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "black", NULL); + + klass->tags[RTT_SEGMENT] = tag; + gtk_text_tag_table_add(table, tag); + + tag = gtk_text_tag_new(NULL); + + g_object_set(G_OBJECT(tag), "foreground", "orange", NULL); + + klass->tags[RTT_STRING] = tag; + gtk_text_tag_table_add(table, tag); + +} + + +/****************************************************************************** +* * +* Paramètres : exporter = instance à initialiser. * +* * +* Description : Initialise une instance de ligne de représentation. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_content_exporter_init(GContentExporter *exporter) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : table = éventuelle instance à enregistrer. * +* * +* Description : Définit et/ou renvoie le singleton pour les marques de texte.* +* * +* Retour : Table courante à utiliser. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkTextTagTable *_get_gtk_tag_table(GtkTextTagTable *table) +{ + static GtkTextTagTable *result = NULL; /* Table valable à renvoyer */ + + if (table != NULL) + { + if (result != NULL) /* TODO : free() */; + result = table; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : exporter = instance sachant exporter son contenu. * +* buffer = zone de texte à venir compléter. * +* iter = point d'insertion du nouveau texte. [OUT] * +* text = texte à insérer dans l'existant. * +* length = taille du texte à traiter. * +* tag = type de décorateur à utiliser. * +* * +* Description : Ajoute du texte à un texte GTK via l'instance spécifiée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_content_exporter_insert_with_gtk_tag(GContentExporter *exporter, GtkTextBuffer *buffer, GtkTextIter *iter, const char *text, size_t length, RenderingTagType tag) +{ + size_t init; /* Point d'insertion initial */ + + init = gtk_text_iter_get_offset(iter); + + if (tag != RTT_NONE) + gtk_text_buffer_insert_with_tags(buffer, iter, text, length, + G_CONTENT_EXPORTER_GET_CLASS(exporter)->tags[tag], + NULL); + + else gtk_text_buffer_insert_with_tags(buffer, iter, text, length, NULL); + + gtk_text_iter_set_offset(iter, init + length); + +} + + +/****************************************************************************** +* * +* Paramètres : exporter = instance sachant exporter son contenu. * +* rendering = support effectif final des lignes de code. * +* buffer = zone de texte à venir compléter. * +* iter = point d'insertion du nouveau texte. * +* * +* Description : Ajoute à un texte GTK le contenu de l'instance spécifiée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_content_exporter_add_to_gtk_buffer(GContentExporter *exporter, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter) +{ + if (exporter->add_to_gtk_buffer != NULL) + exporter->add_to_gtk_buffer(exporter, rendering, buffer, iter, NULL); + +} + + +/****************************************************************************** +* * +* Paramètres : exporter = instance sachant exporter son contenu. * +* format = format du binaire manipulé. * +* syntax = type de représentation demandée. * +* buffer = zone de texte à venir compléter. * +* iter = point d'insertion du nouveau texte. * +* * +* Description : Ajoute à un texte GTK le contenu d'une architecture. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_content_exporter_add_arch_to_gtk_buffer(const GContentExporter *exporter, const GExeFormat *format, AsmSyntax syntax, GtkTextBuffer *buffer, GtkTextIter *iter) +{ + if (exporter->add_arch_to_gtk_buffer != NULL) + exporter->add_arch_to_gtk_buffer(exporter, format, syntax, buffer, iter); + +} diff --git a/src/analysis/exporter.h b/src/analysis/exporter.h new file mode 100644 index 0000000..6d99463 --- /dev/null +++ b/src/analysis/exporter.h @@ -0,0 +1,92 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * exporter.h - prototypes pour la traduction humaine des lignes de rendus + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * 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 _ANALYSIS_EXPORTER_H +#define _ANALYSIS_EXPORTER_H + + +#include <glib-object.h> +#include <gtk/gtktextbuffer.h> + + +#include "roptions.h" + + +/* Types de partie de rendu */ +typedef enum _RenderingTagType +{ + RTT_COMMENT, /* Commentaire */ + RTT_RAW_CODE, /* Code binaire brut */ + + RTT_INSTRUCTION, /* Code binaire brut */ + + RTT_IMMEDIATE, /* Valeur immédiate */ + + RTT_REGISTER, /* Registre */ + + RTT_HOOK, /* Crochets '[' et ']' */ + RTT_SIGNS, /* Signes '+', '-' et '*' */ + RTT_LTGT, /* Caractères '<' et '>' */ + + RTT_SEGMENT, /* Indication de segment */ + RTT_STRING, /* Chaîne de caractères avec " */ + + RTT_COUNT + +} RenderingTagType; + + +#define RTT_NONE RTT_COUNT + + +#define G_TYPE_CONTENT_EXPORTER g_content_exporter_get_type() +#define G_CONTENT_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_content_exporter_get_type(), GContentExporter)) +#define G_IS_CONTENT_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_content_exporter_get_type())) +#define G_CONTENT_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_CONTENT_EXPORTER, GContentExporterClass)) +#define G_IS_CONTENT_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_CONTENT_EXPORTER)) +#define G_CONTENT_EXPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_CONTENT_EXPORTER, GContentExporterClass)) + + +/* Exportation de contenu (instance) */ +typedef struct _GContentExporter GContentExporter; + +/* Exportation de contenu (classe) */ +typedef struct _GContentExporterClass GContentExporterClass; + + +/* Indique le type défini pour une exportation de contenu. */ +GType g_content_exporter_get_type(void); + +/* Définit et/ou renvoie le singleton pour les marques de texte. */ +GtkTextTagTable *_get_gtk_tag_table(GtkTextTagTable *); + +#define get_gtk_tag_table() _get_gtk_tag_table(NULL) + +/* Ajoute à un texte GTK le contenu de l'instance spécifiée. */ +void g_content_exporter_add_to_gtk_buffer(GContentExporter *, MainRendering, GtkTextBuffer *, GtkTextIter *); + +/* Ajoute à un texte GTK le contenu d'une architecture. */ +void g_content_exporter_add_arch_to_gtk_buffer(const GContentExporter *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *); + + +#endif /* _ANALYSIS_EXPORTER_H */ diff --git a/src/analysis/line-int.h b/src/analysis/line-int.h index 4d181f9..c603837 100644 --- a/src/analysis/line-int.h +++ b/src/analysis/line-int.h @@ -28,6 +28,7 @@ #include "line.h" +#include "exporter-int.h" #include "../common/dllist.h" @@ -35,18 +36,15 @@ /* Méthode de mise à jour du nombre d'octets maximal par instruction. */ typedef void (* get_bin_len_fc) (GRenderingLine *, off_t *); -/* Méthode de mise à jour d'une ligne de représentation. */ -typedef void (* refresh_markup_fc) (GRenderingLine *, MainRendering); - /* Ligne de représentation générique (instance) */ struct _GRenderingLine { - GObject parent; /* A laisser en premier */ + GContentExporter parent; /* A laisser en premier */ DL_LIST_ITEM(link); /* Maillon de liste chaînée */ - uint64_t offset; /* Position en mémoire/physique*/ + vmpa_t offset; /* Position en mémoire/physique*/ off_t length; /* Nombre d'adresses associées */ RenderingLineType type; /* Type de représentation */ @@ -63,8 +61,6 @@ struct _GRenderingLine get_bin_len_fc get_bin_len; /* Nbre d'octets représentés */ off_t max_bin_len[MRD_COUNT]; /* Nombre global maximal */ - refresh_markup_fc refresh_markup; /* Reconstruit la représentat° */ - }; @@ -77,7 +73,7 @@ struct _GRenderingLine /* Ligne de représentation générique (classe) */ struct _GRenderingLineClass { - GObjectClass parent; /* A laisser en premier */ + GContentExporterClass parent; /* A laisser en premier */ GtkStyle *style; /* Style GTK commun aux lignes */ diff --git a/src/analysis/line.c b/src/analysis/line.c index 988de1f..739db2c 100644 --- a/src/analysis/line.c +++ b/src/analysis/line.c @@ -62,7 +62,7 @@ static GdkPixbuf *g_rendering_line_render_icon(const GRenderingLine *, const cha /* Indique le type définit pour une ligne de représentation. */ -G_DEFINE_TYPE(GRenderingLine, g_rendering_line, G_TYPE_OBJECT); +G_DEFINE_TYPE(GRenderingLine, g_rendering_line, G_TYPE_CONTENT_EXPORTER); /****************************************************************************** @@ -106,29 +106,8 @@ static void g_rendering_line_class_init(GRenderingLineClass *klass) static void g_rendering_line_init(GRenderingLine *line) { - GdkScreen *screen; /* Ecran d'application */ - PangoFontDescription *desc; /* Description de la police */ - MainRendering i; /* Boucle de parcours */ - - static PangoContext *context = NULL; /* Contexte graphique Pango */ - DL_LIST_ITEM_INIT(&line->link); - if (context == NULL) - { - screen = gdk_screen_get_default(); - desc = pango_font_description_from_string("mono 10"); - - context = gdk_pango_context_get_for_screen(screen); - pango_context_set_font_description(context, desc); - - } - - for (i = 0; i < MRD_COUNT; i++) - line->layout[i] = pango_layout_new(context); - - line->get_bin_len = NULL; - line->refresh_markup = NULL; } @@ -429,7 +408,7 @@ static GdkPixbuf *g_rendering_line_render_icon(const GRenderingLine *line, const void g_rendering_line_draw(GRenderingLine *line, GdkDrawable *drawable, GdkGC *gc, gint x0, gint x1, gint y, gint h, MainRendering rendering) { GdkPixbuf *pixbuf; /* Données utiles au dessin */ - + return ; gdk_draw_layout(drawable, gc, x1, y, line->layout[rendering]); if (line->to != NULL) @@ -604,7 +583,6 @@ void g_rendering_line_update_bin_len(GRenderingLine *lines, GRenderingLine *last lines_list_for_each(iter, lines) { iter->max_bin_len[rendering] = (bin_len > 0 ? bin_len * 2 + (bin_len - 1) : 0); - iter->refresh_markup(iter, rendering); if (iter == last) break; diff --git a/src/analysis/line_code.c b/src/analysis/line_code.c index 697dd7d..4ceabec 100644 --- a/src/analysis/line_code.c +++ b/src/analysis/line_code.c @@ -61,8 +61,8 @@ static void g_code_line_init(GCodeLine *); /* Met à jour le nombre d'octets maximal par instruction. */ void g_code_line_get_binary_len(GCodeLine *, off_t *); -/* Met à jour la ligne de représentation de code. */ -void g_code_line_refresh_markup(GCodeLine *, MainRendering); +/* Ajoute à un texte GTK le contenu de la ligne de code. */ +static void g_code_line_add_to_gtk_buffer(GCodeLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); @@ -103,14 +103,18 @@ static void g_code_line_class_init(GCodeLineClass *klass) static void g_code_line_init(GCodeLine *line) { - GRenderingLine *parent; /* Instance parente */ + GContentExporter *exporter_parent; /* Instance parente #1 */ + GRenderingLine *line_parent; /* Instance parente #2 */ - parent = G_RENDERING_LINE(line); + exporter_parent = G_CONTENT_EXPORTER(line); - parent->type = RLT_CODE; + exporter_parent->add_to_gtk_buffer = (add_to_gtk_buffer_fc)g_code_line_add_to_gtk_buffer; - parent->get_bin_len = (get_bin_len_fc)g_code_line_get_binary_len; - parent->refresh_markup = (refresh_markup_fc)g_code_line_refresh_markup; + line_parent = G_RENDERING_LINE(line); + + line_parent->type = RLT_CODE; + + line_parent->get_bin_len = (get_bin_len_fc)g_code_line_get_binary_len; } @@ -143,8 +147,11 @@ void g_code_line_get_binary_len(GCodeLine *line, off_t *blen) * * * Paramètres : line = ligne de représentation à actualiser. * * rendering = support effectif final des lignes de code. * +* buffer = zone de texte à venir compléter. * +* iter = point d'insertion du nouveau texte. * +* lengths = taille des différentes composantes de la ligne. * * * -* Description : Met à jour la ligne de représentation de code. * +* Description : Ajoute à un texte GTK le contenu de la ligne de code. * * * * Retour : - * * * @@ -152,68 +159,35 @@ void g_code_line_get_binary_len(GCodeLine *line, off_t *blen) * * ******************************************************************************/ -void g_code_line_refresh_markup(GCodeLine *line, MainRendering rendering) +static void g_code_line_add_to_gtk_buffer(GCodeLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, gint lengths[SAR_COUNT]) { bool show_address; /* Affichage de l'adresse ? */ bool show_code; /* Affichage du code brut ? */ - size_t len; /* Taille du contenu */ - char *content; /* Contenu réellement imprimé */ + 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 buffer[CODE_BUFFER_LEN]; /* Zone tampon à utiliser #1 */ - char *buffer2; /* Zone tampon à utiliser #2 */ - const uint8_t *exe_content; /* Contenu binaire global */ - const off_t *max_bin_len; /* Taille de ligne max/globale */ char *bin_code; /* Tampon du code binaire */ - off_t k; /* Boucle de parcours #2 */ - off_t j; /* Boucle de parcours #1 */ + off_t i; /* Boucle de parcours */ show_address = g_rendering_options_has_to_show_address(line->options, rendering); show_code = g_rendering_options_has_to_show_code(line->options, rendering); - len = strlen("<tt>") + 1; - content = (char *)calloc(len, sizeof(char)); - strcpy(content, "<tt>"); - - if (show_code) - g_arch_instruction_get_location(line->instr, &bin_offset, &bin_len, NULL); - - /* Eventuelle adresse virtuelle */ + /* Eventuelle adresse virtuelle ou physique */ if (show_address) { - switch (g_arch_processor_get_memory_size(g_rendering_options_get_processor(line->options))) - { - case MDS_8_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%02llx</span>", - G_RENDERING_LINE(line)->offset); - break; - - case MDS_16_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%04llx</span>", - G_RENDERING_LINE(line)->offset); - break; - - case MDS_32_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%08llx</span>", - G_RENDERING_LINE(line)->offset); - break; - - default: - case MDS_64_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%16llx</span>", - G_RENDERING_LINE(line)->offset); - break; + msize = g_arch_processor_get_memory_size(g_rendering_options_get_processor(line->options)); - } + len = vmpa_to_string(G_RENDERING_LINE(line)->offset, msize, address); - len += strlen(buffer); - content = (char *)realloc(content, len * sizeof(char)); - strcat(content, buffer); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + address, len, RTT_NONE); + + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + "\t", 1, RTT_NONE); } @@ -221,56 +195,34 @@ void g_code_line_refresh_markup(GCodeLine *line, MainRendering rendering) if (show_code) { - exe_content = g_binary_format_get_content(G_BIN_FORMAT(g_rendering_options_get_format(line->options)), NULL); - max_bin_len = &G_RENDERING_LINE(line)->max_bin_len[rendering]; - - bin_code = (char *)calloc(*max_bin_len + 1, sizeof(char)); + content = g_binary_format_get_content(G_BIN_FORMAT(g_rendering_options_get_format(line->options)), NULL); + g_arch_instruction_get_location(line->instr, &bin_offset, &bin_len, NULL); - k = 0; + bin_code = (char *)calloc(bin_len * 3, sizeof(char)); - for (j = 0; j < bin_len; j++) + for (i = 0; i < bin_len; i++) { - if ((j + 1) < bin_len) - k += snprintf(&bin_code[j * (2 + 1)], 4, "%02hhx ", exe_content[bin_offset + j]); + if ((i + 1) < bin_len) + snprintf(&bin_code[i * (2 + 1)], 4, "%02hhx ", content[bin_offset + i]); else - k += snprintf(&bin_code[j * (2 + 1)], 3, "%02hhx", exe_content[bin_offset + j]); + snprintf(&bin_code[i * (2 + 1)], 3, "%02hhx", content[bin_offset + i]); } - for (; k < *max_bin_len; k++) - snprintf(&bin_code[k], 2, " "); - - if (show_address) len += strlen("\t"); - len += strlen(bin_code); - content = (char *)realloc(content, len * sizeof(char)); - if (show_address) strcat(content, "\t"); - strcat(content, bin_code); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + bin_code, bin_len * 3 - 1, RTT_RAW_CODE); free(bin_code); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + "\t", 1, RTT_NONE); + } /* Instruction proprement dite */ - buffer2 = g_arch_instruction_get_text(line->instr, g_rendering_options_get_format(line->options), ASX_INTEL/*FIXME*/); - - if (show_address || show_code) len += strlen("\t"); - len += strlen(buffer2); - - content = (char *)realloc(content, len * sizeof(char)); - if (show_address || show_code) strcat(content, "\t"); - strcat(content, buffer2); - - free(buffer2); - - /* Finalisation */ - - len += strlen("</tt>"); - content = (char *)realloc(content, len * sizeof(char)); - strcat(content, "</tt>"); - - pango_layout_set_markup(G_RENDERING_LINE(line)->layout[rendering], content, len - 1); - - free(content); + g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(line->instr), + g_rendering_options_get_format(line->options), + ASX_INTEL/*FIXME*/, buffer, iter); } diff --git a/src/analysis/line_comment.c b/src/analysis/line_comment.c index a39cb11..2a3030c 100644 --- a/src/analysis/line_comment.c +++ b/src/analysis/line_comment.c @@ -57,8 +57,8 @@ static void g_comment_line_class_init(GCommentLineClass *); /* Initialise la classe des lignes de commentaires entière. */ static void g_comment_line_init(GCommentLine *); -/* Met à jour la ligne de représentation de commentaires. */ -void g_comment_line_refresh_markup(GCommentLine *, MainRendering); +/* Ajoute à un texte GTK le contenu de la ligne de commentaires. */ +static void g_comment_line_add_to_gtk_buffer(GCommentLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); @@ -99,13 +99,16 @@ static void g_comment_line_class_init(GCommentLineClass *klass) static void g_comment_line_init(GCommentLine *line) { - GRenderingLine *parent; /* Instance parente */ + GContentExporter *exporter_parent; /* Instance parente #1 */ + GRenderingLine *line_parent; /* Instance parente #2 */ - parent = G_RENDERING_LINE(line); + exporter_parent = G_CONTENT_EXPORTER(line); - parent->type = RLT_PROTOTYPE/* TODO */; + exporter_parent->add_to_gtk_buffer = (add_to_gtk_buffer_fc)g_comment_line_add_to_gtk_buffer; - parent->refresh_markup = (refresh_markup_fc)g_comment_line_refresh_markup; + line_parent = G_RENDERING_LINE(line); + + line_parent->type = RLT_PROTOTYPE/* TODO */; } @@ -114,8 +117,11 @@ static void g_comment_line_init(GCommentLine *line) * * * Paramètres : line = ligne de représentation à actualiser. * * rendering = support effectif final des lignes de code. * +* buffer = zone de texte à venir compléter. * +* iter = point d'insertion du nouveau texte. * +* lengths = taille des différentes composantes de la ligne. * * * -* Description : Met à jour la ligne de représentation de commentaires. * +* Description : Ajoute à un texte GTK le contenu de la ligne de commentaires.* * * * Retour : - * * * @@ -123,116 +129,48 @@ static void g_comment_line_init(GCommentLine *line) * * ******************************************************************************/ -void g_comment_line_refresh_markup(GCommentLine *line, MainRendering rendering) +static void g_comment_line_add_to_gtk_buffer(GCommentLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, gint lengths[SAR_COUNT]) { bool show_address; /* Affichage de l'adresse ? */ bool show_code; /* Affichage du code brut ? */ - size_t len; /* Taille du contenu */ - char *content; /* Contenu réellement imprimé */ - char buffer[CODE_BUFFER_LEN]; /* Zone tampon à utiliser */ - const off_t *max_bin_len; /* Taille de ligne max/globale */ - size_t clen; /* Taille du commentaire */ + 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é */ show_address = g_rendering_options_has_to_show_address(line->options, rendering); show_code = g_rendering_options_has_to_show_code(line->options, rendering); - len = strlen("<tt>") + 1; - content = (char *)calloc(len, sizeof(char)); - strcpy(content, "<tt>"); - - /* Eventuelle adresse virtuelle */ + /* Eventuelle adresse virtuelle ou physique */ if (show_address) { - switch (g_arch_processor_get_memory_size(g_rendering_options_get_processor(line->options))) - { - case MDS_8_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%02llx</span>", - G_RENDERING_LINE(line)->offset); - break; - - case MDS_16_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%04llx</span>", - G_RENDERING_LINE(line)->offset); - break; - - case MDS_32_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%08llx</span>", - G_RENDERING_LINE(line)->offset); - break; - - default: - case MDS_64_BITS: - snprintf(buffer, CODE_BUFFER_LEN, - "<span foreground='#333333'>0x%16llx</span>", - G_RENDERING_LINE(line)->offset); - break; - - } - - len += strlen(buffer); - content = (char *)realloc(content, len * sizeof(char)); - strcat(content, buffer); - - } - - /* Eventuel code brut (sauté) */ - - if (show_code) - { - max_bin_len = &G_RENDERING_LINE(line)->max_bin_len[rendering]; - - clen = (show_address ? strlen("\t") : 0); - clen += *max_bin_len; - - content = (char *)realloc(content, (len + clen) * sizeof(char)); + msize = g_arch_processor_get_memory_size(g_rendering_options_get_processor(line->options)); - if (show_address) - { - strcat(content, "\t"); - len += strlen("\t"); - } + len = vmpa_to_string(G_RENDERING_LINE(line)->offset, msize, address); - memset(&content[len - 1], - G_RENDERING_LINE(line)->type == RLT_PROTOTYPE ? '-' : ' ', *max_bin_len); - len += *max_bin_len; + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + address, len, RTT_NONE); - content[len - 1] = '\0'; + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + "\t", 1, RTT_NONE); } - /* Commentaire proprement dit */ - - clen = (show_address || show_code ? strlen("\t") : 0); - clen += strlen("<b><span foreground='#003300'>"); - clen += strlen("; ") + strlen(line->comment); - clen += strlen("</span></b>"); - - content = (char *)realloc(content, (len + clen) * sizeof(char)); - - if (show_address || show_code) - { - strcat(content, "\t"); - len += strlen("\t"); - clen -= strlen("\t"); - } - - snprintf(&content[len - 1], clen + 1, "<b><span foreground='#003300'>; %s</span></b>", line->comment); + /* Eventuel code brut (sauté) */ - len += clen; + if (show_code) + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + "\t", 1, RTT_NONE); - /* Finalisation */ + /* Commentaire proprement dit */ - len += strlen("</tt>"); - content = (char *)realloc(content, len * sizeof(char)); - strcat(content, "</tt>"); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + "; ", 2, RTT_COMMENT); - pango_layout_set_markup(G_RENDERING_LINE(line)->layout[rendering], content, len - 1); + len = strlen(line->comment); - free(content); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + line->comment, len, RTT_COMMENT); } diff --git a/src/analysis/line_prologue.c b/src/analysis/line_prologue.c index 4b83b68..13f0c1e 100644 --- a/src/analysis/line_prologue.c +++ b/src/analysis/line_prologue.c @@ -56,8 +56,8 @@ static void g_prologue_line_class_init(GPrologueLineClass *); /* Initialise la classe des lignes de descriptions initiales. */ static void g_prologue_line_init(GPrologueLine *); -/* Met à jour la ligne de représentation de prologue. */ -void g_prologue_line_refresh_markup(GPrologueLine *, MainRendering); +/* Ajoute à un texte GTK le contenu de la ligne d'ouverture. */ +static void g_prologue_line_add_to_gtk_buffer(GPrologueLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); @@ -98,15 +98,16 @@ static void g_prologue_line_class_init(GPrologueLineClass *klass) static void g_prologue_line_init(GPrologueLine *line) { - GRenderingLine *parent; /* Instance parente */ + GContentExporter *exporter_parent; /* Instance parente #1 */ + GRenderingLine *line_parent; /* Instance parente #2 */ - parent = G_RENDERING_LINE(line); + exporter_parent = G_CONTENT_EXPORTER(line); - parent->offset = 0; + exporter_parent->add_to_gtk_buffer = (add_to_gtk_buffer_fc)g_prologue_line_add_to_gtk_buffer; - parent->type = RLT_PROLOGUE; + line_parent = G_RENDERING_LINE(line); - parent->refresh_markup = (refresh_markup_fc)g_prologue_line_refresh_markup; + line_parent->type = RLT_PROLOGUE; } @@ -115,8 +116,11 @@ static void g_prologue_line_init(GPrologueLine *line) * * * Paramètres : line = ligne de représentation à actualiser. * * rendering = support effectif final des lignes de code. * +* buffer = zone de texte à venir compléter. * +* iter = point d'insertion du nouveau texte. * +* lengths = taille des différentes composantes de la ligne. * * * -* Description : Met à jour la ligne de représentation de prologue. * +* Description : Ajoute à un texte GTK le contenu de la ligne d'ouverture. * * * * Retour : - * * * @@ -124,22 +128,17 @@ static void g_prologue_line_init(GPrologueLine *line) * * ******************************************************************************/ -void g_prologue_line_refresh_markup(GPrologueLine *line, MainRendering rendering) +static void g_prologue_line_add_to_gtk_buffer(GPrologueLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, gint lengths[SAR_COUNT]) { - size_t len; /* Taille du contenu */ - char *content; /* Contenu réellement imprimé */ + size_t len; /* Taille de l'élément inséré */ - len = strlen("<b><span foreground='#003300'>"); - len += strlen("; ") + strlen(line->comment); - len += strlen("</span></b>"); + len = strlen(line->comment); - content = (char *)calloc(len + 1, sizeof(char)); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + "; ", 2, RTT_COMMENT); - snprintf(content, len + 1, "<b><span foreground='#003300'>; %s</span></b>", line->comment); - - pango_layout_set_markup(G_RENDERING_LINE(line)->layout[rendering], content, len); - - free(content); + g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, + line->comment, len, RTT_COMMENT); } diff --git a/src/analysis/roptions.h b/src/analysis/roptions.h index 85dc5fb..b2e4973 100644 --- a/src/analysis/roptions.h +++ b/src/analysis/roptions.h @@ -45,6 +45,18 @@ typedef enum _MainRendering } MainRendering; +/* Zone de rendu */ +typedef enum _ShowingArea +{ + SAR_ADDRESS, /* Adresse d'une ligne */ + SAR_CODE, /* Code brut d'une ligne */ + SAR_INSTRUCTION, /* Instruction d'une ligne */ + + SAR_COUNT + +} ShowingArea; + + #define G_TYPE_RENDERING_OPTIONS g_rendering_options_get_type() #define G_RENDERING_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_rendering_options_get_type(), GRenderingOptions)) #define G_IS_RENDERING_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_rendering_options_get_type())) |