summaryrefslogtreecommitdiff
path: root/plugins/pychrysa
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-11-12 20:49:22 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-11-12 20:49:22 (GMT)
commit7591f34e7e9d5dd0f20d242394628ab4bcd0a430 (patch)
treeb5deac80eed58ac9e160f70f4e47bb3180588bcb /plugins/pychrysa
parent0194351c3401df90ab8f7cffb0d40968fb4c31ad (diff)
Improved the type of data read from loaded contents.
Diffstat (limited to 'plugins/pychrysa')
-rw-r--r--plugins/pychrysa/analysis/content.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/plugins/pychrysa/analysis/content.c b/plugins/pychrysa/analysis/content.c
index 5565129..95f88f6 100644
--- a/plugins/pychrysa/analysis/content.c
+++ b/plugins/pychrysa/analysis/content.c
@@ -46,6 +46,9 @@ 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 *);
+/* Fournit une portion des données représentées. */
+static PyObject *py_binary_content_read_raw(PyObject *, PyObject *);
+
/* Lit un nombre non signé sur un octet. */
static PyObject *py_binary_content_read_u8(PyObject *, PyObject *);
@@ -125,6 +128,52 @@ static PyObject *py_binary_content_compute_size(PyObject *self, PyObject *args)
* 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. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_content_read_raw(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Instance à retourner */
+ GBinContent *content; /* Version GLib du format */
+ PyObject *addr_obj; /* Objet pour une position */
+ vmpa2t *addr; /* Position interne associée */
+ unsigned long long length; /* Quantité de données à lire */
+ int ret; /* Bilan de lecture des args. */
+ const bin_t *val; /* Valeur lue à faire suivre */
+
+ content = G_BIN_CONTENT(pygobject_get(self));
+ assert(content != NULL);
+
+ ret = PyArg_ParseTuple(args, "OK", &addr_obj, &length);
+ if (!ret) return NULL;
+
+ addr = get_internal_vmpa(addr_obj);
+ assert(addr != NULL);
+
+ val = g_binary_content_get_raw_access(content, addr, length);
+ if (val == NULL)
+ {
+ PyErr_SetString(PyExc_Exception, _("Invalid read access."));
+ return NULL;
+ }
+
+ result = PyBytes_FromStringAndSize((char *)val, length);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = contenu binaire à manipuler. *
+* args = non utilisé ici. *
+* *
* Description : Lit un nombre non signé sur un octet. *
* *
* Retour : Bilan de l'opération. *
@@ -159,7 +208,7 @@ static PyObject *py_binary_content_read_u8(PyObject *self, PyObject *args)
return NULL;
}
- result = PyBytes_FromStringAndSize((char *)&val, 1);
+ result = PyLong_FromUnsignedLong(val);
return result;
@@ -206,7 +255,7 @@ static PyObject *py_binary_content_read_u16(PyObject *self, PyObject *args)
return NULL;
}
- result = PyBytes_FromStringAndSize((char *)&val, 2);
+ result = PyLong_FromUnsignedLong(val);
return result;
@@ -253,7 +302,7 @@ static PyObject *py_binary_content_read_u32(PyObject *self, PyObject *args)
return NULL;
}
- result = PyBytes_FromStringAndSize((char *)&val, 4);
+ result = PyLong_FromUnsignedLong(val);
return result;
@@ -299,7 +348,7 @@ static PyObject *py_binary_content_read_u64(PyObject *self, PyObject *args)
return NULL;
}
- result = PyBytes_FromStringAndSize((char *)&val, 8);
+ result = PyLong_FromUnsignedLongLong(val);
return result;
@@ -332,6 +381,11 @@ PyTypeObject *get_python_binary_content_type(void)
"compute_size($self, /)\n--\n\nCompute the quantity of readable bytes."
},
{
+ "read_raw", py_binary_content_read_raw,
+ METH_VARARGS,
+ "read_raw($self, addr, length, /)\n--\n\nRead bytes from a given position."
+ },
+ {
"read_u8", py_binary_content_read_u8,
METH_VARARGS,
"read_u8($self, addr, /)\n--\n\nRead an unsigned byte from a given position."