diff options
Diffstat (limited to 'src/analysis/contents/memory.c')
-rw-r--r-- | src/analysis/contents/memory.c | 318 |
1 files changed, 174 insertions, 144 deletions
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; + +} |