summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch/constants.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/arch/constants.c')
-rw-r--r--plugins/pychrysalide/arch/constants.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/plugins/pychrysalide/arch/constants.c b/plugins/pychrysalide/arch/constants.c
index 04d0917..0402b03 100644
--- a/plugins/pychrysalide/arch/constants.c
+++ b/plugins/pychrysalide/arch/constants.c
@@ -26,6 +26,7 @@
#include <arch/instruction.h>
+#include <arch/processor.h>
#include <arch/vmpa.h>
@@ -118,6 +119,100 @@ bool define_arch_instruction_constants(PyTypeObject *type)
* *
* Paramètres : type = type dont le dictionnaire est à compléter. *
* *
+* Description : Définit les constantes relatives aux processeurs. *
+* *
+* Retour : true en cas de succès de l'opération, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_arch_processor_constants(PyTypeObject *type)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *values; /* Groupe de valeurs à établir */
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "DISASSEMBLY", APE_DISASSEMBLY);
+ if (result) result = add_const_to_group(values, "LABEL", APE_LABEL);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, true, "ArchProcessingError", values,
+ "Flags for error occurring while disassembling instructions.");
+
+ exit:
+
+ 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 ArchProcessingError. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_arch_processing_error(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 ArchProcessingError");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if ((value & (APE_DISASSEMBLY | APE_LABEL)) != 0)
+ {
+ PyErr_SetString(PyExc_TypeError, "invalid value for ArchProcessingError");
+ result = 0;
+ }
+
+ else
+ *((ArchProcessingError *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type dont le dictionnaire est à compléter. *
+* *
* Description : Définit les constantes relatives aux emplacements. *
* *
* Retour : true en cas de succès de l'opération, false sinon. *