summaryrefslogtreecommitdiff
path: root/src/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dialogs')
-rw-r--r--src/dialogs/Makefile.am1
-rw-r--r--src/dialogs/gotox.c367
-rw-r--r--src/dialogs/gotox.h44
3 files changed, 412 insertions, 0 deletions
diff --git a/src/dialogs/Makefile.am b/src/dialogs/Makefile.am
index 54b6fa2..1fe821a 100644
--- a/src/dialogs/Makefile.am
+++ b/src/dialogs/Makefile.am
@@ -6,6 +6,7 @@ libdialogs_la_SOURCES = \
bookmark.h bookmark.c \
export.h export.c \
goto.h goto.c \
+ gotox.h gotox.c \
plugins.h plugins.c \
shellcode.h shellcode.c \
storage.h storage.c
diff --git a/src/dialogs/gotox.c b/src/dialogs/gotox.c
new file mode 100644
index 0000000..653a969
--- /dev/null
+++ b/src/dialogs/gotox.c
@@ -0,0 +1,367 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * goto.c - boîte de dialogue pour les sauts à une adresse donnée
+ *
+ * Copyright (C) 2012-2014 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "gotox.h"
+
+
+#include <cairo-gobject.h>
+#include <malloc.h>
+
+
+#include <i18n.h>
+
+
+#include "../gtkext/easygtk.h"
+#include "../gtkext/support.h"
+
+
+
+/* Colonnes de la liste des symboles */
+typedef enum _GotoXColumn
+{
+ GXC_PHYSICAL, /* Correspondance physique */
+ GXC_VIRTUAL, /* Correspondance virtuelle */
+
+ GXC_PICTURE, /* Image de représentation */
+ GXC_ADDRESS, /* Adresse mémoire du symbole */
+ GXC_NAME, /* Désignation humaine */
+ GXC_CONTENT, /* Contenu de la ligne visée */
+
+ GXC_COUNT /* Nombre de colonnes */
+
+} GotoXColumn;
+
+
+
+/* Ajoute une nouvelle localisation de destination. */
+static void add_new_location_to_list(GtkTreeStore *, GLoadedBinary *, const vmpa2t *, GBinSymbol *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : parent = fenêtre parente à surpasser. *
+* binary = binaire dont les points d'entrée sont à afficher. *
+* *
+* Description : Construit la fenêtre de sélection des sections. *
+* *
+* Retour : Adresse de la fenêtre mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkWidget *create_gotox_dialog(GtkWindow *parent, GLoadedBinary *binary)
+{
+ GtkWidget *result; /* Fenêtre à renvoyer */
+ GtkWidget *dlgvbox; /* Zone principale de la boîte */
+ GtkWidget *vbox; /* Support à construire #1 */
+ GtkWidget *scrollwnd; /* Support défilant */
+ GtkWidget *treeview; /* Affichage de la liste */
+ GtkCellRenderer *renderer; /* Moteur de rendu de colonne */
+ GtkTreeViewColumn *column; /* Colonne de la liste */
+ GtkTreeStore *store; /* Modèle de gestion */
+ GBinFormat *format; /* Format associé au binaire */
+ GBinSymbol **symbols; /* Symboles à représenter */
+ size_t sym_count; /* Qté de symboles présents */
+ size_t i; /* Boucle de parcours */
+ vmpa2t addr; /* Localisation de symbole */
+
+ result = gtk_dialog_new();
+ gtk_window_set_title(GTK_WINDOW(result), _("Binary's entry points"));
+ gtk_window_set_default_size(GTK_WINDOW(result), 600, 350);
+ gtk_window_set_position(GTK_WINDOW(result), GTK_WIN_POS_CENTER);
+ gtk_window_set_modal(GTK_WINDOW(result), TRUE);
+ gtk_window_set_type_hint(GTK_WINDOW(result), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+ dlgvbox = gtk_dialog_get_content_area(GTK_DIALOG(result));
+ gtk_widget_show(dlgvbox);
+
+ vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
+ gtk_widget_show(vbox);
+ gtk_box_pack_start(GTK_BOX(dlgvbox), vbox, TRUE, TRUE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
+
+ /* Liste arborescente ou linéaire */
+
+ scrollwnd = gtk_scrolled_window_new(NULL, NULL);
+ gtk_widget_show(scrollwnd);
+ gtk_box_pack_start(GTK_BOX(vbox), scrollwnd, TRUE, TRUE, 0);
+
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwnd), GTK_SHADOW_IN);
+
+ store = gtk_tree_store_new(GXC_COUNT,
+ G_TYPE_UINT64, G_TYPE_UINT64,
+ CAIRO_GOBJECT_TYPE_SURFACE,
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+
+ treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
+ gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(treeview), TRUE);
+
+ g_object_set_data(G_OBJECT(result), "treeview", treeview);
+
+ gtk_widget_show(treeview);
+ gtk_container_add(GTK_CONTAINER(scrollwnd), treeview);
+
+ /* Cellules d'affichage */
+
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes(_("Address"), renderer,
+ "markup", GXC_ADDRESS,
+ NULL);
+ gtk_tree_view_column_set_sort_column_id(column, GXC_ADDRESS);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ column = gtk_tree_view_column_new();
+
+ gtk_tree_view_column_set_title(column, _("Name"));
+
+ renderer = gtk_cell_renderer_pixbuf_new();
+ gtk_tree_view_column_pack_start(column, renderer, FALSE);
+ gtk_tree_view_column_set_attributes(column, renderer,
+ "surface", GXC_PICTURE,
+ NULL);
+
+ g_object_set(G_OBJECT(renderer), "xpad", 4, NULL);
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(column, renderer, TRUE);
+ gtk_tree_view_column_set_attributes(column, renderer,
+ "text", GXC_NAME,
+ NULL);
+
+ gtk_tree_view_column_set_sort_column_id(column, GXC_NAME);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes(_("Content"), renderer,
+ "markup", GXC_CONTENT,
+ NULL);
+ gtk_tree_view_column_set_sort_column_id(column, GXC_CONTENT);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+ /* Zone de validation */
+
+ gtk_dialog_add_button(GTK_DIALOG(result), _("_Cancel"), GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button(GTK_DIALOG(result), _("_Go"), GTK_RESPONSE_OK);
+
+ /* Affichage de tous les points d'entrées */
+
+ format = G_BIN_FORMAT(g_loaded_binary_get_format(binary));
+
+ symbols = g_binary_format_get_symbols(format, &sym_count);
+
+ for (i = 0; i < sym_count; i++)
+ {
+ if (g_binary_symbol_get_target_type(symbols[i]) != STP_ENTRY_POINT)
+ continue;
+
+ copy_vmpa(&addr, get_mrange_addr(g_binary_symbol_get_range(symbols[i])));
+
+ add_new_location_to_list(store, binary, &addr, symbols[i]);
+
+ }
+
+ g_object_unref(G_OBJECT(store));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : store = modèle de gestionnaire pour la liste affichée. *
+* binary = représentation du binaire chargé en mémoire. *
+* addr = localisation à venir ajouter à la liste. *
+* hint = éventuel symbole à venir retrouver à l'adresse. *
+* *
+* Description : Ajoute une nouvelle localisation de destination. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void add_new_location_to_list(GtkTreeStore *store, GLoadedBinary *binary, const vmpa2t *addr, GBinSymbol *hint)
+{
+ GCodeBuffer *buffer; /* Tampon de désassemblage */
+ GBufferLine *line; /* Ligne présente à l'adresse */
+ char *virtual; /* Transcription d'adresse */
+ const char *label; /* Etiquette de symbole trouvé */
+ GBinFormat *format; /* Format associé au binaire */
+ GBinSymbol *symbol; /* Symbole associé à l'adresse */
+ phys_t diff; /* Décalage vis à vis du début */
+ char *name; /* Désignation humaine */
+ gchar *filename; /* Chemin d'accès à utiliser */
+ cairo_surface_t *icon; /* Image pour les symboles */
+ char *content; /* Contenu de la ligne visée */
+ GtkTreeIter iter; /* Point d'insertion */
+
+ /* Adresse en mémoire virtuelle */
+
+ buffer = g_loaded_binary_get_disassembled_buffer(binary);
+ line = g_code_buffer_find_line_by_addr(buffer, addr);
+
+ if (line != NULL)
+ virtual = g_buffer_line_get_text(line, BLC_VIRTUAL, BLC_VIRTUAL + 1, true);
+ else
+ virtual = strdup(_("<line address not found>"));
+
+ /* Désignation humaine de l'adresse */
+
+ if (hint != NULL)
+ {
+ symbol = hint;
+ g_object_ref(G_OBJECT(symbol));
+
+ label = g_binary_symbol_get_label(hint);
+
+ name = make_symbol_offset(label, 0);
+
+ }
+ else
+ {
+ format = G_BIN_FORMAT(g_loaded_binary_get_format(binary));
+
+ if (g_binary_format_resolve_symbol(format, addr, &symbol, &diff))
+ {
+ label = g_binary_symbol_get_label(symbol);
+
+ name = make_symbol_offset(label, diff);
+
+ }
+ else
+ {
+ symbol = NULL;
+
+ name = strdup(_("<no symbol found>"));
+
+ }
+
+ }
+
+ /* Image de représentation */
+
+ switch (g_binary_symbol_get_target_type(symbol))
+ {
+ case STP_ENTRY_POINT:
+ filename = find_pixmap_file("entrypoint.png");
+ break;
+
+ default:
+ filename = NULL;
+ break;
+
+ }
+
+ if (filename != NULL)
+ {
+ icon = cairo_image_surface_create_from_png(filename);
+ g_free(filename);
+ }
+ else
+ icon = NULL;
+
+ /* Contenu d'assemblage */
+
+ if (line != NULL)
+ content = g_buffer_line_get_text(line, BLC_ASSEMBLY_HEAD, BLC_COUNT, true);
+ else
+ content = strdup(_("<assembly line not found>"));
+
+ /* Insertion finale */
+
+ gtk_tree_store_append(store, &iter, NULL);
+
+ gtk_tree_store_set(store, &iter,
+ GXC_PHYSICAL, PHYS_CAST(get_phy_addr(addr)),
+ GXC_VIRTUAL, VIRT_CAST(get_virt_addr(addr)),
+ GXC_PICTURE, icon,
+ GXC_ADDRESS, virtual,
+ GXC_NAME, name,
+ GXC_CONTENT, content,
+ -1);
+
+ if (symbol != NULL)
+ g_object_unref(G_OBJECT(symbol));
+
+ if (virtual != NULL) free(virtual);
+ if (icon != NULL) cairo_surface_destroy(icon);
+ free(name);
+ if (content != NULL) free(content);
+
+ if (line != NULL)
+ g_object_unref(G_OBJECT(line));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : dialog = boîte de dialogue ayant reçu une validation. *
+* *
+* Description : Fournit l'adresse obtenue par la saisie de l'utilisateur. *
+* *
+* Retour : Adresse reccueillie par la boîte de dialogue ou NULL si rien.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+vmpa2t *get_address_from_gotox_dialog(GtkWidget *dialog)
+{
+ vmpa2t *result; /* Adresse à retourner */
+ GtkTreeView *treeview; /* Liste d'adresses à lire */
+ GtkTreeSelection *selection; /* Sélection courante */
+ GtkTreeModel *model; /* Modèle de gestionnaire */
+ GList *selected; /* Liste des sélections */
+ GtkTreeIter iter; /* Tête de lecture */
+ G_TYPE_PHYS phys; /* Position physique */
+ G_TYPE_VIRT virt; /* Adresse virtuelle */
+
+ treeview = GTK_TREE_VIEW(g_object_get_data(G_OBJECT(dialog), "treeview"));
+
+ selection = gtk_tree_view_get_selection(treeview);
+
+ selected = gtk_tree_selection_get_selected_rows(selection, &model);
+ if (selected == NULL) return NULL;
+
+ if (!gtk_tree_model_get_iter(model, &iter, (GtkTreePath *)selected->data))
+ return NULL;
+
+ gtk_tree_model_get(model, &iter,
+ GXC_PHYSICAL, &phys,
+ GXC_VIRTUAL, &virt,
+ -1);
+
+ result = make_vmpa(phys, virt);
+
+ g_list_free_full(selected, (GDestroyNotify)gtk_tree_path_free);
+
+ return result;
+
+}
diff --git a/src/dialogs/gotox.h b/src/dialogs/gotox.h
new file mode 100644
index 0000000..1153478
--- /dev/null
+++ b/src/dialogs/gotox.h
@@ -0,0 +1,44 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * goto.h - prototypes pour la boîte de dialogue pour les sauts à une adresse donnée
+ *
+ * Copyright (C) 2012 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _DIALOGS_GOTOX_H
+#define _DIALOGS_GOTOX_H
+
+
+#include <gtk/gtk.h>
+
+
+#include "../analysis/binary.h"
+#include "../arch/vmpa.h"
+
+
+
+/* Construit la fenêtre de saut à une adresse. */
+GtkWidget *create_gotox_dialog(GtkWindow *, GLoadedBinary *);
+
+/* Fournit l'adresse obtenue par la saisie de l'utilisateur. */
+vmpa2t *get_address_from_gotox_dialog(GtkWidget *);
+
+
+
+#endif /* _DIALOGS_GOTOX_H */