summaryrefslogtreecommitdiff
path: root/src/dialogs
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-03-11 14:05:58 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-03-11 14:05:58 (GMT)
commitd1f5881c1f4ad53781fdadfe5ce6cac24cee3bab (patch)
treeb81348afa4b348590740d189f1b78dabb3ae254c /src/dialogs
parent9714ddda44f92f2939299c6b0aa203d549c32b0d (diff)
Updated the exportation dialog.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@239 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/dialogs')
-rw-r--r--src/dialogs/export.c345
1 files changed, 93 insertions, 252 deletions
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);
-
-}