summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--src/analysis/binary.c306
-rw-r--r--src/analysis/binary.h35
-rw-r--r--src/analysis/disass/disassembler.c2
-rw-r--r--src/analysis/project.c116
5 files changed, 443 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index cfd9dbb..8a4be68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+16-12-31 Cyrille Bagard <nocbos@gmail.com>
+
+ * src/analysis/binary.c:
+ * src/analysis/binary.h:
+ Load binaires without blocking the GUI during the process.
+
+ * src/analysis/disass/disassembler.c:
+ Typo.
+
+ * src/analysis/project.c:
+ Update code.
+
16-12-30 Cyrille Bagard <nocbos@gmail.com>
* configure.ac:
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index ac8863e..281a375 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -47,11 +47,12 @@
#include "../core/params.h"
#include "../core/processors.h"
#include "../glibext/chrysamarshal.h"
+#include "../glibext/delayed-int.h"
#include "../gui/panels/log.h"
-/* ------------------------ DESASSEMBLAGE DE BINAIRE DIFFERE ------------------------ */
+/* ------------------------ ENCADREMENTS D'UN BINAIRE CHARGE ------------------------ */
/* Description de fichier binaire (instance) */
@@ -141,6 +142,73 @@ static bool g_loaded_binary_connect_remote(GLoadedBinary *);
+/* ----------------------- CHARGEMENT DE BINAIRE NON BLOQUANT ----------------------- */
+
+
+#define G_TYPE_BINARY_LOADER g_binary_loader_get_type()
+#define G_BINARY_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BINARY_LOADER, GBinaryLoader))
+#define G_IS_BINARY_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BINARY_LOADER))
+#define G_BINARY_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BINARY_LOADER, GBinaryLoaderClass))
+#define G_IS_BINARY_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BINARY_LOADER))
+#define G_BINARY_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BINARY_LOADER, GBinaryLoaderClass))
+
+
+/* Chargement non bloquant d'un binaire (instance) */
+struct _GBinaryLoader
+{
+ GDelayedWork parent; /* A laisser en premier */
+
+ bool from_content; /* Sélection de champs */
+
+ union
+ {
+ GBinContent *content; /* Contenu brut à disposition */
+
+ struct
+ {
+ char *filename; /* Chemin vers l'ensemble XML */
+ char *path; /* Chemin de la définition XML */
+ GStudyProject *project; /* Accès aux contenus liés */
+
+ };
+
+ };
+
+ GLoadedBinary *binary; /* Résultat du chargement */
+
+};
+
+/* Chargement non bloquant d'un binaire (classe) */
+struct _GBinaryLoaderClass
+{
+ GDelayedWorkClass parent; /* A laisser en premier */
+
+};
+
+
+/* Indique le type défini pour le chargement non bloquant d'un binaire. */
+GType g_binary_loader_get_type(void);
+
+/* Initialise la classe des tâches de chargement non bloquant. */
+static void g_binary_loader_class_init(GBinaryLoaderClass *);
+
+/* Initialise une tâche de chargement non bloquant d'un binaire. */
+static void g_binary_loader_init(GBinaryLoader *);
+
+/* Supprime toutes les références externes. */
+static void g_binary_loader_dispose(GBinaryLoader *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_binary_loader_finalize(GBinaryLoader *);
+
+/* Réalise le chargement effectif d'un binaire. */
+static void g_binary_loader_process(GBinaryLoader *, GtkStatusStack *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* ENCADREMENTS D'UN BINAIRE CHARGE */
+/* ---------------------------------------------------------------------------------- */
/* Indique le type défini pour une description de fichier binaire. */
@@ -370,8 +438,7 @@ GLoadedBinary *g_loaded_binary_new(GBinContent *content)
/******************************************************************************
* *
-* Paramètres : content = contenu binaire chargé en mémoire. *
-* context = contexte pour les recherches XPath. *
+* Paramètres : context = contexte pour les recherches XPath. *
* path = chemin d'accès au noeud XML à lire. *
* project = projet dans lequel venir rechercher les contenus. *
* *
@@ -1695,3 +1762,236 @@ void ack_completed_disassembly(GDelayedDisassembly *disass, GLoadedBinary *binar
g_signal_emit_by_name(binary, "disassembly-done");
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* CHARGEMENT DE BINAIRE NON BLOQUANT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour le chargement non bloquant d'un binaire. */
+G_DEFINE_TYPE(GBinaryLoader, g_binary_loader, G_TYPE_DELAYED_WORK);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des tâches de chargement non bloquant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_loader_class_init(GBinaryLoaderClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GDelayedWorkClass *work; /* Version en classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_loader_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_binary_loader_finalize;
+
+ work = G_DELAYED_WORK_CLASS(klass);
+
+ work->run = (run_task_fc)g_binary_loader_process;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : loader = instance à initialiser. *
+* *
+* Description : Initialise une tâche de chargement non bloquant d'un binaire.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_loader_init(GBinaryLoader *loader)
+{
+ loader->binary = NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : loader = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_loader_dispose(GBinaryLoader *loader)
+{
+ if (loader->from_content)
+ g_object_unref(G_OBJECT(loader->content));
+
+ else
+ g_object_unref(G_OBJECT(loader->project));
+
+ if (loader->binary != NULL)
+ g_object_unref(G_OBJECT(loader->binary));
+
+ G_OBJECT_CLASS(g_binary_loader_parent_class)->dispose(G_OBJECT(loader));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : loader = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_loader_finalize(GBinaryLoader *loader)
+{
+ if (!loader->from_content)
+ {
+ free(loader->filename);
+ free(loader->path);
+ }
+
+ G_OBJECT_CLASS(g_binary_loader_parent_class)->finalize(G_OBJECT(loader));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire chargé en mémoire. *
+* *
+* Description : Prépare le chargement non bloqué d'un contenu binaire. *
+* *
+* Retour : Instance de binaire chargé ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinaryLoader *g_binary_loader_new(GBinContent *content)
+{
+ GBinaryLoader *result; /* Tâche à retourner */
+
+ result = g_object_new(G_TYPE_BINARY_LOADER, NULL);
+
+ result->from_content = true;
+
+ result->content = content;
+ g_object_ref(G_OBJECT(content));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : filename = chemin d'accès au fichier à charger. *
+* path = chemin d'accès au noeud XML à lire. *
+* project = projet dans lequel venir rechercher les contenus. *
+* *
+* Description : Prépare le chargement non bloqué d'un contenu XML. *
+* *
+* Retour : Instance de binaire chargé ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinaryLoader *g_binary_loader_new_from_xml(const char *filename, const char *path, GStudyProject *project)
+{
+ GBinaryLoader *result; /* Tâche à retourner */
+
+ result = g_object_new(G_TYPE_BINARY_LOADER, NULL);
+
+ result->from_content = false;
+
+ result->filename = strdup(filename);
+ result->path = strdup(path);
+ result->project = project;
+ g_object_ref(G_OBJECT(project));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : loader = encadrement du chargement à mener. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Réalise le chargement effectif d'un binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_binary_loader_process(GBinaryLoader *loader, GtkStatusStack *status)
+{
+ xmlDocPtr xdoc; /* Structure XML chargée */
+ xmlXPathContextPtr context; /* Contexte pour les XPath */
+
+ if (loader->from_content)
+ loader->binary = g_loaded_binary_new(loader->content);
+
+ else
+ {
+ if (open_xml_file(loader->filename, &xdoc, &context))
+ {
+ loader->binary = g_loaded_binary_new_from_xml(context, loader->path, loader->project);
+
+ close_xml_file(xdoc, context);
+
+ }
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : loader = encadrement du chargement à consulter. *
+* *
+* Description : Retourne l'instance du binaire chargé en cas de succès. *
+* *
+* Retour : Instance mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GLoadedBinary *g_binary_loader_get_result(const GBinaryLoader *loader)
+{
+ GLoadedBinary *result; /* Chargement à faire suivre */
+
+ result = loader->binary;
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
diff --git a/src/analysis/binary.h b/src/analysis/binary.h
index 501ffe6..deb8815 100644
--- a/src/analysis/binary.h
+++ b/src/analysis/binary.h
@@ -45,6 +45,9 @@ typedef struct _GStudyProject GStudyProject;
+/* ------------------------ ENCADREMENTS D'UN BINAIRE CHARGE ------------------------ */
+
+
#define G_TYPE_LOADED_BINARY g_loaded_binary_get_type()
#define G_LOADED_BINARY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_loaded_binary_get_type(), GLoadedBinary))
#define G_IS_LOADED_BINARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_loaded_binary_get_type()))
@@ -196,4 +199,36 @@ bool *g_loaded_binary_display_decomp_lines(GLoadedBinary *);
+/* ----------------------- CHARGEMENT DE BINAIRE NON BLOQUANT ----------------------- */
+
+
+#define G_TYPE_BINARY_LOADER g_binary_loader_get_type()
+#define G_BINARY_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BINARY_LOADER, GBinaryLoader))
+#define G_IS_BINARY_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BINARY_LOADER))
+#define G_BINARY_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BINARY_LOADER, GBinaryLoaderClass))
+#define G_IS_BINARY_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BINARY_LOADER))
+#define G_BINARY_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BINARY_LOADER, GBinaryLoaderClass))
+
+
+/* Chargement non bloquant d'un binaire (instance) */
+typedef struct _GBinaryLoader GBinaryLoader;
+
+/* Chargement non bloquant d'un binaire (classe) */
+typedef struct _GBinaryLoaderClass GBinaryLoaderClass;
+
+
+/* Indique le type défini pour le chargement non bloquant d'un binaire. */
+GType g_binary_loader_get_type(void);
+
+/* Prépare le chargement non bloqué d'un contenu binaire. */
+GBinaryLoader *g_binary_loader_new(GBinContent *);
+
+/* Prépare le chargement non bloqué d'un contenu XML. */
+GBinaryLoader *g_binary_loader_new_from_xml(const char *, const char *, GStudyProject *);
+
+/* Retourne l'instance du binaire chargé en cas de succès. */
+GLoadedBinary *g_binary_loader_get_result(const GBinaryLoader *);
+
+
+
#endif /* _ANALYSIS_BINARY_H */
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 246a5b2..086d95f 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -165,7 +165,7 @@ static void g_delayed_disassembly_init(GDelayedDisassembly *disass)
/******************************************************************************
* *
-* Paramètres : binary = instance d'objet GLib à traiter. *
+* Paramètres : disass = instance d'objet GLib à traiter. *
* *
* Description : Supprime toutes les références externes. *
* *
diff --git a/src/analysis/project.c b/src/analysis/project.c
index 4251dcc..5775d72 100644
--- a/src/analysis/project.c
+++ b/src/analysis/project.c
@@ -103,6 +103,12 @@ static void g_study_project_class_init(GStudyProjectClass *);
/*Initialise une instance de projet d'étude. */
static void g_study_project_init(GStudyProject *);
+/* Acquitte la fin d'un chargement différé et complet. */
+static void ack_loaded_binary_with_content(GBinaryLoader *, GStudyProject *);
+
+/* Acquitte la fin d'un chargement différé et complet. */
+static void ack_loaded_binary(GBinaryLoader *, GStudyProject *);
+
/* Supprime de l'écran un projet en place. */
static void g_study_project_hide(const GStudyProject *);
@@ -233,7 +239,8 @@ GStudyProject *g_study_project_new(GObject *ref)
/******************************************************************************
* *
-* Paramètres : filename = chemin d'accès au fichier à charger. *
+* Paramètres : ref = espace de référencements global. *
+* filename = chemin d'accès au fichier à charger. *
* *
* Description : Crée un projet à partir du contenu XML d'un fichier. *
* *
@@ -258,7 +265,8 @@ GStudyProject *g_study_project_open(GObject *ref, const char *filename)
long state; /* Etat de ce contenu binaire */
bool status; /* Bilan d'une lecture */
GDelayedStudy *dstudy; /* Etude complémentaire à mener*/
- GLoadedBinary *binary; /* Représentation à intégrer */
+ GBinaryLoader *loader; /* Dispositif de chargement */
+ GWorkQueue *queue; /* Gestionnaire de différés */
if (!open_xml_file(filename, &xdoc, &context)) return NULL;
@@ -343,17 +351,14 @@ GStudyProject *g_study_project_open(GObject *ref, const char *filename)
access = calloc(access_len, sizeof(char));
snprintf(access, access_len, "/ChrysalideProject/Binaries/Binary[position()=%u]", i + 1);
- binary = g_loaded_binary_new_from_xml(context, access, result);
+ loader = g_binary_loader_new_from_xml(filename, access, result);
free(access);
- if (binary != NULL)
- {
- g_signal_connect_to_main(binary, "disassembly-done",
- G_CALLBACK(g_study_project_add_loaded_binary), result,
- g_cclosure_marshal_VOID__VOID);
- g_loaded_binary_analyse(binary);
- }
+ g_signal_connect(loader, "work-completed", G_CALLBACK(ack_loaded_binary), result);
+
+ queue = get_work_queue();
+ g_work_queue_schedule_work(queue, G_DELAYED_WORK(loader), DEFAULT_WORK_GROUP);
}
@@ -550,6 +555,76 @@ GBinContent *g_study_project_find_binary_content_by_hash(GStudyProject *project,
}
+/******************************************************************************
+* *
+* Paramètres : loader = travail de chargement mené à bien. *
+* project = lieu d'intégration des résultats obtenus. *
+* *
+* Description : Acquitte la fin d'un chargement différé et complet. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void ack_loaded_binary_with_content(GBinaryLoader *loader, GStudyProject *project)
+{
+ GLoadedBinary *binary; /* Binaire désormais en place */
+ GExeFormat *format; /* Format de données reconnu */
+ GBinContent *content; /* Contenu binaire d'origine */
+
+ binary = g_binary_loader_get_result(loader);
+
+ if (binary != NULL)
+ {
+ format = g_loaded_binary_get_format(binary);
+ content = g_binary_format_get_content(G_BIN_FORMAT(format));
+
+ g_study_project_add_binary_content(project, content, PCS_ROOT/* FIXME : dstudy->state*/);
+
+ g_object_unref(G_OBJECT(content));
+ g_object_unref(G_OBJECT(format));
+
+ ack_loaded_binary(loader, project);
+
+ g_object_unref(G_OBJECT(binary));
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : loader = travail de chargement mené à bien. *
+* project = lieu d'intégration des résultats obtenus. *
+* *
+* Description : Acquitte la fin d'un chargement différé et complet. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void ack_loaded_binary(GBinaryLoader *loader, GStudyProject *project)
+{
+ GLoadedBinary *binary; /* Binaire désormais en place */
+
+ binary = g_binary_loader_get_result(loader);
+
+ if (binary != NULL)
+ {
+ g_signal_connect_to_main(binary, "disassembly-done",
+ G_CALLBACK(g_study_project_add_loaded_binary), project,
+ g_cclosure_marshal_VOID__VOID);
+
+ g_loaded_binary_analyse(binary);
+
+ }
+
+}
/******************************************************************************
@@ -1126,8 +1201,6 @@ void push_project_into_recent_list(const GStudyProject *project)
/* Constitution de la liste des projets récents */
- /* Constitution de la liste des projets récents */
-
manager = get_projects_manager();
qualified = (char *)calloc(strlen("file://") + strlen(project->filename) + 1, sizeof(char));
@@ -1300,7 +1373,8 @@ static void g_delayed_study_process(GDelayedStudy *dstudy, GtkStatusStack *statu
{
FormatMatchStatus mstatus; /* Statut d'une reconnaissance */
char *target; /* Sous-traitance requise */
- GLoadedBinary *binary; /* Représentation chargée */
+ GBinaryLoader *loader; /* Dispositif de chargement */
+ GWorkQueue *queue; /* Gestionnaire de différés */
mstatus = find_matching_format(dstudy->content, NULL, &target);
@@ -1313,19 +1387,13 @@ static void g_delayed_study_process(GDelayedStudy *dstudy, GtkStatusStack *statu
else
{
- binary = g_loaded_binary_new(dstudy->content);
-
- if (binary != NULL)
- {
- g_study_project_add_binary_content(dstudy->project, dstudy->content, dstudy->state);
-
- g_signal_connect_to_main(binary, "disassembly-done",
- G_CALLBACK(g_study_project_add_loaded_binary),
- dstudy->project, g_cclosure_marshal_VOID__VOID);
+ loader = g_binary_loader_new(dstudy->content);
- g_loaded_binary_analyse(binary);
+ g_signal_connect(loader, "work-completed", G_CALLBACK(ack_loaded_binary_with_content),
+ dstudy->project);
- }
+ queue = get_work_queue();
+ g_work_queue_schedule_work(queue, G_DELAYED_WORK(loader), DEFAULT_WORK_GROUP);
}