From d33e8935c5186ab2459dfa6c9340396377524fb1 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Thu, 27 Dec 2018 23:24:07 +0100
Subject: Extended the Python bindings.

---
 plugins/elf/python/dynamic.c            | 45 ++++++++++++++++++++++++++++++++-
 plugins/elf/python/dynamic.h            |  3 +++
 plugins/elf/python/format.c             |  7 ++++-
 plugins/pychrysalide/analysis/content.c | 44 ++++++++++++++++++++++++++++++++
 4 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/plugins/elf/python/dynamic.c b/plugins/elf/python/dynamic.c
index 9fe6eb4..32c7826 100644
--- a/plugins/elf/python/dynamic.c
+++ b/plugins/elf/python/dynamic.c
@@ -37,7 +37,7 @@
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : self = format Elf à manipuler.                               *
-*                args = indice de la section visée.                           *
+*                args = indice de l'élément recherché.                        *
 *                                                                             *
 *  Description : Retrouve un élément dans la section dynamique par son indice.*
 *                                                                             *
@@ -79,6 +79,49 @@ PyObject *py_elf_format_find_dynamic_item_by_index(PyObject *self, PyObject *arg
 
 /******************************************************************************
 *                                                                             *
+*  Paramètres  : self = format Elf à manipuler.                               *
+*                args = sorte d'élément recherché.                            *
+*                                                                             *
+*  Description : Retrouve un élément dans la section dynamique par son type.  *
+*                                                                             *
+*  Retour      : Elément trouvé ou rien (None).                               *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+PyObject *py_elf_format_find_dynamic_item_by_type(PyObject *self, PyObject *args)
+{
+    PyObject *result;                       /* Trouvaille à retourner      */
+    GElfFormat *format;                     /* Version GLib du format      */
+    unsigned long type;                     /* Type de l'élément visé      */
+    int ret;                                /* Bilan de lecture des args.  */
+    elf_dyn item;                           /* Informations remontées      */
+    bool found;                             /* Recherches concluantes ?    */
+
+    format = G_ELF_FORMAT(pygobject_get(self));
+
+    ret = PyArg_ParseTuple(args, "k", &type);
+    if (!ret) return NULL;
+
+    found = find_elf_dynamic_item_by_type(format, type, &item);
+
+    if (found)
+        result = translate_elf_dyn_to_python(format, &item);
+
+    else
+    {
+        result = Py_None;
+        Py_INCREF(result);
+    }
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
 *  Paramètres  : self    = classe représentant un format ELF.                 *
 *                closure = adresse non utilisée ici.                          *
 *                                                                             *
diff --git a/plugins/elf/python/dynamic.h b/plugins/elf/python/dynamic.h
index 4ef2936..2f209ec 100644
--- a/plugins/elf/python/dynamic.h
+++ b/plugins/elf/python/dynamic.h
@@ -33,6 +33,9 @@
 /* Retrouve un élément dans la section dynamique par son indice. */
 PyObject *py_elf_format_find_dynamic_item_by_index(PyObject *, PyObject *);
 
+/* Retrouve un élément dans la section dynamique par son type. */
+PyObject *py_elf_format_find_dynamic_item_by_type(PyObject *, PyObject *);
+
 /* Fournit la liste des objets partagés requis. */
 PyObject *py_elf_format_get_needed(PyObject *, void *);
 
diff --git a/plugins/elf/python/format.c b/plugins/elf/python/format.c
index 4e2b7cc..b78dadb 100644
--- a/plugins/elf/python/format.c
+++ b/plugins/elf/python/format.c
@@ -180,7 +180,12 @@ PyTypeObject *get_python_elf_format_type(void)
         {
             "find_dynamic_item_by_index", py_elf_format_find_dynamic_item_by_index,
             METH_VARARGS,
-            "find_dynamic_item_by_index($self, type, /)\n--\n\nFind an item from the dynamic segment using a given index."
+            "find_dynamic_item_by_index($self, index, /)\n--\n\nFind an item from the dynamic segment using a given index."
+        },
+        {
+            "find_dynamic_item_by_type", py_elf_format_find_dynamic_item_by_type,
+            METH_VARARGS,
+            "find_dynamic_item_by_type($self, type, /)\n--\n\nFind an item from the dynamic segment using a given type."
         },
         { NULL }
     };
diff --git a/plugins/pychrysalide/analysis/content.c b/plugins/pychrysalide/analysis/content.c
index 26e7654..fab7dfe 100644
--- a/plugins/pychrysalide/analysis/content.c
+++ b/plugins/pychrysalide/analysis/content.c
@@ -41,6 +41,9 @@
 
 
 
+/* Fournit le nom associé au contenu binaire. */
+static PyObject *py_binary_content_describe(PyObject *, PyObject *);
+
 /* Fournit une portion des données représentées. */
 static PyObject *py_binary_content_read_raw(PyObject *, PyObject *);
 
@@ -76,6 +79,42 @@ static PyObject *py_binary_content_get_all_bytes(PyObject *, void *);
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : self = contenu binaire à manipuler.                          *
+*                args = précise s'il s'agit d'une version longue ou non.      *
+*                                                                             *
+*  Description : Fournit le nom associé au contenu binaire.                   *
+*                                                                             *
+*  Retour      : Nom de fichier avec chemin absolu au besoin.                 *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static PyObject *py_binary_content_describe(PyObject *self, PyObject *args)
+{
+    PyObject *result;                       /* Instance à retourner        */
+    GBinContent *content;                   /* Version GLib du format      */
+    int full;                               /* Description complète ?      */
+    int ret;                                /* Bilan de lecture des args.  */
+    const char *desc;                       /* Description obtenue         */
+
+    content = G_BIN_CONTENT(pygobject_get(self));
+    assert(content != NULL);
+
+    ret = PyArg_ParseTuple(args, "p", &full);
+    if (!ret) return NULL;
+
+    desc = g_binary_content_describe(content, full);
+
+    result = PyUnicode_FromString(desc);
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : self = contenu binaire à manipuler.                          *
 *                args = non utilisé ici.                                      *
 *                                                                             *
 *  Description : Fournit une portion des données représentées.                *
@@ -479,6 +518,11 @@ PyTypeObject *get_python_binary_content_type(void)
 {
     static PyMethodDef py_binary_content_methods[] = {
         {
+            "describe", py_binary_content_describe,
+            METH_VARARGS,
+            "describe($self, full, /)\n--\n\nGet a (full ?) description 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."
-- 
cgit v0.11.2-87-g4458