diff options
Diffstat (limited to 'plugins/pychrysa/glibext')
-rw-r--r-- | plugins/pychrysa/glibext/bincontent.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/plugins/pychrysa/glibext/bincontent.c b/plugins/pychrysa/glibext/bincontent.c index a418c34..085c9af 100644 --- a/plugins/pychrysa/glibext/bincontent.c +++ b/plugins/pychrysa/glibext/bincontent.c @@ -40,6 +40,9 @@ static PyObject *py_binary_content_new(PyTypeObject *, PyObject *, PyObject *); /* 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 *); + /* Lit un nombre non signé sur un octet. */ static PyObject *py_binary_content_read_u8(PyObject *, PyObject *); @@ -114,7 +117,36 @@ static PyObject *py_binary_content_get_checksum(PyObject *self, PyObject *args) checksum = g_binary_content_get_cheksum(content); result = PyUnicode_FromString(checksum); - Py_INCREF(result); + + 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; @@ -146,11 +178,11 @@ static PyObject *py_binary_content_read_u8(PyObject *self, PyObject *args) content = G_BIN_CONTENT(pygobject_get(self)); - printf("Passage\n"); + //printf("Passage\n"); ret = PyArg_ParseTuple(args, "O", &addr_obj); - printf("ret == %d\n", ret); + //printf("ret == %d\n", ret); if (!ret) return NULL; @@ -160,7 +192,7 @@ static PyObject *py_binary_content_read_u8(PyObject *self, PyObject *args) status = g_binary_content_read_u8(content, addr, &val); if (!status) return NULL; - printf("val :: 0x%02hhx\n", val); + //printf("val :: 0x%02hhx\n", val); result = PyBytes_FromStringAndSize((char *)&val, 1);; //Py_INCREF(result); @@ -193,7 +225,11 @@ PyTypeObject *get_python_binary_content_type(void) static PyMethodDef py_binary_content_methods[] = { { "get_cheksum", py_binary_content_get_checksum, METH_NOARGS, - "Compute a SHA256 hash as chechsum of handled data." + "get_cheksum($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." }, { "read_u8", py_binary_content_read_u8, METH_VARARGS, |