summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog30
-rw-r--r--po/fr.po45
-rw-r--r--src/dialogs/export.c345
-rw-r--r--src/editor.c33
-rw-r--r--src/glibext/gbufferline.c35
-rw-r--r--src/glibext/gbufferline.h4
-rw-r--r--src/glibext/gbuffersegment.h12
-rw-r--r--src/glibext/gcodebuffer.c221
-rw-r--r--src/glibext/gcodebuffer.h8
-rw-r--r--src/gui/menus/Makefile.am1
-rw-r--r--src/gui/menus/binary.c98
-rw-r--r--src/gui/menus/binary.h41
-rw-r--r--src/gui/menus/menubar.c7
13 files changed, 562 insertions, 318 deletions
diff --git a/ChangeLog b/ChangeLog
index 55216e9..3f9669a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+12-03-11 Cyrille Bagard <nocbos@gmail.com>
+
+ * po/fr.po:
+ Update translations relative to the exportation dialog.
+
+ * src/dialogs/export.c:
+ Update the exportation dialog.
+
+ * src/editor.c:
+ Remove old code.
+
+ * src/glibext/gbufferline.c:
+ * src/glibext/gbufferline.h:
+ * src/glibext/gbuffersegment.h:
+ Start to be able to export lines content.
+
+ * src/glibext/gcodebuffer.c:
+ * src/glibext/gcodebuffer.h:
+ Define a way to scan all lines of a code buffer.
+
+ * src/gui/menus/binary.c:
+ * src/gui/menus/binary.h:
+ New entries: provide a Binary menu.
+
+ * src/gui/menus/Makefile.am:
+ Add the binary.[ch] files to libguimenus_la_SOURCES.
+
+ * src/gui/menus/menubar.c:
+ Load the Binary menu.
+
12-03-07 Cyrille Bagard <nocbos@gmail.com>
* src/arch/dalvik/operands/pool.c:
diff --git a/po/fr.po b/po/fr.po
index be4b328..2b4935f 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -55,8 +55,9 @@ msgstr ""
#: src/analysis/decomp/decompiler.c:92 src/analysis/decomp/decompiler.c:95
#: src/analysis/disass/disassembler.c:324
#: src/analysis/disass/disassembler.c:327
+#: src/dialogs/add_shellcode.c:645 src/dialogs/export.c:306
msgid "File: "
-msgstr ""
+msgstr "Fichier: "
#: src/analysis/binary.c:348
msgid "default"
@@ -230,7 +231,7 @@ msgstr ""
#: src/dialogs/add_shellcode.c:281 src/dialogs/add_shellcode.c:795
#: src/dialogs/export.c:456
msgid "Code"
-msgstr ""
+msgstr "Code"
#: src/dialogs/add_shellcode.c:489
msgid "<span color=\"red\"><b>Error while decoding</b></span>"
@@ -274,40 +275,24 @@ msgid "Architecture"
msgstr ""
#: src/dialogs/add_shellcode.c:629 src/dialogs/export.c:290
-msgid "Format : "
-msgstr ""
+msgid "Format: "
+msgstr "Format : "
#: src/dialogs/add_shellcode.c:635 src/dialogs/export.c:296
msgid "Simple text"
-msgstr ""
-
-#: src/dialogs/add_shellcode.c:645 src/dialogs/export.c:306
-msgid "File : "
-msgstr ""
+msgstr "Texte simple"
#: src/dialogs/add_shellcode.c:657 src/dialogs/export.c:318
msgid "Output"
-msgstr ""
+msgstr "Sortie"
#: src/dialogs/add_shellcode.c:723 src/dialogs/export.c:384
msgid "Choose an output filename"
-msgstr ""
-
-#: src/dialogs/add_shellcode.c:784 src/dialogs/export.c:445
-msgid "<b>Lines to process</b>"
-msgstr ""
-
-#: src/dialogs/add_shellcode.c:791 src/dialogs/export.c:452
-msgid "Prologue"
-msgstr ""
-
-#: src/dialogs/add_shellcode.c:799 src/dialogs/export.c:460
-msgid "Comments"
-msgstr ""
+msgstr "Choisir un fichier de sortie"
#: src/dialogs/add_shellcode.c:805 src/dialogs/export.c:466
msgid "<b>Items to display</b>"
-msgstr ""
+msgstr "<b>Eléments à afficher</b>"
#: src/dialogs/add_shellcode.c:812 src/dialogs/export.c:473 src/editor.c:348
msgid "Virtual address"
@@ -319,19 +304,19 @@ msgstr "Code binaire"
#: src/dialogs/add_shellcode.c:820 src/dialogs/export.c:481
msgid "Assembly code"
-msgstr ""
+msgstr "Code d'assembleur"
#: src/dialogs/add_shellcode.c:827 src/dialogs/export.c:488
msgid "Exported content"
-msgstr ""
+msgstr "Contenu exporté"
#: src/dialogs/export.c:151
msgid "Export assistant"
-msgstr ""
+msgstr "Assistant d'exportation"
#: src/dialogs/export.c:612
msgid "Exporting binary lines..."
-msgstr ""
+msgstr "Exportation des lignes binaires..."
#: src/panel/strings.c:87 src/panels/breaks.c:189 src/panels/strings.c:87
msgid "Address"
@@ -516,7 +501,7 @@ msgstr ""
#: src/editor.c:402
msgid "_Binary"
-msgstr ""
+msgstr "_Binaire"
#: src/editor.c:409
msgid "Select parts..."
@@ -528,7 +513,7 @@ msgstr ""
#: src/editor.c:418
msgid "Export..."
-msgstr ""
+msgstr "Exportation..."
#: src/editor.c:430
msgid "Start process"
diff --git a/src/dialogs/export.c b/src/dialogs/export.c
index 69841f3..c485fd7 100644
--- a/src/dialogs/export.c
+++ b/src/dialogs/export.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* export.c - assistant d'exportation de contenu binaire
*
- * Copyright (C) 2010 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -24,24 +24,33 @@
#include "export.h"
+#include <fcntl.h>
+#include <malloc.h>
#include <stdio.h>
-#include <string.h>
+#include <unistd.h>
+
+
+#include <i18n.h>
-#include "../analysis/exporter.h"
-#include "../glibext/delayed-int.h"
#include "../gtkext/easygtk.h"
-#ifndef _
-# define _(str) str
-#endif
+/* ------------------------ PARTIE PRINCIPALE DE L'ASSISTANT ------------------------ */
+/* Conservation des informations utiles */
+struct _export_data
+{
+ int fd; /* Flux ouvert en écriture */
+ BufferExportType type; /* Type d'exportation */
+ bool addr; /* Affichage des adresses */
+ bool code; /* Affichage du code binaire */
+ bool content; /* Affichage du contenu humain */
-/* ------------------------ PARTIE PRINCIPALE DE L'ASSISTANT ------------------------ */
+};
/* Ferme l'assistant sans dérouler la procédure. */
@@ -50,6 +59,9 @@ static void export_assistant_cancel(GtkAssistant *, gpointer);
/* Ferme l'assistant et déroule la procédure. */
static void export_assistant_close(GtkAssistant *, GObject *);
+/* Assure l'exportation en différé. */
+static bool export_buffer_line(GCodeBuffer *, GBufferLine *, struct _export_data *);
+
/* -------------------- DEFINITION DES REGLAGES DE L'EXPORTATION -------------------- */
@@ -73,55 +85,6 @@ static void on_filename_browsing_clicked(GtkButton *, GObject *);
static void register_content_panel(GtkAssistant *);
-
-/* ------------------------- EXPORTATION DE BINAIRE DIFFERE ------------------------- */
-
-
-#define G_TYPE_DELAYED_EXPORT g_delayed_export_get_type()
-#define G_DELAYED_EXPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_delayed_export_get_type(), GDelayedExport))
-#define G_IS_DELAYED_EXPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_delayed_export_get_type()))
-#define G_DELAYED_EXPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DELAYED_EXPORT, GDelayedExportClass))
-#define G_IS_DELAYED_EXPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DELAYED_EXPORT))
-#define G_DELAYED_EXPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DELAYED_EXPORT, GDelayedExportClass))
-
-
-/* Ensembles binaires à désassembler (instance) */
-typedef struct _GDelayedExport
-{
- GDelayedWork parent; /* A laisser en premier */
-
- char *filename; /* Fichier à remplir */
-
- GOpenidaBinary *binary; /* Destinataire final */
- GRenderingOptions *options; /* Options d'exportation */
-
-} GDelayedExport;
-
-/* Ensembles binaires à désassembler (classe) */
-typedef struct _GDelayedExportClass
-{
- GDelayedWorkClass parent; /* A laisser en premier */
-
-} GDelayedExportClass;
-
-
-/* Indique le type défini pour les tâches d'exportation différée. */
-static GType g_delayed_export_get_type(void);
-
-/* Initialise la classe des tâches d'exportation différée. */
-static void g_delayed_export_class_init(GDelayedExportClass *);
-
-/* Initialise une tâche d'exportation différée. */
-static void g_delayed_export_init(GDelayedExport *);
-
-/* Crée une tâche d'exportation différée. */
-static GDelayedExport *g_delayed_export_new(const char *, GOpenidaBinary *, GRenderingOptions *);
-
-/* Assure l'exportation en différé. */
-static void g_delayed_export_process(GDelayedExport *, GtkExtStatusBar *);
-
-
-
/* ---------------------------------------------------------------------------------- */
/* PARTIE PRINCIPALE DE L'ASSISTANT */
/* ---------------------------------------------------------------------------------- */
@@ -202,49 +165,91 @@ static void export_assistant_cancel(GtkAssistant *assistant, gpointer data)
static void export_assistant_close(GtkAssistant *assistant, GObject *ref)
{
- GOpenidaBinary *binary; /* Binaire chargé à parcourir */
- GExeFormat *format; /* Format du binaire */
- GRenderingOptions *options; /* Options d'exportation */
- GtkToggleButton *checkbutton; /* Coche à retrouver */
- gboolean state; /* Valeur à prendre en compte */
GtkEntry *entry; /* Zone de saisie */
const gchar *filename; /* Chemin d'accès du fichier */
- GDelayedExport *export; /* Procédure d'exportation */
- GWorkQueue *queue; /* Gestionnaire de différés */
+ int fd; /* Descripteur de la sortie */
+ struct _export_data *export; /* Informations à faire suivre */
+ GtkToggleButton *checkbutton; /* Coche à retrouver */
+ GOpenidaBinary *binary; /* Binaire chargé à parcourir */
+ GCodeBuffer *buffer; /* Tampon de code à traiter */
- binary = G_OPENIDA_BINARY(g_object_get_data(ref, "binary"));
+ /* Fichier de sortie */
+
+ entry = GTK_ENTRY(g_object_get_data(ref, "filename"));
+ filename = gtk_entry_get_text(entry);
+
+ fd = open(filename, O_CREAT | O_WRONLY);
+ if (fd == -1)
+ {
+ perror("open");
+ return;
+ }
- format = g_openida_binary_get_format(binary);
- options = g_rendering_options_new(format);
+ export = (struct _export_data *)calloc(1, sizeof(struct _export_data));
+
+ export->fd = fd;
+
+ /* Type d'exportation */
+
+ export->type = BET_TEXT;
/* Eléments à afficher */
checkbutton = GTK_TOGGLE_BUTTON(g_object_get_data(ref, "virtual_addr"));
- state = gtk_toggle_button_get_active(checkbutton);
- g_rendering_options_show_address(options, MRD_BLOCK, state);
+ export->addr = gtk_toggle_button_get_active(checkbutton);
checkbutton = GTK_TOGGLE_BUTTON(g_object_get_data(ref, "binary_code"));
- state = gtk_toggle_button_get_active(checkbutton);
- g_rendering_options_show_code(options, MRD_BLOCK, state);
+ export->code = gtk_toggle_button_get_active(checkbutton);
checkbutton = GTK_TOGGLE_BUTTON(g_object_get_data(ref, "assembly_code"));
- state = gtk_toggle_button_get_active(checkbutton);
+ export->content = gtk_toggle_button_get_active(checkbutton);
/* Programmation de la tâche */
- entry = GTK_ENTRY(g_object_get_data(ref, "filename"));
- filename = gtk_entry_get_text(entry);
+ binary = G_OPENIDA_BINARY(g_object_get_data(ref, "binary"));
- export = g_delayed_export_new(filename, binary, options);
+ buffer = g_openida_binary_get_disassembled_buffer(binary);
- queue = get_work_queue();
- g_work_queue_schedule_work(queue, G_DELAYED_WORK(export));
+ g_buffer_code_scan(buffer, 0, VMPA_MAX, _("Exporting binary lines..."),
+ (process_line_fc)export_buffer_line, export);
gtk_widget_destroy(GTK_WIDGET(assistant));
}
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon de code contenant toutes les lignes. *
+* line = ligne dont le contenu est à exporter. *
+* export = informations utiles à la manoeuvre. *
+* *
+* Description : Assure l'exportation en différé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool export_buffer_line(GCodeBuffer *buffer, GBufferLine *line, struct _export_data *export)
+{
+ /* Si les traitements sont terminés... */
+ if (line == NULL)
+ {
+ close(export->fd);
+ free(export);
+ }
+
+ else
+ g_buffer_line_export(line, export->fd, export->type,
+ export->addr, export->code, export->content);
+
+ return true;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* DEFINITION DES REGLAGES DE L'EXPORTATION */
@@ -287,7 +292,7 @@ static void register_output_panel(GtkAssistant *assistant)
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
- label = qck_create_label(NULL, NULL, _("Format : "));
+ label = qck_create_label(NULL, NULL, _("Format: "));
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
combobox = qck_create_combobox(NULL, NULL, G_CALLBACK(NULL), NULL);
@@ -303,7 +308,7 @@ static void register_output_panel(GtkAssistant *assistant)
gtk_widget_show(hbox);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
- label = qck_create_label(NULL, NULL, _("File : "));
+ label = qck_create_label(NULL, NULL, _("File: "));
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
entry = qck_create_entry(G_OBJECT(assistant), "filename", NULL);
@@ -326,7 +331,7 @@ static void register_output_panel(GtkAssistant *assistant)
filename = g_openida_binary_get_filename(binary);
gtk_entry_set_text(GTK_ENTRY(entry), filename);
- gtk_entry_append_text(GTK_ENTRY(entry), ".txt");
+ gtk_editable_insert_text(GTK_EDITABLE(entry), ".txt", -1, (gint []) { strlen(filename) });
g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(on_export_filename_changed), assistant);
@@ -388,7 +393,7 @@ static void on_filename_browsing_clicked(GtkButton *button, GObject *ref)
NULL);
entry = GTK_ENTRY(g_object_get_data(ref, "filename"));
- gtk_file_chooser_set_filename(dialog, gtk_entry_get_text(entry));
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), gtk_entry_get_text(entry));
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
@@ -429,10 +434,8 @@ static void register_content_panel(GtkAssistant *assistant)
GtkWidget *vbox; /* Support principal */
GtkWidget *frame; /* Support avec encadrement */
GtkWidget *subalign; /* Disposition des options */
-
- GtkWidget *vbox3;
+ GtkWidget *sub_vbox; /* Division verticale */
GtkWidget *checkbutton; /* Coche pour une option */
- GtkWidget *vbox4;
alignment = qck_create_padded_alignment(8, 8, 8, 8);
@@ -440,46 +443,25 @@ static void register_content_panel(GtkAssistant *assistant)
gtk_widget_show(vbox);
gtk_container_add(GTK_CONTAINER(alignment), vbox);
- /* Lignes à traiter */
-
- frame = qck_create_frame(_("<b>Lines to process</b>"), &subalign, 0, 0, 12, 0);
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
-
- vbox3 = gtk_vbox_new(FALSE, 0);
- gtk_widget_show(vbox3);
- gtk_container_add(GTK_CONTAINER(subalign), vbox3);
-
- checkbutton = qck_create_check_button(G_OBJECT(assistant), "prologue", _("Prologue"), NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox3), checkbutton, FALSE, FALSE, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
-
- checkbutton = qck_create_check_button(G_OBJECT(assistant), "code", _("Code"), NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox3), checkbutton, FALSE, FALSE, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
-
- checkbutton = qck_create_check_button(G_OBJECT(assistant), "comments", _("Comments"), NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox3), checkbutton, FALSE, FALSE, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
-
/* Eléments à afficher */
frame = qck_create_frame(_("<b>Items to display</b>"), &subalign, 0, 0, 12, 0);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
- vbox4 = gtk_vbox_new(FALSE, 0);
- gtk_widget_show(vbox4);
- gtk_container_add(GTK_CONTAINER(subalign), vbox4);
+ sub_vbox = gtk_vbox_new(FALSE, 0);
+ gtk_widget_show(sub_vbox);
+ gtk_container_add(GTK_CONTAINER(subalign), sub_vbox);
checkbutton = qck_create_check_button(G_OBJECT(assistant), "virtual_addr", _("Virtual address"), NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox4), checkbutton, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(sub_vbox), checkbutton, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
checkbutton = qck_create_check_button(G_OBJECT(assistant), "binary_code", _("Binary code"), NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox4), checkbutton, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(sub_vbox), checkbutton, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
checkbutton = qck_create_check_button(G_OBJECT(assistant), "assembly_code", _("Assembly code"), NULL, NULL);
- gtk_box_pack_start(GTK_BOX(vbox4), checkbutton, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(sub_vbox), checkbutton, FALSE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton), TRUE);
/* Intégration */
@@ -491,144 +473,3 @@ static void register_content_panel(GtkAssistant *assistant)
gtk_assistant_set_page_complete(assistant, alignment, TRUE);
}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* EXPORTATION DE BINAIRE DIFFERE */
-/* ---------------------------------------------------------------------------------- */
-
-
-/* Indique le type défini pour les tâches d'exportation différée. */
-G_DEFINE_TYPE(GDelayedExport, g_delayed_export, G_TYPE_DELAYED_WORK);
-
-
-/******************************************************************************
-* *
-* Paramètres : klass = classe à initialiser. *
-* *
-* Description : Initialise la classe des tâches d'exportation différée. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_delayed_export_class_init(GDelayedExportClass *klass)
-{
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : disass = instance à initialiser. *
-* *
-* Description : Initialise une tâche d'exportation différée. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_delayed_export_init(GDelayedExport *disass)
-{
- G_DELAYED_WORK(disass)->run = (run_task_fc)g_delayed_export_process;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : filename = chemin d'accès au fichier à remplir. *
-* binary = binaire chargé dont le contenu est à exporter. *
-* options = options d'exportation à respecter. *
-* *
-* Description : Crée une tâche d'exportation différée. *
-* *
-* Retour : Tâche créée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static GDelayedExport *g_delayed_export_new(const char *filename, GOpenidaBinary *binary, GRenderingOptions *options)
-{
- GDelayedExport *result; /* Tâche à retourner */
-
- result = g_object_new(G_TYPE_DELAYED_EXPORT, NULL);
-
- result->filename = strdup(filename);
-
- result->binary = binary;
- result->options = options;
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : export = analyse à mener. *
-* statusbar = barre de statut à tenir informée. *
-* *
-* Description : Assure l'exportation en différé. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_delayed_export_process(GDelayedExport *export, GtkExtStatusBar *statusbar)
-{
- FILE *stream; /* Flux ouvert en écriture */
- GRenderingLine *lines; /* Liste de lignes à intégrer */
- vmpa_t start; /* Adresse de début de parcours*/
- GRenderingLine *iter; /* Boucle de parcours */
- vmpa_t end; /* Adresse de fin de parcours */
- guint id; /* Identifiant de statut */
- size_t ret; /* Quantité d'octets écrite */
- vmpa_t done; /* Quantité déjà parcourue */
-
- stream = fopen(export->filename, "w");
- if (stream == NULL)
- {
- perror("fopen");
- return;
- }
-
- lines = g_openida_binary_get_lines(export->binary);
- if (lines == NULL) return; /* FIXME ? */
-
- start = get_rendering_line_address(lines);
-
- iter = g_rendering_line_get_last_iter(lines, NULL);
- end = get_rendering_line_address(iter) + get_rendering_line_length(iter) - start;
-
- id = gtk_extended_status_bar_push(statusbar, _("Exporting binary lines..."), true);
-
- for (iter = lines;
- iter != NULL;
- iter = g_rendering_line_get_next_iter(lines, iter, NULL))
- {
- /* TODO : filtre... */
-
- g_content_exporter_add_text(G_CONTENT_EXPORTER(iter), export->options, MRD_BLOCK, stream);
-
- ret = fwrite("\n", 1, sizeof(char), stream);
- if (ret != 1) perror("fwrite");
-
- done = get_rendering_line_address(iter) + get_rendering_line_length(iter) - start;
- gtk_extended_status_bar_update_activity(statusbar, id, done * 1.0 / end);
-
- }
-
- gtk_extended_status_bar_remove(statusbar, id);
-
- fclose(stream);
-
-}
diff --git a/src/editor.c b/src/editor.c
index 757b0c9..d40f9ae 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -54,7 +54,6 @@
#include "debug/debugger.h"
//#include "dialogs/add_shellcode.h"
#include "dialogs/binparts.h"
-#include "dialogs/export.h"
#include "dialogs/plugins.h"
#include "gui/menus/menubar.h"
#include "gui/panels/panel.h"
@@ -99,9 +98,6 @@ static void mcb_binary_select_parts(GtkMenuItem *, GObject *);
/* Réagit avec le menu "Binaire -> Sélectionner les greffons...". */
static void mcb_binary_select_plugins(GtkMenuItem *, GObject *);
-/* Réagit au menu "Binaire -> Exporter...". */
-static void mcb_binary_export(GtkMenuItem *, GObject *);
-
/* Réagit avec le menu "Débogage -> Démarrer". */
void mcb_debug_start(GtkCheckMenuItem *, gpointer);
@@ -331,13 +327,6 @@ GtkWidget *create_editor(void)
submenuitem = qck_create_menu_item(NULL, NULL, _("Select plugins..."), G_CALLBACK(mcb_binary_select_plugins), ref);
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_export", _("Export..."), G_CALLBACK(mcb_binary_export), ref);
- gtk_container_add(GTK_CONTAINER(menubar), submenuitem);
-
-
menuitem = gtk_menu_item_new_with_mnemonic(_("_Debug"));
gtk_widget_show(menuitem);
@@ -882,28 +871,6 @@ static void mcb_binary_select_plugins(GtkMenuItem *menuitem, GObject *ref)
}
-/******************************************************************************
-* *
-* Paramètres : menuitem = élément de menu sélectionné. *
-* ref = adresse de l'espace de référencement global. *
-* *
-* Description : Réagit au menu "Binaire -> Exporter...". *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void mcb_binary_export(GtkMenuItem *menuitem, GObject *ref)
-{
- GOpenidaBinary *binary; /* Edition courante */
-
- binary = (GOpenidaBinary *)g_object_get_data(ref, "current_binary");
-
- run_export_assistant(binary, GTK_WINDOW(ref));
-
-}
diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c
index cc99ee8..6017bdd 100644
--- a/src/glibext/gbufferline.c
+++ b/src/glibext/gbufferline.c
@@ -550,3 +550,38 @@ void g_buffer_line_draw(GBufferLine *line, GdkDrawable *drawable, GdkGC *gc, con
}
}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : line = ligne de texte à manipuler. *
+* fd = flux ouvert en écriture. *
+* type = type d'exportation attendue. *
+* addr = indique si les positions doivent être affichées. *
+* code = indique si le code binaire doit être affiché. *
+* content = indique si le gros du contenu doit être affiché. *
+* *
+* Description : Exporte la ligne de texte représentée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_buffer_line_export(GBufferLine *line, int fd, BufferExportType type, bool addr, bool code, bool content)
+{
+ BufferLineColumn i; /* Boucle de parcours */
+
+ for (i = BLC_ADDRESS; i < BLC_COUNT; i++)
+ {
+ if (i == BLC_ADDRESS && !addr) continue;
+ if (i == BLC_BINARY && !code) continue;
+ if (!(i == BLC_ADDRESS || i == BLC_BINARY) && !content) continue;
+
+ dprintf(fd, "TODO\n");
+
+ }
+
+}
diff --git a/src/glibext/gbufferline.h b/src/glibext/gbufferline.h
index 66ec2b0..b5de831 100644
--- a/src/glibext/gbufferline.h
+++ b/src/glibext/gbufferline.h
@@ -30,6 +30,7 @@
#include "gbuffersegment.h"
+#include "../arch/archbase.h"
@@ -126,6 +127,9 @@ void g_buffer_line_start_merge_at(GBufferLine *, BufferLineColumn);
/* Imprime la ligne de texte représentée. */
void g_buffer_line_draw(GBufferLine *, GdkDrawable *, GdkGC *, const gint [BLC_COUNT], gint, gint, bool, bool);
+/* Exporte la ligne de texte représentée. */
+void g_buffer_line_export(GBufferLine *, int, BufferExportType, bool, bool, bool);
+
#endif /* _GLIBEXT_GBUFFERLINE_H */
diff --git a/src/glibext/gbuffersegment.h b/src/glibext/gbuffersegment.h
index 5731415..b335ab6 100644
--- a/src/glibext/gbuffersegment.h
+++ b/src/glibext/gbuffersegment.h
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* gbuffersegment.h - prototypes pour la concentration d'un fragment de caractères aux propriétés communes
*
- * Copyright (C) 2010 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -40,6 +40,16 @@
+/* Types d'exportation */
+typedef enum _BufferExportType
+{
+ BET_TEXT,
+
+ BET_COUNT
+
+} BufferExportType;
+
+
/* Fragment de caractères aux propriétés communes (instance) */
typedef struct _GBufferSegment GBufferSegment;
diff --git a/src/glibext/gcodebuffer.c b/src/glibext/gcodebuffer.c
index 373f33b..8ebc284 100644
--- a/src/glibext/gcodebuffer.c
+++ b/src/glibext/gcodebuffer.c
@@ -25,9 +25,66 @@
#include <malloc.h>
+#include <string.h>
#include <sys/param.h>
+#include "../glibext/delayed-int.h"
+
+
+
+/* -------------------------- PARCOURS DU CODE D'UN TAMPON -------------------------- */
+
+
+#define G_TYPE_BUFFER_SCAN g_buffer_scan_get_type()
+#define G_BUFFER_SCAN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_buffer_scan_get_type(), GDelayedExport))
+#define G_IS_BUFFER_SCAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_buffer_scan_get_type()))
+#define G_BUFFER_SCAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BUFFER_SCAN, GDelayedExportClass))
+#define G_IS_BUFFER_SCAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BUFFER_SCAN))
+#define G_BUFFER_SCAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BUFFER_SCAN, GDelayedExportClass))
+
+
+/* Ensembles binaires à désassembler (instance) */
+typedef struct _GBufferScan
+{
+ GDelayedWork parent; /* A laisser en premier */
+
+ GCodeBuffer *buffer; /* Tampon à manipuler */
+
+ vmpa_t start; /* Début du parcours ou 0 */
+ vmpa_t end; /* Fin du parcours ou VMPA_MAX */
+
+ char *message; /* Message de progression */
+
+ process_line_fc process; /* Fonction de traitement réel */
+ void *user_data; /* Données à faire suivre */
+
+} GBufferScan;
+
+/* Ensembles binaires à désassembler (classe) */
+typedef struct _GBufferScanClass
+{
+ GDelayedWorkClass parent; /* A laisser en premier */
+
+} GBufferScanClass;
+
+
+/* Indique le type défini pour les tâches d'exportation différée. */
+static GType g_buffer_scan_get_type(void);
+
+/* Initialise la classe des tâches d'exportation différée. */
+static void g_buffer_scan_class_init(GBufferScanClass *);
+
+/* Initialise une tâche d'exportation différée. */
+static void g_buffer_scan_init(GBufferScan *);
+
+/* Crée une tâche d'exportation différée. */
+static GBufferScan *g_buffer_scan_new(GCodeBuffer *, vmpa_t, vmpa_t, const char *, process_line_fc, void *);
+
+/* Assure l'exportation en différé. */
+static void g_buffer_scan_process(GBufferScan *, GtkExtStatusBar *);
+
+
/* -------------------------- TAMPON POUR CODE DESASSEMBLE -------------------------- */
@@ -111,6 +168,138 @@ static void g_buffer_view_compute_required_widths(GBufferView *);
/* ---------------------------------------------------------------------------------- */
+/* PARCOURS DU CODE D'UN TAMPON */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour les tâches d'exportation différée. */
+G_DEFINE_TYPE(GBufferScan, g_buffer_scan, G_TYPE_DELAYED_WORK);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des tâches d'exportation différée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_buffer_scan_class_init(GBufferScanClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : disass = instance à initialiser. *
+* *
+* Description : Initialise une tâche d'exportation différée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_buffer_scan_init(GBufferScan *disass)
+{
+ G_DELAYED_WORK(disass)->run = (run_task_fc)g_buffer_scan_process;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon à manipuler. *
+* start = première adresse visée ou 0. *
+* end = dernière adresse visée ou VMPA_MAX. *
+* message = message à afficher lors de la progression. *
+* process = fonction assurant le traitement effectif. *
+* data = données utilisateur à faire suivre. *
+* *
+* Description : Crée une tâche d'exportation différée. *
+* *
+* Retour : Tâche créée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GBufferScan *g_buffer_scan_new(GCodeBuffer *buffer, vmpa_t start, vmpa_t end, const char *message, process_line_fc process, void *data)
+{
+ GBufferScan *result; /* Tâche à retourner */
+
+ result = g_object_new(G_TYPE_BUFFER_SCAN, NULL);
+
+ result->buffer = buffer;
+ g_object_ref(G_OBJECT(buffer));
+
+ result->start = start;
+ result->end = end;
+
+ result->message = strdup(message);
+
+ result->process = process;
+ result->user_data = data;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : scan = parcours à mener. *
+* statusbar = barre de statut à tenir informée. *
+* *
+* Description : Assure l'exportation en différé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_buffer_scan_process(GBufferScan *scan, GtkExtStatusBar *statusbar)
+{
+ size_t first; /* Première ligne visée */
+ size_t last; /* Dernière ligne visée + 1 */
+ GBufferLine **lines; /* Liste des lignes à traiter */
+ guint id; /* Identifiant de statut */
+ size_t i; /* Boucle de parcours */
+
+ first = 0;
+ last = (scan->buffer->used > 0 ? scan->buffer->used - 1 : 0);
+
+ lines = scan->buffer->lines;
+
+ id = gtk_extended_status_bar_push(statusbar, scan->message, true);
+
+ for (i = first; i <= last; i++)
+ {
+ if (!scan->process(scan->buffer, lines[i], scan->user_data))
+ break;
+
+ gtk_extended_status_bar_update_activity(statusbar, id,
+ (i - first) * 1.0 / (last - first));
+
+ }
+
+ gtk_extended_status_bar_remove(statusbar, id);
+
+ /* Avertit le commanditaire... */
+ scan->process(scan->buffer, NULL, scan->user_data);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
/* TAMPON POUR CODE DESASSEMBLE */
/* ---------------------------------------------------------------------------------- */
@@ -209,6 +398,36 @@ GBufferLine *g_code_buffer_append_new_line(GCodeBuffer *buffer)
}
+/******************************************************************************
+* *
+* Paramètres : buffer = tampon de données à utiliser. *
+* start = première adresse visée ou 0. *
+* end = dernière adresse visée ou VMPA_MAX. *
+* message = message à afficher lors de la progression. *
+* process = fonction assurant le traitement effectif. *
+* data = données utilisateur à faire suivre. *
+* *
+* Description : Lance un parcours des différentes lignes du tampon de code. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_buffer_code_scan(GCodeBuffer *buffer, vmpa_t start, vmpa_t end, const char *message, process_line_fc process, void *data)
+{
+ GBufferScan *scan; /* Procédure de parcours */
+ GWorkQueue *queue; /* Gestionnaire de différés */
+
+ scan = g_buffer_scan_new(buffer, start, end, message, process, data);
+
+ queue = get_work_queue();
+ g_work_queue_schedule_work(queue, G_DELAYED_WORK(scan));
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* VUE PARTICULIERE D'UN TAMPON DE CODE */
@@ -436,7 +655,7 @@ void g_buffer_view_define_extra_drawing(GBufferView *view, buffer_line_draw_fc m
* addr = indique si les positions doivent être affichées. *
* code = indique si le code binaire doit être affiché. *
* *
-* Description : Imprime la visualisation du tempon de code désassemblé. *
+* Description : Imprime la visualisation du tampon de code désassemblé. *
* *
* Retour : - *
* *
diff --git a/src/glibext/gcodebuffer.h b/src/glibext/gcodebuffer.h
index 811a479..dee114e 100644
--- a/src/glibext/gcodebuffer.h
+++ b/src/glibext/gcodebuffer.h
@@ -59,6 +59,12 @@ GCodeBuffer *g_code_buffer_new(void);
/* Ajoute une nouvelle ligne à un tampon pour code désassemblé. */
GBufferLine *g_code_buffer_append_new_line(GCodeBuffer *);
+/* Traitement d'une ligne parcourue. */
+typedef bool (* process_line_fc) (GCodeBuffer *, GBufferLine *, void *);
+
+/* Exporte dans un fichier le tampon de code désassemblé. */
+void g_buffer_code_scan(GCodeBuffer *, vmpa_t, vmpa_t, const char *, process_line_fc, void *);
+
/* ---------------------- VUE PARTICULIERE D'UN TAMPON DE CODE ---------------------- */
@@ -94,7 +100,7 @@ void g_buffer_view_get_size(GBufferView *, gint *, gint *, bool, bool);
/* Définit à une procédure à appeler lors des dessins de ligne. */
void g_buffer_view_define_extra_drawing(GBufferView *, buffer_line_draw_fc, void *);
-/* Imprime la visualisation du tempon de code désassemblé. */
+/* Imprime la visualisation du tampon de code désassemblé. */
void g_buffer_view_draw(const GBufferView *, const GdkEventExpose *, GdkGC *, gint, gint, bool, bool);
/* Fournit la ligne présente à une ordonnée donnée. */
diff --git a/src/gui/menus/Makefile.am b/src/gui/menus/Makefile.am
index 4640fd8..0f41d14 100644
--- a/src/gui/menus/Makefile.am
+++ b/src/gui/menus/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libguimenus.la
libguimenus_la_SOURCES = \
+ binary.h binary.c \
debug.h debug.c \
file.h file.c \
help.h help.c \
diff --git a/src/gui/menus/binary.c b/src/gui/menus/binary.c
new file mode 100644
index 0000000..ac59444
--- /dev/null
+++ b/src/gui/menus/binary.c
@@ -0,0 +1,98 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * binary.c - gestion du menu 'Binaire'
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This binary 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 "binary.h"
+
+
+#include <i18n.h>
+
+
+#include "../editem-int.h"
+#include "../../dialogs/export.h"
+#include "../../gtkext/easygtk.h"
+
+
+
+/* Réagit au menu "Binaire -> Exporter...". */
+static void mcb_binary_export(GtkMenuItem *, GMenuBar *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement global. *
+* accgroup = groupe d'accélérateurs pour les menus. *
+* bar = barre de menu parente. *
+* *
+* Description : Construit le menu "Binaire". *
+* *
+* Retour : Panneau de menus mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkWidget *build_menu_binary(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *bar)
+{
+ GtkWidget *result; /* Support à retourner */
+ GtkWidget *menubar; /* Support pour éléments */
+ GtkWidget *submenuitem; /* Sous-élément de menu */
+
+ result = gtk_menu_item_new_with_mnemonic(_("_Binary"));
+ gtk_widget_show(result);
+
+ menubar = gtk_menu_new();
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar);
+
+ submenuitem = qck_create_menu_item(ref, "mnu_binary_export", _("Export..."),
+ G_CALLBACK(mcb_binary_export), bar);
+ gtk_container_add(GTK_CONTAINER(menubar), submenuitem);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : menuitem = élément de menu sélectionné. *
+* bar = barre de menu parente. *
+* *
+* Description : Réagit au menu "Binaire -> Exporter...". *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void mcb_binary_export(GtkMenuItem *menuitem, GMenuBar *bar)
+{
+ GOpenidaBinary *binary; /* Edition courante */
+
+ binary = g_editor_item_get_current_binary(G_EDITOR_ITEM(bar));
+
+ run_export_assistant(binary, GTK_WINDOW(G_EDITOR_ITEM(bar)->ref));
+
+}
diff --git a/src/gui/menus/binary.h b/src/gui/menus/binary.h
new file mode 100644
index 0000000..67007f5
--- /dev/null
+++ b/src/gui/menus/binary.h
@@ -0,0 +1,41 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * binary.h - prototypes pour la gestion du menu 'Binaire'
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This binary 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
+ */
+
+
+#ifndef _GUI_MENUS_BINARY_H
+#define _GUI_MENUS_BINARY_H
+
+
+#include <gtk/gtk.h>
+
+
+#include "menubar.h"
+
+
+
+/* Construit le menu "Binaire". */
+GtkWidget *build_menu_binary(GObject *, GtkAccelGroup *, GMenuBar *);
+
+
+
+#endif /* _GUI_MENUS_BINARY_H */
diff --git a/src/gui/menus/menubar.c b/src/gui/menus/menubar.c
index a7559cd..cb6e58a 100644
--- a/src/gui/menus/menubar.c
+++ b/src/gui/menus/menubar.c
@@ -25,6 +25,7 @@
#include "menubar.h"
+#include "binary.h"
#include "debug.h"
#include "file.h"
#include "help.h"
@@ -42,6 +43,7 @@ struct _GMenuBar
GtkWidget *file; /* Menu "Fichier" */
GtkWidget *view; /* Menu "Affichage" */
GtkWidget *project; /* Menu "Projet" */
+ GtkWidget *binary; /* Menu "Binaire" */
GtkWidget *debug; /* Menu "Débogage" */
GtkWidget *help; /* Menu "Aide" */
@@ -163,6 +165,11 @@ GEditorItem *g_menu_bar_new(GObject *ref, GtkAccelGroup *accgroup)
result->project = build_menu_project(ref, accgroup, result);
gtk_container_add(GTK_CONTAINER(item->widget), result->project);
+ /* Binaire */
+
+ result->binary = build_menu_binary(ref, accgroup, result);
+ gtk_container_add(GTK_CONTAINER(item->widget), result->binary);
+
/* Débogage */
result->debug = build_menu_debug(ref, accgroup);