summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-06-21 20:21:00 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-06-21 20:21:00 (GMT)
commit6183dcf34a45b7250b63add608c02e96bf53e096 (patch)
tree971747a5dfab5384402a30aa26c8bf86e5ec7166 /plugins/pychrysalide/analysis
parentf6e8a85c7fe86e957adffc4e05bf10e8f3ae8ae2 (diff)
Reorganized the code for target operands.
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r--plugins/pychrysalide/analysis/constants.c58
-rw-r--r--plugins/pychrysalide/analysis/constants.h3
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 */