summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-08-22 18:03:30 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-08-22 18:03:30 (GMT)
commit9dca3fdb21e3086363038926d4f49e1300b4130d (patch)
treee056d2b59aa8b73e63b8bb5bc74272cb8edc343e /plugins/pychrysalide/arch
parent119039519376c7fbc9ca5735844100467c30192a (diff)
Restored the operand display switch feature.
Diffstat (limited to 'plugins/pychrysalide/arch')
-rw-r--r--plugins/pychrysalide/arch/operands/constants.c59
-rw-r--r--plugins/pychrysalide/arch/operands/constants.h3
2 files changed, 62 insertions, 0 deletions
diff --git a/plugins/pychrysalide/arch/operands/constants.c b/plugins/pychrysalide/arch/operands/constants.c
index 464f70d..b9d80e4 100644
--- a/plugins/pychrysalide/arch/operands/constants.c
+++ b/plugins/pychrysalide/arch/operands/constants.c
@@ -25,6 +25,9 @@
#include "constants.h"
+#include <assert.h>
+
+
#include <arch/operands/immediate.h>
@@ -73,3 +76,59 @@ bool define_imm_operand_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 ImmOperandDisplay. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_imm_operand_display(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 ImmOperandDisplay");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if (value > IOD_COUNT)
+ {
+ PyErr_SetString(PyExc_TypeError, "invalid value for ImmOperandDisplay");
+ result = 0;
+ }
+
+ else
+ *((ImmOperandDisplay *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/arch/operands/constants.h b/plugins/pychrysalide/arch/operands/constants.h
index b7910c3..71a26cc 100644
--- a/plugins/pychrysalide/arch/operands/constants.h
+++ b/plugins/pychrysalide/arch/operands/constants.h
@@ -34,6 +34,9 @@
/* Définit les constantes relatives aux opérandes d'immédiats. */
bool define_imm_operand_constants(PyTypeObject *);
+/* Tente de convertir en constante ImmOperandDisplay. */
+int convert_to_imm_operand_display(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_CONSTANTS_H */