summaryrefslogtreecommitdiff
path: root/plugins/gdbrsp/python
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-12-07 21:04:46 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-12-07 21:04:46 (GMT)
commit648bf475951e6d588d13539441d8a0e54eab2706 (patch)
treeb654558a0c6bb4bc9d15eb9d65c124acb8a3522a /plugins/gdbrsp/python
parentc980546e8bca6f1c0c340634a4c3640e14fd1228 (diff)
Moved some core features into plugins.
Diffstat (limited to 'plugins/gdbrsp/python')
-rw-r--r--plugins/gdbrsp/python/Makefile.am19
-rw-r--r--plugins/gdbrsp/python/gdb.c173
-rw-r--r--plugins/gdbrsp/python/gdb.h42
-rw-r--r--plugins/gdbrsp/python/module.c94
-rw-r--r--plugins/gdbrsp/python/module.h42
5 files changed, 370 insertions, 0 deletions
diff --git a/plugins/gdbrsp/python/Makefile.am b/plugins/gdbrsp/python/Makefile.am
new file mode 100644
index 0000000..8ece12b
--- /dev/null
+++ b/plugins/gdbrsp/python/Makefile.am
@@ -0,0 +1,19 @@
+
+noinst_LTLIBRARIES = libpychrysadebuggdbrsp.la
+
+libpychrysadebuggdbrsp_la_SOURCES = \
+ gdb.h gdb.c \
+ module.h module.c
+
+libpychrysadebuggdbrsp_la_LDFLAGS =
+
+
+devdir = $(includedir)/chrysalide-$(subdir)
+
+dev_HEADERS = $(libpychrysadebuggdbrsp_la_SOURCES:%c=)
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+ -I$(top_srcdir)/src
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/plugins/gdbrsp/python/gdb.c b/plugins/gdbrsp/python/gdb.c
new file mode 100644
index 0000000..77b72b0
--- /dev/null
+++ b/plugins/gdbrsp/python/gdb.c
@@ -0,0 +1,173 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * gdb.c - équivalent Python du fichier "debug/gdbrsp/gdb.c"
+ *
+ * Copyright (C) 2016 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 "gdb.h"
+
+
+#include <pygobject.h>
+
+
+#include <i18n.h>
+
+
+#include <debug/gdbrsp/gdb.h>
+
+
+#include "../debugger.h"
+#include "../../access.h"
+#include "../../helpers.h"
+#include "../../analysis/binary.h"
+
+
+
+/* Crée un nouvel objet Python de type 'GdbDebugger'. */
+static PyObject *py_gdb_debugger_new(PyTypeObject *, PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* 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 'GdbDebugger'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_gdb_debugger_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Instance à retourner */
+ PyObject *binary_obj; /* Objet pour le binaire lié */
+ const char *server; /* Nom du serveur à contacter */
+ unsigned short port; /* Port de connexion */
+ int ret; /* Bilan de lecture des args. */
+ GLoadedBinary *binary; /* Binaire chargé en mémoire */
+ GBinaryDebugger *debugger; /* Création GLib à transmettre */
+
+ ret = PyArg_ParseTuple(args, "OsH", &binary_obj, &server, &port);
+ if (!ret) return NULL;
+
+ ret = PyObject_IsInstance(binary_obj, (PyObject *)get_python_loaded_binary_type());
+ if (!ret)
+ {
+ PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of LoadedBinary."));
+ return NULL;
+ }
+
+ binary = G_LOADED_BINARY(pygobject_get(binary_obj));
+
+ debugger = g_gdb_debugger_new(binary, server, port);
+
+ result = pygobject_new(G_OBJECT(debugger));
+
+ g_object_unref(debugger);
+
+ return (PyObject *)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_gdb_debugger_type(void)
+{
+ static PyMethodDef py_gdb_debugger_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_gdb_debugger_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_gdb_debugger_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.debug.gdbrsp.GdbDebugger",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "PyChrysalide GDB debugger",
+
+ .tp_methods = py_gdb_debugger_methods,
+ .tp_getset = py_gdb_debugger_getseters,
+ .tp_new = py_gdb_debugger_new
+
+ };
+
+ return &py_gdb_debugger_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide....gdbrsp.GdbDebugger'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_gdb_debugger_is_registered(void)
+{
+ PyTypeObject *type; /* Type Python 'GdbDebugger' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_gdb_debugger_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.debug.gdbrsp");
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_GDB_DEBUGGER, type, get_python_binary_debugger_type()))
+ return false;
+
+ }
+
+ return true;
+
+}
diff --git a/plugins/gdbrsp/python/gdb.h b/plugins/gdbrsp/python/gdb.h
new file mode 100644
index 0000000..057a38d
--- /dev/null
+++ b/plugins/gdbrsp/python/gdb.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * gdb.h - prototypes pour l'équivalent Python du fichier "debug/gdbrsp/gdb.h"
+ *
+ * Copyright (C) 2016 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_DEBUG_GDBRSP_DEBUGGER_H
+#define _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_DEBUGGER_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_gdb_debugger_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.debug.gdbrsp.GdbDebugger'. */
+bool ensure_python_gdb_debugger_is_registered(void);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_DEBUGGER_H */
diff --git a/plugins/gdbrsp/python/module.c b/plugins/gdbrsp/python/module.c
new file mode 100644
index 0000000..c077aa7
--- /dev/null
+++ b/plugins/gdbrsp/python/module.c
@@ -0,0 +1,94 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire gdbrsp en tant que module
+ *
+ * Copyright (C) 2012 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 "gdb.h"
+#include "../../helpers.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : super = module dont la définition est à compléter. *
+* *
+* Description : Ajoute le module 'debug.gdbresp' à un module Python. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_debug_gdbresp_module(PyObject *super)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
+
+ static PyModuleDef py_chrysalide_debug_gdbresp_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.debug.gdbrsp",
+ .m_doc = "Python module for Chrysalide.debug.gdbrsp",
+
+ .m_size = -1,
+
+ };
+
+ module = build_python_module(super, &py_chrysalide_debug_gdbresp_module);
+
+ result = (module != NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Intègre les objets du module 'debug.gdbresp'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool populate_debug_gdbresp_module(void)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ if (result) result = ensure_python_gdb_debugger_is_registered();
+
+ assert(result);
+
+ return result;
+
+}
diff --git a/plugins/gdbrsp/python/module.h b/plugins/gdbrsp/python/module.h
new file mode 100644
index 0000000..0ed3719
--- /dev/null
+++ b/plugins/gdbrsp/python/module.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire gdbrsp en tant que module
+ *
+ * Copyright (C) 2012-2016 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_DEBUG_GDBRSP_MODULE_H
+#define _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_MODULE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute le module 'debug.gdbresp' à un module Python. */
+bool add_debug_gdbresp_module(PyObject *);
+
+/* Intègre les objets du module 'debug.gdbresp'. */
+bool populate_debug_gdbresp_module(void);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_MODULE_H */