summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch/operands
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-05-03 18:15:46 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-05-03 18:15:46 (GMT)
commit78da8b1ad594ca24292eb0f047698bc952b7b961 (patch)
tree1e461944f2a5d9f6b61eb6ca31048021580596cd /plugins/pychrysalide/arch/operands
parent85ddac0558313b5d3fbd9428ae3e9614f16d514d (diff)
Defined the missing features required to build operands from Python.
Diffstat (limited to 'plugins/pychrysalide/arch/operands')
-rw-r--r--plugins/pychrysalide/arch/operands/immediate.c101
-rw-r--r--plugins/pychrysalide/arch/operands/register.c146
-rw-r--r--plugins/pychrysalide/arch/operands/register.h3
3 files changed, 250 insertions, 0 deletions
diff --git a/plugins/pychrysalide/arch/operands/immediate.c b/plugins/pychrysalide/arch/operands/immediate.c
index 39ce2e2..2634352 100644
--- a/plugins/pychrysalide/arch/operands/immediate.c
+++ b/plugins/pychrysalide/arch/operands/immediate.c
@@ -42,6 +42,7 @@
#include "../../access.h"
#include "../../helpers.h"
#include "../../analysis/content.h"
+#include "../../glibext/bufferline.h"
@@ -51,6 +52,12 @@
/* Crée un nouvel objet Python de type 'ImmOperand'. */
static PyObject *py_imm_operand_new(PyTypeObject *, PyObject *, PyObject *);
+/* Compare un opérande avec un autre. */
+static PyObject *py_imm_operand___cmp__(PyObject *, PyObject *);
+
+/* Traduit un opérande en version humainement lisible. */
+static PyObject *py_imm_operand__print(PyObject *, PyObject *);
+
/* Renseigne la taille de la valeur indiquée à la construction. */
static PyObject *py_imm_operand_get_size(PyObject *, void *);
@@ -158,6 +165,98 @@ static PyObject *py_imm_operand_new(PyTypeObject *type, PyObject *args, PyObject
/******************************************************************************
* *
+* Paramètres : self = serveur à manipuler. *
+* args = arguments associés à l'appel. *
+* *
+* Description : Compare un opérande avec un autre. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_imm_operand___cmp__(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ GImmOperand *other; /* Autre opérande à manipuler */
+ int ret; /* Bilan de lecture des args. */
+ GImmOperand *operand; /* Elément à manipuler */
+ int status; /* Bilan de comparaison */
+
+#define IMM_OPERAND_CMP_METHOD PYTHON_METHOD_DEF \
+( \
+ __cmp__, "$self, other, /", \
+ METH_VARARGS, py_imm_operand, \
+ "Implementation of the required method used to compare the" \
+ " operand with another one. This second object is always" \
+ " an pychrysalide.arch.ImmOperand instance.\n" \
+ "\n" \
+ "See the parent class for more information about this method." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_imm_operand, &other);
+ if (!ret) return NULL;
+
+ operand = G_IMM_OPERAND(pygobject_get(self));
+
+ status = g_arch_operand_compare(G_ARCH_OPERAND(operand), G_ARCH_OPERAND(other));
+
+ result = PyLong_FromLong(status);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = serveur à manipuler. *
+* args = arguments associés à l'appel. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_imm_operand__print(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ GBufferLine *line; /* Ligne fournie à peupler */
+ int ret; /* Bilan de lecture des args. */
+ GImmOperand *operand; /* Elément à manipuler */
+
+#define IMM_OPERAND_PRINT_METHOD PYTHON_METHOD_DEF \
+( \
+ _print, "$self, line, /", \
+ METH_VARARGS, py_imm_operand, \
+ "Implementation of the required method used to print the operand" \
+ " into a rendering line, which is a provided" \
+ " pychrysalide.glibext.BufferLine instance.\n" \
+ "\n" \
+ "See the parent class for more information about this method." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_buffer_line, &line);
+ if (!ret) return NULL;
+
+ operand = G_IMM_OPERAND(pygobject_get(self));
+
+ g_arch_operand_print(G_ARCH_OPERAND(operand), line);
+
+ result = Py_None;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -614,6 +713,8 @@ static int py_imm_operand_set_display(PyObject *self, PyObject *value, void *clo
PyTypeObject *get_python_imm_operand_type(void)
{
static PyMethodDef py_imm_operand_methods[] = {
+ IMM_OPERAND_CMP_METHOD,
+ IMM_OPERAND_PRINT_METHOD,
{ NULL }
};
diff --git a/plugins/pychrysalide/arch/operands/register.c b/plugins/pychrysalide/arch/operands/register.c
index 300fd99..ac91945 100644
--- a/plugins/pychrysalide/arch/operands/register.c
+++ b/plugins/pychrysalide/arch/operands/register.c
@@ -37,6 +37,7 @@
#include "../register.h"
#include "../../access.h"
#include "../../helpers.h"
+#include "../../glibext/bufferline.h"
@@ -57,6 +58,12 @@ static int py_register_operand_init(PyObject *, PyObject *, PyObject *);
/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */
+/* Compare un opérande avec un autre. */
+static PyObject *py_register_operand___cmp__(PyObject *, PyObject *);
+
+/* Traduit un opérande en version humainement lisible. */
+static PyObject *py_register_operand__print(PyObject *, PyObject *);
+
/* Fournit le registre associé à l'opérande. */
static PyObject *py_register_operand_get_register(PyObject *, void *);
@@ -220,6 +227,98 @@ static int py_register_operand_init(PyObject *self, PyObject *args, PyObject *kw
/******************************************************************************
* *
+* Paramètres : self = serveur à manipuler. *
+* args = arguments associés à l'appel. *
+* *
+* Description : Compare un opérande avec un autre. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_register_operand___cmp__(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ GRegisterOperand *other; /* Autre opérande à manipuler */
+ int ret; /* Bilan de lecture des args. */
+ GRegisterOperand *operand; /* Elément à manipuler */
+ int status; /* Bilan de comparaison */
+
+#define REGISTER_OPERAND_CMP_METHOD PYTHON_METHOD_DEF \
+( \
+ __cmp__, "$self, other, /", \
+ METH_VARARGS, py_register_operand, \
+ "Implementation of the required method used to compare the" \
+ " operand with another one. This second object is always" \
+ " a pychrysalide.arch.RegisterOperand instance.\n" \
+ "\n" \
+ "See the parent class for more information about this method." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_register_operand, &other);
+ if (!ret) return NULL;
+
+ operand = G_REGISTER_OPERAND(pygobject_get(self));
+
+ status = g_arch_operand_compare(G_ARCH_OPERAND(operand), G_ARCH_OPERAND(other));
+
+ result = PyLong_FromLong(status);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = serveur à manipuler. *
+* args = arguments associés à l'appel. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_register_operand__print(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ GBufferLine *line; /* Ligne fournie à peupler */
+ int ret; /* Bilan de lecture des args. */
+ GRegisterOperand *operand; /* Elément à manipuler */
+
+#define REGISTER_OPERAND_PRINT_METHOD PYTHON_METHOD_DEF \
+( \
+ _print, "$self, line, /", \
+ METH_VARARGS, py_register_operand, \
+ "Implementation of the required method used to print the operand" \
+ " into a rendering line, which is a provided" \
+ " pychrysalide.glibext.BufferLine instance.\n" \
+ "\n" \
+ "See the parent class for more information about this method." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_buffer_line, &line);
+ if (!ret) return NULL;
+
+ operand = G_REGISTER_OPERAND(pygobject_get(self));
+
+ g_arch_operand_print(G_ARCH_OPERAND(operand), line);
+
+ result = Py_None;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -317,6 +416,8 @@ static PyObject *py_register_operand_is_written(PyObject *self, void *closure)
PyTypeObject *get_python_register_operand_type(void)
{
static PyMethodDef py_register_operand_methods[] = {
+ REGISTER_OPERAND_CMP_METHOD,
+ REGISTER_OPERAND_PRINT_METHOD,
{ NULL }
};
@@ -384,3 +485,48 @@ bool ensure_python_register_operand_is_registered(void)
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 opérande de registre. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_register_operand(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_register_operand_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 register operand");
+ break;
+
+ case 1:
+ *((GRegisterOperand **)dst) = G_REGISTER_OPERAND(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/arch/operands/register.h b/plugins/pychrysalide/arch/operands/register.h
index 5fac7c9..4d3fa4b 100644
--- a/plugins/pychrysalide/arch/operands/register.h
+++ b/plugins/pychrysalide/arch/operands/register.h
@@ -40,6 +40,9 @@ PyTypeObject *get_python_register_operand_type(void);
/* Prend en charge l'objet 'pychrysalide.arch.operands.RegisterOperand'. */
bool ensure_python_register_operand_is_registered(void);
+/* Tente de convertir en opérande de registre. */
+int convert_to_register_operand(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_REGISTER_H */