/* Chrysalide - Outil d'analyse de fichiers binaires * binary.c - gestion du menu 'Binaire' * * Copyright (C) 2012-2017 Cyrille Bagard * * This binary is part of Chrysalide. * * Chrysalide 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. * * Chrysalide 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 "binary.h" #include #include "../agroup.h" #include "../editem-int.h" #include "../core/global.h" #include "../dialogs/export_disass.h" #include "../dialogs/export_graph.h" #include "../dialogs/gotox.h" #include "../dialogs/snapshots.h" #include "../dialogs/storage.h" #include "../../gtkext/easygtk.h" #include "../../gtkext/gtkdisplaypanel.h" #include "../../gtkext/gtkgraphdisplay.h" /* Réagit au menu "Binaire -> Points d'entrée". */ static void mcb_binary_entry_points(GtkMenuItem *, GMenuBar *); /* Réagit au menu "Binaire -> Attacher un débogueur". */ static void mcb_binary_attach_debugger(GtkMenuItem *, GMenuBar *); /* Réagit au menu "Binaire -> Enregistrements". */ static void mcb_binary_storage(GtkMenuItem *, GMenuBar *); /* Réagit au menu "Binaire -> Instantanés". */ static void mcb_binary_snapshots(GtkMenuItem *, GMenuBar *); /* Réagit au menu "Binaire -> Exporter -> Désassemblage". */ static void mcb_binary_export_disass(GtkMenuItem *, gpointer); /* Réagit au menu "Binaire -> Exporter -> Vue graphique". */ static void mcb_binary_export_graph(GtkMenuItem *, gpointer); /****************************************************************************** * * * Paramètres : ref = espace de référencement global. * * bar = barre de menu parente. * * * * Description : Construit le menu "Binaire". * * * * Retour : Panneau de menus mis en place. * * * * Remarques : - * * * ******************************************************************************/ GtkWidget *build_menu_binary(GObject *ref, GMenuBar *bar) { GtkWidget *result; /* Support à retourner */ GtkWidget *menubar; /* Support pour éléments */ GtkWidget *submenuitem; /* Sous-élément de menu #1 */ GtkWidget *deepmenubar; /* Support pour éléments #2 */ GtkWidget *deepmenuitem; /* Sous-élément de menu #2 */ result = gtk_menu_item_new_with_mnemonic(_("_Binary")); gtk_widget_show(result); menubar = qck_create_menu(GTK_MENU_ITEM(result)); submenuitem = qck_create_menu_item(ref, "mnu_binary_epoints", _("Entry points"), G_CALLBACK(mcb_binary_entry_points), bar); add_accelerator_to_widget(submenuitem, "E"); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); submenuitem = qck_create_menu_separator(); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); submenuitem = qck_create_menu_item(ref, "mnu_binary_attach_debugger", _("Attach a debugger"), G_CALLBACK(mcb_binary_attach_debugger), bar); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); /* Séparation */ submenuitem = qck_create_menu_separator(); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); /* Bases de données */ submenuitem = qck_create_menu_item(ref, "mnu_binary_storage", _("Storage"), G_CALLBACK(mcb_binary_storage), bar); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); submenuitem = qck_create_menu_item(ref, "mnu_binary_snapshots", _("Snapshots"), G_CALLBACK(mcb_binary_snapshots), bar); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); /* Séparation */ submenuitem = qck_create_menu_separator(); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); /* Exportations */ submenuitem = qck_create_menu_item(NULL, NULL, _("Export"), NULL, NULL); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); deepmenubar = qck_create_menu(GTK_MENU_ITEM(submenuitem)); deepmenuitem = qck_create_menu_item(ref, "mnu_binary_export_disass", _("Disassembly"), G_CALLBACK(mcb_binary_export_disass), bar); gtk_container_add(GTK_CONTAINER(deepmenubar), deepmenuitem); deepmenuitem = qck_create_menu_item(ref, "mnu_binary_export_graph", _("Graph view"), G_CALLBACK(mcb_binary_export_graph), NULL); gtk_container_add(GTK_CONTAINER(deepmenubar), deepmenuitem); return result; } /****************************************************************************** * * * Paramètres : ref = espace de référencement global. * * new = nouveau contenu chargé à analyser. * * * * Description : Réagit à un changement d'affichage principal de contenu. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ void update_access_for_content_in_menu_binary(GObject *ref, GLoadedContent *new) { gboolean access; /* Accès à déterminer */ GtkWidget *item; /* Elément de menu à traiter */ access = G_IS_LOADED_BINARY(new); item = GTK_WIDGET(g_object_get_data(ref, "mnu_binary_epoints")); gtk_widget_set_sensitive(item, access); item = GTK_WIDGET(g_object_get_data(ref, "mnu_binary_storage")); gtk_widget_set_sensitive(item, access); item = GTK_WIDGET(g_object_get_data(ref, "mnu_binary_export_disass")); gtk_widget_set_sensitive(item, access); } /****************************************************************************** * * * Paramètres : ref = espace de référencement global. * * new = nouvelle vue du contenu chargé analysé. * * * * Description : Lance une actualisation du fait d'un changement de support. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ void update_access_for_view_in_menu_binary(GObject *ref, GLoadedPanel *new) { gboolean access; /* Accès à déterminer */ GtkWidget *item; /* Elément de menu à traiter */ access = GTK_IS_GRAPH_DISPLAY(new); item = GTK_WIDGET(g_object_get_data(ref, "mnu_binary_export_graph")); gtk_widget_set_sensitive(item, access); } /****************************************************************************** * * * Paramètres : menuitem = élément de menu sélectionné. * * bar = barre de menu parente. * * * * Description : Réagit au menu "Binaire -> Points d'entrée". * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void mcb_binary_entry_points(GtkMenuItem *menuitem, GMenuBar *bar) { GLoadedBinary *binary; /* Binaire présenté à l'écran */ GtkWindow *editor; /* Fenêtre graphique principale*/ GtkWidget *dialog; /* Boîte de dialogue à montrer */ vmpa2t *addr; /* Adresse de destination */ GLoadedPanel *panel; /* Afficheur effectif de code */ binary = G_LOADED_BINARY(get_current_content()); editor = get_editor_window(); dialog = create_gotox_dialog_for_entry_points(editor, binary); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { addr = get_address_from_gotox_dialog(dialog); panel = get_current_view(); if (GTK_IS_DISPLAY_PANEL(panel)) gtk_display_panel_request_move(GTK_DISPLAY_PANEL(panel), addr); g_object_unref(G_OBJECT(panel)); delete_vmpa(addr); } gtk_widget_destroy(dialog); g_object_unref(G_OBJECT(editor)); g_object_unref(G_OBJECT(binary)); } /****************************************************************************** * * * Paramètres : menuitem = élément de menu sélectionné. * * bar = barre de menu parente. * * * * Description : Réagit au menu "Binaire -> Attacher un débogueur". * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void mcb_binary_attach_debugger(GtkMenuItem *menuitem, GMenuBar *bar) { } /****************************************************************************** * * * Paramètres : menuitem = élément de menu sélectionné. * * bar = barre de menu parente. * * * * Description : Réagit au menu "Binaire -> Enregistrements". * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void mcb_binary_storage(GtkMenuItem *menuitem, GMenuBar *bar) { GLoadedBinary *binary; /* Edition courante */ GtkBuilder *builder; /* Constructeur utilisé */ GtkWindow *editor; /* Fenêtre graphique principale*/ GtkWidget *dialog; /* Boîte de dialogue à montrer */ gint ret; /* Retour de confirmation */ binary = G_LOADED_BINARY(get_current_content()); editor = get_editor_window(); dialog = create_storage_dialog(binary, editor, &builder); ret = gtk_dialog_run(GTK_DIALOG(dialog)); if (ret == GTK_RESPONSE_APPLY) update_binary_storage(builder, binary); gtk_widget_destroy(dialog); g_object_unref(G_OBJECT(builder)); g_object_unref(G_OBJECT(editor)); g_object_unref(G_OBJECT(binary)); } /****************************************************************************** * * * Paramètres : menuitem = élément de menu sélectionné. * * bar = barre de menu parente. * * * * Description : Réagit au menu "Binaire -> Instantanés". * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void mcb_binary_snapshots(GtkMenuItem *menuitem, GMenuBar *bar) { GLoadedBinary *binary; /* Edition courante */ GtkBuilder *builder; /* Constructeur utilisé */ GtkWindow *editor; /* Fenêtre graphique principale*/ GtkWidget *dialog; /* Boîte de dialogue à montrer */ binary = G_LOADED_BINARY(get_current_content()); editor = get_editor_window(); dialog = create_snapshots_dialog(binary, editor, &builder); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_object_unref(G_OBJECT(builder)); g_object_unref(G_OBJECT(editor)); g_object_unref(G_OBJECT(binary)); } /****************************************************************************** * * * Paramètres : menuitem = élément de menu sélectionné. * * unused = adresse non utilisée ici. * * * * Description : Réagit au menu "Binaire -> Exporter -> Désassemblage". * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void mcb_binary_export_disass(GtkMenuItem *menuitem, gpointer unused) { GLoadedBinary *binary; /* Edition courante */ GtkWindow *editor; /* Fenêtre graphique principale*/ binary = G_LOADED_BINARY(get_current_content()); editor = get_editor_window(); run_export_assistant(binary, editor); g_object_unref(G_OBJECT(editor)); g_object_unref(G_OBJECT(binary)); } /****************************************************************************** * * * Paramètres : menuitem = élément de menu sélectionné. * * unused = adresse non utilisée ici. * * * * Description : Réagit au menu "Binaire -> Exporter -> Vue graphique". * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void mcb_binary_export_graph(GtkMenuItem *menuitem, gpointer unused) { GtkGraphDisplay *panel; /* Panneau de code courant */ GLoadedBinary *binary; /* Edition courante */ GtkWindow *editor; /* Fenêtre graphique principale*/ binary = G_LOADED_BINARY(get_current_content()); panel = GTK_GRAPH_DISPLAY(get_current_view()); editor = get_editor_window(); run_graph_export_assistant(binary, panel, editor); g_object_unref(G_OBJECT(editor)); g_object_unref(G_OBJECT(panel)); g_object_unref(G_OBJECT(binary)); }