diff options
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r-- | plugins/pychrysalide/analysis/constants.c | 58 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/constants.h | 3 |
2 files changed, 61 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/constants.c b/plugins/pychrysalide/analysis/constants.c index 9bc3e9f..dc507dc 100644 --- a/plugins/pychrysalide/analysis/constants.c +++ b/plugins/pychrysalide/analysis/constants.c @@ -154,3 +154,61 @@ int convert_to_source_endian(PyObject *arg, void *dst) 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 MemoryDataSize. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_memory_data_size(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 MemoryDataSize"); + break; + + case 1: + value = PyLong_AsUnsignedLong(arg); + + if (value != MDS_UNDEFINED + && (value < MDS_4_BITS_UNSIGNED && value > MDS_64_BITS_UNSIGNED) + && (value < MDS_4_BITS_SIGNED && value > MDS_64_BITS_SIGNED)) + { + PyErr_SetString(PyExc_TypeError, "invalid value for MemoryDataSize"); + result = 0; + } + + else + *((MemoryDataSize *)dst) = value; + + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/analysis/constants.h b/plugins/pychrysalide/analysis/constants.h index 2ab1f0a..45982bb 100644 --- a/plugins/pychrysalide/analysis/constants.h +++ b/plugins/pychrysalide/analysis/constants.h @@ -36,6 +36,9 @@ bool define_analysis_content_constants(PyTypeObject *); /* Tente de convertir en constante SourceEndian. */ int convert_to_source_endian(PyObject *, void *); +/* Tente de convertir en constante MemoryDataSize. */ +int convert_to_memory_data_size(PyObject *, void *); + #endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONSTANTS_H */ |