From ad1caf61fccd0d74be6ac92c41d83e9b0008ff2b Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 7 Jun 2020 22:42:22 +0200 Subject: Reorganized the operands behaving like proxies. --- plugins/pychrysalide/arch/Makefile.am | 1 - plugins/pychrysalide/arch/feeder.c | 116 ------- plugins/pychrysalide/arch/feeder.h | 42 --- plugins/pychrysalide/arch/module.c | 2 - plugins/pychrysalide/arch/operands/Makefile.am | 2 + plugins/pychrysalide/arch/operands/feeder.c | 452 +++++++++++++++++++++++++ plugins/pychrysalide/arch/operands/feeder.h | 45 +++ plugins/pychrysalide/arch/operands/module.c | 4 + plugins/pychrysalide/arch/operands/proxy.c | 383 +++++++++++++++++++++ plugins/pychrysalide/arch/operands/proxy.h | 48 +++ plugins/pychrysalide/format/strsym.c | 2 +- plugins/pychrysalide/glibext/linegen.c | 7 +- src/arch/Makefile.am | 3 - src/arch/feeder-int.h | 66 ---- src/arch/feeder.c | 161 --------- src/arch/feeder.h | 70 ---- src/arch/operands/Makefile.am | 4 + src/arch/operands/feeder-int.h | 66 ++++ src/arch/operands/feeder.c | 161 +++++++++ src/arch/operands/feeder.h | 70 ++++ src/arch/operands/proxy-int.h | 51 +++ src/arch/operands/proxy.c | 326 ++++++++++++++++++ src/arch/operands/proxy.h | 65 ++++ src/arch/proxy.c | 318 ----------------- src/arch/proxy.h | 62 ---- src/format/strsym.c | 2 +- 26 files changed, 1683 insertions(+), 846 deletions(-) delete mode 100644 plugins/pychrysalide/arch/feeder.c delete mode 100644 plugins/pychrysalide/arch/feeder.h create mode 100644 plugins/pychrysalide/arch/operands/feeder.c create mode 100644 plugins/pychrysalide/arch/operands/feeder.h create mode 100644 plugins/pychrysalide/arch/operands/proxy.c create mode 100644 plugins/pychrysalide/arch/operands/proxy.h delete mode 100644 src/arch/feeder-int.h delete mode 100644 src/arch/feeder.c delete mode 100644 src/arch/feeder.h create mode 100644 src/arch/operands/feeder-int.h create mode 100644 src/arch/operands/feeder.c create mode 100644 src/arch/operands/feeder.h create mode 100644 src/arch/operands/proxy-int.h create mode 100644 src/arch/operands/proxy.c create mode 100644 src/arch/operands/proxy.h delete mode 100644 src/arch/proxy.c delete mode 100644 src/arch/proxy.h diff --git a/plugins/pychrysalide/arch/Makefile.am b/plugins/pychrysalide/arch/Makefile.am index 45fd567..cbac988 100644 --- a/plugins/pychrysalide/arch/Makefile.am +++ b/plugins/pychrysalide/arch/Makefile.am @@ -4,7 +4,6 @@ noinst_LTLIBRARIES = libpychrysaarch.la libpychrysaarch_la_SOURCES = \ constants.h constants.c \ context.h context.c \ - feeder.h feeder.c \ instriter.h instriter.c \ instruction.h instruction.c \ module.h module.c \ diff --git a/plugins/pychrysalide/arch/feeder.c b/plugins/pychrysalide/arch/feeder.c deleted file mode 100644 index fbabe80..0000000 --- a/plugins/pychrysalide/arch/feeder.c +++ /dev/null @@ -1,116 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * feeder.c - prototypes pour l'équivalent Python du fichier "arch/feeder.c" - * - * Copyright (C) 2018-2019 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 "feeder.h" - - -#include -#include - - -#include - - -#include "../access.h" -#include "../helpers.h" - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_proxy_feeder_type(void) -{ - static PyMethodDef py_proxy_feeder_methods[] = { - { NULL } - }; - - static PyGetSetDef py_proxy_feeder_getseters[] = { - { NULL } - }; - - static PyTypeObject py_proxy_feeder_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.ProxyFeeder", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide proxy feeder", - - .tp_methods = py_proxy_feeder_methods, - .tp_getset = py_proxy_feeder_getseters - - }; - - return &py_proxy_feeder_type; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.ProxyFeeder'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool ensure_python_proxy_feeder_is_registered(void) -{ - PyTypeObject *type; /* Type Python 'ProxyFeeder' */ - PyObject *module; /* Module à recompléter */ - PyObject *dict; /* Dictionnaire du module */ - - type = get_python_proxy_feeder_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_PROXY_FEEDER, type)) - return false; - - } - - return true; - -} diff --git a/plugins/pychrysalide/arch/feeder.h b/plugins/pychrysalide/arch/feeder.h deleted file mode 100644 index 2655bbc..0000000 --- a/plugins/pychrysalide/arch/feeder.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * feeder.h - prototypes pour l'équivalent Python du fichier "arch/feeder.h" - * - * Copyright (C) 2018 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_FEEDER_H -#define _PLUGINS_PYCHRYSALIDE_ARCH_FEEDER_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_proxy_feeder_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.ProxyFeeder'. */ -bool ensure_python_proxy_feeder_is_registered(void); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_FEEDER_H */ diff --git a/plugins/pychrysalide/arch/module.c b/plugins/pychrysalide/arch/module.c index 1fa017d..5cd6c17 100644 --- a/plugins/pychrysalide/arch/module.c +++ b/plugins/pychrysalide/arch/module.c @@ -33,7 +33,6 @@ #include "context.h" -#include "feeder.h" #include "instriter.h" #include "instruction.h" #include "operand.h" @@ -168,7 +167,6 @@ bool populate_arch_module(void) result = true; if (result) result = ensure_python_proc_context_is_registered(); - if (result) result = ensure_python_proxy_feeder_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(); diff --git a/plugins/pychrysalide/arch/operands/Makefile.am b/plugins/pychrysalide/arch/operands/Makefile.am index 7938320..2074b6b 100644 --- a/plugins/pychrysalide/arch/operands/Makefile.am +++ b/plugins/pychrysalide/arch/operands/Makefile.am @@ -3,8 +3,10 @@ noinst_LTLIBRARIES = libpychrysaarchoperands.la libpychrysaarchoperands_la_SOURCES = \ constants.h constants.c \ + feeder.h feeder.c \ immediate.h immediate.c \ module.h module.c \ + proxy.h proxy.c \ register.h register.c \ rename.h rename.c \ targetable.h targetable.c diff --git a/plugins/pychrysalide/arch/operands/feeder.c b/plugins/pychrysalide/arch/operands/feeder.c new file mode 100644 index 0000000..68fa052 --- /dev/null +++ b/plugins/pychrysalide/arch/operands/feeder.c @@ -0,0 +1,452 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * feeder.c - prototypes pour l'équivalent Python du fichier "arch/operands/feeder.c" + * + * Copyright (C) 2018-2019 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 "feeder.h" + + +#include +#include + + +#include + + +#include "../../access.h" +#include "../../helpers.h" +#include "../../glibext/bufferline.h" + + + +/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ + + +/* Procède à l'initialisation de l'interface de génération. */ +static void py_proxy_feeder_interface_init(GProxyFeederIface *, gpointer *); + +/* Compare un fournisseur avec un autre. */ +static int py_proxy_feeder___cmp___wrapper(const GProxyFeeder *, const GProxyFeeder *); + +/* Traduit un fournisseur en version humainement lisible. */ +static void py_proxy_feeder_print_wrapper(const GProxyFeeder *, GBufferLine *); + + + +/* ------------------------- CONNEXION AVEC L'API DE PYTHON ------------------------- */ + + +/* Effectue une comparaison avec un objet Python 'ProxyFeeder'. */ +static PyObject *py_proxy_feeder_richcompare(PyObject *, PyObject *, int); + +/* Traduit un fournisseur en version humainement lisible. */ +static PyObject *py_proxy_feeder_print(PyObject *, PyObject *); + + + +/* ---------------------------------------------------------------------------------- */ +/* GLUE POUR CREATION DEPUIS PYTHON */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : iface = interface GLib à initialiser. * +* unused = adresse non utilisée ici. * +* * +* Description : Procède à l'initialisation de l'interface de génération. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void py_proxy_feeder_interface_init(GProxyFeederIface *iface, gpointer *unused) +{ + +#define PROXY_FEEDER_DOC \ + "ProxyFeeder gives an interface for operands which aim to provide" \ + " a dynamic content.\n" \ + "\n" \ + "A typical class declaration for a new implementation looks like:\n" \ + "\n" \ + " class NewImplem(GObject.Object, ProxyFeeder):\n" \ + " ...\n" \ + "\n" \ + "The following methods have to be defined for new implementations:\n" \ + "* pychrysalide.arch.operands.ProxyFeeder._compare();\n" \ + "* pychrysalide.arch.operands.ProxyFeeder._print();\n" \ + + iface->compare = py_proxy_feeder___cmp___wrapper; + iface->print = py_proxy_feeder_print_wrapper; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un fournisseur avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_proxy_feeder___cmp___wrapper(const GProxyFeeder *a, const GProxyFeeder *b) +{ + 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 PROXY_FEEDER_CMP_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + __cmp__, "$self, other, /", \ + METH_VARARGS, \ + "Abstract method used to compare the proxy feeder with" \ + " another one. This second object is always an" \ + " pychrysalide.arch.operands.ProxyFeeder 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_DECREF(args); + + Py_XDECREF(pyret); + + } + + Py_DECREF(pyobj); + + PyGILState_Release(gstate); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : feeder = fournisseur à traiter. * +* line = ligne tampon où imprimer l'élément donné. * +* * +* Description : Traduit un fournisseur en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void py_proxy_feeder_print_wrapper(const GProxyFeeder *feeder, 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 PROXY_FEEDER_PRINT_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _print, "$self, line, /", \ + METH_VARARGS, \ + "Abstract method used to generate content into a rendering" \ + " line, which is a provided pychrysalide.glibext.BufferLine" \ + " instance." \ +) + + gstate = PyGILState_Ensure(); + + pyobj = pygobject_new(G_OBJECT(feeder)); + + 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); + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* CONNEXION AVEC L'API DE PYTHON */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* 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 'ProxyFeeder'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_proxy_feeder_richcompare(PyObject *a, PyObject *b, int op) +{ + PyObject *result; /* Bilan à retourner */ + int ret; /* Bilan de lecture des args. */ + const GProxyFeeder *feeder_a; /* Premier élément à traiter */ + const GProxyFeeder *feeder_b; /* Second élément à traiter */ + int status; /* Résultat d'une comparaison */ + + ret = PyObject_IsInstance(b, (PyObject *)get_python_proxy_feeder_type()); + if (!ret) + { + result = Py_NotImplemented; + goto cmp_done; + } + + feeder_a = G_PROXY_FEEDER(pygobject_get(a)); + feeder_b = G_PROXY_FEEDER(pygobject_get(b)); + + status = py_proxy_feeder___cmp___wrapper(feeder_a, feeder_b); + + result = status_to_rich_cmp_state(status, op); + + cmp_done: + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un générateur à manipuler. * +* args = arguments fournis à l'appel. * +* * +* Description : Traduit un fournisseur en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_proxy_feeder_print(PyObject *self, PyObject *args) +{ + GBufferLine *line; /* Ligne de rendu à compléter */ + GProxyFeeder *feeder; /* Version native */ + int ret; /* Bilan de lecture des args. */ + +#define PROXY_FEEDER_PRINT_METHOD PYTHON_METHOD_DEF \ +( \ + print, "$self, line, /", \ + METH_VARARGS, py_proxy_feeder, \ + "Produce output into a rendering line.\n" \ + "\n" \ + "The provided line is a pychrysalide.glibext.BufferLine instance." \ +) + + ret = PyArg_ParseTuple(args, "O&", convert_to_buffer_line, &line); + if (!ret) return NULL; + + feeder = G_PROXY_FEEDER(pygobject_get(self)); + + g_proxy_feeder_print(feeder, line); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_proxy_feeder_type(void) +{ + static PyMethodDef py_proxy_feeder_methods[] = { + PROXY_FEEDER_CMP_WRAPPER, + PROXY_FEEDER_PRINT_WRAPPER, + PROXY_FEEDER_PRINT_METHOD, + { NULL } + }; + + static PyGetSetDef py_proxy_feeder_getseters[] = { + { NULL } + }; + + static PyTypeObject py_proxy_feeder_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.operands.ProxyFeeder", + .tp_basicsize = sizeof(PyObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = PROXY_FEEDER_DOC, + + .tp_richcompare = py_proxy_feeder_richcompare, + + .tp_methods = py_proxy_feeder_methods, + .tp_getset = py_proxy_feeder_getseters + + }; + + return &py_proxy_feeder_type; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.ProxyFeeder'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool ensure_python_proxy_feeder_is_registered(void) +{ + PyTypeObject *type; /* Type Python 'ProxyFeeder' */ + PyObject *module; /* Module à recompléter */ + PyObject *dict; /* Dictionnaire du module */ + + static GInterfaceInfo info = { /* Paramètres d'inscription */ + + .interface_init = (GInterfaceInitFunc)py_proxy_feeder_interface_init, + .interface_finalize = NULL, + .interface_data = NULL, + + }; + + type = get_python_proxy_feeder_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_2(dict, G_TYPE_PROXY_FEEDER, 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 fournisseur intermédiaire. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_proxy_feeder(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_proxy_feeder_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 proxy feeder"); + break; + + case 1: + *((GProxyFeeder **)dst) = G_PROXY_FEEDER(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/arch/operands/feeder.h b/plugins/pychrysalide/arch/operands/feeder.h new file mode 100644 index 0000000..80a5e7d --- /dev/null +++ b/plugins/pychrysalide/arch/operands/feeder.h @@ -0,0 +1,45 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * feeder.h - prototypes pour l'équivalent Python du fichier "arch/operands/feeder.h" + * + * Copyright (C) 2018 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_FEEDER_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_FEEDER_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_proxy_feeder_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.ProxyFeeder'. */ +bool ensure_python_proxy_feeder_is_registered(void); + +/* Tente de convertir en fournisseur intermédiaire. */ +int convert_to_proxy_feeder(PyObject *, void *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_FEEDER_H */ diff --git a/plugins/pychrysalide/arch/operands/module.c b/plugins/pychrysalide/arch/operands/module.c index cbd0bde..15d7835 100644 --- a/plugins/pychrysalide/arch/operands/module.c +++ b/plugins/pychrysalide/arch/operands/module.c @@ -28,7 +28,9 @@ #include +#include "feeder.h" #include "immediate.h" +#include "proxy.h" #include "register.h" #include "rename.h" #include "targetable.h" @@ -97,8 +99,10 @@ 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_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(); diff --git a/plugins/pychrysalide/arch/operands/proxy.c b/plugins/pychrysalide/arch/operands/proxy.c new file mode 100644 index 0000000..401fe40 --- /dev/null +++ b/plugins/pychrysalide/arch/operands/proxy.c @@ -0,0 +1,383 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * proxy.c - équivalent Python du fichier "arch/operands/proxy.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 "proxy.h" + + +#include + + +#include +#include +#include + + +#include "feeder.h" +#include "../operand.h" +#include "../../access.h" +#include "../../helpers.h" + + + +/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ + + +/* Accompagne la création d'une instance dérivée en Python. */ +static PyObject *py_proxy_operand_new(PyTypeObject *, PyObject *, PyObject *); + +/* Initialise la classe des descriptions de fichier binaire. */ +static void py_proxy_operand_init_gclass(GProxyOperandClass *, gpointer); + +/* Initialise une instance sur la base du dérivé de GObject. */ +static int py_proxy_operand_init(PyObject *, PyObject *, PyObject *); + + + +/* ------------------ OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES ------------------ */ + + +/* Fournit le fournisseur représenté par l'opérande. */ +static PyObject *py_proxy_operand_get_feeder(PyObject *, void *); + + + +/* ---------------------------------------------------------------------------------- */ +/* GLUE POUR CREATION DEPUIS PYTHON */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* 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_proxy_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_proxy_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_PROXY_OPERAND, type->tp_name, + (GClassInitFunc)py_proxy_operand_init_gclass, NULL, NULL); + + if (first_time) + { + status = register_class_for_dynamic_pygobject(gtype, type, base); + + 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_proxy_operand_init_gclass(GProxyOperandClass *class, gpointer unused) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet à initialiser (théoriquement). * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Initialise une instance sur la base du dérivé de GObject. * +* * +* Retour : 0. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_proxy_operand_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + GProxyFeeder *feeder; /* Fournisseur transmis */ + int ret; /* Bilan de lecture des args. */ + PyObject *new_args; /* Nouveaux arguments épurés */ + PyObject *new_kwds; /* Nouveau dictionnaire épuré */ + GProxyOperand *operand; /* Opérande à manipuler */ + +#define PROXY_OPERAND_DOC \ + "The ProxyOperand object behaves like a proxy operand for an object" \ + " which can feed the operand with content.\n" \ + "\n" \ + "Instances can be created using the following constructor:\n" \ + "\n" \ + " ProxyOperand(feeder)" \ + "\n" \ + "Where feeder is an instance implementing the" \ + " pychrysalide.arch.operands.ProxyFeeder interface." + + /* Récupération des paramètres */ + + ret = PyArg_ParseTuple(args, "O&", convert_to_proxy_feeder, &feeder); + if (!ret) return -1; + + /* Initialisation d'un objet GLib */ + + new_args = PyTuple_New(0); + new_kwds = PyDict_New(); + + ret = PyGObject_Type.tp_init(self, new_args, new_kwds); + + Py_DECREF(new_kwds); + Py_DECREF(new_args); + + if (ret == -1) return -1; + + /* Eléments de base */ + + operand = G_PROXY_OPERAND(pygobject_get(self)); + + g_object_ref(G_OBJECT(feeder)); + operand->feeder = feeder; + + return 0; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le fournisseur représenté par l'opérande. * +* * +* Retour : Fournisseur associé à l'opérande. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_proxy_operand_get_feeder(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GProxyOperand *operand; /* Version GLib de l'opérande */ + GProxyFeeder *feeder; /* Fournisseur lié à l'opérande*/ + +#define PROXY_OPERAND_FEEDER_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + feeder, py_proxy_operand, \ + "Give the proxy feeder linked to the operand.\n" \ + "\n" \ + "This feeder is a pychrysalide.arch.operands.ProxyFeeder" \ + " providing content for the operand." \ +) + + operand = G_PROXY_OPERAND(pygobject_get(self)); + + feeder = g_proxy_operand_get_feeder(operand); + + result = pygobject_new(G_OBJECT(feeder)); + g_object_unref(feeder); + + 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_proxy_operand_type(void) +{ + static PyMethodDef py_proxy_operand_methods[] = { + { NULL } + }; + + static PyGetSetDef py_proxy_operand_getseters[] = { + PROXY_OPERAND_FEEDER_ATTRIB, + { NULL } + }; + + static PyTypeObject py_proxy_operand_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.operands.ProxyOperand", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = PROXY_OPERAND_DOC, + + .tp_methods = py_proxy_operand_methods, + .tp_getset = py_proxy_operand_getseters, + + .tp_init = py_proxy_operand_init, + .tp_new = py_proxy_operand_new, + + }; + + return &py_proxy_operand_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.ArchOperand'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool ensure_python_proxy_operand_is_registered(void) +{ + PyTypeObject *type; /* Type Python 'ArchOperand' */ + PyObject *module; /* Module à recompléter */ + PyObject *dict; /* Dictionnaire du module */ + + type = get_python_proxy_operand_type(); + + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.arch.operands"); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_PROXY_OPERAND, type, get_python_arch_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 opérande renvoyant vers un élément. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_proxy_operand(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_proxy_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 proxy operand"); + break; + + case 1: + *((GProxyOperand **)dst) = G_PROXY_OPERAND(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/arch/operands/proxy.h b/plugins/pychrysalide/arch/operands/proxy.h new file mode 100644 index 0000000..4fdb6f0 --- /dev/null +++ b/plugins/pychrysalide/arch/operands/proxy.h @@ -0,0 +1,48 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * proxy.h - prototypes pour l'équivalent Python du fichier "arch/operands/proxy.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_PROXY_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_PROXY_H + + +#include +#include + + + +/* ------------------ OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES ------------------ */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_proxy_operand_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.operands.ProxyOperand'. */ +bool ensure_python_proxy_operand_is_registered(void); + +/* Tente de convertir en opérande renvoyant vers un élément. */ +int convert_to_proxy_operand(PyObject *, void *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_OPERANDS_PROXY_H */ diff --git a/plugins/pychrysalide/format/strsym.c b/plugins/pychrysalide/format/strsym.c index 9c86df4..c85d61f 100644 --- a/plugins/pychrysalide/format/strsym.c +++ b/plugins/pychrysalide/format/strsym.c @@ -41,8 +41,8 @@ #include "symbol.h" #include "../access.h" #include "../helpers.h" -#include "../arch/feeder.h" #include "../arch/vmpa.h" +#include "../arch/operands/feeder.h" diff --git a/plugins/pychrysalide/glibext/linegen.c b/plugins/pychrysalide/glibext/linegen.c index 3214cc9..6d29dbc 100644 --- a/plugins/pychrysalide/glibext/linegen.c +++ b/plugins/pychrysalide/glibext/linegen.c @@ -686,9 +686,10 @@ static PyObject *py_line_generator_print(PyObject *self, PyObject *args) METH_VARARGS, py_line_generator, \ "Produce output into a rendering line with optional content.\n" \ "\n" \ - "The line index and the number of repetitions (only relevant" \ - " if the generator produces several lines) give indications" \ - " about the current rendering position.\n" \ + "The provided line is a pychrysalide.glibext.BufferLine" \ + " instance. The index and the number of repetitions (only" \ + " relevant if the generator produces several lines) give" \ + " indications about the current rendering position.\n" \ "\n" \ "If set, the content is a pychrysalide.analysis.BinContent" \ " instance providing access to the processed binary data." \ diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am index af0c79a..a8f9fb0 100644 --- a/src/arch/Makefile.am +++ b/src/arch/Makefile.am @@ -5,8 +5,6 @@ libarch_la_SOURCES = \ archbase.h archbase.c \ context-int.h \ context.h context.c \ - feeder-int.h \ - feeder.h feeder.c \ instriter.h instriter.c \ instruction-int.h \ instruction.h instruction.c \ @@ -17,7 +15,6 @@ libarch_la_SOURCES = \ post.h post.c \ processor-int.h \ processor.h processor.c \ - proxy.h proxy.c \ register-int.h \ register.h register.c \ storage.h storage.c \ diff --git a/src/arch/feeder-int.h b/src/arch/feeder-int.h deleted file mode 100644 index 9312304..0000000 --- a/src/arch/feeder-int.h +++ /dev/null @@ -1,66 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * feeder-int.h - définitions internes propres aux fournisseurs d'éléments non architecturaux - * - * Copyright (C) 2018 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 . - */ - - -#ifndef _ARCH_FEEDER_INT_H -#define _ARCH_FEEDER_INT_H - - -#include "feeder.h" - - - -/* Compare un fournisseur avec un autre. */ -typedef int (* compare_proxy_operand_fc) (const GProxyFeeder *, const GProxyFeeder *); - -/* Traduit un fournisseur en version humainement lisible. */ -typedef void (* print_proxy_feeder_fc) (const GProxyFeeder *, GBufferLine *); - -/* Charge un fournisseur depuis une mémoire tampon. */ -typedef bool (* unserialize_proxy_feeder_fc) (GProxyFeeder *, GBinFormat *, packed_buffer *); - -/* Sauvegarde un fournisseur dans une mémoire tampon. */ -typedef bool (* serialize_proxy_feeder_fc) (const GProxyFeeder *, packed_buffer *); - - - -/* Fournisseur d'élément non architectural (interface) */ -struct _GProxyFeederIface -{ - GTypeInterface base_iface; /* A laisser en premier */ - - compare_proxy_operand_fc compare; /* Comparaison entre éléments */ - - print_proxy_feeder_fc print; /* Affichage sur une ligne */ - - unserialize_proxy_feeder_fc unserialize;/* Restauration de l'élément */ - serialize_proxy_feeder_fc serialize; /* Sauvegarder de l'élément */ - -}; - - -/* Redéfinition */ -typedef GProxyFeederIface GProxyFeederInterface; - - - -#endif /* _ARCH_FEEDER_INT_H */ diff --git a/src/arch/feeder.c b/src/arch/feeder.c deleted file mode 100644 index 6d24efc..0000000 --- a/src/arch/feeder.c +++ /dev/null @@ -1,161 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * feeder.c - fourniture d'éléments non architecturaux - * - * Copyright (C) 2018 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 . - */ - - -#include "feeder.h" - - -#include "feeder-int.h" - - - -/* Procède à l'initialisation de l'interface de rassemblement. */ -static void g_proxy_feeder_default_init(GProxyFeederInterface *); - - - -/* Détermine le type d'une interface pour la Fourniture d'éléments non architecturaux. */ -G_DEFINE_INTERFACE(GProxyFeeder, g_proxy_feeder, G_TYPE_OBJECT) - - -/****************************************************************************** -* * -* Paramètres : iface = interface GLib à initialiser. * -* * -* Description : Procède à l'initialisation de l'interface de rassemblement. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_proxy_feeder_default_init(GProxyFeederInterface *iface) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : a = premier fournisseur à consulter. * -* b = second fournisseur à consulter. * -* * -* Description : Compare un fournisseur avec un autre. * -* * -* Retour : Bilan de la comparaison. * -* * -* Remarques : - * -* * -******************************************************************************/ - -int g_proxy_feeder_compare(const GProxyFeeder *a, const GProxyFeeder *b) -{ - int result; /* Bilan à retourner */ - GProxyFeederIface *iface; /* Interface utilisée */ - - iface = G_PROXY_FEEDER_GET_IFACE(a); - - result = iface->compare(a, b); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : feeder = fournisseur à traiter. * -* line = ligne tampon où imprimer l'élément donné. * -* * -* Description : Traduit un fournisseur en version humainement lisible. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_proxy_feeder_print(const GProxyFeeder *feeder, GBufferLine *line) -{ - GProxyFeederIface *iface; /* Interface utilisée */ - - iface = G_PROXY_FEEDER_GET_IFACE(feeder); - - iface->print(feeder, line); - -} - - -/****************************************************************************** -* * -* Paramètres : feeder = fournisseur à constituer. * -* format = format binaire chargé associé à l'architecture. * -* pbuf = zone tampon à remplir. * -* * -* Description : Charge un fournisseur depuis une mémoire tampon. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_proxy_feeder_unserialize(GProxyFeeder *feeder, GBinFormat *format, packed_buffer *pbuf) -{ - bool result; /* Bilan à retourner */ - GProxyFeederIface *iface; /* Interface utilisée */ - - iface = G_PROXY_FEEDER_GET_IFACE(feeder); - - result = iface->unserialize(feeder, format, pbuf); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : feeder = fournisseur à consulter. * -* pbuf = zone tampon à remplir. * -* * -* Description : Sauvegarde un fournisseur dans une mémoire tampon. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_proxy_feeder_serialize(const GProxyFeeder *feeder, packed_buffer *pbuf) -{ - bool result; /* Bilan à retourner */ - GProxyFeederIface *iface; /* Interface utilisée */ - - iface = G_PROXY_FEEDER_GET_IFACE(feeder); - - result = iface->serialize(feeder, pbuf); - - return result; - -} diff --git a/src/arch/feeder.h b/src/arch/feeder.h deleted file mode 100644 index b01ebf0..0000000 --- a/src/arch/feeder.h +++ /dev/null @@ -1,70 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * feeder.h - prototypes pour la fourniture d'éléments non architecturaux - * - * Copyright (C) 2018 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 . - */ - - -#ifndef _ARCH_FEEDER_H -#define _ARCH_FEEDER_H - - -#include -#include - - -#include "../common/packed.h" -#include "../format/format.h" -#include "../glibext/gbufferline.h" - - - -#define G_TYPE_PROXY_FEEDER (g_proxy_feeder_get_type()) -#define G_PROXY_FEEDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PROXY_FEEDER, GProxyFeeder)) -#define G_PROXY_FEEDER_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_PROXY_FEEDER, GProxyFeederIface)) -#define G_IS_PROXY_FEEDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PROXY_FEEDER)) -#define G_IS_PROXY_FEEDER_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_PROXY_FEEDER)) -#define G_PROXY_FEEDER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_PROXY_FEEDER, GProxyFeederIface)) - - -/* Fournisseur d'élément non architectural (coquille vide) */ -typedef struct _GProxyFeeder GProxyFeeder; - -/* Fournisseur d'élément non architectural (interface) */ -typedef struct _GProxyFeederIface GProxyFeederIface; - - -/* Détermine le type d'une interface pour la Fourniture d'éléments non architecturaux. */ -GType g_proxy_feeder_get_type(void) G_GNUC_CONST; - -/* Compare un fournisseur avec un autre. */ -int g_proxy_feeder_compare(const GProxyFeeder *, const GProxyFeeder *); - -/* Traduit un fournisseur en version humainement lisible. */ -void g_proxy_feeder_print(const GProxyFeeder *, GBufferLine *); - -/* Charge un fournisseur depuis une mémoire tampon. */ -bool g_proxy_feeder_unserialize(GProxyFeeder *, GBinFormat *, packed_buffer *); - -/* Sauvegarde un fournisseur dans une mémoire tampon. */ -bool g_proxy_feeder_serialize(const GProxyFeeder *, packed_buffer *); - - - -#endif /* _ARCH_FEEDER_H */ diff --git a/src/arch/operands/Makefile.am b/src/arch/operands/Makefile.am index 4e52f58..74f057d 100644 --- a/src/arch/operands/Makefile.am +++ b/src/arch/operands/Makefile.am @@ -2,9 +2,13 @@ noinst_LTLIBRARIES = libarchoperands.la libarchoperands_la_SOURCES = \ + feeder-int.h \ + feeder.h feeder.c \ immediate.h immediate.c \ register-int.h \ register.h register.c \ + proxy-int.h \ + proxy.h proxy.c \ rename-int.h \ rename.h rename.c \ targetable-int.h \ diff --git a/src/arch/operands/feeder-int.h b/src/arch/operands/feeder-int.h new file mode 100644 index 0000000..9a58dd5 --- /dev/null +++ b/src/arch/operands/feeder-int.h @@ -0,0 +1,66 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * feeder-int.h - définitions internes propres aux fournisseurs d'éléments non architecturaux + * + * Copyright (C) 2018 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 . + */ + + +#ifndef _ARCH_OPERANDS_FEEDER_INT_H +#define _ARCH_OPERANDS_FEEDER_INT_H + + +#include "feeder.h" + + + +/* Compare un fournisseur avec un autre. */ +typedef int (* compare_proxy_operand_fc) (const GProxyFeeder *, const GProxyFeeder *); + +/* Traduit un fournisseur en version humainement lisible. */ +typedef void (* print_proxy_feeder_fc) (const GProxyFeeder *, GBufferLine *); + +/* Charge un fournisseur depuis une mémoire tampon. */ +typedef bool (* unserialize_proxy_feeder_fc) (GProxyFeeder *, GBinFormat *, packed_buffer *); + +/* Sauvegarde un fournisseur dans une mémoire tampon. */ +typedef bool (* serialize_proxy_feeder_fc) (const GProxyFeeder *, packed_buffer *); + + + +/* Fournisseur d'élément non architectural (interface) */ +struct _GProxyFeederIface +{ + GTypeInterface base_iface; /* A laisser en premier */ + + compare_proxy_operand_fc compare; /* Comparaison entre éléments */ + + print_proxy_feeder_fc print; /* Affichage sur une ligne */ + + unserialize_proxy_feeder_fc unserialize;/* Restauration de l'élément */ + serialize_proxy_feeder_fc serialize; /* Sauvegarder de l'élément */ + +}; + + +/* Redéfinition */ +typedef GProxyFeederIface GProxyFeederInterface; + + + +#endif /* _ARCH_OPERANDS_FEEDER_INT_H */ diff --git a/src/arch/operands/feeder.c b/src/arch/operands/feeder.c new file mode 100644 index 0000000..6d24efc --- /dev/null +++ b/src/arch/operands/feeder.c @@ -0,0 +1,161 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * feeder.c - fourniture d'éléments non architecturaux + * + * Copyright (C) 2018 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 . + */ + + +#include "feeder.h" + + +#include "feeder-int.h" + + + +/* Procède à l'initialisation de l'interface de rassemblement. */ +static void g_proxy_feeder_default_init(GProxyFeederInterface *); + + + +/* Détermine le type d'une interface pour la Fourniture d'éléments non architecturaux. */ +G_DEFINE_INTERFACE(GProxyFeeder, g_proxy_feeder, G_TYPE_OBJECT) + + +/****************************************************************************** +* * +* Paramètres : iface = interface GLib à initialiser. * +* * +* Description : Procède à l'initialisation de l'interface de rassemblement. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_proxy_feeder_default_init(GProxyFeederInterface *iface) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier fournisseur à consulter. * +* b = second fournisseur à consulter. * +* * +* Description : Compare un fournisseur avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int g_proxy_feeder_compare(const GProxyFeeder *a, const GProxyFeeder *b) +{ + int result; /* Bilan à retourner */ + GProxyFeederIface *iface; /* Interface utilisée */ + + iface = G_PROXY_FEEDER_GET_IFACE(a); + + result = iface->compare(a, b); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : feeder = fournisseur à traiter. * +* line = ligne tampon où imprimer l'élément donné. * +* * +* Description : Traduit un fournisseur en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_proxy_feeder_print(const GProxyFeeder *feeder, GBufferLine *line) +{ + GProxyFeederIface *iface; /* Interface utilisée */ + + iface = G_PROXY_FEEDER_GET_IFACE(feeder); + + iface->print(feeder, line); + +} + + +/****************************************************************************** +* * +* Paramètres : feeder = fournisseur à constituer. * +* format = format binaire chargé associé à l'architecture. * +* pbuf = zone tampon à remplir. * +* * +* Description : Charge un fournisseur depuis une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_proxy_feeder_unserialize(GProxyFeeder *feeder, GBinFormat *format, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GProxyFeederIface *iface; /* Interface utilisée */ + + iface = G_PROXY_FEEDER_GET_IFACE(feeder); + + result = iface->unserialize(feeder, format, pbuf); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : feeder = fournisseur à consulter. * +* pbuf = zone tampon à remplir. * +* * +* Description : Sauvegarde un fournisseur dans une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_proxy_feeder_serialize(const GProxyFeeder *feeder, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GProxyFeederIface *iface; /* Interface utilisée */ + + iface = G_PROXY_FEEDER_GET_IFACE(feeder); + + result = iface->serialize(feeder, pbuf); + + return result; + +} diff --git a/src/arch/operands/feeder.h b/src/arch/operands/feeder.h new file mode 100644 index 0000000..7cea504 --- /dev/null +++ b/src/arch/operands/feeder.h @@ -0,0 +1,70 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * feeder.h - prototypes pour la fourniture d'éléments non architecturaux + * + * Copyright (C) 2018 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 . + */ + + +#ifndef _ARCH_OPERANDS_FEEDER_H +#define _ARCH_OPERANDS_FEEDER_H + + +#include +#include + + +#include "../../common/packed.h" +#include "../../format/format.h" +#include "../../glibext/gbufferline.h" + + + +#define G_TYPE_PROXY_FEEDER (g_proxy_feeder_get_type()) +#define G_PROXY_FEEDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PROXY_FEEDER, GProxyFeeder)) +#define G_PROXY_FEEDER_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_PROXY_FEEDER, GProxyFeederIface)) +#define G_IS_PROXY_FEEDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PROXY_FEEDER)) +#define G_IS_PROXY_FEEDER_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_PROXY_FEEDER)) +#define G_PROXY_FEEDER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_PROXY_FEEDER, GProxyFeederIface)) + + +/* Fournisseur d'élément non architectural (coquille vide) */ +typedef struct _GProxyFeeder GProxyFeeder; + +/* Fournisseur d'élément non architectural (interface) */ +typedef struct _GProxyFeederIface GProxyFeederIface; + + +/* Détermine le type d'une interface pour la Fourniture d'éléments non architecturaux. */ +GType g_proxy_feeder_get_type(void) G_GNUC_CONST; + +/* Compare un fournisseur avec un autre. */ +int g_proxy_feeder_compare(const GProxyFeeder *, const GProxyFeeder *); + +/* Traduit un fournisseur en version humainement lisible. */ +void g_proxy_feeder_print(const GProxyFeeder *, GBufferLine *); + +/* Charge un fournisseur depuis une mémoire tampon. */ +bool g_proxy_feeder_unserialize(GProxyFeeder *, GBinFormat *, packed_buffer *); + +/* Sauvegarde un fournisseur dans une mémoire tampon. */ +bool g_proxy_feeder_serialize(const GProxyFeeder *, packed_buffer *); + + + +#endif /* _ARCH_OPERANDS_FEEDER_H */ diff --git a/src/arch/operands/proxy-int.h b/src/arch/operands/proxy-int.h new file mode 100644 index 0000000..c184986 --- /dev/null +++ b/src/arch/operands/proxy-int.h @@ -0,0 +1,51 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * proxy-int.h - définitions internes pour les opérandes renvoyant vers des éléments non architecturaux + * + * 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 . + */ + + +#ifndef _ARCH_OPERANDS_PROXY_INT_H +#define _ARCH_OPERANDS_PROXY_INT_H + + +#include "proxy.h" +#include "../operand-int.h" + + + +/* Définition d'un opérande renvoyant vers un élément (instance) */ +struct _GProxyOperand +{ + GArchOperand parent; /* Instance parente */ + + GProxyFeeder *feeder; /* Fournisseur de contenu */ + +}; + +/* Définition d'un opérande renvoyant vers un élément (classe) */ +struct _GProxyOperandClass +{ + GArchOperandClass parent; /* Classe parente */ + +}; + + + +#endif /* _ARCH_OPERANDS_PROXY_INT_H */ diff --git a/src/arch/operands/proxy.c b/src/arch/operands/proxy.c new file mode 100644 index 0000000..469e656 --- /dev/null +++ b/src/arch/operands/proxy.c @@ -0,0 +1,326 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * proxy.c - opérandes renvoyant vers des éléments non architecturaux + * + * Copyright (C) 2018 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 . + */ + + +#include "proxy.h" + + +#include "proxy-int.h" + + + +/* ------------------ OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES ------------------ */ + + +/* Initialise la classe des opérandes renvoyant vers un élément. */ +static void g_proxy_operand_class_init(GProxyOperandClass *); + +/* Initialise une instance d'opérande renvoyant vers un élément. */ +static void g_proxy_operand_init(GProxyOperand *); + +/* Supprime toutes les références externes. */ +static void g_proxy_operand_dispose(GProxyOperand *); + +/* Procède à la libération totale de la mémoire. */ +static void g_proxy_operand_finalize(GProxyOperand *); + +/* Compare un opérande avec un autre. */ +static int g_proxy_operand_compare(const GProxyOperand *, const GProxyOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static void g_proxy_operand_print(const GProxyOperand *, GBufferLine *); + + + +/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ + + +/* Charge un opérande depuis une mémoire tampon. */ +static bool g_proxy_operand_unserialize(GProxyOperand *, GAsmStorage *, GBinFormat *, packed_buffer *); + +/* Sauvegarde un opérande dans une mémoire tampon. */ +static bool g_proxy_operand_serialize(const GProxyOperand *, GAsmStorage *, packed_buffer *); + + + +/* ---------------------------------------------------------------------------------- */ +/* OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour un opérande de valeur numérique. */ +G_DEFINE_TYPE(GProxyOperand, g_proxy_operand, G_TYPE_ARCH_OPERAND); + + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des opérandes renvoyant vers un élément.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_proxy_operand_class_init(GProxyOperandClass *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_proxy_operand_dispose; + object->finalize = (GObjectFinalizeFunc)g_proxy_operand_finalize; + + operand->compare = (operand_compare_fc)g_proxy_operand_compare; + operand->print = (operand_print_fc)g_proxy_operand_print; + + operand->unserialize = (unserialize_operand_fc)g_proxy_operand_unserialize; + operand->serialize = (serialize_operand_fc)g_proxy_operand_serialize; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = instance à initialiser. * +* * +* Description : Initialise une instance d'opérande renvoyant vers un élément.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_proxy_operand_init(GProxyOperand *operand) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : operand = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_proxy_operand_dispose(GProxyOperand *operand) +{ + if (operand->feeder != NULL) + g_object_unref(G_OBJECT(operand->feeder)); + + G_OBJECT_CLASS(g_proxy_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_proxy_operand_finalize(GProxyOperand *operand) +{ + G_OBJECT_CLASS(g_proxy_operand_parent_class)->finalize(G_OBJECT(operand)); + +} + + +/****************************************************************************** +* * +* Paramètres : feeder = fournisseur sur lequel s'appuyer. * +* * +* Description : Crée un opérande renvoyant vers un élément non architectural.* +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_proxy_operand_new(GProxyFeeder *feeder) +{ + GProxyOperand *result; /* Opérande à retourner */ + + result = g_object_new(G_TYPE_PROXY_OPERAND, NULL); + + result->feeder = feeder; + + 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_proxy_operand_compare(const GProxyOperand *a, const GProxyOperand *b) +{ + int result; /* Bilan à retourner */ + + result = g_proxy_feeder_compare(a->feeder, b->feeder); + + 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_proxy_operand_print(const GProxyOperand *operand, GBufferLine *line) +{ + g_proxy_feeder_print(operand->feeder, line); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à consulter. * +* * +* Description : Fournit le fournisseur représenté par l'opérande. * +* * +* Retour : Fournisseur associé à l'opérande. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GProxyFeeder *g_proxy_operand_get_feeder(const GProxyOperand *operand) +{ + GProxyFeeder *result; /* Instance à retourner */ + + result = operand->feeder; + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* TRANSPOSITIONS VIA CACHE DES OPERANDES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* 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_proxy_operand_unserialize(GProxyOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchOperandClass *parent; /* Classe parente à consulter */ + + parent = G_ARCH_OPERAND_CLASS(g_proxy_operand_parent_class); + + result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf); + + if (result) + result = g_proxy_feeder_unserialize(operand->feeder, format, pbuf); + + 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_proxy_operand_serialize(const GProxyOperand *operand, GAsmStorage *storage, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchOperandClass *parent; /* Classe parente à consulter */ + + parent = G_ARCH_OPERAND_CLASS(g_proxy_operand_parent_class); + + result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf); + + if (result) + result = g_proxy_feeder_serialize(operand->feeder, pbuf); + + return result; + +} diff --git a/src/arch/operands/proxy.h b/src/arch/operands/proxy.h new file mode 100644 index 0000000..16b07a8 --- /dev/null +++ b/src/arch/operands/proxy.h @@ -0,0 +1,65 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * proxy.h - prototypes pour les opérandes renvoyant vers des éléments non architecturaux + * + * Copyright (C) 2018 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 . + */ + + +#ifndef _ARCH_OPERANDS_PROXY_H +#define _ARCH_OPERANDS_PROXY_H + + +#include + + +#include "feeder.h" +#include "../operand.h" + + + +/* ------------------ OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES ------------------ */ + + +#define G_TYPE_PROXY_OPERAND g_proxy_operand_get_type() +#define G_PROXY_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PROXY_OPERAND, GProxyOperand)) +#define G_IS_PROXY_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PROXY_OPERAND)) +#define G_PROXY_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PROXY_OPERAND, GProxyOperandClass)) +#define G_IS_PROXY_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PROXY_OPERAND)) +#define G_PROXY_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PROXY_OPERAND, GProxyOperandClass)) + + +/* Définition d'un opérande renvoyant vers un élément (instance) */ +typedef struct _GProxyOperand GProxyOperand; + +/* Définition d'un opérande renvoyant vers un élément (classe) */ +typedef struct _GProxyOperandClass GProxyOperandClass; + + +/* Indique le type défini pour un opérande d'architecture. */ +GType g_proxy_operand_get_type(void); + +/* Crée un opérande renvoyant vers un élément non architectural. */ +GArchOperand *g_proxy_operand_new(GProxyFeeder *); + +/* Fournit le fournisseur représenté par l'opérande. */ +GProxyFeeder *g_proxy_operand_get_feeder(const GProxyOperand *); + + + +#endif /* _ARCH_OPERANDS_PROXY_H */ diff --git a/src/arch/proxy.c b/src/arch/proxy.c deleted file mode 100644 index 4548ef6..0000000 --- a/src/arch/proxy.c +++ /dev/null @@ -1,318 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * proxy.c - opérandes renvoyant vers des éléments non architecturaux - * - * Copyright (C) 2018 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 . - */ - - -#include "proxy.h" - - -#include "operand-int.h" - - - -/* ------------------ OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES ------------------ */ - - -/* Définition d'un opérande renvoyant vers un élément (instance) */ -struct _GProxyOperand -{ - GArchOperand parent; /* Instance parente */ - - GProxyFeeder *feeder; /* Fournisseur de contenu */ - -}; - -/* Définition d'un opérande renvoyant vers un élément (classe) */ -struct _GProxyOperandClass -{ - GArchOperandClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des opérandes renvoyant vers un élément. */ -static void g_proxy_operand_class_init(GProxyOperandClass *); - -/* Initialise une instance d'opérande renvoyant vers un élément. */ -static void g_proxy_operand_init(GProxyOperand *); - -/* Supprime toutes les références externes. */ -static void g_proxy_operand_dispose(GProxyOperand *); - -/* Procède à la libération totale de la mémoire. */ -static void g_proxy_operand_finalize(GProxyOperand *); - -/* Compare un opérande avec un autre. */ -static int g_proxy_operand_compare(const GProxyOperand *, const GProxyOperand *); - -/* Traduit un opérande en version humainement lisible. */ -static void g_proxy_operand_print(const GProxyOperand *, GBufferLine *); - - - -/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ - - -/* Charge un opérande depuis une mémoire tampon. */ -static bool g_proxy_operand_unserialize(GProxyOperand *, GAsmStorage *, GBinFormat *, packed_buffer *); - -/* Sauvegarde un opérande dans une mémoire tampon. */ -static bool g_proxy_operand_serialize(const GProxyOperand *, GAsmStorage *, packed_buffer *); - - - -/* ---------------------------------------------------------------------------------- */ -/* OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini pour un opérande de valeur numérique. */ -G_DEFINE_TYPE(GProxyOperand, g_proxy_operand, G_TYPE_ARCH_OPERAND); - - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des opérandes renvoyant vers un élément.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_proxy_operand_class_init(GProxyOperandClass *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_proxy_operand_dispose; - object->finalize = (GObjectFinalizeFunc)g_proxy_operand_finalize; - - operand->compare = (operand_compare_fc)g_proxy_operand_compare; - operand->print = (operand_print_fc)g_proxy_operand_print; - - operand->unserialize = (unserialize_operand_fc)g_proxy_operand_unserialize; - operand->serialize = (serialize_operand_fc)g_proxy_operand_serialize; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance à initialiser. * -* * -* Description : Initialise une instance d'opérande renvoyant vers un élément.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_proxy_operand_init(GProxyOperand *operand) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance d'objet GLib à traiter. * -* * -* Description : Supprime toutes les références externes. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_proxy_operand_dispose(GProxyOperand *operand) -{ - if (operand->feeder != NULL) - g_object_unref(G_OBJECT(operand->feeder)); - - G_OBJECT_CLASS(g_proxy_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_proxy_operand_finalize(GProxyOperand *operand) -{ - G_OBJECT_CLASS(g_proxy_operand_parent_class)->finalize(G_OBJECT(operand)); - -} - - -/****************************************************************************** -* * -* Paramètres : feeder = fournisseur sur lequel s'appuyer. * -* * -* Description : Crée un opérande renvoyant vers un élément non architectural.* -* * -* Retour : Opérande mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchOperand *g_proxy_operand_new(GProxyFeeder *feeder) -{ - GProxyOperand *result; /* Opérande à retourner */ - - result = g_object_new(G_TYPE_PROXY_OPERAND, NULL); - - result->feeder = feeder; - - 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_proxy_operand_compare(const GProxyOperand *a, const GProxyOperand *b) -{ - int result; /* Bilan à retourner */ - - result = g_proxy_feeder_compare(a->feeder, b->feeder); - - 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_proxy_operand_print(const GProxyOperand *operand, GBufferLine *line) -{ - g_proxy_feeder_print(operand->feeder, line); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* TRANSPOSITIONS VIA CACHE DES OPERANDES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* 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_proxy_operand_unserialize(GProxyOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf) -{ - bool result; /* Bilan à retourner */ - GArchOperandClass *parent; /* Classe parente à consulter */ - - parent = G_ARCH_OPERAND_CLASS(g_proxy_operand_parent_class); - - result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf); - - if (result) - result = g_proxy_feeder_unserialize(operand->feeder, format, pbuf); - - 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_proxy_operand_serialize(const GProxyOperand *operand, GAsmStorage *storage, packed_buffer *pbuf) -{ - bool result; /* Bilan à retourner */ - GArchOperandClass *parent; /* Classe parente à consulter */ - - parent = G_ARCH_OPERAND_CLASS(g_proxy_operand_parent_class); - - result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf); - - if (result) - result = g_proxy_feeder_serialize(operand->feeder, pbuf); - - return result; - -} diff --git a/src/arch/proxy.h b/src/arch/proxy.h deleted file mode 100644 index 3e4cde6..0000000 --- a/src/arch/proxy.h +++ /dev/null @@ -1,62 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * proxy.h - prototypes pour les opérandes renvoyant vers des éléments non architecturaux - * - * Copyright (C) 2018 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 . - */ - - -#ifndef _ARCH_PROXY_H -#define _ARCH_PROXY_H - - -#include - - -#include "feeder.h" -#include "operand.h" - - - -/* ------------------ OPERANDES CONSTITUANT DE PURS INTERMEDIAIRES ------------------ */ - - -#define G_TYPE_PROXY_OPERAND g_proxy_operand_get_type() -#define G_PROXY_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PROXY_OPERAND, GDynOperand)) -#define G_IS_PROXY_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PROXY_OPERAND)) -#define G_PROXY_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PROXY_OPERAND, GDynOperandClass)) -#define G_IS_PROXY_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PROXY_OPERAND)) -#define G_PROXY_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PROXY_OPERAND, GDynOperandClass)) - - -/* Définition d'un opérande renvoyant vers un élément (instance) */ -typedef struct _GProxyOperand GProxyOperand; - -/* Définition d'un opérande renvoyant vers un élément (classe) */ -typedef struct _GProxyOperandClass GProxyOperandClass; - - -/* Indique le type défini pour un opérande d'architecture. */ -GType g_proxy_operand_get_type(void); - -/* Crée un opérande renvoyant vers un élément non architectural. */ -GArchOperand *g_proxy_operand_new(GProxyFeeder *); - - - -#endif /* _ARCH_PROXY_H */ diff --git a/src/format/strsym.c b/src/format/strsym.c index 97c62d9..5774a0c 100644 --- a/src/format/strsym.c +++ b/src/format/strsym.c @@ -31,7 +31,7 @@ #include "symbol-int.h" -#include "../arch/feeder-int.h" +#include "../arch/operands/feeder-int.h" #include "../common/alloc.h" -- cgit v0.11.2-87-g4458