diff options
Diffstat (limited to 'plugins/pychrysalide/core')
| -rw-r--r-- | plugins/pychrysalide/core/Makefile.am | 1 | ||||
| -rw-r--r-- | plugins/pychrysalide/core/global.c | 280 | ||||
| -rw-r--r-- | plugins/pychrysalide/core/global.h | 42 | ||||
| -rw-r--r-- | plugins/pychrysalide/core/module.c | 2 | 
4 files changed, 325 insertions, 0 deletions
diff --git a/plugins/pychrysalide/core/Makefile.am b/plugins/pychrysalide/core/Makefile.am index bc21d77..999674d 100644 --- a/plugins/pychrysalide/core/Makefile.am +++ b/plugins/pychrysalide/core/Makefile.am @@ -4,6 +4,7 @@ noinst_LTLIBRARIES = libpychrysacore.la  libpychrysacore_la_SOURCES =			\  	demanglers.h demanglers.c			\  	formats.h formats.c					\ +	global.h global.c					\  	logs.h logs.c						\  	module.h module.c					\  	params.h params.c diff --git a/plugins/pychrysalide/core/global.c b/plugins/pychrysalide/core/global.c new file mode 100644 index 0000000..0fe767f --- /dev/null +++ b/plugins/pychrysalide/core/global.c @@ -0,0 +1,280 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * global.c - équivalent Python du fichier "core/global.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 "global.h" + + +#include <pygobject.h> + + +#include <core/global.h> + + +#include "../helpers.h" +#include "../analysis/project.h" + + + +/* Fournit l'adresse de l'explorateur de contenus courant. */ +static PyObject *py_global_get_content_explorer(PyObject *, void *); + +/* Fournit l'adresse du résolveur de contenus courant. */ +static PyObject *py_global_get_content_resolver(PyObject *, void *); + +/* Fournit l'adresse du projet courant. */ +static PyObject *py_global_get_current_project(PyObject *, void *); + +/* Définit l'adresse du projet courant. */ +static int py_global_set_current_project(PyObject *, PyObject *, void *); + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = objet Python concerné par l'appel.                 * +*                closure = non utilisé ici.                                   * +*                                                                             * +*  Description : Fournit l'adresse de l'explorateur de contenus courant.      * +*                                                                             * +*  Retour      : Adresse de l'explorateur global ou None si aucun (!).        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_global_get_content_explorer(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Instance Python à retourner */ +    GContentExplorer *explorer;             /* Gestionnaire natif récupéré */ + +    explorer = get_current_content_explorer(); + +    if (explorer != NULL) +    { +        result = pygobject_new(G_OBJECT(explorer)); +        g_object_unref(G_OBJECT(explorer)); +    } +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = objet Python concerné par l'appel.                 * +*                closure = non utilisé ici.                                   * +*                                                                             * +*  Description : Fournit l'adresse du résolveur de contenus courant.          * +*                                                                             * +*  Retour      : Adresse du résolveur global ou None si aucun (!).            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_global_get_content_resolver(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Instance Python à retourner */ +    GContentResolver *resolver;             /* Gestionnaire natif récupéré */ + +    resolver = get_current_content_resolver(); + +    if (resolver != NULL) +    { +        result = pygobject_new(G_OBJECT(resolver)); +        g_object_unref(G_OBJECT(resolver)); +    } +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = objet Python concerné par l'appel.                 * +*                closure = non utilisé ici.                                   * +*                                                                             * +*  Description : Fournit l'adresse du projet courant.                         * +*                                                                             * +*  Retour      : Adresse du résolveur global ou None si aucun.                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_global_get_current_project(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Instance Python à retourner */ +    GStudyProject *project;                 /* Projet courant récupéré     */ + +    project = get_current_project(); + +    if (project != NULL) +    { +        result = pygobject_new(G_OBJECT(project)); +        g_object_unref(G_OBJECT(project)); +    } +    else +    { +        result = Py_None; +        Py_INCREF(result); +    } + +    printf("result: %p (project=%p)\n", result, project); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = objet Python concerné par l'appel.                 * +*                value   = valeur fournie à intégrer ou prendre en compte.    * +*                closure = adresse non utilisée ici.                          * +*                                                                             * +*  Description : Définit l'adresse du projet courant.                         * +*                                                                             * +*  Retour      : Bilan de l'opération pour Python.                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static int py_global_set_current_project(PyObject *self, PyObject *value, void *closure) +{ +    int ret;                                /* Bilan d'analyse             */ +    GStudyProject *project;                 /* Version GLib du format      */ + +    ret = PyObject_IsInstance(value, (PyObject *)get_python_study_project_type()); +    if (!ret) return -1; + +    project = G_STUDY_PROJECT(pygobject_get(value)); + +    g_object_ref(G_OBJECT(project)); + +    set_current_project(project); + +    return 0; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Fournit un accès à une définition de type à diffuser.        * +*                                                                             * +*  Retour      : Définition d'objet pour Python.                              * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +PyTypeObject *get_python_global_type(void) +{ +    static PyMethodDef py_global_methods[] = { +        { NULL } +    }; + +    static PyGetSetDef py_global_getseters[] = { +        { +            "content_explorer", py_global_get_content_explorer, NULL, +            "Get the global exploration manager discovering contents.", NULL +        }, +        { +            "content_resolver", py_global_get_content_resolver, NULL, +            "Get the global resolution manager translating binary contents into loaded contents.", NULL +        }, +        { +            "current_project", py_global_get_current_project, py_global_set_current_project, +            "Get or set the current global project.", NULL +        }, +        { NULL } +    }; + +    static PyTypeObject py_global_type = { + +        PyVarObject_HEAD_INIT(NULL, 0) + +        .tp_name = "pychrysalide.core._global", +        .tp_basicsize = sizeof(PyObject), + +        .tp_flags = Py_TPFLAGS_DEFAULT, + +        .tp_doc = "Access to the global properties", + +        .tp_methods = py_global_methods, +        .tp_getset  = py_global_getseters + +    }; + +    return &py_global_type; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : module = module dont la définition est à compléter.          * +*                                                                             * +*  Description : Prend en charge l'objet 'pychrysalide.core._global'.         * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool register_python_global(PyObject *module) +{ +    PyTypeObject *py_global_type;           /* Type Python de 'global'     */ +    int ret;                                /* Bilan d'un appel            */ + +    py_global_type = get_python_global_type(); + +    py_global_type->tp_new = PyType_GenericNew; + +    if (PyType_Ready(py_global_type) != 0) +        return false; + +    Py_INCREF(py_global_type); +    ret = PyModule_AddObject(module, "_global", (PyObject *)py_global_type); + +    return (ret == 0); + +} diff --git a/plugins/pychrysalide/core/global.h b/plugins/pychrysalide/core/global.h new file mode 100644 index 0000000..b136cdb --- /dev/null +++ b/plugins/pychrysalide/core/global.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * global.h - prototypes pour l'équivalent Python du fichier "core/global.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_GLOBAL_H +#define _PLUGINS_PYCHRYSALIDE_CORE_GLOBAL_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_global_type(void); + +/* Prend en charge l'objet 'pychrysalide.core._global'. */ +bool register_python_global(PyObject *); + + + +#endif  /* _PLUGINS_PYCHRYSALIDE_CORE_GLOBAL_H */ diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c index dd89ea0..22d9a48 100644 --- a/plugins/pychrysalide/core/module.c +++ b/plugins/pychrysalide/core/module.c @@ -30,6 +30,7 @@  #include "demanglers.h"  #include "formats.h" +#include "global.h"  #include "logs.h"  #include "params.h"  #include "../access.h" @@ -84,6 +85,7 @@ bool add_core_module_to_python_module(PyObject *super)      result &= register_python_demanglers(module);      result &= register_python_formats(module); +    result &= register_python_global(module);      result &= register_python_logs(module);      result &= register_python_params(module);  | 
