summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-08-06 20:29:20 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-08-06 20:29:20 (GMT)
commitfc49e98dc2b3e0ae08a5874ecacaef046a0f3ec1 (patch)
treee121c5eb5dd0629554a498f8e1a1cce3fc0715b4
parentfacec716100f598a8694889274a4589c75c14722 (diff)
Saved progress toward the Android permissions display.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@258 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
-rw-r--r--ChangeLog71
-rw-r--r--configure.ac1
-rw-r--r--plugins/pychrysa/Makefile.am5
-rw-r--r--plugins/pychrysa/analysis/binary.c106
-rw-r--r--plugins/pychrysa/analysis/binary.h2
-rw-r--r--plugins/pychrysa/arch/Makefile.am4
-rw-r--r--plugins/pychrysa/arch/instruction.c418
-rw-r--r--plugins/pychrysa/arch/instruction.h55
-rw-r--r--plugins/pychrysa/arch/module.c14
-rw-r--r--plugins/pychrysa/glibext/Makefile.am18
-rw-r--r--plugins/pychrysa/glibext/bufferline.c155
-rw-r--r--plugins/pychrysa/glibext/bufferline.h44
-rw-r--r--plugins/pychrysa/glibext/codebuffer.c159
-rw-r--r--plugins/pychrysa/glibext/codebuffer.h44
-rw-r--r--plugins/pychrysa/glibext/module.c68
-rw-r--r--plugins/pychrysa/glibext/module.h39
-rw-r--r--plugins/pychrysa/plugin.c48
-rw-r--r--plugins/pychrysa/pychrysa.c2
-rw-r--r--plugins/python/androperms/Makefile.am8
-rw-r--r--plugins/python/androperms/androperms.py30
-rw-r--r--plugins/python/androperms/panel.py89
-rw-r--r--src/analysis/binary.c3
-rw-r--r--src/analysis/disass/disassembler.c14
-rw-r--r--src/analysis/disass/disassembler.h2
-rw-r--r--src/glibext/gbufferline.c38
-rw-r--r--src/glibext/gbufferline.h3
-rw-r--r--src/glibext/gbuffersegment.c26
-rw-r--r--src/glibext/gbuffersegment.h3
-rw-r--r--src/glibext/gcodebuffer.c31
-rw-r--r--src/glibext/gcodebuffer.h3
-rw-r--r--src/gui/menus/project.c8
-rw-r--r--src/project.c6
32 files changed, 1485 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index d9bdf8a..d1bd7b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,76 @@
12-08-06 Cyrille Bagard <nocbos@gmail.com>
+ * configure.ac:
+ Add the new Makefile from the 'plugins/pychrysa/glibext' directory
+ to AC_CONFIG_FILES.
+
+ * plugins/pychrysa/analysis/binary.c:
+ * plugins/pychrysa/analysis/binary.h:
+ Typos. Provide disassembled instructions and buffer.
+
+ * plugins/pychrysa/arch/instruction.c:
+ * plugins/pychrysa/arch/instruction.h:
+ New entries: add instructions access to Python plugins.
+
+ * plugins/pychrysa/arch/Makefile.am:
+ Add the instruction.[ch] files to libpychrysaarch_la_SOURCES.
+
+ * plugins/pychrysa/arch/module.c:
+ Add instructions access to Python plugins.
+
+ * plugins/pychrysa/glibext/bufferline.c:
+ * plugins/pychrysa/glibext/bufferline.h:
+ * plugins/pychrysa/glibext/codebuffer.c:
+ * plugins/pychrysa/glibext/codebuffer.h:
+ * plugins/pychrysa/glibext/Makefile.am:
+ * plugins/pychrysa/glibext/module.c:
+ * plugins/pychrysa/glibext/module.h:
+ New entries: give access to internal buffers for Python.
+
+ * plugins/pychrysa/Makefile.am:
+ Add glibext/libpychrysaglibext.la to pychrysa_la_LIBADD
+ and glibext to SUBDIRS.
+
+ * plugins/pychrysa/plugin.c:
+ Test a way to add PyGtk widgets in the editor.
+
+ * plugins/pychrysa/pychrysa.c:
+ Load glibext Python module.
+
+ * plugins/python/androperms/androperms.py:
+ Play with the new features.
+
+ * plugins/python/androperms/Makefile.am:
+ Add the androperms.db and panel.py files to androperms_DATA and
+ download the first one if needed.
+
+ * plugins/python/androperms/panel.py:
+ New entry: build the beta resulting tree for permissions.
+
+ * src/analysis/binary.c:
+ * src/analysis/disass/disassembler.c:
+ * src/analysis/disass/disassembler.h:
+ Make sure the disassembled buffer is available as soon as plugins
+ may be called.
+
+ * src/glibext/gbufferline.c:
+ * src/glibext/gbufferline.h:
+ * src/glibext/gbuffersegment.c:
+ * src/glibext/gbuffersegment.h:
+ Provide the displayed text of buffer lines.
+
+ * src/glibext/gcodebuffer.c:
+ * src/glibext/gcodebuffer.h:
+ Find buffer lines by addresses.
+
+ * src/gui/menus/project.c:
+ Look at the project directory first when adding files to projects.
+
+ * src/project.c:
+ Save the current project for reloading it at next startup.
+
+12-08-06 Cyrille Bagard <nocbos@gmail.com>
+
* src/gui/menus/project.c:
* src/main.c:
* src/params.h:
diff --git a/configure.ac b/configure.ac
index 0ca98f8..ae07522 100644
--- a/configure.ac
+++ b/configure.ac
@@ -241,6 +241,7 @@ AC_CONFIG_FILES([Makefile
plugins/pychrysa/arch/Makefile
plugins/pychrysa/debug/Makefile
plugins/pychrysa/format/Makefile
+ plugins/pychrysa/glibext/Makefile
plugins/python/Makefile
plugins/python/androperms/Makefile
plugins/python/apkfiles/Makefile
diff --git a/plugins/pychrysa/Makefile.am b/plugins/pychrysa/Makefile.am
index a339dab..f8c08db 100644
--- a/plugins/pychrysa/Makefile.am
+++ b/plugins/pychrysa/Makefile.am
@@ -11,7 +11,8 @@ pychrysa_la_LIBADD = \
analysis/libpychrysaanalysis.la \
arch/libpychrysaarch.la \
debug/libpychrysadebug.la \
- format/libpychrysaformat.la
+ format/libpychrysaformat.la \
+ glibext/libpychrysaglibext.la
pychrysa_la_LDFLAGS = -module -avoid-version $(LIBGTK_LIBS) $(LIBXML_LIBS) $(LIBPYTHON_LIBS) \
$(LIBPYGOBJECT_LIBS) \
@@ -25,4 +26,4 @@ AM_CPPFLAGS =
AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
-SUBDIRS = analysis arch debug format
+SUBDIRS = analysis arch debug format glibext
diff --git a/plugins/pychrysa/analysis/binary.c b/plugins/pychrysa/analysis/binary.c
index 4cfb615..44721b5 100644
--- a/plugins/pychrysa/analysis/binary.c
+++ b/plugins/pychrysa/analysis/binary.c
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* binary.c - équivalent Python du fichier "analysis/binary.h"
*
- * Copyright (C) 2010 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
@@ -29,6 +29,8 @@
#include "../quirks.h"
+#include "../arch/instruction.h"
+#include "../glibext/codebuffer.h"
@@ -38,6 +40,15 @@ static PyObject *py_loaded_binary_new(PyTypeObject *, PyObject *, PyObject *);
/* Fournit le fichier correspondant à l'élément binaire. */
static PyObject *py_loaded_binary_get_filename(PyObject *self, PyObject *args);
+/* Fournit les instructions issues du désassemblage. */
+static PyObject *py_loaded_binary_get_instructions(PyObject *, PyObject *);
+
+
+
+/* Fournit le tampon associé au contenu assembleur d'un binaire. */
+static PyObject *py_loaded_binary_get_disassembled_buffer(PyObject *, void *);
+
+
/******************************************************************************
@@ -92,7 +103,7 @@ PyObject *py_loaded_binary_from_c(GOpenidaBinary *binary)
PyTypeObject *type; /* Type Python correspondant */
module = PyImport_ImportModule("pychrysalide.analysis");
- type = (PyTypeObject*)PyObject_GetAttrString(module, "LoadedBinary");
+ type = (PyTypeObject *)PyObject_GetAttrString(module, "LoadedBinary");
Py_DECREF(module);
pychrysalide_set_instance_data(G_OBJECT(binary), type);
@@ -102,14 +113,9 @@ PyObject *py_loaded_binary_from_c(GOpenidaBinary *binary)
}
-
-
-
-
-
/******************************************************************************
* *
-* Paramètres : self = classe représentant un débogueur. *
+* Paramètres : self = classe représentant un binaire. *
* args = arguments fournis à l'appel. *
* *
* Description : Fournit le fichier correspondant à l'élément binaire. *
@@ -137,6 +143,73 @@ static PyObject *py_loaded_binary_get_filename(PyObject *self, PyObject *args)
}
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un binaire. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Fournit les instructions issues du désassemblage. *
+* *
+* Retour : Instructions issues du désassemblage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_loaded_binary_get_instructions(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ GOpenidaBinary *binary; /* Version native */
+ GArchInstruction *instr; /* Première instruction */
+
+ binary = G_OPENIDA_BINARY(pygobject_get(self));
+
+ instr = g_openida_binary_get_instructions(binary);
+
+ result = py_arch_instruction_from_c(instr);
+
+ return result;
+
+}
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une instruction. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Fournit le tampon associé au contenu assembleur d'un binaire.*
+* *
+* Retour : Valeur associée à la propriété consultée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_loaded_binary_get_disassembled_buffer(PyObject *self, void *closure)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ GOpenidaBinary *binary; /* Version native */
+ GCodeBuffer *buffer; /* Tampon à récupérer */
+
+ binary = G_OPENIDA_BINARY(pygobject_get(self));
+ buffer = g_openida_binary_get_disassembled_buffer(binary);
+
+ result = py_code_buffer_from_c(buffer);
+
+ return result;
+
+}
+
+
+
+
+
+
+
/******************************************************************************
@@ -145,7 +218,7 @@ static PyObject *py_loaded_binary_get_filename(PyObject *self, PyObject *args)
* *
* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.*
* *
-* Retour : - *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
@@ -162,6 +235,20 @@ bool register_python_loaded_binary(PyObject *module)
METH_NOARGS,
"Provide the filename of the loaded binary."
},
+ {
+ "get_instructions", (PyCFunction)py_loaded_binary_get_instructions,
+ METH_NOARGS,
+ "Give access to all disassembled instructions."
+ },
+
+ { NULL }
+ };
+
+ static PyGetSetDef py_loaded_binary_getseters[] = {
+ {
+ "disassembled_buffer", (getter)py_loaded_binary_get_disassembled_buffer, (setter)NULL,
+ "Give access to the disassembled code buffer.", NULL
+ },
{ NULL }
};
@@ -177,6 +264,7 @@ bool register_python_loaded_binary(PyObject *module)
.tp_doc = "PyChrysalide loaded binary",
.tp_methods = py_loaded_binary_methods,
+ .tp_getset = py_loaded_binary_getseters,
.tp_new = (newfunc)py_loaded_binary_new
};
diff --git a/plugins/pychrysa/analysis/binary.h b/plugins/pychrysa/analysis/binary.h
index cc96a5b..89e5e59 100644
--- a/plugins/pychrysa/analysis/binary.h
+++ b/plugins/pychrysa/analysis/binary.h
@@ -2,7 +2,7 @@
/* OpenIDA - Outil d'analyse de fichiers binaires
* binary.h - prototypes pour l'équivalent Python du fichier "analysis/binary.h"
*
- * Copyright (C) 2010 Cyrille Bagard
+ * Copyright (C) 2010-2012 Cyrille Bagard
*
* This file is part of OpenIDA.
*
diff --git a/plugins/pychrysa/arch/Makefile.am b/plugins/pychrysa/arch/Makefile.am
index 6ab3332..fd7c862 100644
--- a/plugins/pychrysa/arch/Makefile.am
+++ b/plugins/pychrysa/arch/Makefile.am
@@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libpychrysaarch.la
libpychrysaarch_la_SOURCES = \
archbase.h archbase.c \
+ instruction.h instruction.c \
module.h module.c \
processor.h processor.c
@@ -10,7 +11,8 @@ libpychrysaarch_la_SOURCES = \
libpychrysaarch_la_LDFLAGS =
-INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) -I../../../src
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+ -I../../../src
AM_CPPFLAGS =
diff --git a/plugins/pychrysa/arch/instruction.c b/plugins/pychrysa/arch/instruction.c
new file mode 100644
index 0000000..80cc4ee
--- /dev/null
+++ b/plugins/pychrysa/arch/instruction.c
@@ -0,0 +1,418 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * instruction.c - équivalent Python du fichier "arch/instruction.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 "instruction.h"
+
+
+#include <pygobject.h>
+#include <stdbool.h>
+#include <string.h>
+
+
+#include "../quirks.h"
+
+
+
+/* --------------------- ITERATEUR POUR BOUCLE SUR INSTRUCTIONS --------------------- */
+
+
+/* Itérateur pour les instructions */
+typedef struct _PyArchInstructionIter
+{
+ PyObject_HEAD /* A laisser en premier */
+
+ GArchInstruction *head; /* Ancrage supposé */
+ PyObject *current; /* Départ, puis parcours... */
+ bool started; /* Démarrage effectué ? */
+
+} PyArchInstructionIter;
+
+
+/* Prépare l'itérateur pour un parcours d'instructions. */
+static PyObject *py_arch_instruction_iterator_create(PyObject *);
+
+/* Libère la mémoire d'un itérateur de 'ArchInstruction'. */
+static void py_arch_instruction_iterator_dealloc(PyArchInstructionIter *);
+
+/* Fournit l'élément suivant dans un parcours d'instructions. */
+static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *);
+
+
+
+/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */
+
+
+/* Crée un nouvel objet Python de type 'ArchInstruction'. */
+static PyObject *py_arch_instruction_new(PyTypeObject *, PyObject *, PyObject *);
+
+/* Prépare un parcours d'instructions. */
+static PyObject *py_arch_instruction_get_iter(PyObject *);
+
+/* Fournit la valeur associée à une propriété donnée. */
+static PyObject *py_arch_instruction_get_location(PyObject *, char *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* ITERATEUR POUR BOUCLE SUR INSTRUCTIONS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : origin = élément à l'origine du parcours. *
+* *
+* Description : Prépare l'itérateur pour un parcours d'instructions. *
+* *
+* Retour : Instance d'itérateur prête à emploi. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_iterator_create(PyObject *origin)
+{
+ PyArchInstructionIter *result; /* Nouvelle instance à renvoyer*/
+ PyObject *module; /* Module d'appartenance */
+ PyTypeObject *type; /* Type d'objet à créer */
+
+ module = PyImport_ImportModule("pychrysalide.arch");
+ type = (PyTypeObject *)PyObject_GetAttrString(module, "ArchInstructionIterator");
+ Py_DECREF(module);
+
+ result = (PyArchInstructionIter *)type->tp_alloc(type, 0);
+
+ if (result != NULL)
+ {
+ result->head = G_ARCH_INSTRUCTION(pygobject_get(origin));
+ g_object_ref(G_OBJECT(result->head));
+
+ Py_INCREF(origin);
+ result->current = origin;
+ }
+
+ return (PyObject *)result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instance d'objet à supprimer. *
+* *
+* Description : Libère la mémoire d'un itérateur de 'ArchInstruction'. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void py_arch_instruction_iterator_dealloc(PyArchInstructionIter *self)
+{
+ g_object_unref(G_OBJECT(self->head));
+ Py_DECREF(self->current);
+
+#if PY_VERSION_HEX < 0x03000000
+ self->ob_type->tp_free((PyObject *)self);
+#else
+ Py_TYPE(self)->tp_free((PyObject *)self);
+#endif
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instance manipulée à traiter. *
+* *
+* Description : Fournit l'élément suivant dans un parcours d'instructions. *
+* *
+* Retour : Point suivant du parcours ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *self)
+{
+ PyObject *result; /* Elément à retourner */
+ GArchInstruction *next; /* Elément réel suivant */
+
+ if (!self->started)
+ {
+ self->started = true;
+ result = self->current;
+ }
+ else
+ {
+ next = G_ARCH_INSTRUCTION(pygobject_get(self->current));
+ next = g_arch_instruction_get_next_iter(self->head, next, VMPA_MAX);
+
+ if (next != NULL)
+ {
+ result = py_arch_instruction_from_c(next);
+
+ Py_INCREF(result);
+ Py_DECREF(self->current);
+ self->current = result;
+
+ }
+ else result = NULL;
+
+ }
+
+ return (PyObject *)result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Permet une itération de 'pychrysalide.arch.ArchInstruction'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_arch_instruction_iterator(PyObject *module)
+{
+ int ret; /* Bilan d'un appel */
+
+ static PyTypeObject py_arch_instruction_iterator_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+ .tp_name = "pychrysalide.arch.ArchInstructionIterator",
+ .tp_basicsize = sizeof(PyArchInstructionIter),
+
+ .tp_dealloc = (destructor)py_arch_instruction_iterator_dealloc,
+
+ .tp_flags = Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_CLASS,
+
+ .tp_doc = "PyChrysalide architecture instruction iterator",
+
+ .tp_iter = PyObject_SelfIter,
+ .tp_iternext = (iternextfunc)py_arch_instruction_iterator_next
+
+ };
+
+ if (PyType_Ready(&py_arch_instruction_iterator_type) < 0)
+ return false;
+
+ Py_INCREF(&py_arch_instruction_iterator_type);
+ ret = PyModule_AddObject(module, "ArchInstructionIterator", (PyObject *)&py_arch_instruction_iterator_type);
+
+ return (ret == 0);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INSTRUCTIONS D'ARCHITECTURES EN PYTHON */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* 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 'ArchInstruction'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ return Py_None;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = instance existante GLib. *
+* *
+* Description : Crée un nouvel objet Python de type 'ArchInstruction'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *py_arch_instruction_from_c(GArchInstruction *instr)
+{
+ PyObject *module; /* Module d'appartenance */
+ PyTypeObject *type; /* Type Python correspondant */
+
+ module = PyImport_ImportModule("pychrysalide.arch");
+ type = (PyTypeObject *)PyObject_GetAttrString(module, "ArchInstruction");
+ Py_DECREF(module);
+
+ pychrysalide_set_instance_data(G_OBJECT(instr), type);
+
+ return pygobject_new(G_OBJECT(instr));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instance manipulée à traiter. *
+* *
+* Description : Prépare un parcours d'instructions. *
+* *
+* Retour : Point de départ d'un parcours. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_get_iter(PyObject *self)
+{
+ return py_arch_instruction_iterator_create(self);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une instruction. *
+* name = nom de la propriété à lire. *
+* *
+* Description : Fournit la valeur associée à une propriété donnée. *
+* *
+* Retour : Valeur associée à la propriété consultée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_get_location(PyObject *self, char *name)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ GArchInstruction *instr; /* Version native */
+ off_t offset; /* Position dans le fichier */
+ off_t length; /* Taille de l'instruction */
+ vmpa_t address; /* Position en mémoire */
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+ g_arch_instruction_get_location(instr, &offset, &length, &address);
+
+ if (strcmp(name, "offset") == 0)
+ result = PyLong_FromLong(offset);
+
+ else if (strcmp(name, "") == 0)
+ result = PyLong_FromLong(length);
+
+ else /*if (strcmp(name, "") == 0)*/
+ result = PyLong_FromLongLong(address);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_arch_instruction(PyObject *module)
+{
+ PyObject *pygobj_mod; /* Module Python-GObject */
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_arch_instruction_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_arch_instruction_getseters[] = {
+ {
+ "offset", (getter)py_arch_instruction_get_location, (setter)NULL,
+ "Provide the location of the instruction in the binary file.", "offset"
+ },
+ {
+ "length", (getter)py_arch_instruction_get_location, (setter)NULL,
+ "Provide the length of the instruction.", "length"
+ },
+ {
+ "address", (getter)py_arch_instruction_get_location, (setter)NULL,
+ "Provide the location of the instruction in memory.", "address"
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_arch_instruction_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+ .tp_name = "pychrysalide.arch.ArchInstruction",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide architecture instruction",
+
+ .tp_methods = py_arch_instruction_methods,
+ .tp_getset = py_arch_instruction_getseters,
+ .tp_new = (newfunc)py_arch_instruction_new,
+
+ .tp_iter = (getiterfunc)py_arch_instruction_get_iter
+
+ };
+
+ pygobj_mod = PyImport_ImportModule("gobject");
+ if (pygobj_mod == NULL) return false;
+
+ py_arch_instruction_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
+ Py_DECREF(pygobj_mod);
+
+ if (PyType_Ready(&py_arch_instruction_type) < 0)
+ return false;
+
+ Py_INCREF(&py_arch_instruction_type);
+ ret = PyModule_AddObject(module, "ArchInstruction", (PyObject *)&py_arch_instruction_type);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pychrysa/arch/instruction.h b/plugins/pychrysa/arch/instruction.h
new file mode 100644
index 0000000..545d88e
--- /dev/null
+++ b/plugins/pychrysa/arch/instruction.h
@@ -0,0 +1,55 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * instruction.h - prototypes pour l'équivalent Python du fichier "arch/instruction.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
+ */
+
+
+#ifndef _PLUGINS_PYOIDA_ARCH_INSTRUCTION_H
+#define _PLUGINS_PYOIDA_ARCH_INSTRUCTION_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+#include <arch/instruction.h>
+
+
+
+/* --------------------- ITERATEUR POUR BOUCLE SUR INSTRUCTIONS --------------------- */
+
+
+/* Permet une itération de 'pychrysalide.arch.ArchInstruction'. */
+bool register_python_arch_instruction_iterator(PyObject *);
+
+
+
+/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */
+
+
+/* Crée un nouvel objet Python de type 'ArchInstruction'. */
+PyObject *py_arch_instruction_from_c(GArchInstruction *);
+
+/* Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. */
+bool register_python_arch_instruction(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ARCH_INSTRUCTION_H */
diff --git a/plugins/pychrysa/arch/module.c b/plugins/pychrysa/arch/module.c
index 59b0c2c..8092b6b 100644
--- a/plugins/pychrysa/arch/module.c
+++ b/plugins/pychrysa/arch/module.c
@@ -25,8 +25,7 @@
#include "module.h"
-#include "archbase.h"
-#include "processor.h"
+#include "instruction.h"
@@ -54,18 +53,19 @@ bool add_arch_module_to_python_module(PyObject *super)
{ NULL }
};
- module = Py_InitModule("pyoida.arch", py_arch_methods);
+ module = Py_InitModule("pychrysalide.arch", py_arch_methods);
if (module == NULL) return false;
Py_INCREF(module);
- ret = PyModule_AddObject(super, "pyoida.arch", module);
+ ret = PyModule_AddObject(super, "pychrysalide.arch", module);
- if (ret != 0) /* ... */;
+ result = (ret != 0);
- result = add_arch_vmpa_to_python_module(module);
- result = add_arch_processor_to_python_module(module);
+ if (ret != 0) /* ... */;
+ result &= register_python_arch_instruction(module);
+ result &= register_python_arch_instruction_iterator(module);
return true;
diff --git a/plugins/pychrysa/glibext/Makefile.am b/plugins/pychrysa/glibext/Makefile.am
new file mode 100644
index 0000000..da33fb6
--- /dev/null
+++ b/plugins/pychrysa/glibext/Makefile.am
@@ -0,0 +1,18 @@
+
+noinst_LTLIBRARIES = libpychrysaglibext.la
+
+libpychrysaglibext_la_SOURCES = \
+ bufferline.h bufferline.c \
+ codebuffer.h codebuffer.c \
+ module.h module.c
+
+
+libpychrysaglibext_la_LDFLAGS =
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+ -I../../../src
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
diff --git a/plugins/pychrysa/glibext/bufferline.c b/plugins/pychrysa/glibext/bufferline.c
new file mode 100644
index 0000000..1e3b611
--- /dev/null
+++ b/plugins/pychrysa/glibext/bufferline.c
@@ -0,0 +1,155 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * bufferline.c - équivalent Python du fichier "glibext/gbufferline.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 "bufferline.h"
+
+
+#include <malloc.h>
+#include <pygobject.h>
+
+
+#include "../quirks.h"
+
+
+
+/* Reconstruit et fournit le texte présent sur une ligne tampon. */
+static PyObject *py_buffer_line_get_text(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = instance existante GLib. *
+* *
+* Description : Crée un nouvel objet Python de type 'BufferLine'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *py_buffer_line_from_c(GBufferLine *line)
+{
+ PyObject *module; /* Module d'appartenance */
+ PyTypeObject *type; /* Type Python correspondant */
+
+ module = PyImport_ImportModule("pychrysalide.glibext");
+ type = (PyTypeObject *)PyObject_GetAttrString(module, "BufferLine");
+ Py_DECREF(module);
+
+ pychrysalide_set_instance_data(G_OBJECT(line), type);
+
+ return pygobject_new(G_OBJECT(line));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant une ligne de tampon. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Reconstruit et fournit le texte présent sur une ligne tampon.*
+* *
+* Retour : Texte reconstruit pour l'occasion. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_buffer_line_get_text(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ GBufferLine *line; /* Version native */
+ char *text; /* Texte reconstruit à libérer */
+
+ line = G_BUFFER_LINE(pygobject_get(self));
+ text = g_buffer_line_get_text(line);
+
+ result = PyString_FromString(text);
+
+ free(text);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_buffer_line(PyObject *module)
+{
+ PyObject *pygobj_mod; /* Module Python-GObject */
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_buffer_line_methods[] = {
+ {
+ "get_text", (PyCFunction)py_buffer_line_get_text,
+ METH_NOARGS,
+ "Rebuild and provide the text of a buffer line."
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_buffer_line_type = {
+
+ PyObject_HEAD_INIT(NULL)
+
+ .tp_name = "pychrysalide.glibext.BufferLine",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide buffer line",
+
+ .tp_methods = py_buffer_line_methods
+
+ };
+
+ pygobj_mod = PyImport_ImportModule("gobject");
+ if (pygobj_mod == NULL) return false;
+
+ py_buffer_line_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
+ Py_DECREF(pygobj_mod);
+
+ if (PyType_Ready(&py_buffer_line_type) < 0)
+ return false;
+
+ Py_INCREF(&py_buffer_line_type);
+ ret = PyModule_AddObject(module, "BufferLine", (PyObject *)&py_buffer_line_type);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pychrysa/glibext/bufferline.h b/plugins/pychrysa/glibext/bufferline.h
new file mode 100644
index 0000000..d15928f
--- /dev/null
+++ b/plugins/pychrysa/glibext/bufferline.h
@@ -0,0 +1,44 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * bufferline.h - prototypes pour l'équivalent Python du fichier "glibext/bufferline.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
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSA_GLIBEXT_BUFFERLINE_H
+#define _PLUGINS_PYCHRYSA_GLIBEXT_BUFFERLINE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+#include <glibext/gbufferline.h>
+
+
+
+/* Crée un nouvel objet Python de type 'BufferLine'. */
+PyObject *py_buffer_line_from_c(GBufferLine *);
+
+/* Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. */
+bool register_python_buffer_line(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSA_GLIBEXT_BUFFERLINE_H */
diff --git a/plugins/pychrysa/glibext/codebuffer.c b/plugins/pychrysa/glibext/codebuffer.c
new file mode 100644
index 0000000..a090e27
--- /dev/null
+++ b/plugins/pychrysa/glibext/codebuffer.c
@@ -0,0 +1,159 @@
+
+/* 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 <pygobject.h>
+
+
+#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 : binary = instance existante GLib. *
+* *
+* Description : Crée un nouvel objet Python de type 'Codebuffer'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *py_code_buffer_from_c(GCodeBuffer *buffer)
+{
+ PyObject *module; /* Module d'appartenance */
+ PyTypeObject *type; /* Type Python correspondant */
+
+ module = PyImport_ImportModule("pychrysalide.glibext");
+ type = (PyTypeObject *)PyObject_GetAttrString(module, "CodeBuffer");
+ Py_DECREF(module);
+
+ pychrysalide_set_instance_data(G_OBJECT(buffer), type);
+
+ return pygobject_new(G_OBJECT(buffer));
+
+}
+
+
+/******************************************************************************
+* *
+* 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) return Py_None;
+
+ line = g_code_buffer_find_line_by_addr(buffer, addr);
+ if (line == NULL) return Py_None;
+
+ result = py_buffer_line_from_c(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);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pychrysa/glibext/codebuffer.h b/plugins/pychrysa/glibext/codebuffer.h
new file mode 100644
index 0000000..ba53fda
--- /dev/null
+++ b/plugins/pychrysa/glibext/codebuffer.h
@@ -0,0 +1,44 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * codebuffer.h - prototypes pour l'équivalent Python du fichier "glibext/codebuffer.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
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSA_GLIBEXT_CODEBUFFER_H
+#define _PLUGINS_PYCHRYSA_GLIBEXT_CODEBUFFER_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+#include <glibext/gcodebuffer.h>
+
+
+
+/* Crée un nouvel objet Python de type 'CodeBuffer'. */
+PyObject *py_code_buffer_from_c(GCodeBuffer *);
+
+/* Prend en charge l'objet 'pychrysalide.glibext.CodeBuffer'. */
+bool register_python_code_buffer(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSA_GLIBEXT_CODEBUFFER_H */
diff --git a/plugins/pychrysa/glibext/module.c b/plugins/pychrysa/glibext/module.c
new file mode 100644
index 0000000..b2ba4ab
--- /dev/null
+++ b/plugins/pychrysa/glibext/module.c
@@ -0,0 +1,68 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire glibext en tant que module
+ *
+ * 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 "module.h"
+
+
+#include "bufferline.h"
+#include "codebuffer.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute le module 'glibext' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_glibext_module_to_python_module(PyObject *super)
+{
+ bool result;
+ PyObject *module;
+ int ret; /* Bilan d'un appel */
+
+ static PyMethodDef py_glibext_methods[] = {
+ { NULL }
+ };
+
+ module = Py_InitModule("pychrysalide.glibext", py_glibext_methods);
+ if (module == NULL) return false;
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "pychrysalide.glibext", module);
+
+ result = (ret != 0);
+
+ result &= register_python_buffer_line(module);
+ result &= register_python_code_buffer(module);
+
+ return result;
+
+}
diff --git a/plugins/pychrysa/glibext/module.h b/plugins/pychrysa/glibext/module.h
new file mode 100644
index 0000000..a68ecb8
--- /dev/null
+++ b/plugins/pychrysa/glibext/module.h
@@ -0,0 +1,39 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire glibext en tant que module
+ *
+ * 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
+ */
+
+
+#ifndef _PLUGINS_PYOIDA_GLIBEXT_MODULE_H
+#define _PLUGINS_PYOIDA_GLIBEXT_MODULE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Ajoute le module 'glibext' au module Python. */
+bool add_glibext_module_to_python_module(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_GLIBEXT_MODULE_H */
diff --git a/plugins/pychrysa/plugin.c b/plugins/pychrysa/plugin.c
index 9dc0c29..6d8a494 100644
--- a/plugins/pychrysa/plugin.c
+++ b/plugins/pychrysa/plugin.c
@@ -482,7 +482,6 @@ static MatchingFormatAction g_python_plugin_is_matching(const GPythonPlugin *plu
-
/******************************************************************************
* *
* Paramètres : plugin = greffon de prise en charge à utiliser. *
@@ -749,6 +748,50 @@ static PyObject *pychrysa_plugin_run(PyObject *self, PyObject *args)
+#include <pygtk-2.0/pygobject.h>
+
+static int convert_to_w(PyGObject *obj, void **out)
+{
+
+ //if (!pygobject_check(obj,
+
+ *out = pygobject_get(obj);
+
+ return (1);
+
+}
+
+
+static PyObject *add_wgt(PyObject *self, PyObject *args)
+{
+ GtkWidget *result;
+ GtkWidget *button;
+
+
+ result = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request(result, 400, 300);
+ gtk_window_set_position(GTK_WINDOW(result), GTK_WIN_POS_CENTER);
+ gtk_container_set_border_width(GTK_CONTAINER(result), 4);
+ gtk_window_set_title(GTK_WINDOW(result), _("ChrysalideWWW"));
+
+ gtk_widget_show (result);
+
+
+ if (!PyArg_ParseTuple(args, "O&", convert_to_w, &button))
+ return Py_None;
+
+ gtk_container_add(GTK_CONTAINER(result), button);
+
+
+ return Py_None;
+
+}
+
+
+
+
+
+
/******************************************************************************
* *
@@ -780,6 +823,9 @@ static PyMethodDef pychrysa_plugin_methods[] = {
{ "run", (PyCFunction)pychrysa_plugin_run, METH_VARARGS,
"Run the plugin for a specific action."
},
+ { "add_wgt", (PyCFunction)add_wgt, METH_VARARGS,
+ "Run the plugin for a specific action."
+ },
NULL
};
diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c
index 7bb1e00..8b9fc50 100644
--- a/plugins/pychrysa/pychrysa.c
+++ b/plugins/pychrysa/pychrysa.c
@@ -37,6 +37,7 @@
#include "arch/module.h"
#include "debug/module.h"
#include "format/module.h"
+#include "glibext/module.h"
/*
#include "analysis/py_binary.h"
@@ -265,6 +266,7 @@ PyMODINIT_FUNC initpychrysa(void)
add_arch_module_to_python_module(module);
add_debug_module_to_python_module(module);
add_format_module_to_python_module(module);
+ add_glibext_module_to_python_module(module);
add_log_to_python_module(module);
add_plugin_to_python_module(module);
diff --git a/plugins/python/androperms/Makefile.am b/plugins/python/androperms/Makefile.am
index 3d1755c..f44be3c 100644
--- a/plugins/python/androperms/Makefile.am
+++ b/plugins/python/androperms/Makefile.am
@@ -3,10 +3,18 @@ andropermsdir = $(datadir)/openida/plugins/python/androperms
androperms_DATA = \
__init__.py \
+ androperms.db \
androperms.py \
defs.py \
manifest.py \
+ panel.py \
parser.py \
reader.py \
stack.py \
string.py
+
+androperms.db:
+ @tmpzip=`tempfile` ; \
+ wget http://www.android-permissions.org/permissionmap.zip -O $$tmpzip ; \
+ unzip -p $$tmpzip permissionmap/APICalls.txt | tail -n +2 - > androperms.db ; \
+ rm $$tmpzip
diff --git a/plugins/python/androperms/androperms.py b/plugins/python/androperms/androperms.py
index f85d402..0d70edc 100644
--- a/plugins/python/androperms/androperms.py
+++ b/plugins/python/androperms/androperms.py
@@ -3,8 +3,10 @@
from pychrysalide import Plugin
from manifest import AndroidManifest
+from panel import PermsPanel
from xml.dom import minidom
+import gtk
import zipfile
@@ -35,7 +37,35 @@ class AndroPerms(Plugin):
print "-------------"
print
+ plist = []
+
for p in xml.getElementsByTagName("uses-permission"):
+ plist.append(p.getAttribute("android:name"))
print p.getAttribute("android:name")
print
+
+ button = gtk.Button("Hello World")
+ button.show()
+
+ treestore = gtk.TreeStore(str, str, str)
+
+
+ panel = PermsPanel()
+
+
+ panel.filter_permissions(plist)
+
+ #self.add_wgt(panel.get_widget())
+
+ instrs = binary.get_instructions()
+
+ for i in instrs:
+ # print i, " :: 0x%08lx" % i.address
+
+ line = binary.disassembled_buffer.find_line_by_addr(i.address)
+ text = line.get_text()
+
+ if text.startswith("invoke"):
+ #print "[0x%08lx] " % i.address, text
+ pass
diff --git a/plugins/python/androperms/panel.py b/plugins/python/androperms/panel.py
new file mode 100644
index 0000000..b852049
--- /dev/null
+++ b/plugins/python/androperms/panel.py
@@ -0,0 +1,89 @@
+
+import gtk
+import os
+
+
+class PermsPanel:
+ """Display all permissions found in the Manifest."""
+
+ def __init__(self):
+
+
+ tree = gtk.TreeView()
+
+ languages = gtk.TreeViewColumn()
+ languages.set_title("Programming languages")
+
+ cell = gtk.CellRendererText()
+ languages.pack_start(cell, True)
+ languages.add_attribute(cell, "text", 0)
+
+ treestore = gtk.TreeStore(str)
+
+ it = treestore.append(None, ["Scripting languages"])
+ treestore.append(it, ["Python"])
+ treestore.append(it, ["PHP"])
+ treestore.append(it, ["Perl"])
+ treestore.append(it, ["Ruby"])
+
+ it = treestore.append(None, ["Compiling languages"])
+ treestore.append(it, ["C#"])
+ treestore.append(it, ["C++"])
+ treestore.append(it, ["C"])
+ treestore.append(it, ["Java"])
+
+ tree.append_column(languages)
+ tree.set_model(treestore)
+
+ tree.show()
+
+ self._view = tree
+
+ self._perms = { }
+
+ self._load_all_definitions()
+
+
+ def get_widget(self):
+
+ return self._view
+
+
+
+
+
+ def _load_all_definitions(self):
+ """Load the database in memory."""
+
+ with open(os.path.dirname(__file__) + '/androperms.db', 'r') as f:
+
+ for line in f.readlines():
+
+ perm = line.strip("\n").split("\t")
+
+ for p in perm[1].split(" "):
+
+ if not p.startswith("android.permission."):
+ continue
+
+ if p not in self._perms:
+ self._perms[p] = []
+
+ self._perms[p].append(perm[0])
+
+
+ def filter_permissions(self, used):
+ """Forget all permissions which are not used."""
+
+ keep = {}
+
+ for p in self._perms:
+ if p in used:
+ keep[p] = self._perms[p]
+
+ self._perms = keep
+
+ # for p in self._perms:
+ # print p
+ # for v in self._perms[p]:
+ # print " - ", v
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 21b4b14..73070b1 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -664,7 +664,8 @@ void g_openida_binary_analyse(GOpenidaBinary *binary)
}
}
- binary->disass_buffer = disassemble_binary(binary, parts, parts_count, &binary->instrs);
+ disassemble_binary(binary, parts, parts_count,
+ &binary->instrs, &binary->disass_buffer);
/* TODO : remme ! */
ack_completed_disassembly(NULL, binary);
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 75e411f..872dc09 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -371,18 +371,18 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con
* parts = parties binaires à désassembler. *
* count = nombre de parties à traiter. *
* instrs = liste des instructions chargées. [OUT] *
+* buffer = tampon de code mis en place. [OUT] *
* *
* Description : Procède au désassemblage d'un contenu binaire donné. *
* *
-* Retour : Tampon de code mis en place. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-GCodeBuffer *disassemble_binary(GOpenidaBinary *binary, GBinPart **parts, size_t parts_count, GArchInstruction **instrs)
+void disassemble_binary(GOpenidaBinary *binary, GBinPart **parts, size_t parts_count, GArchInstruction **instrs, GCodeBuffer **buffer)
{
- GCodeBuffer *result; /* Tampon constitué à renvoyer */
const uint8_t *data; /* Données binaires brutes */
off_t length; /* Quantité de ces données */
GDelayedDisassembly *disass; /* Désassemblage à mener */
@@ -393,12 +393,12 @@ GCodeBuffer *disassemble_binary(GOpenidaBinary *binary, GBinPart **parts, size_t
/* Déroulement de l'opération principale */
- result = g_code_buffer_new();
+ *buffer = g_code_buffer_new();
data = g_openida_binary_get_data(binary, &length);
- build_disass_prologue(result, g_openida_binary_get_filename(binary), data, length);
+ build_disass_prologue(*buffer, g_openida_binary_get_filename(binary), data, length);
- disass = g_delayed_disassembly_new(binary, parts, parts_count, result);
+ disass = g_delayed_disassembly_new(binary, parts, parts_count, *buffer);
queue = get_work_queue();
g_work_queue_schedule_work(queue, G_DELAYED_WORK(disass));
@@ -422,6 +422,4 @@ GCodeBuffer *disassemble_binary(GOpenidaBinary *binary, GBinPart **parts, size_t
}
- return result;
-
}
diff --git a/src/analysis/disass/disassembler.h b/src/analysis/disass/disassembler.h
index 54da069..2c5adef 100644
--- a/src/analysis/disass/disassembler.h
+++ b/src/analysis/disass/disassembler.h
@@ -31,7 +31,7 @@
/* Procède à la décompilation des routines d'un fichier donné. */
-GCodeBuffer *disassemble_binary(GOpenidaBinary *, GBinPart **parts, size_t parts_count, GArchInstruction **);
+void disassemble_binary(GOpenidaBinary *, GBinPart **parts, size_t parts_count, GArchInstruction **, GCodeBuffer **);
diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c
index e32e450..08f5ae7 100644
--- a/src/glibext/gbufferline.c
+++ b/src/glibext/gbufferline.c
@@ -24,9 +24,12 @@
#include "gbufferline.h"
+#include <string.h>
#include <gtk/gtk.h> /* Récupération du langage par défaut ; FIXME ? */
+#include "../common/extstr.h"
+
#include <malloc.h> /* FIXME : à virer */
@@ -495,6 +498,41 @@ void g_buffer_line_insert_text(GBufferLine *line, BufferLineColumn column, const
/******************************************************************************
* *
+* Paramètres : line = ligne à venir consulter. *
+* *
+* Description : Donne le texte représenté par une ligne de tampon. *
+* *
+* Retour : Texte à libérer de la mémoire après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_buffer_line_get_text(const GBufferLine *line)
+{
+ char *result; /* Construction à retourner */
+ BufferLineColumn i; /* Boucle de parcours #1 */
+ size_t j; /* Boucle de parcours #2 */
+
+ result = NULL;
+
+ for (i = BLC_ASSEMBLY_HEAD; i < BLC_COUNT; i++)
+ for (j = 0; j < line->columns[i].count; j++)
+ if (result == NULL)
+ {
+ result = strdup(g_buffer_segment_get_text(line->columns[i].segments[j]));
+ result = stradd(result, " ");
+ }
+ else
+ result = stradd(result, g_buffer_segment_get_text(line->columns[i].segments[j]));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : line = ligne à venir compléter. *
* index = index de la colonne visée par la procédure. *
* *
diff --git a/src/glibext/gbufferline.h b/src/glibext/gbufferline.h
index 1e115cd..a9f6391 100644
--- a/src/glibext/gbufferline.h
+++ b/src/glibext/gbufferline.h
@@ -121,6 +121,9 @@ void g_buffer_line_add_segment(GBufferLine *, BufferLineColumn, GBufferSegment *
/* Ajoute du texte à formater dans une ligne donnée. */
void g_buffer_line_insert_text(GBufferLine *, BufferLineColumn, const char *, size_t, RenderingTagType);
+/* Donne le texte représenté par une ligne de tampon. */
+char *g_buffer_line_get_text(const GBufferLine *);
+
/* Fournit la largeur requise pour une colonne de ligne donnée. */
gint g_buffer_line_get_width(GBufferLine *, BufferLineColumn);
diff --git a/src/glibext/gbuffersegment.c b/src/glibext/gbuffersegment.c
index 0714e9c..6e862ad 100644
--- a/src/glibext/gbuffersegment.c
+++ b/src/glibext/gbuffersegment.c
@@ -25,6 +25,7 @@
#include <stdbool.h>
+#include <string.h>
@@ -38,6 +39,8 @@ struct _GBufferSegment
{
GObject parent; /* A laisser en premier */
+ char *text; /* Texte brut conservé */
+
PangoAttrList *attribs; /* Propriétés du rendu */
GdkColor cache_fg; /* Couleur d'impression */
@@ -376,6 +379,8 @@ GBufferSegment *g_buffer_segment_new(PangoContext *context, PangoAttrList *attri
result = g_object_new(G_TYPE_BUFFER_SEGMENT, NULL);
//result = g_new(GBufferSegment, 1);
+ result->text = strdup(text);
+
result->attribs = pango_attr_list_ref(attribs);
g_buffer_segment_prepare(result, context, attribs, text, length);
@@ -389,7 +394,26 @@ GBufferSegment *g_buffer_segment_new(PangoContext *context, PangoAttrList *attri
/******************************************************************************
* *
-* Paramètres : segment = fragment de texte à consulter. *
+* Paramètres : segment = fragment de texte à consulter. *
+* *
+* Description : Fournit le texte brut conservé dans le segment. *
+* *
+* Retour : Texte conservé en interne. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const char *g_buffer_segment_get_text(const GBufferSegment *segment)
+{
+ return segment->text;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : segment = fragment de texte à consulter. *
* *
* Description : Fournit la quantité de pixels requise pour l'impression. *
* *
diff --git a/src/glibext/gbuffersegment.h b/src/glibext/gbuffersegment.h
index b335ab6..ead0560 100644
--- a/src/glibext/gbuffersegment.h
+++ b/src/glibext/gbuffersegment.h
@@ -64,6 +64,9 @@ GType g_buffer_segment_get_type(void);
/* Crée un nouveau fragment de texte avec des propriétés. */
GBufferSegment *g_buffer_segment_new(PangoContext *, PangoAttrList *, const char *, size_t);
+/* Fournit le texte brut conservé dans le segment. */
+const char *g_buffer_segment_get_text(const GBufferSegment *);
+
/* Fournit la quantité de pixels requise pour l'impression. */
gint g_buffer_segment_get_width(const GBufferSegment *);
diff --git a/src/glibext/gcodebuffer.c b/src/glibext/gcodebuffer.c
index fe00e2d..ac63a87 100644
--- a/src/glibext/gcodebuffer.c
+++ b/src/glibext/gcodebuffer.c
@@ -445,6 +445,37 @@ GBufferLine *g_code_buffer_append_new_line(GCodeBuffer *buffer, vmpa_t addr)
/******************************************************************************
* *
* Paramètres : buffer = composant GTK à mettre à jour. *
+* addr = adresse où retrouver la ligne recherchée. *
+* *
+* Description : Retrouve une ligne au sein d'un tampon avec une adresse. *
+* *
+* Retour : Line retrouvée ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBufferLine *g_code_buffer_find_line_by_addr(const GCodeBuffer *buffer, vmpa_t addr)
+{
+ GBufferLine *result; /* Instance à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = NULL;
+
+ /* TODO : coder un parcours plus optimal ! */
+
+ for (i = 0; i < buffer->used && result == NULL; i++)
+ if (g_buffer_line_get_address(buffer->lines[i]) == addr)
+ result = buffer->lines[i];
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : buffer = composant GTK à mettre à jour. *
* *
* Description : Augmente l'indentation des prochaines lignes. *
* *
diff --git a/src/glibext/gcodebuffer.h b/src/glibext/gcodebuffer.h
index 1cac790..2c8dbe9 100644
--- a/src/glibext/gcodebuffer.h
+++ b/src/glibext/gcodebuffer.h
@@ -62,6 +62,9 @@ GCodeBuffer *g_code_buffer_new(void);
/* Ajoute une nouvelle ligne à un tampon pour code désassemblé. */
GBufferLine *g_code_buffer_append_new_line(GCodeBuffer *, vmpa_t);
+/* Retrouve une ligne au sein d'un tampon avec une adresse. */
+GBufferLine *g_code_buffer_find_line_by_addr(const GCodeBuffer *, vmpa_t);
+
/* Augmente l'indentation des prochaines lignes. */
void g_code_buffer_inc_indentation(GCodeBuffer *);
diff --git a/src/gui/menus/project.c b/src/gui/menus/project.c
index 7e9fc3f..96b411b 100644
--- a/src/gui/menus/project.c
+++ b/src/gui/menus/project.c
@@ -192,6 +192,14 @@ static void mcb_project_add_binary_file(GtkMenuItem *menuitem, GMenuBar *bar)
free(dir);
}
+ if (g_study_project_get_filename(get_current_project()) != NULL)
+ {
+ dir = strdup(g_study_project_get_filename(get_current_project()));
+ dir = dirname(dir);
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
+ free(dir);
+ }
+
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
diff --git a/src/project.c b/src/project.c
index 9763e2d..91fe36c 100644
--- a/src/project.c
+++ b/src/project.c
@@ -664,6 +664,8 @@ void push_project_into_recent_list(const GStudyProject *project)
/* Constitution de la liste des projets récents */
+ /* Constitution de la liste des projets récents */
+
manager = get_projects_manager();
qualified = (char *)calloc(strlen("file://") + strlen(project->filename) + 1, sizeof(char));
@@ -685,4 +687,8 @@ void push_project_into_recent_list(const GStudyProject *project)
set_string_config_value(get_main_configuration(), MPT_LAST_PROJECT, project->filename);
+ /* Pour la prochaine ouverture du programme... */
+
+ set_string_config_value(get_main_configuration(), MPT_LAST_PROJECT, project->filename);
+
}