summaryrefslogtreecommitdiff
path: root/plugins/pyoida/arch
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pyoida/arch')
-rw-r--r--plugins/pyoida/arch/Makefile.am17
-rw-r--r--plugins/pyoida/arch/archbase.c121
-rw-r--r--plugins/pyoida/arch/archbase.h44
-rw-r--r--plugins/pyoida/arch/module.c72
-rw-r--r--plugins/pyoida/arch/module.h39
-rw-r--r--plugins/pyoida/arch/processor.c314
-rw-r--r--plugins/pyoida/arch/processor.h39
7 files changed, 646 insertions, 0 deletions
diff --git a/plugins/pyoida/arch/Makefile.am b/plugins/pyoida/arch/Makefile.am
new file mode 100644
index 0000000..d0113ec
--- /dev/null
+++ b/plugins/pyoida/arch/Makefile.am
@@ -0,0 +1,17 @@
+
+noinst_LTLIBRARIES = libpyoidaarch.la
+
+libpyoidaarch_la_SOURCES = \
+ archbase.h archbase.c \
+ module.h module.c \
+ processor.h processor.c
+
+
+libpyoidaarch_la_LDFLAGS =
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) -I../../../src
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/plugins/pyoida/arch/archbase.c b/plugins/pyoida/arch/archbase.c
new file mode 100644
index 0000000..b73e769
--- /dev/null
+++ b/plugins/pyoida/arch/archbase.c
@@ -0,0 +1,121 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * archbase.c - équivalent Python du fichier "arch/archbase.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 "archbase.h"
+
+
+
+
+
+/* Classe 'arch.vmpa' pour Python */
+typedef PyLongObject py_vmpa;
+
+
+
+/* Fournit le type d'objet 'arch.vmpa' pour Python. */
+static PyTypeObject *get_arch_vmpa_type(void);
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : value = adresse à convertir en objet Python. *
+* *
+* Description : Crée un nouvel objet Python de type 'py_vmpa'. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *py_vmpa_new_from_existing(vmpa_t value)
+{
+ return PyLong_FromLongLong(value);
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit le type d'objet 'arch.vmpa' pour Python. *
+* *
+* Retour : Adresse du type vivant à manipuler. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyTypeObject *get_arch_vmpa_type(void)
+{
+ return &PyLong_Type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'arch.vmpa' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_arch_vmpa_to_python_module(PyObject *module)
+{
+ PyTypeObject *py_vmpa_type; /* Type défini pour Python */
+ int ret; /* Bilan d'un appel */
+
+ py_vmpa_type = get_arch_vmpa_type();
+
+ if (PyType_Ready(py_vmpa_type) < 0)
+ return false;
+
+ Py_INCREF(py_vmpa_type);
+ ret = PyModule_AddObject(module, "Vmpa", (PyObject *)py_vmpa_type);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pyoida/arch/archbase.h b/plugins/pyoida/arch/archbase.h
new file mode 100644
index 0000000..ca621aa
--- /dev/null
+++ b/plugins/pyoida/arch/archbase.h
@@ -0,0 +1,44 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * archbase.h - prototypes pour l'équivalent Python du fichier "arch/archbase.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
+ */
+
+
+#ifndef _PLUGINS_PYOIDA_ARCH_ARCHBASE_H
+#define _PLUGINS_PYOIDA_ARCH_ARCHBASE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+#include <arch/archbase.h>
+
+
+
+/* Crée un nouvel objet Python de type 'py_vmpa'. */
+PyObject *py_vmpa_new_from_existing(vmpa_t);
+
+/* Ajoute l'objet 'arch.vmpa' au module Python. */
+bool add_arch_vmpa_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ARCH_ARCHBASE_H */
diff --git a/plugins/pyoida/arch/module.c b/plugins/pyoida/arch/module.c
new file mode 100644
index 0000000..59b0c2c
--- /dev/null
+++ b/plugins/pyoida/arch/module.c
@@ -0,0 +1,72 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire arch en tant que module
+ *
+ * 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 "module.h"
+
+
+#include "archbase.h"
+#include "processor.h"
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute le module 'arch' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_arch_module_to_python_module(PyObject *super)
+{
+ bool result;
+ PyObject *module;
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_arch_methods[] = {
+ { NULL }
+ };
+
+ module = Py_InitModule("pyoida.arch", py_arch_methods);
+ if (module == NULL) return false;
+
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "pyoida.arch", module);
+
+ if (ret != 0) /* ... */;
+
+ result = add_arch_vmpa_to_python_module(module);
+ result = add_arch_processor_to_python_module(module);
+
+
+ return true;
+
+}
diff --git a/plugins/pyoida/arch/module.h b/plugins/pyoida/arch/module.h
new file mode 100644
index 0000000..4ae3447
--- /dev/null
+++ b/plugins/pyoida/arch/module.h
@@ -0,0 +1,39 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire arch en tant que module
+ *
+ * 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
+ */
+
+
+#ifndef _PLUGINS_PYOIDA_ARCH_MODULE_H
+#define _PLUGINS_PYOIDA_ARCH_MODULE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute le module 'arch' au module Python. */
+bool add_arch_module_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ARCH_MODULE_H */
diff --git a/plugins/pyoida/arch/processor.c b/plugins/pyoida/arch/processor.c
new file mode 100644
index 0000000..0a3fe95
--- /dev/null
+++ b/plugins/pyoida/arch/processor.c
@@ -0,0 +1,314 @@
+
+/* 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;
+
+}
+
+
+
+
+
+
+
+
+
+
+static PyObject *util_FromImport(const char *name, const char *from_item)
+{
+ PyObject *from_list;
+ PyObject *module;
+ PyObject *item;
+
+ /* Make the from list. */
+ from_list = PyList_New(1);
+ PyList_SetItem(from_list, 0, PyString_FromString(from_item));
+
+ /* Attempt the import, with const correctness removed. */
+ module = PyImport_ImportModuleEx((char *)name, NULL, NULL, from_list);
+ Py_DECREF(from_list);
+ if (!module)
+ {
+ return NULL;
+ }
+
+ /* Get the from_item from the module. */
+ item = PyObject_GetAttrString(module, (char *)from_item);
+ Py_DECREF(module);
+
+ return item;
+}
+
+
+
+
+
+
+/******************************************************************************
+* *
+* 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);
+
+}
diff --git a/plugins/pyoida/arch/processor.h b/plugins/pyoida/arch/processor.h
new file mode 100644
index 0000000..032d82d
--- /dev/null
+++ b/plugins/pyoida/arch/processor.h
@@ -0,0 +1,39 @@
+
+/* 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
+ */
+
+
+#ifndef _PLUGINS_PYOIDA_ARCH_PROCESSOR_H
+#define _PLUGINS_PYOIDA_ARCH_PROCESSOR_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute l'objet 'arch.processor' au module Python. */
+bool add_arch_processor_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ARCH_PROCESSOR_H */