diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-08-18 21:55:24 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-08-18 21:55:24 (GMT) |
commit | a0a7b6c1e05c78ae433f353d15e3366107b67d03 (patch) | |
tree | bca0b187778cf016c6131bfc982b08c67a38442b /plugins/pychrysa/analysis/db/items | |
parent | 161c0f8ab227af5033b1b6456607b9b9c3bc60df (diff) |
Inserted storages and collections into loaded binaries (first steps).
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@389 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/analysis/db/items')
-rw-r--r-- | plugins/pychrysa/analysis/db/items/Makefile.am | 14 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/db/items/comment.c | 233 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/db/items/comment.h | 42 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/db/items/module.c | 91 | ||||
-rw-r--r-- | plugins/pychrysa/analysis/db/items/module.h | 39 |
5 files changed, 419 insertions, 0 deletions
diff --git a/plugins/pychrysa/analysis/db/items/Makefile.am b/plugins/pychrysa/analysis/db/items/Makefile.am new file mode 100644 index 0000000..b08a558 --- /dev/null +++ b/plugins/pychrysa/analysis/db/items/Makefile.am @@ -0,0 +1,14 @@ + +noinst_LTLIBRARIES = libpychrysaanalysisdbitems.la + +libpychrysaanalysisdbitems_la_SOURCES = \ + comment.h comment.c \ + module.h module.c + +libpychrysaanalysisdbitems_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/analysis/db/items/comment.c b/plugins/pychrysa/analysis/db/items/comment.c new file mode 100644 index 0000000..1bb2863 --- /dev/null +++ b/plugins/pychrysa/analysis/db/items/comment.c @@ -0,0 +1,233 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comment.c - équivalent Python du fichier "analysis/db/items/comment.c" + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * OpenIDA 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. + * + * OpenIDA 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 "comment.h" + + +#include <pygobject.h> + + +#include <i18n.h> +#include <analysis/db/items/comment.h> + + +#include "../item.h" +#include "../../../arch/vmpa.h" + + + +/* Crée un nouvel objet Python de type 'DbComment'. */ +static PyObject *py_db_comment_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le commentaire associé à un commentaire. */ +static PyObject *py_db_comment_get_text(PyObject *, void *); + +/* Définit le commentaire associé à un commentaire. */ +static int py_db_comment_set_text(PyObject *, PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'DbComment'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_db_comment_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + PyObject *py_vmpa; /* Localisation version Python */ + char *text; /* Texte à associer */ + int is_volatile; /* Conservation en mémoire */ + int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Localisation version C */ + GDbComment *comment; /* Version GLib du commentaire */ + + ret = PyArg_ParseTuple(args, "Osp", &py_vmpa, &text, &is_volatile); + if (!ret) Py_RETURN_NONE; + + addr = get_internal_vmpa(py_vmpa); + if (py_vmpa == NULL) Py_RETURN_NONE; + + comment = g_db_comment_new(addr, text, is_volatile); + + result = pygobject_new(G_OBJECT(comment)); + g_object_unref(comment); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le commentaire associé à un commentaire. * +* * +* Retour : Texte manipulable en Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_db_comment_get_text(PyObject *self, void *closure) +{ + GDbComment *comment; /* Commentaire à consulter */ + const char *content; /* Contenu textuel associé */ + + comment = G_DB_COMMENT(pygobject_get(self)); + content = g_db_comment_get_text(comment); + + return PyUnicode_FromString(content); + +} + + +/*********************d********************************************************* +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit le commentaire associé à un commentaire. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_db_comment_set_text(PyObject *self, PyObject *value, void *closure) +{ + GDbComment *comment; /* Commentaire à consulter */ + + if (!PyUnicode_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string.")); + return -1; + } + + comment = G_DB_COMMENT(pygobject_get(self)); + g_db_comment_set_text(comment, PyUnicode_DATA(value)); + + 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_db_comment_type(void) +{ + static PyMethodDef py_db_comment_methods[] = { + { NULL } + }; + + static PyGetSetDef py_db_comment_getseters[] = { + { + "text", py_db_comment_get_text, py_db_comment_set_text, + "Give access to the content of a given comment.", NULL + }, + { NULL } + }; + + static PyTypeObject py_db_comment_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.db.items.DbComment", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide comment for edited binary", + + .tp_methods = py_db_comment_methods, + .tp_getset = py_db_comment_getseters, + .tp_new = (newfunc)py_db_comment_new + + }; + + return &py_db_comment_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide....db.items.DbComment'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_db_comment(PyObject *module) +{ + PyTypeObject *py_db_comment_type; /* Type Python 'DbComment' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_db_comment_type = get_python_db_comment_type(); + + py_db_comment_type->tp_base = get_python_db_item_type(); + py_db_comment_type->tp_basicsize = py_db_comment_type->tp_base->tp_basicsize; + + if (PyType_Ready(py_db_comment_type) != 0) + return false; + + Py_INCREF(py_db_comment_type); + ret = PyModule_AddObject(module, "DbComment", (PyObject *)py_db_comment_type); + if (ret != 0) return false; + + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "DbComment", G_TYPE_DB_COMMENT, py_db_comment_type, + Py_BuildValue("(O)", py_db_comment_type->tp_base)); + + return true; + +} diff --git a/plugins/pychrysa/analysis/db/items/comment.h b/plugins/pychrysa/analysis/db/items/comment.h new file mode 100644 index 0000000..db02dca --- /dev/null +++ b/plugins/pychrysa/analysis/db/items/comment.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comment.h - prototypes pour l'équivalent Python du fichier "analysis/db/items/comment.h" + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * OpenIDA 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. + * + * OpenIDA 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_PYCHRYSA_ANALYSIS_DB_ITEMS_COMMENT_H +#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_COMMENT_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_db_comment_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.db.items.DbComment'. */ +bool register_python_db_comment(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_COMMENT_H */ diff --git a/plugins/pychrysa/analysis/db/items/module.c b/plugins/pychrysa/analysis/db/items/module.c new file mode 100644 index 0000000..3c634e3 --- /dev/null +++ b/plugins/pychrysa/analysis/db/items/module.c @@ -0,0 +1,91 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire items en tant que module + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * OpenIDA 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. + * + * OpenIDA 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 "module.h" + + +#include "comment.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'items' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_analysis_db_items_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_items_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.analysis.db.items", + .m_doc = "Python module for Chrysalide.analysis.db.items", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_items_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_items_module); + if (ret != 0) goto aadimtpm_exit; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db.items"); + if (ret != 0) goto aadimtpm_exit; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "items", module); + if (ret != 0) goto aadimtpm_exit; + + result = true; + + result &= register_python_db_comment(module); + + aadimtpm_exit: + + if (!result) + { + printf("something went wrong in %s...\n", __FUNCTION__); + /* ... */ + + } + + return result; + +} diff --git a/plugins/pychrysa/analysis/db/items/module.h b/plugins/pychrysa/analysis/db/items/module.h new file mode 100644 index 0000000..d780d30 --- /dev/null +++ b/plugins/pychrysa/analysis/db/items/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire items en tant que module + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * OpenIDA 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. + * + * OpenIDA 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_PYCHRYSA_ANALYSIS_DB_ITEMS_MODULE_H +#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_MODULE_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Ajoute le module 'items' au module Python. */ +bool add_analysis_db_items_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_MODULE_H */ |