summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/analysis/roptions.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-03-17 20:29:47 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-03-17 20:29:47 (GMT)
commitbbad297e902022ecac9fab21c01dc109560db8eb (patch)
tree6d9703e7dda8c0a61b0a3a015be89612df3bf198 /plugins/pychrysa/analysis/roptions.c
parentd1f5881c1f4ad53781fdadfe5ce6cac24cee3bab (diff)
Created the 'pychrysa' Python plugin from the 'pyoida' one.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@240 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/analysis/roptions.c')
-rw-r--r--plugins/pychrysa/analysis/roptions.c272
1 files changed, 272 insertions, 0 deletions
diff --git a/plugins/pychrysa/analysis/roptions.c b/plugins/pychrysa/analysis/roptions.c
new file mode 100644
index 0000000..57a4f52
--- /dev/null
+++ b/plugins/pychrysa/analysis/roptions.c
@@ -0,0 +1,272 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * roptions.c - équivalent Python du fichier "analysis/roptions.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 "roptions.h"
+
+
+#include "../format/executable.h"
+
+
+
+
+/* Classe 'analysis.roptions' pour Python */
+typedef struct _py_rendering_options
+{
+ PyObject_HEAD
+
+ GRenderingOptions *glib; /* Options réelles manipulées */
+
+} py_rendering_options;
+
+
+
+
+/* Crée un nouvel objet Python de type 'py_rendering_options'. */
+static PyObject *py_rendering_options_new(PyTypeObject *, PyObject *, PyObject *);
+
+
+
+/* Indique si les adresses des instructions sont à afficher. */
+static PyObject *py_rendering_options_get_show_address(PyObject *, void *);
+
+/* Affiche (ou non) les adresses des instructions. */
+static int py_rendering_options_set_show_address(PyObject *, PyObject *, void *);
+
+
+
+
+/* Affiche (ou non) le code des instructions. */
+static PyObject *py_rendering_options_show_code(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_rendering_options'. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_rendering_options_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ py_rendering_options *result; /* Instance à retourner */
+ PyObject *executable; /* Format d'exécutable joint */
+ int ret; /* Bilan de lecture des args. */
+ GExeFormat *_executable; /* Version GLib du format */
+
+ ret = PyArg_ParseTuple(args, "O", &executable);
+ if (!ret) return Py_None;
+
+ result = (py_rendering_options *)type->tp_alloc(type, 0);
+
+ _executable = py_executable_get_glib_instance(executable);
+
+ g_object_ref(G_OBJECT(_executable));
+ result->glib = g_rendering_options_new(_executable);
+
+ return (PyObject *)result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : roptions = instance Python dont la référence est à donner. *
+* *
+* Description : Fournit l'instance GLib d'une instance Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRenderingOptions *py_rendering_options_get_glib_instance(PyObject *roptions)
+{
+ return ((py_rendering_options *)roptions)->glib;
+
+}
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe présentant des options de représentation. *
+* data = adresse non utilisée ici. *
+* *
+* Description : Indique si les adresses des instructions sont à afficher. *
+* *
+* Retour : Valeur booléenne indiquant le statut d'une option. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_rendering_options_get_show_address(PyObject *self, void *data)
+{
+
+ printf(" -->> get address\n");
+
+ return Py_BuildValue("i", true);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe présentant des options de représentation. *
+* value = nouvelle valeur affectée. *
+* data = adresse non utilisée ici. *
+* *
+* Description : Affiche (ou non) les adresses des instructions. *
+* *
+* Retour : Bilan de la mise à jour. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_rendering_options_set_show_address(PyObject *self, PyObject *value, void *data)
+{
+ printf(" -->> set address\n");
+
+ return 0;
+
+}
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe assurant le lien avec l'éditeur de messages. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Affiche (ou non) le code des instructions. *
+* *
+* Retour : Rien en équivalent Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_rendering_options_show_code(PyObject *self, PyObject *args)
+{
+ int state; /* Nouveau statut d'affichage */
+
+ if (!PyArg_ParseTuple(args, "i", &state))
+ return NULL;
+
+
+
+
+ printf("show code :: %d\n", state);
+
+ return Py_None;
+
+}
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute l'objet 'analysis.roptions' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_analysis_roptions_to_python_module(PyObject *module)
+{
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_rendering_options_methods[] = {
+ {
+ "show_code", (PyCFunction)py_rendering_options_show_code,
+ METH_VARARGS,
+ "Define if the binary code has to be processed or not."
+ },
+ { NULL }
+ };
+
+ static PyGetSetDef py_rendering_options_getset[] = {
+ {
+ "show_address",
+ (getter)py_rendering_options_get_show_address,
+ (setter)py_rendering_options_set_show_address,
+ "Define or retrieve if the instruction address need to be shown."
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_rendering_options_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+ .tp_name = "pyoida.analysis.RenderingOptions",
+ .tp_basicsize = sizeof(py_rendering_options),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyOIDA rendering options",
+
+ .tp_methods = py_rendering_options_methods,
+ .tp_getset = py_rendering_options_getset,
+ .tp_new = (newfunc)py_rendering_options_new
+
+ };
+
+ if (PyType_Ready(&py_rendering_options_type) < 0)
+ return false;
+
+ Py_INCREF(&py_rendering_options_type);
+ ret = PyModule_AddObject(module, "RenderingOptions", (PyObject *)&py_rendering_options_type);
+
+ return (ret == 0);
+
+}