summaryrefslogtreecommitdiff
path: root/src/gui/tb/source.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/tb/source.c')
-rw-r--r--src/gui/tb/source.c227
1 files changed, 227 insertions, 0 deletions
diff --git a/src/gui/tb/source.c b/src/gui/tb/source.c
new file mode 100644
index 0000000..8750608
--- /dev/null
+++ b/src/gui/tb/source.c
@@ -0,0 +1,227 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * source.c - sélection du fichier ciblé lors d'une décompilation
+ *
+ * Copyright (C) 2010 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 "source.h"
+
+
+#include <i18n.h>
+
+
+#include "toolbar.h"
+#include "../editem-int.h"
+#include "../../format/format.h"
+#include "../../gtkext/easygtk.h"
+#include "../../gtkext/gtkbufferview.h"
+#include "../../gtkext/gtksourceview.h"
+
+
+
+/* Construit l'élément GTK pour une barre d'outils. */
+static GtkWidget *build_source_tb_widget(GObject *);
+
+/* Réagit à un changement du binaire courant. */
+static void update_source_item_binary(GEditorItem *, GOpenidaBinary *);
+
+/* Réagit à un changement de panneau d'affichage courant. */
+static void update_source_item_view(GEditorItem *, GtkViewPanel *);
+
+/* Réagit à un changement de sélection de la source courante. */
+static void change_selected_source(GtkComboBox *, GObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement global. *
+* *
+* Description : Construit l'élément GTK pour une barre d'outils. *
+* *
+* Retour : Adresse du composant mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GtkWidget *build_source_tb_widget(GObject *ref)
+{
+ GtkWidget *result; /* Composant à retourner */
+ GtkWidget *handlebox; /* Support relocalisable */
+ GtkWidget *hbox; /* Support interne */
+ GtkWidget *label; /* Etiquette d'introduction */
+ GtkWidget *comboboxentry; /* Liste de fichiers */
+
+ result = GTK_WIDGET(gtk_tool_item_new());
+ gtk_widget_show(result);
+
+ handlebox = gtk_handle_box_new();
+ gtk_widget_show(handlebox);
+ gtk_container_add(GTK_CONTAINER(result), handlebox);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+ gtk_widget_show(hbox);
+ gtk_container_add(GTK_CONTAINER(handlebox), hbox);
+
+ label = qck_create_label(G_OBJECT(result), "label", _(" Source: "));
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+ comboboxentry = qck_create_combobox(G_OBJECT(result), "combo",
+ G_CALLBACK(change_selected_source), ref);
+ gtk_box_pack_start(GTK_BOX(hbox), comboboxentry, TRUE, TRUE, 0);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement global. *
+* *
+* Description : Crée une sélection de fichier réactive pour barre d'outils. *
+* *
+* Retour : Adresse de la structure d'encadrement mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GEditorItem *create_source_tb_item(GObject *ref)
+{
+ GEditorItem *result; /* Structure à retourner */
+ GtkWidget *widget; /* Composant affiché à l'écran */
+
+ widget = build_source_tb_widget(ref);
+
+ result = g_toolbar_item_new(ref, "source", widget, _("Source files"));
+
+ result->update_binary = update_source_item_binary;
+ result->update_view = update_source_item_view;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément réactif sollicité. *
+* binary = binaire chargé nouvellement affiché. *
+* *
+* Description : Réagit à un changement du binaire courant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void update_source_item_binary(GEditorItem *item, GOpenidaBinary *binary)
+{
+ GtkComboBox *combo; /* Liste de sélection */
+ GtkTreeModel *model; /* Gestionnaire d'éléments */
+ GtkTreeIter iter; /* Boucle de parcours #2 */
+ GExeFormat *format; /* Format d'exécutable associé */
+ size_t count; /* Quantité de fichiers */
+ size_t defsrc; /* Fichier source principal */
+ const char * const *files; /* Liste de fichiers source */
+ size_t i; /* Boucle de parcours #2 */
+
+ /* Réinitialisation */
+
+ combo = GTK_COMBO_BOX(g_object_get_data(G_OBJECT(item->widget), "combo"));
+
+ /* TODO : signal */
+
+ model = gtk_combo_box_get_model(combo);
+
+ while (gtk_tree_model_get_iter_first(model, &iter))
+ gtk_combo_box_remove_text(combo, 0);
+
+ /* Inscriptions */
+
+ format = g_openida_binary_get_format(binary);
+ files = g_binary_format_get_source_files(G_BIN_FORMAT(format), &count, &defsrc);
+
+ for (i = 0; i < count; i++)
+ gtk_combo_box_append_text(combo, files[i]);
+
+ /* Réactivation */
+
+ /* TODO : signal */
+
+ gtk_combo_box_set_active(combo, defsrc);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément réactif sollicité. *
+* view = nouveau panneau d'affichage actif. *
+* *
+* Description : Réagit à un changement de panneau d'affichage courant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void update_source_item_view(GEditorItem *item, GtkViewPanel *view)
+{
+ gtk_widget_set_sensitive(item->widget, GTK_IS_SOURCE_VIEW(view));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : widget = composant GTK en cause. *
+* ref = espace de référencement global. *
+* *
+* Description : Réagit à un changement de sélection de la source courante. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void change_selected_source(GtkComboBox *widget, GObject *ref)
+{
+ gint index; /* Nouvelle source ciblée */
+ GOpenidaBinary *binary; /* Binaire chargé courant */
+ GCodeBuffer *buffer; /* Nouveau tampon à présenter */
+ GtkBufferView *view; /* Afficheur de tampons */
+
+ index = gtk_combo_box_get_active(widget);
+
+ binary = G_OPENIDA_BINARY(g_object_get_data(ref, "current_binary"));
+ buffer = g_openida_binary_get_decompiled_buffer(binary, index);
+
+ view = GTK_BUFFER_VIEW(g_object_get_data(ref, "current_view"));
+ if (GTK_IS_BUFFER_VIEW(view))
+ gtk_buffer_view_attach_buffer(view, buffer);
+
+}