summaryrefslogtreecommitdiff
path: root/src/analysis/binary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r--src/analysis/binary.c306
1 files changed, 303 insertions, 3 deletions
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;
+
+}