summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/analysis/binary.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-08-03 13:03:26 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-08-03 13:03:26 (GMT)
commitb7c83221f2a60be8ee5d44a7599dbe6869af005f (patch)
tree814e294533920d18f8734baa9aaef47c676e520a /plugins/pychrysa/analysis/binary.c
parent7d2b7ca95966c2d687526cd75a96d1ea67d3f503 (diff)
Loaded the permissions used by an APK file.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@255 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/analysis/binary.c')
-rw-r--r--plugins/pychrysa/analysis/binary.c211
1 files changed, 65 insertions, 146 deletions
diff --git a/plugins/pychrysa/analysis/binary.c b/plugins/pychrysa/analysis/binary.c
index d378496..4cfb615 100644
--- a/plugins/pychrysa/analysis/binary.c
+++ b/plugins/pychrysa/analysis/binary.c
@@ -25,41 +25,18 @@
#include "binary.h"
-#include "line.h"
-#include "../format/executable.h"
+#include <pygobject.h>
-
-
-/* Classe 'analysis.binary' pour Python */
-typedef struct _py_binary
-{
- PyObject_HEAD
-
- GOpenidaBinary *binary; /* Référence GLib */
-
-} py_binary;
-
-
-
-
-/* Crée un nouvel objet Python de type 'py_binary'. */
-static PyObject *py_binary_new(PyTypeObject *, PyObject *, PyObject *);
-
+#include "../quirks.h"
-/* Fournit le format de fichier reconnu dans le contenu binaire. */
-static PyObject *py_binary_get_format(py_binary *);
-
-/* Fournit les lignes de rendu associé pour Python. */
-static PyObject *py_binary_get_lines(py_binary *);
-
-
-
-/* Fournit le type d'objet 'analysis.binary' pour Python. */
-static PyTypeObject *get_analysis_binary_type(void);
+/* Crée un nouvel objet Python de type 'LoadedBinary'. */
+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);
@@ -69,19 +46,28 @@ static PyTypeObject *get_analysis_binary_type(void);
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'py_binary'. *
+* Description : Crée un nouvel objet Python de type 'LoadedBinary'. *
* *
-* Retour : - *
+* Retour : Instance Python mise en place. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static PyObject *py_loaded_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- py_binary *result; /* Instance à retourner */
+ PyObject *result; /* Instance à retourner */
+ char *filename; /* Nom du fichier à charger */
+ int ret; /* Bilan de lecture des args. */
+ GOpenidaBinary *binary; /* Version GLib du format */
- result = (py_binary *)type->tp_alloc(type, 0);
+ ret = PyArg_ParseTuple(args, "s", &filename);
+ if (!ret) return Py_None;
+
+ binary = g_openida_binary_new_from_file(filename);
+
+ result = py_loaded_binary_from_c(binary);
+ g_object_unref(binary);
return (PyObject *)result;
@@ -90,38 +76,28 @@ static PyObject *py_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwd
/******************************************************************************
* *
-* Paramètres : binary = objet GLib existant à transposer. *
+* Paramètres : binary = instance existante GLib. *
* *
-* Description : Crée un nouvel objet Python de type 'py_binary'. *
+* Description : Crée un nouvel objet Python de type 'LoadedBinary'. *
* *
-* Retour : - *
+* Retour : Instance Python mise en place. *
* *
* Remarques : - *
* *
******************************************************************************/
-PyObject *py_binary_new_from_existing(GOpenidaBinary *binary)
+PyObject *py_loaded_binary_from_c(GOpenidaBinary *binary)
{
- py_binary *result; /* Instance à retourner */
- PyTypeObject *type; /* Type Python à instancier */
-
- result = (py_binary *)g_object_get_data(G_OBJECT(binary), "python_object");
-
- if (result == NULL)
- {
- type = get_analysis_binary_type();
+ PyObject *module; /* Module d'appartenance */
+ PyTypeObject *type; /* Type Python correspondant */
- result = (py_binary *)type->tp_alloc(type, 0);
+ module = PyImport_ImportModule("pychrysalide.analysis");
+ type = (PyTypeObject*)PyObject_GetAttrString(module, "LoadedBinary");
+ Py_DECREF(module);
- result->binary = binary;
- g_object_ref(binary);
+ pychrysalide_set_instance_data(G_OBJECT(binary), type);
- g_object_set_data(G_OBJECT(binary), "python_object", result);
-
- }
- else Py_INCREF((PyObject *)result);
-
- return (PyObject *)result;
+ return pygobject_new(G_OBJECT(binary));
}
@@ -129,52 +105,32 @@ PyObject *py_binary_new_from_existing(GOpenidaBinary *binary)
-/******************************************************************************
-* *
-* Paramètres : self = instance manipulée à traiter. *
-* *
-* Description : Fournit le format de fichier reconnu dans le contenu binaire.*
-* *
-* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_binary_get_format(py_binary *self)
-{
- PyObject *result; /* Liste à retourner */
- GExeFormat *format; /* Format récupéré à convertir */
-
- format = g_openida_binary_get_format(self->binary);
-
- result = py_executable_convert(format);
-
- return result;
-
-}
/******************************************************************************
* *
-* Paramètres : self = instance manipulée à traiter. *
+* Paramètres : self = classe représentant un débogueur. *
+* args = arguments fournis à l'appel. *
* *
-* Description : Fournit les lignes de rendu associé pour Python. *
+* Description : Fournit le fichier correspondant à l'élément binaire. *
* *
-* Retour : Nouvelle instance d'objet Python ou NULL en cas d'échec. *
+* Retour : Nom de fichier avec chemin absolu. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_get_lines(py_binary *self)
+static PyObject *py_loaded_binary_get_filename(PyObject *self, PyObject *args)
{
- PyObject *result; /* Liste à retourner */
- GRenderingLine *lines; /* Liste récupérée à convertir */
+ PyObject *result; /* Trouvailles à retourner */
+ GOpenidaBinary *binary; /* Version native */
+ const char *filename; /* Fichier associé au binaire */
+
+ binary = G_OPENIDA_BINARY(pygobject_get(self));
- lines = g_openida_binary_get_lines(self->binary);
+ filename = g_openida_binary_get_filename(binary);
- result = py_line_new_from_existing(lines);
+ result = PyString_FromString(filename);
return result;
@@ -183,96 +139,59 @@ static PyObject *py_binary_get_lines(py_binary *self)
-
-
-
-
-
-
-
-
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : module = module dont la définition est à compléter. *
* *
-* Description : Fournit le type d'objet 'analysis.binary' pour Python. *
+* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.*
* *
-* Retour : Adresse du type vivant à manipuler. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyTypeObject *get_analysis_binary_type(void)
+bool register_python_loaded_binary(PyObject *module)
{
- static PyTypeObject *result = NULL; /* Type pour objet à retourner */
+ PyObject *pygobj_mod; /* Module Python-GObject */
+ int ret; /* Bilan d'un appel */
- static PyMethodDef py_binary_methods[] = {
+ static PyMethodDef py_loaded_binary_methods[] = {
{
- "get_format", (PyCFunction)py_binary_get_format,
+ "get_filename", (PyCFunction)py_loaded_binary_get_filename,
METH_NOARGS,
- "Give the file format recognized in the binary content."
+ "Provide the filename of the loaded binary."
},
- {
- "get_lines", (PyCFunction)py_binary_get_lines,
- METH_NOARGS,
- "Provide the rendering lines used by the binary."
- },
- { NULL }
- };
-
- static PyGetSetDef py_binary_getset[] = {
{ NULL }
};
- static PyTypeObject py_binary_type = {
+ static PyTypeObject py_loaded_binary_type = {
PyObject_HEAD_INIT(NULL)
- .tp_name = "pyoida.analysis.Binary",
- .tp_basicsize = sizeof(py_binary),
+ .tp_name = "pychrysalide.analysis.LoadedBinary",
+ .tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = "PyOIDA loaded binary to analyse",
+ .tp_doc = "PyChrysalide loaded binary",
- .tp_methods = py_binary_methods,
- .tp_getset = py_binary_getset,
- .tp_new = (newfunc)py_binary_new
+ .tp_methods = py_loaded_binary_methods,
+ .tp_new = (newfunc)py_loaded_binary_new
};
- if (result == NULL) result = &py_binary_type;
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : module = module dont la définition est à compléter. *
-* *
-* Description : Ajoute l'objet 'analysis.binary' au module Python. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool add_analysis_binary_to_python_module(PyObject *module)
-{
- PyTypeObject *py_binary_type; /* Type défini pour Python */
- int ret; /* Bilan d'un appel */
+ pygobj_mod = PyImport_ImportModule("gobject");
+ if (pygobj_mod == NULL) return false;
- py_binary_type = get_analysis_binary_type();
+ py_loaded_binary_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
+ Py_DECREF(pygobj_mod);
- if (PyType_Ready(py_binary_type) < 0)
+ if (PyType_Ready(&py_loaded_binary_type) < 0)
return false;
- Py_INCREF(py_binary_type);
- ret = PyModule_AddObject(module, "Binary", (PyObject *)py_binary_type);
+ Py_INCREF(&py_loaded_binary_type);
+ ret = PyModule_AddObject(module, "LoadedBinary", (PyObject *)&py_loaded_binary_type);
return (ret == 0);