summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch/processor.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/arch/processor.c')
-rw-r--r--plugins/pychrysalide/arch/processor.c80
1 files changed, 34 insertions, 46 deletions
diff --git a/plugins/pychrysalide/arch/processor.c b/plugins/pychrysalide/arch/processor.c
index 43e42ce..80b55d3 100644
--- a/plugins/pychrysalide/arch/processor.c
+++ b/plugins/pychrysalide/arch/processor.c
@@ -34,6 +34,7 @@
#include <plugins/dt.h>
+#include "constants.h"
#include "context.h"
#include "instriter.h"
#include "instruction.h"
@@ -137,14 +138,6 @@ static PyObject *py_arch_processor_find_instr_by_addr(PyObject *, PyObject *);
-/* ---------------------------- DEFINITION DE PROCESSEUR ---------------------------- */
-
-
-/* Définit les constantes pour les types d'erreurs. */
-static bool define_python_arch_processor_constants(PyTypeObject *);
-
-
-
/* ---------------------------------------------------------------------------------- */
/* GLUE POUR CREATION DEPUIS PYTHON */
/* ---------------------------------------------------------------------------------- */
@@ -1104,7 +1097,21 @@ static PyObject *py_arch_processor_add_error(PyObject *self, PyObject *args)
int ret; /* Bilan de lecture des args. */
GArchProcessor *proc; /* Processeur manipulé */
- ret = PyArg_ParseTuple(args, "IO&s", &type, convert_any_to_vmpa, &addr, &desc);
+#define ARCH_PROCESSOR_ADD_ERROR_METHOD PYTHON_METHOD_DEF \
+( \
+ add_error, "$self, type, addr, desc, /", \
+ METH_VARARGS, py_arch_processor, \
+ "Extend the list of detected disassembling errors.\n" \
+ "\n" \
+ "The type of error has to be one of the" \
+ " pychrysalide.arch.ArchProcessor.ArchProcessingError flags." \
+ " The location of the error is a pychrysalide.arch.vmpa" \
+ " instance and a one-line description should give some details" \
+ " about what has failed." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&O&s", convert_to_arch_processing_error, &type,
+ convert_any_to_vmpa, &addr, &desc);
if (!ret) return NULL;
proc = G_ARCH_PROCESSOR(pygobject_get(self));
@@ -1143,8 +1150,19 @@ static PyObject *py_arch_processor_get_errors(PyObject *self, void *closure)
ArchProcessingError type; /* Type d'erreur détectée */
vmpa2t addr; /* Position d'une erreur */
char *desc; /* Description d'une erreur */
+ PyObject *py_type; /* Version Python du type */
PyObject *error; /* Nouvelle erreur à rajouter */
+#define ARCH_PROCESSOR_ERRORS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ errors, py_arch_processor, \
+ "List of all detected errors which occurred during the disassembling process.\n" \
+ "\n" \
+ "The result is a tuple of (pychrysalide.arch.ArchProcessor.ArchProcessingError," \
+ " pychrysalide.arch.vmpa, string) values, providing a location and a description" \
+ " for each error." \
+)
+
proc = G_ARCH_PROCESSOR(pygobject_get(self));
g_arch_processor_lock_errors(proc);
@@ -1162,7 +1180,10 @@ static PyObject *py_arch_processor_get_errors(PyObject *self, void *closure)
g_arch_processor_get_error(proc, i, &type, &addr, &desc);
#endif
- error = Py_BuildValue("IO&s", type, build_from_internal_vmpa, &addr, desc);
+ py_type = cast_with_constants_group_from_type(get_python_arch_processor_type(),
+ "ArchProcessingError", type);
+ error = Py_BuildValue("OO&s", py_type, build_from_internal_vmpa, &addr, desc);
+ Py_DECREF(py_type);
PyTuple_SetItem(result, i, error);
@@ -1334,32 +1355,6 @@ static PyObject *py_arch_processor_find_instr_by_addr(PyObject *self, PyObject *
/******************************************************************************
* *
-* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
-* *
-* Description : Définit les constantes pour les types d'erreurs. *
-* *
-* Retour : true en cas de succès de l'opération, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool define_python_arch_processor_constants(PyTypeObject *obj_type)
-{
- bool result; /* Bilan à retourner */
-
- result = true;
-
- result &= PyDict_AddULongMacro(obj_type, APE_DISASSEMBLY);
- result &= PyDict_AddULongMacro(obj_type, APE_LABEL);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -1383,11 +1378,7 @@ PyTypeObject *get_python_arch_processor_type(void)
METH_VARARGS,
"disassemble($self, context, content, pos, format, /)\n--\n\nDisassemble a portion of binary content into one instruction."
},
- {
- "add_error", py_arch_processor_add_error,
- METH_VARARGS,
- "add_error($self, type, addr, desc, /)\n--\n\nExtend the list of detected disassembling errors."
- },
+ ARCH_PROCESSOR_ADD_ERROR_METHOD,
{
"find_instr_by_addr", py_arch_processor_find_instr_by_addr,
METH_VARARGS,
@@ -1403,10 +1394,7 @@ PyTypeObject *get_python_arch_processor_type(void)
ARCH_PROCESSOR_MEMORY_SIZE_ATTRIB,
ARCH_PROCESSOR_INS_MIN_SIZE_ATTRIB,
ARCH_PROCESSOR_VIRTUAL_SPACE_ATTRIB,
- {
- "errors", py_arch_processor_get_errors, NULL,
- "List of all detected errors which occurred during the disassembling process.", NULL
- },
+ ARCH_PROCESSOR_ERRORS_ATTRIB,
{
"instrs", py_arch_processor_get_instrs, py_arch_processor_set_instrs,
"Give access to the disassembled instructions run by the current processor.", NULL
@@ -1467,7 +1455,7 @@ bool ensure_python_arch_processor_is_registered(void)
if (!register_class_for_pygobject(dict, G_TYPE_ARCH_PROCESSOR, type, &PyGObject_Type))
return false;
- if (!define_python_arch_processor_constants(type))
+ if (!define_arch_processor_constants(type))
return false;
}