diff options
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r-- | plugins/pychrysalide/analysis/constants.c | 56 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/constants.h | 3 |
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 */ |