diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2009-06-08 12:46:23 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2009-06-08 12:46:23 (GMT) |
commit | fc8324b66dee0abf0a5e5e3cc570e1aed96b80c8 (patch) | |
tree | 04b9220e34b8bdc3449cd73e54a32c5037be5f0c /src | |
parent | dd75712aac8f70d18f07787d5d484d426600edeb (diff) |
Refreshed the panel dealing with found symbols.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@72 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/analysis/binary.c | 14 | ||||
-rw-r--r-- | src/analysis/line_code.c | 19 | ||||
-rw-r--r-- | src/analysis/line_comment.c | 19 | ||||
-rw-r--r-- | src/analysis/prototype.c | 19 | ||||
-rw-r--r-- | src/analysis/prototype.h | 3 | ||||
-rw-r--r-- | src/arch/jvm/processor.c | 1 | ||||
-rw-r--r-- | src/arch/mips/processor.c | 1 | ||||
-rw-r--r-- | src/arch/processor-int.h | 1 | ||||
-rw-r--r-- | src/arch/processor.c | 60 | ||||
-rw-r--r-- | src/arch/processor.h | 29 | ||||
-rw-r--r-- | src/arch/x86/processor.c | 1 | ||||
-rw-r--r-- | src/editor.c | 12 | ||||
-rw-r--r-- | src/format/exe_format.c | 20 | ||||
-rw-r--r-- | src/gtkext/gtksnippet.h | 2 | ||||
-rwxr-xr-x | src/panel/Makefile.am | 3 | ||||
-rw-r--r-- | src/panel/log.c | 7 | ||||
-rw-r--r-- | src/panel/panels.c | 8 | ||||
-rw-r--r-- | src/panel/panels.h | 3 | ||||
-rw-r--r-- | src/panel/symbols.c (renamed from src/pan_symbols.c) | 68 | ||||
-rw-r--r-- | src/panel/symbols.h (renamed from src/pan_symbols.h) | 4 |
21 files changed, 195 insertions, 100 deletions
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, + "<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; - case ADM_64BITS: + default: + case MDS_64_BITS: snprintf(buffer, CODE_BUFFER_LEN, "<span foreground='#333333'>0x%16llx</span>", 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, + "<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; - case ADM_64BITS: + default: + case MDS_64_BITS: snprintf(buffer, CODE_BUFFER_LEN, "<span foreground='#333333'>0x%16llx</span>", 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 <sys/types.h> - - -#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 <glib-object.h> +#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/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/pan_symbols.c b/src/panel/symbols.c index 05a162b..3937849 100644 --- a/src/pan_symbols.c +++ b/src/panel/symbols.c @@ -1,6 +1,6 @@ /* OpenIDA - Outil d'analyse de fichiers binaires - * pan_symbols.c - panneau d'affichage des symboles + * symbols.c - panneau d'affichage des symboles * * Copyright (C) 2006-2007 Cyrille Bagard * @@ -22,14 +22,15 @@ */ -#include "pan_symbols.h" +#include "symbols.h" #include <malloc.h> #include <stdlib.h> -#include "gtkext/gtkbinview.h" +#include "../arch/processor.h" +#include "../gtkext/gtkbinview.h" @@ -49,7 +50,6 @@ void change_symbols_selection(GtkTreeSelection *, gpointer); - /****************************************************************************** * * * Paramètres : ref = adresse de l'espace de référencements. * @@ -127,13 +127,13 @@ void change_symbols_selection(GtkTreeSelection *selection, gpointer data) GtkTreeIter iter; GtkTreeModel *model; gchar *string; /* Chaîne sélectionnée */ - uint64_t address; /* Adresse à rejoindre */ + 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); + address = strtoll(string, NULL, 16); /* FIXME */ g_free(string); binview = GTK_BIN_VIEW(g_object_get_data(G_OBJECT(data), "binview")); @@ -158,46 +158,60 @@ void change_symbols_selection(GtkTreeSelection *selection, gpointer data) * * ******************************************************************************/ -void handle_new_exe_on_symbols_panel(GtkWidget *panel, const exe_format *format) +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 */ - 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 */ + GArchProcessor *proc; /* Architecture utilisée */ size_t i; /* Boucle de parcours */ - char address[11]; - - store = g_object_get_data(G_OBJECT(panel), "store"); + vmpa_t address; /* Adresse associée au symbole */ + char tmp[19]; /* Version humainement lisible */ + GtkTreeIter iter; /* Point d'insertion */ - count = get_exe_symbols(format, &labels, &types, &offsets); + routines = get_all_exe_routines(format, &count); - if (count > 0) + 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; - snprintf(address, 11, "0x%08llx", offsets[i]); + 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, address, - SBC_NAME, labels[i], + SBC_ADDRESS, tmp, + SBC_NAME, g_binary_routine_get_name(routines[i]), -1); - } - free(labels); - free(types); - free(offsets); + free(routines); } - - - } diff --git a/src/pan_symbols.h b/src/panel/symbols.h index d294717..195bcf2 100644 --- a/src/pan_symbols.h +++ b/src/panel/symbols.h @@ -29,7 +29,7 @@ #include <gtk/gtk.h> -#include "format/exe_format.h" +#include "../format/exe_format.h" @@ -38,7 +38,7 @@ 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 *); +void reload_symbols_panel_content(GtkWidget *, const exe_format *); |