summaryrefslogtreecommitdiff
path: root/src/analysis/contents/encapsulated.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/contents/encapsulated.c')
-rw-r--r--src/analysis/contents/encapsulated.c195
1 files changed, 76 insertions, 119 deletions
diff --git a/src/analysis/contents/encapsulated.c b/src/analysis/contents/encapsulated.c
index dadc0a5..e0e6ed1 100644
--- a/src/analysis/contents/encapsulated.c
+++ b/src/analysis/contents/encapsulated.c
@@ -28,7 +28,7 @@
#include <string.h>
-#include "../content-int.h"
+#include "encapsulated-int.h"
#include "../db/misc/rlestr.h"
#include "../storage/serialize-int.h"
#include "../../common/extstr.h"
@@ -38,40 +38,12 @@
/* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */
-/* Contenu de issu d'un contenu plus global (instance) */
-struct _GEncapsContent
-{
- GObject parent; /* A laisser en premier */
-
- GBinContent *base; /* Base offrant une extraction */
- char *path; /* Chemin vers le contenu ciblé*/
- GBinContent *endpoint; /* Contenu ciblé */
-
- char *full_desc; /* Description de l'ensemble */
- char *desc; /* Description de l'ensemble */
-
-};
-
-/* Contenu de issu d'un contenu plus global (classe) */
-struct _GEncapsContentClass
-{
- GObjectClass parent; /* A laisser en premier */
-
-};
-
-
/* Initialise la classe des contenus de données encapsulés. */
static void g_encaps_content_class_init(GEncapsContentClass *);
/* Initialise une instance de contenu de données encapsulé. */
static void g_encaps_content_init(GEncapsContent *);
-/* Procède à l'initialisation de l'interface de sérialisation. */
-static void g_encaps_content_serializable_init(GSerializableObjectInterface *);
-
-/* Procède à l'initialisation de l'interface de lecture. */
-static void g_encaps_content_interface_init(GBinContentInterface *);
-
/* Supprime toutes les références externes. */
static void g_encaps_content_dispose(GEncapsContent *);
@@ -80,7 +52,7 @@ static void g_encaps_content_finalize(GEncapsContent *);
-/* ---------------------- INTERACTIONS AVEC UN CONTENU BINAIRE ---------------------- */
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
/* Associe un ensemble d'attributs au contenu binaire. */
@@ -137,11 +109,6 @@ static bool g_encaps_content_read_uleb128(const GEncapsContent *, vmpa2t *, uleb
/* Lit un nombre signé encodé au format LEB128. */
static bool g_encaps_content_read_leb128(const GEncapsContent *, vmpa2t *, leb128_t *);
-
-
-/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */
-
-
/* Charge un contenu depuis une mémoire tampon. */
static bool g_encaps_content_load(GEncapsContent *, GObjectStorage *, packed_buffer_t *);
@@ -156,9 +123,7 @@ static bool g_encaps_content_store(const GEncapsContent *, GObjectStorage *, pac
/* Indique le type défini par la GLib pour les contenus encapsulés. */
-G_DEFINE_TYPE_WITH_CODE(GEncapsContent, g_encaps_content, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_encaps_content_interface_init)
- G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_encaps_content_serializable_init));
+G_DEFINE_TYPE(GEncapsContent, g_encaps_content, G_TYPE_BIN_CONTENT);
/******************************************************************************
@@ -176,88 +141,53 @@ G_DEFINE_TYPE_WITH_CODE(GEncapsContent, g_encaps_content, G_TYPE_OBJECT,
static void g_encaps_content_class_init(GEncapsContentClass *klass)
{
GObjectClass *object; /* Autre version de la classe */
+ GBinContentClass *content; /* Version parente de la classe*/
object = G_OBJECT_CLASS(klass);
object->dispose = (GObjectFinalizeFunc/* ! */)g_encaps_content_dispose;
object->finalize = (GObjectFinalizeFunc)g_encaps_content_finalize;
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : content = instance à initialiser. *
-* *
-* Description : Initialise une instance de contenu de données encapsulé. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_encaps_content_init(GEncapsContent *content)
-{
- content->base = NULL;
- content->path = NULL;
- content->endpoint = NULL;
-
- content->full_desc = NULL;
- content->desc = NULL;
+ content = G_BIN_CONTENT_CLASS(klass);
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : iface = interface GLib à initialiser. *
-* *
-* Description : Procède à l'initialisation de l'interface de lecture. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ content->set_attribs = (set_content_attributes)g_encaps_content_set_attributes;
+ content->get_attribs = (get_content_attributes)g_encaps_content_get_attributes;
-static void g_encaps_content_interface_init(GBinContentInterface *iface)
-{
- iface->set_attribs = (set_content_attributes)g_encaps_content_set_attributes;
- iface->get_attribs = (get_content_attributes)g_encaps_content_get_attributes;
+ content->get_root = (get_content_root_fc)g_encaps_content_get_root;
- iface->get_root = (get_content_root_fc)g_encaps_content_get_root;
+ content->describe = (describe_content_fc)g_encaps_content_describe;
- iface->describe = (describe_content_fc)g_encaps_content_describe;
+ content->compute_checksum = (compute_checksum_fc)g_encaps_content_compute_checksum;
- iface->compute_checksum = (compute_checksum_fc)g_encaps_content_compute_checksum;
+ content->compute_size = (compute_size_fc)g_encaps_content_compute_size;
+ content->compute_start_pos = (compute_start_pos_fc)g_encaps_content_compute_start_pos;
+ content->compute_end_pos = (compute_end_pos_fc)g_encaps_content_compute_end_pos;
- iface->compute_size = (compute_size_fc)g_encaps_content_compute_size;
- iface->compute_start_pos = (compute_start_pos_fc)g_encaps_content_compute_start_pos;
- iface->compute_end_pos = (compute_end_pos_fc)g_encaps_content_compute_end_pos;
+ content->seek = (seek_fc)g_encaps_content_seek;
- iface->seek = (seek_fc)g_encaps_content_seek;
+ content->get_raw_access = (get_raw_access_fc)g_encaps_content_get_raw_access;
- iface->get_raw_access = (get_raw_access_fc)g_encaps_content_get_raw_access;
+ content->read_raw = (read_raw_fc)g_encaps_content_read_raw;
+ content->read_u4 = (read_u4_fc)g_encaps_content_read_u4;
+ content->read_u8 = (read_u8_fc)g_encaps_content_read_u8;
+ content->read_u16 = (read_u16_fc)g_encaps_content_read_u16;
+ content->read_u32 = (read_u32_fc)g_encaps_content_read_u32;
+ content->read_u64 = (read_u64_fc)g_encaps_content_read_u64;
- iface->read_raw = (read_raw_fc)g_encaps_content_read_raw;
- iface->read_u4 = (read_u4_fc)g_encaps_content_read_u4;
- iface->read_u8 = (read_u8_fc)g_encaps_content_read_u8;
- iface->read_u16 = (read_u16_fc)g_encaps_content_read_u16;
- iface->read_u32 = (read_u32_fc)g_encaps_content_read_u32;
- iface->read_u64 = (read_u64_fc)g_encaps_content_read_u64;
+ content->read_uleb128 = (read_uleb128_fc)g_encaps_content_read_uleb128;
+ content->read_leb128 = (read_leb128_fc)g_encaps_content_read_leb128;
- iface->read_uleb128 = (read_uleb128_fc)g_encaps_content_read_uleb128;
- iface->read_leb128 = (read_leb128_fc)g_encaps_content_read_leb128;
+ content->load = (load_content_cb)g_encaps_content_load;
+ content->store = (store_content_cb)g_encaps_content_store;
}
/******************************************************************************
* *
-* Paramètres : iface = interface GLib à initialiser. *
+* Paramètres : content = instance à initialiser. *
* *
-* Description : Procède à l'initialisation de l'interface de sérialisation. *
+* Description : Initialise une instance de contenu de données encapsulé. *
* *
* Retour : - *
* *
@@ -265,10 +195,14 @@ static void g_encaps_content_interface_init(GBinContentInterface *iface)
* *
******************************************************************************/
-static void g_encaps_content_serializable_init(GSerializableObjectInterface *iface)
+static void g_encaps_content_init(GEncapsContent *content)
{
- iface->load = (load_serializable_object_cb)g_encaps_content_load;
- iface->store = (store_serializable_object_cb)g_encaps_content_store;
+ content->base = NULL;
+ content->path = NULL;
+ content->endpoint = NULL;
+
+ content->full_desc = NULL;
+ content->desc = NULL;
}
@@ -337,30 +271,59 @@ static void g_encaps_content_finalize(GEncapsContent *content)
GBinContent *g_encaps_content_new(GBinContent *base, const char *path, GBinContent *endpoint)
{
- GEncapsContent *result; /* Structure à retourner */
+ GBinContent *result; /* Structure à retourner */
result = g_object_new(G_TYPE_ENCAPS_CONTENT, NULL);
+ if (!g_encaps_content_create(G_ENCAPS_CONTENT(result), base, path, endpoint))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = instance à initialiser pleinement. *
+* base = contenu binaire d'où réaliser une extraction. *
+* path = chemin vers le contenu finalement ciblé. *
+* endpoint = contenu final rendu accessible. *
+* *
+* Description : Met en place un contenu de données brutes encapsulées. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_encaps_content_create(GEncapsContent *content, GBinContent *base, const char *path, GBinContent *endpoint)
+{
+ bool result; /* Bilan à retourner */
+
g_object_ref(base);
g_object_ref(endpoint);
- result->base = base;
- result->path = strdup(path);
- result->endpoint = endpoint;
+ content->base = base;
+ content->path = strdup(path);
+ content->endpoint = endpoint;
/* Description complète */
- result->full_desc = g_binary_content_describe(result->base, true);
+ content->full_desc = g_binary_content_describe(content->base, true);
- result->full_desc = stradd(result->full_desc, G_DIR_SEPARATOR_S);
+ content->full_desc = stradd(content->full_desc, G_DIR_SEPARATOR_S);
- result->full_desc = stradd(result->full_desc, path);
+ content->full_desc = stradd(content->full_desc, path);
/* Description partielle */
- result->desc = strdup(path);
+ content->desc = strdup(path);
+
+ result = true;
- return G_BIN_CONTENT(result);
+ return result;
}
@@ -442,7 +405,7 @@ GBinContent *g_encaps_content_get_endpoint(const GEncapsContent *content)
/* ---------------------------------------------------------------------------------- */
-/* INTERACTIONS AVEC UN CONTENU BINAIRE */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
/* ---------------------------------------------------------------------------------- */
@@ -554,11 +517,11 @@ static char *g_encaps_content_describe(const GEncapsContent *content, bool full)
static void g_encaps_content_compute_checksum(GEncapsContent *content, GChecksum *checksum)
{
- GBinContentIface *iface; /* Interface utilisée */
+ GBinContentClass *class; /* Classe de l'instance */
- iface = G_BIN_CONTENT_GET_IFACE(content->endpoint);
+ class = G_BIN_CONTENT_GET_CLASS(content);
- iface->compute_checksum(content->endpoint, checksum);
+ class->compute_checksum(content->endpoint, checksum);
}
@@ -882,12 +845,6 @@ static bool g_encaps_content_read_leb128(const GEncapsContent *content, vmpa2t *
}
-
-/* ---------------------------------------------------------------------------------- */
-/* CONSERVATION ET RECHARGEMENT DES DONNEES */
-/* ---------------------------------------------------------------------------------- */
-
-
/******************************************************************************
* *
* Paramètres : content = élément GLib à constuire. *