summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch/raw.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/arch/raw.c')
-rw-r--r--plugins/pychrysalide/arch/raw.c94
1 files changed, 77 insertions, 17 deletions
diff --git a/plugins/pychrysalide/arch/raw.c b/plugins/pychrysalide/arch/raw.c
index 318eb6b..da6f759 100644
--- a/plugins/pychrysalide/arch/raw.c
+++ b/plugins/pychrysalide/arch/raw.c
@@ -31,23 +31,29 @@
#include <arch/raw.h>
+#include "constants.h"
#include "instruction.h"
#include "../access.h"
#include "../helpers.h"
+#define RAW_INSTRUCTION_DOC \
+ "The RawInstruction object handles data which is not (yet?) disassembled" \
+ " as code in a binary."
+
+
/* Indique si le contenu de l'instruction est du bourrage. */
-static PyObject *py_arch_instruction_is_padding(PyObject *, void *);
+static PyObject *py_raw_instruction_get_padding(PyObject *, void *);
/* Marque l'instruction comme ne contenant que du bourrage. */
-static int py_arch_instruction_mark_as_padding(PyObject *, PyObject *, void *);
+static int py_raw_instruction_set_padding(PyObject *, PyObject *, void *);
/* Indique si le contenu de l'instruction est un texte. */
-static PyObject *py_arch_instruction_is_string(PyObject *, void *);
+static PyObject *py_raw_instruction_get_string(PyObject *, void *);
/* Marque l'instruction comme contenant une chaîne de texte. */
-static int py_arch_instruction_mark_as_string(PyObject *, PyObject *, void *);
+static int py_raw_instruction_set_string(PyObject *, PyObject *, void *);
@@ -64,12 +70,18 @@ static int py_arch_instruction_mark_as_string(PyObject *, PyObject *, void *);
* *
******************************************************************************/
-static PyObject *py_arch_instruction_is_padding(PyObject *self, void *closure)
+static PyObject *py_raw_instruction_get_padding(PyObject *self, void *closure)
{
PyObject *result; /* Conversion à retourner */
GRawInstruction *instr; /* Version native */
bool state; /* Etat courant à consulter */
+#define RAW_INSTRUCTION_PADDING_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ padding, py_raw_instruction, \
+ "Report if the instruction is seen as padding." \
+)
+
instr = G_RAW_INSTRUCTION(pygobject_get(self));
state = g_raw_instruction_is_padding(instr);
@@ -97,7 +109,7 @@ static PyObject *py_arch_instruction_is_padding(PyObject *self, void *closure)
* *
******************************************************************************/
-static int py_arch_instruction_mark_as_padding(PyObject *self, PyObject *value, void *closure)
+static int py_raw_instruction_set_padding(PyObject *self, PyObject *value, void *closure)
{
bool state; /* Nouvel état à définir */
GRawInstruction *instr; /* Version native */
@@ -129,12 +141,18 @@ static int py_arch_instruction_mark_as_padding(PyObject *self, PyObject *value,
* *
******************************************************************************/
-static PyObject *py_arch_instruction_is_string(PyObject *self, void *closure)
+static PyObject *py_raw_instruction_get_string(PyObject *self, void *closure)
{
PyObject *result; /* Conversion à retourner */
GRawInstruction *instr; /* Version native */
bool state; /* Etat courant à consulter */
+#define RAW_INSTRUCTION_STRING_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ string, py_raw_instruction, \
+ "Report if the instruction is seen as a string." \
+)
+
instr = G_RAW_INSTRUCTION(pygobject_get(self));
state = g_raw_instruction_is_string(instr);
@@ -162,7 +180,7 @@ static PyObject *py_arch_instruction_is_string(PyObject *self, void *closure)
* *
******************************************************************************/
-static int py_arch_instruction_mark_as_string(PyObject *self, PyObject *value, void *closure)
+static int py_raw_instruction_set_string(PyObject *self, PyObject *value, void *closure)
{
bool state; /* Nouvel état à définir */
GRawInstruction *instr; /* Version native */
@@ -200,14 +218,8 @@ PyTypeObject *get_python_raw_instruction_type(void)
};
static PyGetSetDef py_raw_instruction_getseters[] = {
- {
- "is_padding", py_arch_instruction_is_padding, py_arch_instruction_mark_as_padding,
- "Report if the instruction is seen as padding.", NULL
- },
- {
- "is_string", py_arch_instruction_is_string, py_arch_instruction_mark_as_string,
- "Report if the instruction is seen as a string.", NULL
- },
+ RAW_INSTRUCTION_PADDING_ATTRIB,
+ RAW_INSTRUCTION_STRING_ATTRIB,
{ NULL }
};
@@ -220,7 +232,7 @@ PyTypeObject *get_python_raw_instruction_type(void)
.tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = "PyChrysalide raw instruction for a all architectures.",
+ .tp_doc = RAW_INSTRUCTION_DOC,
.tp_methods = py_raw_instruction_methods,
.tp_getset = py_raw_instruction_getseters,
@@ -264,8 +276,56 @@ bool ensure_python_raw_instruction_is_registered(void)
if (!register_class_for_pygobject(dict, G_TYPE_RAW_INSTRUCTION, type, get_python_arch_instruction_type()))
return false;
+ if (!define_raw_instruction_constants(type))
+ return false;
+
}
return true;
}
+
+
+/******************************************************************************
+* *
+* 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 instruction brute. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_raw_instruction(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_raw_instruction_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 raw instruction");
+ break;
+
+ case 1:
+ *((GRawInstruction **)dst) = G_RAW_INSTRUCTION(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}