summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-04-13 22:53:32 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-04-13 22:53:32 (GMT)
commit0794024b412604ae5e5aca0f104b5a8f3ec5412c (patch)
treec5b73975561cf95e9c65f84b27423f218ffab2b0 /plugins/pychrysalide/format
parente75a1aea506869d441fc084f78102367be1f9ed2 (diff)
Avoided to look for syscalls in a kernel binary.
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r--plugins/pychrysalide/format/constants.c56
-rw-r--r--plugins/pychrysalide/format/constants.h3
-rw-r--r--plugins/pychrysalide/format/format.c231
3 files changed, 258 insertions, 32 deletions
diff --git a/plugins/pychrysalide/format/constants.c b/plugins/pychrysalide/format/constants.c
index a0d71f7..0df7bd4 100644
--- a/plugins/pychrysalide/format/constants.c
+++ b/plugins/pychrysalide/format/constants.c
@@ -25,6 +25,7 @@
#include "constants.h"
+#include <format/format.h>
#include <format/symbol.h>
@@ -36,7 +37,60 @@
* *
* Paramètres : type = type dont le dictionnaire est à compléter. *
* *
-* Description : Définit les constantes pour le format Dex. *
+* Description : Définit les constantes pour les formats binaires. *
+* *
+* Retour : true en cas de succès de l'opération, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_binary_format_constants(PyTypeObject *type)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *values; /* Groupe de valeurs à établir */
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "SPECIFICATION", BFE_SPECIFICATION);
+ if (result) result = add_const_to_group(values, "STRUCTURE", BFE_STRUCTURE);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, true, "BinaryFormatError", values,
+ "Flags for error occurring while loading a binary format.");
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "NONE", FFL_NONE);
+ if (result) result = add_const_to_group(values, "RUN_IN_KERNEL_SPACE", FFL_RUN_IN_KERNEL_SPACE);
+ if (result) result = add_const_to_group(values, "MASK", FFL_MASK);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, true, "FormatFlag", values,
+ "Extra indications for formats.");
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type dont le dictionnaire est à compléter. *
+* *
+* Description : Définit les constantes pour les symboles binaires. *
* *
* Retour : true en cas de succès de l'opération, false sinon. *
* *
diff --git a/plugins/pychrysalide/format/constants.h b/plugins/pychrysalide/format/constants.h
index 6515f35..ad7b9a5 100644
--- a/plugins/pychrysalide/format/constants.h
+++ b/plugins/pychrysalide/format/constants.h
@@ -31,6 +31,9 @@
+/* Définit les constantes pour les formats binaires. */
+bool define_binary_format_constants(PyTypeObject *);
+
/* Définit les constantes pour les symboles binaires. */
bool define_binary_symbol_constants(PyTypeObject *);
diff --git a/plugins/pychrysalide/format/format.c b/plugins/pychrysalide/format/format.c
index a0f8079..6c1d2da 100644
--- a/plugins/pychrysalide/format/format.c
+++ b/plugins/pychrysalide/format/format.c
@@ -31,6 +31,7 @@
#include <format/format.h>
+#include "constants.h"
#include "executable.h"
#include "symbol.h"
#include "symiter.h"
@@ -43,6 +44,15 @@
/* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */
+/* Ajoute une information complémentaire à un format. */
+static PyObject *py_binary_format_set_flag(PyObject *, PyObject *);
+
+/* Retire une information complémentaire à un format. */
+static PyObject *py_binary_format_unset_flag(PyObject *, PyObject *);
+
+/* Détermine si un format possède un fanion particulier. */
+static PyObject *py_binary_format_has_flag(PyObject *, PyObject *);
+
/* Assure l'interprétation d'un format en différé. */
static PyObject *py_binary_format_analyze(PyObject *, PyObject *, PyObject *);
@@ -67,6 +77,9 @@ static PyObject *py_binary_format_find_next_symbol_at(PyObject *, PyObject *);
/* Recherche le symbole correspondant à une adresse. */
static PyObject *py_binary_format_resolve_symbol(PyObject *, PyObject *);
+/* Fournit les particularités du format. */
+static PyObject *py_binary_format_get_flags(PyObject *, void *);
+
/* Indique la désignation interne du format. */
static PyObject *py_binary_format_get_name(PyObject *, void *);
@@ -95,9 +108,6 @@ 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 *);
-
/* ---------------------------------------------------------------------------------- */
@@ -107,6 +117,152 @@ static bool define_python_binary_format_constants(PyTypeObject *);
/******************************************************************************
* *
+* Paramètres : self = serveur à manipuler. *
+* args = arguments d'appel non utilisés ici. *
+* *
+* Description : Ajoute une information complémentaire à un format. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_set_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Propriété à traiter */
+ int ret; /* Bilan de lecture des args. */
+ GBinFormat *format; /* Elément à manipuler */
+ bool status; /* Bilan de l'opération */
+
+#define BINARY_FORMAT_SET_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ set_flag, "$self, flag, /", \
+ METH_VARARGS, py_binary_format, \
+ "Add a property from a binary format.\n" \
+ "\n" \
+ "This property is one of the values listed in the" \
+ " of pychrysalide.format.BinFormat.FormatFlag enumeration.\n" \
+ "\n" \
+ "If the flag was not set before the operation, True is" \
+ " returned, else the result is False." \
+)
+
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
+ format = G_BIN_FORMAT(pygobject_get(self));
+
+ status = g_binary_format_set_flag(format, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = serveur à manipuler. *
+* args = arguments d'appel non utilisés ici. *
+* *
+* Description : Retire une information complémentaire à un format. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_unset_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Propriété à traiter */
+ int ret; /* Bilan de lecture des args. */
+ GBinFormat *format; /* Elément à manipuler */
+ bool status; /* Bilan de l'opération */
+
+#define BINARY_FORMAT_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ unset_flag, "$self, flag, /", \
+ METH_VARARGS, py_binary_format, \
+ "Remove a property from a binary format.\n" \
+ "\n" \
+ "This property is one of the values listed in the" \
+ " of pychrysalide.format.BinFormat.FormatFlag enumeration.\n" \
+ "\n" \
+ "If the flag was not set before the operation, False is" \
+ " returned, else the result is True." \
+)
+
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
+ format = G_BIN_FORMAT(pygobject_get(self));
+
+ status = g_binary_format_unset_flag(format, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = serveur à manipuler. *
+* args = arguments d'appel non utilisés ici. *
+* *
+* Description : Détermine si un format possède un fanion particulier. *
+* *
+* Retour : Bilan de la détection. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_has_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Propriété à traiter */
+ int ret; /* Bilan de lecture des args. */
+ GBinFormat *format; /* Elément à manipuler */
+ bool status; /* Bilan de l'opération */
+
+#define BINARY_FORMAT_HAS_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ has_flag, "$self, flag, /", \
+ METH_VARARGS, py_binary_format, \
+ "Test if a binary format has a given property.\n" \
+ "\n" \
+ "This property is one of the values listed in the" \
+ " of pychrysalide.format.BinFormat.FormatFlag enumeration.\n" \
+ "\n" \
+ "The result is a boolean value." \
+)
+
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
+ format = G_BIN_FORMAT(pygobject_get(self));
+
+ status = g_binary_format_has_flag(format, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = contenu binaire à manipuler. *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
@@ -453,6 +609,42 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args)
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
+* Description : Fournit les particularités du format. *
+* *
+* Retour : Somme de tous les fanions associés au format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_format_get_flags(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GBinFormat *format; /* Elément à consulter */
+ FormatFlag flags; /* Indications complémentaires */
+
+#define BINARY_FORMAT_FLAGS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ flags, py_binary_format, \
+ "Provide all the flags set for a format. The return value" \
+ " is of type pychrysalide.format.BinFormat.FormatFlag." \
+)
+
+ format = G_BIN_FORMAT(pygobject_get(self));
+ flags = g_binary_format_get_flags(format);
+
+ result = cast_with_constants_group_from_type(get_python_binary_format_type(), "FormatFlag", flags);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
* Description : Indique la désignation interne du format. *
* *
* Retour : Description du format. *
@@ -674,33 +866,6 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure)
-
-/******************************************************************************
-* *
-* 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_AddULongMacro(obj_type, BFE_SPECIFICATION);
- result &= PyDict_AddULongMacro(obj_type, BFE_STRUCTURE);
-
- return result;
-
-}
-
-
/******************************************************************************
* *
* Paramètres : - *
@@ -716,6 +881,9 @@ static bool define_python_binary_format_constants(PyTypeObject *obj_type)
PyTypeObject *get_python_binary_format_type(void)
{
static PyMethodDef py_bin_format_methods[] = {
+ BINARY_FORMAT_SET_FLAG_METHOD,
+ BINARY_FORMAT_UNSET_FLAG_METHOD,
+ BINARY_FORMAT_HAS_FLAG_METHOD,
BINARY_FORMAT_ANALYZE_METHOD,
{
"register_code_point", py_binary_format_register_code_point,
@@ -761,6 +929,7 @@ PyTypeObject *get_python_binary_format_type(void)
};
static PyGetSetDef py_bin_format_getseters[] = {
+ BINARY_FORMAT_FLAGS_ATTRIB,
{
"name", py_binary_format_get_name, NULL,
"Internal name of the binary format.", NULL
@@ -836,7 +1005,7 @@ bool ensure_python_binary_format_is_registered(void)
if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, type, &PyGObject_Type))
return false;
- if (!define_python_binary_format_constants(type))
+ if (!define_binary_format_constants(type))
return false;
}