summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/db
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-08 07:47:41 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-08 07:47:41 (GMT)
commitfbb80d00d8ac456451963d52af24fcccbbc1d751 (patch)
tree232d2f63378bf30db17c33c399cedc28fc13d4f9 /plugins/pychrysalide/analysis/db
parent1a85f36e0505d75a51ab7b7f2c5078da7ef6bd98 (diff)
Updated the database protocol for bookmarks.
Diffstat (limited to 'plugins/pychrysalide/analysis/db')
-rw-r--r--plugins/pychrysalide/analysis/db/item.c45
-rw-r--r--plugins/pychrysalide/analysis/db/item.h3
-rw-r--r--plugins/pychrysalide/analysis/db/items/Makefile.am1
-rw-r--r--plugins/pychrysalide/analysis/db/items/bookmark.c397
-rw-r--r--plugins/pychrysalide/analysis/db/items/bookmark.h45
-rw-r--r--plugins/pychrysalide/analysis/db/items/module.c2
6 files changed, 493 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/db/item.c b/plugins/pychrysalide/analysis/db/item.c
index 0544d86..981e0c0 100644
--- a/plugins/pychrysalide/analysis/db/item.c
+++ b/plugins/pychrysalide/analysis/db/item.c
@@ -188,3 +188,48 @@ bool ensure_python_db_item_is_registered(void)
return true;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en élément pour base de données. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_db_item(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_db_item_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to database item");
+ break;
+
+ case 1:
+ *((GDbItem **)dst) = G_DB_ITEM(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/analysis/db/item.h b/plugins/pychrysalide/analysis/db/item.h
index 376371b..09a6a07 100644
--- a/plugins/pychrysalide/analysis/db/item.h
+++ b/plugins/pychrysalide/analysis/db/item.h
@@ -37,6 +37,9 @@ PyTypeObject *get_python_db_item_type(void);
/* Prend en charge l'objet 'pychrysalide.analysis.db.DbItem'. */
bool ensure_python_db_item_is_registered(void);
+/* Tente de convertir en élément pour base de données. */
+int convert_to_db_item(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEM_H */
diff --git a/plugins/pychrysalide/analysis/db/items/Makefile.am b/plugins/pychrysalide/analysis/db/items/Makefile.am
index fbb3e22..bea86de 100644
--- a/plugins/pychrysalide/analysis/db/items/Makefile.am
+++ b/plugins/pychrysalide/analysis/db/items/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libpychrysaanalysisdbitems.la
libpychrysaanalysisdbitems_la_SOURCES = \
+ bookmark.h bookmark.c \
comment.h comment.c \
module.h module.c
diff --git a/plugins/pychrysalide/analysis/db/items/bookmark.c b/plugins/pychrysalide/analysis/db/items/bookmark.c
new file mode 100644
index 0000000..8a33357
--- /dev/null
+++ b/plugins/pychrysalide/analysis/db/items/bookmark.c
@@ -0,0 +1,397 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * bookmark.c - équivalent Python du fichier "analysis/db/items/bookmark.c"
+ *
+ * Copyright (C) 2019 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 "bookmark.h"
+
+
+#include <malloc.h>
+#include <pygobject.h>
+
+
+#include <analysis/db/items/bookmark.h>
+#include <plugins/dt.h>
+
+
+#include "../item.h"
+#include "../../../access.h"
+#include "../../../helpers.h"
+#include "../../../arch/vmpa.h"
+
+
+
+/* Crée un nouvel objet Python de type 'DbBookmark'. */
+static PyObject *py_db_bookmark_new(PyTypeObject *, PyObject *, PyObject *);
+
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_db_bookmark_init(PyObject *, PyObject *, PyObject *);
+
+/* Fournit l'adresse associée à un signet. */
+static PyObject *py_db_bookmark_get_address(PyObject *, void *);
+
+/* Fournit le commentaire associé à un signet. */
+static PyObject *py_db_bookmark_get_comment(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 'DbBookmark'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_db_bookmark_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Objet à retourner */
+ PyTypeObject *base; /* Type de base à dériver */
+ bool first_time; /* Evite les multiples passages*/
+ GType gtype; /* Nouveau type de processeur */
+ bool status; /* Bilan d'un enregistrement */
+
+ /* Validations diverses */
+
+ base = get_python_db_bookmark_type();
+
+ if (type == base)
+ goto simple_way;
+
+ /* Mise en place d'un type dédié */
+
+ first_time = (g_type_from_name(type->tp_name) == 0);
+
+ gtype = build_dynamic_type(G_TYPE_DB_BOOKMARK, type->tp_name, NULL, NULL, NULL);
+
+ if (first_time)
+ {
+ status = register_class_for_dynamic_pygobject(gtype, type, base);
+
+ if (!status)
+ {
+ result = NULL;
+ goto exit;
+ }
+
+ }
+
+ /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
+
+ simple_way:
+
+ result = PyType_GenericNew(type, args, kwds);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet à initialiser (théoriquement). *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
+* *
+* Retour : 0 en cas de succès, -1 sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_db_bookmark_init(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ int result; /* Bilan à renvoyer */
+ vmpa2t addr; /* Emplacement ciblé */
+ const char *comment; /* Commentaire éventuel associé*/
+ int ret; /* Bilan de lecture des args. */
+ PyObject *new_args; /* Nouveaux arguments épurés */
+ PyObject *new_kwds; /* Nouveau dictionnaire épuré */
+ GDbBookmark *bookmark; /* Version GLib du signet */
+ bool status; /* Bilan de l'initialisation */
+
+#define DB_BOOKMARK_DOC \
+ "DbBookmark provides support for bookmarks inside the disassembled code.\n" \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " DbBookmark(addr, comment=None)" \
+ "\n" \
+ "Where addr is a location of type pychrysalide.arch.vmpa and" \
+ " comment is a string or None."
+
+ result = -1;
+
+ /* Récupération des paramètres */
+
+ comment = NULL;
+
+ ret = PyArg_ParseTuple(args, "O&|s", convert_any_to_vmpa, &addr, &comment);
+ if (!ret) goto exit;
+
+ /* Initialisation d'un objet GLib */
+
+ new_args = PyTuple_New(0);
+ new_kwds = PyDict_New();
+
+ ret = PyGObject_Type.tp_init(self, new_args, new_kwds);
+
+ Py_DECREF(new_kwds);
+ Py_DECREF(new_args);
+
+ if (ret == -1) goto exit;
+
+ /* Eléments de base */
+
+ bookmark = G_DB_BOOKMARK(pygobject_get(self));
+
+ status = g_db_bookmark_fill(bookmark, &addr, comment);
+ if (!status) goto exit;
+
+ result = 0;
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit l'adresse associée à un signet. *
+* *
+* Retour : Adresse mémoire. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_db_bookmark_get_address(PyObject *self, void *closure)
+{
+ PyObject *result; /* Résultat à retourner */
+ GDbBookmark *bookmark; /* Signet à consulter */
+ const vmpa2t *addr; /* Localisation de ce signet */
+
+#define DB_BOOKMARK_ADDRESS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ address, py_db_bookmark, \
+ "Location of the bookmark." \
+)
+
+ bookmark = G_DB_BOOKMARK(pygobject_get(self));
+
+ addr = g_db_bookmark_get_address(bookmark);
+
+ result = build_from_internal_vmpa(addr);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit le commentaire associé à un signet. *
+* *
+* Retour : Commentaire existant ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_db_bookmark_get_comment(PyObject *self, void *closure)
+{
+ PyObject *result; /* Résultat à retourner */
+ GDbBookmark *bookmark; /* Signet à consulter */
+ const char *comment; /* Contenu textuel associé */
+
+#define DB_BOOKMARK_COMMENT_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ comment, py_db_bookmark, \
+ "Comment linked to the bookmark or None if the bookmark has been unset." \
+)
+
+ bookmark = G_DB_BOOKMARK(pygobject_get(self));
+
+ comment = g_db_bookmark_get_comment(bookmark);
+
+ if (comment != NULL)
+ result = PyUnicode_FromString(comment);
+
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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_bookmark_type(void)
+{
+ static PyMethodDef py_db_bookmark_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_db_bookmark_getseters[] = {
+ DB_BOOKMARK_ADDRESS_ATTRIB,
+ DB_BOOKMARK_COMMENT_ATTRIB,
+ { NULL }
+ };
+
+ static PyTypeObject py_db_bookmark_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.db.items.DbBookmark",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = DB_BOOKMARK_DOC,
+
+ .tp_methods = py_db_bookmark_methods,
+ .tp_getset = py_db_bookmark_getseters,
+
+ .tp_init = py_db_bookmark_init,
+ .tp_new = py_db_bookmark_new,
+
+ };
+
+ return &py_db_bookmark_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide...db.items.DbBookmark'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_db_bookmark_is_registered(void)
+{
+ PyTypeObject *type; /* Type Python 'DbBookmark' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_db_bookmark_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.analysis.db.items");
+
+ dict = PyModule_GetDict(module);
+
+ if (!ensure_python_db_item_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, G_TYPE_DB_BOOKMARK, type, get_python_db_item_type()))
+ return false;
+
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en signet de collection. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_db_bookmark(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_db_bookmark_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to collection bookmark");
+ break;
+
+ case 1:
+ *((GDbBookmark **)dst) = G_DB_BOOKMARK(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/analysis/db/items/bookmark.h b/plugins/pychrysalide/analysis/db/items/bookmark.h
new file mode 100644
index 0000000..bcf1c11
--- /dev/null
+++ b/plugins/pychrysalide/analysis/db/items/bookmark.h
@@ -0,0 +1,45 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * bookmark.h - prototypes pour l'équivalent Python du fichier "analysis/db/items/bookmark.h"
+ *
+ * Copyright (C) 2019 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_BOOKMARK_H
+#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_BOOKMARK_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_db_bookmark_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.db.items.DbBookmark'. */
+bool ensure_python_db_bookmark_is_registered(void);
+
+/* Tente de convertir en signet de collection. */
+int convert_to_db_bookmark(PyObject *, void *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_BOOKMARK_H */
diff --git a/plugins/pychrysalide/analysis/db/items/module.c b/plugins/pychrysalide/analysis/db/items/module.c
index 1f9e580..fcf636f 100644
--- a/plugins/pychrysalide/analysis/db/items/module.c
+++ b/plugins/pychrysalide/analysis/db/items/module.c
@@ -28,6 +28,7 @@
#include <assert.h>
+#include "bookmark.h"
#include "comment.h"
#include "../../../helpers.h"
@@ -88,6 +89,7 @@ bool populate_analysis_db_items_module(void)
result = true;
+ if (result) result = ensure_python_db_bookmark_is_registered();
if (result) result = ensure_python_db_comment_is_registered();
assert(result);