summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-02-04 12:23:04 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-02-04 12:23:04 (GMT)
commitec0f07c0b9468d6798befd887b02d9668faf806b (patch)
treef8b243f9b08006a4206b29b9af5b73a5d25361c7
parent296b4ed15fd074f80266e1d22ef4ade7ee11905e (diff)
Created a new interface for renamed operands.
-rw-r--r--plugins/pychrysalide/arch/operands/Makefile.am1
-rw-r--r--plugins/pychrysalide/arch/operands/immediate.c253
-rw-r--r--plugins/pychrysalide/arch/operands/immediate.h20
-rw-r--r--plugins/pychrysalide/arch/operands/module.c4
-rw-r--r--plugins/pychrysalide/arch/operands/rename.c314
-rw-r--r--plugins/pychrysalide/arch/operands/rename.h56
-rw-r--r--plugins/pychrysalide/arch/operands/targetable.c5
-rw-r--r--src/arch/operand-int.h11
-rw-r--r--src/arch/operand.c112
-rw-r--r--src/arch/operand.h3
-rw-r--r--src/arch/operands/Makefile.am2
-rw-r--r--src/arch/operands/immediate.c463
-rw-r--r--src/arch/operands/immediate.h29
-rw-r--r--src/arch/operands/rename-int.h76
-rw-r--r--src/arch/operands/rename.c152
-rw-r--r--src/arch/operands/rename.h84
16 files changed, 1431 insertions, 154 deletions
diff --git a/plugins/pychrysalide/arch/operands/Makefile.am b/plugins/pychrysalide/arch/operands/Makefile.am
index 7974c42..7938320 100644
--- a/plugins/pychrysalide/arch/operands/Makefile.am
+++ b/plugins/pychrysalide/arch/operands/Makefile.am
@@ -6,6 +6,7 @@ libpychrysaarchoperands_la_SOURCES = \
immediate.h immediate.c \
module.h module.c \
register.h register.c \
+ rename.h rename.c \
targetable.h targetable.c
libpychrysaarchoperands_la_LIBADD =
diff --git a/plugins/pychrysalide/arch/operands/immediate.c b/plugins/pychrysalide/arch/operands/immediate.c
index ab9e16c..6353655 100644
--- a/plugins/pychrysalide/arch/operands/immediate.c
+++ b/plugins/pychrysalide/arch/operands/immediate.c
@@ -36,6 +36,7 @@
#include "constants.h"
+#include "rename.h"
#include "targetable.h"
#include "../operand.h"
#include "../../access.h"
@@ -44,6 +45,9 @@
+/* ------------------------- OPERANDE POUR VALEUR IMMEDIATE ------------------------- */
+
+
/* Crée un nouvel objet Python de type 'ImmOperand'. */
static PyObject *py_imm_operand_new(PyTypeObject *, PyObject *, PyObject *);
@@ -79,6 +83,19 @@ static int py_imm_operand_set_display(PyObject *, PyObject *, void *);
+/* ----------------------- REMPLACEMENT DE VALEURS IMMEDIATES ----------------------- */
+
+
+/* Crée un nouvel objet Python de type 'KnownImmOperand'. */
+static PyObject *py_known_imm_operand_new(PyTypeObject *, PyObject *, PyObject *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* OPERANDE POUR VALEUR IMMEDIATE */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
* Paramètres : type = type de l'objet à instancier. *
@@ -610,7 +627,7 @@ PyTypeObject *get_python_imm_operand_type(void)
.tp_name = "pychrysalide.arch.operands.ImmOperand",
.tp_basicsize = sizeof(PyGObject),
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE,
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = IMM_OPERAND_DOC,
@@ -657,6 +674,9 @@ bool ensure_python_imm_operand_is_registered(void)
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, get_python_arch_operand_type()))
return false;
@@ -668,3 +688,234 @@ bool ensure_python_imm_operand_is_registered(void)
return true;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en opérande de valeur immédiate. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_imm_operand(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_imm_operand_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to immediate operand");
+ break;
+
+ case 1:
+ *((GImmOperand **)dst) = G_IMM_OPERAND(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* REMPLACEMENT DE VALEURS IMMEDIATES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de l'objet à instancier. *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Crée un nouvel objet Python de type 'KnownImmOperand'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_known_imm_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Instance à retourner */
+ GImmOperand *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" \
+ " display."
+
+ ret = PyArg_ParseTuple(args, "O&s", convert_to_imm_operand, &imm, &alt);
+ if (!ret) return NULL;
+
+ operand = g_known_imm_operand_new(imm, alt);
+
+ result = pygobject_new(G_OBJECT(operand));
+
+ g_object_unref(operand);
+
+ return (PyObject *)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_known_imm_operand_type(void)
+{
+ static PyMethodDef py_known_imm_operand_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_known_imm_operand_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_known_imm_operand_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.arch.operands.KnownImmOperand",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = KNOWN_IMM_OPERAND_DOC,
+
+ .tp_methods = py_known_imm_operand_methods,
+ .tp_getset = py_known_imm_operand_getseters,
+ .tp_new = py_known_imm_operand_new
+
+ };
+
+ return &py_known_imm_operand_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.arch.KnownImmOperand'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_known_imm_operand_is_registered(void)
+{
+ PyTypeObject *type; /* Type Python 'ImmOperand' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_known_imm_operand_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.arch.operands");
+
+ dict = PyModule_GetDict(module);
+
+ if (!ensure_python_imm_operand_is_registered())
+ return false;
+
+ if (!ensure_python_renamed_operand_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, G_TYPE_KNOWN_IMM_OPERAND, type, get_python_imm_operand_type()))
+ return false;
+
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en remplaçant d'opérande d'immédiat. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_known_imm_operand(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_known_imm_operand_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to known immediate operand");
+ break;
+
+ case 1:
+ *((GKnownImmOperand **)dst) = G_KNOWN_IMM_OPERAND(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/arch/operands/immediate.h b/plugins/pychrysalide/arch/operands/immediate.h
index 9f32758..fe5d4a9 100644
--- a/plugins/pychrysalide/arch/operands/immediate.h
+++ b/plugins/pychrysalide/arch/operands/immediate.h
@@ -31,12 +31,32 @@
+/* ------------------------- OPERANDE POUR VALEUR IMMEDIATE ------------------------- */
+
+
/* Fournit un accès à une définition de type à diffuser. */
PyTypeObject *get_python_imm_operand_type(void);
/* Prend en charge l'objet 'pychrysalide.arch.ImmOperand'. */
bool ensure_python_imm_operand_is_registered(void);
+/* Tente de convertir en opérande de valeur immédiate. */
+int convert_to_imm_operand(PyObject *, void *);
+
+
+
+/* ----------------------- REMPLACEMENT DE VALEURS IMMEDIATES ----------------------- */
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_known_imm_operand_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.arch.KnownImmOperand'. */
+bool ensure_python_known_imm_operand_is_registered(void);
+
+/* Tente de convertir en remplaçant d'opérande d'immédiat. */
+int convert_to_known_imm_operand(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_IMMEDIATE_H */
diff --git a/plugins/pychrysalide/arch/operands/module.c b/plugins/pychrysalide/arch/operands/module.c
index f800e38..34614b3 100644
--- a/plugins/pychrysalide/arch/operands/module.c
+++ b/plugins/pychrysalide/arch/operands/module.c
@@ -30,6 +30,7 @@
#include "immediate.h"
#include "register.h"
+#include "rename.h"
#include "targetable.h"
#include "../../helpers.h"
@@ -97,7 +98,10 @@ bool populate_arch_operands_module(void)
result = true;
if (result) result = ensure_python_imm_operand_is_registered();
+ if (result) result = ensure_python_known_imm_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_targetable_operand_is_registered();
assert(result);
diff --git a/plugins/pychrysalide/arch/operands/rename.c b/plugins/pychrysalide/arch/operands/rename.c
new file mode 100644
index 0000000..da1543b
--- /dev/null
+++ b/plugins/pychrysalide/arch/operands/rename.c
@@ -0,0 +1,314 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * rename.c - prototypes pour l'équivalent Python du fichier "arch/operands/rename.c"
+ *
+ * Copyright (C) 2020 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 "rename.h"
+
+
+#include <pygobject.h>
+
+
+#include <arch/operands/rename.h>
+
+
+#include "../../access.h"
+#include "../../helpers.h"
+
+
+
+/* ------------------------ INTERFACE POUR OPERANDE RENOMMEE ------------------------ */
+
+
+#define RENAMED_OPERAND_DOC \
+ "The RenamedOperand interface depicts operands renamed with an" \
+ " alternative text."
+
+
+/* Fournit un texte comme représentation alternative d'opérande. */
+static PyObject *py_renamed_operand_get_text(PyObject *, void *);
+
+
+
+/* ----------------------- INTERFACE POUR OPERANDE RENOMMABLE ----------------------- */
+
+
+#define RENAMEABLE_OPERAND_DOC \
+ "The RenameableOperand interface depicts operands which can get" \
+ " renamed with an alternative text." \
+
+
+/* Construit un opérande de représentation alternative. */
+static PyObject *py_renameable_operand_build(PyObject *, PyObject *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTERFACE POUR OPERANDE RENOMMEE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit un texte comme représentation alternative d'opérande.*
+* *
+* Retour : Chaîne de caractère de représentation alternative. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_renamed_operand_get_text(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GRenamedOperand *operand; /* Elément à consulter */
+ const char *text; /* Texte alternatif de rendu */
+
+#define RENAMED_OPERAND_TEXT_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ text, py_renamed_operand, \
+ "Alternative text for the operand rendering." \
+)
+
+ operand = G_RENAMED_OPERAND(pygobject_get(self));
+ text = g_renamed_operand_get_text(operand);
+
+ result = PyUnicode_FromString(text);
+
+ 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_renamed_operand_type(void)
+{
+ static PyMethodDef py_renamed_operand_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_renamed_operand_getseters[] = {
+ RENAMED_OPERAND_TEXT_ATTRIB,
+ { NULL }
+ };
+
+ static PyTypeObject py_renamed_operand_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.arch.operands.RenamedOperand",
+ .tp_basicsize = sizeof(PyObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = RENAMED_OPERAND_DOC,
+
+ .tp_methods = py_renamed_operand_methods,
+ .tp_getset = py_renamed_operand_getseters
+
+ };
+
+ return &py_renamed_operand_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.....RenamedOperand'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_renamed_operand_is_registered(void)
+{
+ PyTypeObject *type; /* Type 'RenamedOperand' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_renamed_operand_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.arch.operands");
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_interface_for_pygobject(dict, G_TYPE_RENAMED_OPERAND, type))
+ return false;
+
+ }
+
+ return true;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTERFACE POUR OPERANDE RENOMMABLE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : self = contenu binaire à manipuler. *
+* args = argument accompagnant l'appel. *
+* *
+* Description : Construit un opérande de représentation alternative. *
+* *
+* Retour : Nouvel opérande, en version renommée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_renameable_operand_build(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Instance à retourner */
+ const char *text; /* Texte alternatif à utiliser */
+ int ret; /* Bilan de lecture des args. */
+ GRenameableOperand *operand; /* Instance à manipuler */
+ GRenamedOperand *renamed; /* Instance nouvelle */
+
+#define RENAMEABLE_OPERAND_BUILD_METHOD PYTHON_METHOD_DEF \
+( \
+ build, "$self, text", \
+ METH_VARARGS, py_renameable_operand, \
+ "Build a new operand with an alternative text as rendering." \
+ "\n" \
+ "The result of the call is an object implementing the" \
+ " pychrysalide.arch.operands.RenamedOperand interface." \
+)
+
+ ret = PyArg_ParseTuple(args, "s", &text);
+ if (!ret) return NULL;
+
+ operand = G_RENAMEABLE_OPERAND(pygobject_get(self));
+
+ renamed = g_renameable_operand_build(operand, text);
+
+ result = pygobject_new(G_OBJECT(renamed));
+ g_object_unref(G_OBJECT(renamed));
+
+ 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_renameable_operand_type(void)
+{
+ static PyMethodDef py_renameable_operand_methods[] = {
+ RENAMEABLE_OPERAND_BUILD_METHOD,
+ { NULL }
+ };
+
+ static PyGetSetDef py_renameable_operand_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_renameable_operand_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.arch.operands.RenameableOperand",
+ .tp_basicsize = sizeof(PyObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = RENAMEABLE_OPERAND_DOC,
+
+ .tp_methods = py_renameable_operand_methods,
+ .tp_getset = py_renameable_operand_getseters
+
+ };
+
+ return &py_renameable_operand_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.....RenameableOperand'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_renameable_operand_is_registered(void)
+{
+ PyTypeObject *type; /* Type 'RenameableOperand' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_renameable_operand_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.arch.operands");
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_interface_for_pygobject(dict, G_TYPE_RENAMEABLE_OPERAND, type))
+ return false;
+
+ }
+
+ return true;
+
+}
diff --git a/plugins/pychrysalide/arch/operands/rename.h b/plugins/pychrysalide/arch/operands/rename.h
new file mode 100644
index 0000000..a7f9233
--- /dev/null
+++ b/plugins/pychrysalide/arch/operands/rename.h
@@ -0,0 +1,56 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * rename.h - prototypes pour l'équivalent Python du fichier "arch/operands/rename.h"
+ *
+ * Copyright (C) 2020 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_OPERANDS_RENAME_H
+#define _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_RENAME_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* ------------------------ INTERFACE POUR OPERANDE RENOMMEE ------------------------ */
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_renamed_operand_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.arch.RenamedOperand'. */
+bool ensure_python_renamed_operand_is_registered(void);
+
+
+
+/* ----------------------- INTERFACE POUR OPERANDE RENOMMABLE ----------------------- */
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_renameable_operand_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.arch.RenameableOperand'. */
+bool ensure_python_renameable_operand_is_registered(void);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_RENAME_H */
diff --git a/plugins/pychrysalide/arch/operands/targetable.c b/plugins/pychrysalide/arch/operands/targetable.c
index a633b82..00647cc 100644
--- a/plugins/pychrysalide/arch/operands/targetable.c
+++ b/plugins/pychrysalide/arch/operands/targetable.c
@@ -28,9 +28,6 @@
#include <pygobject.h>
-#include <i18n.h>
-
-
#include <arch/operands/targetable.h>
@@ -59,7 +56,7 @@ static PyObject *py_targetable_operand_get_addr(PyObject *, PyObject *);
/******************************************************************************
* *
* Paramètres : self = contenu binaire à manipuler. *
-* args = non utilisé ici. *
+* args = arguments accompagnant l'appel. *
* *
* Description : Obtient l'adresse de la cible visée par un opérande. *
* *
diff --git a/src/arch/operand-int.h b/src/arch/operand-int.h
index bd12904..dda4a11 100644
--- a/src/arch/operand-int.h
+++ b/src/arch/operand-int.h
@@ -45,22 +45,11 @@ typedef bool (* unserialize_operand_fc) (GArchOperand *, GAsmStorage *, GBinForm
typedef bool (* serialize_operand_fc) (const GArchOperand *, GAsmStorage *, packed_buffer *);
-/* Adjonction de rendu alternatif */
-typedef struct _alt_rendering
-{
- RenderingTagType tag; /* Type de rendu */
- char text[0]; /* Texte alternatif */
-
-} alt_rendering;
-
-
/* Définition générique d'un opérande d'architecture (instance) */
struct _GArchOperand
{
GObject parent; /* A laisser en premier */
- alt_rendering *alt_info; /* Autre rendu éventuel */
-
};
diff --git a/src/arch/operand.c b/src/arch/operand.c
index 5936979..e5bfb0a 100644
--- a/src/arch/operand.c
+++ b/src/arch/operand.c
@@ -152,8 +152,6 @@ static void g_arch_operand_dispose(GArchOperand *operand)
static void g_arch_operand_finalize(GArchOperand *operand)
{
- g_arch_operand_set_alt_text(operand, NULL, RTT_COUNT);
-
G_OBJECT_CLASS(g_arch_operand_parent_class)->finalize(G_OBJECT(operand));
}
@@ -196,51 +194,6 @@ int g_arch_operand_compare(const GArchOperand *a, const GArchOperand *b)
/******************************************************************************
* *
* Paramètres : operand = opérande à traiter. *
-* text = représentation lisible alternative. *
-* tag = style d'impression pour le remplacement. *
-* *
-* Description : Définit une autre représentation textuelle pour l'opérande. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_arch_operand_set_alt_text(GArchOperand *operand, const char *text, RenderingTagType tag)
-{
- size_t alt_len; /* Taille du texte alternatif */
-
- if (operand->alt_info != NULL)
- free(operand->alt_info);
-
- if (text == NULL)
- operand->alt_info = NULL;
-
- else
- {
- alt_len = strlen(text);
-
- if (alt_len == 0)
- operand->alt_info = NULL;
-
- else
- {
- operand->alt_info = (alt_rendering *)malloc(sizeof(RenderingTagType) + alt_len + 1);
-
- operand->alt_info->tag = tag;
- strcpy(operand->alt_info->text, text);
-
- }
-
- }
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : operand = opérande à traiter. *
* line = ligne tampon où imprimer l'opérande donné. *
* *
* Description : Traduit un opérande en version humainement lisible. *
@@ -253,21 +206,7 @@ void g_arch_operand_set_alt_text(GArchOperand *operand, const char *text, Render
void g_arch_operand_print(const GArchOperand *operand, GBufferLine *line)
{
- size_t alt_len; /* Taille du texte alternatif */
-
- if (operand->alt_info != NULL)
- {
- alt_len = strlen(operand->alt_info->text);
-
- g_buffer_line_append_text(line, BLC_ASSEMBLY,
- operand->alt_info->text,
- alt_len,
- operand->alt_info->tag,
- NULL);
-
- }
- else
- G_ARCH_OPERAND_GET_CLASS(operand)->print(operand, line);
+ G_ARCH_OPERAND_GET_CLASS(operand)->print(operand, line);
}
@@ -326,28 +265,8 @@ char *g_arch_operand_build_tooltip(const GArchOperand *operand, const GLoadedBin
static bool g_arch_operand_unserialize(GArchOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf)
{
bool result; /* Bilan à retourner */
- unsigned char len; /* Taille du contenu alternatif*/
- char *text; /* Texte alternatif */
- RenderingTagType tag; /* Type de rendu */
-
- result = extract_packed_buffer(pbuf, &len, sizeof(unsigned char), false);
-
- if (result && len > 0)
- {
- text = (char *)malloc(len);
-
- if (result)
- result = extract_packed_buffer(pbuf, text, len, false);
-
- if (result)
- result = extract_packed_buffer(pbuf, &tag, sizeof(RenderingTagType), true);
-
- if (result)
- g_arch_operand_set_alt_text(operand, text, tag);
- free(text);
-
- }
+ result = true;
return result;
@@ -409,33 +328,8 @@ GArchOperand *g_arch_operand_load(GAsmStorage *storage, GBinFormat *format, pack
static bool g_arch_operand_serialize(const GArchOperand *operand, GAsmStorage *storage, packed_buffer *pbuf)
{
bool result; /* Bilan à retourner */
- size_t len; /* Taille du contenu alternatif*/
- if (operand->alt_info == NULL)
- result = extend_packed_buffer(pbuf, (unsigned char []) { 0 }, sizeof(unsigned char), false);
-
- else
- {
- len = strlen(operand->alt_info->text) + 1;
- assert(len > 1);
-
- if (len > (2 << (sizeof(unsigned char) * 8 - 1)))
- {
- log_variadic_message(LMT_ERROR, "Alternative text too long: '%s' (%zu bytes)",
- operand->alt_info->text, len);
- result = false;
- }
-
- else
- result = extend_packed_buffer(pbuf, (unsigned char []) { len }, sizeof(unsigned char), false);
-
- if (result)
- result = extend_packed_buffer(pbuf, operand->alt_info->text, len, false);
-
- if (result)
- result = extend_packed_buffer(pbuf, &operand->alt_info->tag, sizeof(RenderingTagType), true);
-
- }
+ result = true;
return result;
diff --git a/src/arch/operand.h b/src/arch/operand.h
index a881a91..05405ef 100644
--- a/src/arch/operand.h
+++ b/src/arch/operand.h
@@ -62,9 +62,6 @@ GType g_arch_operand_get_type(void);
/* Compare un opérande avec un autre. */
int g_arch_operand_compare(const GArchOperand *, const GArchOperand *);
-/* Définit une autre représentation textuelle pour l'opérande. */
-void g_arch_operand_set_alt_text(GArchOperand *, const char *, RenderingTagType);
-
/* Traduit un opérande en version humainement lisible. */
void g_arch_operand_print(const GArchOperand *, GBufferLine *);
diff --git a/src/arch/operands/Makefile.am b/src/arch/operands/Makefile.am
index 3d464e3..4e52f58 100644
--- a/src/arch/operands/Makefile.am
+++ b/src/arch/operands/Makefile.am
@@ -5,6 +5,8 @@ libarchoperands_la_SOURCES = \
immediate.h immediate.c \
register-int.h \
register.h register.c \
+ rename-int.h \
+ rename.h rename.c \
targetable-int.h \
targetable.h targetable.c
diff --git a/src/arch/operands/immediate.c b/src/arch/operands/immediate.c
index 0ecb5f7..58e40aa 100644
--- a/src/arch/operands/immediate.c
+++ b/src/arch/operands/immediate.c
@@ -37,14 +37,19 @@
#include <i18n.h>
+#include "rename-int.h"
#include "targetable-int.h"
#include "../operand-int.h"
#include "../../common/asm.h"
#include "../../common/extstr.h"
+#include "../../core/logs.h"
#include "../../format/format.h"
+/* ------------------------- OPERANDE POUR VALEUR IMMEDIATE ------------------------- */
+
+
/* Définition d'un opérande de valeur numérique (instance) */
struct _GImmOperand
{
@@ -81,15 +86,18 @@ struct _GImmOperandClass
};
-/* Initialise la classe des lignes de descriptions initiales. */
+/* Initialise la classe des opérandes de valeur immédiate. */
static void g_imm_operand_class_init(GImmOperandClass *);
-/* Initialise la classe des lignes de descriptions initiales. */
+/* Initialise un opérande de valeur immédiate. */
static void g_imm_operand_init(GImmOperand *);
/* Procède à l'initialisation de l'interface de ciblage. */
static void g_imm_operand_targetable_interface_init(GTargetableOperandInterface *);
+/* Procède à l'initialisation de l'interface de renommage. */
+static void g_imm_operand_renameable_interface_init(GRenameableOperandInterface *);
+
/* Supprime toutes les références externes. */
static void g_imm_operand_dispose(GImmOperand *);
@@ -111,38 +119,88 @@ static void g_imm_operand_print(const GImmOperand *, GBufferLine *);
/* Construit un petit résumé concis de l'opérande. */
static char *g_imm_operand_build_tooltip(const GImmOperand *, const GLoadedBinary *);
-
-
-/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */
-
-
/* Charge un opérande depuis une mémoire tampon. */
static bool g_imm_operand_unserialize(GImmOperand *, GAsmStorage *, GBinFormat *, packed_buffer *);
/* Sauvegarde un opérande dans une mémoire tampon. */
static bool g_imm_operand_serialize(const GImmOperand *, GAsmStorage *, packed_buffer *);
+/* Obtient l'adresse de la cible visée par un opérande. */
+static bool g_imm_operand_get_addr(const GImmOperand *, const vmpa2t *, GBinFormat *, GArchProcessor *, vmpa2t *);
+/* Construit un opérande de représentation alternative. */
+static GRenamedOperand *g_imm_operand_build(const GImmOperand *, const char *);
-/* ----------------------- INTERFACE DE CIBLAGE POUR OPERANDE ----------------------- */
-/* Obtient l'adresse de la cible visée par un opérande. */
-static bool g_imm_operand_get_addr(const GImmOperand *, const vmpa2t *, GBinFormat *, GArchProcessor *, vmpa2t *);
+/* ----------------------- REMPLACEMENT DE VALEURS IMMEDIATES ----------------------- */
+
+
+/* Définition d'un remplacement d'opérande de valeur numérique (instance) */
+struct _GKnownImmOperand
+{
+ GImmOperand parent; /* Instance parente */
+
+ char *alt_text; /* Alternative humaine */
+
+};
+
+/* Définition d'un remplacement d'opérande de valeur numérique (classe) */
+struct _GKnownImmOperandClass
+{
+ GImmOperandClass parent; /* Classe parente */
+
+};
+
+/* Initialise la classe des remplacements d'opérandes. */
+static void g_known_imm_operand_class_init(GKnownImmOperandClass *);
+
+/* Initialise un remplacement d'opérande de valeur immédiate. */
+static void g_known_imm_operand_init(GKnownImmOperand *);
+
+/* Procède à l'initialisation de l'interface de renommage. */
+static void g_known_imm_operand_renamed_interface_init(GRenamedOperandInterface *);
+
+/* Supprime toutes les références externes. */
+static void g_known_imm_operand_dispose(GKnownImmOperand *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_known_imm_operand_finalize(GKnownImmOperand *);
+
+/* Compare un opérande avec un autre. */
+static int g_known_imm_operand_compare(const GKnownImmOperand *, const GKnownImmOperand *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void g_known_imm_operand_print(const GKnownImmOperand *, GBufferLine *);
+
+/* Charge un opérande depuis une mémoire tampon. */
+static bool g_known_imm_operand_unserialize(GKnownImmOperand *, GAsmStorage *, GBinFormat *, packed_buffer *);
+
+/* Sauvegarde un opérande dans une mémoire tampon. */
+static bool g_known_imm_operand_serialize(const GKnownImmOperand *, GAsmStorage *, packed_buffer *);
+
+/* Fournit un texte comme représentation alternative d'opérande. */
+static const char *g_known_imm_operand_get_text(const GKnownImmOperand *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* OPERANDE POUR VALEUR IMMEDIATE */
+/* ---------------------------------------------------------------------------------- */
/* Indique le type défini pour un opérande de valeur numérique. */
G_DEFINE_TYPE_WITH_CODE(GImmOperand, g_imm_operand, G_TYPE_ARCH_OPERAND,
- G_IMPLEMENT_INTERFACE(G_TYPE_TARGETABLE_OPERAND, g_imm_operand_targetable_interface_init));
-
+ G_IMPLEMENT_INTERFACE(G_TYPE_TARGETABLE_OPERAND, g_imm_operand_targetable_interface_init)
+ G_IMPLEMENT_INTERFACE(G_TYPE_RENAMEABLE_OPERAND, g_imm_operand_renameable_interface_init));
/******************************************************************************
* *
* Paramètres : klass = classe à initialiser. *
* *
-* Description : Initialise la classe des lignes de descriptions initiales. *
+* Description : Initialise la classe des opérandes de valeur immédiate. *
* *
* Retour : - *
* *
@@ -175,7 +233,7 @@ static void g_imm_operand_class_init(GImmOperandClass *klass)
* *
* Paramètres : operand = instance à initialiser. *
* *
-* Description : Initialise la classe des lignes de descriptions initiales. *
+* Description : Initialise un opérande de valeur immédiate. *
* *
* Retour : - *
* *
@@ -214,6 +272,25 @@ static void g_imm_operand_targetable_interface_init(GTargetableOperandInterface
/******************************************************************************
* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de renommage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_imm_operand_renameable_interface_init(GRenameableOperandInterface *iface)
+{
+ iface->build = (build_renameable_fc)g_imm_operand_build;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : operand = instance d'objet GLib à traiter. *
* *
* Description : Supprime toutes les références externes. *
@@ -1403,12 +1480,6 @@ bool g_imm_operand_to_off_t(const GImmOperand *operand, off_t *value, bool *nega
}
-
-/* ---------------------------------------------------------------------------------- */
-/* TRANSPOSITIONS VIA CACHE DES OPERANDES */
-/* ---------------------------------------------------------------------------------- */
-
-
/******************************************************************************
* *
* Paramètres : operand = opérande d'assemblage à constituer. *
@@ -1496,12 +1567,6 @@ static bool g_imm_operand_serialize(const GImmOperand *operand, GAsmStorage *sto
}
-
-/* ---------------------------------------------------------------------------------- */
-/* INTERFACE DE CIBLAGE POUR OPERANDE */
-/* ---------------------------------------------------------------------------------- */
-
-
/******************************************************************************
* *
* Paramètres : operand = operande à consulter. *
@@ -1531,3 +1596,349 @@ static bool g_imm_operand_get_addr(const GImmOperand *operand, const vmpa2t *src
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = operande à consulter. *
+* text = texte alternatif de représentation. *
+* *
+* Description : Construit un opérande de représentation alternative. *
+* *
+* Retour : Nouvel opérande, en version renommée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GRenamedOperand *g_imm_operand_build(const GImmOperand *operand, const char *text)
+{
+ GRenamedOperand *result; /* Instance à retourner */
+
+ result = G_RENAMED_OPERAND(g_known_imm_operand_new(operand, text));
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* REMPLACEMENT DE VALEURS IMMEDIATES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour un remplacemet d'opérande de valeur numérique. */
+G_DEFINE_TYPE_WITH_CODE(GKnownImmOperand, g_known_imm_operand, G_TYPE_IMM_OPERAND,
+ G_IMPLEMENT_INTERFACE(G_TYPE_RENAMED_OPERAND, g_known_imm_operand_renamed_interface_init));
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des remplacements d'opérandes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_known_imm_operand_class_init(GKnownImmOperandClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GArchOperandClass *operand; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+ operand = G_ARCH_OPERAND_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_known_imm_operand_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_known_imm_operand_finalize;
+
+ operand->compare = (operand_compare_fc)g_known_imm_operand_compare;
+ operand->print = (operand_print_fc)g_known_imm_operand_print;
+
+ operand->unserialize = (unserialize_operand_fc)g_known_imm_operand_unserialize;
+ operand->serialize = (serialize_operand_fc)g_known_imm_operand_serialize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise un remplacement d'opérande de valeur immédiate. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_known_imm_operand_init(GKnownImmOperand *operand)
+{
+ operand->alt_text = NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de renommage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_known_imm_operand_renamed_interface_init(GRenamedOperandInterface *iface)
+{
+ iface->get_text = (get_renamed_text_fc)g_known_imm_operand_get_text;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_known_imm_operand_dispose(GKnownImmOperand *operand)
+{
+ G_OBJECT_CLASS(g_known_imm_operand_parent_class)->dispose(G_OBJECT(operand));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_known_imm_operand_finalize(GKnownImmOperand *operand)
+{
+ G_OBJECT_CLASS(g_known_imm_operand_parent_class)->finalize(G_OBJECT(operand));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : old = opérande à venir copier avant son remplacement. *
+* alt = texte alternatif à présenter pour l'impression. *
+* *
+* Description : Crée un opérande remplaçant visuellement une valeur. *
+* *
+* Retour : Instruction mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_known_imm_operand_new(const GImmOperand *old, const char *alt)
+{
+ GKnownImmOperand *result; /* Remplacement à retourner */
+
+ result = g_object_new(G_TYPE_KNOWN_IMM_OPERAND, NULL);
+
+ result->parent.raw = old->raw;
+
+ result->parent.size = old->size;
+ result->parent.def_display = old->def_display;
+ result->parent.display = old->display;
+ result->parent.misc = old->misc;
+
+ result->alt_text = strdup(alt);
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : a = premier opérande à consulter. *
+* b = second opérande à consulter. *
+* *
+* Description : Compare un opérande avec un autre. *
+* *
+* Retour : Bilan de la comparaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int g_known_imm_operand_compare(const GKnownImmOperand *a, const GKnownImmOperand *b)
+{
+ int result; /* Bilan à retourner */
+ GArchOperandClass *class; /* Classe parente à consulter */
+
+ class = G_ARCH_OPERAND_CLASS(g_known_imm_operand_parent_class);
+
+ result = class->compare(G_ARCH_OPERAND(a), G_ARCH_OPERAND(b));
+
+ if (result == 0)
+ result = strcmp(a->alt_text, b->alt_text);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
+* line = ligne tampon où imprimer l'opérande donné. *
+* *
+* Description : Traduit un opérande en version humainement lisible. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_known_imm_operand_print(const GKnownImmOperand *operand, GBufferLine *line)
+{
+ size_t len; /* Taille de l'élément inséré */
+
+ len = strlen(operand->alt_text);
+
+ g_buffer_line_append_text(line, BLC_MAIN, operand->alt_text, len, RTT_IMMEDIATE, G_OBJECT(operand));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande d'assemblage à constituer. *
+* storage = mécanisme de sauvegarde à manipuler. *
+* format = format binaire chargé associé à l'architecture. *
+* pbuf = zone tampon à remplir. *
+* *
+* Description : Charge un opérande depuis une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_known_imm_operand_unserialize(GKnownImmOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchOperandClass *parent; /* Classe parente à consulter */
+ unsigned short len; /* Taille du contenu alternatif*/
+
+ parent = G_ARCH_OPERAND_CLASS(g_known_imm_operand_parent_class);
+
+ result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf);
+
+ if (result)
+ result = extract_packed_buffer(pbuf, &len, sizeof(unsigned short), true);
+
+ if (result)
+ result = (len > 0);
+
+ if (result)
+ {
+ operand->alt_text = malloc(len);
+
+ result = extract_packed_buffer(pbuf, operand->alt_text, len, false);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande d'assemblage à consulter. *
+* storage = mécanisme de sauvegarde à manipuler. *
+* pbuf = zone tampon à remplir. *
+* *
+* Description : Sauvegarde un opérande dans une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_known_imm_operand_serialize(const GKnownImmOperand *operand, GAsmStorage *storage, packed_buffer *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchOperandClass *parent; /* Classe parente à consulter */
+ size_t len; /* Taille du contenu alternatif*/
+
+ parent = G_ARCH_OPERAND_CLASS(g_known_imm_operand_parent_class);
+
+ result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf);
+
+ if (result)
+ {
+ len = strlen(operand->alt_text) + 1;
+ assert(len > 1);
+
+ if (len > (2 << (sizeof(unsigned short) * 8 - 1)))
+ {
+ log_variadic_message(LMT_ERROR, "Alternative text too long: '%s' (%zu bytes)",
+ operand->alt_text, len);
+ result = false;
+ }
+
+ else
+ result = extend_packed_buffer(pbuf, (unsigned short []) { len }, sizeof(unsigned short), true);
+
+ if (result)
+ result = extend_packed_buffer(pbuf, operand->alt_text, len, false);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = operande à consulter. *
+* *
+* Description : Fournit un texte comme représentation alternative d'opérande.*
+* *
+* Retour : Chaîne de caractère de représentation alternative. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_known_imm_operand_get_text(const GKnownImmOperand *operand)
+{
+ const char *result; /* Texte à retourner */
+
+ result = operand->alt_text;
+
+ return result;
+
+}
diff --git a/src/arch/operands/immediate.h b/src/arch/operands/immediate.h
index 4d9a77e..28fe7ba 100644
--- a/src/arch/operands/immediate.h
+++ b/src/arch/operands/immediate.h
@@ -36,6 +36,9 @@
+/* ------------------------- OPERANDE POUR VALEUR IMMEDIATE ------------------------- */
+
+
/* Grande ligne d'un format d'affichage */
typedef enum _ImmOperandDisplay
{
@@ -154,4 +157,30 @@ bool g_imm_operand_to_off_t(const GImmOperand *, off_t *, bool *) __attribute__
+/* ----------------------- REMPLACEMENT DE VALEURS IMMEDIATES ----------------------- */
+
+
+#define G_TYPE_KNOWN_IMM_OPERAND g_known_imm_operand_get_type()
+#define G_KNOWN_IMM_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_KNOWN_IMM_OPERAND, GKnownImmOperand))
+#define G_IS_KNOWN_IMM_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_KNOWN_IMM_OPERAND))
+#define G_KNOWN_IMM_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_KNOWN_IMM_OPERAND, GKnownImmOperandClass))
+#define G_IS_KNOWN_IMM_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_KNOWN_IMM_OPERAND))
+#define G_KNOWN_IMM_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_KNOWN_IMM_OPERAND, GKnownImmOperandClass))
+
+
+/* Définition d'un remplacement d'opérande de valeur numérique (instance) */
+typedef struct _GKnownImmOperand GKnownImmOperand;
+
+/* Définition d'un remplacement d'opérande de valeur numérique (classe) */
+typedef struct _GKnownImmOperandClass GKnownImmOperandClass;
+
+
+/* Indique le type défini pour un remplacemet d'opérande de valeur numérique. */
+GType g_known_imm_operand_get_type(void);
+
+/* Crée un opérande remplaçant visuellement une valeur. */
+GArchOperand *g_known_imm_operand_new(const GImmOperand *, const char *);
+
+
+
#endif /* _ARCH_OPERANDS_IMMEDIATE_H */
diff --git a/src/arch/operands/rename-int.h b/src/arch/operands/rename-int.h
new file mode 100644
index 0000000..28653b9
--- /dev/null
+++ b/src/arch/operands/rename-int.h
@@ -0,0 +1,76 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * rename-int.h - définitions internes propres aux opérandes ciblant une portion de désassemblage
+ *
+ * Copyright (C) 2020 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_OPERANDS_RENAME_INT_H
+#define _ARCH_OPERANDS_RENAME_INT_H
+
+
+#include "rename.h"
+
+
+
+/* ------------------------ INTERFACE POUR OPERANDE RENOMMEE ------------------------ */
+
+
+/* Obtient l'adresse de la cible visée par un opérande. */
+typedef const char * (* get_renamed_text_fc) (const GRenamedOperand *);
+
+
+/* Opérande renommé avec un texte alternatif (interface) */
+struct _GRenamedOperandIface
+{
+ GTypeInterface base_iface; /* A laisser en premier */
+
+ get_renamed_text_fc get_text; /* Récupération d'alternative */
+
+};
+
+
+/* Redéfinition */
+typedef GRenamedOperandIface GRenamedOperandInterface;
+
+
+
+/* ----------------------- INTERFACE POUR OPERANDE RENOMMABLE ----------------------- */
+
+
+/* Obtient l'adresse de la cible visée par un opérande. */
+typedef GRenamedOperand * (* build_renameable_fc) (const GRenameableOperand *, const char *);
+
+
+/* Opérande offrant une capacité de renommage (interface) */
+struct _GRenameableOperandIface
+{
+ GTypeInterface base_iface; /* A laisser en premier */
+
+ build_renameable_fc build; /* Obtention de la cible */
+
+};
+
+
+/* Redéfinition */
+typedef GRenameableOperandIface GRenameableOperandInterface;
+
+
+
+#endif /* _ARCH_OPERANDS_RENAME_INT_H */
diff --git a/src/arch/operands/rename.c b/src/arch/operands/rename.c
new file mode 100644
index 0000000..e865b63
--- /dev/null
+++ b/src/arch/operands/rename.c
@@ -0,0 +1,152 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * rename.c - opérandes pouvant être renommées
+ *
+ * Copyright (C) 2020 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "rename.h"
+
+
+#include "rename-int.h"
+
+
+
+/* ------------------------ INTERFACE POUR OPERANDE RENOMMEE ------------------------ */
+
+
+/* Procède à l'initialisation de l'interface de renommage. */
+static void g_renamed_operand_default_init(GRenamedOperandInterface *);
+
+
+
+/* ----------------------- INTERFACE POUR OPERANDE RENOMMABLE ----------------------- */
+
+
+/* Procède à l'initialisation de l'interface de renommage. */
+static void g_renameable_operand_default_init(GRenameableOperandInterface *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTERFACE POUR OPERANDE RENOMMEE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Détermine le type d'une interface pour un opérande renommé. */
+G_DEFINE_INTERFACE(GRenamedOperand, g_renamed_operand, G_TYPE_OBJECT)
+
+
+/******************************************************************************
+* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de renommage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_renamed_operand_default_init(GRenamedOperandInterface *iface)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = operande à consulter. *
+* *
+* Description : Fournit un texte comme représentation alternative d'opérande.*
+* *
+* Retour : Chaîne de caractère de représentation alternative. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const char *g_renamed_operand_get_text(const GRenamedOperand *operand)
+{
+ const char *result; /* Texte à retourner */
+ GRenamedOperandIface *iface; /* Interface utilisée */
+
+ iface = G_RENAMED_OPERAND_GET_IFACE(operand);
+
+ result = iface->get_text(operand);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTERFACE POUR OPERANDE RENOMMABLE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Détermine le type d'une interface pour le renommage d'un opérande. */
+G_DEFINE_INTERFACE(GRenameableOperand, g_renameable_operand, G_TYPE_OBJECT)
+
+
+/******************************************************************************
+* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de renommage. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_renameable_operand_default_init(GRenameableOperandInterface *iface)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = operande à consulter. *
+* text = texte alternatif de représentation. *
+* *
+* Description : Construit un opérande de représentation alternative. *
+* *
+* Retour : Nouvel opérande, en version renommée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRenamedOperand *g_renameable_operand_build(const GRenameableOperand *operand, const char *text)
+{
+ GRenamedOperand *result; /* Instance à retourner */
+ GRenameableOperandIface *iface; /* Interface utilisée */
+
+ iface = G_RENAMEABLE_OPERAND_GET_IFACE(operand);
+
+ result = iface->build(operand, text);
+
+ return result;
+
+}
diff --git a/src/arch/operands/rename.h b/src/arch/operands/rename.h
new file mode 100644
index 0000000..a6b99d7
--- /dev/null
+++ b/src/arch/operands/rename.h
@@ -0,0 +1,84 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * rename.h - prototypes pour les opérandes pouvant être renommées
+ *
+ * Copyright (C) 2020 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_OPERANDS_RENAME_H
+#define _ARCH_OPERANDS_RENAME_H
+
+
+#include <glib-object.h>
+
+
+
+/* ------------------------ INTERFACE POUR OPERANDE RENOMMEE ------------------------ */
+
+
+#define G_TYPE_RENAMED_OPERAND (g_renamed_operand_get_type())
+#define G_RENAMED_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_RENAMED_OPERAND, GRenamedOperand))
+#define G_RENAMED_OPERAND_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_RENAMED_OPERAND, GRenamedOperandIface))
+#define G_IS_RENAMED_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_RENAMED_OPERAND))
+#define G_IS_RENAMED_OPERAND_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_RENAMED_OPERAND))
+#define G_RENAMED_OPERAND_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_RENAMED_OPERAND, GRenamedOperandIface))
+
+
+/* Opérande renommé avec un texte alternatif (coquille vide) */
+typedef struct _GRenamedOperand GRenamedOperand;
+
+/* Opérande renommé avec un texte alternatif (interface) */
+typedef struct _GRenamedOperandIface GRenamedOperandIface;
+
+
+/* Détermine le type d'une interface pour un opérande renommé. */
+GType g_renamed_operand_get_type(void) G_GNUC_CONST;
+
+/* Fournit un texte comme représentation alternative d'opérande. */
+const char *g_renamed_operand_get_text(const GRenamedOperand *);
+
+
+
+/* ----------------------- INTERFACE POUR OPERANDE RENOMMABLE ----------------------- */
+
+
+#define G_TYPE_RENAMEABLE_OPERAND (g_renameable_operand_get_type())
+#define G_RENAMEABLE_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_RENAMEABLE_OPERAND, GRenameableOperand))
+#define G_RENAMEABLE_OPERAND_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_RENAMEABLE_OPERAND, GRenameableOperandIface))
+#define G_IS_RENAMEABLE_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_RENAMEABLE_OPERAND))
+#define G_IS_RENAMEABLE_OPERAND_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_RENAMEABLE_OPERAND))
+#define G_RENAMEABLE_OPERAND_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_RENAMEABLE_OPERAND, GRenameableOperandIface))
+
+
+/* Opérande offrant une capacité de renommage (coquille vide) */
+typedef struct _GRenameableOperand GRenameableOperand;
+
+/* Opérande offrant une capacité de renommage (interface) */
+typedef struct _GRenameableOperandIface GRenameableOperandIface;
+
+
+/* Détermine le type d'une interface pour le renommage d'un opérande. */
+GType g_renameable_operand_get_type(void) G_GNUC_CONST;
+
+/* Construit un opérande de représentation alternative. */
+GRenamedOperand *g_renameable_operand_build(const GRenameableOperand *, const char *);
+
+
+
+#endif /* _ARCH_OPERANDS_RENAME_H */