/* Chrysalide - Outil d'analyse de fichiers binaires * status.c - affichage d'informations de statut dans la fenêtre principale * * Copyright (C) 2013 Cyrille Bagard * * This file is part of Chrysalide. * * 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 "status.h" #include #include #include #include "editem-int.h" #include "../common/extstr.h" #include "../gtkext/gtkbufferview.h" #include "../gtkext/gtkblockview.h" #include "../gtkext/gtkextstatusbar.h" /* Barre de statut de la fenêtre principale (instance) */ struct _GStatusInfo { GEditorItem parent; /* A laisser en premier */ GObject *caret_instance; /* Dernier émetteur de signaux */ bstatus_id_t msg_id; /* Identifiant du dernier msg. */ }; /* Barre de statut de la fenêtre principale (classe) */ struct _GStatusInfoClass { GEditorItemClass parent; /* A laisser en premier */ }; /* Initialise la classe de la barre de statut de l'éditeur. */ static void g_status_info_class_init(GStatusInfoClass *); /* Initialise une instance de la barre de statut pour l'éditeur. */ static void g_status_info_init(GStatusInfo *); /* Supprime toutes les références externes. */ static void g_status_info_dispose(GStatusInfo *); /* Procède à la libération totale de la mémoire. */ static void g_status_info_finalize(GStatusInfo *); /* Lance une actualisation du fait d'un changement de vue. */ static void update_status_info_for_view(GStatusInfo *, GtkViewPanel *); /* Imprime la position du parcours courant dans le statut. */ static void track_caret_address_on_buffer_views(GtkBufferView *, const vmpa2t *, GStatusInfo *); /* Concentre l'attention de l'ensemble sur une adresse donnée. */ static void focus_address_in_status_info(GStatusInfo *, GLoadedBinary *, const vmpa2t *); /* Indique le type défini pour la barre de statut de la fenêtre principale. */ G_DEFINE_TYPE(GStatusInfo, g_status_info, G_TYPE_EDITOR_ITEM); /****************************************************************************** * * * Paramètres : klass = classe à initialiser. * * * * Description : Initialise la classe de la barre de statut de l'éditeur. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_status_info_class_init(GStatusInfoClass *klass) { GObjectClass *object; /* Autre version de la classe */ GEditorItemClass *editem; /* Encore une autre vision... */ object = G_OBJECT_CLASS(klass); object->dispose = (GObjectFinalizeFunc/* ! */)g_status_info_dispose; object->finalize = (GObjectFinalizeFunc)g_status_info_finalize; editem = G_EDITOR_ITEM_CLASS(klass); editem->update_view = (update_item_view_fc)update_status_info_for_view; editem->focus_addr = (focus_addr_fc)focus_address_in_status_info; } /****************************************************************************** * * * Paramètres : bar = instance à initialiser. * * * * Description : Initialise une instance de la barre de statut pour l'éditeur.* * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_status_info_init(GStatusInfo *bar) { GEditorItem *item; /* Autre version de l'élément */ item = G_EDITOR_ITEM(bar); item->name = "status"; item->widget = gtk_extended_status_bar_new(); gtk_widget_show(item->widget); } /****************************************************************************** * * * Paramètres : info = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_status_info_dispose(GStatusInfo *info) { if (info->caret_instance != NULL) { g_signal_handlers_disconnect_by_func(info->caret_instance, G_CALLBACK(track_caret_address_on_buffer_views), info); g_object_unref(info->caret_instance); } G_OBJECT_CLASS(g_status_info_parent_class)->dispose(G_OBJECT(info)); } /****************************************************************************** * * * Paramètres : info = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_status_info_finalize(GStatusInfo *info) { G_OBJECT_CLASS(g_status_info_parent_class)->finalize(G_OBJECT(info)); } /****************************************************************************** * * * Paramètres : ref = espace de référencement global. * * * * Description : Compose la barre de statut principale. * * * * Retour : Adresse de la structure mise en place. * * * * Remarques : - * * * ******************************************************************************/ GEditorItem *g_status_info_new(GObject *ref) { GStatusInfo *result; /* Structure à retourner */ GEditorItem *item; /* Autre version de l'élément */ result = g_object_new(G_TYPE_STATUS_INFO, NULL); item = G_EDITOR_ITEM(result); g_object_ref(ref); item->ref = ref; g_object_set_data(ref, "statusbar", item->widget); return G_EDITOR_ITEM(result); } /****************************************************************************** * * * Paramètres : info = barre de statut à actualiser. * * view = nouveau panneau d'affichage actif. * * * * Description : Lance une actualisation du fait d'un changement de vue. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void update_status_info_for_view(GStatusInfo *info, GtkViewPanel *view) { if (info->caret_instance != NULL) { g_signal_handlers_disconnect_by_func(info->caret_instance, G_CALLBACK(track_caret_address_on_buffer_views), info); g_object_unref(info->caret_instance); } if (GTK_IS_BLOCK_VIEW(view)) g_signal_connect(view, "caret-moved", G_CALLBACK(track_caret_address_on_buffer_views), info); info->caret_instance = G_OBJECT(view); g_object_ref(info->caret_instance); } /****************************************************************************** * * * Paramètres : view = composant d'affichage parcouru. * * addr = nouvelle adresse du curseur courant. * * info = barre de statut présentant les informations. * * * * Description : Imprime la position du parcours courant dans le statut. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void track_caret_address_on_buffer_views(GtkBufferView *view, const vmpa2t *addr, GStatusInfo *info) { GEditorItem *item; /* Autre version de l'élément */ GLoadedBinary *binary; /* Binaire courant */ GExeFormat *format; /* Format du fichier binaire */ GArchProcessor *proc; /* Architecture du binaire */ MemoryDataSize msize; /* Taille par défaut */ char *msg; /* Message à transmettre */ VMPA_BUFFER(conv); /* Zone de conversion */ vmpa_t rel; /* Adresse relative à un symb. */ const char *label; /* Désignation d'un symbole */ item = G_EDITOR_ITEM(info); binary = g_editor_item_get_current_binary(item); proc = g_loaded_binary_get_processor(binary); msize = g_arch_processor_get_memory_size(proc); g_object_unref(G_OBJECT(proc)); /* Réinitiation seule si il n'y a plus d'adresse... */ if (addr == NULL) { if (info->msg_id > 0) gtk_extended_status_bar_remove(GTK_EXT_STATUS_BAR(item->widget), info->msg_id); return; } /* Adresse brute */ msize = g_arch_processor_get_memory_size(proc); msg = strdup(_("Location phys:")); vmpa2_phys_to_string(addr, msize, conv, NULL); msg = stradd(msg, conv); msg = stradd(msg, " virt:"); vmpa2_virt_to_string(addr, msize, conv, NULL); msg = stradd(msg, conv); #if 0 /* Relation avec les symboles */ binary = G_LOADED_BINARY(g_object_get_data(item->ref, "current_binary")); format = g_loaded_binary_get_format(binary); rel = addr; if (g_binary_format_resolve_relative_routine(G_BIN_FORMAT(format), &label, &rel)) { msg = stradd(msg, _(" at ")); msg = stradd(msg, label); msg = stradd(msg, _("+")); snprintf(tmp, VMPA_MAX_SIZE, VMPA_FMT, rel); msg = stradd(msg, tmp); } #endif /* Impression */ if (info->msg_id > 0) gtk_extended_status_bar_remove(GTK_EXT_STATUS_BAR(item->widget), info->msg_id); info->msg_id = gtk_extended_status_bar_push(GTK_EXT_STATUS_BAR(item->widget), msg, FALSE); printf("---- moved to 0x%08llx\n", addr); printf(" MSG '%s'\n", msg); //update_menu_project_for_project(bar->project, project, bar); free(msg); } /****************************************************************************** * * * Paramètres : info = composant réactif à mettre à jour. * * binary = binaire contenant l'adresse à représenter. * * addr = adresse mémoire à mettre en avant. * * * * Description : Concentre l'attention de l'ensemble sur une adresse donnée. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void focus_address_in_status_info(GStatusInfo *info, GLoadedBinary *binary, const vmpa2t *addr) { GExeFormat *format; /* Format associé au binaire */ GArchProcessor *proc; /* Architecture du binaire */ MemoryDataSize msize; /* Taille du bus d'adresses */ char *msg; /* Message à transmettre */ VMPA_BUFFER(tmp); /* Traduction d'adresses */ GBinSymbol *symbol; /* Symbole présent à l'adresse */ phys_t diff; /* Décallage de l'adresse */ const char *label; /* Description d'un symbole */ GBinPortion *portions; /* Portions binaires existantes*/ GBinPortion *portion; /* Zone mémoire d'appartenance */ size_t len; /* Caractère à faire basculer */ format = g_loaded_binary_get_format(binary); proc = g_loaded_binary_get_processor(binary); msize = g_arch_processor_get_memory_size(proc); g_object_unref(G_OBJECT(proc)); msg = strdup(_("Localisation:")); /* Adresses de base */ msg = stradd(msg, " phys:"); vmpa2_phys_to_string(addr, msize, tmp, NULL); msg = stradd(msg, tmp); msg = stradd(msg, " virt:"); vmpa2_virt_to_string(addr, msize, tmp, NULL); msg = stradd(msg, tmp); /* Symbole présent ? */ if (g_binary_format_resolve_symbol(G_BIN_FORMAT(format), addr, &symbol, &diff)) { label = g_binary_symbol_get_label(symbol); if (label != NULL) { msg = stradd(msg, _(" at ")); msg = stradd(msg, label); msg = stradd(msg, _("+")); snprintf(tmp, VMPA_MAX_SIZE, "0x%x", diff); msg = stradd(msg, tmp); } g_object_unref(G_OBJECT(symbol)); } /* Zone d'appartenance */ portions = g_exe_format_get_portions(format); portion = g_binary_portion_find_at_addr(portions, addr, (GdkRectangle []) { }); label = g_binary_portion_get_desc(portion); msg = stradd(msg, _(" (")); /** * Pas très propre : on bascule de majuscule en minuscule ici... * FIXME ? */ len = strlen(msg); msg = stradd(msg, label); msg[len] = tolower(msg[len]); msg = stradd(msg, _(")")); /* Impression */ if (info->msg_id > 0) gtk_extended_status_bar_remove(GTK_EXT_STATUS_BAR(G_EDITOR_ITEM(info)->widget), info->msg_id); info->msg_id = gtk_extended_status_bar_push(GTK_EXT_STATUS_BAR(G_EDITOR_ITEM(info)->widget), msg, FALSE); free(msg); }