summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/format
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/format')
-rw-r--r--plugins/pychrysa/format/dex/class.c34
-rw-r--r--plugins/pychrysa/format/dex/class.h5
-rw-r--r--plugins/pychrysa/format/dex/dex.c50
-rw-r--r--plugins/pychrysa/format/dex/dex.h5
-rw-r--r--plugins/pychrysa/format/executable.c2
-rw-r--r--plugins/pychrysa/format/format.c65
-rw-r--r--plugins/pychrysa/format/format.h5
-rw-r--r--plugins/pychrysa/format/module.c2
8 files changed, 66 insertions, 102 deletions
diff --git a/plugins/pychrysa/format/dex/class.c b/plugins/pychrysa/format/dex/class.c
index 97c1968..bc07fae 100644
--- a/plugins/pychrysa/format/dex/class.c
+++ b/plugins/pychrysa/format/dex/class.c
@@ -28,6 +28,9 @@
#include <pygobject.h>
+#include <format/dex/class.h>
+
+
#include "../../quirks.h"
@@ -53,37 +56,11 @@ static PyObject *py_dex_class_new(PyTypeObject *, PyObject *, PyObject *);
static PyObject *py_dex_class_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- return Py_None;
+ Py_RETURN_NONE;
}
-/******************************************************************************
-* *
-* Paramètres : item = instance existante GLib. *
-* *
-* Description : Crée un nouvel objet Python de type 'DexClass'. *
-* *
-* Retour : Instance Python mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyObject *py_dex_class_from_c(GDexClass *class)
-{
- PyObject *module; /* Module d'appartenance */
- PyTypeObject *type; /* Type Python correspondant */
-
- module = PyImport_ImportModule("pychrysalide.format.dex");
- type = (PyTypeObject *)PyObject_GetAttrString(module, "DexClass");
- Py_DECREF(module);
-
- pychrysalide_set_instance_data(G_OBJECT(class), type);
-
- return pygobject_new(G_OBJECT(class));
-
-}
@@ -152,6 +129,9 @@ bool register_python_dex_class(PyObject *module)
Py_INCREF(&py_dex_class_type);
ret = PyModule_AddObject(module, "DexClass", (PyObject *)&py_dex_class_type);
+ pygobject_register_class(module, "GDexClass", G_TYPE_DEX_CLASS, &py_dex_class_type,
+ Py_BuildValue("(O)", py_dex_class_type.tp_base));
+
return (ret == 0);
}
diff --git a/plugins/pychrysa/format/dex/class.h b/plugins/pychrysa/format/dex/class.h
index addf7ca..c2a8222 100644
--- a/plugins/pychrysa/format/dex/class.h
+++ b/plugins/pychrysa/format/dex/class.h
@@ -29,13 +29,8 @@
#include <Python.h>
#include <stdbool.h>
-#include <format/dex/class.h>
-
-/* Crée un nouvel objet Python de type 'DexClass'. */
-PyObject *py_dex_class_from_c(GDexClass *);
-
/* Prend en charge l'objet 'pychrysalide.format.dex.DexClass'. */
bool register_python_dex_class(PyObject *module);
diff --git a/plugins/pychrysa/format/dex/dex.c b/plugins/pychrysa/format/dex/dex.c
index 2df8d1b..cae87f7 100644
--- a/plugins/pychrysa/format/dex/dex.c
+++ b/plugins/pychrysa/format/dex/dex.c
@@ -27,6 +27,7 @@
#include <pygobject.h>
+
#include <format/dex/dex-int.h>
@@ -69,13 +70,13 @@ static PyObject *py_dex_format_new(PyTypeObject *type, PyObject *args, PyObject
GBinFormat *format; /* Version GLib du format */
ret = PyArg_ParseTuple(args, "s#", &content, &length);
- if (!ret) return Py_None;
+ if (!ret) Py_RETURN_NONE;
format = g_dex_format_new(content, length);
- if (format == NULL) return Py_None;
+ if (format == NULL) Py_RETURN_NONE;
- result = py_dex_format_from_c(G_DEX_FORMAT(format));
- g_object_unref(format);
+ result = pygobject_new(G_OBJECT(format));
+ //g_object_unref(format);
return (PyObject *)result;
@@ -84,34 +85,6 @@ static PyObject *py_dex_format_new(PyTypeObject *type, PyObject *args, PyObject
/******************************************************************************
* *
-* Paramètres : item = instance existante GLib. *
-* *
-* Description : Crée un nouvel objet Python de type 'DexFormat'. *
-* *
-* Retour : Instance Python mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyObject *py_dex_format_from_c(GDexFormat *format)
-{
- PyObject *module; /* Module d'appartenance */
- PyTypeObject *type; /* Type Python correspondant */
-
- module = PyImport_ImportModule("pychrysalide.format.dex");
- type = (PyTypeObject *)PyObject_GetAttrString(module, "DexFormat");
- Py_DECREF(module);
-
- pychrysalide_set_instance_data(G_OBJECT(format), type);
-
- return pygobject_new(G_OBJECT(format));
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = classe représentant un binaire. *
* args = arguments fournis à l'appel. *
* *
@@ -162,14 +135,14 @@ static PyObject *py_dex_format_get_class(PyObject *self, PyObject *args)
GDexClass *class; /* Classe à communiquer */
ret = PyArg_ParseTuple(args, "i", &index);
- if (!ret) return Py_None;
+ if (!ret) Py_RETURN_NONE;
format = G_DEX_FORMAT(pygobject_get(self));
class = g_dex_format_get_class(format, index);
- if (class == NULL) return Py_None;
+ if (class == NULL) Py_RETURN_NONE;
- result = py_dex_class_from_c(class);
+ result = pygobject_new(G_OBJECT(class));
return result;
@@ -233,10 +206,10 @@ bool register_python_dex_format(PyObject *module)
};
- pygobj_mod = PyImport_ImportModule("gobject");
+ pygobj_mod = PyImport_ImportModule("pychrysalide.format");
if (pygobj_mod == NULL) return false;
- py_dex_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
+ py_dex_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "BinFormat");
Py_DECREF(pygobj_mod);
if (PyType_Ready(&py_dex_format_type) < 0)
@@ -245,6 +218,9 @@ bool register_python_dex_format(PyObject *module)
Py_INCREF(&py_dex_format_type);
ret = PyModule_AddObject(module, "DexFormat", (PyObject *)&py_dex_format_type);
+ pygobject_register_class(module, "GDexFormat", G_TYPE_DEX_FORMAT, &py_dex_format_type,
+ Py_BuildValue("(O)", py_dex_format_type.tp_base));
+
return (ret == 0);
}
diff --git a/plugins/pychrysa/format/dex/dex.h b/plugins/pychrysa/format/dex/dex.h
index 65eec0d..dc97269 100644
--- a/plugins/pychrysa/format/dex/dex.h
+++ b/plugins/pychrysa/format/dex/dex.h
@@ -29,13 +29,8 @@
#include <Python.h>
#include <stdbool.h>
-#include <format/dex/dex.h>
-
-/* Crée un nouvel objet Python de type 'DexFormat'. */
-PyObject *py_dex_format_from_c(GDexFormat *);
-
/* Prend en charge l'objet 'pychrysalide.format.dex.DexFormat'. */
bool register_python_dex_format(PyObject *module);
diff --git a/plugins/pychrysa/format/executable.c b/plugins/pychrysa/format/executable.c
index 7cdc855..43375ea 100644
--- a/plugins/pychrysa/format/executable.c
+++ b/plugins/pychrysa/format/executable.c
@@ -48,7 +48,7 @@
PyObject *py_executable_format_from_c(GExeFormat *format)
{
- return py_binary_format_from_c(G_BIN_FORMAT(format));
+ return NULL;//py_binary_format_from_c(G_BIN_FORMAT(format));
}
diff --git a/plugins/pychrysa/format/format.c b/plugins/pychrysa/format/format.c
index ea556ba..4032da0 100644
--- a/plugins/pychrysa/format/format.c
+++ b/plugins/pychrysa/format/format.c
@@ -28,6 +28,9 @@
#include <pygobject.h>
+#include <format/format.h>
+
+
#include "dex/dex.h"
#include "../quirks.h"
@@ -36,6 +39,9 @@
/* Crée un nouvel objet Python de type 'BinFormat'. */
static PyObject *py_binary_format_new(PyTypeObject *, PyObject *, PyObject *);
+/* Recherche une position dans une routine selon une adresse. */
+static PyObject *py_binary_format_resolve_relative_routine(PyObject *, PyObject *);
+
/******************************************************************************
@@ -54,43 +60,53 @@ static PyObject *py_binary_format_new(PyTypeObject *, PyObject *, PyObject *);
static PyObject *py_binary_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- return Py_None;
+ Py_RETURN_NONE;
}
+
+
+
+
+
/******************************************************************************
* *
-* Paramètres : format = instance existante GLib. *
+* Paramètres : self = classe représentant un binaire. *
+* args = arguments fournis à l'appel. *
* *
-* Description : Crée un nouvel objet Python de type 'BinFormat'. *
+* Description : Recherche une position dans une routine selon une adresse. *
* *
-* Retour : Instance Python mise en place. *
+* Retour : Tuple (nom, décallage) ou Py_None. *
* *
* Remarques : - *
* *
******************************************************************************/
-PyObject *py_binary_format_from_c(GBinFormat *format)
+static PyObject *py_binary_format_resolve_relative_routine(PyObject *self, PyObject *args)
{
- PyObject *result; /* Conversion à retourner */
- GType type; /* Type réel du format */
+ PyObject *result; /* Tuple à retourner */
+ GBinFormat *format; /* Format à manipuler */
+ vmpa_t addr; /* Adresse demandée en visuel */
+ int ret; /* Bilan de lecture des args. */
+ bool found; /* Bilan de la résolution */
+ const char *label; /* Désignation de la trouvaille*/
- type = G_OBJECT_TYPE(G_OBJECT(format));
-
- if (type == G_TYPE_DEX_FORMAT)
- result = py_dex_format_from_c(G_DEX_FORMAT(format));
- else
- result = Py_None;
-
- return result;
-
-}
+ format = G_BIN_FORMAT(pygobject_get(self));
+ ret = PyArg_ParseTuple(args, "K", &addr);
+ if (!ret) Py_RETURN_NONE;
+ found = g_binary_format_resolve_relative_routine(format, &label, &addr);
+ if (!found) Py_RETURN_NONE;
+ result = PyTuple_New(2);
+ PyTuple_SetItem(result, 0, PyString_FromString(label));
+ PyTuple_SetItem(result, 1, PyLong_FromLongLong(addr));
+ return result;
+}
@@ -114,10 +130,15 @@ PyObject *py_binary_format_from_c(GBinFormat *format)
bool register_python_binary_format(PyObject *module)
{
- PyObject *pygobj_mod; /* Module Python-GObject */
+ PyObject *parent_mod; /* Module Python-GObject */
int ret; /* Bilan d'un appel */
static PyMethodDef py_binary_format_methods[] = {
+ {
+ "resolve_relative_routine", (PyCFunction)py_binary_format_resolve_relative_routine,
+ METH_VARARGS,
+ "Search a position inside a routine by a given address."
+ },
{ NULL }
};
@@ -142,11 +163,11 @@ bool register_python_binary_format(PyObject *module)
};
- pygobj_mod = PyImport_ImportModule("gobject");
- if (pygobj_mod == NULL) return false;
+ parent_mod = PyImport_ImportModule("gobject");
+ if (parent_mod == NULL) return false;
- py_binary_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
- Py_DECREF(pygobj_mod);
+ py_binary_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "GObject");
+ Py_DECREF(parent_mod);
if (PyType_Ready(&py_binary_format_type) < 0)
return false;
diff --git a/plugins/pychrysa/format/format.h b/plugins/pychrysa/format/format.h
index 8f38408..ede833e 100644
--- a/plugins/pychrysa/format/format.h
+++ b/plugins/pychrysa/format/format.h
@@ -29,13 +29,8 @@
#include <Python.h>
#include <stdbool.h>
-#include <format/format.h>
-
-/* Crée un nouvel objet Python de type 'BinFormat'. */
-PyObject *py_binary_format_from_c(GBinFormat *);
-
/* Prend en charge l'objet 'pychrysalide.format.BinFormat'. */
bool register_python_binary_format(PyObject *module);
diff --git a/plugins/pychrysa/format/module.c b/plugins/pychrysa/format/module.c
index d3e863f..8bf2ed2 100644
--- a/plugins/pychrysa/format/module.c
+++ b/plugins/pychrysa/format/module.c
@@ -26,6 +26,7 @@
#include "executable.h"
+#include "format.h"
#include "dex/module.h"
@@ -62,6 +63,7 @@ bool add_format_module_to_python_module(PyObject *super)
result = (ret != 0);
+ result &= register_python_binary_format(module);
result &= add_format_executable_to_python_module(module);
result &= add_format_dex_module_to_python_module(module);