summaryrefslogtreecommitdiff
path: root/src/dialogs
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-11-18 23:20:16 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-11-18 23:20:16 (GMT)
commit783e5e1977c1e4dadf938befa9fce9a311079413 (patch)
tree995423e1069e31db4fe0517fb9a45432dafceb6d /src/dialogs
parent26d75963fba34d8e5a5b9a6186604110552f3a38 (diff)
Saved the current work on binary parts selection.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@137 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/dialogs')
-rw-r--r--src/dialogs/binparts.c604
-rw-r--r--src/dialogs/binparts.h42
2 files changed, 646 insertions, 0 deletions
diff --git a/src/dialogs/binparts.c b/src/dialogs/binparts.c
new file mode 100644
index 0000000..1135348
--- /dev/null
+++ b/src/dialogs/binparts.c
@@ -0,0 +1,604 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dlg_sections.h - boîte de dialogue permettant une sélection des sections
+ *
+ * Copyright (C) 2008 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "binparts.h"
+
+
+#include "../format/format.h"
+#include "../gtkext/easygtk.h"
+
+
+
+#define _(str) str
+
+
+
+/* Colonnes de la liste des symboles */
+typedef enum _PartsColumn
+{
+ PTC_ACTIVE, /* Zone de code active ? */
+ PTC_NAME, /* Désignation humaine */
+ PTC_START, /* Adresse de départ */
+ PTC_END, /* Adresse d'arrivée (exclue) */
+
+ PTC_COUNT /* Nombre de colonnes */
+
+} PartsColumn;
+
+
+
+/* Mémoire d'un modèle */
+typedef struct _parts_model
+{
+ gboolean *selected; /* Sélection ou non de parties */
+ size_t count; /* Qté. de prises en compte */
+
+} parts_model;
+
+
+
+
+
+/* Charge les sections sélectionnées pour le projet courant. */
+void load_project_sections(void *, GObject *);
+
+
+
+
+
+/* Affiche les parties désassemblées par défaut. */
+static void load_default_parts(GObject *);
+
+/* Affiche les parties désassemblées selon les routines. */
+static void load_routines_parts(GObject *);
+
+
+
+/* Réagit à un changement de modèle. */
+static void on_model_change(GtkComboBox *, GObject *);
+
+/* Réagit à un changement de sélection de partie. */
+static void on_part_selection_toggle(GtkCellRendererToggle *, gchar *, GObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = informations sur le binaire actuellement ouvert. *
+* *
+* Description : Construit la fenêtre de sélection des sections. *
+* *
+* Retour : Adresse de la fenêtre mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkWidget *create_sections_dialog(GOpenidaBinary *binary)
+{
+ GtkWidget *result; /* Fenêtre à renvoyer */
+ GObject *ref; /* Espace de référencements */
+
+
+
+
+
+ GtkWidget *vbox1;
+ //GtkWidget *hbox1;
+
+
+ GtkWidget *label; /* Etiquette à afficher */
+
+
+ GtkWidget *combobox;
+
+ GtkWidget *alignment; /* Adaptation de disposition */
+ GtkWidget *frame; /* Support avec encadrement */
+
+ GtkWidget *vbox2;
+ GtkWidget *hbox2;
+ GtkWidget *comboboxentry;
+ GtkWidget *hbox3;
+ GtkWidget *scrolledwindow1;
+
+ GtkTreeStore *store; /* Modèle de gestion */
+ GtkWidget *treeview; /* Affichage de la liste */
+ GtkCellRenderer *renderer; /* Moteur de rendu de colonne */
+ GtkTreeViewColumn *column; /* Colonne de la liste */
+
+
+ GtkWidget *vbuttonbox1;
+ GtkWidget *hbuttonbox1;
+
+ GtkWidget *button; /* Bouton de commande */
+
+ result = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request(result, 600, 400);
+ gtk_container_set_border_width(GTK_CONTAINER(result), 8);
+ gtk_window_set_title(GTK_WINDOW(result), _("Sections selection"));
+ gtk_window_set_position(GTK_WINDOW(result), GTK_WIN_POS_CENTER);
+ gtk_window_set_default_size(GTK_WINDOW(result), 600, 400);
+ gtk_window_set_type_hint(GTK_WINDOW(result), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+ ref= G_OBJECT(result);
+ g_object_set_data(ref, "binary", binary);
+
+ vbox1 = gtk_vbox_new(FALSE, 8);
+ gtk_widget_show(vbox1);
+ gtk_container_add(GTK_CONTAINER(result), vbox1);
+
+ /*
+ hbox1 = gtk_hbox_new(FALSE, 8);
+ gtk_widget_show(hbox1);
+ gtk_box_pack_start(GTK_BOX(vbox1), hbox1, FALSE, FALSE, 0);
+
+ label = qck_create_label(NULL, NULL, _("Binary :"));
+ gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
+
+ combobox = gtk_combo_box_new_text();
+ gtk_widget_show(combobox);
+ gtk_box_pack_start(GTK_BOX(hbox1), combobox, TRUE, TRUE, 0);
+ */
+
+ frame = qck_create_frame(_("<b>Content to display</b>"), &alignment, 4, 4, 12, 0);
+ gtk_box_pack_start(GTK_BOX(vbox1), frame, TRUE, TRUE, 0);
+
+
+
+
+ vbox2 = gtk_vbox_new(FALSE, 8);
+ gtk_widget_show(vbox2);
+ gtk_container_add(GTK_CONTAINER(alignment), vbox2);
+
+ hbox2 = gtk_hbox_new(FALSE, 8);
+ gtk_widget_show(hbox2);
+ gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE, FALSE, 0);
+
+ label = qck_create_label(NULL, NULL, _("Model :"));
+ gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
+
+ comboboxentry = qck_create_combobox(ref, "models", G_CALLBACK(NULL), NULL);
+ gtk_box_pack_start(GTK_BOX(hbox2), comboboxentry, TRUE, TRUE, 0);
+
+
+ button = qck_create_button_with_img(NULL, NULL, "gtk-add", G_CALLBACK(NULL), NULL);
+ gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, 0);
+
+ button = qck_create_button_with_img(NULL, NULL, "gtk-remove", G_CALLBACK(NULL), NULL);
+ gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, 0);
+
+
+
+
+ hbox3 = gtk_hbox_new(FALSE, 8);
+ gtk_widget_show(hbox3);
+ gtk_box_pack_start(GTK_BOX(vbox2), hbox3, TRUE, TRUE, 0);
+
+ scrolledwindow1 = gtk_scrolled_window_new(NULL, NULL);
+ gtk_widget_show(scrolledwindow1);
+ gtk_box_pack_start(GTK_BOX(hbox3), scrolledwindow1, TRUE, TRUE, 0);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow1), GTK_SHADOW_IN);
+
+
+
+
+
+
+ store = gtk_tree_store_new(PTC_COUNT, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ g_object_set_data(ref, "store", store);
+
+ treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+ gtk_widget_show(treeview);
+ gtk_container_add(GTK_CONTAINER(scrolledwindow1), treeview);
+
+ g_object_unref(G_OBJECT(store));
+ /*
+ column = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_visible(column, FALSE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+ gtk_tree_view_set_expander_column(GTK_TREE_VIEW(treeview), column);
+ */
+
+ renderer = gtk_cell_renderer_toggle_new();
+ gtk_cell_renderer_toggle_set_activatable(GTK_CELL_RENDERER_TOGGLE(renderer), TRUE);
+ column = gtk_tree_view_column_new_with_attributes(_("Active"), renderer, "active", PTC_ACTIVE, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+ g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(on_part_selection_toggle), ref);
+
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, "text", PTC_NAME, NULL);
+ gtk_tree_view_column_set_expand(column, TRUE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes(_("Start"), renderer, "text", PTC_START, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes(_("End"), renderer, "text", PTC_END, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+
+
+
+
+
+
+ vbuttonbox1 = gtk_vbutton_box_new();
+ gtk_widget_show(vbuttonbox1);
+ gtk_box_pack_start(GTK_BOX(hbox3), vbuttonbox1, FALSE, FALSE, 0);
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(vbuttonbox1), GTK_BUTTONBOX_SPREAD);
+
+
+
+
+ button = qck_create_button_with_img(NULL, NULL, "gtk-add", G_CALLBACK(NULL), NULL);
+ gtk_container_add(GTK_CONTAINER(vbuttonbox1), button);
+
+ button = qck_create_button_with_img(NULL, NULL, "gtk-remove", G_CALLBACK(NULL), NULL);
+ gtk_container_add(GTK_CONTAINER(vbuttonbox1), button);
+
+
+
+
+
+ hbuttonbox1 = gtk_hbutton_box_new();
+ gtk_widget_show(hbuttonbox1);
+ gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox1, FALSE, FALSE, 0);
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1), GTK_BUTTONBOX_END);
+
+
+ button = qck_create_button_from_stock(NULL, NULL, "gtk-ok", G_CALLBACK(NULL), NULL);
+ gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);
+
+ button = qck_create_button_from_stock(NULL, NULL, "gtk-cancel", G_CALLBACK(NULL), NULL);
+ gtk_container_add(GTK_CONTAINER(hbuttonbox1), button);
+
+
+
+
+
+
+ g_signal_connect(G_OBJECT(comboboxentry), "changed", G_CALLBACK(on_model_change), ref);
+
+ gtk_combo_box_append_text(GTK_COMBO_BOX(comboboxentry), _("Default"));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(comboboxentry), _("Routines"));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(comboboxentry), _("User"));
+
+ return result;
+
+}
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : project = informations sur le project actuellement ouvert. *
+* ref = espace de référencement principal. *
+* *
+* Description : Charge les sections sélectionnées pour le projet courant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void load_project_sections(void *project, GObject *ref)
+{
+
+
+
+ /*
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), _("Never automatically"));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), _("When the window gets the focus"));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), _("On click on the window"));
+
+ */
+
+}
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement principal. *
+* *
+* Description : Affiche les parties désassemblées par défaut. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void load_default_parts(GObject *ref)
+{
+ GOpenidaBinary *binary; /* Binaire à traiter */
+ GtkTreeStore *store; /* Modèle de gestion */
+ GExeFormat *format; /* Format associé au binaire */
+ GArchProcessor *proc; /* Architecture utilisée */
+ GBinPart **parts; /* Parties d'élément binaire */
+ size_t parts_count; /* Nombre de ces parties */
+ parts_model *model; /* Mémoire du modèle */
+ bool exist; /* Mémoire présente ? */
+ size_t i; /* Boucle de parcours */
+ off_t size; /* Taille de la partie */
+ vmpa_t addr; /* Adresse de départ */
+ char start[VMPA_MAX_SIZE]; /* Version humainement lisible */
+ char end[VMPA_MAX_SIZE]; /* Version humainement lisible */
+ GtkTreeIter iter; /* Point d'insertion */
+
+ binary = G_OPENIDA_BINARY(g_object_get_data(ref, "binary"));
+ store = GTK_TREE_STORE(g_object_get_data(ref, "store"));
+
+ format = g_openida_binary_get_format(binary);
+ proc = get_arch_processor_from_format(format);
+
+ parts = g_exe_format_get_parts(format, &parts_count);
+ qsort(parts, parts_count, sizeof(GBinPart *), g_binary_part_compare);
+
+ model = (parts_model *)g_object_get_data(ref, "default_model");
+ exist = (model != NULL);
+
+ if (!exist)
+ {
+ model = (parts_model *)calloc(1, sizeof(parts_model));
+ g_object_set_data(ref, "default_model", model);
+
+ model->selected = (gboolean *)calloc(parts_count, sizeof(gboolean));
+ model->count = parts_count;
+
+ }
+
+ for (i = 0; i < parts_count; i++)
+ {
+ g_binary_part_get_values(parts[i], NULL, &size, &addr);
+
+ vmpa_to_string(addr, g_arch_processor_get_memory_size(proc), start);
+ vmpa_to_string(addr + size, g_arch_processor_get_memory_size(proc), end);
+
+ if (!exist)
+ model->selected[i] = TRUE;
+
+ gtk_tree_store_append(store, &iter, NULL);
+ gtk_tree_store_set(store, &iter,
+ PTC_ACTIVE, model->selected[i],
+ PTC_NAME, g_binary_part_get_name(parts[i]),
+ PTC_START, start,
+ PTC_END, end,
+ -1);
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement principal. *
+* *
+* Description : Affiche les parties désassemblées selon les routines. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void load_routines_parts(GObject *ref)
+{
+ GOpenidaBinary *binary; /* Binaire à traiter */
+ GtkTreeStore *store; /* Modèle de gestion */
+ GExeFormat *format; /* Format associé au binaire */
+ GArchProcessor *proc; /* Architecture utilisée */
+ GBinRoutine **routines; /* Liste des routines trouvées */
+ size_t routines_count; /* Nombre de ces routines */
+ parts_model *model; /* Mémoire du modèle */
+ bool exist; /* Mémoire présente ? */
+ size_t i; /* Boucle de parcours */
+ vmpa_t addr; /* Adresse à transcrire */
+ char start[VMPA_MAX_SIZE]; /* Version humainement lisible */
+ char end[VMPA_MAX_SIZE]; /* Version humainement lisible */
+ GtkTreeIter iter; /* Point d'insertion */
+
+ binary = G_OPENIDA_BINARY(g_object_get_data(ref, "binary"));
+ store = GTK_TREE_STORE(g_object_get_data(ref, "store"));
+
+ format = g_openida_binary_get_format(binary);
+ proc = get_arch_processor_from_format(format);
+
+ routines = g_binary_format_get_routines(G_BIN_FORMAT(format), &routines_count);
+ qsort(routines, routines_count, sizeof(GBinRoutine *), g_binary_routine_compare);
+
+ model = (parts_model *)g_object_get_data(ref, "routines_model");
+ exist = (model != NULL);
+
+ if (!exist)
+ {
+ model = (parts_model *)calloc(1, sizeof(parts_model));
+ g_object_set_data(ref, "routines_model", model);
+
+ model->selected = (gboolean *)calloc(routines_count, sizeof(gboolean));
+ model->count = routines_count;
+
+ }
+
+ for (i = 0; i < routines_count; i++)
+ {
+ addr = g_binary_routine_get_address(routines[i]);
+ vmpa_to_string(addr, g_arch_processor_get_memory_size(proc), start);
+
+ addr += g_binary_routine_get_size(routines[i]);
+ vmpa_to_string(addr, g_arch_processor_get_memory_size(proc), end);
+
+ if (!exist)
+ model->selected[i] = TRUE;
+
+ gtk_tree_store_append(store, &iter, NULL);
+ gtk_tree_store_set(store, &iter,
+ PTC_ACTIVE, model->selected[i],
+ PTC_NAME, g_binary_routine_get_name(routines[i]),
+ PTC_START, start,
+ PTC_END, end,
+ -1);
+
+ }
+
+}
+
+
+
+
+
+static void user_function(GtkButton *button, GObject *ref)
+{
+
+
+
+
+
+
+
+
+}
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : combo = liste des modèles proposés. *
+* ref = espace de référencement principal. *
+* *
+* Description : Réagit à un changement de modèle. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void on_model_change(GtkComboBox *combo, GObject *ref)
+{
+ gint index; /* Indice du nouveau modèle */
+ GtkTreeStore *store; /* Modèle de gestion */
+
+ store = GTK_TREE_STORE(g_object_get_data(ref, "store"));
+ gtk_tree_store_clear(store);
+
+ index = gtk_combo_box_get_active(combo);
+
+ switch (index)
+ {
+ case BPM_DEFAULT:
+ load_default_parts(ref);
+ break;
+
+ case BPM_ROUTINES:
+ load_routines_parts(ref);
+ break;
+
+ case BPM_USER:
+ break;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : renderer = cellule de rendu à mettre à jour. *
+* path = chemin menant à la ligne concernée. *
+* ref = espace de référencement principal. *
+* *
+* Description : Réagit à un changement de sélection de partie. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void on_part_selection_toggle(GtkCellRendererToggle *renderer, gchar *path, GObject *ref)
+{
+ GtkTreeModel *model; /* Modèle de représentation */
+ GtkTreeIter iter; /* Lieu de la mise à jour */
+ gboolean state; /* Etat de la sélection */
+ GtkComboBox *combo; /* Liste de tous les modèles */
+ gint index; /* Indice du modèle courant */
+ parts_model *list; /* Mémorisation des sélections */
+
+
+ printf("path :: %s\n", path);
+
+ model = GTK_TREE_MODEL(g_object_get_data(ref, "store"));
+
+ if (gtk_tree_model_get_iter_from_string(model, &iter, path))
+ {
+ gtk_tree_model_get(model, &iter, PTC_ACTIVE, &state, -1);
+
+ combo = GTK_COMBO_BOX(g_object_get_data(ref, "models"));
+ index = gtk_combo_box_get_active(combo);
+
+ switch (index)
+ {
+ case BPM_DEFAULT:
+ list = (parts_model *)g_object_get_data(ref, "default_model");
+ break;
+
+ case BPM_ROUTINES:
+ list = (parts_model *)g_object_get_data(ref, "routines_model");
+ break;
+
+ case BPM_USER:
+ break;
+
+ }
+
+ list->selected[atoi(path)] = !state;
+
+ gtk_tree_store_set(GTK_TREE_STORE(model), &iter,
+ PTC_ACTIVE, !state,
+ -1);
+
+ }
+
+}
diff --git a/src/dialogs/binparts.h b/src/dialogs/binparts.h
new file mode 100644
index 0000000..dd7fa5e
--- /dev/null
+++ b/src/dialogs/binparts.h
@@ -0,0 +1,42 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * dlg_sections.h - prototypes pour la boîte de dialogue permettant une sélection des sections
+ *
+ * Copyright (C) 2008 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _DLG_SECTIONS_H
+#define _DLG_SECTIONS_H
+
+
+#include <gtk/gtk.h>
+
+
+#include "../analysis/binary.h"
+
+
+
+/* Construit la fenêtre de sélection des sections. */
+GtkWidget *create_sections_dialog(GOpenidaBinary *);
+
+
+
+
+
+#endif /* _DLG_SECTIONS_H */