/* OpenIDA - Outil d'analyse de fichiers binaires * processor.h - prototypes pour l'équivalent Python du fichier "arch/processor.h" * * Copyright (C) 2010 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 "processor.h" #include "../../../src/arch/processor.h" /* ------------------------- TYPAGE DES ENUMERATIONS PYTHON ------------------------- */ /* Définit les constantes pour les types de processeur. */ bool py_arch_processor_type_define_constants(PyObject *); /* Ajoute l'objet 'arch.processor.ArchProcessorType' au module. */ bool add_arch_processor_type_to_python_module(PyObject *); /* ------------------------- PARTIE STATIQUE DE PROCESSEURS ------------------------- */ /* Classe 'analysis.roptions' pour Python */ typedef struct _py_processor { PyObject_HEAD } py_processor; /* ---------------------------------------------------------------------------------- */ /* TYPAGE DES ENUMERATIONS PYTHON */ /* ---------------------------------------------------------------------------------- */ /****************************************************************************** * * * Paramètres : dict = dictionnaire à compléter. * * * * Description : Définit les constantes pour les types de processeur. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ bool py_arch_processor_type_define_constants(PyObject *dict) { int ret; /* Bilan d'un ajout */ ret = PyDict_SetItemString(dict, "APT_JVM", PyInt_FromLong(APT_JVM)); if (ret == -1) return false; ret = PyDict_SetItemString(dict, "APT_MIPS", PyInt_FromLong(APT_MIPS)); if (ret == -1) return false; ret = PyDict_SetItemString(dict, "APT_386", PyInt_FromLong(APT_386)); if (ret == -1) return false; ret = PyDict_SetItemString(dict, "APT_COUNT", PyInt_FromLong(APT_COUNT)); if (ret == -1) return false; return true; } PyObject *__test; /****************************************************************************** * * * Paramètres : module = module dont la définition est à compléter. * * * * Description : Ajoute l'objet 'arch.processor.ArchProcessorType' au module. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ bool add_arch_processor_type_to_python_module(PyObject *module) { int ret; /* Bilan d'un appel */ static PyTypeObject py_arch_processor_type_type = { PyObject_HEAD_INIT(NULL) .tp_name = "pyoida.arch.processor.ArchProcessorType", .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_doc = "PyOIDA version of the ArchProcessorType enumeration", }; if (PyType_Ready(&py_arch_processor_type_type) < 0) return false; py_arch_processor_type_define_constants(py_arch_processor_type_type.tp_dict); Py_INCREF(&py_arch_processor_type_type); ret = PyModule_AddObject(module, "ArchProcessorType", (PyObject *)&py_arch_processor_type_type); __test = &py_arch_processor_type_type; return (ret == 0); } /* ---------------------------------------------------------------------------------- */ /* PARTIE STATIQUE DE PROCESSEURS */ /* ---------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------- */ /* PARTIE GRAPHIQUE DES [DE]CHARGEMENTS */ /* ---------------------------------------------------------------------------------- */ /* Crée un nouvel objet Python de type 'py_processor'. */ static PyObject *py_processor_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 'py_processor'. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static PyObject *py_processor_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { py_processor *result; /* Instance à retourner */ result = (py_processor *)type->tp_alloc(type, 0); return (PyObject *)result; } /****************************************************************************** * * * Paramètres : module = module dont la définition est à compléter. * * * * Description : Ajoute l'objet 'analysis.roptions' au module Python. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ bool add_arch_processor_to_python_module(PyObject *module) { bool result; /* Bilan à retourner */ int ret; /* Bilan d'un appel */ static PyMethodDef py_processor_methods[] = { { NULL } }; static PyGetSetDef py_processor_getset[] = { { NULL } }; static PyTypeObject py_processor_type = { PyObject_HEAD_INIT(NULL) .tp_name = "pyoida.arch.Processor", .tp_basicsize = sizeof(py_processor), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_doc = "PyOIDA processor for a given architecture", .tp_methods = py_processor_methods, .tp_getset = py_processor_getset, .tp_new = (newfunc)py_processor_new }; if (PyType_Ready(&py_processor_type) < 0) return false; //printf("ret import = %p\n", PyImport_ImportModule("pyoida.arch.processor.ArchProcessorType")); Py_INCREF(&py_processor_type); ret = PyModule_AddObject(module, "Processor", (PyObject *)&py_processor_type); result = add_arch_processor_type_to_python_module(module); return (ret == 0); }