summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r--plugins/pychrysalide/format/flat.c7
-rw-r--r--plugins/pychrysalide/format/format.c12
-rw-r--r--plugins/pychrysalide/format/symbol.c46
-rw-r--r--plugins/pychrysalide/format/symbol.h3
4 files changed, 55 insertions, 13 deletions
diff --git a/plugins/pychrysalide/format/flat.c b/plugins/pychrysalide/format/flat.c
index 3f32832..ce93493 100644
--- a/plugins/pychrysalide/format/flat.c
+++ b/plugins/pychrysalide/format/flat.c
@@ -63,16 +63,13 @@ static PyObject *py_flat_format_set_target_machine(PyObject *, PyObject *);
static PyObject *py_flat_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Instance à retourner */
- PyObject *content_obj; /* Objet pour le contenu */
- int ret; /* Bilan de lecture des args. */
GBinContent *content; /* Instance GLib du contenu */
+ int ret; /* Bilan de lecture des args. */
GExeFormat *format; /* Création GLib à transmettre */
- ret = PyArg_ParseTuple(args, "O!", get_python_binary_content_type(), &content_obj);
+ ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content);
if (!ret) return NULL;
- content = G_BIN_CONTENT(pygobject_get(content_obj));
-
format = g_flat_format_new(content);
if (format == NULL)
diff --git a/plugins/pychrysalide/format/format.c b/plugins/pychrysalide/format/format.c
index 82cb575..1dc4edd 100644
--- a/plugins/pychrysalide/format/format.c
+++ b/plugins/pychrysalide/format/format.c
@@ -150,17 +150,15 @@ static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject *
static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
- PyObject *symbol_obj; /* Version Python d'un symbole */
+ GBinSymbol *symbol; /* Enventuel symbole trouvé */
int ret; /* Bilan de lecture des args. */
GBinFormat *format; /* Format de binaire manipulé */
- GBinSymbol *symbol; /* Enventuel symbole trouvé */
bool added; /* Bilan de l'appel interne */
- ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj);
+ ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol);
if (!ret) return NULL;
format = G_BIN_FORMAT(pygobject_get(self));
- symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj));
g_object_ref(G_OBJECT(symbol));
added = g_binary_format_add_symbol(format, symbol);
@@ -189,16 +187,14 @@ static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args)
static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
- PyObject *symbol_obj; /* Version Python d'un symbole */
+ GBinSymbol *symbol; /* Enventuel symbole trouvé */
int ret; /* Bilan de lecture des args. */
GBinFormat *format; /* Format de binaire manipulé */
- GBinSymbol *symbol; /* Enventuel symbole trouvé */
- ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj);
+ ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol);
if (!ret) return NULL;
format = G_BIN_FORMAT(pygobject_get(self));
- symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj));
g_binary_format_remove_symbol(format, symbol);
diff --git a/plugins/pychrysalide/format/symbol.c b/plugins/pychrysalide/format/symbol.c
index bb58f64..3295e8c 100644
--- a/plugins/pychrysalide/format/symbol.c
+++ b/plugins/pychrysalide/format/symbol.c
@@ -25,6 +25,7 @@
#include "symbol.h"
+#include <assert.h>
#include <malloc.h>
#include <pygobject.h>
@@ -502,3 +503,48 @@ bool ensure_python_binary_symbol_is_registered(void)
return true;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en symbole binaire. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_binary_symbol(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_binary_symbol_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to binary symbol");
+ break;
+
+ case 1:
+ *((GBinSymbol **)dst) = G_BIN_SYMBOL(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/format/symbol.h b/plugins/pychrysalide/format/symbol.h
index a9161c6..2e3b013 100644
--- a/plugins/pychrysalide/format/symbol.h
+++ b/plugins/pychrysalide/format/symbol.h
@@ -37,6 +37,9 @@ PyTypeObject *get_python_binary_symbol_type(void);
/* Prend en charge l'objet 'pychrysalide.format.BinSymbol'. */
bool ensure_python_binary_symbol_is_registered(void);
+/* Tente de convertir en symbole binaire. */
+int convert_to_binary_symbol(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_SYMBOL_H */