/* Chrysalide - Outil d'analyse de fichiers binaires * binary.c - panneau d'affichage de contenus d'un binaire, bruts ou non * * Copyright (C) 2024 Cyrille Bagard * * This file 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 "binary-int.h" #include "../window.h" #include "../../analysis/contents/file.h" #include "../../gtkext/helpers.h" #include "../../gtkext/hexview.h" /* ------------------------- COEUR D'UN PANNEAU D'AFFICHAGE ------------------------- */ /* Initialise la classe des panneaux pour binaires. */ static void gtk_binary_panel_class_init(GtkBinaryPanelClass *); /* Initialise une instance de panneau pour binaire. */ static void gtk_binary_panel_init(GtkBinaryPanel *); /* Supprime toutes les références externes. */ static void gtk_binary_panel_dispose(GtkBinaryPanel *); /* Procède à la libération totale de la mémoire. */ static void gtk_binary_panel_finalize(GtkBinaryPanel *); /* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ /* ---------------------- MANIPULATIONS D'UN PANNEAU GRAPHIQUE ---------------------- */ /* Initialise la classe des panneaux graphiques pour binaires. */ static void g_binary_panel_class_init(GBinaryPanelClass *); /* Initialise une instance de panneau graphique pour binaire. */ static void g_binary_panel_init(GBinaryPanel *); /* Supprime toutes les références externes. */ static void g_binary_panel_dispose(GBinaryPanel *); /* Procède à la libération totale de la mémoire. */ static void g_binary_panel_finalize(GBinaryPanel *); /* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ /* Fournit une indication sur la personnalité du panneau. */ static PanelItemPersonality g_binary_panel_get_personality(const GBinaryPanel *); /* Fournit un composant pour lancer l'activité d'un panneau. */ static GtkWidget *g_binary_panel_get_launcher(GBinaryPanel *); /* Fournit un composant pour paramétrer l'activité d'un panneau. */ static GtkWidget *g_binary_panel_get_properties(GBinaryPanel *); /* Ouvre une boîte de dialogue pour récupérer un fichier. */ static void g_binary_panel_on_new_file_entry_icon_release(GtkEntry *, GtkEntryIconPosition, GBinaryPanel *); /* Fournit un composant représentant un panneau graphique. */ static GtkTiledPanel *g_binary_panel_get_panel(GBinaryPanel *, GtkWidget *); /* ---------------------------------------------------------------------------------- */ /* COEUR D'UN PANNEAU D'AFFICHAGE */ /* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour un panneau d'accueil. */ G_DEFINE_TYPE(GtkBinaryPanel, gtk_binary_panel, GTK_TYPE_TILED_PANEL); /****************************************************************************** * * * Paramètres : class = classe à initialiser. * * * * Description : Initialise la classe des panneaux pour binaires. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_binary_panel_class_init(GtkBinaryPanelClass *class) { GObjectClass *object; /* Autre version de la classe */ GtkWidgetClass *widget; /* Classe de haut niveau */ object = G_OBJECT_CLASS(class); object->dispose = (GObjectFinalizeFunc/* ! */)gtk_binary_panel_dispose; object->finalize = (GObjectFinalizeFunc)gtk_binary_panel_finalize; widget = GTK_WIDGET_CLASS(class); gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/binary.ui"); gtk_widget_class_bind_template_child(widget, GtkBinaryPanel, hex_scroll); } /****************************************************************************** * * * Paramètres : panel = instance à initialiser. * * * * Description : Initialise une instance de panneau pour binaire. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_binary_panel_init(GtkBinaryPanel *panel) { gtk_widget_init_template(GTK_WIDGET(panel)); } /****************************************************************************** * * * Paramètres : panel = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_binary_panel_dispose(GtkBinaryPanel *panel) { gtk_widget_dispose_template(GTK_WIDGET(panel), GTK_TYPE_BINARY_PANEL); G_OBJECT_CLASS(gtk_binary_panel_parent_class)->dispose(G_OBJECT(panel)); } /****************************************************************************** * * * Paramètres : panel = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_binary_panel_finalize(GtkBinaryPanel *panel) { G_OBJECT_CLASS(gtk_binary_panel_parent_class)->finalize(G_OBJECT(panel)); } /****************************************************************************** * * * Paramètres : content = contenu brut à exposer. * * * * Description : Crée une nouvelle instance de panneau pour binaire. * * * * Retour : Composant GTK mis en place. * * * * Remarques : - * * * ******************************************************************************/ GtkTiledPanel *gtk_binary_panel_new_for_content(GBinContent *content) { GtkTiledPanel *result; /* Instance à retourner */ GtkHexView *view; /* Composant d'affichage */ result = g_object_new(GTK_TYPE_BINARY_PANEL, NULL); view = gtk_hex_view_new(content); gtk_scrolled_window_set_child(GTK_BINARY_PANEL(result)->hex_scroll, GTK_WIDGET(view)); return result; } /* ---------------------------------------------------------------------------------- */ /* IMPLEMENTATION DES FONCTIONS DE CLASSE */ /* ---------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------- */ /* MANIPULATIONS D'UN PANNEAU GRAPHIQUE */ /* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour une manipulation de panneau pour binaires. */ G_DEFINE_TYPE(GBinaryPanel, g_binary_panel, G_TYPE_PANEL_ITEM); /****************************************************************************** * * * Paramètres : class = classe à initialiser. * * * * Description : Initialise la classe des panneaux graphiques pour binaires. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_binary_panel_class_init(GBinaryPanelClass *class) { GObjectClass *object; /* Autre version de la classe */ GPanelItemClass *panel; /* Encore une autre vision... */ object = G_OBJECT_CLASS(class); object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_panel_dispose; object->finalize = (GObjectFinalizeFunc)g_binary_panel_finalize; panel = G_PANEL_ITEM_CLASS(class); panel->get_personality = (get_panel_item_personality_cb)g_binary_panel_get_personality; panel->get_launcher = (get_panel_item_widget_cb)g_binary_panel_get_launcher; panel->get_properties = (get_panel_item_widget_cb)g_binary_panel_get_properties; panel->get_panel = (get_panel_item_panel_cb)g_binary_panel_get_panel; } /****************************************************************************** * * * Paramètres : panel = instance à initialiser. * * * * Description : Initialise une instance de panneau graphique pour binaire. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_binary_panel_init(GBinaryPanel *panel) { } /****************************************************************************** * * * Paramètres : panel = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_binary_panel_dispose(GBinaryPanel *panel) { G_OBJECT_CLASS(g_binary_panel_parent_class)->dispose(G_OBJECT(panel)); } /****************************************************************************** * * * Paramètres : panel = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_binary_panel_finalize(GBinaryPanel *panel) { G_OBJECT_CLASS(g_binary_panel_parent_class)->finalize(G_OBJECT(panel)); } /****************************************************************************** * * * Paramètres : - * * * * Description : Constitue une définition de manipulation de panneau. * * * * Retour : Définition de propriétés mise en place. * * * * Remarques : - * * * ******************************************************************************/ GPanelItem *g_binary_panel_new(void) { GPanelItem *result; /* Structure à retourner */ result = g_object_new(G_TYPE_BINARY_PANEL, NULL); return result; } /* ---------------------------------------------------------------------------------- */ /* IMPLEMENTATION DES FONCTIONS DE CLASSE */ /* ---------------------------------------------------------------------------------- */ /****************************************************************************** * * * Paramètres : panel = définition de panneau à consulter. * * * * Description : Fournit une indication sur la personnalité du panneau. * * * * Retour : Identifiant lié à la nature du panneau. * * * * Remarques : - * * * ******************************************************************************/ static PanelItemPersonality g_binary_panel_get_personality(const GBinaryPanel *panel) { PanelItemPersonality result; /* Personnalité à retourner */ result = PIP_MAIN_PANEL; return result; } /****************************************************************************** * * * Paramètres : panel = définition de panneau à manipuler. * * * * Description : Fournit un composant pour lancer l'activité d'un panneau. * * * * Retour : Composant GTK (déjà ?) mis en place. * * * * Remarques : - * * * ******************************************************************************/ static GtkWidget *g_binary_panel_get_launcher(GBinaryPanel *panel) { GtkWidget *result; /* Composant à retourner */ GtkBuilder *builder; /* Constructeur d'UI */ builder = gtk_builder_new_from_resource("/re/chrysalide/framework/gui/panels/binary-launch.ui"); result = GTK_WIDGET(gtk_builder_get_object(builder, "launcher")); ref_object(result); unref_object(builder); return result; } /****************************************************************************** * * * Paramètres : panel = définition de panneau à manipuler. * * * * Description : Fournit un composant pour paramétrer l'activité d'un panneau.* * * * Retour : Composant GTK (déjà ?) mis en place. * * * * Remarques : - * * * ******************************************************************************/ static GtkWidget *g_binary_panel_get_properties(GBinaryPanel *panel) { GtkWidget *result; /* Composant à retourner */ GtkBuilderScope *scope; /* Fonctions pour signaux */ GtkBuilderCScope *cscope; /* Fonctions pour signaux */ GtkBuilder *builder; /* Constructeur d'UI */ #ifndef NDEBUG gboolean status; /* Bilan d'un chargement */ #endif scope = gtk_builder_cscope_new(); cscope = GTK_BUILDER_CSCOPE(scope); gtk_builder_cscope_add_callback_symbol(cscope, BUILDER_CB(g_binary_panel_on_new_file_entry_icon_release)); builder = gtk_builder_new(); gtk_builder_set_scope(builder, scope); gtk_builder_set_current_object(builder, G_OBJECT(panel)); #ifndef NDEBUG status = gtk_builder_add_from_resource(builder, "/re/chrysalide/framework/gui/panels/binary-props.ui", NULL); assert(status); #else gtk_builder_add_from_resource(builder, "/re/chrysalide/framework/gui/panels/binary-props.ui", NULL); #endif result = GTK_WIDGET(gtk_builder_get_object(builder, "properties")); ref_object(result); unref_object(builder); unref_object(scope); return result; } /****************************************************************************** * * * Paramètres : entry = zone de saisie concernée par l'appel. * * icon_pos = position de l'icone incrustée dans la zone. * * panel = définition de panneau à manipuler. * * * * Description : Ouvre une boîte de dialogue pour récupérer un fichier. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_binary_panel_on_new_file_entry_icon_release(GtkEntry *entry, GtkEntryIconPosition icon_pos, GBinaryPanel *panel) { GtkRoot *root; /* Racine du composant */ GtkTiledPanel *tiled; /* Panneau d'affichage complet */ root = gtk_widget_get_root(GTK_WIDGET(entry)); tiled = g_binary_panel_get_panel(panel, NULL); gtk_framework_window_add(GTK_FRAMEWORK_WINDOW(root), tiled); } /****************************************************************************** * * * Paramètres : panel = définition de panneau à manipuler. * * props = éventuels éléments graphiques de paramétrages. * * * * Description : Fournit un composant représentant un panneau graphique. * * * * Retour : Composant GTK (déjà ?) mis en place. * * * * Remarques : - * * * ******************************************************************************/ static GtkTiledPanel *g_binary_panel_get_panel(GBinaryPanel *panel, GtkWidget *props) { GtkTiledPanel *result; /* Composant à retourner */ GBinContent *content; /* Contenu binaire à afficher */ content = g_file_content_new("/bin/id"); result = gtk_binary_panel_new_for_content(content); unref_object(content); return result; }