summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-01-16 18:42:29 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-01-16 18:42:29 (GMT)
commiteb9b7fd76451db5c9f07a800c0394480e4b88c9c (patch)
tree0ed8261cffd4a40f4f7924f4dc12cc37c00bf554 /plugins
parent23b9c6e68bbe5f0531f9a9408c2deb9f897701dc (diff)
Improved the removal of format symbols.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/pychrysa/format/format.c104
-rw-r--r--plugins/pychrysa/format/symbol.c2
2 files changed, 101 insertions, 5 deletions
diff --git a/plugins/pychrysa/format/format.c b/plugins/pychrysa/format/format.c
index 5920b27..3bfc705 100644
--- a/plugins/pychrysa/format/format.c
+++ b/plugins/pychrysa/format/format.c
@@ -31,6 +31,7 @@
#include <format/format.h>
+#include "symbol.h"
#include "symiter.h"
#include "../helpers.h"
#include "../arch/vmpa.h"
@@ -40,6 +41,13 @@
/* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */
+
+/* Ajoute un symbole à la collection du format binaire. */
+static PyObject *py_binary_format_add_symbol(PyObject *, PyObject *);
+
+/* Retire un symbole de la collection du format binaire. */
+static PyObject *py_binary_format_remove_symbol(PyObject *, PyObject *);
+
/* Recherche le symbole correspondant à une étiquette. */
static PyObject *py_binary_format_find_symbol_by_label(PyObject *, PyObject *);
@@ -84,6 +92,84 @@ static bool define_python_binary_format_constants(PyTypeObject *);
/* ---------------------------------------------------------------------------------- */
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un format. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Ajoute un symbole à la collection du format binaire. *
+* *
+* Retour : True si le symbole était bien localisé et a été inséré. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Valeur à retourner */
+ PyObject *symbol_obj; /* Version Python d'un symbole */
+ 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);
+ if (!ret) return NULL;
+
+ format = G_BIN_FORMAT(pygobject_get(self));
+ symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj));
+
+ added = g_binary_format_add_symbol(format, symbol);
+
+ result = added ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = classe représentant un format. *
+* args = arguments fournis à l'appel. *
+* *
+* Description : Retire un symbole de la collection du format binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Valeur à retourner */
+ PyObject *symbol_obj; /* Version Python d'un symbole */
+ 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);
+ 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);
+
+ result = Py_None;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : self = classe représentant un binaire. *
@@ -104,7 +190,7 @@ static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject
int ret; /* Bilan de lecture des args. */
GBinFormat *format; /* Format de binaire manipulé */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
- bool found;
+ bool found; /* Bilan de la recherche */
ret = PyArg_ParseTuple(args, "O", &label);
if (!ret) return NULL;
@@ -149,7 +235,7 @@ static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args)
int ret; /* Bilan de lecture des args. */
GBinFormat *format; /* Format de binaire manipulé */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
- bool found;
+ bool found; /* Bilan de la recherche */
ret = PyArg_ParseTuple(args, "O", &py_vmpa);
if (!ret) return NULL;
@@ -197,7 +283,7 @@ static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject *
int ret; /* Bilan de lecture des args. */
GBinFormat *format; /* Format de binaire manipulé */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
- bool found;
+ bool found; /* Bilan de la recherche */
ret = PyArg_ParseTuple(args, "O", &py_vmpa);
if (!ret) return NULL;
@@ -247,7 +333,7 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args)
GBinFormat *format; /* Format de binaire manipulé */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
phys_t diff; /* Décallage éventuel mesuré */
- bool found;
+ bool found; /* Bilan de la recherche */
ret = PyArg_ParseTuple(args, "Op", &py_vmpa, &strict);
if (!ret) return NULL;
@@ -486,6 +572,16 @@ PyTypeObject *get_python_binary_format_type(void)
{
static PyMethodDef py_bin_format_methods[] = {
{
+ "add_symbol", py_binary_format_add_symbol,
+ METH_VARARGS,
+ "add_symbol($self, symbol, /)\n--\n\nRegister a new symbol for the format."
+ },
+ {
+ "remove_symbol", py_binary_format_remove_symbol,
+ METH_VARARGS,
+ "remove_symbol($self, symbol, /)\n--\n\nUnregister a symbol from the format."
+ },
+ {
"find_symbol_by_label", py_binary_format_find_symbol_by_label,
METH_VARARGS,
"find_symbol_by_label($self, label, /)\n--\n\nFind a symbol by its label."
diff --git a/plugins/pychrysa/format/symbol.c b/plugins/pychrysa/format/symbol.c
index 736a8d2..5ddaca2 100644
--- a/plugins/pychrysa/format/symbol.c
+++ b/plugins/pychrysa/format/symbol.c
@@ -138,7 +138,7 @@ static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObje
if (stype >= STP_COUNT)
{
- PyErr_SetString(PyExc_ValueError, _("Invalid type of message"));
+ PyErr_SetString(PyExc_ValueError, _("Invalid type of symbol."));
return NULL;
}