summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/arch')
-rw-r--r--plugins/pychrysalide/arch/Makefile.am32
-rw-r--r--plugins/pychrysalide/arch/constants.c5
-rw-r--r--plugins/pychrysalide/arch/constants.h5
-rw-r--r--plugins/pychrysalide/arch/instruction.c866
-rw-r--r--plugins/pychrysalide/arch/instructions/Makefile.am3
-rw-r--r--plugins/pychrysalide/arch/instructions/constants.c58
-rw-r--r--plugins/pychrysalide/arch/instructions/constants.h5
-rw-r--r--plugins/pychrysalide/arch/instructions/raw.c142
-rw-r--r--plugins/pychrysalide/arch/instructions/undefined.c145
-rw-r--r--plugins/pychrysalide/arch/instructions/undefined.h4
-rw-r--r--plugins/pychrysalide/arch/module-ui.c66
-rw-r--r--plugins/pychrysalide/arch/module-ui.h38
-rw-r--r--plugins/pychrysalide/arch/module.c17
-rw-r--r--plugins/pychrysalide/arch/operand-ui.c461
-rw-r--r--plugins/pychrysalide/arch/operand-ui.h45
-rw-r--r--plugins/pychrysalide/arch/operand.c480
-rw-r--r--plugins/pychrysalide/arch/operand.h5
-rw-r--r--plugins/pychrysalide/arch/operands/Makefile.am16
-rw-r--r--plugins/pychrysalide/arch/operands/constants.c19
-rw-r--r--plugins/pychrysalide/arch/operands/constants.h7
-rw-r--r--plugins/pychrysalide/arch/operands/immediate.c384
-rw-r--r--plugins/pychrysalide/arch/operands/immediate.h10
-rw-r--r--plugins/pychrysalide/arch/operands/known.c125
-rw-r--r--plugins/pychrysalide/arch/operands/known.h10
-rw-r--r--plugins/pychrysalide/arch/operands/module.c16
-rw-r--r--plugins/pychrysalide/arch/operands/register.c196
-rw-r--r--plugins/pychrysalide/arch/register.c361
27 files changed, 2050 insertions, 1471 deletions
diff --git a/plugins/pychrysalide/arch/Makefile.am b/plugins/pychrysalide/arch/Makefile.am
index d3ee3f0..a0dcfdb 100644
--- a/plugins/pychrysalide/arch/Makefile.am
+++ b/plugins/pychrysalide/arch/Makefile.am
@@ -1,19 +1,13 @@
-noinst_LTLIBRARIES = libpychrysaarch4.la # libpychrysaarch.la
+noinst_LTLIBRARIES = libpychrysaarch4.la libpychrysaarchui.la # libpychrysaarch.la
# libpychrysaarch_la_SOURCES = \
-# constants.h constants.c \
# context.h context.c \
# instriter.h instriter.c \
-# instruction.h instruction.c \
-# module.h module.c \
-# operand.h operand.c \
-# processor.h processor.c \
-# register.h register.c \
-# vmpa.h vmpa.c
+# processor.h processor.c
# libpychrysaarch_la_LIBADD = \
-# instructions/libpychrysaarchinstructions.la \
+# \
# operands/libpychrysaarchoperands.la
# libpychrysaarch_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
@@ -22,21 +16,33 @@ noinst_LTLIBRARIES = libpychrysaarch4.la # libpychrysaarch.la
libpychrysaarch4_la_SOURCES = \
constants.h constants.c \
+ instruction.h instruction.c \
module.h module.c \
+ operand.h operand.c \
+ register.h register.c \
vmpa.h vmpa.c
-# libpychrysaarch4_la_LIBADD = \
-# instructions/libpychrysaarchinstructions.la \
-# operands/libpychrysaarchoperands.la
+libpychrysaarch4_la_LIBADD = \
+ instructions/libpychrysaarchinstructions.la \
+ operands/libpychrysaarchoperands.la
libpychrysaarch4_la_CFLAGS = $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
$(TOOLKIT_CFLAGS) \
-I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT
+libpychrysaarchui_la_SOURCES = \
+ module-ui.h module-ui.c \
+ operand-ui.h operand-ui.c
+
+libpychrysaarchui_la_CFLAGS = $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+ $(TOOLKIT_CFLAGS) \
+ -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT
+
+
devdir = $(includedir)/chrysalide/$(subdir)
dev_HEADERS = $(libpychrysaarch_la_SOURCES:%c=)
-# SUBDIRS = instructions operands
+SUBDIRS = instructions operands
diff --git a/plugins/pychrysalide/arch/constants.c b/plugins/pychrysalide/arch/constants.c
index 3604795..5db59ff 100644
--- a/plugins/pychrysalide/arch/constants.c
+++ b/plugins/pychrysalide/arch/constants.c
@@ -25,7 +25,7 @@
#include "constants.h"
-//#include <arch/instruction.h>
+#include <arch/instruction.h>
//#include <arch/processor.h>
#include <arch/vmpa.h>
@@ -33,7 +33,6 @@
#include "../helpers.h"
-#if 0 // FIXME
/******************************************************************************
* *
@@ -116,6 +115,8 @@ bool define_arch_instruction_constants(PyTypeObject *type)
}
+#if 0 // FIXME
+
/******************************************************************************
* *
* Paramètres : type = type dont le dictionnaire est à compléter. *
diff --git a/plugins/pychrysalide/arch/constants.h b/plugins/pychrysalide/arch/constants.h
index b12579e..2f16c4f 100644
--- a/plugins/pychrysalide/arch/constants.h
+++ b/plugins/pychrysalide/arch/constants.h
@@ -30,10 +30,13 @@
#include <stdbool.h>
-#if 0 // FIXME
+
/* Définit les constantes relatives aux instructions. */
bool define_arch_instruction_constants(PyTypeObject *);
+
+#if 0 // FIXME
+
/* Définit les constantes relatives aux processeurs. */
bool define_arch_processor_constants(PyTypeObject *);
diff --git a/plugins/pychrysalide/arch/instruction.c b/plugins/pychrysalide/arch/instruction.c
index 0a9ba16..49daa9c 100644
--- a/plugins/pychrysalide/arch/instruction.c
+++ b/plugins/pychrysalide/arch/instruction.c
@@ -27,13 +27,12 @@
#include <assert.h>
#include <malloc.h>
-#include <string.h>
#include <pygobject.h>
#include <i18n.h>
+#include <plugins/self.h>
#include <arch/instruction-int.h>
-#include <plugins/dt.h>
#include "constants.h"
@@ -41,30 +40,38 @@
#include "vmpa.h"
#include "../access.h"
#include "../helpers.h"
-#include "../glibext/linegen.h"
-
-
-
-static G_DEFINE_QUARK(cached_keyword, get_cached_keyword);
+#include "../glibext/objhole.h"
+#include "../glibext/serialize.h"
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_arch_instruction_new(PyTypeObject *, PyObject *, PyObject *);
-
/* Initialise la classe générique des instructions. */
-static void py_arch_instruction_init_gclass(GArchInstructionClass *, gpointer);
+static int py_arch_instruction_init_gclass(GArchInstructionClass *, PyTypeObject *);
-CREATE_DYN_ABSTRACT_CONSTRUCTOR(arch_instruction, G_TYPE_ARCH_INSTRUCTION, py_arch_instruction_init_gclass);
+CREATE_DYN_ABSTRACT_CONSTRUCTOR(arch_instruction, G_TYPE_ARCH_INSTRUCTION);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_arch_instruction_init(PyObject *, PyObject *, PyObject *);
+/* Indique l'encodage d'une instruction de façon détaillée. */
+static char *py_arch_instruction_get_encoding_wrapper(const GArchInstruction *);
+
/* Fournit le nom humain de l'instruction manipulée. */
-static const char *py_arch_instruction_get_class_keyword(GArchInstruction *);
+static char *py_arch_instruction_get_keyword_wrapper(const GArchInstruction *);
+
+
+
+/* ------------------- DEFINITION DES LIAISONS ENTRE INSTRUCTIONS ------------------- */
+
+
+/* Fournit les origines d'une instruction donnée. */
+static PyObject *py_arch_instruction_get_sources(PyObject *, void *);
+
+/* Fournit les destinations d'une instruction donnée. */
+static PyObject *py_arch_instruction_get_destinations(PyObject *, void *);
@@ -72,10 +79,7 @@ static const char *py_arch_instruction_get_class_keyword(GArchInstruction *);
/* Attache un opérande supplémentaire à une instruction. */
-static PyObject *py_arch_instruction_attach_extra_operand(PyObject *, PyObject *);
-
-/* Fournit tous les opérandes d'une instruction. */
-static PyObject *py_arch_instruction_get_operands(PyObject *, void *);
+static PyObject *py_arch_instruction_attach_operand(PyObject *, PyObject *);
/* Remplace un opérande d'une instruction par un autre. */
static PyObject *py_arch_instruction_replace_operand(PyObject *, PyObject *);
@@ -89,34 +93,35 @@ static PyObject *py_arch_instruction_find_operand_path(PyObject *, PyObject *);
/* Obtient l'opérande correspondant à un chemin donné. */
static PyObject *py_arch_instruction_get_operand_from_path(PyObject *, PyObject *);
+/* Fournit tous les opérandes d'une instruction. */
+static PyObject *py_arch_instruction_get_operands(PyObject *, void *);
-/* ------------------- DEFINITION DES LIAISONS ENTRE INSTRUCTIONS ------------------- */
+/* ------------------ LIAISON DE FONCTIONNALITES AVEC L'API PYTHON ------------------ */
-/* Fournit les origines d'une instruction donnée. */
-static PyObject *py_arch_instruction_get_sources(PyObject *, void *);
-/* Fournit les destinations d'une instruction donnée. */
-static PyObject *py_arch_instruction_get_destinations(PyObject *, void *);
+/* Ajoute une information complémentaire à une instruction. */
+static PyObject *py_arch_instruction_set_flag(PyObject *, PyObject *);
+/* Retire une information complémentaire à une instruction. */
+static PyObject *py_arch_instruction_unset_flag(PyObject *, PyObject *);
+/* Détermine si une instruction possède un fanion particulier. */
+static PyObject *py_arch_instruction_has_flag(PyObject *, PyObject *);
-/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */
+/* Fournit l'identifiant correspondant à un type d'instructions. */
+static PyObject *py_arch_instruction_get_type_id(PyObject *, void *);
+/* Indique l'encodage d'une instruction de façon détaillée. */
+static PyObject *py_arch_instruction_get_encoding(PyObject *, void *);
-/* Fournit l'identifiant unique pour un ensemble d'instructions. */
-static PyObject *py_arch_instruction_get_unique_id(PyObject *, void *);
+/* Indique l'encodage d'une instruction de façon détaillée. */
+static PyObject *py_arch_instruction_get_keyword(PyObject *, void *);
/* Fournit la place mémoire d'une instruction. */
static PyObject *py_arch_instruction_get_range(PyObject *, void *);
-/* Définit la localisation d'une instruction. */
-static int py_arch_instruction_set_range(PyObject *, PyObject *, void *);
-
-/* Fournit le nom humain de l'instruction manipulée. */
-static PyObject *py_arch_instruction_get_keyword(PyObject *, void *);
-
/* ---------------------------------------------------------------------------------- */
@@ -126,24 +131,23 @@ static PyObject *py_arch_instruction_get_keyword(PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : class = classe à initialiser. *
-* unused = données non utilisées ici. *
+* Paramètres : gclass = classe GLib à initialiser. *
+* pyclass = classe Python à initialiser. *
* *
* Description : Initialise la classe générique des instructions. *
* *
-* Retour : - *
+* Retour : 0 pour indiquer un succès de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static void py_arch_instruction_init_gclass(GArchInstructionClass *class, gpointer unused)
+static int py_arch_instruction_init_gclass(GArchInstructionClass *gclass, PyTypeObject *pyclass)
{
- GArchInstructionClass *instr; /* Encore une autre vision... */
-
- instr = G_ARCH_INSTRUCTION_CLASS(class);
+ PY_CLASS_SET_WRAPPER(gclass->get_encoding, py_arch_instruction_get_encoding_wrapper);
+ PY_CLASS_SET_WRAPPER(gclass->get_keyword, py_arch_instruction_get_keyword_wrapper);
- instr->get_keyword = (get_instruction_keyword_fc)py_arch_instruction_get_class_keyword;
+ return 0;
}
@@ -164,17 +168,25 @@ static void py_arch_instruction_init_gclass(GArchInstructionClass *class, gpoint
static int py_arch_instruction_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- unsigned short int uid; /* Indentifiant unique de type */
- const char *keyword; /* Désignation d'instruction */
+ unsigned short int tid; /* Indentifiant unique de type */
int ret; /* Bilan de lecture des args. */
GArchInstruction *instr; /* Instruction à manipuler */
- GQuark cache_key; /* Emplacement local */
- static char *kwlist[] = { "uid", "keyword", NULL };
+#define ARCH_INSTRUCTION_DOC \
+ "The ArchInstruction object provides a base class for instructions" \
+ " of any architecture.\n" \
+ " operands of any kind for new architectures.\n" \
+ "\n" \
+ "Calls to the *__init__* constructor of this abstract object expect"\
+ " one argument: an unique identifier, as an integer value.\n" \
+ "\n" \
+ "The following methods have to be defined for new classes:\n" \
+ "* pychrysalide.arch.ArchRegister._get_encoding();\n" \
+ "* pychrysalide.arch.ArchRegister._get_keyword().\n"
/* Récupération des paramètres */
- ret = PyArg_ParseTupleAndKeywords(args, kwds, "Hs", kwlist, &uid, &keyword);
+ ret = PyArg_ParseTuple(args, "H", &tid);
if (!ret) return -1;
/* Initialisation d'un objet GLib */
@@ -186,13 +198,72 @@ static int py_arch_instruction_init(PyObject *self, PyObject *args, PyObject *kw
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- cache_key = get_cached_keyword_quark();
+ if (!g_arch_instruction_create(instr, tid))
+ return -1;
+
+ return 0;
- g_object_set_qdata_full(G_OBJECT(instr), cache_key, strdup(keyword), g_free);
+}
- g_arch_instruction_set_unique_id(G_ARCH_INSTRUCTION(instr), uid);
- return 0;
+/******************************************************************************
+* *
+* Paramètres : instr = instruction quelconque à consulter. *
+* *
+* Description : Indique l'encodage d'une instruction de façon détaillée. *
+* *
+* Retour : Description humaine de l'encodage utilisé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *py_arch_instruction_get_encoding_wrapper(const GArchInstruction *instr)
+{
+ char *result; /* Encodage à retourner */
+ PyGILState_STATE gstate; /* Sauvegarde d'environnement */
+ PyObject *pyobj; /* Objet Python concerné */
+ PyObject *pyret; /* Bilan d'exécution */
+
+#define PLUGIN_MODULE_GET_ENCODING_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _get_encoding, "$self, /", \
+ METH_NOARGS, \
+ "Abstract method describing the encoding related to an" \
+ " instruction.\n" \
+ "\n" \
+ "The result should be the string value.\n" \
+)
+
+ result = NULL;
+
+ gstate = PyGILState_Ensure();
+
+ pyobj = pygobject_new(G_OBJECT(instr));
+
+ if (has_python_method(pyobj, "_get_encoding"))
+ {
+ pyret = run_python_method(pyobj, "_get_encoding", NULL);
+
+ if (pyret != NULL)
+ {
+ if (!PyUnicode_Check(pyret))
+ log_variadic_message(LMT_ERROR, _("The returned raw name must be a string"));
+
+ else
+ result = strdup(PyUnicode_DATA(pyret));
+
+ }
+
+ Py_XDECREF(pyret);
+
+ }
+
+ Py_DECREF(pyobj);
+
+ PyGILState_Release(gstate);
+
+ return result;
}
@@ -209,15 +280,50 @@ static int py_arch_instruction_init(PyObject *self, PyObject *args, PyObject *kw
* *
******************************************************************************/
-static const char *py_arch_instruction_get_class_keyword(GArchInstruction *instr)
+static char *py_arch_instruction_get_keyword_wrapper(const GArchInstruction *instr)
{
- const char *result; /* Désignation à retourner */
- GQuark cache_key; /* Emplacement local */
+ char *result; /* Etiquette à retourner */
+ PyGILState_STATE gstate; /* Sauvegarde d'environnement */
+ PyObject *pyobj; /* Objet Python concerné */
+ PyObject *pyret; /* Bilan d'exécution */
+
+#define PLUGIN_MODULE_GET_KEYWORD_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _get_keyword, "$self, /", \
+ METH_NOARGS, \
+ "Abstract method giving the official name of the assembly" \
+ " instruction.\n" \
+ "\n" \
+ "The result should be the string value.\n" \
+)
+
+ result = NULL;
+
+ gstate = PyGILState_Ensure();
+
+ pyobj = pygobject_new(G_OBJECT(instr));
+
+ if (has_python_method(pyobj, "_get_keyword"))
+ {
+ pyret = run_python_method(pyobj, "_get_keyword", NULL);
+
+ if (pyret != NULL)
+ {
+ if (!PyUnicode_Check(pyret))
+ log_variadic_message(LMT_ERROR, _("The returned raw name must be a string"));
- cache_key = get_cached_keyword_quark();
+ else
+ result = strdup(PyUnicode_DATA(pyret));
- result = g_object_get_qdata(G_OBJECT(instr), cache_key);
- assert(result != NULL);
+ }
+
+ Py_XDECREF(pyret);
+
+ }
+
+ Py_DECREF(pyobj);
+
+ PyGILState_Release(gstate);
return result;
@@ -226,94 +332,201 @@ static const char *py_arch_instruction_get_class_keyword(GArchInstruction *instr
/* ---------------------------------------------------------------------------------- */
-/* MANIPULATION DES OPERANDES */
+/* DEFINITION DES LIAISONS ENTRE INSTRUCTIONS */
/* ---------------------------------------------------------------------------------- */
/******************************************************************************
* *
-* Paramètres : self = architecture concernée par la procédure. *
-* args = instruction représentant le point de départ. *
+* Paramètres : self = instruction d'architecture à manipuler. *
+* unused = adresse non utilisée ici. *
* *
-* Description : Attache un opérande supplémentaire à une instruction. *
+* Description : Fournit les origines d'une instruction donnée. *
* *
-* Retour : None. *
+* Retour : Nombre de ces origines. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_instruction_attach_extra_operand(PyObject *self, PyObject *args)
+static PyObject *py_arch_instruction_get_sources(PyObject *self, void *unused)
{
- GArchOperand *op; /* Opérande concerné à ajouter */
- int ret; /* Bilan de lecture des args. */
- GArchInstruction *instr; /* Instruction manipulée */
+ PyObject *result; /* Instance à retourner */
+ GArchInstruction *instr; /* Version native */
+ size_t count; /* Nombre de liens présents */
+ size_t i; /* Boucle de parcours */
- ret = PyArg_ParseTuple(args, "O&", convert_to_arch_operand, &op);
- if (!ret) return NULL;
+
+ GArchInstruction *src; /* Instruction en source */
+ InstructionLinkType src_type; /* Type de lien */
+ PyObject *linked; /* Source de lien Python */
+ PyObject *lnk_type; /* Nature du lien en Python */
+#ifndef NDEBUG
+ int ret; /* Bilan d'une écriture d'arg. */
+#endif
+
+#define ARCH_INSTRUCTION_SOURCES_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ sources, py_arch_instruction, \
+ "Provide the instructions list driving to the current instruction.\n" \
+ "\n" \
+ "Each item of the resulting tuple is a pair of" \
+ " pychrysalide.arch.ArchInstruction instance and" \
+ " pychrysalide.arch.ArchInstruction.InstructionLinkType value." \
+)
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- g_object_ref(G_OBJECT(op));
+ g_thick_object_lock(G_THICK_OBJECT(instr));
+
+ count = g_arch_instruction_count_src_links(instr);
+
+ result = PyTuple_New(count);
+
+ for (i = 0; i < count; i++)
+ {
+ src = g_arch_instruction_get_linked_source(instr, i, &src_type);
+
+ linked = pygobject_new(G_OBJECT(src));
+ lnk_type = cast_with_constants_group_from_type(get_python_arch_instruction_type(),
+ "InstructionLinkType", src_type);
+
+#ifndef NDEBUG
+ ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, lnk_type));
+ assert(ret == 0);
+#else
+ PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, lnk_type));
+#endif
+
+ unref_object(src);
+
+ }
- g_arch_instruction_attach_extra_operand(instr, op);
+ g_thick_object_unlock(G_THICK_OBJECT(instr));
- Py_RETURN_NONE;
+ return result;
}
/******************************************************************************
* *
-* Paramètres : self = objet représentant une instruction. *
+* Paramètres : self = instruction d'architecture à manipuler. *
* unused = adresse non utilisée ici. *
* *
-* Description : Fournit tous les opérandes d'une instruction. *
+* Description : Fournit les destinations d'une instruction donnée. *
* *
-* Retour : Valeur associée à la propriété consultée. *
+* Retour : Nombre de ces destinations. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_instruction_get_operands(PyObject *self, void *unused)
+static PyObject *py_arch_instruction_get_destinations(PyObject *self, void *unused)
{
PyObject *result; /* Instance à retourner */
GArchInstruction *instr; /* Version native */
- size_t count; /* Nombre d'opérandes présents */
+ size_t count; /* Nombre de liens présents */
size_t i; /* Boucle de parcours */
- GArchOperand *operand; /* Opérande à manipuler */
- PyObject *opobj; /* Version Python */
+ GArchInstruction *dest; /* Instruction en source */
+ InstructionLinkType dest_type; /* Type de lien */
+ PyObject *linked; /* Destination de lien Python */
+ PyObject *lnk_type; /* Nature du lien en Python */
#ifndef NDEBUG
int ret; /* Bilan d'une écriture d'arg. */
#endif
+#define ARCH_INSTRUCTION_DESTINATIONS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ destinations, py_arch_instruction, \
+ "Provide the instructions list following the current instruction.\n" \
+ "\n" \
+ "Each item of the resulting tuple is a pair of" \
+ " pychrysalide.arch.ArchInstruction instance and" \
+ " pychrysalide.arch.ArchInstruction.InstructionLinkType value." \
+)
+
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- g_arch_instruction_lock_operands(instr);
+ g_thick_object_lock(G_THICK_OBJECT(instr));
- count = _g_arch_instruction_count_operands(instr);
+ count = g_arch_instruction_count_dest_links(instr);
result = PyTuple_New(count);
for (i = 0; i < count; i++)
{
- operand = _g_arch_instruction_get_operand(instr, i);
+ dest = g_arch_instruction_get_linked_destination(instr, i, &dest_type);
- opobj = pygobject_new(G_OBJECT(operand));
+ linked = pygobject_new(G_OBJECT(dest));
+ lnk_type = cast_with_constants_group_from_type(get_python_arch_instruction_type(),
+ "InstructionLinkType", dest_type);
#ifndef NDEBUG
- ret = PyTuple_SetItem(result, i, Py_BuildValue("O", opobj));
+ ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, lnk_type));
assert(ret == 0);
#else
- PyTuple_SetItem(result, i, Py_BuildValue("O", opobj));
+ PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, lnk_type));
#endif
- g_object_unref(G_OBJECT(operand));
+ unref_object(dest);
}
- g_arch_instruction_unlock_operands(instr);
+ g_thick_object_unlock(G_THICK_OBJECT(instr));
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATION DES OPERANDES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Attache un opérande supplémentaire à une instruction. *
+* *
+* Retour : None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_attach_operand(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ GArchOperand *op; /* Opérande concerné à ajouter */
+ int ret; /* Bilan de lecture des args. */
+ GArchInstruction *instr; /* Instruction manipulée */
+
+#define ARCH_INSTRUCTION_ATTACH_OPERAND_METHOD PYTHON_METHOD_DEF \
+( \
+ attach_operand, "$self, operand, /", \
+ METH_VARARGS, py_arch_instruction, \
+ "Add an extra operand to an instruction.\n" \
+ "\n" \
+ "The instruction has to be locked during the instruction.\n" \
+ "\n" \
+ "The *operand* argument has to be a pychrysalide.arch.ArchOperand" \
+ " instance." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_arch_operand, &op);
+ if (!ret) return NULL;
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+
+ g_arch_instruction_attach_operand(instr, op);
+
+ result = Py_None;
+ Py_INCREF(result);
return result;
@@ -342,6 +555,21 @@ static PyObject *py_arch_instruction_replace_operand(PyObject *self, PyObject *a
GArchInstruction *instr; /* Instruction manipulée */
bool status; /* Bilan de l'opération */
+#define ARCH_INSTRUCTION_REPLACE_OPERAND_METHOD PYTHON_METHOD_DEF \
+( \
+ replace_operand, "$self, old, new, /", \
+ METH_VARARGS, py_arch_instruction, \
+ "Replace an old instruction operand by a another one.\n" \
+ "\n" \
+ "The instruction has to be locked during the instruction.\n" \
+ "\n" \
+ "Both the *old* and *new* arguments have to be a" \
+ " pychrysalide.arch.ArchOperand instance.\n" \
+ "\n" \
+ "The status of the operation is returned as a boolean value: *True*"\
+ " if the operand has been replaced, *False* in case of failure." \
+)
+
ret = PyArg_ParseTuple(args, "O&O&", convert_to_arch_operand, &old, convert_to_arch_operand, &new);
if (!ret) return NULL;
@@ -349,9 +577,6 @@ static PyObject *py_arch_instruction_replace_operand(PyObject *self, PyObject *a
status = g_arch_instruction_replace_operand(instr, old, new);
- if (status)
- g_object_ref(G_OBJECT(new));
-
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -381,6 +606,21 @@ static PyObject *py_arch_instruction_detach_operand(PyObject *self, PyObject *ar
GArchInstruction *instr; /* Instruction manipulée */
bool status; /* Bilan de l'opération */
+#define ARCH_INSTRUCTION_DETACH_OPERAND_METHOD PYTHON_METHOD_DEF \
+( \
+ detach_operand, "$self, operand, /", \
+ METH_VARARGS, py_arch_instruction, \
+ "Remove an operand from the instruction.\n" \
+ "\n" \
+ "The instruction has to be locked during the instruction.\n" \
+ "\n" \
+ "The *operand* argument has to be a pychrysalide.arch.ArchOperand" \
+ " instance.\n" \
+ "\n" \
+ "The status of the operation is returned as a boolean value: *True*"\
+ " if the operand has been removed, *False* in case of failure." \
+)
+
ret = PyArg_ParseTuple(args, "O&", convert_to_arch_operand, &target);
if (!ret) return NULL;
@@ -500,7 +740,7 @@ static PyObject *py_arch_instruction_get_operand_from_path(PyObject *self, PyObj
if (op != NULL)
{
result = pygobject_new(G_OBJECT(op));
- g_object_unref(G_OBJECT(op));
+ unref_object(op);
}
else
{
@@ -513,182 +753,258 @@ static PyObject *py_arch_instruction_get_operand_from_path(PyObject *self, PyObj
}
-
-/* ---------------------------------------------------------------------------------- */
-/* DEFINITION DES LIAISONS ENTRE INSTRUCTIONS */
-/* ---------------------------------------------------------------------------------- */
-
-
/******************************************************************************
* *
-* Paramètres : self = instruction d'architecture à manipuler. *
+* Paramètres : self = objet représentant une instruction. *
* unused = adresse non utilisée ici. *
* *
-* Description : Fournit les origines d'une instruction donnée. *
+* Description : Fournit tous les opérandes d'une instruction. *
* *
-* Retour : Nombre de ces origines. *
+* Retour : Valeur associée à la propriété consultée. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_instruction_get_sources(PyObject *self, void *unused)
+static PyObject *py_arch_instruction_get_operands(PyObject *self, void *unused)
{
PyObject *result; /* Instance à retourner */
GArchInstruction *instr; /* Version native */
- size_t count; /* Nombre de liens présents */
+ size_t count; /* Nombre d'opérandes présents */
size_t i; /* Boucle de parcours */
- const instr_link_t *source; /* Origine des liens */
- PyObject *linked; /* Source de lien Python */
- PyObject *type; /* Nature du lien en Python */
+ GArchOperand *operand; /* Opérande à manipuler */
+ PyObject *opobj; /* Version Python */
#ifndef NDEBUG
int ret; /* Bilan d'une écriture d'arg. */
#endif
-#define ARCH_INSTRUCTION_SOURCES_ATTRIB PYTHON_GET_DEF_FULL \
-( \
- sources, py_arch_instruction, \
- "Provide the instructions list driving to the current instruction.\n" \
- "\n" \
- "Each item of the resulting tuple is a pair of" \
- " pychrysalide.arch.ArchInstruction instance and" \
- " pychrysalide.arch.ArchInstruction.InstructionLinkType value." \
+#define ARCH_INSTRUCTION_OPERANDS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ operands, py_arch_instruction, \
+ "List of instruction attached operands.\n" \
+ "\n" \
+ "The result is a list of pychrysalide.arch.ArchOperand" \
+ " instances, which can be empty." \
)
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- g_arch_instruction_lock_src(instr);
+ g_thick_object_lock(G_THICK_OBJECT(instr));
- count = g_arch_instruction_count_sources(instr);
+ count = g_arch_instruction_count_operands(instr);
result = PyTuple_New(count);
for (i = 0; i < count; i++)
{
- source = g_arch_instruction_get_source(instr, i);
+ operand = g_arch_instruction_get_operand(instr, i);
- linked = pygobject_new(G_OBJECT(source->linked));
- type = cast_with_constants_group_from_type(get_python_arch_instruction_type(),
- "InstructionLinkType", source->type);
+ opobj = pygobject_new(G_OBJECT(operand));
#ifndef NDEBUG
- ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type));
+ ret = PyTuple_SetItem(result, i, Py_BuildValue("O", opobj));
assert(ret == 0);
#else
- PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type));
+ PyTuple_SetItem(result, i, Py_BuildValue("O", opobj));
#endif
- unref_instr_link(source);
+ unref_object(operand);
}
- g_arch_instruction_unlock_src(instr);
+ g_thick_object_unlock(G_THICK_OBJECT(instr));
return result;
}
+
+/* ---------------------------------------------------------------------------------- */
+/* LIAISON DE FONCTIONNALITES AVEC L'API PYTHON */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
-* Paramètres : self = instruction d'architecture à manipuler. *
-* unused = adresse non utilisée ici. *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
* *
-* Description : Fournit les destinations d'une instruction donnée. *
+* Description : Ajoute une information complémentaire à une instruction. *
* *
-* Retour : Nombre de ces destinations. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_instruction_get_destinations(PyObject *self, void *unused)
+static PyObject *py_arch_instruction_set_flag(PyObject *self, PyObject *args)
{
- PyObject *result; /* Instance à retourner */
- GArchInstruction *instr; /* Version native */
- size_t count; /* Nombre de liens présents */
- size_t i; /* Boucle de parcours */
- const instr_link_t *dest; /* Destination des liens */
- PyObject *linked; /* Destination de lien Python */
- PyObject *type; /* Nature du lien en Python */
-#ifndef NDEBUG
- int ret; /* Bilan d'une écriture d'arg. */
-#endif
-
-#define ARCH_INSTRUCTION_DESTINATIONS_ATTRIB PYTHON_GET_DEF_FULL \
-( \
- destinations, py_arch_instruction, \
- "Provide the instructions list following the current instruction.\n" \
- "\n" \
- "Each item of the resulting tuple is a pair of" \
- " pychrysalide.arch.ArchInstruction instance and" \
- " pychrysalide.arch.ArchInstruction.InstructionLinkType value." \
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Fanion(s) à appliquer */
+ int ret; /* Bilan de lecture des args. */
+ GArchInstruction *instr; /* Instruction manipulée */
+ bool status; /* Bilan à transmettre */
+
+#define ARCH_INSTRUCTION_SET_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ set_flag, "$self, flag, /", \
+ METH_VARARGS, py_arch_instruction, \
+ "Add some flags to the instruction.\n" \
+ "\n" \
+ "This *flag* argument is an integer value containing" \
+ " bits to apply to the instruction state.\n" \
+ "\n" \
+ "The result is an boolean status: *True* for operation" \
+ " success, *False* otherwise." \
)
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- g_arch_instruction_lock_dest(instr);
+ status = g_arch_instruction_set_flag(instr, flag);
- count = g_arch_instruction_count_destinations(instr);
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
- result = PyTuple_New(count);
+ return result;
- for (i = 0; i < count; i++)
- {
- dest = g_arch_instruction_get_destination(instr, i);
+}
- linked = pygobject_new(G_OBJECT(dest->linked));
- type = cast_with_constants_group_from_type(get_python_arch_instruction_type(),
- "InstructionLinkType", dest->type);
-#ifndef NDEBUG
- ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type));
- assert(ret == 0);
-#else
- PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type));
-#endif
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Retire une information complémentaire à une instruction. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_instruction_unset_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Fanion(s) à appliquer */
+ int ret; /* Bilan de lecture des args. */
+ GArchInstruction *instr; /* Instruction manipulée */
+ bool status; /* Bilan à transmettre */
+
+#define ARCH_INSTRUCTION_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ unset_flag, "$self, flag, /", \
+ METH_VARARGS, py_arch_instruction, \
+ "Remove some flags from the instruction.\n" \
+ "\n" \
+ "This *flag* argument is an integer value containing" \
+ " bits to delete from the instruction state.\n" \
+ "\n" \
+ "The result is an boolean status: *True* for operation" \
+ " success, *False* otherwise." \
+)
- unref_instr_link(dest);
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
- }
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- g_arch_instruction_unlock_dest(instr);
+ status = g_arch_instruction_unset_flag(instr, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
return result;
}
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Détermine si une instruction possède un fanion particulier. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
-/* ---------------------------------------------------------------------------------- */
-/* INSTRUCTIONS D'ARCHITECTURES EN PYTHON */
-/* ---------------------------------------------------------------------------------- */
+static PyObject *py_arch_instruction_has_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Fanion(s) à appliquer */
+ int ret; /* Bilan de lecture des args. */
+ GArchInstruction *instr; /* Instruction manipulée */
+ bool status; /* Bilan à transmettre */
+
+#define ARCH_INSTRUCTION_HAS_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ has_flag, "$self, flag, /", \
+ METH_VARARGS, py_arch_instruction, \
+ "Tell if some flags are set for the instruction.\n" \
+ "\n" \
+ "This *flag* argument is an integer value containing" \
+ " bits to test for the instruction state.\n" \
+ "\n" \
+ "The result is an boolean status: *True* if the bits" \
+ " are active, *False* otherwise." \
+)
+
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
+
+ status = g_arch_instruction_has_flag(instr, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
/******************************************************************************
* *
-* Paramètres : self = classe représentant une instruction. *
-* closure = adresse non utilisée ici. *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
* *
-* Description : Fournit l'identifiant unique pour un ensemble d'instructions.*
+* Description : Fournit l'identifiant correspondant à un type d'instructions.*
* *
-* Retour : Identifiant unique par type d'instruction. *
+* Retour : Identifiant unique par type d'instruction et architecture. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_instruction_get_unique_id(PyObject *self, void *closure)
+static PyObject *py_arch_instruction_get_type_id(PyObject *self, void *closure)
{
- PyObject *result; /* Conversion à retourner */
- GArchInstruction *instr; /* Version native */
- itid_t uid; /* Identifiant unique associé */
+ PyObject *result; /* Valeur à retourner */
+ GArchInstruction *instr; /* Instruction manipulée */
+ itid_t tid; /* Identifiant à transmettre */
+
+#define ARCH_INSTRUCTION_TYPE_ID_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ type_id, py_arch_instruction, \
+ "Provide the unique identifier given to this kind of" \
+ " instruction.\n" \
+ "\n" \
+ "The returned value is an integer." \
+)
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- uid = g_arch_instruction_get_unique_id(instr);
+ tid = g_arch_instruction_get_type_id(instr);
- result = PyLong_FromUnsignedLong(uid);
+ result = PyLong_FromUnsignedLong(tid);
return result;
@@ -697,27 +1013,61 @@ static PyObject *py_arch_instruction_get_unique_id(PyObject *self, void *closure
/******************************************************************************
* *
-* Paramètres : self = classe représentant une instruction. *
-* closure = adresse non utilisée ici. *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
* *
-* Description : Fournit la place mémoire d'une instruction. *
+* Description : Indique l'encodage d'une instruction de façon détaillée. *
* *
-* Retour : Valeur associée à la propriété consultée. *
+* Retour : Description humaine de l'encodage utilisé. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_instruction_get_range(PyObject *self, void *closure)
+static PyObject *py_arch_instruction_get_encoding(PyObject *self, void *closure)
{
- PyObject *result; /* Conversion à retourner */
- GArchInstruction *instr; /* Version native */
- const mrange_t *range; /* Espace mémoire à exporter */
+ PyObject *result; /* Valeur à retourner */
+ GArchInstruction *instr; /* Instruction manipulée */
+ char *encoding; /* Encodage d'une instruction */
+
+#define ARCH_INSTRUCTION_ENCODING_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ encoding, py_arch_instruction, \
+ "Describe the encoding related to an instruction.\n" \
+ "\n" \
+ "The returned value is an arbitrary string value." \
+)
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- range = g_arch_instruction_get_range(instr);
- result = build_from_internal_mrange(range);
+ encoding = g_arch_instruction_get_encoding(instr);
+
+ if (encoding != NULL)
+ {
+ result = PyUnicode_FromString(encoding);
+
+ free(encoding);
+
+ }
+
+ else
+ {
+ /**
+ * La méthode de classe sollicitée a renvoyé une valeur nulle.
+ *
+ * Si cette méthode correspond à une implémentation Python
+ * (avec un appel à not_yet_implemented_method()), une exception
+ * est déjà en place.
+ *
+ * Si aucune exception n'a été prévue, un rattrapage est effectué ici.
+ */
+
+ if (PyErr_Occurred() == NULL)
+ PyErr_SetString(PyExc_NotImplementedError, _("unexpected NULL value as encoding"));
+
+ result = NULL;
+
+ }
return result;
@@ -727,59 +1077,108 @@ static PyObject *py_arch_instruction_get_range(PyObject *self, void *closure)
/******************************************************************************
* *
* Paramètres : self = objet Python concerné par l'appel. *
-* value = valeur fournie à intégrer ou prendre en compte. *
-* closure = adresse non utilisée ici. *
+* closure = non utilisé ici. *
* *
-* Description : Définit la localisation d'une instruction. *
+* Description : Indique l'encodage d'une instruction de façon détaillée. *
* *
-* Retour : Bilan de l'opération pour Python. *
+* Retour : Description humaine de l'encodage utilisé. *
* *
* Remarques : - *
* *
******************************************************************************/
-static int py_arch_instruction_set_range(PyObject *self, PyObject *value, void *closure)
+static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *closure)
{
- int ret; /* Bilan d'analyse */
- mrange_t *range; /* Espace mémoire à manipuler */
- GArchInstruction *instr; /* Version native */
+ PyObject *result; /* Valeur à retourner */
+ GArchInstruction *instr; /* Instruction manipulée */
+ char *keyword; /* Désignation d'une instruct° */
+
+#define ARCH_INSTRUCTION_KEYWORD_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ keyword, py_arch_instruction, \
+ "Give the official name of the assembly instruction.\n" \
+ "\n" \
+ "The returned value is a string value." \
+)
- ret = PyObject_IsInstance(value, (PyObject *)get_python_mrange_type());
- if (!ret) return -1;
+ instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- range = get_internal_mrange(value);
+ keyword = g_arch_instruction_get_keyword(instr);
- instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- g_arch_instruction_set_range(instr, range);
+ if (keyword != NULL)
+ {
+ result = PyUnicode_FromString(keyword);
- return 0;
+ free(keyword);
+
+ }
+
+ else
+ {
+ /**
+ * La méthode de classe sollicitée a renvoyé une valeur nulle.
+ *
+ * Si cette méthode correspond à une implémentation Python
+ * (avec un appel à not_yet_implemented_method()), une exception
+ * est déjà en place.
+ *
+ * Si aucune exception n'a été prévue, un rattrapage est effectué ici.
+ */
+
+ if (PyErr_Occurred() == NULL)
+ PyErr_SetString(PyExc_NotImplementedError, _("unexpected NULL value as keyword"));
+
+ result = NULL;
+
+ }
+
+ return result;
}
/******************************************************************************
* *
-* Paramètres : self = classe représentant une instruction. *
-* unused = adresse non utilisée ici. *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
* *
-* Description : Fournit le nom humain de l'instruction manipulée. *
+* Description : Fournit la place mémoire d'une instruction. *
* *
-* Retour : Valeur associée à la propriété consultée. *
+* Retour : Définition de localisation ou *None*. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *unused)
+static PyObject *py_arch_instruction_get_range(PyObject *self, void *closure)
{
- PyObject *result; /* Trouvailles à retourner */
- GArchInstruction *instr; /* Version native */
- const char *kw; /* Valeur récupérée */
+ PyObject *result; /* Valeur à retourner */
+ GArchInstruction *instr; /* Instruction manipulée */
+ mrange_t range; /* Localisation d'instruction */
+ bool valid; /* Validité de la localisation */
+
+#define ARCH_INSTRUCTION_RANGE_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ range, py_arch_instruction, \
+ "Give access to the memory range covered by the" \
+ " current instruction.\n" \
+ "\n" \
+ "The returned value is a pychrysalide.arch.mrange" \
+ " instance or *None* if no location is currently" \
+ " defined." \
+)
instr = G_ARCH_INSTRUCTION(pygobject_get(self));
- kw = g_arch_instruction_get_keyword(instr);
- result = PyUnicode_FromString(kw);
+ valid = g_arch_instruction_get_range(instr, &range);
+
+ if (valid)
+ result = build_from_internal_mrange(&range);
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
return result;
@@ -801,45 +1200,25 @@ static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *unused)
PyTypeObject *get_python_arch_instruction_type(void)
{
static PyMethodDef py_arch_instruction_methods[] = {
- {
- "attach_operand", py_arch_instruction_attach_extra_operand,
- METH_VARARGS,
- "attach_operand($self, op, /)\n--\n\nAdd a new operand to the instruction."
- },
- {
- "replace_operand", py_arch_instruction_replace_operand,
- METH_VARARGS,
- "replace_operand($self, old, new, /)\n--\n\nReplace an old instruction operand by a another one."
- },
- {
- "detach_operand", py_arch_instruction_detach_operand,
- METH_VARARGS,
- "detach_operand($self, target, /)\n--\n\nRemove an operand from the instruction."
- },
+ ARCH_INSTRUCTION_ATTACH_OPERAND_METHOD,
+ ARCH_INSTRUCTION_REPLACE_OPERAND_METHOD,
+ ARCH_INSTRUCTION_DETACH_OPERAND_METHOD,
ARCH_INSTRUCTION_FIND_OPERAND_PATH_METHOD,
ARCH_INSTRUCTION_GET_OPERAND_FROM_PATH_METHOD,
+ ARCH_INSTRUCTION_SET_FLAG_METHOD,
+ ARCH_INSTRUCTION_UNSET_FLAG_METHOD,
+ ARCH_INSTRUCTION_HAS_FLAG_METHOD,
{ NULL }
};
static PyGetSetDef py_arch_instruction_getseters[] = {
- {
- "uid", py_arch_instruction_get_unique_id, NULL,
- "Provide the unique identification number given to this kind of instruction.", NULL
- },
- {
- "range", py_arch_instruction_get_range, py_arch_instruction_set_range,
- "Give access to the memory range covered by the current instruction.", NULL
- },
- {
- "keyword", (getter)py_arch_instruction_get_keyword, (setter)NULL,
- "Give le name of the assembly instruction.", NULL
- },
- {
- "operands", (getter)py_arch_instruction_get_operands, (setter)NULL,
- "Provide the list of instruction attached operands.", NULL
- },
ARCH_INSTRUCTION_SOURCES_ATTRIB,
ARCH_INSTRUCTION_DESTINATIONS_ATTRIB,
+ ARCH_INSTRUCTION_OPERANDS_ATTRIB,
+ ARCH_INSTRUCTION_TYPE_ID_ATTRIB,
+ ARCH_INSTRUCTION_ENCODING_ATTRIB,
+ ARCH_INSTRUCTION_KEYWORD_ATTRIB,
+ ARCH_INSTRUCTION_RANGE_ATTRIB,
{ NULL }
};
@@ -852,7 +1231,7 @@ PyTypeObject *get_python_arch_instruction_type(void)
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE,
- .tp_doc = "PyChrysalide instruction for a given architecture.",
+ .tp_doc = ARCH_INSTRUCTION_DOC,
.tp_methods = py_arch_instruction_methods,
.tp_getset = py_arch_instruction_getseters,
@@ -893,9 +1272,14 @@ bool ensure_python_arch_instruction_is_registered(void)
dict = PyModule_GetDict(module);
- if (!ensure_python_line_generator_is_registered())
+ if (!ensure_python_thick_object_is_registered())
return false;
+ if (!ensure_python_serializable_object_is_registered())
+ return false;
+
+ pyg_register_class_init(G_TYPE_ARCH_INSTRUCTION, (PyGClassInitFunc)py_arch_instruction_init_gclass);
+
if (!register_class_for_pygobject(dict, G_TYPE_ARCH_INSTRUCTION, type))
return false;
diff --git a/plugins/pychrysalide/arch/instructions/Makefile.am b/plugins/pychrysalide/arch/instructions/Makefile.am
index 65efe42..29c2a45 100644
--- a/plugins/pychrysalide/arch/instructions/Makefile.am
+++ b/plugins/pychrysalide/arch/instructions/Makefile.am
@@ -7,7 +7,8 @@ libpychrysaarchinstructions_la_SOURCES = \
raw.h raw.c \
undefined.h undefined.c
-libpychrysaarchinstructions_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+libpychrysaarchinstructions_la_CFLAGS = $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+ $(TOOLKIT_CFLAGS) \
-I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT
diff --git a/plugins/pychrysalide/arch/instructions/constants.c b/plugins/pychrysalide/arch/instructions/constants.c
index af7baa9..257c501 100644
--- a/plugins/pychrysalide/arch/instructions/constants.c
+++ b/plugins/pychrysalide/arch/instructions/constants.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* constants.c - ajout des constantes de base pour les instructions
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -112,3 +112,59 @@ bool define_undefined_instruction_constants(PyTypeObject *type)
return result;
}
+
+
+/******************************************************************************
+* *
+* 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 constante ExpectedBehavior. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_undefined_expected_behavior(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+ unsigned long value; /* Valeur récupérée */
+
+ result = PyObject_IsInstance(arg, (PyObject *)&PyLong_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 ExpectedBehavior");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if (value > IEB_RESERVED)
+ {
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to ExpectedBehavior");
+ result = 0;
+ }
+
+ else
+ *((InstrExpectedBehavior *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/arch/instructions/constants.h b/plugins/pychrysalide/arch/instructions/constants.h
index 2f0c587..b6ef9a4 100644
--- a/plugins/pychrysalide/arch/instructions/constants.h
+++ b/plugins/pychrysalide/arch/instructions/constants.h
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* constants.h - prototypes pour l'ajout des constantes de base pour les instructions
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -37,6 +37,9 @@ bool define_raw_instruction_constants(PyTypeObject *);
/* Définit les constantes liées aux comportements erratiques. */
bool define_undefined_instruction_constants(PyTypeObject *);
+/* Tente de convertir en constante ExpectedBehavior. */
+int convert_to_undefined_expected_behavior(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_CONSTANTS_H */
diff --git a/plugins/pychrysalide/arch/instructions/raw.c b/plugins/pychrysalide/arch/instructions/raw.c
index 7e58b96..ae730e8 100644
--- a/plugins/pychrysalide/arch/instructions/raw.c
+++ b/plugins/pychrysalide/arch/instructions/raw.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* raw.c - équivalent Python du fichier "arch/instructions/raw.h"
*
- * Copyright (C) 2018-2020 Cyrille Bagard
+ * Copyright (C) 2018-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -28,26 +28,33 @@
#include <pygobject.h>
-#include <i18n.h>
-#include <arch/instructions/raw.h>
-#include <plugins/dt.h>
+#include <arch/instructions/raw-int.h>
#include "constants.h"
#include "../instruction.h"
#include "../vmpa.h"
#include "../../access.h"
+#include "../../constants.h"
#include "../../helpers.h"
#include "../../analysis/content.h"
+#include "../../glibext/portion.h"
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_raw_instruction_new(PyTypeObject *, PyObject *, PyObject *);
+/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
+
+
+CREATE_DYN_CONSTRUCTOR(raw_instruction, G_TYPE_RAW_INSTRUCTION);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_raw_instruction_init(PyObject *, PyObject *, PyObject *);
+
+
+/* ------------------------ FONCTIONNALITES DE L'INSTRUCTION ------------------------ */
+
+
/* Indique si le contenu de l'instruction est du bourrage. */
static PyObject *py_raw_instruction_get_padding(PyObject *, void *);
@@ -62,64 +69,9 @@ static int py_raw_instruction_set_string(PyObject *, PyObject *, void *);
-/******************************************************************************
-* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_raw_instruction_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* Validations diverses */
-
- base = get_python_raw_instruction_type();
-
- if (type == base)
- goto simple_way;
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_RAW_INSTRUCTION, type->tp_name, NULL, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
-
- if (!status)
- {
- result = NULL;
- goto exit;
- }
-
- }
-
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
-
- simple_way:
-
- result = PyType_GenericNew(type, args, kwds);
-
- exit:
-
- return result;
-
-}
+/* ---------------------------------------------------------------------------------- */
+/* GLUE POUR CREATION DEPUIS PYTHON */
+/* ---------------------------------------------------------------------------------- */
/******************************************************************************
@@ -139,20 +91,17 @@ static PyObject *py_raw_instruction_new(PyTypeObject *type, PyObject *args, PyOb
static int py_raw_instruction_init(PyObject *self, PyObject *args, PyObject *kwds)
{
int result; /* Bilan à retourner */
+ GBinaryPortion *area; /* Zone de contenance */
vmpa2t *addr; /* Texte de lecture */
- unsigned long mem_size; /* Taille de portion brute */
+ MemoryDataSize size; /* Taille de portion brute */
unsigned long long value; /* Valeur brute à considérer */
GBinContent *content; /* Contenu à lire au besoin */
unsigned long count; /* Nombre d'éléments à lister */
- unsigned int endian; /* Type de boutisme impliqué */
+ SourceEndian endian; /* Type de boutisme impliqué */
int ret; /* Bilan de lecture des args. */
- GArchInstruction *fake; /* Instruction à copier */
- GArchInstruction *instr; /* Instruction à manipuler */
- size_t op_count; /* Nombre d'opérande à copier */
- size_t i; /* Boucle de parcours */
- GArchOperand *op; /* Opérande à transférer */
+ GRawInstruction *instr; /* Instruction à manipuler */
- static char *kwlist[] = { "addr", "mem_size", "value", "content", "count", "endian", NULL };
+ static char *kwlist[] = { "area", "addr", "size", "value", "content", "count", "endian", NULL };
#define RAW_INSTRUCTION_DOC \
"The RawInstruction object handles data which is not (yet?) disassembled" \
@@ -187,9 +136,14 @@ static int py_raw_instruction_init(PyObject *self, PyObject *args, PyObject *kwd
count = 0;
endian = 0;
- ret = PyArg_ParseTupleAndKeywords(args, kwds, "O&k|KO&kI", kwlist,
- convert_any_to_vmpa, &addr, &mem_size,
- &value, convert_to_binary_content, &content, &count, &endian);
+ ret = PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&|KO&kO&", kwlist,
+ convert_to_binary_portion, &area,
+ convert_any_to_vmpa, &addr,
+ convert_to_memory_data_size, &size,
+ &value,
+ convert_to_binary_content, &content,
+ &count,
+ convert_to_source_endian, &endian);
if (!ret) return -1;
/* Initialisation d'un objet GLib */
@@ -199,35 +153,19 @@ static int py_raw_instruction_init(PyObject *self, PyObject *args, PyObject *kwd
/* Eléments de base */
- if (content != NULL)
- fake = g_raw_instruction_new_array(content, mem_size, count, addr, endian);
- else
- fake = g_raw_instruction_new_from_value(addr, mem_size, value);
+ instr = G_RAW_INSTRUCTION(pygobject_get(self));
- if (fake == NULL)
+ if (content != NULL)
{
- PyErr_SetString(PyExc_ValueError, _("Unable to build the object with the given parameters."));
- goto clean_exit;
+ if (!g_raw_instruction_create_array(instr, area, addr, size, content, count, endian))
+ goto clean_exit;
}
-
- instr = G_ARCH_INSTRUCTION(pygobject_get(self));
-
- g_arch_instruction_lock_operands(fake);
-
- op_count = _g_arch_instruction_count_operands(fake);
-
- for (i = 0; i < op_count; i++)
+ else
{
- op = _g_arch_instruction_get_operand(fake, i);
- g_arch_instruction_attach_extra_operand(instr, op);
+ if (!g_raw_instruction_create_value(instr, area, addr, size, value))
+ goto clean_exit;
}
- g_arch_instruction_unlock_operands(fake);
-
- g_arch_instruction_set_range(instr, g_arch_instruction_get_range(fake));
-
- g_object_unref(G_OBJECT(fake));
-
result = 0;
clean_exit:
@@ -239,6 +177,12 @@ static int py_raw_instruction_init(PyObject *self, PyObject *args, PyObject *kwd
}
+
+/* ---------------------------------------------------------------------------------- */
+/* FONCTIONNALITES DE L'INSTRUCTION */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
* Paramètres : self = classe représentant une instruction. *
@@ -271,7 +215,6 @@ static PyObject *py_raw_instruction_get_padding(PyObject *self, void *closure)
result = state ? Py_True : Py_False;
Py_INCREF(result);
-
return result;
}
@@ -342,7 +285,6 @@ static PyObject *py_raw_instruction_get_string(PyObject *self, void *closure)
result = state ? Py_True : Py_False;
Py_INCREF(result);
-
return result;
}
diff --git a/plugins/pychrysalide/arch/instructions/undefined.c b/plugins/pychrysalide/arch/instructions/undefined.c
index 1246daa..1c2bccc 100644
--- a/plugins/pychrysalide/arch/instructions/undefined.c
+++ b/plugins/pychrysalide/arch/instructions/undefined.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* undefined.c - équivalent Python du fichier "arch/instructions/undefined.h"
*
- * Copyright (C) 2019 Cyrille Bagard
+ * Copyright (C) 2019-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -28,9 +28,7 @@
#include <pygobject.h>
-#include <i18n.h>
#include <arch/instructions/undefined-int.h>
-#include <plugins/dt.h>
#include "constants.h"
@@ -40,75 +38,27 @@
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_undef_instruction_new(PyTypeObject *, PyObject *, PyObject *);
+/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Initialise une instance sur la base du dérivé de GObject. */
-static int py_undef_instruction_init(PyObject *, PyObject *, PyObject *);
-
-/* Indique le type de conséquences réél de l'instruction. */
-static PyObject *py_undef_instruction_get_behavior(PyObject *, void *);
-
-
-
-/******************************************************************************
-* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_undef_instruction_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* Validations diverses */
- base = get_python_undefined_instruction_type();
+CREATE_DYN_CONSTRUCTOR(undefined_instruction, G_TYPE_UNDEFINED_INSTRUCTION);
- if (type == base)
- goto simple_way;
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_UNDEF_INSTRUCTION, type->tp_name, NULL, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_undefined_instruction_init(PyObject *, PyObject *, PyObject *);
- if (!status)
- {
- result = NULL;
- goto exit;
- }
- }
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
+/* ------------------------ FONCTIONNALITES DE L'INSTRUCTION ------------------------ */
- simple_way:
- result = PyType_GenericNew(type, args, kwds);
+/* Indique le type de conséquences réél de l'instruction. */
+static PyObject *py_undefined_instruction_get_behavior(PyObject *, void *);
- exit:
- return result;
-}
+/* ---------------------------------------------------------------------------------- */
+/* GLUE POUR CREATION DEPUIS PYTHON */
+/* ---------------------------------------------------------------------------------- */
/******************************************************************************
@@ -125,30 +75,27 @@ static PyObject *py_undef_instruction_new(PyTypeObject *type, PyObject *args, Py
* *
******************************************************************************/
-static int py_undef_instruction_init(PyObject *self, PyObject *args, PyObject *kwds)
+static int py_undefined_instruction_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- unsigned long behavior; /* Conséquence pour l'instruct°*/
+ InstrExpectedBehavior behavior; /* Conséquence pour l'instruct°*/
int ret; /* Bilan de lecture des args. */
- GUndefInstruction *instr; /* Instruction à manipuler */
- undef_extra_data_t *extra; /* Données insérées à modifier */
+ GUndefinedInstruction *instr; /* Instruction à manipuler */
- static char *kwlist[] = { "behavior", NULL };
-
-#define UNDEF_INSTRUCTION_DOC \
- "UndefInstruction represents all kinds of instructions which are" \
+#define UNDEFINED_INSTRUCTION_DOC \
+ "UndefinedInstruction represents all kinds of instructions which are" \
" officially not part of a runnable instruction set.\n" \
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " UndefInstruction(behavior)" \
+ " UndefinedInstruction(behavior)" \
"\n" \
"Where behavior is a" \
- " pychrysalide.arch.instructions.UndefInstruction.ExpectedBehavior" \
+ " pychrysalide.arch.instructions.UndefinedInstruction.ExpectedBehavior" \
" constant describing the state of the CPU once the instruction is run."
/* Récupération des paramètres */
- ret = PyArg_ParseTupleAndKeywords(args, kwds, "k", kwlist, &behavior);
+ ret = PyArg_ParseTuple(args, "O&", convert_to_undefined_expected_behavior, &behavior);
if (!ret) return -1;
/* Initialisation d'un objet GLib */
@@ -158,17 +105,22 @@ static int py_undef_instruction_init(PyObject *self, PyObject *args, PyObject *k
/* Eléments de base */
- instr = G_UNDEF_INSTRUCTION(pygobject_get(self));
-
- extra = GET_UNDEF_INSTR_EXTRA(instr);
+ instr = G_UNDEFINED_INSTRUCTION(pygobject_get(self));
- extra->behavior = behavior;
+ if (!g_undefined_instruction_create(instr, behavior))
+ return -1;
return 0;
}
+
+/* ---------------------------------------------------------------------------------- */
+/* FONCTIONNALITES DE L'INSTRUCTION */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
* Paramètres : self = classe représentant une instruction. *
@@ -182,24 +134,25 @@ static int py_undef_instruction_init(PyObject *self, PyObject *args, PyObject *k
* *
******************************************************************************/
-static PyObject *py_undef_instruction_get_behavior(PyObject *self, void *closure)
+static PyObject *py_undefined_instruction_get_behavior(PyObject *self, void *closure)
{
PyObject *result; /* Conversion à retourner */
- GUndefInstruction *instr; /* Version native */
+ GUndefinedInstruction *instr; /* Version native */
InstrExpectedBehavior behavior; /* Comportement attendu */
-#define UNDEF_INSTRUCTION_BEHAVIOR_ATTRIB PYTHON_GET_DEF_FULL \
-( \
- behavior, py_undef_instruction, \
- "Consequence carried by the undefined instruction.\n" \
- "\n" \
- "The result is provided as a" \
- " pychrysalide.arch.instructions.UndefInstruction.ExpectedBehavior" \
- " constant." \
+#define UNDEFINED_INSTRUCTION_BEHAVIOR_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ behavior, py_undefined_instruction, \
+ "Consequence carried by the undefined instruction.\n" \
+ "\n" \
+ "The result is provided as a" \
+ " pychrysalide.arch.instructions.UndefinedInstruction.ExpectedBehavior" \
+ " constant." \
)
- instr = G_UNDEF_INSTRUCTION(pygobject_get(self));
- behavior = g_undef_instruction_get_behavior(instr);
+ instr = G_UNDEFINED_INSTRUCTION(pygobject_get(self));
+
+ behavior = g_undefined_instruction_get_behavior(instr);
result = cast_with_constants_group_from_type(get_python_undefined_instruction_type(),
"ExpectedBehavior", behavior);
@@ -228,7 +181,7 @@ PyTypeObject *get_python_undefined_instruction_type(void)
};
static PyGetSetDef py_undefined_instruction_getseters[] = {
- UNDEF_INSTRUCTION_BEHAVIOR_ATTRIB,
+ UNDEFINED_INSTRUCTION_BEHAVIOR_ATTRIB,
{ NULL }
};
@@ -236,18 +189,18 @@ PyTypeObject *get_python_undefined_instruction_type(void)
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.arch.instructions.UndefInstruction",
+ .tp_name = "pychrysalide.arch.instructions.UndefinedInstruction",
.tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = UNDEF_INSTRUCTION_DOC,
+ .tp_doc = UNDEFINED_INSTRUCTION_DOC,
.tp_methods = py_undefined_instruction_methods,
.tp_getset = py_undefined_instruction_getseters,
- .tp_init = py_undef_instruction_init,
- .tp_new = py_undef_instruction_new,
+ .tp_init = py_undefined_instruction_init,
+ .tp_new = py_undefined_instruction_new,
};
@@ -260,7 +213,7 @@ PyTypeObject *get_python_undefined_instruction_type(void)
* *
* Paramètres : module = module dont la définition est à compléter. *
* *
-* Description : Prend en charge l'objet 'pychrysalide.....UndefInstruction'. *
+* Description : Prend en charge l'objet '....UndefinedInstruction'. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -285,7 +238,7 @@ bool ensure_python_undefined_instruction_is_registered(void)
if (!ensure_python_arch_instruction_is_registered())
return false;
- if (!register_class_for_pygobject(dict, G_TYPE_UNDEF_INSTRUCTION, type))
+ if (!register_class_for_pygobject(dict, G_TYPE_UNDEFINED_INSTRUCTION, type))
return false;
if (!define_undefined_instruction_constants(type))
@@ -329,7 +282,7 @@ int convert_to_undefined_instruction(PyObject *arg, void *dst)
break;
case 1:
- *((GUndefInstruction **)dst) = G_UNDEF_INSTRUCTION(pygobject_get(arg));
+ *((GUndefinedInstruction **)dst) = G_UNDEFINED_INSTRUCTION(pygobject_get(arg));
break;
default:
diff --git a/plugins/pychrysalide/arch/instructions/undefined.h b/plugins/pychrysalide/arch/instructions/undefined.h
index 3fa0453..1453612 100644
--- a/plugins/pychrysalide/arch/instructions/undefined.h
+++ b/plugins/pychrysalide/arch/instructions/undefined.h
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* undefined.h - prototypes pour l'équivalent Python du fichier "arch/instructions/undefined.h"
*
- * Copyright (C) 2019 Cyrille Bagard
+ * Copyright (C) 2019-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -34,7 +34,7 @@
/* Fournit un accès à une définition de type à diffuser. */
PyTypeObject *get_python_undefined_instruction_type(void);
-/* Prend en charge l'objet 'pychrysalide.arch.instructions.UndefInstruction'. */
+/* Prend en charge l'objet 'pychrysalide.arch.instructions.UndefinedInstruction'. */
bool ensure_python_undefined_instruction_is_registered(void);
/* Tente de convertir en instruction non définie. */
diff --git a/plugins/pychrysalide/arch/module-ui.c b/plugins/pychrysalide/arch/module-ui.c
new file mode 100644
index 0000000..65d1290
--- /dev/null
+++ b/plugins/pychrysalide/arch/module-ui.c
@@ -0,0 +1,66 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.c - intégration du répertoire arch (forme graphique) en tant que module
+ *
+ * Copyright (C) 2025 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "module-ui.h"
+
+
+#include <assert.h>
+
+
+#include "operand-ui.h"
+#include "../glibext/generator.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Intègre les objets du module 'arch' (mode UI). *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool populate_arch_module_ui(void)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ if (result) result = ensure_python_arch_operand_ui_is_registered();
+
+ /**
+ * Préparation du terrain pour les instructions, sans lien directe
+ * de la partie UI depuis la partie NOX.
+ */
+ if (result) result = ensure_python_token_generator_is_registered();
+
+ assert(result);
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/arch/module-ui.h b/plugins/pychrysalide/arch/module-ui.h
new file mode 100644
index 0000000..afa31d2
--- /dev/null
+++ b/plugins/pychrysalide/arch/module-ui.h
@@ -0,0 +1,38 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * module.h - prototypes pour l'intégration du répertoire arch (forme graphique) en tant que module
+ *
+ * Copyright (C) 2025 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_UI_H
+#define _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_UI_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+/* Intègre les objets du module 'arch' (mode UI). */
+bool populate_arch_module_ui(void);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_UI_H */
diff --git a/plugins/pychrysalide/arch/module.c b/plugins/pychrysalide/arch/module.c
index bbdaf76..94f5ad7 100644
--- a/plugins/pychrysalide/arch/module.c
+++ b/plugins/pychrysalide/arch/module.c
@@ -28,22 +28,17 @@
#include <assert.h>
-#include <arch/archbase.h>
-
-
/*
#include "context.h"
#include "instriter.h"
+*/
#include "instruction.h"
#include "operand.h"
-#include "processor.h"
+//#include "processor.h"
#include "register.h"
-*/
#include "vmpa.h"
-/*
#include "instructions/module.h"
#include "operands/module.h"
-*/
#include "../helpers.h"
@@ -80,10 +75,8 @@ bool add_arch_module(PyObject *super)
result = (module != NULL);
- /*
if (result) result = add_arch_instructions_module(module);
if (result) result = add_arch_operands_module(module);
- */
return result;
@@ -111,18 +104,16 @@ bool populate_arch_module(void)
/*
if (result) result = ensure_python_proc_context_is_registered();
if (result) result = ensure_python_instr_iterator_is_registered();
+ */
if (result) result = ensure_python_arch_instruction_is_registered();
if (result) result = ensure_python_arch_operand_is_registered();
- if (result) result = ensure_python_arch_processor_is_registered();
+ //if (result) result = ensure_python_arch_processor_is_registered();
if (result) result = ensure_python_arch_register_is_registered();
- */
if (result) result = ensure_python_vmpa_is_registered();
if (result) result = ensure_python_mrange_is_registered();
- /*
if (result) result = populate_arch_instructions_module();
if (result) result = populate_arch_operands_module();
- */
assert(result);
diff --git a/plugins/pychrysalide/arch/operand-ui.c b/plugins/pychrysalide/arch/operand-ui.c
new file mode 100644
index 0000000..5062513
--- /dev/null
+++ b/plugins/pychrysalide/arch/operand-ui.c
@@ -0,0 +1,461 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * operand-ui.c - équivalent Python du fichier "arch/operand-ui.c"
+ *
+ * Copyright (C) 2025 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "operand-ui.h"
+
+
+#include <assert.h>
+#include <pygobject.h>
+
+
+#include <arch/operand-ui-int.h>
+
+
+#include "../access.h"
+#include "../helpers.h"
+
+
+
+/* Procède à l'initialisation de l'interface d'exportation. */
+static void py_arch_operand_ui_interface_init(GArchOperandUIInterface *, gpointer *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void py_arch_operand_ui_print_wrapper(const GArchOperandUI *, GBufferLine *);
+
+/* Construit un petit résumé concis de l'opérande. */
+static char *py_arch_operand_ui_build_tooltip_wrapper(const GArchOperandUI *, const GLoadedBinary *);
+
+/* Traduit un opérande en version humainement lisible. */
+static PyObject *py_arch_operand_ui_print(PyObject *, PyObject *);
+
+/* Construit un petit résumé concis de l'opérande. */
+static PyObject *py_arch_operand_ui_build_tooltip(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : iface = interface GLib à initialiser. *
+* unused = adresse non utilisée ici. *
+* *
+* Description : Procède à l'initialisation de l'interface d'exportation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void py_arch_operand_ui_interface_init(GArchOperandUIInterface *iface, gpointer *unused)
+{
+#define ARCH_OPERAND_UI_DOC \
+ "The ArchOperandUI interface ensure pychrysalide.arch.ArchOperand" \
+ " implementations provide UI features when Chrysalide is running with" \
+ " a GUI.\n" \
+ "\n" \
+ "A typical class declaration for a new implementation looks like:\n" \
+ "\n" \
+ " class NewImplem(ArchOperand, ArchOperandUi):\n" \
+ " ...\n" \
+ "\n" \
+ "The following method has to be defined for new implementations:\n" \
+ "* pychrysalide.arch.ArchOperandUI._print();\n" \
+ "* pychrysalide.arch.ArchOperandUI._build_tooltip().\n"
+
+ iface->print = py_arch_operand_ui_print_wrapper;
+ iface->build_tooltip = py_arch_operand_ui_build_tooltip_wrapper;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = registre visé par la procédure. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void py_arch_operand_ui_print_wrapper(const GArchOperandUI *operand, GBufferLine *line)
+{
+ PyGILState_STATE gstate; /* Sauvegarde d'environnement */
+ PyObject *pyobj; /* Objet Python concerné */
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *pyret; /* Bilan de consultation */
+
+#define ARCH_OPERAND_UI_PRINT_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _print, "$self, line, /", \
+ METH_VARARGS, \
+ "Abstract method used to print an operand into a rendering" \
+ " *line*, which is a provided pychrysalide.glibext.BufferLine" \
+ " instance." \
+)
+
+ gstate = PyGILState_Ensure();
+
+ pyobj = pygobject_new(G_OBJECT(operand));
+
+ if (has_python_method(pyobj, "_print"))
+ {
+ args = PyTuple_New(1);
+ PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(line)));
+
+ pyret = run_python_method(pyobj, "_print", args);
+
+ Py_XDECREF(pyret);
+
+ Py_DECREF(args);
+
+ }
+
+ Py_DECREF(pyobj);
+
+ PyGILState_Release(gstate);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* binary = informations relatives au binaire chargé. *
+* *
+* Description : Construit un petit résumé concis de l'opérande. *
+* *
+* Retour : Chaîne de caractères à libérer après usage ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *py_arch_operand_ui_build_tooltip_wrapper(const GArchOperandUI *operand, const GLoadedBinary *binary)
+{
+ char *result; /* Description à retourner */
+ PyGILState_STATE gstate; /* Sauvegarde d'environnement */
+ PyObject *pyobj; /* Objet Python concerné */
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *pyret; /* Bilan de consultation */
+
+#define ARCH_OPERAND_UI_BUILD_TOOLTIP_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _build_tooltip, "$self, binary, /", \
+ METH_VARARGS, \
+ "Abstract method used to build a tooltip text shown when the" \
+ " mouse is over an operand.\n" \
+ "\n" \
+ "A pychrysalide.analysis.LoadedBinary instance is provided in" \
+ " case of need." \
+)
+
+ result = NULL;
+
+ gstate = PyGILState_Ensure();
+
+ pyobj = pygobject_new(G_OBJECT(operand));
+
+ if (has_python_method(pyobj, "_build_tooltip"))
+ {
+ args = PyTuple_New(1);
+ PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(binary)));
+
+ pyret = run_python_method(pyobj, "_build_tooltip", args);
+
+ if (pyret != NULL)
+ {
+ if (PyUnicode_Check(pyret))
+ result = strdup(PyUnicode_AsUTF8(pyret));
+ }
+
+ Py_XDECREF(pyret);
+
+ Py_DECREF(args);
+
+ }
+
+ Py_DECREF(pyobj);
+
+ PyGILState_Release(gstate);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet manipulé ici. *
+* args = adresse non utilisée ici. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_operand_ui_print(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Emplacement à retourner */
+
+#if 0 // TODO
+
+ GBufferLine *line; /* Zone d'impression du rendu */
+ int ret; /* Bilan de lecture des args. */
+ GArchOperandUI *operand; /* Mécanismes natifs */
+
+#define ARCH_OPERAND_UI_PRINT_METHOD PYTHON_METHOD_DEF \
+( \
+ print, "$self, line", \
+ METH_VARARGS, py_arch_operand_ui, \
+ "Translate an operand into a human readable version.\n" \
+ "\n" \
+ "The *line* arguement is a pychrysalide.glibext.BufferLine" \
+ " instance which has to get filled with rendering" \
+ " information.\n" \
+ "\n" \
+ "The result returns nothing (*None*)." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_buffer_line, &line);
+ if (!ret) return NULL;
+
+ operand = G_ARCH_OPERAND_UI(pygobject_get(self));
+
+ g_arch_operand_ui_print(operand, line);
+
+#endif
+
+ result = Py_None;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet manipulé ici. *
+* args = adresse non utilisée ici. *
+* *
+* Description : Construit un petit résumé concis de l'opérande. *
+* *
+* Retour : Chaîne de caractères à libérer après usage ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_operand_ui_build_tooltip(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Emplacement à retourner */
+
+#if 0 // TODO
+
+ GLoadedBinary *binary; /* Infos sur le binaire chargé */
+ int ret; /* Bilan de lecture des args. */
+ GArchOperandUI *operand; /* Mécanismes natifs */
+ char *tooltip; /* Eventuelle indication */
+
+#define ARCH_OPERAND_UI_BUILD_TOOLTIP_METHOD PYTHON_METHOD_DEF \
+( \
+ build_tooltip, "$self, binary", \
+ METH_VARARGS, py_arch_operand_ui, \
+ "Build a tooltip text shown when the mouse is over an" \
+ " operand.\n" \
+ "\n" \
+ "The *binary* argument is a pychrysalide.analysis.LoadedBinary" \
+ " instance provided in case of need." \
+ "\n" \
+ "The result is a string or *None* in case of error." \
+)
+
+ ret = PyArg_ParseTuple(args, "O&", convert_to_loaded_binary, &binary);
+ if (!ret) return NULL;
+
+ operand = G_ARCH_OPERAND_UI(pygobject_get(self));
+
+ tooltip = g_arch_operand_ui_build_tooltip(operand, binary);
+
+ if (tooltip != NULL)
+ {
+ PyUnicode_FromString(tooltip);
+ free(tooltip);
+ }
+ else
+
+#endif
+
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_arch_operand_ui_type(void)
+{
+ static PyMethodDef py_arch_operand_ui_methods[] = {
+ ARCH_OPERAND_UI_PRINT_WRAPPER,
+ ARCH_OPERAND_UI_BUILD_TOOLTIP_WRAPPER,
+#if 0 // TODO
+ ARCH_OPERAND_UI_PRINT_METHOD,
+ ARCH_OPERAND_UI_BUILD_TOOLTIP_METHOD,
+#endif
+ { NULL }
+ };
+
+ static PyGetSetDef py_arch_operand_ui_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_arch_operand_ui_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.arch.ArchOperandUI",
+ .tp_basicsize = sizeof(PyObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = ARCH_OPERAND_UI_DOC,
+
+ .tp_methods = py_arch_operand_ui_methods,
+ .tp_getset = py_arch_operand_ui_getseters
+
+ };
+
+ return &py_arch_operand_ui_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.arch.ArchOperandUI'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_arch_operand_ui_is_registered(void)
+{
+ PyTypeObject *type; /* Type Python 'ArchOperandUI' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ static GInterfaceInfo info = { /* Paramètres d'inscription */
+
+ .interface_init = (GInterfaceInitFunc)py_arch_operand_ui_interface_init,
+ .interface_finalize = NULL,
+ .interface_data = NULL,
+
+ };
+
+ type = get_python_arch_operand_ui_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.arch");
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_interface_for_pygobject(dict, G_TYPE_ARCH_OPERAND_UI, type, &info))
+ 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 interface d'exportation graphique. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_arch_operand_ui(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_arch_operand_ui_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 UI arch operand");
+ break;
+
+ case 1:
+ *((GArchOperandUI **)dst) = G_ARCH_OPERAND_UI(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/arch/operand-ui.h b/plugins/pychrysalide/arch/operand-ui.h
new file mode 100644
index 0000000..b9e2131
--- /dev/null
+++ b/plugins/pychrysalide/arch/operand-ui.h
@@ -0,0 +1,45 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * operand-ui.h - prototypes pour l'équivalent Python du fichier "arch/operand-ui.h"
+ *
+ * Copyright (C) 2025 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSALIDE_ARCH_OPERAND_UI_H
+#define _PLUGINS_PYCHRYSALIDE_ARCH_OPERAND_UI_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_arch_operand_ui_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.arch.ArchOperandUI'. */
+bool ensure_python_arch_operand_ui_is_registered(void);
+
+/* Tente de convertir en interface d'exportation graphique. */
+int convert_to_arch_operand_ui(PyObject *, void *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERAND_UI_H */
diff --git a/plugins/pychrysalide/arch/operand.c b/plugins/pychrysalide/arch/operand.c
index 0aee4f7..2281dae 100644
--- a/plugins/pychrysalide/arch/operand.c
+++ b/plugins/pychrysalide/arch/operand.c
@@ -30,23 +30,32 @@
#include <i18n.h>
#include <arch/operand-int.h>
-#include <plugins/dt.h>
+#include <glibext/strbuilder-int.h>
#include "../access.h"
#include "../helpers.h"
+#include "../glibext/comparable.h"
+#include "../glibext/hashable.h"
+#include "../glibext/objhole.h"
+#include "../glibext/serialize.h"
#include "../glibext/singleton.h"
+#include "../glibext/strbuilder.h"
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_arch_operand_new(PyTypeObject *, PyObject *, PyObject *);
-
/* Initialise la classe générique des opérandes. */
-static void py_arch_operand_init_gclass(GArchOperandClass *, gpointer);
+static int py_arch_operand_init_gclass(GArchOperandClass *, PyTypeObject *);
+
+CREATE_DYN_ABSTRACT_CONSTRUCTOR(arch_operand, G_TYPE_ARCH_OPERAND);
+
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_arch_operand_init(PyObject *, PyObject *, PyObject *);
+
+#if 0
/* Compare un opérande avec un autre. */
static int py_arch_operand___cmp___wrapper(const GArchOperand *, const GArchOperand *, bool);
@@ -57,14 +66,6 @@ static char *py_arch_operand_find_inner_operand_path_wrapper(const GArchOperand
/* Obtient l'opérande correspondant à un chemin donné. */
static GArchOperand *py_arch_operand_get_inner_operand_from_path_wrapper(const GArchOperand *, const char *);
-/* Traduit un opérande en version humainement lisible. */
-static void py_arch_operand_print_wrapper(const GArchOperand *, GBufferLine *);
-
-#ifdef INCLUDE_GTK_SUPPORT
-
-/* Construit un petit résumé concis de l'opérande. */
-static char *py_arch_operand_build_tooltip_wrapper(const GArchOperand *, const GLoadedBinary *);
-
#endif
@@ -72,6 +73,9 @@ static char *py_arch_operand_build_tooltip_wrapper(const GArchOperand *, const G
/* ------------------------ DEFINITION D'OPERANDE QUELCONQUE ------------------------ */
+#if 0
+
+
/* Effectue une comparaison avec un objet Python 'ArchOperand'. */
static PyObject *py_arch_operand_richcompare(PyObject *, PyObject *, int);
@@ -81,6 +85,19 @@ static PyObject *py_arch_operand_find_inner_operand_path(PyObject *, PyObject *)
/* Obtient l'opérande correspondant à un chemin donné. */
static PyObject *py_arch_operand_get_inner_operand_from_path(PyObject *, PyObject *);
+#endif
+
+
+/* Ajoute une information complémentaire à un opérande. */
+static PyObject *py_arch_operand_set_flag(PyObject *, PyObject *);
+
+/* Retire une information complémentaire à un opérande. */
+static PyObject *py_arch_operand_unset_flag(PyObject *, PyObject *);
+
+/* Détermine si un opérande possède un fanion particulier. */
+static PyObject *py_arch_operand_has_flag(PyObject *, PyObject *);
+
+
/* ---------------------------------------------------------------------------------- */
@@ -90,113 +107,109 @@ static PyObject *py_arch_operand_get_inner_operand_from_path(PyObject *, PyObjec
/******************************************************************************
* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
+* Paramètres : gclass = classe GLib à initialiser. *
+* pyclass = classe Python à initialiser. *
* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
+* Description : Initialise la classe générique des opérandes. *
* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
+* Retour : 0 pour indiquer un succès de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_arch_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_arch_operand_init_gclass(GArchOperandClass *gclass, PyTypeObject *pyclass)
{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
-#define ARCH_OPERAND_DOC \
- "The ArchOperand object aims to get subclassed to create" \
- " operands of any kind for new architectures.\n" \
- "\n" \
- "Calls to the *__init__* constructor of this abstract object expect"\
- " no particular argument.\n" \
- "\n" \
- "The following methods have to be defined for new classes:\n" \
- "* pychrysalide.arch.ArchRegister.__cmp__();\n" \
- "* pychrysalide.arch.ArchRegister._print();\n" \
- "* pychrysalide.arch.ArchRegister._build_tooltip().\n" \
- "\n" \
- "Some extra method definitions are optional for new classes:\n" \
- "* pychrysalide.arch.ArchRegister._find_inner_operand_path();\n" \
- "* pychrysalide.arch.ArchRegister._get_inner_operand_from_path().\n"\
- "\n" \
- "Chrysalide creates an internal glue to provide rich comparisons" \
- " for operands based on the old-style *__cmp__* function."
- /* Validations diverses */
+#if 0
+ GStringBuilderInterface *iface; /* Interface utilisée */
- base = get_python_arch_operand_type();
+ iface = g_type_interface_peek(gclass, G_TYPE_STRING_BUILDER);
- if (type == base)
- {
- result = NULL;
- PyErr_Format(PyExc_RuntimeError, _("%s is an abstract class"), type->tp_name);
- goto exit;
- }
- /* Mise en place d'un type dédié */
+ /*
+ printf("???????? init Python Operand ?????????????? -> class: %p '%s' - strbuilder iface: %p\n",
+ gclass, g_type_name(G_TYPE_FROM_CLASS(gclass)), iface);
+ */
- first_time = (g_type_from_name(type->tp_name) == 0);
+#endif
- gtype = build_dynamic_type(G_TYPE_ARCH_OPERAND, type->tp_name,
- (GClassInitFunc)py_arch_operand_init_gclass, NULL, NULL);
+#if 0
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
+ class->compare = py_arch_operand___cmp___wrapper;
+ class->find_inner = py_arch_operand_find_inner_operand_path_wrapper;
+ class->get_inner = py_arch_operand_get_inner_operand_from_path_wrapper;
- if (!status)
- {
- result = NULL;
- goto exit;
- }
- }
+#endif
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
- result = PyType_GenericNew(type, args, kwds);
- exit:
+ //PY_CLASS_SET_WRAPPER(gclass->xxx, py_arch_operand_xxx_wrapper);
- return result;
+ return 0;
}
/******************************************************************************
* *
-* Paramètres : class = classe à initialiser. *
-* unused = données non utilisées ici. *
+* Paramètres : self = objet à initialiser (théoriquement). *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
* *
-* Description : Initialise la classe générique des opérandes. *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
* *
-* Retour : - *
+* Retour : 0. *
* *
* Remarques : - *
* *
******************************************************************************/
-static void py_arch_operand_init_gclass(GArchOperandClass *class, gpointer unused)
+static int py_arch_operand_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- class->compare = py_arch_operand___cmp___wrapper;
- class->find_inner = py_arch_operand_find_inner_operand_path_wrapper;
- class->get_inner = py_arch_operand_get_inner_operand_from_path_wrapper;
+ //unsigned int endianness; /* Boutisme du processeur */
+ int ret; /* Bilan de lecture des args. */
+ //GArchProcessor *proc; /* Processeur à manipuler */
- class->print = py_arch_operand_print_wrapper;
-#ifdef INCLUDE_GTK_SUPPORT
- class->build_tooltip = py_arch_operand_build_tooltip_wrapper;
-#endif
+#define ARCH_OPERAND_DOC \
+ "The ArchOperand object aims to get subclassed to create" \
+ " operands of any kind for new architectures.\n" \
+ "\n" \
+ "Calls to the *__init__* constructor of this abstract object expect"\
+ " no particular argument.\n" \
+ "\n" \
+ "The following methods have to be defined for new classes:\n" \
+ "* pychrysalide.arch.ArchRegister.__cmp__();\n" \
+ "* pychrysalide.arch.ArchRegister._print();\n" \
+ "* pychrysalide.arch.ArchRegister._build_tooltip().\n" \
+ "\n" \
+ "Some extra method definitions are optional for new classes:\n" \
+ "* pychrysalide.arch.ArchRegister._find_inner_operand_path();\n" \
+ "* pychrysalide.arch.ArchRegister._get_inner_operand_from_path().\n"\
+ "\n" \
+ "Chrysalide creates an internal glue to provide rich comparisons" \
+ " for operands based on the old-style *__cmp__* function."
+
+ /* Initialisation d'un objet GLib */
+
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
+
+ /* Eléments de base */
+
+ //proc = G_ARCH_PROCESSOR(pygobject_get(self));
+
+ //proc->endianness = endianness;
+
+ return 0;
}
+
+#if 0
+
/******************************************************************************
* *
* Paramètres : a = premier opérande à consulter. *
@@ -410,126 +423,6 @@ static GArchOperand *py_arch_operand_get_inner_operand_from_path_wrapper(const G
}
-/******************************************************************************
-* *
-* Paramètres : operand = registre visé par la procédure. *
-* *
-* Description : Traduit un opérande en version humainement lisible. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void py_arch_operand_print_wrapper(const GArchOperand *operand, GBufferLine *line)
-{
- PyGILState_STATE gstate; /* Sauvegarde d'environnement */
- PyObject *pyobj; /* Objet Python concerné */
- PyObject *args; /* Arguments pour l'appel */
- PyObject *pyret; /* Bilan de consultation */
-
-#define ARCH_OPERAND_PRINT_WRAPPER PYTHON_WRAPPER_DEF \
-( \
- _print, "$self, line, /", \
- METH_VARARGS, \
- "Abstract method used to print the operand into a rendering" \
- " line, which is a provided pychrysalide.glibext.BufferLine" \
- " instance." \
-)
-
- gstate = PyGILState_Ensure();
-
- pyobj = pygobject_new(G_OBJECT(operand));
-
- if (has_python_method(pyobj, "_print"))
- {
- args = PyTuple_New(1);
- PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(line)));
-
- pyret = run_python_method(pyobj, "_print", args);
-
- Py_XDECREF(pyret);
-
- Py_DECREF(args);
-
- }
-
- Py_DECREF(pyobj);
-
- PyGILState_Release(gstate);
-
-}
-
-
-#ifdef INCLUDE_GTK_SUPPORT
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à consulter. *
-* binary = informations relatives au binaire chargé. *
-* *
-* Description : Construit un petit résumé concis de l'opérande. *
-* *
-* Retour : Chaîne de caractères à libérer après usage ou NULL. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static char *py_arch_operand_build_tooltip_wrapper(const GArchOperand *operand, const GLoadedBinary *binary)
-{
- char *result; /* Description à retourner */
- PyGILState_STATE gstate; /* Sauvegarde d'environnement */
- PyObject *pyobj; /* Objet Python concerné */
- PyObject *args; /* Arguments pour l'appel */
- PyObject *pyret; /* Bilan de consultation */
-
-#define ARCH_OPERAND_BUILD_TOOLTIP_WRAPPER PYTHON_WRAPPER_DEF \
-( \
- _build_tooltip, "$self, line, /", \
- METH_VARARGS, \
- "Abstract method used to build a tooltip text shown when the" \
- " mouse is over the operand.\n" \
- "\n" \
- "A pychrysalide.analysis.LoadedBinary instance is provided in" \
- " case of need." \
-)
-
- result = NULL;
-
- gstate = PyGILState_Ensure();
-
- pyobj = pygobject_new(G_OBJECT(operand));
-
- if (has_python_method(pyobj, "_build_tooltip"))
- {
- args = PyTuple_New(1);
- PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(binary)));
-
- pyret = run_python_method(pyobj, "_build_tooltip", args);
-
- if (pyret != NULL)
- {
- if (PyUnicode_Check(pyret))
- result = strdup(PyUnicode_AsUTF8(pyret));
- }
-
- Py_XDECREF(pyret);
-
- Py_DECREF(args);
-
- }
-
- Py_DECREF(pyobj);
-
- PyGILState_Release(gstate);
-
- return result;
-
-}
-
#endif
@@ -540,6 +433,9 @@ static char *py_arch_operand_build_tooltip_wrapper(const GArchOperand *operand,
/* ---------------------------------------------------------------------------------- */
+
+#if 0
+
/******************************************************************************
* *
* Paramètres : a = premier object Python à consulter. *
@@ -701,6 +597,164 @@ static PyObject *py_arch_operand_get_inner_operand_from_path(PyObject *self, PyO
}
+#endif
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Ajoute une information complémentaire à un opérande. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_operand_set_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Fanion(s) à appliquer */
+ int ret; /* Bilan de lecture des args. */
+ GArchOperand *operand; /* Opérande manipulé */
+ bool status; /* Bilan à transmettre */
+
+#define ARCH_OPERAND_SET_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ set_flag, "$self, flag, /", \
+ METH_VARARGS, py_arch_operand, \
+ "Add some flags to the operand.\n" \
+ "\n" \
+ "This *flag* argument is an integer value containing" \
+ " bits to apply to the operand state.\n" \
+ "\n" \
+ "The result is an boolean status: *True* for operation" \
+ " success, *False* otherwise." \
+)
+
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
+ operand = G_ARCH_OPERAND(pygobject_get(self));
+
+ status = g_arch_operand_set_flag(operand, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Retire une information complémentaire à un opérande. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_operand_unset_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Fanion(s) à appliquer */
+ int ret; /* Bilan de lecture des args. */
+ GArchOperand *operand; /* Opérande manipulé */
+ bool status; /* Bilan à transmettre */
+
+#define ARCH_OPERAND_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ unset_flag, "$self, flag, /", \
+ METH_VARARGS, py_arch_operand, \
+ "Remove some flags from the operand.\n" \
+ "\n" \
+ "This *flag* argument is an integer value containing" \
+ " bits to delete from the operand state.\n" \
+ "\n" \
+ "The result is an boolean status: *True* for operation" \
+ " success, *False* otherwise." \
+)
+
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
+ operand = G_ARCH_OPERAND(pygobject_get(self));
+
+ status = g_arch_operand_unset_flag(operand, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = architecture concernée par la procédure. *
+* args = instruction représentant le point de départ. *
+* *
+* Description : Détermine si un opérande possède un fanion particulier. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_arch_operand_has_flag(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ unsigned int flag; /* Fanion(s) à appliquer */
+ int ret; /* Bilan de lecture des args. */
+ GArchOperand *operand; /* Opérande manipulé */
+ bool status; /* Bilan à transmettre */
+
+#define ARCH_OPERAND_HAS_FLAG_METHOD PYTHON_METHOD_DEF \
+( \
+ has_flag, "$self, flag, /", \
+ METH_VARARGS, py_arch_operand, \
+ "Tell if some flags are set for the operand.\n" \
+ "\n" \
+ "This *flag* argument is an integer value containing" \
+ " bits to test for the operand state.\n" \
+ "\n" \
+ "The result is an boolean status: *True* if the bits" \
+ " are active, *False* otherwise." \
+)
+
+ ret = PyArg_ParseTuple(args, "I", &flag);
+ if (!ret) return NULL;
+
+ operand = G_ARCH_OPERAND(pygobject_get(self));
+
+ status = g_arch_operand_has_flag(operand, flag);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
/******************************************************************************
* *
@@ -717,6 +771,11 @@ static PyObject *py_arch_operand_get_inner_operand_from_path(PyObject *self, PyO
PyTypeObject *get_python_arch_operand_type(void)
{
static PyMethodDef py_arch_operand_methods[] = {
+ ARCH_OPERAND_SET_FLAG_METHOD,
+ ARCH_OPERAND_UNSET_FLAG_METHOD,
+ ARCH_OPERAND_HAS_FLAG_METHOD,
+
+ /*
ARCH_OPERAND_CMP_WRAPPER,
ARCH_OPERAND_FIND_INNER_OPERAND_PATH_WRAPPER,
ARCH_OPERAND_GET_INNER_OPERAND_FROM_PATH_WRAPPER,
@@ -726,6 +785,7 @@ PyTypeObject *get_python_arch_operand_type(void)
#endif
ARCH_OPERAND_FIND_INNER_OPERAND_PATH_METHOD,
ARCH_OPERAND_GET_INNER_OPERAND_FROM_PATH_METHOD,
+ */
{ NULL }
};
@@ -744,11 +804,12 @@ PyTypeObject *get_python_arch_operand_type(void)
.tp_doc = ARCH_OPERAND_DOC,
- .tp_richcompare = py_arch_operand_richcompare,
+ //.tp_richcompare = py_arch_operand_richcompare,
.tp_methods = py_arch_operand_methods,
.tp_getset = py_arch_operand_getseters,
+ .tp_init = py_arch_operand_init,
.tp_new = py_arch_operand_new,
};
@@ -784,9 +845,26 @@ bool ensure_python_arch_operand_is_registered(void)
dict = PyModule_GetDict(module);
+ if (!ensure_python_thick_object_is_registered())
+ return false;
+
+ if (!ensure_python_comparable_object_is_registered())
+ return false;
+
+ if (!ensure_python_hashable_object_is_registered())
+ return false;
+
+ if (!ensure_python_serializable_object_is_registered())
+ return false;
+
if (!ensure_python_singleton_candidate_is_registered())
return false;
+ if (!ensure_python_string_builder_is_registered())
+ return false;
+
+ pyg_register_class_init(G_TYPE_ARCH_OPERAND, (PyGClassInitFunc)py_arch_operand_init_gclass);
+
if (!register_class_for_pygobject(dict, G_TYPE_ARCH_OPERAND, type))
return false;
diff --git a/plugins/pychrysalide/arch/operand.h b/plugins/pychrysalide/arch/operand.h
index 9cb40a0..f3bfbf2 100644
--- a/plugins/pychrysalide/arch/operand.h
+++ b/plugins/pychrysalide/arch/operand.h
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* operand.h - prototypes pour l'équivalent Python du fichier "arch/operand.h"
*
- * Copyright (C) 2018-2019 Cyrille Bagard
+ * Copyright (C) 2018-2024 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -31,9 +31,6 @@
-/* ------------------------ DEFINITION D'OPERANDE QUELCONQUE ------------------------ */
-
-
/* Fournit un accès à une définition de type à diffuser. */
PyTypeObject *get_python_arch_operand_type(void);
diff --git a/plugins/pychrysalide/arch/operands/Makefile.am b/plugins/pychrysalide/arch/operands/Makefile.am
index a41cbbb..3b753cc 100644
--- a/plugins/pychrysalide/arch/operands/Makefile.am
+++ b/plugins/pychrysalide/arch/operands/Makefile.am
@@ -1,19 +1,21 @@
noinst_LTLIBRARIES = libpychrysaarchoperands.la
+# libpychrysaarchoperands_la_SOURCES = \
+# feeder.h feeder.c \
+# proxy.h proxy.c \
+# rename.h rename.c \
+# target.h target.c \
+# targetable.h targetable.c
+
libpychrysaarchoperands_la_SOURCES = \
constants.h constants.c \
- feeder.h feeder.c \
immediate.h immediate.c \
known.h known.c \
module.h module.c \
- proxy.h proxy.c \
- register.h register.c \
- rename.h rename.c \
- target.h target.c \
- targetable.h targetable.c
+ register.h register.c
-libpychrysaarchoperands_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
+libpychrysaarchoperands_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \
-I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT
diff --git a/plugins/pychrysalide/arch/operands/constants.c b/plugins/pychrysalide/arch/operands/constants.c
index b9d80e4..78eeded 100644
--- a/plugins/pychrysalide/arch/operands/constants.c
+++ b/plugins/pychrysalide/arch/operands/constants.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* constants.c - ajout des constantes de base pour les opérandes
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -47,20 +47,33 @@
* *
******************************************************************************/
-bool define_imm_operand_constants(PyTypeObject *type)
+bool define_immediate_operand_constants(PyTypeObject *type)
{
bool result; /* Bilan à retourner */
PyObject *values; /* Groupe de valeurs à établir */
values = PyDict_New();
+ result = add_const_to_group(values, "ZERO_PADDING_BY_DEFAULT", IOF_ZERO_PADDING_BY_DEFAULT);
+ if (result) result = add_const_to_group(values, "ZERO_PADDING", IOF_ZERO_PADDING);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, true, "ImmOperandFlag", values,
+ "Specific state bits for immediate operands.");
+
+ values = PyDict_New();
+
result = add_const_to_group(values, "BIN", IOD_BIN);
if (result) result = add_const_to_group(values, "OCT", IOD_OCT);
if (result) result = add_const_to_group(values, "DEC", IOD_DEC);
if (result) result = add_const_to_group(values, "HEX", IOD_HEX);
if (result) result = add_const_to_group(values, "CHAR", IOD_CHAR);
if (result) result = add_const_to_group(values, "COUNT", IOD_COUNT);
- if (result) result = add_const_to_group(values, "LAST_VALID", IOD_LAST_VALID);
if (!result)
{
diff --git a/plugins/pychrysalide/arch/operands/constants.h b/plugins/pychrysalide/arch/operands/constants.h
index 71a26cc..5170faa 100644
--- a/plugins/pychrysalide/arch/operands/constants.h
+++ b/plugins/pychrysalide/arch/operands/constants.h
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* constants.h - prototypes pour l'ajout des constantes de base pour les opérandes
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -32,11 +32,14 @@
/* Définit les constantes relatives aux opérandes d'immédiats. */
-bool define_imm_operand_constants(PyTypeObject *);
+bool define_immediate_operand_constants(PyTypeObject *);
/* Tente de convertir en constante ImmOperandDisplay. */
int convert_to_imm_operand_display(PyObject *, void *);
+#define cast_imm_operand_display_to_python(v) \
+ cast_with_constants_group_from_type(get_python_immediate_operand_type(), "ImmOperandDisplay", v)
+
#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_CONSTANTS_H */
diff --git a/plugins/pychrysalide/arch/operands/immediate.c b/plugins/pychrysalide/arch/operands/immediate.c
index 2239eb2..a335db3 100644
--- a/plugins/pychrysalide/arch/operands/immediate.c
+++ b/plugins/pychrysalide/arch/operands/immediate.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* immediate.c - équivalent Python du fichier "arch/operands/immediate.h"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -30,201 +30,119 @@
#include <i18n.h>
-
-
-#include <arch/operands/immediate.h>
+#include <arch/operands/immediate-int.h>
#include "constants.h"
-#include "rename.h"
-#include "targetable.h"
#include "../operand.h"
#include "../../access.h"
+#include "../../constants.h"
#include "../../helpers.h"
#include "../../analysis/content.h"
-#include "../../glibext/bufferline.h"
-/* Crée un nouvel objet Python de type 'ImmOperand'. */
-static PyObject *py_imm_operand_new(PyTypeObject *, PyObject *, PyObject *);
+/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
+
+
+CREATE_DYN_CONSTRUCTOR(immediate_operand, G_TYPE_IMMEDIATE_OPERAND);
+
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_immediate_operand_init(PyObject *, PyObject *, PyObject *);
+
+
-/* Compare un opérande avec un autre. */
-static PyObject *py_imm_operand___cmp__(PyObject *, PyObject *);
+/* ---------------------------- DEFINITION D'UN IMMEDIAT ---------------------------- */
-/* 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 *);
+static PyObject *py_immediate_operand_get_size(PyObject *, void *);
/* Fournit la valeur portée par une opérande numérique. */
-static PyObject *py_imm_operand_get_value(PyObject *, void *);
+static PyObject *py_immediate_operand_get_value(PyObject *, void *);
+
+/* Indique le signe d'une valeur immédiate. */
+static PyObject *py_immediate_operand_is_negative(PyObject *, void *);
/* Indique le format textuel par défaut de la valeur. */
-static PyObject *py_imm_operand_get_default_display(PyObject *, void *);
+static PyObject *py_immediate_operand_get_default_display(PyObject *, void *);
/* Définit le format textuel par défaut de la valeur. */
-static int py_imm_operand_set_default_display(PyObject *, PyObject *, void *);
+static int py_immediate_operand_set_default_display(PyObject *, PyObject *, void *);
/* Indique la grande ligne du format textuel de la valeur. */
-static PyObject *py_imm_operand_get_display(PyObject *, void *);
+static PyObject *py_immediate_operand_get_display(PyObject *, void *);
/* Définit la grande ligne du format textuel de la valeur. */
-static int py_imm_operand_set_display(PyObject *, PyObject *, void *);
+static int py_immediate_operand_set_display(PyObject *, PyObject *, void *);
+
+/* ---------------------------------------------------------------------------------- */
+/* GLUE POUR CREATION DEPUIS PYTHON */
+/* ---------------------------------------------------------------------------------- */
+
/******************************************************************************
* *
-* Paramètres : type = type de l'objet à instancier. *
+* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'ImmOperand'. *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
* *
-* Retour : Instance Python mise en place. *
+* Retour : 0. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_imm_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_immediate_operand_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *result; /* Instance à retourner */
- unsigned int raw_size; /* Taille obtenue de Python */
+ MemoryDataSize size; /* Taille des données finale */
unsigned long long value; /* Valeur brute à représenter */
int ret; /* Bilan de lecture des args. */
- MemoryDataSize size; /* Taille des données finale */
- GArchOperand *operand; /* Création GLib à transmettre */
+ GImmediateOperand *operand; /* Opérande natif à manipuler */
-#define IMM_OPERAND_DOC \
- "The ImmOperand deals with immediate value as operand." \
+#define IMMEDIATE_OPERAND_DOC \
+ "The ImmediateOperand deals with immediate value as operand." \
"\n" \
"There are several ways to display these values in a disassembly," \
" the operand handles that.\n" \
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " ImmOperand(size, value)" \
+ " ImmediateOperand(size, value)" \
"\n" \
- "Where size specifies the original size of the provided value, as" \
- " a pychrysalide.analysis.BinContent.MemoryDataSize."
+ "Where *size* specifies the original size of the provided *value*," \
+ " as a pychrysalide.MemoryDataSize."
- ret = PyArg_ParseTuple(args, "IK", &raw_size, &value);
- if (!ret) return NULL;
+ /* Récupération des paramètres */
- size = raw_size;
+ ret = PyArg_ParseTuple(args, "O&K", convert_to_memory_data_size, &size, &value);
+ if (!ret) return -1;
- if (size != MDS_UNDEFINED
- && !(MDS_4_BITS_UNSIGNED <= size && size <= MDS_64_BITS_UNSIGNED)
- && !(MDS_4_BITS_SIGNED <= size && size <= MDS_64_BITS_SIGNED))
- {
- PyErr_SetString(PyExc_ValueError, _("Invalid size to build an immediate operand"));
- return NULL;
- }
+ /* Initialisation d'un objet GLib */
- operand = g_imm_operand_new_from_value(size, value);
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
- result = pygobject_new(G_OBJECT(operand));
+ /* Eléments de base */
- g_object_unref(operand);
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
- return (PyObject *)result;
-
-}
-
-
-/******************************************************************************
-* *
-* 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);
+ if (!g_immediate_operand_create_from_value(operand, size, value))
+ return -1;
- return result;
+ return 0;
}
-/******************************************************************************
-* *
-* 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;
-
-}
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION D'UN IMMEDIAT */
+/* ---------------------------------------------------------------------------------- */
/******************************************************************************
@@ -240,25 +158,26 @@ static PyObject *py_imm_operand__print(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_imm_operand_get_size(PyObject *self, void *closure)
+static PyObject *py_immediate_operand_get_size(PyObject *self, void *closure)
{
PyObject *result; /* Instance Python à retourner */
- GImmOperand *operand; /* Version GLib de l'opérande */
+ GImmediateOperand *operand; /* Version GLib de l'opérande */
MemoryDataSize size; /* Type de donnée représentée */
-#define IMM_OPERAND_SIZE_ATTRIB PYTHON_GET_DEF_FULL \
+#define IMMEDIATE_OPERAND_SIZE_ATTRIB PYTHON_GET_DEF_FULL \
( \
- size, py_imm_operand, \
+ size, py_immediate_operand, \
"Get or set the size of the value contained in the operand." \
"\n" \
"The property is a value of type" \
- " pychrysalide.analysis.BinContent.MemoryDataSize." \
+ " pychrysalide.MemoryDataSize." \
)
- operand = G_IMM_OPERAND(pygobject_get(self));
- size = g_imm_operand_get_size(operand);
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
+
+ size = g_immediate_operand_get_size(operand);
- result = cast_with_constants_group_from_type(get_python_binary_content_type(), "MemoryDataSize", size);
+ result = cast_memory_data_size_to_python(size);
return result;
@@ -278,10 +197,10 @@ static PyObject *py_imm_operand_get_size(PyObject *self, void *closure)
* *
******************************************************************************/
-static PyObject *py_imm_operand_get_value(PyObject *self, void *closure)
+static PyObject *py_immediate_operand_get_value(PyObject *self, void *closure)
{
PyObject *result; /* Instance Python à retourner */
- GImmOperand *operand; /* Version GLib de l'opérande */
+ GImmediateOperand *operand; /* Version GLib de l'opérande */
MemoryDataSize size; /* Type de donnée représentée */
uint8_t uval8; /* Valeur sur 8 bits */
uint16_t uval16; /* Valeur sur 16 bits */
@@ -292,15 +211,15 @@ static PyObject *py_imm_operand_get_value(PyObject *self, void *closure)
int32_t sval32; /* Valeur sur 32 bits */
int64_t sval64; /* Valeur sur 64 bits */
-#define IMM_OPERAND_VALUE_ATTRIB PYTHON_GET_DEF_FULL \
-( \
- value, py_imm_operand, \
- "Value of the immediate operand, as an integer." \
+#define IMMEDIATE_OPERAND_VALUE_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ value, py_immediate_operand, \
+ "Value of the immediate operand, as an integer." \
)
- operand = G_IMM_OPERAND(pygobject_get(self));
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
- size = g_imm_operand_get_size(operand);
+ size = g_immediate_operand_get_size(operand);
switch (size)
{
@@ -311,36 +230,36 @@ static PyObject *py_imm_operand_get_value(PyObject *self, void *closure)
break;
case MDS_4_BITS_UNSIGNED:
case MDS_8_BITS_UNSIGNED:
- g_imm_operand_get_value(operand, size, &uval8);
+ g_immediate_operand_get_value(operand, size, &uval8);
result = PyLong_FromUnsignedLong(uval8);
break;
case MDS_16_BITS_UNSIGNED:
- g_imm_operand_get_value(operand, size, &uval16);
+ g_immediate_operand_get_value(operand, size, &uval16);
result = PyLong_FromUnsignedLong(uval16);
break;
case MDS_32_BITS_UNSIGNED:
- g_imm_operand_get_value(operand, size, &uval32);
+ g_immediate_operand_get_value(operand, size, &uval32);
result = PyLong_FromUnsignedLong(uval32);
break;
case MDS_64_BITS_UNSIGNED:
- g_imm_operand_get_value(operand, size, &uval64);
+ g_immediate_operand_get_value(operand, size, &uval64);
result = PyLong_FromUnsignedLongLong(uval64);
break;
case MDS_4_BITS_SIGNED:
case MDS_8_BITS_SIGNED:
- g_imm_operand_get_value(operand, size, &sval8);
+ g_immediate_operand_get_value(operand, size, &sval8);
result = PyLong_FromLong(sval8);
break;
case MDS_16_BITS_SIGNED:
- g_imm_operand_get_value(operand, size, &sval16);
+ g_immediate_operand_get_value(operand, size, &sval16);
result = PyLong_FromLong(sval16);
break;
case MDS_32_BITS_SIGNED:
- g_imm_operand_get_value(operand, size, &sval32);
+ g_immediate_operand_get_value(operand, size, &sval32);
result = PyLong_FromLong(sval32);
break;
case MDS_64_BITS_SIGNED:
- g_imm_operand_get_value(operand, size, &sval64);
+ g_immediate_operand_get_value(operand, size, &sval64);
result = PyLong_FromLongLong(sval64);
break;
@@ -363,6 +282,43 @@ static PyObject *py_imm_operand_get_value(PyObject *self, void *closure)
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
+* Description : Indique le signe d'une valeur immédiate. *
+* *
+* Retour : True si la valeur est strictement négative, False sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_immediate_operand_is_negative(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance Python à retourner */
+ GImmediateOperand *operand; /* Version GLib de l'opérande */
+ bool status; /* Etat à faire connaître */
+
+#define IMMEDIATE_OPERAND_NEGATIVE_ATTRIB PYTHON_IS_DEF_FULL \
+( \
+ negative, py_immediate_operand, \
+ "Sign of the value, as a boolean status." \
+)
+
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
+
+ status = g_immediate_operand_is_negative(operand);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
* Description : Indique le format textuel par défaut de la valeur. *
* *
* Retour : Format global d'un affichage de valeur. *
@@ -371,25 +327,26 @@ static PyObject *py_imm_operand_get_value(PyObject *self, void *closure)
* *
******************************************************************************/
-static PyObject *py_imm_operand_get_default_display(PyObject *self, void *closure)
+static PyObject *py_immediate_operand_get_default_display(PyObject *self, void *closure)
{
PyObject *result; /* Instance Python à retourner */
- GImmOperand *operand; /* Version GLib de l'opérande */
+ GImmediateOperand *operand; /* Version GLib de l'opérande */
ImmOperandDisplay display; /* Type d'affichage courant */
-#define IMM_OPERAND_DEFAULT_DISPLAY_ATTRIB PYTHON_GETSET_DEF_FULL \
+#define IMMEDIATE_OPERAND_DEFAULT_DISPLAY_ATTRIB PYTHON_GETSET_DEF_FULL \
( \
- default_display, py_imm_operand, \
+ default_display, py_immediate_operand, \
"Define of the immediate operand default textual representation." \
"\n" \
"The property is a value of type" \
" pychrysalide.arch.operands.ImmOperand.ImmOperandDisplay." \
)
- operand = G_IMM_OPERAND(pygobject_get(self));
- display = g_imm_operand_get_default_display(operand);
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
+
+ display = g_immediate_operand_get_default_display(operand);
- result = cast_with_constants_group_from_type(get_python_imm_operand_type(), "ImmOperandDisplay", display);
+ result = cast_imm_operand_display_to_python(display);
return result;
@@ -410,10 +367,10 @@ static PyObject *py_imm_operand_get_default_display(PyObject *self, void *closur
* *
******************************************************************************/
-static int py_imm_operand_set_default_display(PyObject *self, PyObject *value, void *closure)
+static int py_immediate_operand_set_default_display(PyObject *self, PyObject *value, void *closure)
{
ImmOperandDisplay display; /* Type d'affichage demandé */
- GImmOperand *operand; /* Version GLib de l'opérande */
+ GImmediateOperand *operand; /* Version GLib de l'opérande */
if (!PyLong_Check(value))
{
@@ -429,9 +386,9 @@ static int py_imm_operand_set_default_display(PyObject *self, PyObject *value, v
return -1;
}
- operand = G_IMM_OPERAND(pygobject_get(self));
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
- g_imm_operand_set_default_display(operand, display);
+ g_immediate_operand_set_default_display(operand, display);
return 0;
@@ -451,25 +408,27 @@ static int py_imm_operand_set_default_display(PyObject *self, PyObject *value, v
* *
******************************************************************************/
-static PyObject *py_imm_operand_get_display(PyObject *self, void *closure)
+static PyObject *py_immediate_operand_get_display(PyObject *self, void *closure)
{
PyObject *result; /* Instance Python à retourner */
- GImmOperand *operand; /* Version GLib de l'opérande */
+ GImmediateOperand *operand; /* Version GLib de l'opérande */
ImmOperandDisplay display; /* Type d'affichage courant */
-#define IMM_OPERAND_DISPLAY_ATTRIB PYTHON_GETSET_DEF_FULL \
-( \
- display, py_imm_operand, \
- "Define of the immediate operand current textual representation." \
- "\n" \
- "The property is a value of type" \
- " pychrysalide.arch.operands.ImmOperand.ImmOperandDisplay." \
+#define IMMEDIATE_OPERAND_DISPLAY_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ display, py_immediate_operand, \
+ "Retrieve or define of the immediate operand current textual" \
+ " representation." \
+ "\n" \
+ "The property is a value of type" \
+ " pychrysalide.arch.operands.ImmOperand.ImmOperandDisplay." \
)
- operand = G_IMM_OPERAND(pygobject_get(self));
- display = g_imm_operand_get_display(operand);
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
- result = cast_with_constants_group_from_type(get_python_imm_operand_type(), "ImmOperandDisplay", display);
+ display = g_immediate_operand_get_display(operand);
+
+ result = cast_imm_operand_display_to_python(display);
return result;
@@ -490,10 +449,10 @@ static PyObject *py_imm_operand_get_display(PyObject *self, void *closure)
* *
******************************************************************************/
-static int py_imm_operand_set_display(PyObject *self, PyObject *value, void *closure)
+static int py_immediate_operand_set_display(PyObject *self, PyObject *value, void *closure)
{
ImmOperandDisplay display; /* Type d'affichage demandé */
- GImmOperand *operand; /* Version GLib de l'opérande */
+ GImmediateOperand *operand; /* Version GLib de l'opérande */
if (!PyLong_Check(value))
{
@@ -509,9 +468,9 @@ static int py_imm_operand_set_display(PyObject *self, PyObject *value, void *clo
return -1;
}
- operand = G_IMM_OPERAND(pygobject_get(self));
+ operand = G_IMMEDIATE_OPERAND(pygobject_get(self));
- g_imm_operand_set_display(operand, display);
+ g_immediate_operand_set_display(operand, display);
return 0;
@@ -530,40 +489,41 @@ static int py_imm_operand_set_display(PyObject *self, PyObject *value, void *clo
* *
******************************************************************************/
-PyTypeObject *get_python_imm_operand_type(void)
+PyTypeObject *get_python_immediate_operand_type(void)
{
- static PyMethodDef py_imm_operand_methods[] = {
- IMM_OPERAND_CMP_METHOD,
- IMM_OPERAND_PRINT_METHOD,
+ static PyMethodDef py_immediate_operand_methods[] = {
{ NULL }
};
- static PyGetSetDef py_imm_operand_getseters[] = {
- IMM_OPERAND_SIZE_ATTRIB,
- IMM_OPERAND_VALUE_ATTRIB,
- IMM_OPERAND_DEFAULT_DISPLAY_ATTRIB,
- IMM_OPERAND_DISPLAY_ATTRIB,
+ static PyGetSetDef py_immediate_operand_getseters[] = {
+ IMMEDIATE_OPERAND_SIZE_ATTRIB,
+ IMMEDIATE_OPERAND_VALUE_ATTRIB,
+ IMMEDIATE_OPERAND_NEGATIVE_ATTRIB,
+ IMMEDIATE_OPERAND_DEFAULT_DISPLAY_ATTRIB,
+ IMMEDIATE_OPERAND_DISPLAY_ATTRIB,
{ NULL }
};
- static PyTypeObject py_imm_operand_type = {
+ static PyTypeObject py_immediate_operand_type = {
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.arch.operands.ImmOperand",
+ .tp_name = "pychrysalide.arch.operands.ImmediateOperand",
.tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = IMM_OPERAND_DOC,
+ .tp_doc = IMMEDIATE_OPERAND_DOC,
+
+ .tp_methods = py_immediate_operand_methods,
+ .tp_getset = py_immediate_operand_getseters,
- .tp_methods = py_imm_operand_methods,
- .tp_getset = py_imm_operand_getseters,
- .tp_new = py_imm_operand_new
+ .tp_init = py_immediate_operand_init,
+ .tp_new = py_immediate_operand_new,
};
- return &py_imm_operand_type;
+ return &py_immediate_operand_type;
}
@@ -580,13 +540,13 @@ PyTypeObject *get_python_imm_operand_type(void)
* *
******************************************************************************/
-bool ensure_python_imm_operand_is_registered(void)
+bool ensure_python_immediate_operand_is_registered(void)
{
- PyTypeObject *type; /* Type Python 'ImmOperand' */
+ PyTypeObject *type; /* Type 'ImmediateOperand' */
PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- type = get_python_imm_operand_type();
+ type = get_python_immediate_operand_type();
if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
{
@@ -597,16 +557,10 @@ bool ensure_python_imm_operand_is_registered(void)
if (!ensure_python_arch_operand_is_registered())
return false;
- if (!ensure_python_targetable_operand_is_registered())
- return false;
-
- if (!ensure_python_renameable_operand_is_registered())
- return false;
-
- if (!register_class_for_pygobject(dict, G_TYPE_IMM_OPERAND, type))
+ if (!register_class_for_pygobject(dict, G_TYPE_IMMEDIATE_OPERAND, type))
return false;
- if (!define_imm_operand_constants(type))
+ if (!define_immediate_operand_constants(type))
return false;
}
@@ -629,11 +583,11 @@ bool ensure_python_imm_operand_is_registered(void)
* *
******************************************************************************/
-int convert_to_imm_operand(PyObject *arg, void *dst)
+int convert_to_immediate_operand(PyObject *arg, void *dst)
{
int result; /* Bilan à retourner */
- result = PyObject_IsInstance(arg, (PyObject *)get_python_imm_operand_type());
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_immediate_operand_type());
switch (result)
{
@@ -647,7 +601,7 @@ int convert_to_imm_operand(PyObject *arg, void *dst)
break;
case 1:
- *((GImmOperand **)dst) = G_IMM_OPERAND(pygobject_get(arg));
+ *((GImmediateOperand **)dst) = G_IMMEDIATE_OPERAND(pygobject_get(arg));
break;
default:
diff --git a/plugins/pychrysalide/arch/operands/immediate.h b/plugins/pychrysalide/arch/operands/immediate.h
index 4a1e6de..8b8de83 100644
--- a/plugins/pychrysalide/arch/operands/immediate.h
+++ b/plugins/pychrysalide/arch/operands/immediate.h
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* immediate.h - prototypes pour l'équivalent Python du fichier "arch/operands/immediate.h"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -32,13 +32,13 @@
/* Fournit un accès à une définition de type à diffuser. */
-PyTypeObject *get_python_imm_operand_type(void);
+PyTypeObject *get_python_immediate_operand_type(void);
-/* Prend en charge l'objet 'pychrysalide.arch.ImmOperand'. */
-bool ensure_python_imm_operand_is_registered(void);
+/* Prend en charge l'objet 'pychrysalide.arch.ImmediateOperand'. */
+bool ensure_python_immediate_operand_is_registered(void);
/* Tente de convertir en opérande de valeur immédiate. */
-int convert_to_imm_operand(PyObject *, void *);
+int convert_to_immediate_operand(PyObject *, void *);
diff --git a/plugins/pychrysalide/arch/operands/known.c b/plugins/pychrysalide/arch/operands/known.c
index fab426e..85cabc2 100644
--- a/plugins/pychrysalide/arch/operands/known.c
+++ b/plugins/pychrysalide/arch/operands/known.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* known.c - équivalent Python du fichier "arch/operands/known.h"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -29,70 +29,92 @@
#include <pygobject.h>
-#include <arch/operands/known.h>
+#include <arch/operands/known-int.h>
#include "immediate.h"
-#include "rename.h"
#include "../../access.h"
#include "../../helpers.h"
-/* Crée un nouvel objet Python de type 'KnownImmOperand'. */
-static PyObject *py_known_imm_operand_new(PyTypeObject *, PyObject *, PyObject *);
+/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
+CREATE_DYN_CONSTRUCTOR(known_immediate_operand, G_TYPE_KNOWN_IMMEDIATE_OPERAND);
+
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_known_immediate_operand_init(PyObject *, PyObject *, PyObject *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* GLUE POUR CREATION DEPUIS PYTHON */
+/* ---------------------------------------------------------------------------------- */
+
/******************************************************************************
* *
-* Paramètres : type = type de l'objet à instancier. *
+* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'KnownImmOperand'. *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
* *
-* Retour : Instance Python mise en place. *
+* Retour : 0. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_known_imm_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_known_immediate_operand_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *result; /* Instance à retourner */
- GImmOperand *imm; /* Opérande à remplacer */
+ GImmediateOperand *imm; /* Opérande à remplacer */
const char *alt; /* Impression alternative */
int ret; /* Bilan de lecture des args. */
- GArchOperand *operand; /* Création GLib à transmettre */
-
-#define KNOWN_IMM_OPERAND_DOC \
- "The KnownImmOperand provides replacement of" \
- " pychrysalide.arch.operands.ImmOperand instances by an alternative" \
- " text.\n" \
- "\n" \
- "Instances can be created using the following constructor:\n" \
- "\n" \
- " KnownImmOperand(imm, alt)" \
- "\n" \
- "Where imm is an operand of type pychrysalide.arch.operands.ImmOperand" \
- " and alt is a string providing the text to be rendered at object" \
+ GKnownImmediateOperand *operand; /* Opérande natif à manipuler */
+
+#define KNOWN_IMMEDIATE_OPERAND_DOC \
+ "The KnownImmediateOperand provides replacement of" \
+ " pychrysalide.arch.operands.ImmediateOperand instances by an alternative" \
+ " text.\n" \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " KnownImmediateOperand(imm, alt)" \
+ "\n" \
+ "Where *imm* is an operand of type pychrysalide.arch.operands.ImmediateOperand" \
+ " and *alt* is a string providing the text to be rendered at object" \
" display."
- ret = PyArg_ParseTuple(args, "O&s", convert_to_imm_operand, &imm, &alt);
- if (!ret) return NULL;
+ /* Récupération des paramètres */
+
+ ret = PyArg_ParseTuple(args, "O&s", convert_to_immediate_operand, &imm, &alt);
+ if (!ret) return -1;
+
+ /* Initialisation d'un objet GLib */
- operand = g_known_imm_operand_new(imm, alt);
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
- result = pygobject_new(G_OBJECT(operand));
+ /* Eléments de base */
- g_object_unref(operand);
+ operand = G_KNOWN_IMMEDIATE_OPERAND(pygobject_get(self));
- return (PyObject *)result;
+ if (!g_known_immediate_operand_create(operand, imm, alt))
+ return -1;
+
+ return 0;
}
+
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION D'UN IMMEDIAT CONNU */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
* Paramètres : - *
@@ -105,34 +127,36 @@ static PyObject *py_known_imm_operand_new(PyTypeObject *type, PyObject *args, Py
* *
******************************************************************************/
-PyTypeObject *get_python_known_imm_operand_type(void)
+PyTypeObject *get_python_known_immediate_operand_type(void)
{
- static PyMethodDef py_known_imm_operand_methods[] = {
+ static PyMethodDef py_known_immediate_operand_methods[] = {
{ NULL }
};
- static PyGetSetDef py_known_imm_operand_getseters[] = {
+ static PyGetSetDef py_known_immediate_operand_getseters[] = {
{ NULL }
};
- static PyTypeObject py_known_imm_operand_type = {
+ static PyTypeObject py_known_immediate_operand_type = {
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.arch.operands.KnownImmOperand",
+ .tp_name = "pychrysalide.arch.operands.KnownImmediateOperand",
.tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = KNOWN_IMM_OPERAND_DOC,
+ .tp_doc = KNOWN_IMMEDIATE_OPERAND_DOC,
- .tp_methods = py_known_imm_operand_methods,
- .tp_getset = py_known_imm_operand_getseters,
- .tp_new = py_known_imm_operand_new
+ .tp_methods = py_known_immediate_operand_methods,
+ .tp_getset = py_known_immediate_operand_getseters,
+
+ .tp_init = py_known_immediate_operand_init,
+ .tp_new = py_known_immediate_operand_new,
};
- return &py_known_imm_operand_type;
+ return &py_known_immediate_operand_type;
}
@@ -141,7 +165,7 @@ PyTypeObject *get_python_known_imm_operand_type(void)
* *
* Paramètres : module = module dont la définition est à compléter. *
* *
-* Description : Prend en charge l'objet 'pychrysalide.arch.KnownImmOperand'. *
+* Description : Prend en charge l'objet '....KnownImmediateOperand'. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -149,13 +173,13 @@ PyTypeObject *get_python_known_imm_operand_type(void)
* *
******************************************************************************/
-bool ensure_python_known_imm_operand_is_registered(void)
+bool ensure_python_known_immediate_operand_is_registered(void)
{
- PyTypeObject *type; /* Type Python 'ImmOperand' */
+ PyTypeObject *type; /* Type 'KnownImmediateOperand'*/
PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- type = get_python_known_imm_operand_type();
+ type = get_python_known_immediate_operand_type();
if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
{
@@ -163,13 +187,10 @@ bool ensure_python_known_imm_operand_is_registered(void)
dict = PyModule_GetDict(module);
- if (!ensure_python_imm_operand_is_registered())
- return false;
-
- if (!ensure_python_renamed_operand_is_registered())
+ if (!ensure_python_immediate_operand_is_registered())
return false;
- if (!register_class_for_pygobject(dict, G_TYPE_KNOWN_IMM_OPERAND, type))
+ if (!register_class_for_pygobject(dict, G_TYPE_KNOWN_IMMEDIATE_OPERAND, type))
return false;
}
@@ -192,11 +213,11 @@ bool ensure_python_known_imm_operand_is_registered(void)
* *
******************************************************************************/
-int convert_to_known_imm_operand(PyObject *arg, void *dst)
+int convert_to_known_immediate_operand(PyObject *arg, void *dst)
{
int result; /* Bilan à retourner */
- result = PyObject_IsInstance(arg, (PyObject *)get_python_known_imm_operand_type());
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_known_immediate_operand_type());
switch (result)
{
@@ -210,7 +231,7 @@ int convert_to_known_imm_operand(PyObject *arg, void *dst)
break;
case 1:
- *((GKnownImmOperand **)dst) = G_KNOWN_IMM_OPERAND(pygobject_get(arg));
+ *((GKnownImmediateOperand **)dst) = G_KNOWN_IMMEDIATE_OPERAND(pygobject_get(arg));
break;
default:
diff --git a/plugins/pychrysalide/arch/operands/known.h b/plugins/pychrysalide/arch/operands/known.h
index b5ced68..f5b80e8 100644
--- a/plugins/pychrysalide/arch/operands/known.h
+++ b/plugins/pychrysalide/arch/operands/known.h
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* known.h - prototypes pour l'équivalent Python du fichier "arch/operands/known.h"
*
- * Copyright (C) 2020 Cyrille Bagard
+ * Copyright (C) 2020-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -32,13 +32,13 @@
/* Fournit un accès à une définition de type à diffuser. */
-PyTypeObject *get_python_known_imm_operand_type(void);
+PyTypeObject *get_python_known_immediate_operand_type(void);
-/* Prend en charge l'objet 'pychrysalide.arch.KnownImmOperand'. */
-bool ensure_python_known_imm_operand_is_registered(void);
+/* Prend en charge l'objet 'pychrysalide.arch.KnownImmediateOperand'. */
+bool ensure_python_known_immediate_operand_is_registered(void);
/* Tente de convertir en remplaçant d'opérande d'immédiat. */
-int convert_to_known_imm_operand(PyObject *, void *);
+int convert_to_known_immediate_operand(PyObject *, void *);
diff --git a/plugins/pychrysalide/arch/operands/module.c b/plugins/pychrysalide/arch/operands/module.c
index 89adecc..486e259 100644
--- a/plugins/pychrysalide/arch/operands/module.c
+++ b/plugins/pychrysalide/arch/operands/module.c
@@ -28,14 +28,20 @@
#include <assert.h>
+/*
#include "feeder.h"
+*/
#include "immediate.h"
#include "known.h"
+/*
#include "proxy.h"
+*/
#include "register.h"
+/*
#include "rename.h"
#include "target.h"
#include "targetable.h"
+*/
#include "../../helpers.h"
@@ -101,15 +107,21 @@ bool populate_arch_operands_module(void)
result = true;
+ /*
if (result) result = ensure_python_proxy_feeder_is_registered();
- if (result) result = ensure_python_imm_operand_is_registered();
- if (result) result = ensure_python_known_imm_operand_is_registered();
+ */
+ if (result) result = ensure_python_immediate_operand_is_registered();
+ if (result) result = ensure_python_known_immediate_operand_is_registered();
+ /*
if (result) result = ensure_python_proxy_operand_is_registered();
+ */
if (result) result = ensure_python_register_operand_is_registered();
+ /*
if (result) result = ensure_python_renamed_operand_is_registered();
if (result) result = ensure_python_renameable_operand_is_registered();
if (result) result = ensure_python_target_operand_is_registered();
if (result) result = ensure_python_targetable_operand_is_registered();
+ */
assert(result);
diff --git a/plugins/pychrysalide/arch/operands/register.c b/plugins/pychrysalide/arch/operands/register.c
index 2a48a0f..707524a 100644
--- a/plugins/pychrysalide/arch/operands/register.c
+++ b/plugins/pychrysalide/arch/operands/register.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* register.c - équivalent Python du fichier "arch/operands/register.c"
*
- * Copyright (C) 2019-2020 Cyrille Bagard
+ * Copyright (C) 2019-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -30,25 +30,19 @@
#include <i18n.h>
#include <arch/operands/register-int.h>
-#include <plugins/dt.h>
#include "../operand.h"
#include "../register.h"
#include "../../access.h"
#include "../../helpers.h"
-#include "../../glibext/bufferline.h"
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_register_operand_new(PyTypeObject *, PyObject *, PyObject *);
-
-/* Initialise la classe des descriptions de fichier binaire. */
-static void py_register_operand_init_gclass(GRegisterOperandClass *, gpointer);
+CREATE_DYN_CONSTRUCTOR(register_operand, G_TYPE_REGISTER_OPERAND);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_register_operand_init(PyObject *, PyObject *, PyObject *);
@@ -58,12 +52,6 @@ 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 *);
@@ -76,86 +64,6 @@ static PyObject *py_register_operand_get_register(PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_register_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* Validations diverses */
-
- base = get_python_register_operand_type();
-
- if (type == base)
- goto simple_way;
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_REGISTER_OPERAND, type->tp_name,
- (GClassInitFunc)py_register_operand_init_gclass, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
-
- if (!status)
- {
- result = NULL;
- goto exit;
- }
-
- }
-
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
-
- simple_way:
-
- result = PyType_GenericNew(type, args, kwds);
-
- exit:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : class = classe à initialiser. *
-* unused = données non utilisées ici. *
-* *
-* Description : Initialise la classe des descriptions de fichier binaire. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void py_register_operand_init_gclass(GRegisterOperandClass *class, gpointer unused)
-{
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
@@ -182,7 +90,7 @@ static int py_register_operand_init(PyObject *self, PyObject *args, PyObject *kw
"\n" \
" RegisterOperand(reg)" \
"\n" \
- "Where reg is an architecture register defined from a subclass of" \
+ "Where *reg* is an architecture register defined from a subclass of" \
" pychrysalide.arch.ArchRegister."
/* Récupération des paramètres */
@@ -199,8 +107,8 @@ static int py_register_operand_init(PyObject *self, PyObject *args, PyObject *kw
operand = G_REGISTER_OPERAND(pygobject_get(self));
- g_object_ref(G_OBJECT(reg));
- operand->reg = reg;
+ if (!g_register_operand_create(operand, reg))
+ return -1;
return 0;
@@ -215,98 +123,6 @@ 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. *
* *
@@ -367,8 +183,6 @@ static PyObject *py_register_operand_get_register(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 }
};
diff --git a/plugins/pychrysalide/arch/register.c b/plugins/pychrysalide/arch/register.c
index 615a5b7..7139e47 100644
--- a/plugins/pychrysalide/arch/register.c
+++ b/plugins/pychrysalide/arch/register.c
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* register.c - équivalent Python du fichier "arch/register.c"
*
- * Copyright (C) 2019 Cyrille Bagard
+ * Copyright (C) 2019-2025 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -31,32 +31,27 @@
#include <i18n.h>
#include <arch/register-int.h>
-#include <plugins/dt.h>
#include "../access.h"
#include "../helpers.h"
-#include "../analysis/storage/serialize.h"
+#include "../glibext/comparable.h"
+#include "../glibext/hashable.h"
+#include "../glibext/serialize.h"
+#include "../glibext/strbuilder.h"
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_arch_register_new(PyTypeObject *, PyObject *, PyObject *);
-
/* Initialise la classe des registres. */
-static void py_arch_register_init_gclass(GArchRegisterClass *, gpointer);
-
-/* Produit une empreinte à partir d'un registre. */
-static guint py_arch_register___hash___wrapper(const GArchRegister *);
+static int py_arch_register_init_gclass(GArchRegisterClass *, PyTypeObject *);
-/* Compare un registre avec un autre. */
-static int py_arch_register___cmp___wrapper(const GArchRegister *, const GArchRegister *);
+CREATE_DYN_ABSTRACT_CONSTRUCTOR(arch_register, G_TYPE_ARCH_REGISTER);
-/* Traduit un registre en version humainement lisible. */
-static void py_arch_register_print_wrapper(const GArchRegister *, GBufferLine *);
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_arch_register_init(PyObject *, PyObject *, PyObject *);
/* Indique si le registre correspond à ebp ou similaire. */
static bool py_arch_register_is_base_pointer_wrapper(const GArchRegister *);
@@ -69,9 +64,6 @@ static bool py_arch_register_is_stack_pointer_wrapper(const GArchRegister *);
/* ---------------------------- PUR REGISTRE DU MATERIEL ---------------------------- */
-/* Effectue une comparaison avec un objet Python 'ArchRegister'. */
-static PyObject *py_arch_register_richcompare(PyObject *, PyObject *, int);
-
/* Indique si le registre correspond à ebp ou similaire. */
static PyObject *py_arch_register_is_base_pointer(PyObject *, void *);
@@ -87,88 +79,8 @@ static PyObject *py_arch_register_is_stack_pointer(PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_arch_register_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de registre */
- bool status; /* Bilan d'un enregistrement */
-
-#define ARCH_REGISTER_DOC \
- "The ArchRegister object aims to get subclassed to create" \
- " registers suitable for new architectures.\n" \
- "\n" \
- "Calls to the *__init__* constructor of this abstract object expect"\
- " no particular argument.\n" \
- "\n" \
- "The following methods have to be defined for new classes:\n" \
- "* pychrysalide.arch.ArchRegister.__hash__();\n" \
- "* pychrysalide.arch.ArchRegister.__cmp__();\n" \
- "* pychrysalide.arch.ArchRegister._print();\n" \
- "* pychrysalide.arch.ArchRegister._is_base_pointer();\n" \
- "* pychrysalide.arch.ArchRegister._is_stack_pointer().\n" \
- "\n" \
- "Chrysalide creates an internal glue to provide rich comparisons" \
- " for registers based on the old-style *__cmp__* function."
-
- /* Validations diverses */
-
- base = get_python_arch_register_type();
-
- if (type == base)
- {
- result = NULL;
- PyErr_Format(PyExc_RuntimeError, _("%s is an abstract class"), type->tp_name);
- goto exit;
- }
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_ARCH_REGISTER, type->tp_name,
- (GClassInitFunc)py_arch_register_init_gclass, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
-
- if (!status)
- {
- result = NULL;
- goto exit;
- }
-
- }
-
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
-
- result = PyType_GenericNew(type, args, kwds);
-
- exit:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : class = classe à initialiser. *
-* unused = données non utilisées ici. *
+* Paramètres : gclass = classe GLib à initialiser. *
+* pyclass = classe Python à initialiser. *
* *
* Description : Initialise la classe des registres. *
* *
@@ -178,190 +90,51 @@ static PyObject *py_arch_register_new(PyTypeObject *type, PyObject *args, PyObje
* *
******************************************************************************/
-static void py_arch_register_init_gclass(GArchRegisterClass *class, gpointer unused)
-{
- class->hash = py_arch_register___hash___wrapper;
- class->compare = py_arch_register___cmp___wrapper;
- class->print = py_arch_register_print_wrapper;
- class->is_bp = py_arch_register_is_base_pointer_wrapper;
- class->is_sp = py_arch_register_is_stack_pointer_wrapper;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : reg = registre visé par la procédure. *
-* *
-* Description : Produit une empreinte à partir d'un registre. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static guint py_arch_register___hash___wrapper(const GArchRegister *reg)
-{
- guint result; /* Empreinte à retourner */
- PyGILState_STATE gstate; /* Sauvegarde d'environnement */
- PyObject *pyobj; /* Objet Python concerné */
- PyObject *pyret; /* Bilan de consultation */
-
-#define ARCH_REGISTER_HASH_WRAPPER PYTHON_WRAPPER_DEF \
-( \
- __hash__, "$self, /", \
- METH_NOARGS, \
- "Abstract method used to produce a hash of the object. The" \
- " result must be an integer value." \
-)
-
- result = 0;
-
- gstate = PyGILState_Ensure();
-
- pyobj = pygobject_new(G_OBJECT(reg));
-
- if (has_python_method(pyobj, "__hash__"))
- {
- pyret = run_python_method(pyobj, "__hash__", NULL);
-
- if (pyret != NULL)
- {
- if (PyLong_Check(pyret))
- result = PyLong_AsUnsignedLong(pyret);
-
- Py_DECREF(pyret);
-
- }
-
- }
-
- Py_DECREF(pyobj);
-
- PyGILState_Release(gstate);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : a = premier registre à consulter. *
-* b = second registre à consulter. *
-* *
-* Description : Compare un registre avec un autre. *
-* *
-* Retour : Bilan de la comparaison. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static int py_arch_register___cmp___wrapper(const GArchRegister *a, const GArchRegister *b)
+static int py_arch_register_init_gclass(GArchRegisterClass *gclass, PyTypeObject *pyclass)
{
- int result; /* Empreinte à retourner */
- PyGILState_STATE gstate; /* Sauvegarde d'environnement */
- PyObject *pyobj; /* Objet Python concerné */
- PyObject *args; /* Arguments pour l'appel */
- PyObject *pyret; /* Bilan de consultation */
-
-#define ARCH_REGISTER_CMP_WRAPPER PYTHON_WRAPPER_DEF \
-( \
- __cmp__, "$self, other, /", \
- METH_VARARGS, \
- "Abstract method used to compare the register with another" \
- " one. This second object is always an" \
- " pychrysalide.arch.ArchRegister instance.\n" \
- "\n" \
- " This is the Python old-style comparison method, but" \
- " Chrysalide provides a glue to automatically build a rich" \
- " version of this function." \
-)
-
- result = 0;
-
- gstate = PyGILState_Ensure();
-
- pyobj = pygobject_new(G_OBJECT(a));
-
- if (has_python_method(pyobj, "__cmp__"))
- {
- args = PyTuple_New(1);
- PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(b)));
-
- pyret = run_python_method(pyobj, "__cmp__", args);
-
- if (pyret != NULL)
- {
- if (PyLong_Check(pyret))
- result = PyLong_AsLong(pyret);
- }
+ PY_CLASS_SET_WRAPPER(gclass->is_bp, py_arch_register_is_base_pointer_wrapper);
+ PY_CLASS_SET_WRAPPER(gclass->is_sp, py_arch_register_is_stack_pointer_wrapper);
- Py_DECREF(args);
-
- Py_XDECREF(pyret);
-
- }
-
- Py_DECREF(pyobj);
-
- PyGILState_Release(gstate);
-
- return result;
+ return 0;
}
/******************************************************************************
* *
-* Paramètres : reg = registre visé par la procédure. *
+* Paramètres : self = objet à initialiser (théoriquement). *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
* *
-* Description : Traduit un registre en version humainement lisible. *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
* *
-* Retour : - *
+* Retour : 0. *
* *
* Remarques : - *
* *
******************************************************************************/
-static void py_arch_register_print_wrapper(const GArchRegister *reg, GBufferLine *line)
+static int py_arch_register_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyGILState_STATE gstate; /* Sauvegarde d'environnement */
- PyObject *pyobj; /* Objet Python concerné */
- PyObject *args; /* Arguments pour l'appel */
- PyObject *pyret; /* Bilan de consultation */
-
-#define ARCH_REGISTER_PRINT_WRAPPER PYTHON_WRAPPER_DEF \
-( \
- _print, "$self, line, /", \
- METH_VARARGS, \
- "Abstract method used to print the register into a rendering" \
- " line, which is a provided pychrysalide.glibext.BufferLine" \
- " instance." \
-)
-
- gstate = PyGILState_Ensure();
-
- pyobj = pygobject_new(G_OBJECT(reg));
-
- if (has_python_method(pyobj, "_print"))
- {
- args = PyTuple_New(1);
- PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(line)));
-
- pyret = run_python_method(pyobj, "_print", args);
-
- Py_DECREF(args);
+ int ret; /* Bilan de lecture des args. */
- Py_XDECREF(pyret);
+#define ARCH_REGISTER_DOC \
+ "The ArchRegister object aims to get subclassed in order to create" \
+ " registers suitable for new architectures.\n" \
+ "\n" \
+ "Calls to the *__init__* constructor of this abstract object expect"\
+ " no particular argument.\n" \
+ "\n" \
+ "The following methods may to be implemnted for new classes:\n" \
+ "* pychrysalide.arch.ArchRegister._is_base_pointer();\n" \
+ "* pychrysalide.arch.ArchRegister._is_stack_pointer().\n"
- }
+ /* Initialisation d'un objet GLib */
- Py_DECREF(pyobj);
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
- PyGILState_Release(gstate);
+ return 0;
}
@@ -486,51 +259,6 @@ static bool py_arch_register_is_stack_pointer_wrapper(const GArchRegister *reg)
/******************************************************************************
* *
-* Paramètres : a = premier object Python à consulter. *
-* b = second object Python à consulter. *
-* op = type de comparaison menée. *
-* *
-* Description : Effectue une comparaison avec un objet Python 'ArchRegister'.*
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_arch_register_richcompare(PyObject *a, PyObject *b, int op)
-{
- PyObject *result; /* Bilan à retourner */
- int ret; /* Bilan de lecture des args. */
- const GArchRegister *reg_a; /* Premier élément à traiter */
- const GArchRegister *reg_b; /* Second élément à traiter */
- int status; /* Résultat d'une comparaison */
-
- ret = PyObject_IsInstance(b, (PyObject *)get_python_arch_register_type());
- if (!ret)
- {
- result = Py_NotImplemented;
- goto cmp_done;
- }
-
- reg_a = G_ARCH_REGISTER(pygobject_get(a));
- reg_b = G_ARCH_REGISTER(pygobject_get(b));
-
- status = py_arch_register___cmp___wrapper(reg_a, reg_b);
-
- result = status_to_rich_cmp_state(status, op);
-
- cmp_done:
-
- Py_INCREF(result);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -618,9 +346,6 @@ static PyObject *py_arch_register_is_stack_pointer(PyObject *self, void *closure
PyTypeObject *get_python_arch_register_type(void)
{
static PyMethodDef py_arch_register_methods[] = {
- ARCH_REGISTER_HASH_WRAPPER,
- ARCH_REGISTER_CMP_WRAPPER,
- ARCH_REGISTER_PRINT_WRAPPER,
ARCH_REGISTER_IS_BASE_POINTER_WRAPPER,
ARCH_REGISTER_IS_STACK_POINTER_WRAPPER,
{ NULL }
@@ -643,11 +368,10 @@ PyTypeObject *get_python_arch_register_type(void)
.tp_doc = ARCH_REGISTER_DOC,
- .tp_richcompare = py_arch_register_richcompare,
-
.tp_methods = py_arch_register_methods,
.tp_getset = py_arch_register_getseters,
+ .tp_init = py_arch_register_init,
.tp_new = py_arch_register_new,
};
@@ -683,9 +407,20 @@ bool ensure_python_arch_register_is_registered(void)
dict = PyModule_GetDict(module);
+ if (!ensure_python_comparable_object_is_registered())
+ return false;
+
+ if (!ensure_python_hashable_object_is_registered())
+ return false;
+
if (!ensure_python_serializable_object_is_registered())
return false;
+ if (!ensure_python_string_builder_is_registered())
+ return false;
+
+ pyg_register_class_init(G_TYPE_ARCH_REGISTER, (PyGClassInitFunc)py_arch_register_init_gclass);
+
if (!register_class_for_pygobject(dict, G_TYPE_ARCH_REGISTER, type))
return false;