From cdfc8c13fdd78c4af6e0ad120a8369e5fcb2e78d Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Wed, 12 Dec 2018 03:37:58 +0100 Subject: Implemented the Python bindings to load unknown binaries. --- plugins/pychrysalide/analysis/project.c | 98 ++++++++++++++++++++++++++++-- plugins/pychrysalide/core/Makefile.am | 3 +- plugins/pychrysalide/core/module.c | 2 + plugins/pychrysalide/core/params.c | 4 +- plugins/pychrysalide/core/queue.c | 103 ++++++++++++++++++++++++++++++++ plugins/pychrysalide/core/queue.h | 39 ++++++++++++ 6 files changed, 240 insertions(+), 9 deletions(-) create mode 100644 plugins/pychrysalide/core/queue.c create mode 100644 plugins/pychrysalide/core/queue.h diff --git a/plugins/pychrysalide/analysis/project.c b/plugins/pychrysalide/analysis/project.c index 62ce43b..06a67b6 100644 --- a/plugins/pychrysalide/analysis/project.c +++ b/plugins/pychrysalide/analysis/project.c @@ -25,13 +25,14 @@ #include "project.h" -#include +#include #include #include +#include "content.h" #include "loaded.h" #include "../access.h" #include "../helpers.h" @@ -44,9 +45,15 @@ static PyObject *py_study_project_new(PyTypeObject *, PyObject *, PyObject *); /* Procède à l'enregistrement d'un projet donné. */ static PyObject *py_study_project_save(PyObject *, PyObject *); +/* Assure l'intégration de contenus binaires dans un projet. */ +static PyObject *py_study_project_discover_binary_content(PyObject *, PyObject *); + /* Attache un contenu donné à un projet donné. */ static PyObject *py_study_project_attach_content(PyObject *, PyObject *); +/* Fournit l'ensemble des contenus associés à un projet. */ +static PyObject *py_study_project_get_contents(PyObject *, void *); + /****************************************************************************** @@ -112,7 +119,6 @@ static PyObject *py_study_project_save(PyObject *self, PyObject *args) bool status; /* Bilan de l'opération */ project = G_STUDY_PROJECT(pygobject_get(self)); - assert(project != NULL); ret = PyArg_ParseTuple(args, "s", &filename); if (!ret) return NULL; @@ -132,6 +138,37 @@ static PyObject *py_study_project_save(PyObject *self, PyObject *args) * Paramètres : self = projet d'étude à manipuler. * * args = arguments accompagnant l'appel. * * * +* Description : Assure l'intégration de contenus binaires dans un projet. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_study_project_discover_binary_content(PyObject *self, PyObject *args) +{ + GStudyProject *project; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + GBinContent *content; /* Instance de contenu binaire */ + + project = G_STUDY_PROJECT(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content); + if (!ret) return NULL; + + g_study_project_discover_binary_content(project, content); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = projet d'étude à manipuler. * +* args = arguments accompagnant l'appel. * +* * * Description : Attache un contenu donné à un projet donné. * * * * Retour : - * @@ -142,17 +179,16 @@ static PyObject *py_study_project_save(PyObject *self, PyObject *args) static PyObject *py_study_project_attach_content(PyObject *self, PyObject *args) { - GStudyProject *project; /* Version GLib du format */ PyObject *content_obj; /* Objet pour le contenu */ int ret; /* Bilan de lecture des args. */ GLoadedContent *content; /* Instance GLib correspondante*/ - - project = G_STUDY_PROJECT(pygobject_get(self)); - assert(project != NULL); + GStudyProject *project; /* Version GLib du format */ ret = PyArg_ParseTuple(args, "O!", get_python_loaded_content_type(), &content_obj); if (!ret) return NULL; + project = G_STUDY_PROJECT(pygobject_get(self)); + content = G_LOADED_CONTENT(pygobject_get(content_obj)); g_study_project_attach_content(project, content); @@ -164,6 +200,46 @@ static PyObject *py_study_project_attach_content(PyObject *self, PyObject *args) /****************************************************************************** * * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit l'ensemble des contenus associés à un projet. * +* * +* Retour : Liste de contenus chargés. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_study_project_get_contents(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GStudyProject *project; /* Version GLib du format */ + size_t count; /* Nombre de contenus présents */ + GLoadedContent **contents; /* Liste de contenus chargés */ + size_t i; /* Boucle de parcours */ + + project = G_STUDY_PROJECT(pygobject_get(self)); + + contents = g_study_project_get_contents(project, &count); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + PyTuple_SetItem(result, i, pygobject_new(G_OBJECT(contents[i]))); + + g_object_unref(G_OBJECT(contents[i])); + + } + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * @@ -183,6 +259,11 @@ PyTypeObject *get_python_study_project_type(void) "save($self, filename, /)\n--\n\nSave the project into a given file." }, { + "discover", py_study_project_discover_binary_content, + METH_VARARGS, + "discover($self, content, /)\n--\n\nExplore a new binary content for the project." + }, + { "attach", py_study_project_attach_content, METH_VARARGS, "attach($self, loaded, /)\n--\n\nAdd a loaded content to the project." @@ -191,6 +272,11 @@ PyTypeObject *get_python_study_project_type(void) }; static PyGetSetDef py_study_project_getseters[] = { + { + "contents", py_study_project_get_contents, NULL, + "List of all loaded contents for the project.", NULL + }, + { NULL } }; diff --git a/plugins/pychrysalide/core/Makefile.am b/plugins/pychrysalide/core/Makefile.am index b431dcc..4018012 100644 --- a/plugins/pychrysalide/core/Makefile.am +++ b/plugins/pychrysalide/core/Makefile.am @@ -6,7 +6,8 @@ libpychrysacore_la_SOURCES = \ global.h global.c \ logs.h logs.c \ module.h module.c \ - params.h params.c + params.h params.c \ + queue.h queue.c libpychrysacore_la_LDFLAGS = diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c index 71fa508..aade384 100644 --- a/plugins/pychrysalide/core/module.c +++ b/plugins/pychrysalide/core/module.c @@ -32,6 +32,7 @@ #include "global.h" #include "logs.h" #include "params.h" +#include "queue.h" #include "../helpers.h" @@ -95,6 +96,7 @@ bool populate_core_module(void) if (result) result = ensure_python_global_is_registered(); if (result) result = ensure_python_logs_is_registered(); if (result) result = ensure_python_params_is_registered(); + if (result) result = populate_core_module_with_queue(); assert(result); diff --git a/plugins/pychrysalide/core/params.c b/plugins/pychrysalide/core/params.c index 94d55b1..e31c129 100644 --- a/plugins/pychrysalide/core/params.c +++ b/plugins/pychrysalide/core/params.c @@ -51,7 +51,7 @@ static bool py_params_define_constants(PyTypeObject *); * * * Description : Fournit la version du programme global. * * * -* Retour : Numéro de révision. * +* Retour : Configuration prête à emploi ou None si aucune définie. * * * * Remarques : - * * * @@ -107,7 +107,7 @@ PyTypeObject *get_python_params_type(void) .tp_doc = "Python object for parameters", - .tp_methods = py_params_methods + .tp_methods = py_params_methods }; diff --git a/plugins/pychrysalide/core/queue.c b/plugins/pychrysalide/core/queue.c new file mode 100644 index 0000000..9c1365a --- /dev/null +++ b/plugins/pychrysalide/core/queue.c @@ -0,0 +1,103 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * queue.c - équivalent Python du fichier "core/queue.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "queue.h" + + +#include + + +#include + + +#include "../access.h" +#include "../helpers.h" + + + +/* Attend que toutes les tâches de tout groupe soient traitées. */ +static PyObject *py_queue_wait_for_all_global_works(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = non utilisé ici. * +* * +* Description : Attend que toutes les tâches de tout groupe soient traitées. * +* * +* Retour : None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_queue_wait_for_all_global_works(PyObject *self, PyObject *args) +{ + wait_for_all_global_works(); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Définit une extension du module 'core' à compléter. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool populate_core_module_with_queue(void) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Module à recompléter */ + int ret; /* Bilan d'un appel */ + + static PyMethodDef py_queue_methods[] = { + + { "wait_for_all_global_works", py_queue_wait_for_all_global_works, + METH_NOARGS, + "wait_for_all_global_works(, /)\n--\n\nWait for all tasks being processed." + }, + { NULL } + + }; + + module = get_access_to_python_module("pychrysalide.core"); + + ret = PyModule_AddFunctions(module, py_queue_methods); + + result = (ret == 0); + + return result; + +} + diff --git a/plugins/pychrysalide/core/queue.h b/plugins/pychrysalide/core/queue.h new file mode 100644 index 0000000..36da0ca --- /dev/null +++ b/plugins/pychrysalide/core/queue.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * queue.h - prototypes pour l'équivalent Python du fichier "core/queue.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_CORE_QUEUE_H +#define _PLUGINS_PYCHRYSALIDE_CORE_QUEUE_H + + +#include +#include + + + +/* Définit une extension du module 'core' à compléter. */ +bool populate_core_module_with_queue(void); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_CORE_QUEUE_H */ -- cgit v0.11.2-87-g4458