diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2009-09-13 23:11:24 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2009-09-13 23:11:24 (GMT) |
commit | 1c4da24a1d4b96d58fee08e2be21198b22e7eef6 (patch) | |
tree | a0723bd1948395413fa5a7a37a9405567e32c015 /src/panels/symbols.c | |
parent | 18134387d5cb025703af8e1d07e0152784e31efc (diff) |
Improved the editor window refreshing when several binaries are loaded.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@114 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/panels/symbols.c')
-rw-r--r-- | src/panels/symbols.c | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/src/panels/symbols.c b/src/panels/symbols.c new file mode 100644 index 0000000..c7c8369 --- /dev/null +++ b/src/panels/symbols.c @@ -0,0 +1,284 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * symbols.c - panneau d'affichage des symboles + * + * Copyright (C) 2006-2007 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "symbols.h" + + +#include <gtk/gtk.h> + + +#include "panel-int.h" +#include "../format/format.h" + + + +#define _(str) str + + + + +/* Panneau d'aperçu de graphiques (instance) */ +struct _GSymbolsPanel +{ + GEditorPanel parent; /* A laisser en premier */ + + GtkTreeStore *store; /* Modèle de gestion */ + + GtkBinView *binview; /* Affichage à faire défiler */ + +}; + + + +/* Panneau d'aperçu de graphiques (classe) */ +struct _GSymbolsPanelClass +{ + GEditorPanelClass parent; /* A laisser en premier */ + +}; + + +/* Colonnes de la liste des symboles */ +typedef enum _SymbolsColumn +{ + SBC_ADDRESS, /* Adresse mémoire du symbole */ + SBC_NAME, /* Désignation humaine */ + + SBC_COUNT /* Nombre de colonnes */ + +} SymbolsColumn; + + + +/* Initialise la classe des panneaux d'aperçu de graphiques. */ +static void g_symbols_panel_class_init(GSymbolsPanelClass *); + +/* Initialise une instance de panneau d'aperçu de graphiques. */ +static void g_symbols_panel_init(GSymbolsPanel *); + +/* Réagit au changement de sélection des symboles. */ +static void on_symbols_selection_change(GtkTreeSelection *, GSymbolsPanel *); + +/* Réagit à un changement d'affichage principal de contenu. */ +static void reload_symbols_for_new_view(GSymbolsPanel *, GtkBinView *, bool); + + + +/* Indique le type définit pour un panneau d'aperçu de graphiques. */ +G_DEFINE_TYPE(GSymbolsPanel, g_symbols_panel, G_TYPE_EDITOR_PANEL); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des panneaux d'aperçu de graphiques. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_symbols_panel_class_init(GSymbolsPanelClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : panel = instance à initialiser. * +* * +* Description : Initialise une instance de panneau d'aperçu de graphiques. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_symbols_panel_init(GSymbolsPanel *panel) +{ + GEditorPanel *base; /* Version basique d'instance */ + GtkWidget *treeview; /* Affichage de la liste */ + GtkCellRenderer *renderer; /* Moteur de rendu de colonne */ + GtkTreeViewColumn *column; /* Colonne de la liste */ + GtkTreeSelection *select; /* Sélection dans la liste */ + + base = G_EDITOR_PANEL(panel); + + base->name = _("Symbols"); + base->reload_view = (reload_for_new_view_fc)reload_symbols_for_new_view; + + base->widget = gtk_scrolled_window_new(NULL, NULL); + gtk_widget_show(base->widget); + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(base->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(base->widget), GTK_SHADOW_IN); + + panel->store = gtk_tree_store_new(SBC_COUNT, G_TYPE_STRING, G_TYPE_STRING); + + treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(panel->store)); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); + gtk_widget_show(treeview); + gtk_container_add(GTK_CONTAINER(base->widget), treeview); + + g_object_unref(G_OBJECT(panel->store)); + + column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_visible(column, FALSE); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + gtk_tree_view_set_expander_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Address", renderer, "text", SBC_ADDRESS, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", SBC_NAME, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + select = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); + g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK(on_symbols_selection_change), panel); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Crée un panneau d'aperçu de graphiques. * +* * +* Retour : Adresse de la structure mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GEditorPanel *g_symbols_panel_new(void) +{ + GEditorPanel *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_SYMBOLS_PANEL, NULL); + + return G_EDITOR_PANEL(result); + +} + + +/****************************************************************************** +* * +* Paramètres : selection = sélection modifiée. * +* panel = structure contenant les informations maîtresses. * +* * +* Description : Réagit au changement de sélection des symboles. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void on_symbols_selection_change(GtkTreeSelection *selection, GSymbolsPanel *panel) +{ + GtkTreeIter iter; /* Point de sélection */ + GtkTreeModel *model; /* Modèle de gestion */ + gchar *string; /* Chaîne sélectionnée */ + vmpa_t address; /* Adresse à rejoindre */ + + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + { + gtk_tree_model_get(model, &iter, SBC_ADDRESS, &string, -1); + address = strtoll(string, NULL, 16); /* FIXME */ + g_free(string); + + gtk_bin_view_scroll_to_address(panel->binview, address); + + } + +} + + +/****************************************************************************** +* * +* Paramètres : panel = panneau à mettre à jour. * +* view = nouvelle visualisation de désassemblage. * +* same = changement de binaire ou de vue ? * +* * +* Description : Réagit à un changement d'affichage principal de contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void reload_symbols_for_new_view(GSymbolsPanel *panel, GtkBinView *view, bool same) +{ + GOpenidaBinary *binary; /* Binaire en cours d'édition */ + GExeFormat *format; /* Format associé au binaire */ + GBinSymbol **symbols; /* Symboles trouvés */ + size_t count; /* Nombre de ces symboles */ + GArchProcessor *proc; /* Architecture utilisée */ + size_t i; /* Boucle de parcours */ + vmpa_t address; /* Adresse associée au symbole */ + char tmp[VMPA_MAX_SIZE]; /* Version humainement lisible */ + GtkTreeIter iter; /* Point d'insertion */ + + panel->binview = view; + + if (same) return; + + gtk_tree_store_clear(panel->store); + + binary = gtk_bin_view_get_binary(view); + format = g_openida_binary_get_format(binary); + symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &count); + + if (symbols != NULL) + { + proc = get_arch_processor_from_format(format); + + for (i = 0; i < count; i++) + { + if (g_binary_symbol_get_target_type(symbols[i]) == STP_STRING) + continue; + + address = g_binary_symbol_get_address(symbols[i]); + vmpa_to_string(address, g_arch_processor_get_memory_size(proc), tmp); + + gtk_tree_store_append(panel->store, &iter, NULL); + gtk_tree_store_set(panel->store, &iter, + SBC_ADDRESS, tmp, + SBC_NAME, g_binary_symbol_to_string(symbols[i]), + -1); + + } + + } + +} |