/* OpenIDA - Outil d'analyse de fichiers binaires * codebuffer.c - équivalent Python du fichier "glibext/gcodebuffer.h" * * Copyright (C) 2012 Cyrille Bagard * * This file is part of OpenIDA. * * 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 "codebuffer.h" #include #include #include "../quirks.h" /* Retrouve une ligne au sein d'un tampon avec une adresse. */ static PyObject *py_code_buffer_find_line_by_addr(PyObject *, PyObject *); /****************************************************************************** * * * Paramètres : self = classe représentant un tampon de code. * * args = arguments fournis à l'appel. * * * * Description : Retrouve une ligne au sein d'un tampon avec une adresse. * * * * Retour : Instance de la ligne trouvée. * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_code_buffer_find_line_by_addr(PyObject *self, PyObject *args) { PyObject *result; /* Trouvailles à retourner */ GCodeBuffer *buffer; /* Version native */ vmpa_t addr; /* Adresse visée par l'opérat° */ int ret; /* Bilan de lecture des args. */ GBufferLine *line; /* Ligne trouvée */ buffer = G_CODE_BUFFER(pygobject_get(self)); ret = PyArg_ParseTuple(args, "K", &addr); if (!ret) Py_RETURN_NONE; line = g_code_buffer_find_line_by_addr(buffer, addr); if (line == NULL) Py_RETURN_NONE; result = pygobject_new(G_OBJECT(line)); return result; } /****************************************************************************** * * * Paramètres : module = module dont la définition est à compléter. * * * * Description : Prend en charge l'objet 'pychrysalide.glibext.Codebuffer'. * * * * Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ bool register_python_code_buffer(PyObject *module) { PyObject *pygobj_mod; /* Module Python-GObject */ int ret; /* Bilan d'un appel */ static PyMethodDef py_code_buffer_methods[] = { { "find_line_by_addr", (PyCFunction)py_code_buffer_find_line_by_addr, METH_VARARGS, "Find a buffer line with a given address." }, { NULL } }; static PyTypeObject py_code_buffer_type = { PyObject_HEAD_INIT(NULL) .tp_name = "pychrysalide.glibext.CodeBuffer", .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_doc = "PyChrysalide code buffer", .tp_methods = py_code_buffer_methods }; pygobj_mod = PyImport_ImportModule("gobject"); if (pygobj_mod == NULL) return false; py_code_buffer_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject"); Py_DECREF(pygobj_mod); if (PyType_Ready(&py_code_buffer_type) < 0) return false; Py_INCREF(&py_code_buffer_type); ret = PyModule_AddObject(module, "CodeBuffer", (PyObject *)&py_code_buffer_type); pygobject_register_class(module, "GCodeBuffer", G_TYPE_CODE_BUFFER, &py_code_buffer_type, Py_BuildValue("(O)", py_code_buffer_type.tp_base)); return (ret == 0); }