From d405d93f41f9376c55ac8af7acde62eec80386ec Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Wed, 13 Oct 2021 00:26:55 +0200
Subject: Reorganize the remaining code for binary contents.

---
 src/analysis/contents/encapsulated.c  | 364 +++++++++++++++++++++-------------
 src/analysis/contents/file.c          |  64 +++---
 src/analysis/contents/memory.c        | 318 +++++++++++++++--------------
 tests/analysis/contents/checksum.py   |   2 +-
 tests/analysis/contents/endian.py     |  50 ++---
 tests/analysis/contents/memory.py     |  18 +-
 tests/analysis/contents/restricted.py |   1 -
 7 files changed, 473 insertions(+), 344 deletions(-)

diff --git a/src/analysis/contents/encapsulated.c b/src/analysis/contents/encapsulated.c
index 7fb7e0c..dadc0a5 100644
--- a/src/analysis/contents/encapsulated.c
+++ b/src/analysis/contents/encapsulated.c
@@ -35,6 +35,9 @@
 
 
 
+/* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */
+
+
 /* Contenu de issu d'un contenu plus global (instance) */
 struct _GEncapsContent
 {
@@ -75,11 +78,16 @@ static void g_encaps_content_dispose(GEncapsContent *);
 /* Procède à la libération totale de la mémoire. */
 static void g_encaps_content_finalize(GEncapsContent *);
 
-/* Charge un contenu depuis une mémoire tampon. */
-static bool g_encaps_content_load(GEncapsContent *, GObjectStorage *, packed_buffer_t *);
 
-/* Sauvegarde un contenu dans une mémoire tampon. */
-static bool g_encaps_content_store(const GEncapsContent *, GObjectStorage *, packed_buffer_t *);
+
+/* ---------------------- INTERACTIONS AVEC UN CONTENU BINAIRE ---------------------- */
+
+
+/* Associe un ensemble d'attributs au contenu binaire. */
+static void g_encaps_content_set_attributes(GEncapsContent *, GContentAttributes *);
+
+/* Fournit l'ensemble des attributs associés à un contenu. */
+static GContentAttributes *g_encaps_content_get_attributes(const GEncapsContent *);
 
 /* Donne l'origine d'un contenu binaire. */
 static GBinContent *g_encaps_content_get_root(GEncapsContent *);
@@ -131,10 +139,26 @@ static bool g_encaps_content_read_leb128(const GEncapsContent *, vmpa2t *, leb12
 
 
 
+/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */
+
+
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_encaps_content_load(GEncapsContent *, GObjectStorage *, packed_buffer_t *);
+
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_encaps_content_store(const GEncapsContent *, GObjectStorage *, packed_buffer_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/*                            ENSEMBLE DE DONNEES BINAIRES                            */
+/* ---------------------------------------------------------------------------------- */
+
+
 /* 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_SERIALIZABLE_OBJECT, g_encaps_content_serializable_init)
-                        G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_encaps_content_interface_init));
+                        G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_encaps_content_interface_init)
+                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_encaps_content_serializable_init));
 
 
 /******************************************************************************
@@ -189,26 +213,6 @@ static void g_encaps_content_init(GEncapsContent *content)
 *                                                                             *
 *  Paramètres  : iface = interface GLib à initialiser.                        *
 *                                                                             *
-*  Description : Procède à l'initialisation de l'interface de sérialisation.  *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void g_encaps_content_serializable_init(GSerializableObjectInterface *iface)
-{
-    iface->load = (load_serializable_object_cb)g_encaps_content_load;
-    iface->store = (store_serializable_object_cb)g_encaps_content_store;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : iface = interface GLib à initialiser.                        *
-*                                                                             *
 *  Description : Procède à l'initialisation de l'interface de lecture.        *
 *                                                                             *
 *  Retour      : -                                                            *
@@ -219,6 +223,9 @@ static void g_encaps_content_serializable_init(GSerializableObjectInterface *ifa
 
 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;
+
     iface->get_root = (get_content_root_fc)g_encaps_content_get_root;
 
     iface->describe = (describe_content_fc)g_encaps_content_describe;
@@ -248,6 +255,26 @@ static void g_encaps_content_interface_init(GBinContentInterface *iface)
 
 /******************************************************************************
 *                                                                             *
+*  Paramètres  : iface = interface GLib à initialiser.                        *
+*                                                                             *
+*  Description : Procède à l'initialisation de l'interface de sérialisation.  *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void g_encaps_content_serializable_init(GSerializableObjectInterface *iface)
+{
+    iface->load = (load_serializable_object_cb)g_encaps_content_load;
+    iface->store = (store_serializable_object_cb)g_encaps_content_store;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
 *  Paramètres  : content = instance d'objet GLib à traiter.                   *
 *                                                                             *
 *  Description : Supprime toutes les références externes.                     *
@@ -340,75 +367,47 @@ GBinContent *g_encaps_content_new(GBinContent *base, const char *path, GBinConte
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : content = élément GLib à constuire.                          *
-*                storage = conservateur de données à manipuler ou NULL.       *
-*                pbuf    = zone tampon à lire.                                *
+*  Paramètres  : content = contenu binaire à venir consulter.                 *
 *                                                                             *
-*  Description : Charge un contenu depuis une mémoire tampon.                 *
+*  Description : Indique la base d'un contenu binaire encapsulé.              *
 *                                                                             *
-*  Retour      : Bilan de l'opération.                                        *
+*  Retour      : Instance de contenu binaire ou NULL si aucune.               *
 *                                                                             *
 *  Remarques   : -                                                            *
 *                                                                             *
 ******************************************************************************/
 
-static bool g_encaps_content_load(GEncapsContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
+GBinContent *g_encaps_content_get_base(const GEncapsContent *content)
 {
-    bool result;                            /* Bilan à retourner           */
-    rle_string str;                         /* Chaîne à charger            */
-
-    content->base = G_BIN_CONTENT(g_object_storage_unpack_object(storage, "contents", pbuf));
-    result = (content->base != NULL);
-
-    setup_empty_rle_string(&str);
-
-    if (result)
-        result = unpack_rle_string(&str, pbuf);
-
-    if (result)
-    {
-        result = (get_rle_string(&str) != NULL);
-
-        if (result)
-            content->path = strdup(get_rle_string(&str));
-
-        exit_rle_string(&str);
-
-    }
-
-    if (result)
-    {
-        content->endpoint = G_BIN_CONTENT(g_object_storage_unpack_object(storage, "contents", pbuf));
-        result = (content->endpoint != NULL);
-    }
-
-    if (result)
-        result = unpack_rle_string(&str, pbuf);
-
-    if (result)
-    {
-        result = (get_rle_string(&str) != NULL);
+    GBinContent *result;                    /* Contenu binaire à renvoyer  */
 
-        if (result)
-            content->full_desc = strdup(get_rle_string(&str));
+    result = content->base;
 
-        exit_rle_string(&str);
+    if (result != NULL)
+        g_object_ref(G_OBJECT(result));
 
-    }
+    return result;
 
-    if (result)
-        result = unpack_rle_string(&str, pbuf);
+}
 
-    if (result)
-    {
-        result = (get_rle_string(&str) != NULL);
 
-        if (result)
-            content->desc = strdup(get_rle_string(&str));
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : content = contenu binaire à venir consulter.                 *
+*                                                                             *
+*  Description : Fournit le chemin vers le contenu interne représenté.        *
+*                                                                             *
+*  Retour      : Chemin d'accès au contenu binaire.                           *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
 
-        exit_rle_string(&str);
+const char *g_encaps_content_get_path(const GEncapsContent *content)
+{
+    char *result;                           /* Chemin d'accès à retourner  */
 
-    }
+    result = content->path;
 
     return result;
 
@@ -417,57 +416,73 @@ static bool g_encaps_content_load(GEncapsContent *content, GObjectStorage *stora
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : content = élément GLib à consulter.                          *
-*                storage = conservateur de données à manipuler ou NULL.       *
-*                pbuf    = zone tampon à remplir.                             *
+*  Paramètres  : content = contenu binaire à venir consulter.                 *
 *                                                                             *
-*  Description : Sauvegarde un contenu dans une mémoire tampon.               *
+*  Description : Indique le contenu binaire embarqué dans une encapsulation.  *
 *                                                                             *
-*  Retour      : Bilan de l'opération.                                        *
+*  Retour      : Instance de contenu binaire ou NULL si aucune.               *
 *                                                                             *
 *  Remarques   : -                                                            *
 *                                                                             *
 ******************************************************************************/
 
-static bool g_encaps_content_store(const GEncapsContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
+GBinContent *g_encaps_content_get_endpoint(const GEncapsContent *content)
 {
-    bool result;                            /* Bilan à retourner           */
-    rle_string str;                         /* Chaîne à conserver          */
+    GBinContent *result;                    /* Contenu binaire à renvoyer  */
 
-    result = g_object_storage_pack_object(storage, "contents", G_SERIALIZABLE_OBJECT(content->base), pbuf);
+    result = content->endpoint;
 
-    if (result)
-    {
-        init_static_rle_string(&str, content->path);
+    if (result != NULL)
+        g_object_ref(G_OBJECT(result));
 
-        result = pack_rle_string(&str, pbuf);
+    return result;
 
-        exit_rle_string(&str);
+}
 
-    }
 
-    if (result)
-        result = g_object_storage_pack_object(storage, "contents", G_SERIALIZABLE_OBJECT(content->endpoint), pbuf);
 
-    if (result)
-    {
-        init_static_rle_string(&str, content->full_desc);
+/* ---------------------------------------------------------------------------------- */
+/*                        INTERACTIONS AVEC UN CONTENU BINAIRE                        */
+/* ---------------------------------------------------------------------------------- */
 
-        result = pack_rle_string(&str, pbuf);
 
-        exit_rle_string(&str);
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : content = contenu binaire à actualiser.                      *
+*                attribs = jeu d'attributs à lier au contenu courant.         *
+*                                                                             *
+*  Description : Associe un ensemble d'attributs au contenu binaire.          *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
 
-    }
+static void g_encaps_content_set_attributes(GEncapsContent *content, GContentAttributes *attribs)
+{
+    g_binary_content_set_attributes(content->endpoint, attribs);
 
-    if (result)
-    {
-        init_static_rle_string(&str, content->desc);
+}
 
-        result = pack_rle_string(&str, pbuf);
 
-        exit_rle_string(&str);
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : content = contenu binaire à consulter.                       *
+*                                                                             *
+*  Description : Fournit l'ensemble des attributs associés à un contenu.      *
+*                                                                             *
+*  Retour      : Jeu d'attributs liés au contenu courant.                     *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
 
-    }
+static GContentAttributes *g_encaps_content_get_attributes(const GEncapsContent *content)
+{
+    GContentAttributes *result;             /* Instance à retourner        */
+
+    result = g_binary_content_get_attributes(content->endpoint);
 
     return result;
 
@@ -867,49 +882,83 @@ static bool g_encaps_content_read_leb128(const GEncapsContent *content, vmpa2t *
 }
 
 
+
+/* ---------------------------------------------------------------------------------- */
+/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */
+/* ---------------------------------------------------------------------------------- */
+
+
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : content = contenu binaire à venir consulter.                 *
+*  Paramètres  : content = élément GLib à constuire.                          *
+*                storage = conservateur de données à manipuler ou NULL.       *
+*                pbuf    = zone tampon à lire.                                *
 *                                                                             *
-*  Description : Indique la base d'un contenu binaire encapsulé.              *
+*  Description : Charge un contenu depuis une mémoire tampon.                 *
 *                                                                             *
-*  Retour      : Instance de contenu binaire ou NULL si aucune.               *
+*  Retour      : Bilan de l'opération.                                        *
 *                                                                             *
 *  Remarques   : -                                                            *
 *                                                                             *
 ******************************************************************************/
 
-GBinContent *g_encaps_content_get_base(const GEncapsContent *content)
+static bool g_encaps_content_load(GEncapsContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
 {
-    GBinContent *result;                    /* Contenu binaire à renvoyer  */
+    bool result;                            /* Bilan à retourner           */
+    rle_string str;                         /* Chaîne à charger            */
 
-    result = content->base;
+    content->base = G_BIN_CONTENT(g_object_storage_unpack_object(storage, "contents", pbuf));
+    result = (content->base != NULL);
 
-    if (result != NULL)
-        g_object_ref(G_OBJECT(result));
+    setup_empty_rle_string(&str);
 
-    return result;
+    if (result)
+        result = unpack_rle_string(&str, pbuf);
 
-}
+    if (result)
+    {
+        result = (get_rle_string(&str) != NULL);
 
+        if (result)
+            content->path = strdup(get_rle_string(&str));
 
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : content = contenu binaire à venir consulter.                 *
-*                                                                             *
-*  Description : Fournit le chemin vers le contenu interne représenté.        *
-*                                                                             *
-*  Retour      : Chemin d'accès au contenu binaire.                           *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
+        exit_rle_string(&str);
 
-const char *g_encaps_content_get_path(const GEncapsContent *content)
-{
-    char *result;                           /* Chemin d'accès à retourner  */
+    }
 
-    result = content->path;
+    if (result)
+    {
+        content->endpoint = G_BIN_CONTENT(g_object_storage_unpack_object(storage, "contents", pbuf));
+        result = (content->endpoint != NULL);
+    }
+
+    if (result)
+        result = unpack_rle_string(&str, pbuf);
+
+    if (result)
+    {
+        result = (get_rle_string(&str) != NULL);
+
+        if (result)
+            content->full_desc = strdup(get_rle_string(&str));
+
+        exit_rle_string(&str);
+
+    }
+
+    if (result)
+        result = unpack_rle_string(&str, pbuf);
+
+    if (result)
+    {
+        result = (get_rle_string(&str) != NULL);
+
+        if (result)
+            content->desc = strdup(get_rle_string(&str));
+
+        exit_rle_string(&str);
+
+    }
 
     return result;
 
@@ -918,24 +967,57 @@ const char *g_encaps_content_get_path(const GEncapsContent *content)
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : content = contenu binaire à venir consulter.                 *
+*  Paramètres  : content = élément GLib à consulter.                          *
+*                storage = conservateur de données à manipuler ou NULL.       *
+*                pbuf    = zone tampon à remplir.                             *
 *                                                                             *
-*  Description : Indique le contenu binaire embarqué dans une encapsulation.  *
+*  Description : Sauvegarde un contenu dans une mémoire tampon.               *
 *                                                                             *
-*  Retour      : Instance de contenu binaire ou NULL si aucune.               *
+*  Retour      : Bilan de l'opération.                                        *
 *                                                                             *
 *  Remarques   : -                                                            *
 *                                                                             *
 ******************************************************************************/
 
-GBinContent *g_encaps_content_get_endpoint(const GEncapsContent *content)
+static bool g_encaps_content_store(const GEncapsContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
 {
-    GBinContent *result;                    /* Contenu binaire à renvoyer  */
+    bool result;                            /* Bilan à retourner           */
+    rle_string str;                         /* Chaîne à conserver          */
 
-    result = content->endpoint;
+    result = g_object_storage_pack_object(storage, "contents", G_SERIALIZABLE_OBJECT(content->base), pbuf);
 
-    if (result != NULL)
-        g_object_ref(G_OBJECT(result));
+    if (result)
+    {
+        init_static_rle_string(&str, content->path);
+
+        result = pack_rle_string(&str, pbuf);
+
+        exit_rle_string(&str);
+
+    }
+
+    if (result)
+        result = g_object_storage_pack_object(storage, "contents", G_SERIALIZABLE_OBJECT(content->endpoint), pbuf);
+
+    if (result)
+    {
+        init_static_rle_string(&str, content->full_desc);
+
+        result = pack_rle_string(&str, pbuf);
+
+        exit_rle_string(&str);
+
+    }
+
+    if (result)
+    {
+        init_static_rle_string(&str, content->desc);
+
+        result = pack_rle_string(&str, pbuf);
+
+        exit_rle_string(&str);
+
+    }
 
     return result;
 
diff --git a/src/analysis/contents/file.c b/src/analysis/contents/file.c
index 78bd981..4f102d8 100644
--- a/src/analysis/contents/file.c
+++ b/src/analysis/contents/file.c
@@ -40,6 +40,9 @@
 
 
 
+/* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */
+
+
 /* Contenu de données binaires issues d'un fichier (instance) */
 struct _GFileContent
 {
@@ -72,6 +75,10 @@ static void g_file_content_dispose(GFileContent *);
 /* Procède à la libération totale de la mémoire. */
 static void g_file_content_finalize(GFileContent *);
 
+
+/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */
+
+
 /* Charge un contenu depuis une mémoire tampon. */
 static bool g_file_content_load(GFileContent *, GObjectStorage *, packed_buffer_t *);
 
@@ -80,6 +87,11 @@ static bool g_file_content_store(const GFileContent *, GObjectStorage *, packed_
 
 
 
+/* ---------------------------------------------------------------------------------- */
+/*                            ENSEMBLE DE DONNEES BINAIRES                            */
+/* ---------------------------------------------------------------------------------- */
+
+
 /* Indique le type défini par la GLib pour les contenus de données. */
 G_DEFINE_TYPE_WITH_CODE(GFileContent, g_file_content, G_TYPE_MEMORY_CONTENT,
                         G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_file_content_serializable_init));
@@ -261,6 +273,35 @@ GBinContent *g_file_content_new(const char *filename)
 
 /******************************************************************************
 *                                                                             *
+*  Paramètres  : content = contenu binaire à venir consulter.                 *
+*                                                                             *
+*  Description : Fournit le nom de fichier associé au contenu binaire.        *
+*                                                                             *
+*  Retour      : Chemin d'accès au contenu binaire.                           *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+const char *g_file_content_get_filename(const GFileContent *content)
+{
+    char *result;                           /* Chemin d'accès à retourner  */
+
+    result = content->filename;
+
+    return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+*                                                                             *
 *  Paramètres  : content = élément GLib à constuire.                          *
 *                storage = conservateur de données à manipuler ou NULL.       *
 *                pbuf    = zone tampon à lire.                                *
@@ -341,26 +382,3 @@ static bool g_file_content_store(const GFileContent *content, GObjectStorage *st
     return result;
 
 }
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : content = contenu binaire à venir consulter.                 *
-*                                                                             *
-*  Description : Fournit le nom de fichier associé au contenu binaire.        *
-*                                                                             *
-*  Retour      : Chemin d'accès au contenu binaire.                           *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-const char *g_file_content_get_filename(const GFileContent *content)
-{
-    char *result;                           /* Chemin d'accès à retourner  */
-
-    result = content->filename;
-
-    return result;
-
-}
diff --git a/src/analysis/contents/memory.c b/src/analysis/contents/memory.c
index 50647f6..e28d31c 100644
--- a/src/analysis/contents/memory.c
+++ b/src/analysis/contents/memory.c
@@ -42,29 +42,31 @@
 
 
 
+/* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */
+
+
 /* Initialise la classe des contenus de données en mémoire. */
 static void g_memory_content_class_init(GMemoryContentClass *);
 
 /* Initialise une instance de contenu de données en mémoire. */
 static void g_memory_content_init(GMemoryContent *);
 
-/* Procède à l'initialisation de l'interface de sérialisation. */
-static void g_memory_content_serializable_init(GSerializableObjectInterface *);
-
 /* Procède à l'initialisation de l'interface de lecture. */
 static void g_memory_content_interface_init(GBinContentInterface *);
 
+/* Procède à l'initialisation de l'interface de sérialisation. */
+static void g_memory_content_serializable_init(GSerializableObjectInterface *);
+
 /* Supprime toutes les références externes. */
 static void g_memory_content_dispose(GMemoryContent *);
 
 /* Procède à la libération totale de la mémoire. */
 static void g_memory_content_finalize(GMemoryContent *);
 
-/* Charge un contenu depuis une mémoire tampon. */
-static bool g_memory_content_load(GMemoryContent *, GObjectStorage *, packed_buffer_t *);
 
-/* Sauvegarde un contenu dans une mémoire tampon. */
-static bool g_memory_content_store(const GMemoryContent *, GObjectStorage *, packed_buffer_t *);
+
+/* ---------------------- INTERACTIONS AVEC UN CONTENU BINAIRE ---------------------- */
+
 
 /* Associe un ensemble d'attributs au contenu binaire. */
 static void g_memory_content_set_attributes(GMemoryContent *, GContentAttributes *);
@@ -122,10 +124,26 @@ static bool g_memory_content_read_leb128(const GMemoryContent *, vmpa2t *, leb12
 
 
 
+/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */
+
+
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_memory_content_load(GMemoryContent *, GObjectStorage *, packed_buffer_t *);
+
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_memory_content_store(const GMemoryContent *, GObjectStorage *, packed_buffer_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/*                            ENSEMBLE DE DONNEES BINAIRES                            */
+/* ---------------------------------------------------------------------------------- */
+
+
 /* Indique le type défini par la GLib pour les contenus de données en mémoire. */
 G_DEFINE_TYPE_WITH_CODE(GMemoryContent, g_memory_content, G_TYPE_OBJECT,
-                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_memory_content_serializable_init)
-                        G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_memory_content_interface_init));
+                        G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_memory_content_interface_init)
+                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_memory_content_serializable_init));
 
 
 /******************************************************************************
@@ -187,26 +205,6 @@ static void g_memory_content_init(GMemoryContent *content)
 *                                                                             *
 *  Paramètres  : iface = interface GLib à initialiser.                        *
 *                                                                             *
-*  Description : Procède à l'initialisation de l'interface de sérialisation.  *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void g_memory_content_serializable_init(GSerializableObjectInterface *iface)
-{
-    iface->load = (load_serializable_object_cb)g_memory_content_load;
-    iface->store = (store_serializable_object_cb)g_memory_content_store;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : iface = interface GLib à initialiser.                        *
-*                                                                             *
 *  Description : Procède à l'initialisation de l'interface de lecture.        *
 *                                                                             *
 *  Retour      : -                                                            *
@@ -249,6 +247,26 @@ static void g_memory_content_interface_init(GBinContentInterface *iface)
 
 /******************************************************************************
 *                                                                             *
+*  Paramètres  : iface = interface GLib à initialiser.                        *
+*                                                                             *
+*  Description : Procède à l'initialisation de l'interface de sérialisation.  *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void g_memory_content_serializable_init(GSerializableObjectInterface *iface)
+{
+    iface->load = (load_serializable_object_cb)g_memory_content_load;
+    iface->store = (store_serializable_object_cb)g_memory_content_store;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
 *  Paramètres  : content = instance d'objet GLib à traiter.                   *
 *                                                                             *
 *  Description : Supprime toutes les références externes.                     *
@@ -333,122 +351,10 @@ GBinContent *g_memory_content_new(const bin_t *data, phys_t size)
 }
 
 
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : content = élément GLib à constuire.                          *
-*                storage = conservateur de données à manipuler ou NULL.       *
-*                pbuf    = zone tampon à lire.                                *
-*                                                                             *
-*  Description : Charge un contenu depuis une mémoire tampon.                 *
-*                                                                             *
-*  Retour      : Bilan de l'opération.                                        *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static bool g_memory_content_load(GMemoryContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
-{
-    bool result;                            /* Bilan à retourner           */
-    uleb128_t length;                       /* Quantité de données à suivre*/
-    rle_string str;                         /* Chaîne à charger            */
-
-    result = unpack_uleb128(&length, pbuf);
-
-    if (result)
-    {
-        content->data = malloc(length);
-        result = (content->data != NULL);
-    }
-
-    if (result)
-    {
-        content->length = length;
-        result = extract_packed_buffer(pbuf, content->data, length, false);
-    }
-
-    setup_empty_rle_string(&str);
-
-    if (result)
-        result = unpack_rle_string(&str, pbuf);
-
-    if (result)
-    {
-        result = (get_rle_string(&str) != NULL);
-
-        if (result)
-            content->full_desc = strdup(get_rle_string(&str));
-
-        exit_rle_string(&str);
-
-    }
-
-    if (result)
-        result = unpack_rle_string(&str, pbuf);
-
-    if (result)
-    {
-        result = (get_rle_string(&str) != NULL);
-
-        if (result)
-            content->desc = strdup(get_rle_string(&str));
-
-        exit_rle_string(&str);
-
-    }
-
-    return result;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : content = élément GLib à consulter.                          *
-*                storage = conservateur de données à manipuler ou NULL.       *
-*                pbuf    = zone tampon à remplir.                             *
-*                                                                             *
-*  Description : Sauvegarde un contenu dans une mémoire tampon.               *
-*                                                                             *
-*  Retour      : Bilan de l'opération.                                        *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static bool g_memory_content_store(const GMemoryContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
-{
-    bool result;                            /* Bilan à retourner           */
-    rle_string str;                         /* Chaîne à conserver          */
-
-    result = pack_uleb128((uleb128_t []){ content->length }, pbuf);
-
-    if (result)
-        result = extend_packed_buffer(pbuf, content->data, content->length, false);
-
-    if (result)
-    {
-        init_static_rle_string(&str, content->full_desc);
-
-        result = pack_rle_string(&str, pbuf);
-
-        exit_rle_string(&str);
-
-    }
-
-    if (result)
-    {
-        init_static_rle_string(&str, content->desc);
-
-        result = pack_rle_string(&str, pbuf);
-
-        exit_rle_string(&str);
 
-    }
-
-    return result;
-
-}
+/* ---------------------------------------------------------------------------------- */
+/*                        INTERACTIONS AVEC UN CONTENU BINAIRE                        */
+/* ---------------------------------------------------------------------------------- */
 
 
 /******************************************************************************
@@ -979,3 +885,127 @@ static bool g_memory_content_read_leb128(const GMemoryContent *content, vmpa2t *
     return result;
 
 }
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : content = élément GLib à constuire.                          *
+*                storage = conservateur de données à manipuler ou NULL.       *
+*                pbuf    = zone tampon à lire.                                *
+*                                                                             *
+*  Description : Charge un contenu depuis une mémoire tampon.                 *
+*                                                                             *
+*  Retour      : Bilan de l'opération.                                        *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static bool g_memory_content_load(GMemoryContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
+{
+    bool result;                            /* Bilan à retourner           */
+    uleb128_t length;                       /* Quantité de données à suivre*/
+    rle_string str;                         /* Chaîne à charger            */
+
+    result = unpack_uleb128(&length, pbuf);
+
+    if (result)
+    {
+        content->data = malloc(length);
+        result = (content->data != NULL);
+    }
+
+    if (result)
+    {
+        content->length = length;
+        result = extract_packed_buffer(pbuf, content->data, length, false);
+    }
+
+    setup_empty_rle_string(&str);
+
+    if (result)
+        result = unpack_rle_string(&str, pbuf);
+
+    if (result)
+    {
+        result = (get_rle_string(&str) != NULL);
+
+        if (result)
+            content->full_desc = strdup(get_rle_string(&str));
+
+        exit_rle_string(&str);
+
+    }
+
+    if (result)
+        result = unpack_rle_string(&str, pbuf);
+
+    if (result)
+    {
+        result = (get_rle_string(&str) != NULL);
+
+        if (result)
+            content->desc = strdup(get_rle_string(&str));
+
+        exit_rle_string(&str);
+
+    }
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : content = élément GLib à consulter.                          *
+*                storage = conservateur de données à manipuler ou NULL.       *
+*                pbuf    = zone tampon à remplir.                             *
+*                                                                             *
+*  Description : Sauvegarde un contenu dans une mémoire tampon.               *
+*                                                                             *
+*  Retour      : Bilan de l'opération.                                        *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static bool g_memory_content_store(const GMemoryContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
+{
+    bool result;                            /* Bilan à retourner           */
+    rle_string str;                         /* Chaîne à conserver          */
+
+    result = pack_uleb128((uleb128_t []){ content->length }, pbuf);
+
+    if (result)
+        result = extend_packed_buffer(pbuf, content->data, content->length, false);
+
+    if (result)
+    {
+        init_static_rle_string(&str, content->full_desc);
+
+        result = pack_rle_string(&str, pbuf);
+
+        exit_rle_string(&str);
+
+    }
+
+    if (result)
+    {
+        init_static_rle_string(&str, content->desc);
+
+        result = pack_rle_string(&str, pbuf);
+
+        exit_rle_string(&str);
+
+    }
+
+    return result;
+
+}
diff --git a/tests/analysis/contents/checksum.py b/tests/analysis/contents/checksum.py
index 54e4630..fd0c3ed 100644
--- a/tests/analysis/contents/checksum.py
+++ b/tests/analysis/contents/checksum.py
@@ -56,7 +56,7 @@ class TestRestrictedContent(ChrysalideTestCase):
         fcnt = FileContent(self._out.name)
         self.assertIsNotNone(fcnt)
 
-        start = vmpa(4, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(4, vmpa.VmpaSpecialValue.NO_VIRTUAL)
         covered = mrange(start, 4) # 'BBBB'
 
         rcnt = RestrictedContent(fcnt, covered)
diff --git a/tests/analysis/contents/endian.py b/tests/analysis/contents/endian.py
index 77ed77a..b7c8bec 100644
--- a/tests/analysis/contents/endian.py
+++ b/tests/analysis/contents/endian.py
@@ -6,7 +6,7 @@
 
 
 from chrysacase import ChrysalideTestCase
-from pychrysalide import arch
+from pychrysalide.analysis import BinContent
 from pychrysalide.analysis.contents import FileContent, RestrictedContent
 from pychrysalide.arch import vmpa
 import tempfile
@@ -53,38 +53,38 @@ class TestEndianness(ChrysalideTestCase):
 
         # 16 bits
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u16(start, arch.SRE_LITTLE_WORD)
+        val = fcnt.read_u16(start, BinContent.SourceEndian.LITTLE_WORD)
         self.assertEqual(val, 0x1516)
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u16(start, arch.SRE_BIG_WORD)
+        val = fcnt.read_u16(start, BinContent.SourceEndian.BIG_WORD)
         self.assertEqual(val, 0x1615)
 
         # 32 bits
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u32(start, arch.SRE_LITTLE_WORD)
+        val = fcnt.read_u32(start, BinContent.SourceEndian.LITTLE_WORD)
         self.assertEqual(val, 0x17181516)
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u32(start, arch.SRE_BIG_WORD)
+        val = fcnt.read_u32(start, BinContent.SourceEndian.BIG_WORD)
         self.assertEqual(val, 0x16151817)
 
         # 64 bits
 
-        start = vmpa(0, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(0, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u64(start, arch.SRE_LITTLE_WORD)
+        val = fcnt.read_u64(start, BinContent.SourceEndian.LITTLE_WORD)
         self.assertEqual(val, 0x0708050603040102)
 
-        start = vmpa(0, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(0, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u64(start, arch.SRE_BIG_WORD)
+        val = fcnt.read_u64(start, BinContent.SourceEndian.BIG_WORD)
         self.assertEqual(val, 0x0201040306050807)
 
 
@@ -95,36 +95,36 @@ class TestEndianness(ChrysalideTestCase):
 
         # 16 bits
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u16(start, arch.SRE_LITTLE)
+        val = fcnt.read_u16(start, BinContent.SourceEndian.LITTLE)
         self.assertEqual(val, 0x1615)
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u16(start, arch.SRE_BIG)
+        val = fcnt.read_u16(start, BinContent.SourceEndian.BIG)
         self.assertEqual(val, 0x1516)
 
         # 32 bits
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u32(start, arch.SRE_LITTLE)
+        val = fcnt.read_u32(start, BinContent.SourceEndian.LITTLE)
         self.assertEqual(val, 0x18171615)
 
-        start = vmpa(12, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(12, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u32(start, arch.SRE_BIG)
+        val = fcnt.read_u32(start, BinContent.SourceEndian.BIG)
         self.assertEqual(val, 0x15161718)
 
         # 64 bits
 
-        start = vmpa(0, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(0, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u64(start, arch.SRE_LITTLE)
+        val = fcnt.read_u64(start, BinContent.SourceEndian.LITTLE)
         self.assertEqual(val, 0x0807060504030201)
 
-        start = vmpa(0, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(0, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = fcnt.read_u64(start, arch.SRE_BIG)
+        val = fcnt.read_u64(start, BinContent.SourceEndian.BIG)
         self.assertEqual(val, 0x0102030405060708)
diff --git a/tests/analysis/contents/memory.py b/tests/analysis/contents/memory.py
index 55ce035..f99e607 100644
--- a/tests/analysis/contents/memory.py
+++ b/tests/analysis/contents/memory.py
@@ -7,7 +7,7 @@
 
 
 from chrysacase import ChrysalideTestCase
-from pychrysalide import arch
+from pychrysalide.analysis import BinContent
 from pychrysalide.analysis.contents import MemoryContent
 from pychrysalide.arch import vmpa, mrange
 
@@ -29,7 +29,7 @@ class TestMemoryContent(ChrysalideTestCase):
 
         cnt = MemoryContent(data)
 
-        start = vmpa(4, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(4, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
         val = cnt.read_u8(start)
         self.assertEqual(val, 0x05)
@@ -37,14 +37,14 @@ class TestMemoryContent(ChrysalideTestCase):
         val = cnt.read_u8(start)
         self.assertEqual(val, 0x06)
 
-        start = vmpa(14, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(14, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = cnt.read_u16(start, arch.SRE_LITTLE)
+        val = cnt.read_u16(start, BinContent.SourceEndian.LITTLE)
         self.assertEqual(val, 0x1817)
 
-        start = vmpa(10, vmpa.VMPA_NO_VIRTUAL)
+        start = vmpa(10, vmpa.VmpaSpecialValue.NO_VIRTUAL)
 
-        val = cnt.read_u32(start, arch.SRE_LITTLE)
+        val = cnt.read_u32(start, BinContent.SourceEndian.LITTLE)
         self.assertEqual(val, 0x16150013)
 
 
@@ -57,10 +57,10 @@ class TestMemoryContent(ChrysalideTestCase):
 
         with self.assertRaisesRegex(Exception, 'Invalid read access.'):
 
-            start = vmpa(1, vmpa.VMPA_NO_VIRTUAL)
+            start = vmpa(1, vmpa.VmpaSpecialValue.NO_VIRTUAL)
             val = cnt.read_u8(start)
 
         with self.assertRaisesRegex(Exception, 'Invalid read access.'):
 
-            start = vmpa(0, vmpa.VMPA_NO_VIRTUAL)
-            val = cnt.read_u16(start, arch.SRE_LITTLE)
+            start = vmpa(0, vmpa.VmpaSpecialValue.NO_VIRTUAL)
+            val = cnt.read_u16(start, BinContent.SourceEndian.LITTLE)
diff --git a/tests/analysis/contents/restricted.py b/tests/analysis/contents/restricted.py
index ae11619..023e600 100644
--- a/tests/analysis/contents/restricted.py
+++ b/tests/analysis/contents/restricted.py
@@ -7,7 +7,6 @@
 
 
 from chrysacase import ChrysalideTestCase
-from pychrysalide import arch
 from pychrysalide.analysis import BinContent
 from pychrysalide.analysis.contents import FileContent, RestrictedContent
 from pychrysalide.arch import vmpa, mrange
-- 
cgit v0.11.2-87-g4458