From fc8324b66dee0abf0a5e5e3cc570e1aed96b80c8 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 8 Jun 2009 12:46:23 +0000 Subject: Refreshed the panel dealing with found symbols. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@72 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 55 +++++++++++ src/Makefile.am | 1 - src/analysis/binary.c | 14 +-- src/analysis/line_code.c | 19 +++- src/analysis/line_comment.c | 19 +++- src/analysis/prototype.c | 19 ++++ src/analysis/prototype.h | 3 + src/arch/jvm/processor.c | 1 + src/arch/mips/processor.c | 1 + src/arch/processor-int.h | 1 + src/arch/processor.c | 60 ++++++++++++ src/arch/processor.h | 29 ++---- src/arch/x86/processor.c | 1 + src/editor.c | 12 +-- src/format/exe_format.c | 20 +--- src/gtkext/gtksnippet.h | 2 - src/pan_symbols.c | 203 ----------------------------------------- src/pan_symbols.h | 45 --------- src/panel/Makefile.am | 3 +- src/panel/log.c | 7 +- src/panel/panels.c | 8 +- src/panel/panels.h | 3 +- src/panel/symbols.c | 217 ++++++++++++++++++++++++++++++++++++++++++++ src/panel/symbols.h | 45 +++++++++ 24 files changed, 469 insertions(+), 319 deletions(-) delete mode 100644 src/pan_symbols.c delete mode 100644 src/pan_symbols.h create mode 100644 src/panel/symbols.c create mode 100644 src/panel/symbols.h diff --git a/ChangeLog b/ChangeLog index e8fe6ab..d13bebf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,60 @@ 09-06-08 Cyrille Bagard + * src/analysis/binary.c: + Update the code loading the processor. + + * src/analysis/line_code.c: + * src/analysis/line_comment.c: + Fix the address printing (need to be improved). + + * src/analysis/prototype.c: + * src/analysis/prototype.h: + Retrieve only the name of a routine. + + * src/arch/jvm/processor.c: + * src/arch/mips/processor.c: + Define the memory size of the architecture. + + * src/arch/processor.c: + * src/arch/processor.h: + Change the code providing the linked architecture. Define the memory + size of the architecture. Convert formats into architectures. Clean + the code. + + * src/arch/processor-int.h: + * src/arch/x86/processor.c: + Define the memory size of the architecture. + + * src/editor.c: + Typo. Update the calls. + + * src/format/exe_format.c: + Remove the log messages in favour of binary.c + + * src/gtkext/gtksnippet.h: + Remove the useless AdressMode field. + + * src/Makefile.am: + Remove the pan_symbols.[ch] from openida_SOURCES. + + * src/panel/log.c: + Fix some compilation warnings. + + * src/panel/Makefile.am: + Add the symbols.[ch] files to libpanel_a_SOURCES. + + * src/panel/panels.c: + * src/panel/panels.h: + Load the symbols panel. + + * src/panel/symbols.c: + * src/panel/symbols.h: + * src/pan_symbols.c: + * src/pan_symbols.h: + Moved entries: refresh the panel dealing with found symbols. + +09-06-08 Cyrille Bagard + * src/arch/x86/instruction.c: * src/arch/x86/instruction.h: Support more opcodes. diff --git a/src/Makefile.am b/src/Makefile.am index dd5d1ea..c47f5e7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -64,7 +64,6 @@ openida_SOURCES = \ dlg_sections.h dlg_sections.c \ editor.c \ pan_strings.h pan_strings.c \ - pan_symbols.h pan_symbols.c \ project.h project.c \ shell.h shell.c \ xdg.h xdg.c \ diff --git a/src/analysis/binary.c b/src/analysis/binary.c index 88201ac..01ccfdd 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -39,6 +39,7 @@ #include "line_comment.h" #include "line_prologue.h" #include "prototype.h" +#include "../panel/log.h" #include "../plugins/pglist.h" @@ -117,23 +118,22 @@ openida_binary *load_binary_file(const char *filename) switch (get_exe_target_machine(result->format)) { case FTM_JVM: - result->proc = get_arch_processor_for_type(APT_JVM); + log_simple_message(LMT_INFO, _("Detected architecture: Java Virtual Machine")); break; - case FTM_MIPS: - result->proc = get_arch_processor_for_type(APT_MIPS); + log_simple_message(LMT_INFO, _("Detected architecture: Microprocessor without Interlocked Pipeline Stages")); break; - case FTM_386: - result->proc = get_arch_processor_for_type(APT_386); + log_simple_message(LMT_INFO, _("Detected architecture: i386")); break; - default: + log_simple_message(LMT_INFO, _("Unknown architecture")); goto lbf_error; break; - } + result->proc = get_arch_processor_from_format(result->format); + result->options.show_address = true; result->options.show_code = true; diff --git a/src/analysis/line_code.c b/src/analysis/line_code.c index a234055..cd7eba6 100644 --- a/src/analysis/line_code.c +++ b/src/analysis/line_code.c @@ -174,15 +174,28 @@ void g_code_line_refresh_markup(GCodeLine *line) if (line->options->show_address) { - switch (ADM_32BITS /* FIXME */) + switch (g_arch_processor_get_memory_size(line->options->proc)) { - case ADM_32BITS: + case MDS_8_BITS: + snprintf(buffer, CODE_BUFFER_LEN, + "0x%02llx", + G_RENDERING_LINE(line)->offset); + break; + + case MDS_16_BITS: + snprintf(buffer, CODE_BUFFER_LEN, + "0x%04llx", + G_RENDERING_LINE(line)->offset); + break; + + case MDS_32_BITS: snprintf(buffer, CODE_BUFFER_LEN, "0x%08llx", G_RENDERING_LINE(line)->offset); break; - case ADM_64BITS: + default: + case MDS_64_BITS: snprintf(buffer, CODE_BUFFER_LEN, "0x%16llx", G_RENDERING_LINE(line)->offset); diff --git a/src/analysis/line_comment.c b/src/analysis/line_comment.c index ea6d6d6..1d37613 100644 --- a/src/analysis/line_comment.c +++ b/src/analysis/line_comment.c @@ -137,15 +137,28 @@ void g_comment_line_refresh_markup(GCommentLine *line) if (line->options->show_address) { - switch (ADM_32BITS /* FIXME */) + switch (g_arch_processor_get_memory_size(line->options->proc)) { - case ADM_32BITS: + case MDS_8_BITS: + snprintf(buffer, CODE_BUFFER_LEN, + "0x%02llx", + G_RENDERING_LINE(line)->offset); + break; + + case MDS_16_BITS: + snprintf(buffer, CODE_BUFFER_LEN, + "0x%04llx", + G_RENDERING_LINE(line)->offset); + break; + + case MDS_32_BITS: snprintf(buffer, CODE_BUFFER_LEN, "0x%08llx", G_RENDERING_LINE(line)->offset); break; - case ADM_64BITS: + default: + case MDS_64_BITS: snprintf(buffer, CODE_BUFFER_LEN, "0x%16llx", G_RENDERING_LINE(line)->offset); diff --git a/src/analysis/prototype.c b/src/analysis/prototype.c index 1e27f2c..78854f9 100644 --- a/src/analysis/prototype.c +++ b/src/analysis/prototype.c @@ -245,6 +245,25 @@ void g_binary_routine_set_name(GBinRoutine *routine, char *name) /****************************************************************************** * * * Paramètres : routine = routine à mettre à jour. * +* * +* Description : Fournit le nom humain d'une routine. * +* * +* Retour : Désignation humainement lisible ou NULL si non définie. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *g_binary_routine_get_name(const GBinRoutine *routine) +{ + return routine->name; + +} + + +/****************************************************************************** +* * +* Paramètres : routine = routine à mettre à jour. * * var = variable représentant un type de retour. * * * * Description : Définit le type de retour d'une routine. * diff --git a/src/analysis/prototype.h b/src/analysis/prototype.h index 3fd822e..299cce6 100644 --- a/src/analysis/prototype.h +++ b/src/analysis/prototype.h @@ -75,6 +75,9 @@ void g_binary_routine_set_type(GBinRoutine *, RoutineType); /* Définit le nom humain d'une routine. */ void g_binary_routine_set_name(GBinRoutine *, char *); +/* Désignation humainement lisible ou NULL si non définie. */ +const char *g_binary_routine_get_name(const GBinRoutine *); + /* Définit le type de retour d'une routine. */ void g_binary_routine_set_return_type(GBinRoutine *, variable *); diff --git a/src/arch/jvm/processor.c b/src/arch/jvm/processor.c index 8226afc..034b864 100644 --- a/src/arch/jvm/processor.c +++ b/src/arch/jvm/processor.c @@ -98,6 +98,7 @@ static void g_jvm_processor_init(GJvmProcessor *proc) parent = G_ARCH_PROCESSOR(proc); parent->endianness = SRE_BIG; + parent->memsize = MDS_32_BITS; parent->decode = (decode_instruction_fc)g_jvm_processor_decode_instruction; diff --git a/src/arch/mips/processor.c b/src/arch/mips/processor.c index c28c7b4..7e921c1 100644 --- a/src/arch/mips/processor.c +++ b/src/arch/mips/processor.c @@ -97,6 +97,7 @@ static void g_mips_processor_init(GMipsProcessor *proc) parent = G_ARCH_PROCESSOR(proc); parent->endianness = SRE_BIG; + parent->memsize = MDS_32_BITS; parent->decode = (decode_instruction_fc)g_mips_processor_decode_instruction; diff --git a/src/arch/processor-int.h b/src/arch/processor-int.h index bbe2384..fc9097e 100644 --- a/src/arch/processor-int.h +++ b/src/arch/processor-int.h @@ -58,6 +58,7 @@ struct _GArchProcessor GObject parent; /* A laisser en premier */ SourceEndian endianness; /* Boutisme de l'architecture */ + MemoryDataSize memsize; /* Taille de l'espace mémoire */ decode_instruction_fc decode; /* Traduction en instructions */ diff --git a/src/arch/processor.c b/src/arch/processor.c index 317e893..c8630d7 100644 --- a/src/arch/processor.c +++ b/src/arch/processor.c @@ -132,6 +132,25 @@ SourceEndian g_arch_processor_get_endianness(const GArchProcessor *proc) /****************************************************************************** * * +* Paramètres : proc = processeur d'architecture à consulter. * +* * +* Description : Fournit la taille de l'espace mémoire d'une architecture. * +* * +* Retour : Taille de l'espace mémoire. * +* * +* Remarques : - * +* * +******************************************************************************/ + +MemoryDataSize g_arch_processor_get_memory_size(const GArchProcessor *proc) +{ + return proc->memsize; + +} + + +/****************************************************************************** +* * * Paramètres : proc = architecture visée par la procédure. * * data = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * @@ -216,3 +235,44 @@ GArchProcessor *get_arch_processor_for_type(ArchProcessorType type) return _processors_list[type]; } + + +/****************************************************************************** +* * +* Paramètres : format = exécutable d'origine. * +* * +* Description : Fournit le processeur d'architecture lié à un format. * +* * +* Retour : Processeur d'architecture trouvé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchProcessor *get_arch_processor_from_format(const exe_format *format) +{ + GArchProcessor *result; /* Conversion à retourner */ + + switch (get_exe_target_machine(format)) + { + case FTM_JVM: + result = get_arch_processor_for_type(APT_JVM); + break; + + case FTM_MIPS: + result = get_arch_processor_for_type(APT_MIPS); + break; + + case FTM_386: + result = get_arch_processor_for_type(APT_386); + break; + + default: + result = NULL; + break; + + } + + return result; + +} diff --git a/src/arch/processor.h b/src/arch/processor.h index 5726197..8529d50 100644 --- a/src/arch/processor.h +++ b/src/arch/processor.h @@ -25,31 +25,10 @@ #define _ARCH_PROCESSOR_H -#include - - -#include "operand.h" /* AsmSyntax */ -#include "instruction.h" - - - -/* FIXME : lieu de définition temporaire */ - -/* Mode d'adressage à utiliser */ -typedef enum _AdressMode -{ - ADM_32BITS, /* Adresses sur 32 bits */ - ADM_64BITS /* Adresses sur 64 bits */ - -} AdressMode; - - - - - #include +#include "instruction.h" #include "../common/endianness.h" @@ -73,6 +52,9 @@ GType g_arch_processor_get_type(void); /* Fournit le boustime du processeur d'une architecture. */ SourceEndian g_arch_processor_get_endianness(const GArchProcessor *); +/* Fournit la taille de l'espace mémoire d'une architecture. */ +MemoryDataSize g_arch_processor_get_memory_size(const GArchProcessor *); + /* Décode une instruction dans un flux de données. */ GArchInstruction *g_arch_processor_decode_instruction(const GArchProcessor *, const bin_t *, off_t *, off_t, off_t, vmpa_t); @@ -99,6 +81,9 @@ bool init_all_processors(void); /* Fournit le processeur d'architecture correspondant à un type. */ GArchProcessor *get_arch_processor_for_type(ArchProcessorType); +/* Fournit le processeur d'architecture lié à un format. */ +GArchProcessor *get_arch_processor_from_format(const exe_format *); + #endif /* _ARCH_PROCESSOR_H */ diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c index 8af84b2..7370da1 100644 --- a/src/arch/x86/processor.c +++ b/src/arch/x86/processor.c @@ -97,6 +97,7 @@ static void g_x86_processor_init(GX86Processor *proc) parent = G_ARCH_PROCESSOR(proc); parent->endianness = SRE_BIG; + parent->memsize = MDS_32_BITS; parent->decode = (decode_instruction_fc)g_x86_processor_decode_instruction; diff --git a/src/editor.c b/src/editor.c index ff1217b..7185e3f 100644 --- a/src/editor.c +++ b/src/editor.c @@ -43,7 +43,6 @@ #include "dlg_sections.h" #include "pan_strings.h" -#include "pan_symbols.h" #include "analysis/binary.h" #include "gtkext/easygtk.h" #include "gtkext/gtkbinview.h" @@ -233,7 +232,7 @@ int main(int argc, char **argv) GtkWidget *create_editor(void) { GtkWidget *result; /* Fenêtre à renvoyer */ - GObject *ref; /* version de référence */ + GObject *ref; /* Version de référence */ GtkWidget *menuboard; /* Barre de menus principale */ GtkWidget *menuitem; /* Elément de menu */ GtkWidget *menubar; /* Support pour éléments */ @@ -252,7 +251,6 @@ GtkWidget *create_editor(void) GtkWidget *binview; GtkWidget *panel; - GtkWidget *_panel; openida_project *project; @@ -441,7 +439,7 @@ GtkWidget *create_editor(void) gtk_paned_set_position (GTK_PANED (hpaned1), 600); - init_panels(); + init_panels(ref); dpanel = gtk_dock_panel_new(); @@ -503,10 +501,8 @@ GtkWidget *create_editor(void) gtk_paned_pack2(GTK_PANED(hpaned1), dpanel, TRUE, TRUE); - panel = build_symbols_panel(G_OBJECT(result)); - _panel = panel; - ditem = gtk_dock_item_new(_("Symbols"), panel); + ditem = gtk_dock_item_new(_("Symbols"), get_panel(PNT_SYMBOLS)); gtk_dock_panel_add_item(dpanel, ditem); ditem = gtk_dock_item_new(_("Registers"), get_panel(PNT_REGISTERS)); @@ -1221,7 +1217,7 @@ void open_last_file(GObject *ref) g_object_set_data(ref, "current_binary", binary); - + reload_symbols_panel_content(get_panel(PNT_SYMBOLS), get_openida_binary_format(binary)); } diff --git a/src/format/exe_format.c b/src/format/exe_format.c index 2924847..ffd9fde 100644 --- a/src/format/exe_format.c +++ b/src/format/exe_format.c @@ -360,25 +360,7 @@ const uint8_t *get_exe_content(const exe_format *format, off_t *length) FormatTargetMachine get_exe_target_machine(const exe_format *format) { - FormatTargetMachine result; /* Type à retourner */ - - result = format->get_target_machine(format); - - switch (result) - { - case FTM_JVM: - log_simple_message(LMT_INFO, _("Detected architecture: Java Virtual Machine")); - break; - case FTM_MIPS: - log_simple_message(LMT_INFO, _("Detected architecture: Microprocessor without Interlocked Pipeline Stages")); - break; - case FTM_386: - log_simple_message(LMT_INFO, _("Detected architecture: i386")); - break; - - } - - return result; + return format->get_target_machine(format); } diff --git a/src/gtkext/gtksnippet.h b/src/gtkext/gtksnippet.h index f079258..aa388a2 100644 --- a/src/gtkext/gtksnippet.h +++ b/src/gtkext/gtksnippet.h @@ -54,8 +54,6 @@ struct _GtkSnippet { GtkWidget widget; /* Présence obligatoire en 1er */ - AdressMode mode; /* Mode d'affichage */ - bool show_vaddress; /* Affichage des adresses ? */ bool show_code; /* Affichage du code brut ? */ diff --git a/src/pan_symbols.c b/src/pan_symbols.c deleted file mode 100644 index 05a162b..0000000 --- a/src/pan_symbols.c +++ /dev/null @@ -1,203 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * pan_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 "pan_symbols.h" - - -#include -#include - - -#include "gtkext/gtkbinview.h" - - - -/* 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; - - -/* Réagit au changement de sélection des symboles. */ -void change_symbols_selection(GtkTreeSelection *, gpointer); - - - - -/****************************************************************************** -* * -* Paramètres : ref = adresse de l'espace de référencements. * -* * -* Description : Construit le panneau d'affichage des symboles. * -* * -* Retour : Adresse du panneau mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *build_symbols_panel(GObject *ref) -{ - GtkWidget *result; /* Panneau à retourner */ - GtkTreeStore *store; /* Modèle de gestion */ - 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 */ - - result = gtk_scrolled_window_new(NULL, NULL); - gtk_widget_show(result); - - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(result), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(result), GTK_SHADOW_IN); - - store = gtk_tree_store_new(SBC_COUNT, G_TYPE_STRING, G_TYPE_STRING); - g_object_set_data(G_OBJECT(result), "store", store); - - treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); - gtk_widget_show(treeview); - gtk_container_add(GTK_CONTAINER(result), treeview); - - g_object_unref(G_OBJECT(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(change_symbols_selection), ref); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : selection = sélection modifiée. * -* data = adresse de l'espace de référencements. * -* * -* Description : Réagit au changement de sélection des symboles. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void change_symbols_selection(GtkTreeSelection *selection, gpointer data) -{ - GtkTreeIter iter; - GtkTreeModel *model; - gchar *string; /* Chaîne sélectionnée */ - uint64_t address; /* Adresse à rejoindre */ - GtkBinview *binview; /* Affichage à faire défiler */ - - if (gtk_tree_selection_get_selected(selection, &model, &iter)) - { - gtk_tree_model_get(model, &iter, SBC_ADDRESS, &string, -1); - address = strtoll(string, NULL, 16); - g_free(string); - - binview = GTK_BIN_VIEW(g_object_get_data(G_OBJECT(data), "binview")); - - gtk_binview_scroll_to_address(binview, address); - - } - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau à mettre à jour. * -* format = données sur l'exécutable à représenter. * -* * -* Description : Affiche la liste des symboles présents dans un exécutable. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void handle_new_exe_on_symbols_panel(GtkWidget *panel, const exe_format *format) -{ - GtkTreeStore *store; /* Modèle de gestion */ - GtkTreeIter iter; /* Point d'insertion */ - char **labels; /* Etiquettes humaines */ - SymbolType *types; /* Type des symboles listés */ - uint64_t *offsets; /* Emplacements de mémoire */ - size_t count; /* Nombre des symboles */ - size_t i; /* Boucle de parcours */ - char address[11]; - - store = g_object_get_data(G_OBJECT(panel), "store"); - - count = get_exe_symbols(format, &labels, &types, &offsets); - - if (count > 0) - { - for (i = 0; i < count; i++) - { - - - snprintf(address, 11, "0x%08llx", offsets[i]); - - - gtk_tree_store_append(store, &iter, NULL); - gtk_tree_store_set(store, &iter, - SBC_ADDRESS, address, - SBC_NAME, labels[i], - -1); - - - } - - free(labels); - free(types); - free(offsets); - - } - - - - -} diff --git a/src/pan_symbols.h b/src/pan_symbols.h deleted file mode 100644 index d294717..0000000 --- a/src/pan_symbols.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * pan_symbols.h - prototypes pour le 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 - */ - - -#ifndef _PAN_SYMBOLS_H -#define _PAN_SYMBOLS_H - - -#include - - -#include "format/exe_format.h" - - - -/* Construit le panneau d'affichage des symboles. */ -GtkWidget *build_symbols_panel(GObject *); - - -/* Affiche la liste des symboles présents dans un exécutable. */ -void handle_new_exe_on_symbols_panel(GtkWidget *, const exe_format *); - - - -#endif /* _PAN_SYMBOLS_H */ diff --git a/src/panel/Makefile.am b/src/panel/Makefile.am index f53a841..48f0958 100755 --- a/src/panel/Makefile.am +++ b/src/panel/Makefile.am @@ -4,7 +4,8 @@ noinst_LTLIBRARIES = libpanel.la libpanel_la_SOURCES = \ log.h log.c \ panels.h panels.c \ - registers.h registers.c + registers.h registers.c \ + symbols.h symbols.c libpanel_la_LDFLAGS = diff --git a/src/panel/log.c b/src/panel/log.c index 812d470..e8ac952 100644 --- a/src/panel/log.c +++ b/src/panel/log.c @@ -67,7 +67,6 @@ GtkWidget *build_log_panel(void) 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 */ result = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(result); @@ -154,6 +153,12 @@ void log_simple_message(LogMessageType type, const char *msg) -1); break; + default: + gtk_tree_store_set(store, &iter, + LGC_STRING, msg, + -1); + break; + } } diff --git a/src/panel/panels.c b/src/panel/panels.c index eae6ba3..39adc10 100644 --- a/src/panel/panels.c +++ b/src/panel/panels.c @@ -27,6 +27,7 @@ #include "log.h" #include "registers.h" +#include "symbols.h" @@ -36,7 +37,7 @@ static GtkWidget *panel_list[PNT_COUNT]; /****************************************************************************** * * -* Paramètres : - * +* Paramètres : ref = espace de référencements global. * * * * Description : Procède au chargement de tous les panneaux. * * * @@ -46,10 +47,11 @@ static GtkWidget *panel_list[PNT_COUNT]; * * ******************************************************************************/ -void init_panels(void) +void init_panels(GObject *ref) { panel_list[PNT_LOG] = build_log_panel(); panel_list[PNT_REGISTERS] = build_registers_panel(); + panel_list[PNT_SYMBOLS] = build_symbols_panel(ref); } @@ -68,6 +70,6 @@ void init_panels(void) GtkWidget *get_panel(PanelType id) { - return panel_list[id]; + return (id < PNT_COUNT ? panel_list[id] : NULL); } diff --git a/src/panel/panels.h b/src/panel/panels.h index e38f196..feaa908 100644 --- a/src/panel/panels.h +++ b/src/panel/panels.h @@ -35,6 +35,7 @@ typedef enum _PanelType { PNT_LOG, /* Messages système */ PNT_REGISTERS, /* Registres d'architecture */ + PNT_SYMBOLS, /* Symboles d'exécutable */ PNT_COUNT @@ -42,7 +43,7 @@ typedef enum _PanelType /* Procède au chargement de tous les panneaux. */ -void init_panels(void); +void init_panels(GObject *); /* Fournit la référence d'un panneau donné. */ GtkWidget *get_panel(PanelType); diff --git a/src/panel/symbols.c b/src/panel/symbols.c new file mode 100644 index 0000000..3937849 --- /dev/null +++ b/src/panel/symbols.c @@ -0,0 +1,217 @@ + +/* 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 +#include + + +#include "../arch/processor.h" +#include "../gtkext/gtkbinview.h" + + + +/* 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; + + +/* Réagit au changement de sélection des symboles. */ +void change_symbols_selection(GtkTreeSelection *, gpointer); + + + +/****************************************************************************** +* * +* Paramètres : ref = adresse de l'espace de référencements. * +* * +* Description : Construit le panneau d'affichage des symboles. * +* * +* Retour : Adresse du panneau mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *build_symbols_panel(GObject *ref) +{ + GtkWidget *result; /* Panneau à retourner */ + GtkTreeStore *store; /* Modèle de gestion */ + 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 */ + + result = gtk_scrolled_window_new(NULL, NULL); + gtk_widget_show(result); + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(result), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(result), GTK_SHADOW_IN); + + store = gtk_tree_store_new(SBC_COUNT, G_TYPE_STRING, G_TYPE_STRING); + g_object_set_data(G_OBJECT(result), "store", store); + + treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); + gtk_widget_show(treeview); + gtk_container_add(GTK_CONTAINER(result), treeview); + + g_object_unref(G_OBJECT(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(change_symbols_selection), ref); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : selection = sélection modifiée. * +* data = adresse de l'espace de référencements. * +* * +* Description : Réagit au changement de sélection des symboles. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void change_symbols_selection(GtkTreeSelection *selection, gpointer data) +{ + GtkTreeIter iter; + GtkTreeModel *model; + gchar *string; /* Chaîne sélectionnée */ + vmpa_t address; /* Adresse à rejoindre */ + GtkBinview *binview; /* Affichage à faire défiler */ + + 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); + + binview = GTK_BIN_VIEW(g_object_get_data(G_OBJECT(data), "binview")); + + gtk_binview_scroll_to_address(binview, address); + + } + +} + + +/****************************************************************************** +* * +* Paramètres : panel = panneau à mettre à jour. * +* format = données sur l'exécutable à représenter. * +* * +* Description : Affiche la liste des symboles présents dans un exécutable. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void reload_symbols_panel_content(GtkWidget *panel, const exe_format *format) +{ + GBinRoutine **routines; /* Routines trouvées */ + size_t count; /* Nombre de ces routines */ + GtkTreeStore *store; /* Modèle de gestion */ + GArchProcessor *proc; /* Architecture utilisée */ + size_t i; /* Boucle de parcours */ + vmpa_t address; /* Adresse associée au symbole */ + char tmp[19]; /* Version humainement lisible */ + GtkTreeIter iter; /* Point d'insertion */ + + routines = get_all_exe_routines(format, &count); + + if (routines != NULL) + { + store = g_object_get_data(G_OBJECT(panel), "store"); + + proc = get_arch_processor_from_format(format); + + for (i = 0; i < count; i++) + { + address = g_binary_routine_get_address(routines[i]); + + switch (g_arch_processor_get_memory_size(proc)) + { + case MDS_8_BITS: + snprintf(tmp, 19, "0x%02llx", address); + break; + + case MDS_16_BITS: + snprintf(tmp, 19, "0x%04llx", address); + break; + + case MDS_32_BITS: + snprintf(tmp, 19, "0x%08llx", address); + break; + + default: + case MDS_64_BITS: + snprintf(tmp, 19, "0x%16llx", address); + break; + + } + + gtk_tree_store_append(store, &iter, NULL); + gtk_tree_store_set(store, &iter, + SBC_ADDRESS, tmp, + SBC_NAME, g_binary_routine_get_name(routines[i]), + -1); + + } + + free(routines); + + } + +} diff --git a/src/panel/symbols.h b/src/panel/symbols.h new file mode 100644 index 0000000..195bcf2 --- /dev/null +++ b/src/panel/symbols.h @@ -0,0 +1,45 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pan_symbols.h - prototypes pour le 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 + */ + + +#ifndef _PAN_SYMBOLS_H +#define _PAN_SYMBOLS_H + + +#include + + +#include "../format/exe_format.h" + + + +/* Construit le panneau d'affichage des symboles. */ +GtkWidget *build_symbols_panel(GObject *); + + +/* Affiche la liste des symboles présents dans un exécutable. */ +void reload_symbols_panel_content(GtkWidget *, const exe_format *); + + + +#endif /* _PAN_SYMBOLS_H */ -- cgit v0.11.2-87-g4458