From d8f695596e4225de797504f8f797e1347491dd14 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 27 Sep 2018 00:40:22 +0200 Subject: Extended the API for binary contents. --- plugins/pychrysalide/analysis/content.c | 76 +++++++++++++++++++++++++++++++++ src/analysis/content-int.h | 4 ++ src/analysis/content.c | 24 +++++++++++ src/analysis/content.h | 3 ++ src/analysis/contents/encapsulated.c | 48 +++++++++++++++++++++ src/analysis/contents/file.c | 24 +++++++++++ src/analysis/contents/memory.c | 24 +++++++++++ src/analysis/contents/restricted.c | 24 +++++++++++ 8 files changed, 227 insertions(+) diff --git a/plugins/pychrysalide/analysis/content.c b/plugins/pychrysalide/analysis/content.c index e657857..f828b1a 100644 --- a/plugins/pychrysalide/analysis/content.c +++ b/plugins/pychrysalide/analysis/content.c @@ -47,6 +47,12 @@ static PyObject *py_binary_content_get_checksum(PyObject *, PyObject *); /* Détermine le nombre d'octets lisibles. */ static PyObject *py_binary_content_compute_size(PyObject *, PyObject *); +/* Détermine la position initiale d'un contenu. */ +static PyObject *py_binary_content_compute_start_pos(PyObject *, PyObject *); + +/* Détermine la position finale d'un contenu. */ +static PyObject *py_binary_content_compute_end_pos(PyObject *, PyObject *); + /* Fournit une portion des données représentées. */ static PyObject *py_binary_content_read_raw(PyObject *, PyObject *); @@ -132,6 +138,66 @@ static PyObject *py_binary_content_compute_size(PyObject *self, PyObject *args) * Paramètres : self = contenu binaire à manipuler. * * args = non utilisé ici. * * * +* Description : Détermine la position initiale d'un contenu. * +* * +* Retour : Position initiale. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_compute_start_pos(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + vmpa2t pos; /* Position à transmettre */ + + content = G_BIN_CONTENT(pygobject_get(self)); + + g_binary_content_compute_start_pos(content, &pos); + + result = build_from_internal_vmpa(&pos); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Détermine la position finale d'un contenu. * +* * +* Retour : Position finale. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_compute_end_pos(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + vmpa2t pos; /* Position à transmettre */ + + content = G_BIN_CONTENT(pygobject_get(self)); + + g_binary_content_compute_end_pos(content, &pos); + + result = build_from_internal_vmpa(&pos); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * * Description : Fournit une portion des données représentées. * * * * Retour : Bilan de l'opération. * @@ -423,6 +489,16 @@ PyTypeObject *get_python_binary_content_type(void) "compute_size($self, /)\n--\n\nCompute the quantity of readable bytes." }, { + "compute_start_pos", py_binary_content_compute_start_pos, + METH_NOARGS, + "compute_start_pos($self, /)\n--\n\nCompute the starting position of the binary content." + }, + { + "compute_end_pos", py_binary_content_compute_end_pos, + METH_NOARGS, + "compute_end_pos($self, /)\n--\n\nCompute the ending position of the binary content." + }, + { "read_raw", py_binary_content_read_raw, METH_VARARGS, "read_raw($self, addr, length, /)\n--\n\nRead bytes from a given position." diff --git a/src/analysis/content-int.h b/src/analysis/content-int.h index 49d5269..f3d698e 100644 --- a/src/analysis/content-int.h +++ b/src/analysis/content-int.h @@ -44,6 +44,9 @@ typedef void (* compute_checksum_fc) (GBinContent *, GChecksum *); /* Détermine le nombre d'octets lisibles. */ typedef phys_t (* compute_size_fc) (const GBinContent *); +/* Détermine la position initiale d'un contenu. */ +typedef void (* compute_start_pos_fc) (const GBinContent *, vmpa2t *); + /* Détermine la position finale d'un contenu. */ typedef void (* compute_end_pos_fc) (const GBinContent *, vmpa2t *); @@ -92,6 +95,7 @@ struct _GBinContentIface compute_checksum_fc compute_checksum; /* Calcul de l'empreinte */ compute_size_fc compute_size; /* Calcul de la taille totale */ + compute_start_pos_fc compute_start_pos; /* Calcul de position initiale */ compute_end_pos_fc compute_end_pos; /* Calcul de position finale */ seek_fc seek; /* Avancée de tête de lecture */ diff --git a/src/analysis/content.c b/src/analysis/content.c index 3c394f1..dbece37 100644 --- a/src/analysis/content.c +++ b/src/analysis/content.c @@ -243,6 +243,30 @@ phys_t g_binary_content_compute_size(const GBinContent *content) /****************************************************************************** * * * Paramètres : content = contenu binaire à venir lire. * +* pos = position initiale. [OUT] * +* * +* Description : Détermine la position initiale d'un contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_content_compute_start_pos(const GBinContent *content, vmpa2t *pos) +{ + GBinContentIface *iface; /* Interface utilisée */ + + iface = G_BIN_CONTENT_GET_IFACE(content); + + return iface->compute_start_pos(content, pos); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à venir lire. * * pos = position finale (exclusive). [OUT] * * * * Description : Détermine la position finale d'un contenu. * diff --git a/src/analysis/content.h b/src/analysis/content.h index 3f471f9..f16a164 100644 --- a/src/analysis/content.h +++ b/src/analysis/content.h @@ -72,6 +72,9 @@ const gchar *g_binary_content_get_checksum(GBinContent *); /* Détermine le nombre d'octets lisibles. */ phys_t g_binary_content_compute_size(const GBinContent *); +/* Détermine la position initiale d'un contenu. */ +void g_binary_content_compute_start_pos(const GBinContent *, vmpa2t *); + /* Détermine la position finale d'un contenu. */ void g_binary_content_compute_end_pos(const GBinContent *, vmpa2t *); diff --git a/src/analysis/contents/encapsulated.c b/src/analysis/contents/encapsulated.c index 74795ea..8a6ecae 100644 --- a/src/analysis/contents/encapsulated.c +++ b/src/analysis/contents/encapsulated.c @@ -85,6 +85,12 @@ static void g_encaps_content_compute_checksum(GEncapsContent *, GChecksum *); /* Détermine le nombre d'octets lisibles. */ static phys_t g_encaps_content_compute_size(const GEncapsContent *); +/* Détermine la position initiale d'un contenu. */ +static void g_encaps_content_compute_start_pos(const GEncapsContent *, vmpa2t *); + +/* Détermine la position finale d'un contenu. */ +static void g_encaps_content_compute_end_pos(const GEncapsContent *, vmpa2t *); + /* Avance la tête de lecture d'une certaine quantité de données. */ static bool g_encaps_content_seek(const GEncapsContent *, vmpa2t *, phys_t); @@ -193,6 +199,8 @@ static void g_encaps_content_interface_init(GBinContentInterface *iface) iface->compute_checksum = (compute_checksum_fc)g_encaps_content_compute_checksum; 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; iface->seek = (seek_fc)g_encaps_content_seek; @@ -525,6 +533,46 @@ static phys_t g_encaps_content_compute_size(const GEncapsContent *content) /****************************************************************************** * * * Paramètres : content = contenu binaire à venir lire. * +* pos = position initiale. [OUT] * +* * +* Description : Détermine la position initiale d'un contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_encaps_content_compute_start_pos(const GEncapsContent *content, vmpa2t *pos) +{ + g_binary_content_compute_start_pos(content->endpoint, pos); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à venir lire. * +* pos = position finale (exclusive). [OUT] * +* * +* Description : Détermine la position finale d'un contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_encaps_content_compute_end_pos(const GEncapsContent *content, vmpa2t *pos) +{ + g_binary_content_compute_end_pos(content->endpoint, pos); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à venir lire. * * addr = position de la tête de lecture. * * length = quantité d'octets à provisionner. * * * diff --git a/src/analysis/contents/file.c b/src/analysis/contents/file.c index 3f256c9..6b55840 100644 --- a/src/analysis/contents/file.c +++ b/src/analysis/contents/file.c @@ -88,6 +88,9 @@ static void g_file_content_compute_checksum(GFileContent *, GChecksum *); /* Détermine le nombre d'octets lisibles. */ static phys_t g_file_content_compute_size(const GFileContent *); +/* Détermine la position initiale d'un contenu. */ +static void g_file_content_compute_start_pos(const GFileContent *, vmpa2t *); + /* Détermine la position finale d'un contenu. */ static void g_file_content_compute_end_pos(const GFileContent *, vmpa2t *); @@ -193,6 +196,7 @@ static void g_file_content_interface_init(GBinContentInterface *iface) iface->compute_checksum = (compute_checksum_fc)g_file_content_compute_checksum; iface->compute_size = (compute_size_fc)g_file_content_compute_size; + iface->compute_start_pos = (compute_start_pos_fc)g_file_content_compute_start_pos; iface->compute_end_pos = (compute_end_pos_fc)g_file_content_compute_end_pos; iface->seek = (seek_fc)g_file_content_seek; @@ -530,6 +534,26 @@ static phys_t g_file_content_compute_size(const GFileContent *content) /****************************************************************************** * * * Paramètres : content = contenu binaire à venir lire. * +* pos = position initiale. [OUT] * +* * +* Description : Détermine la position initiale d'un contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_file_content_compute_start_pos(const GFileContent *content, vmpa2t *pos) +{ + copy_vmpa(pos, get_mrange_addr(&content->range)); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à venir lire. * * pos = position finale (exclusive). [OUT] * * * * Description : Détermine la position finale d'un contenu. * diff --git a/src/analysis/contents/memory.c b/src/analysis/contents/memory.c index 404481f..7406a3a 100644 --- a/src/analysis/contents/memory.c +++ b/src/analysis/contents/memory.c @@ -88,6 +88,9 @@ static void g_memory_content_compute_checksum(GMemoryContent *, GChecksum *); /* Détermine le nombre d'octets lisibles. */ static phys_t g_memory_content_compute_size(const GMemoryContent *); +/* Détermine la position initiale d'un contenu. */ +static void g_memory_content_compute_start_pos(const GMemoryContent *, vmpa2t *); + /* Détermine la position finale d'un contenu. */ static void g_memory_content_compute_end_pos(const GMemoryContent *, vmpa2t *); @@ -195,6 +198,7 @@ static void g_memory_content_interface_init(GBinContentInterface *iface) 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; @@ -513,6 +517,26 @@ static phys_t g_memory_content_compute_size(const GMemoryContent *content) /****************************************************************************** * * * Paramètres : content = contenu binaire à venir lire. * +* pos = position initiale. [OUT] * +* * +* Description : Détermine la position initiale d'un contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_memory_content_compute_start_pos(const GMemoryContent *content, vmpa2t *pos) +{ + g_binary_content_compute_start_pos(content->backend, pos); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à venir lire. * * pos = position finale (exclusive). [OUT] * * * * Description : Détermine la position finale d'un contenu. * diff --git a/src/analysis/contents/restricted.c b/src/analysis/contents/restricted.c index 647192f..1c0c8e6 100644 --- a/src/analysis/contents/restricted.c +++ b/src/analysis/contents/restricted.c @@ -75,6 +75,9 @@ static void g_restricted_content_compute_checksum(GRestrictedContent *, GChecksu /* Détermine le nombre d'octets lisibles. */ static phys_t g_restricted_content_compute_size(const GRestrictedContent *); +/* Détermine la position initiale d'un contenu. */ +static void g_restricted_content_compute_start_pos(const GRestrictedContent *, vmpa2t *); + /* Détermine la position finale d'un contenu. */ static void g_restricted_content_compute_end_pos(const GRestrictedContent *, vmpa2t *); @@ -176,6 +179,7 @@ static void g_restricted_content_interface_init(GBinContentInterface *iface) iface->compute_checksum = (compute_checksum_fc)g_restricted_content_compute_checksum; iface->compute_size = (compute_size_fc)g_restricted_content_compute_size; + iface->compute_start_pos = (compute_start_pos_fc)g_restricted_content_compute_start_pos; iface->compute_end_pos = (compute_end_pos_fc)g_restricted_content_compute_end_pos; iface->seek = (seek_fc)g_restricted_content_seek; @@ -379,6 +383,26 @@ static phys_t g_restricted_content_compute_size(const GRestrictedContent *conten /****************************************************************************** * * * Paramètres : content = contenu binaire à venir lire. * +* pos = position initiale. [OUT] * +* * +* Description : Détermine la position initiale d'un contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_restricted_content_compute_start_pos(const GRestrictedContent *content, vmpa2t *pos) +{ + copy_vmpa(pos, get_mrange_addr(&content->range)); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à venir lire. * * pos = position finale (exclusive). [OUT] * * * * Description : Détermine la position finale d'un contenu. * -- cgit v0.11.2-87-g4458