summaryrefslogtreecommitdiff
path: root/src/analysis/contents/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/contents/memory.c')
-rw-r--r--src/analysis/contents/memory.c395
1 files changed, 210 insertions, 185 deletions
diff --git a/src/analysis/contents/memory.c b/src/analysis/contents/memory.c
index 6a020e8..f8ff863 100644
--- a/src/analysis/contents/memory.c
+++ b/src/analysis/contents/memory.c
@@ -42,29 +42,25 @@
+/* -------------------------- 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 *);
-
/* 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 *);
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
/* Associe un ensemble d'attributs au contenu binaire. */
static void g_memory_content_set_attributes(GMemoryContent *, GContentAttributes *);
@@ -120,12 +116,21 @@ static bool g_memory_content_read_uleb128(const GMemoryContent *, vmpa2t *, uleb
/* Lit un nombre signé encodé au format LEB128. */
static bool g_memory_content_read_leb128(const GMemoryContent *, vmpa2t *, leb128_t *);
+/* 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_DEFINE_TYPE(GMemoryContent, g_memory_content, G_TYPE_BIN_CONTENT);
/******************************************************************************
@@ -143,71 +148,53 @@ G_DEFINE_TYPE_WITH_CODE(GMemoryContent, g_memory_content, G_TYPE_OBJECT,
static void g_memory_content_class_init(GMemoryContentClass *klass)
{
GObjectClass *object; /* Autre version de la classe */
+ GBinContentClass *content; /* Version parente de la classe*/
object = G_OBJECT_CLASS(klass);
object->dispose = (GObjectFinalizeFunc/* ! */)g_memory_content_dispose;
object->finalize = (GObjectFinalizeFunc)g_memory_content_finalize;
-}
+ content = G_BIN_CONTENT_CLASS(klass);
+ content->set_attribs = (set_content_attributes)g_memory_content_set_attributes;
+ content->get_attribs = (get_content_attributes)g_memory_content_get_attributes;
-/******************************************************************************
-* *
-* Paramètres : content = instance à initialiser. *
-* *
-* Description : Initialise une instance de contenu de données en mémoire. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ content->get_root = (get_content_root_fc)g_memory_content_get_root;
-static void g_memory_content_init(GMemoryContent *content)
-{
- GContentAttributes *empty; /* Jeu d'attributs vide */
+ content->describe = (describe_content_fc)g_memory_content_describe;
- content->attribs = NULL;
+ content->compute_checksum = (compute_checksum_fc)g_memory_content_compute_checksum;
- empty = g_content_attributes_new("");
+ content->compute_size = (compute_size_fc)g_memory_content_compute_size;
+ content->compute_start_pos = (compute_start_pos_fc)g_memory_content_compute_start_pos;
+ content->compute_end_pos = (compute_end_pos_fc)g_memory_content_compute_end_pos;
- g_binary_content_set_attributes(G_BIN_CONTENT(content), empty);
+ content->seek = (seek_fc)g_memory_content_seek;
- content->data = NULL;
- content->length = 0;
+ content->get_raw_access = (get_raw_access_fc)g_memory_content_get_raw_access;
- content->full_desc = strdup("In-memory content");
- content->desc = strdup("In-memory content");
+ content->read_raw = (read_raw_fc)g_memory_content_read_raw;
+ content->read_u4 = (read_u4_fc)g_memory_content_read_u4;
+ content->read_u8 = (read_u8_fc)g_memory_content_read_u8;
+ content->read_u16 = (read_u16_fc)g_memory_content_read_u16;
+ content->read_u32 = (read_u32_fc)g_memory_content_read_u32;
+ content->read_u64 = (read_u64_fc)g_memory_content_read_u64;
-}
+ content->read_uleb128 = (read_uleb128_fc)g_memory_content_read_uleb128;
+ content->read_leb128 = (read_leb128_fc)g_memory_content_read_leb128;
-
-/******************************************************************************
-* *
-* 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;
+ content->load = (load_content_cb)g_memory_content_load;
+ content->store = (store_content_cb)g_memory_content_store;
}
/******************************************************************************
* *
-* Paramètres : iface = interface GLib à initialiser. *
+* Paramètres : content = instance à initialiser. *
* *
-* Description : Procède à l'initialisation de l'interface de lecture. *
+* Description : Initialise une instance de contenu de données en mémoire. *
* *
* Retour : - *
* *
@@ -215,34 +202,24 @@ static void g_memory_content_serializable_init(GSerializableObjectInterface *ifa
* *
******************************************************************************/
-static void g_memory_content_interface_init(GBinContentInterface *iface)
+static void g_memory_content_init(GMemoryContent *content)
{
- iface->set_attribs = (set_content_attributes)g_memory_content_set_attributes;
- iface->get_attribs = (get_content_attributes)g_memory_content_get_attributes;
-
- iface->get_root = (get_content_root_fc)g_memory_content_get_root;
-
- iface->describe = (describe_content_fc)g_memory_content_describe;
+ GContentAttributes *empty; /* Jeu d'attributs vide */
- iface->compute_checksum = (compute_checksum_fc)g_memory_content_compute_checksum;
+ content->attribs = NULL;
- iface->compute_size = (compute_size_fc)g_memory_content_compute_size;
- iface->compute_start_pos = (compute_start_pos_fc)g_memory_content_compute_start_pos;
- iface->compute_end_pos = (compute_end_pos_fc)g_memory_content_compute_end_pos;
+ empty = g_content_attributes_new("", NULL);
- iface->seek = (seek_fc)g_memory_content_seek;
+ g_binary_content_set_attributes(G_BIN_CONTENT(content), empty);
- iface->get_raw_access = (get_raw_access_fc)g_memory_content_get_raw_access;
+ g_object_unref(G_OBJECT(empty));
- iface->read_raw = (read_raw_fc)g_memory_content_read_raw;
- iface->read_u4 = (read_u4_fc)g_memory_content_read_u4;
- iface->read_u8 = (read_u8_fc)g_memory_content_read_u8;
- iface->read_u16 = (read_u16_fc)g_memory_content_read_u16;
- iface->read_u32 = (read_u32_fc)g_memory_content_read_u32;
- iface->read_u64 = (read_u64_fc)g_memory_content_read_u64;
+ content->data = NULL;
+ content->length = 0;
+ content->allocated = false;
- iface->read_uleb128 = (read_uleb128_fc)g_memory_content_read_uleb128;
- iface->read_leb128 = (read_leb128_fc)g_memory_content_read_leb128;
+ content->full_desc = strdup("In-memory content");
+ content->desc = strdup("In-memory content");
}
@@ -282,8 +259,11 @@ static void g_memory_content_dispose(GMemoryContent *content)
static void g_memory_content_finalize(GMemoryContent *content)
{
- if (content->data != NULL)
- free(content->data);
+ if (content->allocated)
+ {
+ if (content->data != NULL)
+ free(content->data);
+ }
if (content->desc != NULL)
free(content->desc);
@@ -311,35 +291,25 @@ static void g_memory_content_finalize(GMemoryContent *content)
GBinContent *g_memory_content_new(const bin_t *data, phys_t size)
{
- GMemoryContent *result; /* Structure à retourner */
- bin_t *allocated; /* Zone de réception */
-
- allocated = malloc(size);
- if (allocated == NULL)
- {
- LOG_ERROR_N("malloc");
- return NULL;
- }
-
- memcpy(allocated, data, size);
+ GBinContent *result; /* Structure à retourner */
result = g_object_new(G_TYPE_MEMORY_CONTENT, NULL);
- result->data = allocated;
- result->length = size;
+ if (!g_memory_content_create(G_MEMORY_CONTENT(result), data, size))
+ g_clear_object(&result);
- return G_BIN_CONTENT(result);
+ return result;
}
/******************************************************************************
* *
-* Paramètres : content = élément GLib à constuire. *
-* storage = conservateur de données à manipuler ou NULL. *
-* pbuf = zone tampon à lire. *
+* Paramètres : content = instance à initialiser pleinement. *
+* data = données du contenu volatile. *
+* size = quantité de ces données. *
* *
-* Description : Charge un contenu depuis une mémoire tampon. *
+* Description : Met en place un contenu de données brutes depuis la mémoire. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -347,108 +317,37 @@ GBinContent *g_memory_content_new(const bin_t *data, phys_t size)
* *
******************************************************************************/
-static bool g_memory_content_load(GMemoryContent *content, GObjectStorage *storage, packed_buffer_t *pbuf)
+bool g_memory_content_create(GMemoryContent *content, const bin_t *data, phys_t size)
{
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);
+ bin_t *allocated; /* Zone de réception */
- if (result)
+ allocated = malloc(size);
+ if (allocated == NULL)
{
- result = (get_rle_string(&str) != NULL);
-
- if (result)
- content->full_desc = strdup(get_rle_string(&str));
-
- exit_rle_string(&str);
-
+ LOG_ERROR_N("malloc");
+ goto exit;
}
- if (result)
- result = unpack_rle_string(&str, pbuf);
+ memcpy(allocated, data, size);
- if (result)
- {
- result = (get_rle_string(&str) != NULL);
+ content->data = allocated;
+ content->length = size;
+ content->allocated = true;
- if (result)
- content->desc = strdup(get_rle_string(&str));
+ result = true;
- exit_rle_string(&str);
-
- }
+ exit:
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;
-}
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
/******************************************************************************
@@ -466,7 +365,10 @@ static bool g_memory_content_store(const GMemoryContent *content, GObjectStorage
static void g_memory_content_set_attributes(GMemoryContent *content, GContentAttributes *attribs)
{
+ g_clear_object(&content->attribs);
+
content->attribs = attribs;
+ g_object_ref(G_OBJECT(attribs));
}
@@ -489,6 +391,9 @@ static GContentAttributes *g_memory_content_get_attributes(const GMemoryContent
result = content->attribs;
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
return result;
}
@@ -512,6 +417,8 @@ static GBinContent *g_memory_content_get_root(GMemoryContent *content)
result = G_BIN_CONTENT(content);
+ g_object_ref(G_OBJECT(result));
+
return result;
}
@@ -789,15 +696,12 @@ static bool g_memory_content_read_u8(const GMemoryContent *content, vmpa2t *addr
{
bool result; /* Bilan de lecture à renvoyer */
phys_t pos; /* Tête de lecture courante */
- phys_t length; /* Taille de la surface dispo. */
pos = get_phy_addr(addr);
if (pos == VMPA_NO_PHYSICAL)
return false;
- length = length;
-
result = read_u8(val, content->data, &pos, content->length);
if (result)
@@ -979,3 +883,124 @@ static bool g_memory_content_read_leb128(const GMemoryContent *content, vmpa2t *
return result;
}
+
+
+/******************************************************************************
+* *
+* 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);
+
+ content->allocated = true;
+
+ }
+
+ 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;
+
+}