summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-04-12 22:25:43 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-04-12 22:25:43 (GMT)
commit8d4c5ae6dfd812b753109a25d7e84f7e524d4bf0 (patch)
treeb437de37b5447daa02263901aca4ef7a7d2d0386
parentb4cbeedf6ed4e04dd85c92e8345b4cb8dcaab27d (diff)
Improved support of type prefix for symbols.
-rw-r--r--plugins/pychrysalide/format/constants.c3
-rw-r--r--plugins/pychrysalide/format/symbol.c55
-rw-r--r--src/format/symbol-int.h3
-rw-r--r--src/format/symbol.c64
-rw-r--r--src/format/symbol.h10
-rw-r--r--tests/format/symbol.py8
6 files changed, 132 insertions, 11 deletions
diff --git a/plugins/pychrysalide/format/constants.c b/plugins/pychrysalide/format/constants.c
index dfa4615..a0d71f7 100644
--- a/plugins/pychrysalide/format/constants.c
+++ b/plugins/pychrysalide/format/constants.c
@@ -88,7 +88,8 @@ bool define_binary_symbol_constants(PyTypeObject *type)
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) result = add_const_to_group(values, "HAS_NM_PREFIX", SFL_HAS_NM_PREFIX);
+ if (result) result = add_const_to_group(values, "MASK", SFL_MASK);
if (!result)
{
diff --git a/plugins/pychrysalide/format/symbol.c b/plugins/pychrysalide/format/symbol.c
index 75eb8f4..6f1c1d2 100644
--- a/plugins/pychrysalide/format/symbol.c
+++ b/plugins/pychrysalide/format/symbol.c
@@ -93,9 +93,6 @@ static PyObject *py_binary_symbol_get_stype(PyObject *, void *);
/* Définit le type du symbole. */
static int py_binary_symbol_set_stype(PyObject *, PyObject *, void *);
-/* Fournit un étiquette pour viser un symbole. */
-static PyObject *py_binary_symbol_get_label(PyObject *, void *);
-
/* Fournit la visibilité du symbole. */
static PyObject *py_binary_symbol_get_status(PyObject *, void *);
@@ -105,6 +102,12 @@ 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 *);
+/* Fournit le préfixe compatible avec une sortie "nm". */
+static PyObject *py_binary_symbol_get_nm_prefix(PyObject *, void *);
+
+/* Fournit un étiquette pour viser un symbole. */
+static PyObject *py_binary_symbol_get_label(PyObject *, void *);
+
/* Définit un autre nom pour le symbole. */
static int py_binary_symbol_set_label(PyObject *, PyObject *, void *);
@@ -747,6 +750,51 @@ static PyObject *py_binary_symbol_get_flags(PyObject *self, void *closure)
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
+* Description : Fournit le préfixe compatible avec une sortie "nm". *
+* *
+* Retour : Caractère éventuel ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_symbol_get_nm_prefix(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GBinSymbol *symbol; /* Elément à consulter */
+ char prefix[2]; /* Eventuel préfixe "nm" */
+ bool status; /* Validité de ce préfixe */
+
+#define BINARY_SYMBOL_NM_PREFIX_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ nm_prefix, py_binary_symbol, \
+ "Single-byte string for an optional *nm* prefix, or None if any." \
+)
+
+ symbol = G_BIN_SYMBOL(pygobject_get(self));
+ status = g_binary_symbol_get_nm_prefix(symbol, &prefix[0]);
+
+ if (status)
+ {
+ prefix[1] = '\0';
+ result = PyUnicode_FromString(prefix);
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ 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. *
@@ -852,6 +900,7 @@ PyTypeObject *get_python_binary_symbol_type(void)
BINARY_SYMBOL_STYPE_ATTRIB,
BINARY_SYMBOL_STATUS_ATTRIB,
BINARY_SYMBOL_FLAGS_ATTRIB,
+ BINARY_SYMBOL_NM_PREFIX_ATTRIB,
BINARY_SYMBOL_LABEL_ATTRIB,
{ NULL }
};
diff --git a/src/format/symbol-int.h b/src/format/symbol-int.h
index 77ffd39..5e77a4d 100644
--- a/src/format/symbol-int.h
+++ b/src/format/symbol-int.h
@@ -41,6 +41,9 @@ typedef union _sym_obj_extra
{
SymbolType stype; /* Type du symbole */
SymbolStatus status; /* Visibilité du symbole */
+
+ char nm_prefix; /* Eventuel préfixe "nm" */
+
SymbolFlag flags; /* Informations complémentaires*/
};
diff --git a/src/format/symbol.c b/src/format/symbol.c
index 7d272ce..abf284e 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -549,7 +549,7 @@ SymbolFlag g_binary_symbol_get_flags(const GBinSymbol *symbol)
g_bit_lock(&extra->lock, HOLE_LOCK_BIT);
- result = extra->flags;
+ result = (extra->flags & SFL_MASK);
g_bit_unlock(&extra->lock, HOLE_LOCK_BIT);
@@ -561,6 +561,68 @@ SymbolFlag g_binary_symbol_get_flags(const GBinSymbol *symbol)
/******************************************************************************
* *
* Paramètres : symbol = symbole à venir consulter. *
+* prefix = éventuel préfixe à constituer. [OUT] *
+* *
+* Description : Fournit le préfixe compatible avec une sortie "nm". *
+* *
+* Retour : true si un préfixe "nm" est renseigné. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_symbol_get_nm_prefix(const GBinSymbol *symbol, char *prefix)
+{
+ bool result; /* Validité à retourner */
+ sym_obj_extra *extra; /* Données insérées à modifier */
+
+ extra = GET_BIN_SYMBOL_EXTRA(symbol);
+
+ g_bit_lock(&extra->lock, HOLE_LOCK_BIT);
+
+ result = (extra->flags & SFL_HAS_NM_PREFIX);
+
+ if (result)
+ *prefix = extra->nm_prefix;
+
+ g_bit_unlock(&extra->lock, HOLE_LOCK_BIT);
+
+ return result;
+
+}
+
+/******************************************************************************
+* *
+* Paramètres : symbol = symbole à venir consulter. *
+* prefix = préfixe "nm" à associer au symbole. *
+* *
+* Description : Définit le préfixe compatible avec une sortie "nm". *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_binary_symbol_set_nm_prefix(const GBinSymbol *symbol, char prefix)
+{
+ sym_obj_extra *extra; /* Données insérées à modifier */
+
+ extra = GET_BIN_SYMBOL_EXTRA(symbol);
+
+ g_bit_lock(&extra->lock, HOLE_LOCK_BIT);
+
+ extra->nm_prefix = prefix;
+ extra->flags |= SFL_HAS_NM_PREFIX;
+
+ g_bit_unlock(&extra->lock, HOLE_LOCK_BIT);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : symbol = symbole à venir consulter. *
* *
* Description : Fournit une étiquette pour viser un symbole. *
* *
diff --git a/src/format/symbol.h b/src/format/symbol.h
index e304d69..577eb83 100644
--- a/src/format/symbol.h
+++ b/src/format/symbol.h
@@ -66,9 +66,9 @@ typedef enum _SymbolStatus
typedef enum _SymbolFlag
{
SFL_NONE = (0 << 0), /* Aucune propriété */
- SFL_PREFIXED_NAME = (1 << 0), /* Indication en amont du nom */
+ SFL_HAS_NM_PREFIX = (1 << 0), /* Indication de nature */
- SFL_COUNT
+ SFL_MASK = (1 << 1) - 1, /* Indication de nature */
} SymbolFlag;
@@ -130,6 +130,12 @@ bool g_binary_symbol_has_flag(const GBinSymbol *, SymbolFlag);
/* Fournit les particularités du symbole. */
SymbolFlag g_binary_symbol_get_flags(const GBinSymbol *);
+/* Fournit le préfixe compatible avec une sortie "nm". */
+bool g_binary_symbol_get_nm_prefix(const GBinSymbol *, char *);
+
+/* Définit le préfixe compatible avec une sortie "nm". */
+void g_binary_symbol_set_nm_prefix(const GBinSymbol *, char);
+
/* Fournit une étiquette pour viser un symbole. */
char *g_binary_symbol_get_label(const GBinSymbol *);
diff --git a/tests/format/symbol.py b/tests/format/symbol.py
index fed4133..0b5f0a1 100644
--- a/tests/format/symbol.py
+++ b/tests/format/symbol.py
@@ -80,16 +80,16 @@ class TestBinarySymbols(ChrysalideTestCase):
ret = symbol.unset_flag(BinSymbol.SymbolFlag.NONE)
self.assertFalse(ret)
- ret = symbol.set_flag(BinSymbol.SymbolFlag.PREFIXED_NAME)
+ ret = symbol.set_flag(BinSymbol.SymbolFlag.HAS_NM_PREFIX)
self.assertTrue(ret)
- ret = symbol.has_flag(BinSymbol.SymbolFlag.PREFIXED_NAME)
+ ret = symbol.has_flag(BinSymbol.SymbolFlag.HAS_NM_PREFIX)
self.assertTrue(ret)
- ret = symbol.unset_flag(BinSymbol.SymbolFlag.PREFIXED_NAME)
+ ret = symbol.unset_flag(BinSymbol.SymbolFlag.HAS_NM_PREFIX)
self.assertTrue(ret)
- ret = symbol.has_flag(BinSymbol.SymbolFlag.PREFIXED_NAME)
+ ret = symbol.has_flag(BinSymbol.SymbolFlag.HAS_NM_PREFIX)
self.assertFalse(ret)