diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/pychrysalide/format/constants.c | 14 | ||||
-rw-r--r-- | plugins/pychrysalide/format/symbol.c | 198 |
2 files changed, 212 insertions, 0 deletions
diff --git a/plugins/pychrysalide/format/constants.c b/plugins/pychrysalide/format/constants.c index 4ffdc5f..dfa4615 100644 --- a/plugins/pychrysalide/format/constants.c +++ b/plugins/pychrysalide/format/constants.c @@ -85,6 +85,20 @@ bool define_binary_symbol_constants(PyTypeObject *type) result = attach_constants_group_to_type(type, false, "SymbolStatus", values, "Status of a symbol visibility."); + values = PyDict_New(); + + result = add_const_to_group(values, "NONE", SFL_NONE); + if (result) result = add_const_to_group(values, "PREFIXED_NAME", SFL_PREFIXED_NAME); + + if (!result) + { + Py_DECREF(values); + goto exit; + } + + result = attach_constants_group_to_type(type, true, "SymbolFlag", values, + "Extra indications for symbols."); + exit: return result; diff --git a/plugins/pychrysalide/format/symbol.c b/plugins/pychrysalide/format/symbol.c index c67d6e7..75eb8f4 100644 --- a/plugins/pychrysalide/format/symbol.c +++ b/plugins/pychrysalide/format/symbol.c @@ -72,6 +72,15 @@ static int py_binary_symbol_init(PyObject *, PyObject *, PyObject *); /* Effectue une comparaison avec un objet Python 'BinSymbol'. */ static PyObject *py_binary_symbol_richcompare(PyObject *, PyObject *, int); +/* Ajoute une information complémentaire à un symbole. */ +static PyObject *py_binary_symbol_set_flag(PyObject *, PyObject *); + +/* Retire une information complémentaire à un symbole. */ +static PyObject *py_binary_symbol_unset_flag(PyObject *, PyObject *); + +/* Détermine si un symbole possède un fanion particulier. */ +static PyObject *py_binary_symbol_has_flag(PyObject *, PyObject *); + /* Fournit l'emplacement où se situe un symbole. */ static PyObject *py_binary_symbol_get_range(PyObject *, void *); @@ -93,6 +102,9 @@ static PyObject *py_binary_symbol_get_status(PyObject *, void *); /* Définit la visibilité du symbole. */ static int py_binary_symbol_set_status(PyObject *, PyObject *, void *); +/* Fournit les particularités du symbole. */ +static PyObject *py_binary_symbol_get_flags(PyObject *, void *); + /* Définit un autre nom pour le symbole. */ static int py_binary_symbol_set_label(PyObject *, PyObject *, void *); @@ -343,6 +355,152 @@ static PyObject *py_binary_symbol_richcompare(PyObject *a, PyObject *b, int op) /****************************************************************************** * * +* Paramètres : self = serveur à manipuler. * +* args = arguments d'appel non utilisés ici. * +* * +* Description : Ajoute une information complémentaire à un symbole. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_set_flag(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + unsigned int flag; /* Propriété à traiter */ + int ret; /* Bilan de lecture des args. */ + GBinSymbol *symbol; /* Elément à manipuler */ + bool status; /* Bilan de l'opération */ + +#define BINARY_SYMBOL_SET_FLAG_METHOD PYTHON_METHOD_DEF \ +( \ + set_flag, "$self, flag, /", \ + METH_VARARGS, py_binary_symbol, \ + "Add a property from a binary symbol.\n" \ + "\n" \ + "This property is one of the values listed in the" \ + " of pychrysalide.format.BinSymbol.SymbolFlag enumeration.\n" \ + "\n" \ + "If the flag was not set before the operation, True is" \ + " returned, else the result is False." \ +) + + ret = PyArg_ParseTuple(args, "I", &flag); + if (!ret) return NULL; + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + + status = g_binary_symbol_set_flag(symbol, flag); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = serveur à manipuler. * +* args = arguments d'appel non utilisés ici. * +* * +* Description : Retire une information complémentaire à un symbole. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_unset_flag(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + unsigned int flag; /* Propriété à traiter */ + int ret; /* Bilan de lecture des args. */ + GBinSymbol *symbol; /* Elément à manipuler */ + bool status; /* Bilan de l'opération */ + +#define BINARY_SYMBOL_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \ +( \ + unset_flag, "$self, flag, /", \ + METH_VARARGS, py_binary_symbol, \ + "Remove a property from a binary symbol.\n" \ + "\n" \ + "This property is one of the values listed in the" \ + " of pychrysalide.format.BinSymbol.SymbolFlag enumeration.\n" \ + "\n" \ + "If the flag was not set before the operation, False is" \ + " returned, else the result is True." \ +) + + ret = PyArg_ParseTuple(args, "I", &flag); + if (!ret) return NULL; + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + + status = g_binary_symbol_unset_flag(symbol, flag); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = serveur à manipuler. * +* args = arguments d'appel non utilisés ici. * +* * +* Description : Détermine si un symbole possède un fanion particulier. * +* * +* Retour : Bilan de la détection. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_has_flag(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + unsigned int flag; /* Propriété à traiter */ + int ret; /* Bilan de lecture des args. */ + GBinSymbol *symbol; /* Elément à manipuler */ + bool status; /* Bilan de l'opération */ + +#define BINARY_SYMBOL_HAS_FLAG_METHOD PYTHON_METHOD_DEF \ +( \ + has_flag, "$self, flag, /", \ + METH_VARARGS, py_binary_symbol, \ + "Test if a binary symbol has a given property.\n" \ + "\n" \ + "This property is one of the values listed in the" \ + " of pychrysalide.format.BinSymbol.SymbolFlag enumeration.\n" \ + "\n" \ + "The result is a boolean value." \ +) + + ret = PyArg_ParseTuple(args, "I", &flag); + if (!ret) return NULL; + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + + status = g_binary_symbol_has_flag(symbol, flag); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * @@ -553,6 +711,42 @@ static int py_binary_symbol_set_status(PyObject *self, PyObject *value, void *cl * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * +* Description : Fournit les particularités du symbole. * +* * +* Retour : Somme de tous les fanions associés au symbole. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_get_flags(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBinSymbol *symbol; /* Elément à consulter */ + SymbolFlag flags; /* Indications complémentaires */ + +#define BINARY_SYMBOL_FLAGS_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + flags, py_binary_symbol, \ + "Provide all the flags set for a symbol. The return value" \ + " is of type pychrysalide.format.BinSymbol.SymbolFlag." \ +) + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + flags = g_binary_symbol_get_flags(symbol); + + result = cast_with_constants_group_from_type(get_python_binary_symbol_type(), "SymbolFlag", flags); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * * Description : Fournit un étiquette pour viser un symbole. * * * * Retour : Chaîne de caractères renvoyant au symbole. * @@ -647,6 +841,9 @@ static int py_binary_symbol_set_label(PyObject *self, PyObject *value, void *clo PyTypeObject *get_python_binary_symbol_type(void) { static PyMethodDef binary_symbol_methods[] = { + BINARY_SYMBOL_SET_FLAG_METHOD, + BINARY_SYMBOL_UNSET_FLAG_METHOD, + BINARY_SYMBOL_HAS_FLAG_METHOD, { NULL } }; @@ -654,6 +851,7 @@ PyTypeObject *get_python_binary_symbol_type(void) BINARY_SYMBOL_RANGE_ATTRIB, BINARY_SYMBOL_STYPE_ATTRIB, BINARY_SYMBOL_STATUS_ATTRIB, + BINARY_SYMBOL_FLAGS_ATTRIB, BINARY_SYMBOL_LABEL_ATTRIB, { NULL } }; |