diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-05-21 20:43:30 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-05-21 20:43:30 (GMT) |
commit | d8eb070be32504949ad55fd644d9f1a69df1e05d (patch) | |
tree | 321a2591b67b3131baa514fdfe47ae492f665263 /plugins/pychrysalide/analysis/constants.c | |
parent | 7e5b1add6fdeb74b2356acf8ccf7009f45cfa85e (diff) |
Written a proper documentation for the binary format Python bindings.
Diffstat (limited to 'plugins/pychrysalide/analysis/constants.c')
-rw-r--r-- | plugins/pychrysalide/analysis/constants.c | 56 |
1 files changed, 56 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; + +} |