diff options
Diffstat (limited to 'plugins/pychrysa/gtkext')
-rw-r--r-- | plugins/pychrysa/gtkext/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/pychrysa/gtkext/blockview.c | 109 | ||||
-rw-r--r-- | plugins/pychrysa/gtkext/blockview.h | 9 | ||||
-rw-r--r-- | plugins/pychrysa/gtkext/bufferview.c | 117 | ||||
-rw-r--r-- | plugins/pychrysa/gtkext/bufferview.h | 42 | ||||
-rw-r--r-- | plugins/pychrysa/gtkext/module.c | 39 | ||||
-rw-r--r-- | plugins/pychrysa/gtkext/viewpanel.c | 126 | ||||
-rw-r--r-- | plugins/pychrysa/gtkext/viewpanel.h | 9 |
8 files changed, 334 insertions, 118 deletions
diff --git a/plugins/pychrysa/gtkext/Makefile.am b/plugins/pychrysa/gtkext/Makefile.am index 4849c7b..958f000 100644 --- a/plugins/pychrysa/gtkext/Makefile.am +++ b/plugins/pychrysa/gtkext/Makefile.am @@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libpychrysagtkext.la libpychrysagtkext_la_SOURCES = \ blockview.h blockview.c \ + bufferview.h bufferview.c \ viewpanel.h viewpanel.c \ module.h module.c diff --git a/plugins/pychrysa/gtkext/blockview.c b/plugins/pychrysa/gtkext/blockview.c index e076e3c..973538b 100644 --- a/plugins/pychrysa/gtkext/blockview.c +++ b/plugins/pychrysa/gtkext/blockview.c @@ -31,66 +31,51 @@ #include <gtkext/gtkblockview.h> -#include "../quirks.h" - - - -/* Crée un nouvel objet Python de type 'ViewPanel'. */ -static PyObject *py_block_view_new(PyTypeObject *, PyObject *, PyObject *); +#include "bufferview.h" /****************************************************************************** * * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * +* Paramètres : - * * * -* Description : Crée un nouvel objet Python de type 'ViewPanel'. * +* Description : Fournit un accès à une définition de type à diffuser. * * * -* Retour : Instance Python mise en place. * +* Retour : Définition d'objet pour Python. * * * * Remarques : - * * * ******************************************************************************/ -static PyObject *py_block_view_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +PyTypeObject *get_python_block_view_type(void) { -#if 0 - PyObject *result; /* Instance à retourner */ - const char *name; /* Désignation humaine */ - const char *lname; /* Nom version longue */ - PyGObject *widget; /* Composant visuel du panneau */ - const char *path; /* Placement à l'affichage */ - int ret; /* Bilan de lecture des args. */ - GEditorItem *item; /* Version GLib du format */ - - ret = PyArg_ParseTuple(args, "ssOs", &name, &lname, &widget, &path); - if (!ret) Py_RETURN_NONE; - - item = g_block_view_new(get_internal_ref(), name, lname, - GTK_WIDGET(pygobject_get(widget)), path); - - result = py_block_view_from_c(G_BLOCK_VIEW(item)); - g_object_unref(item); - - return (PyObject *)result; -#endif - - /* FIXME */ - + static PyMethodDef py_block_view_methods[] = { + { NULL } + }; - Py_RETURN_NONE; + static PyGetSetDef py_block_view_getseters[] = { + { NULL } + }; -} + static PyTypeObject py_block_view_type = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "pychrysalide.gtkext.BlockView", + .tp_basicsize = sizeof(PyGObject), + .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_doc = "PyChrysalide block view.", + .tp_methods = py_block_view_methods, + .tp_getset = py_block_view_getseters + }; + return &py_block_view_type; +} /****************************************************************************** @@ -107,50 +92,26 @@ static PyObject *py_block_view_new(PyTypeObject *type, PyObject *args, PyObject bool register_python_block_view(PyObject *module) { - PyObject *parent_mod; /* Module Python-EditorItem */ + PyTypeObject *py_block_view_type; /* Type Python 'BlockView' */ int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ - static PyMethodDef py_block_view_methods[] = { - { NULL } - }; - - static PyGetSetDef py_block_view_getseters[] = { - { NULL } - }; - - static PyTypeObject py_block_view_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pychrysalide.gtkext.BlockView", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide view panel", - - .tp_methods = py_block_view_methods, - .tp_getset = py_block_view_getseters, - .tp_new = (newfunc)py_block_view_new, - .tp_init = (initproc)pychrysalide_allow_args_for_gobjects - - }; - - parent_mod = PyImport_ImportModule("pychrysalide.gtkext"); - if (parent_mod == NULL) return false; + py_block_view_type = get_python_block_view_type(); - py_block_view_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "ViewPanel"); - Py_DECREF(parent_mod); + py_block_view_type->tp_base = get_python_buffer_view_type(); + py_block_view_type->tp_basicsize = py_block_view_type->tp_base->tp_basicsize; - if (PyType_Ready(&py_block_view_type) < 0) + if (PyType_Ready(py_block_view_type) != 0) return false; - Py_INCREF(&py_block_view_type); - ret = PyModule_AddObject(module, "BlockView", (PyObject *)&py_block_view_type); + Py_INCREF(py_block_view_type); + ret = PyModule_AddObject(module, "BlockView", (PyObject *)py_block_view_type); + if (ret != 0) return false; - pygobject_register_class(module, "GtkBlockView", GTK_TYPE_BLOCK_VIEW, &py_block_view_type, - Py_BuildValue("(O)", py_block_view_type.tp_base)); + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "BlockView", GTK_TYPE_BLOCK_VIEW, py_block_view_type, + Py_BuildValue("(O)", py_block_view_type->tp_base)); - return (ret == 0); + return true; } diff --git a/plugins/pychrysa/gtkext/blockview.h b/plugins/pychrysa/gtkext/blockview.h index a6cf3a0..1735ac3 100644 --- a/plugins/pychrysa/gtkext/blockview.h +++ b/plugins/pychrysa/gtkext/blockview.h @@ -22,8 +22,8 @@ */ -#ifndef _PLUGINS_PYCHRYSA_GTKEXT_MODULE_BLOCK_VIEW_H -#define _PLUGINS_PYCHRYSA_GTKEXT_MODULE_BLOCK_VIEW_H +#ifndef _PLUGINS_PYCHRYSA_GTKEXT_BLOCKVIEW_H +#define _PLUGINS_PYCHRYSA_GTKEXT_BLOCKVIEW_H #include <Python.h> @@ -31,9 +31,12 @@ +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_block_view_type(void); + /* Prend en charge l'objet 'pychrysalide.gtkext.BlockView'. */ bool register_python_block_view(PyObject *module); -#endif /* _PLUGINS_PYCHRYSA_GTKEXT_MODULE_BLOCK_VIEW_H */ +#endif /* _PLUGINS_PYCHRYSA_GTKEXT_BLOCKVIEW_H */ diff --git a/plugins/pychrysa/gtkext/bufferview.c b/plugins/pychrysa/gtkext/bufferview.c new file mode 100644 index 0000000..a8b86e8 --- /dev/null +++ b/plugins/pychrysa/gtkext/bufferview.c @@ -0,0 +1,117 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bufferview.c - prototypes pour l'équivalent Python du fichier "gtkext/gtkbufferview.c" + * + * Copyright (C) 2012 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 "bufferview.h" + + +#include <pygobject.h> + + +#include <gtkext/gtkbufferview.h> + + +#include "viewpanel.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_buffer_view_type(void) +{ + static PyMethodDef py_buffer_view_methods[] = { + { NULL } + }; + + static PyGetSetDef py_buffer_view_getseters[] = { + { NULL } + }; + + static PyTypeObject py_buffer_view_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.gtkext.Bufferview", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide buffer view.", + + .tp_methods = py_buffer_view_methods, + .tp_getset = py_buffer_view_getseters + + }; + + return &py_buffer_view_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gtkext.Bufferview'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_buffer_view(PyObject *module) +{ + PyTypeObject *py_buffer_view_type; /* Type Python 'Bufferview' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_buffer_view_type = get_python_buffer_view_type(); + + py_buffer_view_type->tp_base = get_python_view_panel_type(); + py_buffer_view_type->tp_basicsize = py_buffer_view_type->tp_base->tp_basicsize; + + if (PyType_Ready(py_buffer_view_type) != 0) + return false; + + Py_INCREF(py_buffer_view_type); + ret = PyModule_AddObject(module, "Bufferview", (PyObject *)py_buffer_view_type); + if (ret != 0) return false; + + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "Bufferview", GTK_TYPE_BUFFER_VIEW, py_buffer_view_type, + Py_BuildValue("(O)", py_buffer_view_type->tp_base)); + + return true; + +} diff --git a/plugins/pychrysa/gtkext/bufferview.h b/plugins/pychrysa/gtkext/bufferview.h new file mode 100644 index 0000000..7ef9995 --- /dev/null +++ b/plugins/pychrysa/gtkext/bufferview.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bufferview.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkbufferview.h" + * + * Copyright (C) 2012 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_GTKEXT_BUFFERVIEW_H +#define _PLUGINS_PYCHRYSA_GTKEXT_BUFFERVIEW_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_buffer_view_type(void); + +/* Prend en charge l'objet 'pychrysalide.gtkext.Bufferview'. */ +bool register_python_buffer_view(PyObject *module); + + + +#endif /* _PLUGINS_PYCHRYSA_GTKEXT_BUFFERVIEW_H */ diff --git a/plugins/pychrysa/gtkext/module.c b/plugins/pychrysa/gtkext/module.c index ef006e2..507b3cb 100644 --- a/plugins/pychrysa/gtkext/module.c +++ b/plugins/pychrysa/gtkext/module.c @@ -25,7 +25,11 @@ #include "module.h" +#include <assert.h> + + #include "blockview.h" +#include "bufferview.h" #include "viewpanel.h" @@ -44,25 +48,46 @@ bool add_gtkext_module_to_python_module(PyObject *super) { - bool result; - PyObject *module; + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ int ret; /* Bilan d'un appel */ - static PyMethodDef py_gtkext_methods[] = { - { NULL } + static PyModuleDef py_chrysalide_gtkext_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.gtkext", + .m_doc = "Python module for Chrysalide.gtkext", + + .m_size = -1, + }; - module = Py_InitModule("pychrysalide.gtkext", py_gtkext_methods); + result = false; + + module = PyModule_Create(&py_chrysalide_gtkext_module); if (module == NULL) return false; + ret = PyState_AddModule(super, &py_chrysalide_gtkext_module); + if (ret != 0) goto agmtpm_exit; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.gtkext"); + if (ret != 0) goto agmtpm_exit; + Py_INCREF(module); - ret = PyModule_AddObject(super, "pychrysalide.gtkext", module); + ret = PyModule_AddObject(super, "gtkext", module); + if (ret != 0) goto agmtpm_exit; - result = (ret == 0); + result = true; result &= register_python_view_panel(module); + result &= register_python_buffer_view(module); result &= register_python_block_view(module); + agmtpm_exit: + + assert(result); + return result; } diff --git a/plugins/pychrysa/gtkext/viewpanel.c b/plugins/pychrysa/gtkext/viewpanel.c index f680487..8c85fbd 100644 --- a/plugins/pychrysa/gtkext/viewpanel.c +++ b/plugins/pychrysa/gtkext/viewpanel.c @@ -31,16 +31,22 @@ #include <gtkext/gtkviewpanel.h> -#include "../quirks.h" +#include "../helpers.h" +#include "../arch/vmpa.h" /* Crée un nouvel objet Python de type 'ViewPanel'. */ +#if 0 static PyObject *py_view_panel_new(PyTypeObject *, PyObject *, PyObject *); +#endif /* S'assure qu'une adresse donnée est visible à l'écran. */ static PyObject *py_view_panel_scroll_to_address(PyObject *, PyObject *); +/* Définit les constantes pour les panneaux de vue. */ +static bool py_view_panel_define_constants(PyTypeObject *); + /****************************************************************************** @@ -56,7 +62,7 @@ static PyObject *py_view_panel_scroll_to_address(PyObject *, PyObject *); * Remarques : - * * * ******************************************************************************/ - +#if 0 static PyObject *py_view_panel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { #if 0 @@ -86,10 +92,7 @@ static PyObject *py_view_panel_new(PyTypeObject *type, PyObject *args, PyObject Py_RETURN_NONE; } - - - - +#endif /****************************************************************************** @@ -108,47 +111,75 @@ static PyObject *py_view_panel_new(PyTypeObject *type, PyObject *args, PyObject static PyObject *py_view_panel_scroll_to_address(PyObject *self, PyObject *args) { GtkViewPanel *panel; /* Panneau à manipuler */ - vmpa_t addr; /* Adresse demandée en visuel */ + PyObject *py_vmpa; /* Localisation version Python */ int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Adresse visée par l'opérat° */ - panel = GTK_VIEW_PANEL(pygobject_get(self)); + ret = PyArg_ParseTuple(args, "O", &py_vmpa); + if (!ret) return NULL; - ret = PyArg_ParseTuple(args, "K", &addr); - 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 (addr == NULL) return NULL; + + panel = GTK_VIEW_PANEL(pygobject_get(self)); - //gtk_view_panel_scroll_to_address(panel, addr); + gtk_view_panel_scroll_to_address(panel, addr, SPT_RAW); Py_RETURN_NONE; } +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les panneaux de vue. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_view_panel_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + result = true; + result &= PyDict_AddIntMacro(obj_type, SPT_RAW); + result &= PyDict_AddIntMacro(obj_type, SPT_TOP); + result &= PyDict_AddIntMacro(obj_type, SPT_CENTER); + result &= PyDict_AddIntMacro(obj_type, SPT_BOTTOM); + + return result; + +} /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * -* Description : Prend en charge l'objet 'pychrysalide.gtkext.ViewPanel'. * +* Description : Fournit un accès à une définition de type à diffuser. * * * -* Retour : Bilan de l'opération. * +* Retour : Définition d'objet pour Python. * * * * Remarques : - * * * ******************************************************************************/ -bool register_python_view_panel(PyObject *module) +PyTypeObject *get_python_view_panel_type(void) { - PyObject *parent_mod; /* Module Python-EditorItem */ - int ret; /* Bilan d'un appel */ - static PyMethodDef py_view_panel_methods[] = { { "scroll_to_address", (PyCFunction)py_view_panel_scroll_to_address, METH_VARARGS, - "Ensure a given address is displayed in the view panel." + "scroll_to_address($self, addr, tweak, /)\n--\n\nEnsure a given address is displayed in the view panel." }, { NULL } }; @@ -159,37 +190,70 @@ bool register_python_view_panel(PyObject *module) static PyTypeObject py_view_panel_type = { - PyObject_HEAD_INIT(NULL) + PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.gtkext.ViewPanel", .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_doc = "PyChrysalide view panel", + .tp_doc = "PyChrysalide view panel.", .tp_methods = py_view_panel_methods, .tp_getset = py_view_panel_getseters, - .tp_new = (newfunc)py_view_panel_new, - .tp_init = (initproc)pychrysalide_allow_args_for_gobjects + //.tp_new = (newfunc)py_view_panel_new, + //.tp_init = (initproc)pychrysalide_allow_args_for_gobjects }; - parent_mod = PyImport_ImportModule("gtk"); + return &py_view_panel_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gtkext.ViewPanel'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_view_panel(PyObject *module) +{ + PyTypeObject *py_view_panel_type; /* Type Python 'ViewPanel' */ + PyObject *parent_mod; /* Module Python Fixed */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_view_panel_type = get_python_view_panel_type(); + + parent_mod = PyImport_ImportModule("gi.repository.Gtk"); if (parent_mod == NULL) return false; - py_view_panel_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "Fixed"); + py_view_panel_type->tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "Fixed"); Py_DECREF(parent_mod); - if (PyType_Ready(&py_view_panel_type) < 0) + py_view_panel_type->tp_basicsize = py_view_panel_type->tp_base->tp_basicsize; + + if (PyType_Ready(py_view_panel_type) != 0) + return false; + + if (!py_view_panel_define_constants(py_view_panel_type)) return false; - Py_INCREF(&py_view_panel_type); - ret = PyModule_AddObject(module, "ViewPanel", (PyObject *)&py_view_panel_type); + Py_INCREF(py_view_panel_type); + ret = PyModule_AddObject(module, "ViewPanel", (PyObject *)py_view_panel_type); + if (ret != 0) return false; - pygobject_register_class(module, "GtkViewPanel", GTK_TYPE_VIEW_PANEL, &py_view_panel_type, - Py_BuildValue("(O)", py_view_panel_type.tp_base)); + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "ViewPanel", GTK_TYPE_VIEW_PANEL, py_view_panel_type, + Py_BuildValue("(O)", py_view_panel_type->tp_base)); - return (ret == 0); + return true; } diff --git a/plugins/pychrysa/gtkext/viewpanel.h b/plugins/pychrysa/gtkext/viewpanel.h index 175546b..7a349f8 100644 --- a/plugins/pychrysa/gtkext/viewpanel.h +++ b/plugins/pychrysa/gtkext/viewpanel.h @@ -22,8 +22,8 @@ */ -#ifndef _PLUGINS_PYCHRYSA_GTKEXT_MODULE_VIEW_PANEL_H -#define _PLUGINS_PYCHRYSA_GTKEXT_MODULE_VIEW_PANEL_H +#ifndef _PLUGINS_PYCHRYSA_GTKEXT_VIEWPANEL_H +#define _PLUGINS_PYCHRYSA_GTKEXT_VIEWPANEL_H #include <Python.h> @@ -31,9 +31,12 @@ +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_view_panel_type(void); + /* Prend en charge l'objet 'pychrysalide.gtkext.ViewPanel'. */ bool register_python_view_panel(PyObject *module); -#endif /* _PLUGINS_PYCHRYSA_GTKEXT_MODULE_VIEW_PANEL_H */ +#endif /* _PLUGINS_PYCHRYSA_GTKEXT_VIEWPANEL_H */ |