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.c179
1 files changed, 82 insertions, 97 deletions
diff --git a/src/analysis/contents/memory.c b/src/analysis/contents/memory.c
index 9ddc4fa..f8ff863 100644
--- a/src/analysis/contents/memory.c
+++ b/src/analysis/contents/memory.c
@@ -51,12 +51,6 @@ 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 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 *);
@@ -65,7 +59,7 @@ static void g_memory_content_finalize(GMemoryContent *);
-/* ---------------------- INTERACTIONS AVEC UN CONTENU BINAIRE ---------------------- */
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
/* Associe un ensemble d'attributs au contenu binaire. */
@@ -122,11 +116,6 @@ 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 *);
-
-
-/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */
-
-
/* Charge un contenu depuis une mémoire tampon. */
static bool g_memory_content_load(GMemoryContent *, GObjectStorage *, packed_buffer_t *);
@@ -141,9 +130,7 @@ static bool g_memory_content_store(const GMemoryContent *, GObjectStorage *, pac
/* 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_BIN_CONTENT, g_memory_content_interface_init)
- G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_memory_content_serializable_init));
+G_DEFINE_TYPE(GMemoryContent, g_memory_content, G_TYPE_BIN_CONTENT);
/******************************************************************************
@@ -161,12 +148,45 @@ 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;
+
+ content->get_root = (get_content_root_fc)g_memory_content_get_root;
+
+ content->describe = (describe_content_fc)g_memory_content_describe;
+
+ content->compute_checksum = (compute_checksum_fc)g_memory_content_compute_checksum;
+
+ 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;
+
+ content->seek = (seek_fc)g_memory_content_seek;
+
+ content->get_raw_access = (get_raw_access_fc)g_memory_content_get_raw_access;
+
+ 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;
+
+ content->load = (load_content_cb)g_memory_content_load;
+ content->store = (store_content_cb)g_memory_content_store;
+
}
@@ -196,6 +216,7 @@ static void g_memory_content_init(GMemoryContent *content)
content->data = NULL;
content->length = 0;
+ content->allocated = false;
content->full_desc = strdup("In-memory content");
content->desc = strdup("In-memory content");
@@ -205,70 +226,6 @@ static void g_memory_content_init(GMemoryContent *content)
/******************************************************************************
* *
-* Paramètres : iface = interface GLib à initialiser. *
-* *
-* Description : Procède à l'initialisation de l'interface de lecture. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void g_memory_content_interface_init(GBinContentInterface *iface)
-{
- 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;
-
- iface->compute_checksum = (compute_checksum_fc)g_memory_content_compute_checksum;
-
- 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;
-
- iface->seek = (seek_fc)g_memory_content_seek;
-
- iface->get_raw_access = (get_raw_access_fc)g_memory_content_get_raw_access;
-
- 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;
-
- iface->read_uleb128 = (read_uleb128_fc)g_memory_content_read_uleb128;
- iface->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;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : content = instance d'objet GLib à traiter. *
* *
* Description : Supprime toutes les références externes. *
@@ -302,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);
@@ -331,31 +291,62 @@ static void g_memory_content_finalize(GMemoryContent *content)
GBinContent *g_memory_content_new(const bin_t *data, phys_t size)
{
- GMemoryContent *result; /* Structure à retourner */
+ GBinContent *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_MEMORY_CONTENT, NULL);
+
+ if (!g_memory_content_create(G_MEMORY_CONTENT(result), data, size))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = instance à initialiser pleinement. *
+* data = données du contenu volatile. *
+* size = quantité de ces données. *
+* *
+* Description : Met en place un contenu de données brutes depuis la mémoire. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_memory_content_create(GMemoryContent *content, const bin_t *data, phys_t size)
+{
+ bool result; /* Bilan à retourner */
bin_t *allocated; /* Zone de réception */
allocated = malloc(size);
if (allocated == NULL)
{
LOG_ERROR_N("malloc");
- return NULL;
+ goto exit;
}
memcpy(allocated, data, size);
- result = g_object_new(G_TYPE_MEMORY_CONTENT, NULL);
+ content->data = allocated;
+ content->length = size;
+ content->allocated = true;
- result->data = allocated;
- result->length = size;
+ result = true;
+
+ exit:
- return G_BIN_CONTENT(result);
+ return result;
}
/* ---------------------------------------------------------------------------------- */
-/* INTERACTIONS AVEC UN CONTENU BINAIRE */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
/* ---------------------------------------------------------------------------------- */
@@ -705,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)
@@ -897,12 +885,6 @@ static bool g_memory_content_read_leb128(const GMemoryContent *content, vmpa2t *
}
-
-/* ---------------------------------------------------------------------------------- */
-/* CONSERVATION ET RECHARGEMENT DES DONNEES */
-/* ---------------------------------------------------------------------------------- */
-
-
/******************************************************************************
* *
* Paramètres : content = élément GLib à constuire. *
@@ -929,6 +911,9 @@ static bool g_memory_content_load(GMemoryContent *content, GObjectStorage *stora
{
content->data = malloc(length);
result = (content->data != NULL);
+
+ content->allocated = true;
+
}
if (result)