summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-05-21 20:43:30 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-05-21 20:43:30 (GMT)
commitd8eb070be32504949ad55fd644d9f1a69df1e05d (patch)
tree321a2591b67b3131baa514fdfe47ae492f665263 /plugins/pychrysalide/analysis
parent7e5b1add6fdeb74b2356acf8ccf7009f45cfa85e (diff)
Written a proper documentation for the binary format Python bindings.
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r--plugins/pychrysalide/analysis/constants.c56
-rw-r--r--plugins/pychrysalide/analysis/constants.h3
2 files changed, 59 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/constants.c b/plugins/pychrysalide/analysis/constants.c
index a162ac7..9bc3e9f 100644
--- a/plugins/pychrysalide/analysis/constants.c
+++ b/plugins/pychrysalide/analysis/constants.c
@@ -98,3 +98,59 @@ bool define_analysis_content_constants(PyTypeObject *type)
return result;
}
+
+
+/******************************************************************************
+* *
+* 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 constante SourceEndian. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_source_endian(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+ unsigned long value; /* Valeur transcrite */
+
+ result = PyObject_IsInstance(arg, (PyObject *)&PyLong_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 SourceEndian");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if (value > SRE_BIG)
+ {
+ PyErr_SetString(PyExc_TypeError, "invalid value for SourceEndian");
+ result = 0;
+ }
+
+ else
+ *((SourceEndian *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/analysis/constants.h b/plugins/pychrysalide/analysis/constants.h
index c4da054..2ab1f0a 100644
--- a/plugins/pychrysalide/analysis/constants.h
+++ b/plugins/pychrysalide/analysis/constants.h
@@ -33,6 +33,9 @@
/* Définit les constantes relatives aux contenus binaires. */
bool define_analysis_content_constants(PyTypeObject *);
+/* Tente de convertir en constante SourceEndian. */
+int convert_to_source_endian(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONSTANTS_H */