summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-07-20 15:59:12 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-07-20 15:59:12 (GMT)
commitf0682e7b195acbd4d83148f3829479d682f9ee9f (patch)
tree39ec963de4b08dfde01cb621a48d14e01a365541 /plugins/pychrysalide/format
parent71db5a3a8a7a337ba63a47b6472baf99581d8400 (diff)
Marked some Dex strings as structural.
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r--plugins/pychrysalide/format/strsym.c125
1 files changed, 101 insertions, 24 deletions
diff --git a/plugins/pychrysalide/format/strsym.c b/plugins/pychrysalide/format/strsym.c
index 8c210a2..94edd24 100644
--- a/plugins/pychrysalide/format/strsym.c
+++ b/plugins/pychrysalide/format/strsym.c
@@ -42,15 +42,21 @@
+/* Indique si une chaîne de caractères est liée au format. */
+static PyObject *py_string_symbol_get_structural(PyObject *, void *);
+
+/* Définit si une chaîne de caractères est liée au format. */
+static int py_string_symbol_set_structural(PyObject *, PyObject *, void *);
+
+/* Fournit l'encodage d'une chaîne de caractères. */
+static PyObject *py_string_symbol_get_encoding(PyObject *, void *);
+
/* Fournit la chaîne brute de caractères du symbole. */
static PyObject *py_string_symbol_get_raw(PyObject *, void *);
/* Fournit la chaîne de caractères du symbole. */
static PyObject *py_string_symbol_get_utf8(PyObject *, void *);
-/* Fournit l'encodage d'une chaîne de caractères. */
-static PyObject *py_string_symbol_get_encoding(PyObject *, void *);
-
/* Définit les constantes pour les chaînes de caractères. */
static bool py_string_symbol_define_constants(PyTypeObject *);
@@ -61,25 +67,32 @@ static bool py_string_symbol_define_constants(PyTypeObject *);
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
-* Description : Fournit la chaîne brute de caractères du symbole. *
+* Description : Indique si une chaîne de caractères est liée au format. *
* *
-* Retour : Chaîne de caractères d'origine. *
+* Retour : Indication sur l'emploi de la chaîne. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_string_symbol_get_raw(PyObject *self, void *closure)
+static PyObject *py_string_symbol_get_structural(PyObject *self, void *closure)
{
PyObject *result; /* Valeur à retourner */
GStrSymbol *symbol; /* Elément à consulter */
- size_t len; /* Taille de la chaîne */
- const char *data; /* Données à manipuler */
+ bool status; /* Etat à transmettre */
+
+#define STRING_SYMBOL_STRUCTURAL_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ structural, py_string_symbol, \
+ "True if the string symbol is linked to the file structure, else False." \
+)
symbol = G_STR_SYMBOL(pygobject_get(self));
- data = g_string_symbol_get_raw(symbol, &len);
- result = PyBytes_FromStringAndSize(data, len);
+ status = g_string_symbol_is_structural(symbol);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
return result;
@@ -89,29 +102,30 @@ static PyObject *py_string_symbol_get_raw(PyObject *self, void *closure)
/******************************************************************************
* *
* Paramètres : self = objet Python concerné par l'appel. *
-* closure = non utilisé ici. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = adresse non utilisée ici. *
* *
-* Description : Fournit la chaîne de caractères du symbole. *
+* Description : Définit si une chaîne de caractères est liée au format. *
* *
-* Retour : Chaîne de caractères, à priori en UTF-8. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_string_symbol_get_utf8(PyObject *self, void *closure)
+static int py_string_symbol_set_structural(PyObject *self, PyObject *value, void *closure)
{
- PyObject *result; /* Valeur à retourner */
+ int ret; /* Bilan d'analyse */
GStrSymbol *symbol; /* Elément à consulter */
- size_t len; /* Taille de la chaîne */
- const char *data; /* Données à manipuler */
+
+ ret = PyBool_Check(value);
+ if (!ret) return -1;
symbol = G_STR_SYMBOL(pygobject_get(self));
- data = g_string_symbol_get_utf8(symbol, &len);
- result = PyUnicode_FromStringAndSize(data, len);
+ g_string_symbol_set_structural(symbol, value == Py_True);
- return result;
+ return 0;
}
@@ -147,6 +161,66 @@ static PyObject *py_string_symbol_get_encoding(PyObject *self, void *closure)
/******************************************************************************
* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit la chaîne brute de caractères du symbole. *
+* *
+* Retour : Chaîne de caractères d'origine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_string_symbol_get_raw(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GStrSymbol *symbol; /* Elément à consulter */
+ size_t len; /* Taille de la chaîne */
+ const char *data; /* Données à manipuler */
+
+ symbol = G_STR_SYMBOL(pygobject_get(self));
+ data = g_string_symbol_get_raw(symbol, &len);
+
+ result = PyBytes_FromStringAndSize(data, len);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit la chaîne de caractères du symbole. *
+* *
+* Retour : Chaîne de caractères, à priori en UTF-8. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_string_symbol_get_utf8(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GStrSymbol *symbol; /* Elément à consulter */
+ size_t len; /* Taille de la chaîne */
+ const char *data; /* Données à manipuler */
+
+ symbol = G_STR_SYMBOL(pygobject_get(self));
+ data = g_string_symbol_get_utf8(symbol, &len);
+
+ result = PyUnicode_FromStringAndSize(data, len);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
* *
* Description : Définit les constantes pour les chaînes de caractères. *
@@ -163,6 +237,8 @@ static bool py_string_symbol_define_constants(PyTypeObject *obj_type)
result = true;
+ result &= PyDict_AddULongMacro(obj_type, SET_NONE);
+
result &= PyDict_AddULongMacro(obj_type, SET_ASCII);
result &= PyDict_AddULongMacro(obj_type, SET_UTF_8);
result &= PyDict_AddULongMacro(obj_type, SET_MUTF_8);
@@ -193,6 +269,11 @@ PyTypeObject *get_python_string_symbol_type(void)
};
static PyGetSetDef py_str_symbol_getseters[] = {
+ STRING_SYMBOL_STRUCTURAL_ATTRIB,
+ {
+ "encoding", py_string_symbol_get_encoding, NULL,
+ "Encoding of the string.", NULL
+ },
{
"raw", py_string_symbol_get_raw, NULL,
"String content as raw data.", NULL
@@ -201,10 +282,6 @@ PyTypeObject *get_python_string_symbol_type(void)
"utf8", py_string_symbol_get_utf8, NULL,
"String content as UTF-8 data.", NULL
},
- {
- "encoding", py_string_symbol_get_encoding, NULL,
- "Encoding of the string.", NULL
- },
{ NULL }
};