summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/content.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-10-01 19:58:48 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-10-01 19:58:48 (GMT)
commite7a46981a76c2d60b8485d06ffc408623276a091 (patch)
tree5bbcbfd4ee4b294e46f3d222d09db203d5f89b8e /plugins/pychrysalide/analysis/content.c
parentd8f695596e4225de797504f8f797e1347491dd14 (diff)
Made the Python bindings more Pythonish.
Diffstat (limited to 'plugins/pychrysalide/analysis/content.c')
-rw-r--r--plugins/pychrysalide/analysis/content.c296
1 files changed, 146 insertions, 150 deletions
diff --git a/plugins/pychrysalide/analysis/content.c b/plugins/pychrysalide/analysis/content.c
index f828b1a..f590f82 100644
--- a/plugins/pychrysalide/analysis/content.c
+++ b/plugins/pychrysalide/analysis/content.c
@@ -41,18 +41,6 @@
-/* Fournit une empreinte unique (SHA256) pour les données. */
-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 *);
@@ -68,129 +56,21 @@ static PyObject *py_binary_content_read_u32(PyObject *, PyObject *);
/* Lit un nombre non signé sur huit octets. */
static PyObject *py_binary_content_read_u64(PyObject *, PyObject *);
-/* Renvoie tout le contenu binaire d'un coup. */
-static PyObject *py_binary_content_get_all_bytes(PyObject *, void *);
-
-
-
-/******************************************************************************
-* *
-* Paramètres : self = contenu binaire à manipuler. *
-* args = non utilisé ici. *
-* *
-* Description : Fournit une empreinte unique (SHA256) pour les données. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_binary_content_get_checksum(PyObject *self, PyObject *args)
-{
- PyObject *result; /* Instance à retourner */
- GBinContent *content; /* Version GLib du format */
- const gchar *checksum; /* Empreinte fournie */
-
- content = G_BIN_CONTENT(pygobject_get(self));
-
- checksum = g_binary_content_get_checksum(content);
-
- result = PyUnicode_FromString(checksum);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = contenu binaire à manipuler. *
-* args = non utilisé ici. *
-* *
-* Description : Détermine le nombre d'octets lisibles. *
-* *
-* Retour : Quantité représentée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_binary_content_compute_size(PyObject *self, PyObject *args)
-{
- PyObject *result; /* Instance à retourner */
- GBinContent *content; /* Version GLib du format */
- phys_t size; /* Quantité d'octets dispos. */
-
- content = G_BIN_CONTENT(pygobject_get(self));
-
- size = g_binary_content_compute_size(content);
-
- result = PyLong_FromUnsignedLongLong(size);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* 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 */
+/* Fournit une empreinte unique (SHA256) pour les données. */
+static PyObject *py_binary_content_get_checksum(PyObject *, void *);
- content = G_BIN_CONTENT(pygobject_get(self));
+/* Détermine le nombre d'octets lisibles. */
+static PyObject *py_binary_content_compute_size(PyObject *, void *);
- g_binary_content_compute_end_pos(content, &pos);
+/* Détermine la position initiale d'un contenu. */
+static PyObject *py_binary_content_compute_start_pos(PyObject *, void *);
- result = build_from_internal_vmpa(&pos);
+/* Détermine la position finale d'un contenu. */
+static PyObject *py_binary_content_compute_end_pos(PyObject *, void *);
- return result;
+/* Renvoie tout le contenu binaire d'un coup. */
+static PyObject *py_binary_content_get_all_bytes(PyObject *, void *);
-}
/******************************************************************************
@@ -430,6 +310,126 @@ static PyObject *py_binary_content_read_u64(PyObject *self, PyObject *args)
* Paramètres : self = contenu binaire à manipuler. *
* closure = adresse non utilisée ici. *
* *
+* Description : Fournit une empreinte unique (SHA256) pour les données. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_content_get_checksum(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance à retourner */
+ GBinContent *content; /* Version GLib du format */
+ const gchar *checksum; /* Empreinte fournie */
+
+ content = G_BIN_CONTENT(pygobject_get(self));
+
+ checksum = g_binary_content_get_checksum(content);
+
+ result = PyUnicode_FromString(checksum);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = contenu binaire à manipuler. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Détermine le nombre d'octets lisibles. *
+* *
+* Retour : Quantité représentée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_content_compute_size(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance à retourner */
+ GBinContent *content; /* Version GLib du format */
+ phys_t size; /* Quantité d'octets dispos. */
+
+ content = G_BIN_CONTENT(pygobject_get(self));
+
+ size = g_binary_content_compute_size(content);
+
+ result = PyLong_FromUnsignedLongLong(size);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = contenu binaire à manipuler. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Détermine la position initiale d'un contenu. *
+* *
+* Retour : Position initiale. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_content_compute_start_pos(PyObject *self, void *closure)
+{
+ 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. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Détermine la position finale d'un contenu. *
+* *
+* Retour : Position finale. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_content_compute_end_pos(PyObject *self, void *closure)
+{
+ 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. *
+* closure = adresse non utilisée ici. *
+* *
* Description : Renvoie tout le contenu binaire d'un coup. *
* *
* Retour : Ensemble d'octets lus. *
@@ -479,26 +479,6 @@ PyTypeObject *get_python_binary_content_type(void)
{
static PyMethodDef py_binary_content_methods[] = {
{
- "get_checksum", py_binary_content_get_checksum,
- METH_NOARGS,
- "get_checksum($self, /)\n--\n\nCompute a SHA256 hash as chechsum of handled data."
- },
- {
- "compute_size", py_binary_content_compute_size,
- METH_NOARGS,
- "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."
@@ -528,6 +508,22 @@ PyTypeObject *get_python_binary_content_type(void)
static PyGetSetDef py_binary_content_getseters[] = {
{
+ "checksum", py_binary_content_get_checksum, NULL,
+ "Compute a SHA256 hash as chechsum of handled data.", NULL
+ },
+ {
+ "size", py_binary_content_compute_size, NULL,
+ "Compute the quantity of readable bytes.", NULL
+ },
+ {
+ "start_pos", py_binary_content_compute_start_pos, NULL,
+ "Provide the starting position of the binary content.", NULL
+ },
+ {
+ "end_pos", py_binary_content_compute_end_pos, NULL,
+ "Provide the ending position of the binary content.", NULL
+ },
+ {
"data", py_binary_content_get_all_bytes, NULL,
"Provide all the content bytes at once.", NULL
},