summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-06-25 06:46:04 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-06-25 06:46:04 (GMT)
commit3bf12eda58a8d04ac3d2d6754a480de4c262570d (patch)
tree010fc97ad481adc00ac4722d77093f469096638b /plugins/pychrysa/arch
parent11395d684736467fb010b93b0eaeefcc06bf0f5e (diff)
Built the first steps to upgrade to Python3.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@379 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/arch')
-rw-r--r--plugins/pychrysa/arch/Makefile.am10
-rw-r--r--plugins/pychrysa/arch/archbase.h20
-rw-r--r--plugins/pychrysa/arch/instruction.c2
-rw-r--r--plugins/pychrysa/arch/module.c47
-rw-r--r--plugins/pychrysa/arch/module.h6
-rw-r--r--plugins/pychrysa/arch/vmpa.c325
-rw-r--r--plugins/pychrysa/arch/vmpa.h42
7 files changed, 426 insertions, 26 deletions
diff --git a/plugins/pychrysa/arch/Makefile.am b/plugins/pychrysa/arch/Makefile.am
index a01d570..54b9261 100644
--- a/plugins/pychrysa/arch/Makefile.am
+++ b/plugins/pychrysa/arch/Makefile.am
@@ -2,10 +2,14 @@
noinst_LTLIBRARIES = libpychrysaarch.la
libpychrysaarch_la_SOURCES = \
- archbase.h archbase.c \
- instruction.h instruction.c \
module.h module.c \
- processor.h processor.c
+ vmpa.h vmpa.c
+
+# libpychrysaarch_la_SOURCES = \
+# archbase.h archbase.c \
+# instruction.h instruction.c \
+# module.h module.c \
+# processor.h processor.c
libpychrysaarch_la_LDFLAGS =
diff --git a/plugins/pychrysa/arch/archbase.h b/plugins/pychrysa/arch/archbase.h
index 8721371..b5d9811 100644
--- a/plugins/pychrysa/arch/archbase.h
+++ b/plugins/pychrysa/arch/archbase.h
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * archbase.h - prototypes pour l'équivalent Python du fichier "arch/archbase.h"
+ * vmpa.h - prototypes pour l'équivalent Python du fichier "arch/vmpa.h"
*
- * Copyright (C) 2010-2012 Cyrille Bagard
+ * Copyright (C) 2014 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -22,11 +22,19 @@
*/
-#ifndef _PLUGINS_PYOIDA_ARCH_ARCHBASE_H
-#define _PLUGINS_PYOIDA_ARCH_ARCHBASE_H
+#ifndef _PLUGINS_PYCHRYSA_ARCH_VMPA_H
+#define _PLUGINS_PYCHRYSA_ARCH_VMPA_H
+
#include <Python.h>
+
+
+
+
+
+
+#if 0
#include <stdbool.h>
#include <arch/archbase.h>
@@ -38,7 +46,9 @@ 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
+
-#endif /* _PLUGINS_PYOIDA_ARCH_ARCHBASE_H */
+#endif /* _PLUGINS_PYCHRYSA_ARCH_VMPA_H */
diff --git a/plugins/pychrysa/arch/instruction.c b/plugins/pychrysa/arch/instruction.c
index 685d82f..efbdaa5 100644
--- a/plugins/pychrysa/arch/instruction.c
+++ b/plugins/pychrysa/arch/instruction.c
@@ -223,7 +223,7 @@ bool register_python_arch_instruction_iterator(PyObject *module)
.tp_dealloc = (destructor)py_arch_instruction_iterator_dealloc,
- .tp_flags = Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_CLASS,
+ //.tp_flags = Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_CLASS,
.tp_doc = "PyChrysalide architecture instruction iterator",
diff --git a/plugins/pychrysa/arch/module.c b/plugins/pychrysa/arch/module.c
index 7e8fcb3..92172e0 100644
--- a/plugins/pychrysa/arch/module.c
+++ b/plugins/pychrysa/arch/module.c
@@ -25,9 +25,7 @@
#include "module.h"
-#include "instruction.h"
-
-
+#include "vmpa.h"
@@ -45,28 +43,49 @@
bool add_arch_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_arch_methods[] = {
- { NULL }
+ static PyModuleDef py_chrysalide_arch_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.arch",
+ .m_doc = "Python module for Chrysalide.arch",
+
+ .m_size = -1,
+
};
- module = Py_InitModule("pychrysalide.arch", py_arch_methods);
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_arch_module);
if (module == NULL) return false;
+ ret = PyState_AddModule(super, &py_chrysalide_arch_module);
+ if (ret != 0) goto aamtpm_exit;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.arch");
+ if (ret != 0) goto aamtpm_exit;
Py_INCREF(module);
- ret = PyModule_AddObject(super, "pychrysalide.arch", module);
+ ret = PyModule_AddObject(super, "arch", module);
+ if (ret != 0) goto aamtpm_exit;
+
+ result = true;
+
+ result &= register_python_vmpa(module);
- result = (ret == 0);
+ aamtpm_exit:
- if (ret != 0) /* ... */;
+ if (!result)
+ {
+ printf("something went wrong in %s...\n", __FUNCTION__);
+ /* ... */
- result &= register_python_arch_instruction(module);
- result &= register_python_arch_instruction_iterator(module);
+ }
- return true;
+ return result;
}
diff --git a/plugins/pychrysa/arch/module.h b/plugins/pychrysa/arch/module.h
index 8017f76..403ec8a 100644
--- a/plugins/pychrysa/arch/module.h
+++ b/plugins/pychrysa/arch/module.h
@@ -22,8 +22,8 @@
*/
-#ifndef _PLUGINS_PYOIDA_ARCH_MODULE_H
-#define _PLUGINS_PYOIDA_ARCH_MODULE_H
+#ifndef _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_H
+#define _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_H
#include <Python.h>
@@ -36,4 +36,4 @@ bool add_arch_module_to_python_module(PyObject *);
-#endif /* _PLUGINS_PYOIDA_ARCH_MODULE_H */
+#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_H */
diff --git a/plugins/pychrysa/arch/vmpa.c b/plugins/pychrysa/arch/vmpa.c
new file mode 100644
index 0000000..b429699
--- /dev/null
+++ b/plugins/pychrysa/arch/vmpa.c
@@ -0,0 +1,325 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * vmpa.c - équivalent Python du fichier "arch/vmpa.c"
+ *
+ * Copyright (C) 2014 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 "vmpa.h"
+
+
+#include <src/arch/vmpa.h>
+
+
+
+
+
+
+
+typedef struct _py_vmpa_t
+{
+ PyObject_HEAD
+
+ vmpa2_t addr;
+
+} py_vmpa_t;
+
+
+
+
+/* Fournit une représentation d'une variable 'vmpa_t'. */
+static PyObject *py_vmpa_to_str(PyObject *);
+
+
+
+
+/* Effectue une conversion d'un objet Python en type 'vmpa_t'. */
+static bool convert_pyobj_to_vmpa(PyObject *, vmpa2_t *);
+
+/* Effectue une opération de type 'add' avec le type 'vmpa'. */
+static PyObject *py_vmpa_nb_add(PyObject *, PyObject *);
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : obj = objet Python à traiter. *
+* *
+* Description : Fournit une représentation d'une variable 'vmpa_t'. *
+* *
+* Retour : Chaîne de caractère pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_vmpa_to_str(PyObject *obj)
+{
+ vmpa2_t *addr;
+
+ addr = &((py_vmpa_t *)obj)->addr;
+
+ return PyUnicode_FromFormat("<phy=%d, virt=0x%08x>", addr->physical, addr->virtual);
+
+}
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : obj = objet Python à tenter de convertir. *
+* addr = structure équivalente pour Chrysalide. *
+* *
+* Description : Effectue une conversion d'un objet Python en type 'vmpa_t'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool convert_pyobj_to_vmpa(PyObject *obj, vmpa2_t *addr)
+{
+ bool result; /* Résulats à retourner */
+ PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */
+ int ret; /* Bilan d'un appel */
+ PY_LONG_LONG value; /* Valeur de type générique */
+ int overflow; /* Détection d'une grosse val. */
+
+ result = false;
+
+ py_vmpa_type = get_python_vmpa_type();
+
+ ret = PyObject_IsInstance(obj, (PyObject *)py_vmpa_type);
+
+ /* S'il n'y a rien à faire... */
+ if (ret == 1)
+ {
+ *addr = ((py_vmpa_t *)obj)->addr;
+ result = true;
+ }
+
+ /* Sinon on demande à Python... */
+ else
+ {
+ value = PyLong_AsLongLongAndOverflow(obj, &overflow);
+
+ if (value == -1 && (overflow == 1 || PyErr_Occurred()))
+ PyErr_Clear();
+
+ else
+ {
+ init_vmpa(addr, value, value);
+ result = true;
+ }
+
+ }
+
+ return result;
+
+}
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : o1 = premier élément concerné par l'opération. *
+* o2 = second élément concerné par l'opération. *
+* *
+* Description : Effectue une opération de type 'add' avec le type 'vmpa'. *
+* *
+* Retour : Résultat de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_vmpa_nb_add(PyObject *o1, PyObject *o2)
+{
+ PyObject *result; /* Résultat à retourner */
+ vmpa2_t addr1; /* Première adresse à traiter */
+ vmpa2_t addr2; /* Seconde adresse à traiter */
+ PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */
+
+ if (!convert_pyobj_to_vmpa(o1, &addr1))
+ return NULL;
+
+ if (!convert_pyobj_to_vmpa(o2, &addr2))
+ return NULL;
+
+ py_vmpa_type = get_python_vmpa_type();
+
+ result = PyObject_CallObject((PyObject *)py_vmpa_type, NULL);
+
+ init_vmpa(&((py_vmpa_t *)result)->addr,
+ addr1.physical + addr2.physical,
+ addr1.virtual + addr2.virtual);
+
+ return result;
+
+}
+
+
+
+
+void log_simple_message(/*LogMessageType*/ int type, const char *msg)
+{
+
+}
+
+
+void log_variadic_message(/*LogMessageType*/ int type, const char *fmt, ...)
+{
+
+
+}
+
+
+void change_editor_items_current_view_content(void/*GtkViewPanel*/ *view)
+{
+
+
+}
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_vmpa_type(void)
+{
+ static PyNumberMethods py_vmpa_nb_proto = {
+
+ .nb_add = py_vmpa_nb_add,
+
+ /*
+ binaryfunc nb_add;
+ binaryfunc nb_subtract;
+ binaryfunc nb_multiply;
+ binaryfunc nb_remainder;
+ binaryfunc nb_divmod;
+ ternaryfunc nb_power;
+ unaryfunc nb_negative;
+ unaryfunc nb_positive;
+ unaryfunc nb_absolute;
+ inquiry nb_bool;
+ unaryfunc nb_invert;
+ binaryfunc nb_lshift;
+ binaryfunc nb_rshift;
+ binaryfunc nb_and;
+ binaryfunc nb_xor;
+ binaryfunc nb_or;
+ unaryfunc nb_int;
+ void *nb_reserved;
+ unaryfunc nb_float;
+
+ binaryfunc nb_inplace_add;
+ binaryfunc nb_inplace_subtract;
+ binaryfunc nb_inplace_multiply;
+ binaryfunc nb_inplace_remainder;
+ ternaryfunc nb_inplace_power;
+ binaryfunc nb_inplace_lshift;
+ binaryfunc nb_inplace_rshift;
+ binaryfunc nb_inplace_and;
+ binaryfunc nb_inplace_xor;
+ binaryfunc nb_inplace_or;
+
+ binaryfunc nb_floor_divide;
+ binaryfunc nb_true_divide;
+ binaryfunc nb_inplace_floor_divide;
+ binaryfunc nb_inplace_true_divide;
+
+ unaryfunc nb_index;
+
+ */
+
+ };
+
+ static PyTypeObject py_vmpa_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.arch.vmpa",
+ .tp_basicsize = sizeof(py_vmpa_t),
+
+ .tp_as_number = &py_vmpa_nb_proto,
+
+ .tp_str = py_vmpa_to_str,
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "Python object for vmpa_t"
+
+ };
+
+ return &py_vmpa_type;
+
+}
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.arch.vmpa'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_vmpa(PyObject *module)
+{
+ PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */
+ int ret; /* Bilan d'un appel */
+
+ py_vmpa_type = get_python_vmpa_type();
+
+ py_vmpa_type->tp_new = PyType_GenericNew;
+
+ 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/pychrysa/arch/vmpa.h b/plugins/pychrysa/arch/vmpa.h
new file mode 100644
index 0000000..6ee00b2
--- /dev/null
+++ b/plugins/pychrysa/arch/vmpa.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * vmpa.h - prototypes pour l'équivalent Python du fichier "arch/vmpa.h"
+ *
+ * Copyright (C) 2014 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_PYCHRYSALIDE_ARCH_VMPA_H
+#define _PLUGINS_PYCHRYSALIDE_ARCH_VMPA_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_vmpa_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.arch.vmpa'. */
+bool register_python_vmpa(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_VMPA_H */