summaryrefslogtreecommitdiff
path: root/src/gtkext/gtkblockview.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-06-14 11:57:14 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-06-14 11:57:14 (GMT)
commitae0135d727fdc67a268ede1530042a42a2a1ccd3 (patch)
treed3dc13797072c261ea8bb49dc2e83b0858478bc7 /src/gtkext/gtkblockview.c
parentfa0509e2914e3cb562a7cc58293f1171886fafb0 (diff)
Cleaned and improved the binary views ; implemented some first steps for the graphical view.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@76 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/gtkext/gtkblockview.c')
-rw-r--r--src/gtkext/gtkblockview.c338
1 files changed, 72 insertions, 266 deletions
diff --git a/src/gtkext/gtkblockview.c b/src/gtkext/gtkblockview.c
index dc889f9..648421d 100644
--- a/src/gtkext/gtkblockview.c
+++ b/src/gtkext/gtkblockview.c
@@ -33,8 +33,6 @@
-#define CONTENT_BUFFER_LEN 64
-
#define MARGIN_SPACE 4
@@ -52,8 +50,6 @@ struct _GtkBlockView
const exe_format *format; /* Format du contenu bianire */
- GRenderingLine *lines; /* Contenu à représenter */
-
};
struct _GtkBlockViewClass
@@ -64,6 +60,13 @@ struct _GtkBlockViewClass
+/* Procède à l'initialisation de l'afficheur d'un bloc binaire. */
+static void gtk_block_view_init(GtkBlockView *);
+
+
+/* Définit les lignes du bloc de représentation. */
+static void gtk_block_view_set_rendering_lines(GtkBlockView *, GRenderingLine *, GRenderingLine *);
+
@@ -82,6 +85,9 @@ void gtk_block_view_recompute_size_request(GtkBlockView *);
+/* Indique la position d'affichage d'une adresse donnée. */
+static bool gtk_block_view_get_address_coordinates(GtkBlockView *, vmpa_t, gint *, gint *);
+
@@ -120,8 +126,8 @@ GtkWidget * gtk_block_view_new(void)
}
-static void
-gtk_block_view_class_init(GtkBlockViewClass *klass)
+
+static void gtk_block_view_class_init(GtkBlockViewClass *klass)
{
GtkWidgetClass *widget_class;
GtkObjectClass *object_class;
@@ -141,13 +147,31 @@ gtk_block_view_class_init(GtkBlockViewClass *klass)
}
-static void
-gtk_block_view_init(GtkBlockView *view)
+/******************************************************************************
+* *
+* Paramètres : view = composant GTK à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'afficheur d'un bloc binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void gtk_block_view_init(GtkBlockView *view)
{
+ GtkBinView *binview; /* Instance parente */
+
+ binview = GTK_BIN_VIEW(view);
+
+ binview->set_lines = (set_rendering_lines_fc)gtk_block_view_set_rendering_lines;
+ binview->get_coordinates = (get_addr_coordinates_fc)gtk_block_view_get_address_coordinates;
}
+
static void
gtk_block_view_size_request(GtkWidget *widget,
GtkRequisition *requisition)
@@ -221,8 +245,6 @@ gtk_block_view_realize(GtkWidget *widget)
GTK_BLOCK_VIEW(widget)->layout = gtk_widget_create_pango_layout(widget, NULL);
GTK_BLOCK_VIEW(widget)->gc = gdk_gc_new(GDK_DRAWABLE(widget->window));
- gtk_block_view_build_content(GTK_BLOCK_VIEW(widget));
-
}
@@ -238,7 +260,7 @@ static gboolean gtk_block_view_button_press(GtkWidget *widget, GdkEventButton *e
view = GTK_BLOCK_VIEW(widget);
y = event->y;
- line = g_rendering_line_find_by_y(view->lines, &y);
+ line = g_rendering_line_find_by_y(GTK_BIN_VIEW(view)->lines, GTK_BIN_VIEW(view)->last, &y);
if (line != NULL)
{
@@ -335,14 +357,8 @@ gtk_block_view_paint(GtkBlockView *view)
GdkColor white; /* Couleur du fond */
int width; /* Largeur de l'élément */
int height; /* Hauteur de l'élément */
- GdkColor red; /* Couleur des arrêts */
- PangoLayoutIter *iter; /* Boucle de parcours */
- unsigned int index; /* Indice de la ligne visée */
- int y0; /* Ordonnée du haut d'une ligne*/
- int y1; /* Ordonnée du bas d'une ligne */
-
- GRenderingLine *liter;
-
+ int y; /* Ordonnée du haut d'une ligne*/
+ GRenderingLine *iter; /* Boucle de parcours */
widget = GTK_WIDGET(view);
gdk_gc_get_values(view->gc, &values);
@@ -355,53 +371,26 @@ gtk_block_view_paint(GtkBlockView *view)
gdk_draw_rectangle(GDK_DRAWABLE(widget->window), GTK_BLOCK_VIEW(widget)->gc,
TRUE, 0, 0, width, height);
- gdk_color_parse("#ff0000", &red);
- gdk_color_alloc(gtk_widget_get_colormap(widget), &red);
- gdk_gc_set_foreground(view->gc, &red);
-
-
- index = 0;
- iter = pango_layout_get_iter(view->layout);
-
-#if 0
- for (; index < view->info_count; index++, pango_layout_iter_next_line(iter))
- {
- if (!view->info[index].bp_set) continue;
-
- pango_layout_iter_get_line_yrange(iter, &y0, &y1);
-
-
-
- gdk_draw_arc(GDK_DRAWABLE(widget->window), GTK_BLOCK_VIEW(widget)->gc,
- FALSE, MARGIN_SPACE, y0 / PANGO_SCALE,
- view->line_height - 2, view->line_height - 2,
- 0, 360 * 64);
-
- }
-#endif
-
- pango_layout_iter_free(iter);
-
gdk_gc_set_foreground(view->gc, &values.foreground);
gdk_draw_layout(GDK_DRAWABLE(widget->window), view->gc,
2 * MARGIN_SPACE + view->line_height, 0,
view->layout);
+ y = 0;
- y0 = 0;
-
- for (/* l! */liter = view->lines; liter != NULL; liter = g_rendering_line_get_next_iter(view->lines, liter))
+ for (iter = GTK_BIN_VIEW(view)->lines;
+ iter != NULL;
+ iter = g_rendering_line_get_next_iter(GTK_BIN_VIEW(view)->lines, iter, GTK_BIN_VIEW(view)->last))
{
- g_rendering_line_draw(liter, GDK_DRAWABLE(widget->window), view->gc,
+ g_rendering_line_draw(iter, GDK_DRAWABLE(widget->window), view->gc,
MARGIN_SPACE, 2 * MARGIN_SPACE + view->line_height,
- y0, view->line_height);
+ y, view->line_height);
- y0 += view->line_height;
+ y += view->line_height;
}
-
}
@@ -445,7 +434,7 @@ void gtk_block_view_show_vaddress(GtkBlockView *view, gboolean show)
{
view->show_vaddress = show;
- gtk_block_view_build_content(view);
+ //gtk_block_view_build_content(view);
}
@@ -467,7 +456,7 @@ void gtk_block_view_show_code(GtkBlockView *view, gboolean show)
{
view->show_code = show;
- gtk_block_view_build_content(view);
+ //gtk_block_view_build_content(view);
}
@@ -499,6 +488,7 @@ void gtk_block_view_set_format(GtkBlockView *view, const exe_format *format)
* *
* Paramètres : view = composant GTK à mettre à jour. *
* lines = informations à intégrer. *
+* last = dernière ligne à intégrer ou NULL pour toutes. *
* *
* Description : Définit les lignes du bloc de représentation. *
* *
@@ -508,17 +498,19 @@ void gtk_block_view_set_format(GtkBlockView *view, const exe_format *format)
* *
******************************************************************************/
-void gtk_block_view_set_rendering_lines(GtkBlockView *view, GRenderingLine *lines)
+static void gtk_block_view_set_rendering_lines(GtkBlockView *view, GRenderingLine *lines, GRenderingLine *last)
{
GRenderingLine *iter; /* Boucle de parcours */
- view->lines = lines;
-
- for (iter = lines; iter != NULL; iter = g_rendering_line_get_next_iter(lines, iter))
+ for (iter = GTK_BIN_VIEW(view)->lines;
+ iter != NULL;
+ iter = g_rendering_line_get_next_iter(GTK_BIN_VIEW(view)->lines, iter, GTK_BIN_VIEW(view)->last))
+ {
g_signal_connect(iter, "rendering-line-flags-changed",
G_CALLBACK(gtk_block_view_update_margin), view);
+ }
- g_rendering_line_update_bin_len(lines);
+ g_rendering_line_update_bin_len(GTK_BIN_VIEW(view)->lines, GTK_BIN_VIEW(view)->last);
gtk_block_view_recompute_size_request(view);
@@ -545,7 +537,8 @@ void gtk_block_view_recompute_size_request(GtkBlockView *view)
int width; /* Largeur de l'objet actuelle */
int height; /* Hauteur de l'objet actuelle */
- g_rendering_line_get_size(view->lines, &width, &height, &view->line_height);
+ g_rendering_line_get_size(GTK_BIN_VIEW(view)->lines, GTK_BIN_VIEW(view)->last,
+ &width, &height, &view->line_height);
gtk_widget_set_size_request(GTK_WIDGET(view),
width + 2 * MARGIN_SPACE + view->line_height,
@@ -560,226 +553,39 @@ void gtk_block_view_recompute_size_request(GtkBlockView *view)
-
-
/******************************************************************************
* *
-* Paramètres : view = composant GTK à mettre à jour. *
+* Paramètres : view = composant GTK à consulter. *
+* addr = adresse à présenter à l'écran. *
+* x = position horizontale au sein du composant. [OUT] *
+* y = position verticale au sein du composant. [OUT] *
* *
-* Description : Définit le contenu visuel à partir des infos enregistrées. *
+* Description : Indique la position d'affichage d'une adresse donnée. *
* *
-* Retour : - *
+* Retour : TRUE si l'adresse fait partie du composant, FALSE sinon. *
* *
* Remarques : - *
* *
******************************************************************************/
-void gtk_block_view_build_content(GtkBlockView *view)
+static bool gtk_block_view_get_address_coordinates(GtkBlockView *view, vmpa_t addr, gint *x, gint *y)
{
-#if 0
- const uint8_t *exe_content; /* Contenu binaire global */
- off_t max_bin_len; /* Taille max du code brut */
- unsigned int i; /* Boucle de traitement */
- off_t bin_len; /* Taille d'instruction */
- char *bin_code; /* Tampon du code binaire */
- char *content; /* Contenu à définir */
- size_t content_len; /* Taille du contenu */
- AdressMode mode; /* Affichage des adresses */
- char buffer[CONTENT_BUFFER_LEN]; /* Zone tampon à utiliser */
- off_t bin_offset; /* Début de l'instruction */
- off_t k; /* Boucle de parcours #2 */
- off_t j; /* Boucle de parcours #1 */
- int width; /* Largeur de l'objet actuelle */
- int height; /* Hauteur de l'objet actuelle */
- PangoLayoutIter *iter; /* Boucle de parcours */
- int y0; /* Ordonnée du haut d'une ligne*/
- int y1; /* Ordonnée du bas d'une ligne */
-
- /* Calcul de la largeur maximale brute si besoin est */
- if (view->show_code)
- {
- exe_content = get_exe_content(view->format, NULL);
-
- max_bin_len = 1;
-
- for (i = 0; i < view->info_count; i++)
- {
- /* Commentaire uniquement */
- if (view->info[i].instr == NULL) continue;
-
- get_asm_instr_offset_and_length(view->info[i].instr, NULL, &bin_len);
- if (bin_len > max_bin_len) max_bin_len = bin_len;
-
- }
-
- max_bin_len = max_bin_len * 2 + (max_bin_len - 1);
- bin_code = (char *)calloc(max_bin_len + 1, sizeof(char));
-
- }
-
- content_len = strlen("<tt>") + 1;
- content = (char *)calloc(content_len, sizeof(char));
- strcpy(content, "<tt>");
-
- mode = ADM_32BITS; /* FIXME */
-
- for (i = 0; i < view->info_count; i++)
- {
- if (i > 0)
- {
- content = (char *)realloc(content, ++content_len * sizeof(char));
- strcat(content, "\n");
- }
-
- /* Eventuelle adresse virtuelle */
-
- if (view->show_vaddress)
- {
- switch (mode)
- {
- case ADM_32BITS:
- snprintf(buffer, CONTENT_BUFFER_LEN,
- "<span foreground='#333333'>0x%08llx</span>",
- view->info[i].offset);
- break;
-
- case ADM_64BITS:
- snprintf(buffer, CONTENT_BUFFER_LEN,
- "<span foreground='#333333'>0x%16llx</span>",
- view->info[i].offset);
- break;
-
- }
-
- content_len += strlen(buffer);
- content = (char *)realloc(content, content_len * sizeof(char));
- strcat(content, buffer);
-
- }
-
- /* Eventuel code brut */
-
- if (view->show_code)
- {
- k = 0;
-
- if (view->info[i].instr != NULL)
- {
- get_asm_instr_offset_and_length(view->info[i].instr, &bin_offset, &bin_len);
-
- for (j = 0; j < bin_len; j++)
- {
- if ((j + 1) < bin_len)
- k += snprintf(&bin_code[j * (2 + 1)], 4, "%02hhx ", exe_content[bin_offset + j]);
- else
- k += snprintf(&bin_code[j * (2 + 1)], 3, "%02hhx", exe_content[bin_offset + j]);
- }
-
- }
-
- for (; k < max_bin_len; k++)
- snprintf(&bin_code[k], 2, " ");
-
- if (view->show_vaddress) content_len += strlen("\t");
- content_len += strlen(bin_code);
- content = (char *)realloc(content, content_len * sizeof(char));
- if (view->show_vaddress) strcat(content, "\t");
- strcat(content, bin_code);
-
- }
-
- /* Eventuelle instruction */
-
- if (view->info[i].instr != NULL)
- {
- print_hinstruction(view->proc, view->format, view->info[i].instr, buffer, CONTENT_BUFFER_LEN, ASX_INTEL);
-
- if (view->show_vaddress || view->show_code) content_len += strlen("\t");
- content_len += strlen(buffer);
-
- content = (char *)realloc(content, content_len * sizeof(char));
- if (view->show_vaddress || view->show_code) strcat(content, "\t");
- strcat(content, buffer);
-
- }
-
- /* Eventuel commantaire */
-
- if (view->info[i].comment != NULL)
- {
- if (view->show_vaddress || view->show_code) content_len += strlen("\t");
- content_len += strlen("<b><span foreground='#003300'>; ") + strlen(view->info[i].comment) + strlen("</span></b>");
-
- content = (char *)realloc(content, content_len * sizeof(char));
- if (view->show_vaddress || view->show_code) strcat(content, "\t");
- strcat(content, "<b><span foreground='#003300'>; ");
- strcat(content, view->info[i].comment);
- strcat(content, "</span></b>");
-
- }
-
- }
-
- content_len += strlen("</tt>");
- content = (char *)realloc(content, content_len * sizeof(char));
- strcat(content, "</tt>");
-
- if (view->show_code) free(bin_code);
-
- pango_layout_set_markup(view->layout, content, content_len - 1);
+ bool result; /* Bilan à retourner */
+ GRenderingLine *iter; /* Boucle de parcours */
- pango_layout_get_pixel_size(view->layout, &width, &height);
+ result = false;
- view->line_height = 0;
- iter = pango_layout_get_iter(view->layout);
+ *x = 0;
+ *y = 0;
- do
+ for (iter = GTK_BIN_VIEW(view)->lines;
+ iter != NULL && !result;
+ iter = g_rendering_line_get_next_iter(GTK_BIN_VIEW(view)->lines, iter, GTK_BIN_VIEW(view)->last))
{
- pango_layout_iter_get_line_yrange(iter, &y0, &y1);
- view->line_height = MAX(view->line_height, (y1 - y0) / PANGO_SCALE);
+ if (get_rendering_line_address(iter) == addr) result = true;
+ else *y += view->line_height;
}
- while (pango_layout_iter_next_line(iter));
-
- pango_layout_iter_free(iter);
-
- //gtk_widget_set_size_request(GTK_WIDGET(block_view), width + 2 * MARGIN_SPACE + view->line_height, height);
-#endif
-}
-
-
-
-
-
-
-
-
-/******************************************************************************
-* *
-* Paramètres : view = composant GTK à consulter. *
-* address = adresse à présenter à l'écran. *
-* position = position verticale au sein du composant. [OUT] *
-* *
-* Description : Indique la position verticale d'une adresse donnée. *
-* *
-* Retour : TRUE si l'adresse fait partie du composant, FALSE sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-gboolean gtk_block_view_get_address_vposition(GtkBlockView *view, uint64_t address, gint *position)
-{
- unsigned int i; /* Boucle de parcours */
- *position = 0;
-#if 0
- for (i = 0; i < view->info_count; i++)
- {
- if (view->info[i].offset == address) break;
- else *position += view->line_height;
- }
-#endif
- return false;//(i < view->info_count);
+ return result;
}
-