From af083f8bd6da340214ae392451dde5782fb79039 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 16 Sep 2014 20:08:57 +0000 Subject: Used the new vmpa_t type in binary portions. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@405 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 22 ++++++++++++++++++++ src/format/elf/elf.c | 15 ++++++-------- src/format/executable.c | 6 +++++- src/glibext/gbinportion.c | 47 ++++++++++++++++++++----------------------- src/glibext/gbinportion.h | 10 ++++----- src/gtkext/gtkbinarystrip.c | 38 ++++++++++++++++++++++++++-------- src/gtkext/gtkbinarystrip.h | 3 +++ src/gtkext/gtkbufferview.c | 2 +- src/gtkext/gtkviewpanel-int.h | 2 +- src/gtkext/gtkviewpanel.c | 4 ++-- src/gui/tb/portions.c | 10 ++++++--- 11 files changed, 104 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c463d4..582044a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +14-09-16 Cyrille Bagard + + * src/format/elf/elf.c: + * src/format/executable.c: + Update code. + + * src/glibext/gbinportion.c: + * src/glibext/gbinportion.h: + Use the new vmpa_t type in binary portions. + + * src/gtkext/gtkbinarystrip.c: + * src/gtkext/gtkbinarystrip.h: + Update code. + + * src/gtkext/gtkbufferview.c: + * src/gtkext/gtkviewpanel.c: + * src/gtkext/gtkviewpanel-int.h: + Clean and update code. + + * src/gui/tb/portions.c: + Update code. + 14-09-15 Cyrille Bagard * configure.ac: diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c index 4a56c52..64708ee 100644 --- a/src/format/elf/elf.c +++ b/src/format/elf/elf.c @@ -318,6 +318,7 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion * const char *background; /* Fond signigicatif */ GBinPortion *new; /* Nouvelle portion définie */ char desc[MAX_PORTION_DESC]; /* Description d'une portion */ + vmpa2t addr; /* Emplacement dans le binaire */ PortionAccessRights rights; /* Droits d'une portion */ elf_shdr strings; /* Section des descriptions */ bool has_strings; /* Section trouvée ? */ @@ -350,10 +351,8 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion * g_binary_portion_set_desc(new, desc); - g_binary_portion_set_values(new, - ELF_PHDR(format, phdr, p_offset), - ELF_PHDR(format, phdr, p_filesz), - ELF_PHDR(format, phdr, p_vaddr)); + init_vmpa(&addr, ELF_PHDR(format, phdr, p_offset), ELF_PHDR(format, phdr, p_vaddr)); + g_binary_portion_set_values(new, &addr, ELF_PHDR(format, phdr, p_filesz)); rights = PAC_NONE; if (p_flags & PF_R) rights |= PAC_READ; @@ -398,6 +397,9 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion * g_binary_portion_set_desc(new, desc); + init_vmpa(&addr, ELF_SHDR(format, section, sh_offset), ELF_SHDR(format, section, sh_addr)); + g_binary_portion_set_values(new, &addr, ELF_SHDR(format, section, sh_size)); + rights = PAC_NONE; if (sh_flags & SHF_ALLOC) rights |= PAC_READ; if (sh_flags & SHF_WRITE) rights |= PAC_WRITE; @@ -405,11 +407,6 @@ static void g_elf_format_refine_portions(const GElfFormat *format, GBinPortion * g_binary_portion_set_rights(new, rights); - g_binary_portion_set_values(new, - ELF_SHDR(format, section, sh_offset), - ELF_SHDR(format, section, sh_size), - ELF_SHDR(format, section, sh_addr)); - g_binary_portion_include(raw, new); } diff --git a/src/format/executable.c b/src/format/executable.c index f4c8739..6b39ac8 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -138,10 +138,14 @@ vmpa_t g_exe_format_get_entry_point(const GExeFormat *format) GBinPortion *g_exe_format_get_portions(GExeFormat *format) { + vmpa2t addr; /* Emplacement vide de sens */ + if (format->portions == NULL) { format->portions = g_binary_portion_new(BPC_RAW); - g_binary_portion_set_values(format->portions, 0, G_BIN_FORMAT(format)->length, 0); + + init_vmpa(&addr, 0, VMPA_NO_VIRTUAL); + g_binary_portion_set_values(format->portions, &addr, G_BIN_FORMAT(format)->length); if (format->refine_portions != NULL) format->refine_portions(format, format->portions); diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c index 41778ba..76926ca 100644 --- a/src/glibext/gbinportion.c +++ b/src/glibext/gbinportion.c @@ -50,9 +50,8 @@ struct _GBinPortion char *desc; /* Désignation humaine */ - off_t offset; /* Position physique */ + vmpa2t addr; /* Emplacement dans le code */ off_t size; /* Taille de la partie */ - vmpa_t addr; /* Adresse associée */ PortionAccessRights rights; /* Droits d'accès */ @@ -263,9 +262,8 @@ const char *g_binary_portion_get_desc(const GBinPortion *portion) /****************************************************************************** * * * Paramètres : portion = description de partie à mettre à jour. * -* offset = position de la section à conserver. * +* addr = emplacement de la section à conserver. * * size = taille de la section à conserver. * -* addr = adresse de la section à conserver. * * * * Description : Définit les valeurs utiles d'une partie de code. * * * @@ -275,11 +273,10 @@ const char *g_binary_portion_get_desc(const GBinPortion *portion) * * ******************************************************************************/ -void g_binary_portion_set_values(GBinPortion *portion, off_t offset, off_t size, vmpa_t addr) +void g_binary_portion_set_values(GBinPortion *portion, const vmpa2t *addr, off_t size) { - portion->offset = offset; + copy_vmpa(&portion->addr, addr); portion->size = size; - portion->addr = addr; } @@ -369,7 +366,7 @@ static bool g_binary_portion_compute_sub_area(GBinPortion *portion, GBinPortion sub_area->y = area->y; sub_area->height = area->height; - sub_area->x = area->x + (sub->offset * area->width) / portion->size; + sub_area->x = area->x + (get_phy_addr(&sub->addr) * area->width) / portion->size; sub_area->width = (sub->size * area->width) / portion->size; return true; @@ -438,7 +435,7 @@ GBinPortion *g_binary_portion_find_at_pos(GBinPortion *portion, gint x, GdkRecta * * ******************************************************************************/ -GBinPortion *g_binary_portion_find_at_addr(GBinPortion *portion, vmpa_t addr, GdkRectangle *area) +GBinPortion *g_binary_portion_find_at_addr(GBinPortion *portion, const vmpa2t *addr, GdkRectangle *area) { GBinPortion *result; /* Portion à retourner */ size_t i; /* Boucle de parcours #1 */ @@ -452,11 +449,14 @@ GBinPortion *g_binary_portion_find_at_addr(GBinPortion *portion, vmpa_t addr, Gd { sub = portion->sub_portions[i]; + /* FIXME : cmp ? */ + /* Portion non allouée en mémoire -> adresse nulle ; on écarte */ - if (sub->addr == 0) + if (get_virt_addr(&sub->addr) == 0) continue; - if (addr < sub->addr || addr >= (sub->addr + sub->size)) + if (get_virt_addr(addr) < get_virt_addr(&sub->addr) + || get_virt_addr(addr) >= (get_virt_addr(&sub->addr) + sub->size)) continue; if (!g_binary_portion_compute_sub_area(portion, sub, area, &sub_area)) @@ -496,7 +496,7 @@ GBinPortion *g_binary_portion_find_at_addr(GBinPortion *portion, vmpa_t addr, Gd * * ******************************************************************************/ -bool g_binary_portion_get_addr_from_pos(GBinPortion *portion, gint x, const GdkRectangle *area, vmpa_t *addr) +bool g_binary_portion_get_addr_from_pos(GBinPortion *portion, gint x, const GdkRectangle *area, vmpa2t *addr) { GdkRectangle owner_area; /* Aire de contenance */ GBinPortion *owner; /* Conteneur propriétaire */ @@ -506,7 +506,9 @@ bool g_binary_portion_get_addr_from_pos(GBinPortion *portion, gint x, const GdkR owner = g_binary_portion_find_at_pos(portion, x, &owner_area); if (owner == NULL) return false; - *addr = owner->addr + (owner->size * (x - owner_area.x)) / owner_area.width; + copy_vmpa(addr, &owner->addr); + + advance_vmpa(addr, (owner->size * (x - owner_area.x)) / owner_area.width); return true; @@ -528,18 +530,18 @@ bool g_binary_portion_get_addr_from_pos(GBinPortion *portion, gint x, const GdkR * * ******************************************************************************/ -bool g_binary_portion_get_pos_from_addr(GBinPortion *portion, vmpa_t addr, const GdkRectangle *area, gint *x) +bool g_binary_portion_get_pos_from_addr(GBinPortion *portion, const vmpa2t *addr, const GdkRectangle *area, gint *x) { GdkRectangle owner_area; /* Aire de contenance */ GBinPortion *owner; /* Conteneur propriétaire */ - vmpa_t diff; /* Décallage à appliquer */ + off_t diff; /* Décallage à appliquer */ owner_area = *area; owner = g_binary_portion_find_at_addr(portion, addr, &owner_area); if (owner == NULL) return false; - diff = addr - owner->addr; + diff = compute_vmpa_diff(addr, &owner->addr); *x = owner_area.x + (diff * owner_area.width) / owner->size; @@ -605,19 +607,21 @@ gboolean g_binary_portion_query_tooltip(GBinPortion *portion, gint x, gint y, co markup = stradd(markup, "\n"); markup = stradd(markup, _("physical: from ")); - snprintf(value, 2 * VMPA_MAX_SIZE, OFF_FMT, OFF_CAST(selected->offset)); + snprintf(value, 2 * VMPA_MAX_SIZE, OFF_FMT, OFF_CAST(get_phy_addr(&selected->addr))); markup = stradd(markup, value); markup = stradd(markup, _(" to ")); - snprintf(value, 2 * VMPA_MAX_SIZE, OFF_FMT, OFF_CAST(selected->offset + selected->size)); + snprintf(value, 2 * VMPA_MAX_SIZE, OFF_FMT, OFF_CAST(get_phy_addr(&selected->addr) + selected->size)); markup = stradd(markup, value); markup = stradd(markup, "\n"); markup = stradd(markup, _("memory: from ")); +#if 0 snprintf(value, 2 * VMPA_MAX_SIZE, VMPA_FMT_LONG, VMPA_CAST(selected->addr)); markup = stradd(markup, value); markup = stradd(markup, _(" to ")); snprintf(value, 2 * VMPA_MAX_SIZE, VMPA_FMT_LONG, VMPA_CAST(selected->addr + selected->size)); markup = stradd(markup, value); +#endif markup = stradd(markup, "\n\n"); /* Droits d'accès */ @@ -643,13 +647,6 @@ gboolean g_binary_portion_query_tooltip(GBinPortion *portion, gint x, gint y, co } - - -extern GtkCssProvider *__provider; /* Fournisseur par défaut */ - - - - /****************************************************************************** * * * Paramètres : portion = description de partie à consulter. * diff --git a/src/glibext/gbinportion.h b/src/glibext/gbinportion.h index fd1336b..fb32496 100644 --- a/src/glibext/gbinportion.h +++ b/src/glibext/gbinportion.h @@ -30,7 +30,7 @@ #include -#include "../arch/archbase.h" +#include "../arch/vmpa.h" #include "../common/fnv1a.h" @@ -85,7 +85,7 @@ void g_binary_portion_set_desc(GBinPortion *, const char *); const char *g_binary_portion_get_desc(const GBinPortion *); /* Définit les valeurs utiles d'une partie de code. */ -void g_binary_portion_set_values(GBinPortion *, off_t, off_t, vmpa_t); +void g_binary_portion_set_values(GBinPortion *, const vmpa2t *, off_t); /* Définit les droits associés à une partie de code. */ void g_binary_portion_set_rights(GBinPortion *, PortionAccessRights); @@ -100,13 +100,13 @@ void g_binary_portion_include(GBinPortion *, GBinPortion *); GBinPortion *g_binary_portion_find_at_pos(GBinPortion *, gint, GdkRectangle *); /* Recherche la portion présente à une adresse donnée. */ -GBinPortion *g_binary_portion_find_at_addr(GBinPortion *, vmpa_t, GdkRectangle *); +GBinPortion *g_binary_portion_find_at_addr(GBinPortion *, const vmpa2t *, GdkRectangle *); /* Fournit la position correspondant à une adresse donnée. */ -bool g_binary_portion_get_addr_from_pos(GBinPortion *, gint, const GdkRectangle *, vmpa_t *); +bool g_binary_portion_get_addr_from_pos(GBinPortion *, gint, const GdkRectangle *, vmpa2t *); /* Fournit l'adresse correspondant à une position donnée. */ -bool g_binary_portion_get_pos_from_addr(GBinPortion *, vmpa_t, const GdkRectangle *, gint *); +bool g_binary_portion_get_pos_from_addr(GBinPortion *, const vmpa2t *, const GdkRectangle *, gint *); /* Prépare une astuce concernant une portion pour son affichage. */ gboolean g_binary_portion_query_tooltip(GBinPortion *, gint, gint, const GdkRectangle *, GtkTooltip *); diff --git a/src/gtkext/gtkbinarystrip.c b/src/gtkext/gtkbinarystrip.c index 4ed5cf9..e0016d2 100644 --- a/src/gtkext/gtkbinarystrip.c +++ b/src/gtkext/gtkbinarystrip.c @@ -36,7 +36,7 @@ struct _GtkBinaryStrip GLoadedBinary *binary; /* Binaire à représenter */ gint display_pos; /* Position à l'écran */ - gint cursor_addr; /* Adresse de la position */ + vmpa2t cursor_addr; /* Adresse de la position */ gint cursor_pos; /* Position à l'écran */ }; @@ -46,7 +46,7 @@ struct _GtkBinaryStripClass { GtkDrawingAreaClass parent; /* A laisser en premier */ - void (* select_address) (GtkBinaryStrip *, vmpa_t); + void (* select_address) (GtkBinaryStrip *); }; @@ -111,8 +111,8 @@ static void gtk_binary_strip_class_init(GtkBinaryStripClass *class) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET(GtkBinaryStripClass, select_address), NULL, NULL, - g_cclosure_user_marshal_VOID__UINT64, - G_TYPE_NONE, 1, G_TYPE_UINT64); + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } @@ -229,7 +229,7 @@ static void gtk_binary_strip_size_allocate(GtkWidget *widget, GtkAllocation *all area.width = allocation->width; area.height = allocation->height; - if (!g_binary_portion_get_pos_from_addr(portions, strip->cursor_addr, &area, &strip->cursor_pos)) + if (!g_binary_portion_get_pos_from_addr(portions, &strip->cursor_addr, &area, &strip->cursor_pos)) strip->cursor_pos = 0; } @@ -256,7 +256,7 @@ static gboolean gtk_binary_strip_button_release(GtkWidget *widget, GdkEventButto GExeFormat *format; /* Format du binaire */ GBinPortion *portions; /* Portions binaires à dessiner*/ GdkRectangle area; /* Surface du composant */ - vmpa_t addr; /* Adresse à sélectionner */ + vmpa2t addr; /* Adresse à sélectionner */ if (event->x < 0 || event->y < 0) return FALSE; @@ -278,12 +278,15 @@ static gboolean gtk_binary_strip_button_release(GtkWidget *widget, GdkEventButto if (g_binary_portion_get_addr_from_pos(portions, event->x, &area, &addr)) { - strip->cursor_addr = addr; + copy_vmpa(&strip->cursor_addr, &addr); strip->cursor_pos = event->x; gtk_widget_queue_draw(GTK_WIDGET(strip)); - g_signal_emit_by_name(strip, "select-address", addr); + printf("got :: %p\n", &addr); + printf(" -> 0x%x 0x%x\n", (unsigned int)get_phy_addr(&addr), (unsigned int)get_virt_addr(&addr)); + + g_signal_emit_by_name(strip, "select-address"); } @@ -441,6 +444,25 @@ void gtk_binary_strip_attach(GtkBinaryStrip *strip, GLoadedBinary *binary) /****************************************************************************** * * +* Paramètres : strip = composant GTK à consulter. * +* * +* Description : Indique l'adresse physique et virtuelle représentée. * +* * +* Retour : Localisation, initialisée ou non. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const vmpa2t *gtk_binary_strip_get_location(const GtkBinaryStrip *strip) +{ + return &strip->cursor_addr; + +} + + +/****************************************************************************** +* * * Paramètres : strip = composant GTK à mettre à jour. * * binary = nouveau contenu binaire à représenter. * * * diff --git a/src/gtkext/gtkbinarystrip.h b/src/gtkext/gtkbinarystrip.h index 09152a3..3f082f5 100644 --- a/src/gtkext/gtkbinarystrip.h +++ b/src/gtkext/gtkbinarystrip.h @@ -57,6 +57,9 @@ GtkWidget *gtk_binary_strip_new(void); /* Attache un nouveau binaire à la barre de représentation. */ void gtk_binary_strip_attach(GtkBinaryStrip *, GLoadedBinary *); +/* Indique l'adresse physique et virtuelle représentée. */ +const vmpa2t *gtk_binary_strip_get_location(const GtkBinaryStrip *); + #endif /* _GTKEXT_BINARYSTRIP_H */ diff --git a/src/gtkext/gtkbufferview.c b/src/gtkext/gtkbufferview.c index 87928b9..4b515b4 100644 --- a/src/gtkext/gtkbufferview.c +++ b/src/gtkext/gtkbufferview.c @@ -109,6 +109,7 @@ static void gtk_buffer_view_class_init(GtkBufferViewClass *class) widget_class->key_press_event = gtk_buffer_view_key_press; panel_class->compute_size = (compute_requested_size)gtk_buffer_view_compute_requested_size; + panel_class->get_coordinates = (get_addr_coordinates_fc)gtk_buffer_view_get_address_coordinates; g_signal_new("caret-moved", GTK_TYPE_BUFFER_VIEW, @@ -139,7 +140,6 @@ static void gtk_buffer_view_init(GtkBufferView *view) viewpanel = GTK_VIEW_PANEL(view); - viewpanel->get_coordinates = (get_addr_coordinates_fc)gtk_buffer_view_get_address_coordinates; viewpanel->cache_glance = (cache_glance_fc)gtk_buffer_view_cache_glance; view->caret.x = 10; diff --git a/src/gtkext/gtkviewpanel-int.h b/src/gtkext/gtkviewpanel-int.h index 1d55bf2..f89fdcf 100644 --- a/src/gtkext/gtkviewpanel-int.h +++ b/src/gtkext/gtkviewpanel-int.h @@ -70,7 +70,6 @@ struct _GtkViewPanel attach_binary_fc attach; /* Association avec un binaire */ define_address_fc define; /* Centrage sur une partie */ prepare_resize_fc resize; /* Prépare une nouvelle taille */ - get_addr_coordinates_fc get_coordinates;/* Conversion adresse <-> pos. */ cache_glance_fc cache_glance; /* Cache de la mignature */ bool *display_phys; /* Affichage des adresses ? */ @@ -85,6 +84,7 @@ struct _GtkViewPanelClass GtkFixedClass parent; /* A laisser en premier */ compute_requested_size compute_size; /* Calcul de la taille requise */ + get_addr_coordinates_fc get_coordinates;/* Conversion adresse <-> pos. */ }; diff --git a/src/gtkext/gtkviewpanel.c b/src/gtkext/gtkviewpanel.c index 353022a..1933add 100644 --- a/src/gtkext/gtkviewpanel.c +++ b/src/gtkext/gtkviewpanel.c @@ -761,7 +761,7 @@ bool gtk_view_panel_contain_address(const GtkViewPanel *panel, vmpa_t addr) gint dummy_x; /* Abscisse pour l'appel */ gint dummy_y; /* Ordonnée pour l'appel */ - return panel->get_coordinates(panel, addr, &dummy_x, &dummy_y); + return GTK_VIEW_PANEL_GET_CLASS(panel)->get_coordinates(panel, addr, &dummy_x, &dummy_y); } @@ -794,7 +794,7 @@ void gtk_view_panel_scroll_to_address(GtkViewPanel *panel, const vmpa2t *addr) */ - if (panel->get_coordinates(panel, addr, &x, &y) && 0 /* ARG */) + if (GTK_VIEW_PANEL_GET_CLASS(panel)->get_coordinates(panel, addr, &x, &y)) { viewport = gtk_widget_get_parent(GTK_WIDGET(panel)); diff --git a/src/gui/tb/portions.c b/src/gui/tb/portions.c index 53d9dd4..53c7dea 100644 --- a/src/gui/tb/portions.c +++ b/src/gui/tb/portions.c @@ -67,7 +67,7 @@ static void g_portions_tbitem_finalize(GPortionsTbItem *); static void update_portions_item_binary(GEditorItem *, GLoadedBinary *); /* Fait suivre un changement d'adresse dans la barre. */ -static void track_address_on_binary_strip(GtkBinaryStrip *, vmpa_t, GObject *); +static void track_address_on_binary_strip(GtkBinaryStrip *, GEditorItem *); @@ -243,10 +243,14 @@ static void update_portions_item_binary(GEditorItem *item, GLoadedBinary *binary * * ******************************************************************************/ -static void track_address_on_binary_strip(GtkBinaryStrip *strip, vmpa_t addr, GObject *ref) +static void track_address_on_binary_strip(GtkBinaryStrip *strip, GEditorItem *item) { + const vmpa2t *addr; /* Nouvelle destination */ + GtkViewPanel *vpanel; /* Afficheur effectif de code */ - printf("===> CHANGE TO 0x%08llx\n", 123); + addr = gtk_binary_strip_get_location(strip); + vpanel = g_editor_item_get_current_view(item); + gtk_view_panel_scroll_to_address(vpanel, addr); } -- cgit v0.11.2-87-g4458