/* Chrysalide - Outil d'analyse de fichiers binaires * editem.c - prototypes pour l'équivalent Python du fichier "gui/editem.c" * * Copyright (C) 2012-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 "editem.h" #include #include #include "../access.h" #include "../helpers.h" #include "../analysis/binary.h" #include "../gtkext/displaypanel.h" /* Réagit à un changement du binaire courant. */ static void _change_editor_item_content_python_wrapper(GEditorItem *, GLoadedContent *, GLoadedContent *); /* Réagit à un changement de vue. */ static void _change_editor_item_view_python_wrapper(GEditorItem *, GLoadedPanel *, GLoadedPanel *); /* Réagit à un changement de contenu. */ static void _update_editor_item_view_python_wrapper(GEditorItem *, GLoadedPanel *); /* Réagit à un changement de contenu chargé en cours d'analyse. */ static PyObject *py_editor_item_change_content(PyObject *, PyObject *); /* Réagit à un changement de vue du contenu en cours d'analyse. */ static PyObject *py_editor_item_change_view(PyObject *, PyObject *); /* Réagit à une modification de la vue du contenu analysé. */ static PyObject *py_editor_item_update_view(PyObject *, PyObject *); /* Procède à l'enregistrement d'un élément reactif de l'éditeur. */ static PyObject *py_editor_item_register(PyObject *, PyObject *); /****************************************************************************** * * * Paramètres : item = élément à actualiser. * * old = ancien contenu chargé analysé. * * new = nouveau contenu chargé à analyser. * * * * Description : Réagit à un changement du binaire courant. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void _change_editor_item_content_python_wrapper(GEditorItem *item, GLoadedContent *old, GLoadedContent *new) { PyObject *target; /* Version Python de l'élément */ PyObject *args; /* Arguments pour l'appel */ PyObject *value; /* Retour obtenu */ /** * Normalement, l'objet Python est enregistré dans la liste de Chrysalide * des éléments d'éditeur, via py_editor_item_register(), donc son compteur * de références doit le maintenir en vie. * * On peut donc le récupérer directement depuis l'instance GLib, sans passer * par la procédure de pygobject, qui obligerait à connaître le type précis * de l'instance GLib manipulée. */ target = pygobject_new(G_OBJECT(item)); args = PyTuple_New(2); PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(old))); PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(new))); value = run_python_method(target, "change_content", args); Py_XDECREF(value); Py_DECREF(args); Py_DECREF(target); } /****************************************************************************** * * * Paramètres : item = élément à actualiser. * * old = ancienne vue du contenu chargé analysé. * * new = nouvelle vue du contenu chargé analysé. * * * * Description : Réagit à un changement de vue. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void _change_editor_item_view_python_wrapper(GEditorItem *item, GLoadedPanel *old, GLoadedPanel *new) { PyObject *target; /* Version Python de l'élément */ PyObject *args; /* Arguments pour l'appel */ PyObject *value; /* Retour obtenu */ /** * Normalement, l'objet Python est enregistré dans la liste de Chrysalide * des éléments d'éditeur, via py_editor_item_register(), donc son compteur * de références doit le maintenir en vie. * * On peut donc le récupérer directement depuis l'instane GLib, sans passer * par la procédure de pygobject, qui obligerait à connaître le type précis * de l'instance GLib manipulée. */ target = pygobject_new(G_OBJECT(item)); args = PyTuple_New(2); PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(old))); PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(new))); value = run_python_method(target, "change_view", args); Py_XDECREF(value); Py_DECREF(args); Py_DECREF(target); } /****************************************************************************** * * * Paramètres : item = élément à actualiser. * * panel = vue du contenu chargé analysé modifiée. * * * * Description : Réagit à un changement de contenu. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void _update_editor_item_view_python_wrapper(GEditorItem *item, GLoadedPanel *panel) { PyObject *target; /* Version Python de l'élément */ PyObject *args; /* Arguments pour l'appel */ PyObject *value; /* Retour obtenu */ /** * Normalement, l'objet Python est enregistré dans la liste de Chrysalide * des éléments d'éditeur, via py_editor_item_register(), donc son compteur * de références doit le maintenir en vie. * * On peut donc le récupérer directement depuis l'instane GLib, sans passer * par la procédure de pygobject, qui obligerait à connaître le type précis * de l'instance GLib manipulée. */ target = pygobject_new(G_OBJECT(item)); args = PyTuple_New(1); PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(panel))); value = run_python_method(target, "update_view", args); Py_XDECREF(value); Py_DECREF(args); Py_DECREF(target); } /****************************************************************************** * * * Paramètres : self = classe représentant un binaire. * * args = arguments fournis à l'appel. * * * * Description : Réagit à un changement de contenu chargé en cours d'analyse. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_editor_item_change_content(PyObject *self, PyObject *args) { Py_RETURN_NONE; } /****************************************************************************** * * * Paramètres : self = classe représentant un binaire. * * args = arguments fournis à l'appel. * * * * Description : Réagit à un changement de vue du contenu en cours d'analyse. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_editor_item_change_view(PyObject *self, PyObject *args) { Py_RETURN_NONE; } /****************************************************************************** * * * Paramètres : self = classe représentant un binaire. * * args = arguments fournis à l'appel. * * * * Description : Réagit à une modification de la vue du contenu analysé. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_editor_item_update_view(PyObject *self, PyObject *args) { Py_RETURN_NONE; } /****************************************************************************** * * * Paramètres : self = classe représentant un binaire. * * args = arguments fournis à l'appel. * * * * Description : Procède à l'enregistrement d'un élément reactif de l'éditeur.* * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_editor_item_register(PyObject *self, PyObject *args) { //GEditorItem *item; /* Version GLib de l'élément */ //item = G_EDITOR_ITEM(pygobject_get(self)); //item->update_binary = _change_editor_item_content_python_wrapper; //item->update_view = _change_editor_item_view_python_wrapper; //item->update_content = _update_editor_item_view_python_wrapper; Py_INCREF(self); //register_editor_item(item); Py_RETURN_NONE; } /****************************************************************************** * * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * * * * Retour : Définition d'objet pour Python. * * * * Remarques : - * * * ******************************************************************************/ PyTypeObject *get_python_editor_item_type(void) { static PyMethodDef py_editor_item_methods[] = { { "change_content", py_editor_item_change_content, METH_VARARGS, "change_content($self, /)\n--\n\nCalled by Chrysalide on each content change, if the item is registered." }, { "change_view", py_editor_item_change_view, METH_VARARGS, "change_view($self, /)\n--\n\nCalled by Chrysalide on each view change, if the item is registered." }, { "update_view", py_editor_item_update_view, METH_VARARGS, "update_view($self, /)\n--\n\nCalled by Chrysalide on each view content change, if the item is registered." }, { "register", py_editor_item_register, METH_NOARGS, "register($self, /)\n--\n\nregister($self, /)\n--\n\nRegister the item as editor item." }, { NULL } }; static PyGetSetDef py_editor_item_getseters[] = { { NULL } }; static PyTypeObject py_editor_item_type = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.gui.EditorItem", .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_doc = "PyChrysalide editor item", .tp_methods = py_editor_item_methods, .tp_getset = py_editor_item_getseters, }; return &py_editor_item_type; } /****************************************************************************** * * * Paramètres : module = module dont la définition est à compléter. * * * * Description : Prend en charge l'objet 'pychrysalide.gui.EditorItem'. * * * * Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ bool ensure_python_editor_item_is_registered(void) { PyTypeObject *type; /* Type Python 'EditorItem' */ PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ type = get_python_editor_item_type(); if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) { module = get_access_to_python_module("pychrysalide.gui"); dict = PyModule_GetDict(module); if (!register_class_for_pygobject(dict, G_TYPE_EDITOR_ITEM, type, &PyGObject_Type)) return false; } return true; }