summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/db/items
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/analysis/db/items')
-rw-r--r--plugins/pychrysalide/analysis/db/items/Makefile.am14
-rw-r--r--plugins/pychrysalide/analysis/db/items/comment.c241
-rw-r--r--plugins/pychrysalide/analysis/db/items/comment.h42
-rw-r--r--plugins/pychrysalide/analysis/db/items/module.c93
-rw-r--r--plugins/pychrysalide/analysis/db/items/module.h39
5 files changed, 429 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/db/items/Makefile.am b/plugins/pychrysalide/analysis/db/items/Makefile.am
new file mode 100644
index 0000000..b08a558
--- /dev/null
+++ b/plugins/pychrysalide/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/pychrysalide/analysis/db/items/comment.c b/plugins/pychrysalide/analysis/db/items/comment.c
new file mode 100644
index 0000000..28886f5
--- /dev/null
+++ b/plugins/pychrysalide/analysis/db/items/comment.c
@@ -0,0 +1,241 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * comment.c - équivalent Python du fichier "analysis/db/items/comment.c"
+ *
+ * Copyright (C) 2014-2017 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 "comment.h"
+
+
+#include <malloc.h>
+#include <pygobject.h>
+
+
+#include <i18n.h>
+#include <analysis/db/items/comment.h>
+
+
+#include "../item.h"
+#include "../../../helpers.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 */
+ const 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;
+
+ ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type());
+ if (!ret) return NULL;
+
+ addr = get_internal_vmpa(py_vmpa);
+ if (py_vmpa == NULL) Py_RETURN_NONE;
+
+ return NULL;/* FIXME */
+ //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)
+{
+ PyObject *result; /* Résultat à retourner */
+ GDbComment *comment; /* Commentaire à consulter */
+ char *text; /* Contenu textuel associé */
+
+ comment = G_DB_COMMENT(pygobject_get(self));
+ text = g_db_comment_get_text(comment);
+
+ if (text == NULL)
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+ else
+ {
+ result = PyUnicode_FromString(text);
+ free(text);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_db_comment_type = get_python_db_comment_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_DB_COMMENT, py_db_comment_type, get_python_db_item_type()))
+ return false;
+
+ return true;
+
+}
diff --git a/plugins/pychrysalide/analysis/db/items/comment.h b/plugins/pychrysalide/analysis/db/items/comment.h
new file mode 100644
index 0000000..2b4f130
--- /dev/null
+++ b/plugins/pychrysalide/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-2017 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_ANALYSIS_DB_ITEMS_COMMENT_H
+#define _PLUGINS_PYCHRYSALIDE_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_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_COMMENT_H */
diff --git a/plugins/pychrysalide/analysis/db/items/module.c b/plugins/pychrysalide/analysis/db/items/module.c
new file mode 100644
index 0000000..cf0fe56
--- /dev/null
+++ b/plugins/pychrysalide/analysis/db/items/module.c
@@ -0,0 +1,93 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire items en tant que module
+ *
+ * Copyright (C) 2014-2017 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 "module.h"
+
+
+#include <assert.h>
+
+
+#include "comment.h"
+#include "../../../access.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 loading_failed;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db.items");
+ if (ret != 0) goto loading_failed;
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "items", module);
+ if (ret != 0) goto loading_failed;
+
+ result = true;
+
+ result &= register_python_db_comment(module);
+
+ if (result)
+ register_access_to_python_module("pychrysalide.analysis.db.items", module);
+
+ loading_failed:
+
+ assert(result);
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/analysis/db/items/module.h b/plugins/pychrysalide/analysis/db/items/module.h
new file mode 100644
index 0000000..1382226
--- /dev/null
+++ b/plugins/pychrysalide/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-2017 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_ANALYSIS_DB_ITEMS_MODULE_H
+#define _PLUGINS_PYCHRYSALIDE_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_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_MODULE_H */