summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-08-07 21:50:38 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-08-07 21:50:38 (GMT)
commita9328553fc558bca2e75f2c93b35acc5518d9568 (patch)
treece15e5259df278d386683dac217ec2b4a86e7c94 /plugins
parent5f55377ff6c014d513f13b76ec5faf56c31da478 (diff)
Stored all errors detected when loading and disassembling a binary file.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/pychrysa/arch/processor.c153
-rw-r--r--plugins/pychrysa/format/format.c157
2 files changed, 309 insertions, 1 deletions
diff --git a/plugins/pychrysa/arch/processor.c b/plugins/pychrysa/arch/processor.c
index c3d744b..4470e78 100644
--- a/plugins/pychrysa/arch/processor.c
+++ b/plugins/pychrysa/arch/processor.c
@@ -55,12 +55,18 @@
+/* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */
+/* Etend la liste des soucis détectés avec de nouvelles infos. */
+static PyObject *py_arch_processor_add_error(PyObject *, PyObject *);
+
+/* Fournit les éléments concernant tous les soucis détectés. */
+static PyObject *py_arch_processor_get_errors(PyObject *, void *);
-/* ------------------ MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES ------------------ */
+/* ------------------ MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES ------------------ */
/* Fournit les instructions désassemblées pour une architecture. */
@@ -74,6 +80,109 @@ static PyObject *py_arch_processor_find_instr_by_addr(PyObject *, PyObject *);
+
+
+/* Définit les constantes pour les types d'erreurs. */
+static bool define_python_arch_processor_constants(PyTypeObject *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Etend la liste des soucis détectés avec de nouvelles infos. *
+* *
+* Retour : None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_processor_add_error(PyObject *self, PyObject *args)
+{
+ ArchProcessingError type; /* Type d'erreur détectée */
+ vmpa2t addr; /* Position d'une erreur */
+ char *desc; /* Description d'une erreur */
+ int ret; /* Bilan de lecture des args. */
+ GArchProcessor *proc; /* Processeur manipulé */
+
+ ret = PyArg_ParseTuple(args, "IO&s", &type, convert_any_to_vmpa, &addr, &desc);
+ if (!ret) return NULL;
+
+ proc = G_ARCH_PROCESSOR(pygobject_get(self));
+
+ g_arch_processor_add_error(proc, type, &addr, desc);
+
+ Py_RETURN_NONE;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit les éléments concernant tous les soucis détectés. *
+* *
+* Retour : Liste des erreurs relevées au niveau de l'assembleur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_processor_get_errors(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance Python à retourner */
+ GArchProcessor *proc; /* Architecture visée */
+ size_t count; /* Nombre d'éléments à traiter */
+ size_t i; /* Boucle de parcours */
+#ifndef NDEBUG
+ bool status; /* Bilan d'un appel */
+#endif
+ ArchProcessingError type; /* Type d'erreur détectée */
+ vmpa2t addr; /* Position d'une erreur */
+ char *desc; /* Description d'une erreur */
+ PyObject *error; /* Nouvelle erreur à rajouter */
+
+ proc = G_ARCH_PROCESSOR(pygobject_get(self));
+
+ g_arch_processor_lock_errors(proc);
+
+ count = g_arch_processor_count_errors(proc);
+
+ result = PyTuple_New(count);
+
+ for (i = 0; i < count; i++)
+ {
+#ifndef NDEBUG
+ status = g_arch_processor_get_error(proc, i, &type, &addr, &desc);
+ assert(status);
+#else
+ g_arch_processor_get_error(proc, i, &type, &addr, &desc);
+#endif
+
+ error = Py_BuildValue("IO&s", type, build_from_internal_vmpa, &addr, desc);
+
+ PyTuple_SetItem(result, i, error);
+
+ }
+
+ g_arch_processor_unlock_errors(proc);
+
+ return result;
+
+}
+
+
+
/* ---------------------------------------------------------------------------------- */
/* MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES */
/* ---------------------------------------------------------------------------------- */
@@ -227,6 +336,36 @@ 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_AddIntMacro(obj_type, APE_DISASSEMBLY);
+ result &= PyDict_AddIntMacro(obj_type, APE_LABEL);
+
+ return result;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : - *
@@ -243,6 +382,11 @@ PyTypeObject *get_python_arch_processor_type(void)
{
static PyMethodDef py_arch_processor_methods[] = {
{
+ "add_error", py_arch_processor_add_error,
+ METH_VARARGS,
+ "add_error($self, type, addr, desc, /)\n--\n\nExtend the list of detected disassembling errors."
+ },
+ {
"find_instr_by_addr", py_arch_processor_find_instr_by_addr,
METH_VARARGS,
"find_instr_by_addr($self, addr, /)\n--\n\nLook for an instruction located at a given address."
@@ -252,6 +396,10 @@ PyTypeObject *get_python_arch_processor_type(void)
static PyGetSetDef py_arch_processor_getseters[] = {
{
+ "errors", py_arch_processor_get_errors, NULL,
+ "List of all detected errors which occurred during the disassembling process.", NULL
+ },
+ {
"instrs", py_arch_processor_get_instrs, py_arch_processor_set_instrs,
"Give access to the disassembled instructions run by the current processor.", NULL
},
@@ -303,6 +451,9 @@ bool register_python_arch_processor(PyObject *module)
if (!register_class_for_pygobject(dict, G_TYPE_ARCH_PROCESSOR, py_arch_processor_type, &PyGObject_Type))
return false;
+ if (!define_python_arch_processor_constants(py_arch_processor_type))
+ return false;
+
return true;
}
diff --git a/plugins/pychrysa/format/format.c b/plugins/pychrysa/format/format.c
index cc9e819..773b928 100644
--- a/plugins/pychrysa/format/format.c
+++ b/plugins/pychrysa/format/format.c
@@ -84,6 +84,25 @@ static PyObject *py_binary_format_get_symbols(PyObject *, void *);
+/* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */
+
+
+/* Etend la liste des soucis détectés avec de nouvelles infos. */
+static PyObject *py_binary_format_add_error(PyObject *, PyObject *);
+
+/* Fournit les éléments concernant tous les soucis détectés. */
+static PyObject *py_binary_format_get_errors(PyObject *, void *);
+
+
+
+
+
+
+/* Définit les constantes pour les types d'erreurs. */
+static bool define_python_binary_format_constants(PyTypeObject *);
+
+
+
/* ---------------------------------------------------------------------------------- */
/* PARCOURS DE SYMBOLES DE BINAIRES */
/* ---------------------------------------------------------------------------------- */
@@ -538,6 +557,132 @@ static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure)
}
+
+/* ---------------------------------------------------------------------------------- */
+/* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Etend la liste des soucis détectés avec de nouvelles infos. *
+* *
+* Retour : None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args)
+{
+ BinaryFormatError type; /* Type d'erreur détectée */
+ vmpa2t addr; /* Position d'une erreur */
+ char *desc; /* Description d'une erreur */
+ int ret; /* Bilan de lecture des args. */
+ GBinFormat *format; /* Format binaire manipulé */
+
+ ret = PyArg_ParseTuple(args, "IO&s", &type, convert_any_to_vmpa, &addr, &desc);
+ if (!ret) return NULL;
+
+ format = G_BIN_FORMAT(pygobject_get(self));
+
+ g_binary_format_add_error(format, type, &addr, desc);
+
+ Py_RETURN_NONE;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit les éléments concernant tous les soucis détectés. *
+* *
+* Retour : Liste des erreurs relevées au niveau de l'assembleur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_get_errors(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance Python à retourner */
+ GBinFormat *format; /* Format binaire manipulé */
+ size_t count; /* Nombre d'éléments à traiter */
+ size_t i; /* Boucle de parcours */
+#ifndef NDEBUG
+ bool status; /* Bilan d'un appel */
+#endif
+ BinaryFormatError type; /* Type d'erreur détectée */
+ vmpa2t addr; /* Position d'une erreur */
+ char *desc; /* Description d'une erreur */
+ PyObject *error; /* Nouvelle erreur à rajouter */
+
+ format = G_BIN_FORMAT(pygobject_get(self));
+
+ g_binary_format_lock_errors(format);
+
+ count = g_binary_format_count_errors(format);
+
+ result = PyTuple_New(count);
+
+ for (i = 0; i < count; i++)
+ {
+#ifndef NDEBUG
+ status = g_binary_format_get_error(format, i, &type, &addr, &desc);
+ assert(status);
+#else
+ g_binary_format_get_error(format, i, &type, &addr, &desc);
+#endif
+
+ error = Py_BuildValue("IO&s", type, build_from_internal_vmpa, &addr, desc);
+
+ PyTuple_SetItem(result, i, error);
+
+ }
+
+ g_binary_format_unlock_errors(format);
+
+ return result;
+
+}
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* 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_binary_format_constants(PyTypeObject *obj_type)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ result &= PyDict_AddIntMacro(obj_type, BFE_STRUCTURE);
+
+ return result;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : - *
@@ -573,6 +718,11 @@ PyTypeObject *get_python_binary_format_type(void)
METH_VARARGS,
"resolve_symbol($self, addr, strict, /)\n--\n\nSearch a position inside a routine by a given address."
},
+ {
+ "add_error", py_binary_format_add_error,
+ METH_VARARGS,
+ "add_error($self, type, addr, desc, /)\n--\n\nExtend the list of detected disassembling errors."
+ },
{ NULL }
};
@@ -585,6 +735,10 @@ PyTypeObject *get_python_binary_format_type(void)
"symbols", py_binary_format_get_symbols, NULL,
"Iterable list of all symbols found in the binary format.", NULL
},
+ {
+ "errors", py_binary_format_get_errors, NULL,
+ "List of all detected errors which occurred while loading the binary.", NULL
+ },
{ NULL }
};
@@ -635,6 +789,9 @@ bool register_python_binary_format(PyObject *module)
if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, py_bin_format_type, &PyGObject_Type))
return false;
+ if (!define_python_binary_format_constants(py_bin_format_type))
+ return false;
+
return true;
}