diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2024-11-15 10:01:42 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2024-11-15 10:01:42 (GMT) |
commit | 671f61ec87f5e8d762ea890aabbc62c777e1c4f9 (patch) | |
tree | 1517f5fc5d00c8fd04872b35571556b021866f14 | |
parent | 3e21278480a25552401644cd0dc168e3588508dd (diff) |
Restore a skeleton of support for file formats.
27 files changed, 1331 insertions, 893 deletions
diff --git a/plugins/pychrysalide/Makefile.am b/plugins/pychrysalide/Makefile.am index 8408c96..183a4ef 100644 --- a/plugins/pychrysalide/Makefile.am +++ b/plugins/pychrysalide/Makefile.am @@ -48,7 +48,6 @@ AM_CFLAGS = $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) $(TOOLKIT_CFL # common/libpychrysacommon.la \ # core/libpychrysacore.la \ # debug/libpychrysadebug.la \ -# format/libpychrysaformat.la \ # $(GTKEXT_LIBADD) \ # $(GUI_LIBADD) \ # mangling/libpychrysamangling.la \ @@ -59,6 +58,7 @@ pychrysalide_la_LIBADD = \ arch/libpychrysaarch4.la \ common/libpychrysacommon.la \ core/libpychrysacore.la \ + format/libpychrysaformat.la \ glibext/libpychrysaglibext.la \ plugins/libpychrysaplugins.la @@ -76,5 +76,5 @@ devdir = $(includedir)/chrysalide/$(subdir) dev_HEADERS = $(pychrysalide_la_SOURCES:%c=) -#SUBDIRS = analysis arch common core debug format glibext $(GTKEXT_SUBDIR) $(GUI_SUBDIR) mangling plugins -SUBDIRS = analysis arch common core glibext plugins +#SUBDIRS = analysis arch common core debug $(GTKEXT_SUBDIR) $(GUI_SUBDIR) mangling plugins +SUBDIRS = analysis arch common core format glibext plugins diff --git a/plugins/pychrysalide/core.c b/plugins/pychrysalide/core.c index 6842c34..c76fae4 100644 --- a/plugins/pychrysalide/core.c +++ b/plugins/pychrysalide/core.c @@ -64,7 +64,7 @@ #include "core/module.h" #include "glibext/module.h" /* #include "debug/module.h" */ -/* #include "format/module.h" */ +#include "format/module.h" /* #ifdef INCLUDE_GTK_SUPPORT */ /* # include "gtkext/module.h" */ /* # include "gui/module.h" */ @@ -648,7 +648,9 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) if (status) status = add_core_module(result); /* if (status) status = add_debug_module(result); + */ if (status) status = add_format_module(result); + /* #ifdef INCLUDE_GTK_SUPPORT if (status) status = add_gtkext_module(result); if (status) status = add_gui_module(result); @@ -671,7 +673,9 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) if (status) status = populate_core_module(); /* if (status) status = populate_debug_module(); + */ if (status) status = populate_format_module(); + /* #ifdef INCLUDE_GTK_SUPPORT if (status) status = populate_gtkext_module(); if (status) status = populate_gui_module(); diff --git a/plugins/pychrysalide/format/Makefile.am b/plugins/pychrysalide/format/Makefile.am index 02f0a6e..efe58f3 100644 --- a/plugins/pychrysalide/format/Makefile.am +++ b/plugins/pychrysalide/format/Makefile.am @@ -1,19 +1,26 @@ noinst_LTLIBRARIES = libpychrysaformat.la +# libpychrysaformat_la_SOURCES = \ +# constants.h constants.c \ +# executable.h executable.c \ +# flat.h flat.c \ +# program.h program.c \ +# known.h known.c \ +# module.h module.c \ +# preload.h preload.c \ +# strsym.h strsym.c \ +# symbol.h symbol.c \ +# symiter.h symiter.c + libpychrysaformat_la_SOURCES = \ - constants.h constants.c \ executable.h executable.c \ flat.h flat.c \ - program.h program.c \ known.h known.c \ module.h module.c \ - preload.h preload.c \ - strsym.h strsym.c \ - symbol.h symbol.c \ - symiter.h symiter.c + program.h program.c -libpychrysaformat_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ +libpychrysaformat_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT diff --git a/plugins/pychrysalide/format/executable.c b/plugins/pychrysalide/format/executable.c index ff2d14a..d886e9a 100644 --- a/plugins/pychrysalide/format/executable.c +++ b/plugins/pychrysalide/format/executable.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * executable.c - équivalent Python du fichier "format/executable.c" * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -30,15 +30,31 @@ #include <i18n.h> -#include <core/processors.h> +#include <format/executable-int.h> -#include "format.h" +#include "program.h" #include "../access.h" #include "../helpers.h" -#include "../arch/processor.h" -#include "../arch/vmpa.h" -#include "../glibext/binportion.h" +//#include "../arch/processor.h" +//#include "../arch/vmpa.h" +//#include "../glibext/binportion.h" + + + +/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ + + +/* Initialise la classe des formats exécutables. */ +static void py_executable_format_init_gclass(GExecutableFormatClass *, gpointer); + +CREATE_DYN_ABSTRACT_CONSTRUCTOR(executable_format, G_TYPE_EXECUTABLE_FORMAT, py_executable_format_init_gclass); + +/* Initialise une instance sur la base du dérivé de GObject. */ +static int py_executable_format_init(PyObject *, PyObject *, PyObject *); + +/* Indique le type d'architecture visée par le format. */ +static char *py_executable_format_get_target_machine_wrapper(const GExecutableFormat *); @@ -46,13 +62,145 @@ /* Enregistre une portion artificielle pour le format. */ -static PyObject *py_exe_format_register_user_portion(PyObject *, PyObject *); +//static PyObject *py_executable_format_register_user_portion(PyObject *, PyObject *); /* Fournit l'emplacement correspondant à une position physique. */ -static PyObject *py_exe_format_translate_offset_into_vmpa(PyObject *, PyObject *); +//static PyObject *py_executable_format_translate_offset_into_vmpa(PyObject *, PyObject *); /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *, PyObject *); +//static PyObject *py_executable_format_translate_address_into_vmpa(PyObject *, PyObject *); + +/* Indique le type d'architecture visée par le format. */ +static PyObject *py_executable_format_get_target_machine(PyObject *, void *); + + + +/* ---------------------------------------------------------------------------------- */ +/* GLUE POUR CREATION DEPUIS PYTHON */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : class = classe à initialiser. * +* unused = données non utilisées ici. * +* * +* Description : Initialise la classe des formats exécutables. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void py_executable_format_init_gclass(GExecutableFormatClass *class, gpointer unused) +{ + class->get_machine = py_executable_format_get_target_machine_wrapper; + +} + + +/****************************************************************************** +* * +* 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_executable_format_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + int ret; /* Bilan de lecture des args. */ + +#define EXECUTABLE_FORMAT_DOC \ + "The ExecutableFormat class provides support for formats containing"\ + " code to run.\n" \ + "\n" \ + "The following method has to be defined for new classes:\n" \ + "* pychrysalide.format.ExecutableFormat._get_target_machine();\n" \ + "\n" \ + "\n" \ + "Calls to the *__init__* constructor of this abstract object expect"\ + " no particular argument." + + /* Initialisation d'un objet GLib */ + + ret = forward_pygobjet_init(self); + if (ret == -1) return -1; + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : format = description du format exécutable à consulter. * +* * +* Description : Indique le type d'architecture visée par le format. * +* * +* Retour : Identifiant de l'architecture ciblée par le format. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static char *py_executable_format_get_target_machine_wrapper(const GExecutableFormat *format) +{ + char *result; /* Désignation à renvoyer */ + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ + PyObject *pyobj; /* Objet Python concerné */ + PyObject *pyret; /* Valeur retournée */ + int ret; /* Bilan d'une conversion */ + +#define EXECUTABLE_FORMAT_GET_TARGET_MACHINE_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _get_target_machine, "$self", \ + METH_NOARGS, \ + "Abstract method used to define the identifier of the architecture" \ + " suitable for the executable format.\n" \ + "\n" \ + "The return value has to be a (tiny) string." \ +) + + result = NULL; + + gstate = PyGILState_Ensure(); + + pyobj = pygobject_new(G_OBJECT(format)); + + if (has_python_method(pyobj, "_get_target_machine")) + { + pyret = run_python_method(pyobj, "_get_target_machine", NULL); + + if (pyret != NULL) + { + ret = PyUnicode_Check(pyret); + + if (ret) + result = strdup(PyUnicode_AsUTF8(pyret)); + else + PyErr_SetString(PyExc_ValueError, _("unexpected value type for executable format target machine")); + + Py_DECREF(pyret); + + } + + } + + Py_DECREF(pyobj); + + PyGILState_Release(gstate); + + return result; + +} @@ -61,6 +209,7 @@ static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *, PyObject /* ---------------------------------------------------------------------------------- */ +#if 0 /****************************************************************************** * * * Paramètres : self = description de l'exécutable à consulter. * @@ -74,16 +223,16 @@ static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *, PyObject * * ******************************************************************************/ -static PyObject *py_exe_format_register_user_portion(PyObject *self, PyObject *args) +static PyObject *py_executable_format_register_user_portion(PyObject *self, PyObject *args) { GBinPortion *portion; /* Portion binaire à conserver */ int ret; /* Bilan de lecture des args. */ - GExeFormat *format; /* Version GLib du format */ + GExecutableFormat *format; /* Version GLib du format */ ret = PyArg_ParseTuple(args, "O&", convert_to_binary_portion, &portion); if (!ret) return NULL; - format = G_EXE_FORMAT(pygobject_get(self)); + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); g_object_ref(G_OBJECT(portion)); g_exe_format_register_user_portion(format, portion); @@ -106,16 +255,16 @@ static PyObject *py_exe_format_register_user_portion(PyObject *self, PyObject *a * * ******************************************************************************/ -static PyObject *py_exe_format_translate_offset_into_vmpa(PyObject *self, PyObject *args) +static PyObject *py_executable_format_translate_offset_into_vmpa(PyObject *self, PyObject *args) { PyObject *result; /* Instance à retourner */ - GExeFormat *format; /* Version GLib du format */ + GExecutableFormat *format; /* Version GLib du format */ unsigned long long off; /* Adresse en mémoire virtuelle*/ int ret; /* Bilan de lecture des args. */ vmpa2t pos; /* Position complète déterminée*/ bool status; /* Bilan de l'opération */ - format = G_EXE_FORMAT(pygobject_get(self)); + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); assert(format != NULL); ret = PyArg_ParseTuple(args, "K", &off); @@ -150,16 +299,16 @@ static PyObject *py_exe_format_translate_offset_into_vmpa(PyObject *self, PyObje * * ******************************************************************************/ -static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *self, PyObject *args) +static PyObject *py_executable_format_translate_address_into_vmpa(PyObject *self, PyObject *args) { PyObject *result; /* Instance à retourner */ - GExeFormat *format; /* Version GLib du format */ + GExecutableFormat *format; /* Version GLib du format */ unsigned long long addr; /* Adresse en mémoire virtuelle*/ int ret; /* Bilan de lecture des args. */ vmpa2t pos; /* Position complète déterminée*/ bool status; /* Bilan de l'opération */ - format = G_EXE_FORMAT(pygobject_get(self)); + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); assert(format != NULL); ret = PyArg_ParseTuple(args, "K", &addr); @@ -179,6 +328,56 @@ static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *self, PyObj return result; } +#endif + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique le type d'architecture visée par le format. * +* * +* Retour : Identifiant de l'architecture ciblée par le format. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_executable_format_get_target_machine(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GExecutableFormat *format; /* Format exécutable manipulé */ + char *machine; /* Désignation machine ciblée */ + +#define EXECUTABLE_FORMAT_TARGET_MACHINE_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + target_machine, py_executable_format, \ + "Identifier of the architecture suitable for the executable format,"\ + " provided as a (tiny) string." \ +) + + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); + + machine = g_executable_format_get_target_machine(format); + + if (machine != NULL) + { + result = PyUnicode_FromString(machine); + free(machine); + } + else + { + result = NULL; + + if (PyErr_Occurred() == NULL) + PyErr_SetString(PyExc_ValueError, _("unexpected NULL value for executable format target machine")); + + } + + return result; + +} /****************************************************************************** @@ -195,46 +394,53 @@ static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *self, PyObj PyTypeObject *get_python_executable_format_type(void) { - static PyMethodDef py_exe_format_methods[] = { + static PyMethodDef py_executable_format_methods[] = { + EXECUTABLE_FORMAT_GET_TARGET_MACHINE_WRAPPER, +#if 0 { - "register_user_portion", py_exe_format_register_user_portion, + "register_user_portion", py_executable_format_register_user_portion, METH_VARARGS, "register_user_portion($self, portion, /)\n--\n\nRemember a given user-defined binary portion as part of the executable format content." }, { - "translate_offset_into_vmpa", py_exe_format_translate_offset_into_vmpa, + "translate_offset_into_vmpa", py_executable_format_translate_offset_into_vmpa, METH_VARARGS, "translate_offset_into_vmpa($self, off, /)\n--\n\nTranslate a physical offset to a full location." }, { - "translate_address_into_vmpa", py_exe_format_translate_address_into_vmpa, + "translate_address_into_vmpa", py_executable_format_translate_address_into_vmpa, METH_VARARGS, "translate_address_into_vmpa($self, addr, /)\n--\n\nTranslate a physical offset to a full location." }, +#endif { NULL } }; - static PyGetSetDef py_exe_format_getseters[] = { + static PyGetSetDef py_executable_format_getseters[] = { + EXECUTABLE_FORMAT_TARGET_MACHINE_ATTRIB, { NULL } }; - static PyTypeObject py_exe_format_type = { + static PyTypeObject py_executable_format_type = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pychrysalide.format.ExeFormat", + .tp_name = "pychrysalide.format.ExecutableFormat", .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_doc = "PyChrysalide executable format", + .tp_doc = EXECUTABLE_FORMAT_DOC, + + .tp_methods = py_executable_format_methods, + .tp_getset = py_executable_format_getseters, - .tp_methods = py_exe_format_methods, - .tp_getset = py_exe_format_getseters, + .tp_init = py_executable_format_init, + .tp_new = py_executable_format_new, }; - return &py_exe_format_type; + return &py_executable_format_type; } @@ -265,10 +471,10 @@ bool ensure_python_executable_format_is_registered(void) dict = PyModule_GetDict(module); - if (!ensure_python_binary_format_is_registered()) + if (!ensure_python_program_format_is_registered()) return false; - if (!register_class_for_pygobject(dict, G_TYPE_EXE_FORMAT, type)) + if (!register_class_for_pygobject(dict, G_TYPE_EXECUTABLE_FORMAT, type)) return false; } @@ -309,7 +515,7 @@ int convert_to_executable_format(PyObject *arg, void *dst) break; case 1: - *((GExeFormat **)dst) = G_EXE_FORMAT(pygobject_get(arg)); + *((GExecutableFormat **)dst) = G_EXECUTABLE_FORMAT(pygobject_get(arg)); break; default: @@ -328,7 +534,7 @@ int convert_to_executable_format(PyObject *arg, void *dst) /* TRADUCTION D'EMPLACEMENT */ /* ---------------------------------------------------------------------------------- */ - +#if 0 /****************************************************************************** * * * Paramètres : obj = objet Python à convertir en emplacement. * @@ -391,3 +597,4 @@ int convert_to_vmpa_using_executable(PyObject *obj, exe_cv_info_t *info) return result; } +#endif diff --git a/plugins/pychrysalide/format/executable.h b/plugins/pychrysalide/format/executable.h index 9ef1fe5..1b305a4 100644 --- a/plugins/pychrysalide/format/executable.h +++ b/plugins/pychrysalide/format/executable.h @@ -50,7 +50,7 @@ int convert_to_executable_format(PyObject *, void *); /* ---------------------------- TRADUCTION D'EMPLACEMENT ---------------------------- */ - +#if 0 /* Informations utiles à une traduction */ typedef struct _exe_cv_info_t { @@ -64,7 +64,7 @@ typedef struct _exe_cv_info_t /* Réalise une conversion d'un objet Python en localisation. */ int convert_to_vmpa_using_executable(PyObject *, exe_cv_info_t *); - +#endif #endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_EXECUTABLE_H */ diff --git a/plugins/pychrysalide/format/flat.c b/plugins/pychrysalide/format/flat.c index 4df3646..a115c57 100644 --- a/plugins/pychrysalide/format/flat.c +++ b/plugins/pychrysalide/format/flat.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat.c - équivalent Python du fichier "format/flat.c" * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -28,43 +28,46 @@ #include <pygobject.h> -#include <format/flat.h> +#include <format/flat-int.h> #include "executable.h" #include "../access.h" +#include "../constants.h" #include "../helpers.h" #include "../analysis/content.h" -/* Crée un nouvel objet Python de type 'FlatFormat'. */ -static PyObject *py_flat_format_new(PyTypeObject *, PyObject *, PyObject *); +CREATE_DYN_CONSTRUCTOR(flat_format, G_TYPE_FLAT_FORMAT); + + +/* Initialise une instance sur la base du dérivé de GObject. */ +static int py_flat_format_init(PyObject *, PyObject *, PyObject *); /****************************************************************************** * * -* Paramètres : type = type de l'objet à instancier. * +* Paramètres : self = objet à initialiser (théoriquement). * * args = arguments fournis à l'appel. * * kwds = arguments de type key=val fournis. * * * -* Description : Crée un nouvel objet Python de type 'FlatFormat'. * +* Description : Initialise une instance sur la base du dérivé de GObject. * * * -* Retour : Instance Python mise en place. * +* Retour : 0. * * * * Remarques : - * * * ******************************************************************************/ -static PyObject *py_flat_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static int py_flat_format_init(PyObject *self, PyObject *args, PyObject *kwds) { - PyObject *result; /* Instance à retourner */ GBinContent *content; /* Instance GLib du contenu */ const char *machine; /* Identifiant d'architecture */ - unsigned int endian; /* Boutisme de l'architecture */ + SourceEndian endian; /* Boutisme de l'architecture */ int ret; /* Bilan de lecture des args. */ - GExeFormat *format; /* Création GLib à transmettre */ + GFlatFormat *format; /* Création GLib à transmettre */ #define FLAT_FORMAT_DOC \ "FlatFormat is suitable for all executable contents without a proper" \ @@ -75,27 +78,30 @@ static PyObject *py_flat_format_new(PyTypeObject *type, PyObject *args, PyObject " FlatFormat(content, machine, endian)" \ "\n" \ "Where content is a pychrysalide.analysis.BinContent object, machine" \ - " defines the target architecture and endian provides the right" \ - " endianness of the data." + " defines the target architecture as a string value and endian provides"\ + " the right endianness of the data, as pychrysalide.SourceEndian value." - ret = PyArg_ParseTuple(args, "O&sI", convert_to_binary_content, &content, &machine, &endian); - if (!ret) return NULL; + /* Récupération des paramètres */ - format = g_flat_format_new(content, machine, endian); + ret = PyArg_ParseTuple(args, "O&sO&", + convert_to_binary_content, &content, + &machine, + convert_to_source_endian, &endian); + if (!ret) return -1; - if (format == NULL) - { - result = Py_None; - Py_INCREF(result); - } + /* Initialisation d'un objet GLib */ - else - { - result = pygobject_new(G_OBJECT(format)); - g_object_unref(format); - } + ret = forward_pygobjet_init(self); + if (ret == -1) return -1; - return result; + /* Eléments de base */ + + format = G_FLAT_FORMAT(pygobject_get(self)); + + if (!g_flat_format_create(format, content, machine, endian)) + return -1; + + return 0; } @@ -135,7 +141,9 @@ PyTypeObject *get_python_flat_format_type(void) .tp_methods = py_flat_format_methods, .tp_getset = py_flat_format_getseters, - .tp_new = py_flat_format_new + + .tp_init = py_flat_format_init, + .tp_new = py_flat_format_new, }; diff --git a/plugins/pychrysalide/format/known.c b/plugins/pychrysalide/format/known.c index 3167ba2..e38c975 100644 --- a/plugins/pychrysalide/format/known.c +++ b/plugins/pychrysalide/format/known.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * known.c - équivalent Python du fichier "format/known.c" * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -30,7 +30,6 @@ #include <i18n.h> #include <format/known-int.h> -#include <plugins/dt.h> #include "../access.h" @@ -42,12 +41,11 @@ /* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ -/* Accompagne la création d'une instance dérivée en Python. */ -static PyObject *py_known_format_new(PyTypeObject *, PyObject *, PyObject *); - /* Initialise la classe des descriptions de fichier binaire. */ static void py_known_format_init_gclass(GKnownFormatClass *, gpointer); +CREATE_DYN_ABSTRACT_CONSTRUCTOR(known_format, G_TYPE_KNOWN_FORMAT, py_known_format_init_gclass); + /* Initialise une instance sur la base du dérivé de GObject. */ static int py_known_format_init(PyObject *, PyObject *, PyObject *); @@ -57,11 +55,13 @@ static char *py_known_format_get_key_wrapper(const GKnownFormat *); /* Fournit une description humaine du format. */ static char *py_known_format_get_description_wrapper(const GKnownFormat *); +#if 0 /* Assure l'interprétation d'un format en différé. */ static bool py_known_format_analyze_wrapper(GKnownFormat *, wgroup_id_t, GtkStatusStack *); /* Réalise un traitement post-désassemblage. */ static void py_known_format_complete_analysis_wrapper(GKnownFormat *, wgroup_id_t, GtkStatusStack *); +#endif @@ -69,10 +69,10 @@ static void py_known_format_complete_analysis_wrapper(GKnownFormat *, wgroup_id_ /* Assure l'interprétation d'un format en différé. */ -static PyObject *py_known_format_analyze(PyObject *, PyObject *); +//static PyObject *py_known_format_analyze(PyObject *, PyObject *); /* Réalise un traitement post-désassemblage. */ -static PyObject *py_known_format_complete_analysis(PyObject *, PyObject *); +//static PyObject *py_known_format_complete_analysis(PyObject *, PyObject *); /* Indique la désignation interne du format. */ static PyObject *py_known_format_get_key(PyObject *, void *); @@ -92,73 +92,10 @@ static PyObject *py_known_format_get_content(PyObject *, void *); /****************************************************************************** * * -* Paramètres : type = type du nouvel objet à mettre en place. * -* args = éventuelle liste d'arguments. * -* kwds = éventuel dictionnaire de valeurs mises à disposition. * -* * -* Description : Accompagne la création d'une instance dérivée en Python. * -* * -* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_known_format_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_known_format_type(); - - if (type == base) - { - result = NULL; - PyErr_Format(PyExc_RuntimeError, _("%s is an abstract class"), type->tp_name); - goto exit; - } - - /* Mise en place d'un type dédié */ - - first_time = (g_type_from_name(type->tp_name) == 0); - - gtype = build_dynamic_type(G_TYPE_KNOWN_FORMAT, type->tp_name, - (GClassInitFunc)py_known_format_init_gclass, NULL, NULL); - - if (first_time) - { - status = register_class_for_dynamic_pygobject(gtype, type); - - if (!status) - { - result = NULL; - goto exit; - } - - } - - /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */ - - result = PyType_GenericNew(type, args, kwds); - - exit: - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : class = classe à initialiser. * * unused = données non utilisées ici. * * * -* Description : Initialise la classe générique des processeurs. * +* Description : Initialise la classe des formats connus. * * * * Retour : - * * * @@ -171,8 +108,8 @@ static void py_known_format_init_gclass(GKnownFormatClass *class, gpointer unuse class->get_key = py_known_format_get_key_wrapper; class->get_desc = py_known_format_get_description_wrapper; - class->analyze = py_known_format_analyze_wrapper; - class->complete = py_known_format_complete_analysis_wrapper; + //class->analyze = py_known_format_analyze_wrapper; + //class->complete = py_known_format_complete_analysis_wrapper; } @@ -201,12 +138,8 @@ static int py_known_format_init(PyObject *self, PyObject *args, PyObject *kwds) "KnownFormat is a small class providing basic features for" \ " recognized formats.\n" \ "\n" \ - "One item has to be defined as class attribute in the final" \ - " class:\n" \ - "* *_key*: a string providing a small name used to identify the" \ - " format.\n" \ - "\n" \ "The following methods have to be defined for new classes:\n" \ + "* pychrysalide.format.KnownFormat._get_key();\n" \ "* pychrysalide.format.KnownFormat._get_description();\n" \ "* pychrysalide.format.KnownFormat._analyze().\n" \ "\n" \ @@ -231,7 +164,8 @@ static int py_known_format_init(PyObject *self, PyObject *args, PyObject *kwds) format = G_KNOWN_FORMAT(pygobject_get(self)); - g_known_format_set_content(format, content); + if (!g_known_format_create(format, content)) + return -1; return 0; @@ -255,27 +189,39 @@ static char *py_known_format_get_key_wrapper(const GKnownFormat *format) char *result; /* Désignation à renvoyer */ PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ - PyObject *pykey; /* Clef en objet Python */ + PyObject *pyret; /* Valeur retournée */ int ret; /* Bilan d'une conversion */ +#define KNOWN_FORMAT_GET_KEY_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _get_key, "$self", \ + METH_NOARGS, \ + "Abstract method used to define the internal name" \ + " of the known format.\n" \ + "\n" \ + "The return value has to be a (tiny) string." \ +) + result = NULL; gstate = PyGILState_Ensure(); pyobj = pygobject_new(G_OBJECT(format)); - if (PyObject_HasAttrString(pyobj, "_key")) + if (has_python_method(pyobj, "_get_key")) { - pykey = PyObject_GetAttrString(pyobj, "_key"); + pyret = run_python_method(pyobj, "_get_key", NULL); - if (pykey != NULL) + if (pyret != NULL) { - ret = PyUnicode_Check(pykey); + ret = PyUnicode_Check(pyret); if (ret) - result = strdup(PyUnicode_AsUTF8(pykey)); + result = strdup(PyUnicode_AsUTF8(pyret)); + else + PyErr_SetString(PyExc_ValueError, _("unexpected value type for known format key")); - Py_DECREF(pykey); + Py_DECREF(pyret); } @@ -335,6 +281,8 @@ static char *py_known_format_get_description_wrapper(const GKnownFormat *format) if (ret) result = strdup(PyUnicode_AsUTF8(pyret)); + else + PyErr_SetString(PyExc_ValueError, _("unexpected value type for known format description")); Py_DECREF(pyret); @@ -350,7 +298,7 @@ static char *py_known_format_get_description_wrapper(const GKnownFormat *format) } - +#if 0 /****************************************************************************** * * * Paramètres : format = format chargé dont l'analyse est lancée. * @@ -475,7 +423,7 @@ static void py_known_format_complete_analysis_wrapper(GKnownFormat *format, wgro PyGILState_Release(gstate); } - +#endif /* ---------------------------------------------------------------------------------- */ @@ -483,6 +431,7 @@ static void py_known_format_complete_analysis_wrapper(GKnownFormat *format, wgro /* ---------------------------------------------------------------------------------- */ +#if 0 /****************************************************************************** * * * Paramètres : self = objet représentant un format connu. * @@ -584,6 +533,7 @@ static PyObject *py_known_format_complete_analysis(PyObject *self, PyObject *arg return result; } +#endif /****************************************************************************** @@ -615,9 +565,30 @@ static PyObject *py_known_format_get_key(PyObject *self, void *closure) key = g_known_format_get_key(format); - result = PyUnicode_FromString(key); + if (key != NULL) + { + result = PyUnicode_FromString(key); + free(key); + } + else + { + result = NULL; - free(key); + /** + * Si l'absence de retour vient d'une instance implémentée en Python, + * une exception peut (et doit dans ce cas) avoir été définie dans la + * fonction py_known_format_get_key_wrapper(). + * + * Aucun traitement supplémntaire n'est alors nécessaire. + * + * Une action est cependant nécessaire pour assurer un traitement + * des extensions purement natives offrant une mauvaise implémentation. + */ + + if (PyErr_Occurred() == NULL) + PyErr_SetString(PyExc_ValueError, _("unexpected NULL value for known format key")); + + } return result; @@ -653,9 +624,30 @@ static PyObject *py_known_format_get_description(PyObject *self, void *closure) desc = g_known_format_get_description(format); - result = PyUnicode_FromString(desc); + if (desc != NULL) + { + result = PyUnicode_FromString(desc); + free(desc); + } + else + { + result = NULL; - free(desc); + /** + * Si l'absence de retour vient d'une instance implémentée en Python, + * une exception peut (et doit dans ce cas) avoir été définie dans la + * fonction py_known_format_get_description_wrapper(). + * + * Aucun traitement supplémntaire n'est alors nécessaire. + * + * Une action est cependant nécessaire pour assurer un traitement + * des extensions purement natives offrant une mauvaise implémentation. + */ + + if (PyErr_Occurred() == NULL) + PyErr_SetString(PyExc_ValueError, _("unexpected NULL value for known format description")); + + } return result; @@ -724,11 +716,12 @@ static PyObject *py_known_format_get_content(PyObject *self, void *closure) PyTypeObject *get_python_known_format_type(void) { static PyMethodDef py_known_format_methods[] = { + KNOWN_FORMAT_GET_KEY_WRAPPER, KNOWN_FORMAT_GET_DESCRIPTION_WRAPPER, - KNOWN_FORMAT_ANALYZE_WRAPPER, - KNOWN_FORMAT_COMPLETE_ANALYSIS_WRAPPER, - KNOWN_FORMAT_ANALYZE_METHOD, - KNOWN_FORMAT_COMPLETE_ANALYSIS_METHOD, + //KNOWN_FORMAT_ANALYZE_WRAPPER, + //KNOWN_FORMAT_COMPLETE_ANALYSIS_WRAPPER, + //KNOWN_FORMAT_ANALYZE_METHOD, + //KNOWN_FORMAT_COMPLETE_ANALYSIS_METHOD, { NULL } }; diff --git a/plugins/pychrysalide/format/module.c b/plugins/pychrysalide/format/module.c index 62c15ed..95d4172 100644 --- a/plugins/pychrysalide/format/module.c +++ b/plugins/pychrysalide/format/module.c @@ -30,12 +30,12 @@ #include "executable.h" #include "flat.h" -#include "format.h" #include "known.h" -#include "preload.h" -#include "strsym.h" -#include "symbol.h" -#include "symiter.h" +//#include "preload.h" +#include "program.h" +//#include "strsym.h" +//#include "symbol.h" +//#include "symiter.h" #include "../helpers.h" @@ -105,11 +105,11 @@ bool populate_format_module(void) if (result) result = ensure_python_executable_format_is_registered(); if (result) result = ensure_python_flat_format_is_registered(); if (result) result = ensure_python_known_format_is_registered(); - if (result) result = ensure_python_binary_format_is_registered(); - if (result) result = ensure_python_preload_info_is_registered(); - if (result) result = ensure_python_string_symbol_is_registered(); - if (result) result = ensure_python_binary_symbol_is_registered(); - if (result) result = ensure_python_sym_iterator_is_registered(); + //if (result) result = ensure_python_preload_info_is_registered(); + if (result) result = ensure_python_program_format_is_registered(); + //if (result) result = ensure_python_string_symbol_is_registered(); + //if (result) result = ensure_python_binary_symbol_is_registered(); + //if (result) result = ensure_python_sym_iterator_is_registered(); assert(result); diff --git a/plugins/pychrysalide/format/program.c b/plugins/pychrysalide/format/program.c index 82c6c33..d96c2db 100644 --- a/plugins/pychrysalide/format/program.c +++ b/plugins/pychrysalide/format/program.c @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format.c - équivalent Python du fichier "format/format.c" + * program.c - équivalent Python du fichier "format/program.c" * - * Copyright (C) 2018-2020 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -22,101 +22,104 @@ */ -#include "format.h" +#include "program.h" #include <pygobject.h> -#include <i18n.h> -#include <format/format-int.h> -#include <plugins/dt.h> +#include <format/program-int.h> +#include "known.h" +#include "../access.h" +#include "../constants.h" +#include "../helpers.h" + + +/* #include "constants.h" #include "executable.h" -#include "known.h" #include "symbol.h" #include "symiter.h" -#include "../access.h" -#include "../helpers.h" #include "../analysis/constants.h" #include "../analysis/content.h" #include "../arch/vmpa.h" #include "../arch/constants.h" +*/ /* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */ -/* Accompagne la création d'une instance dérivée en Python. */ -static PyObject *py_binary_format_new(PyTypeObject *, PyObject *, PyObject *); +/* Initialise la classe des formats de programmes. */ +static void py_program_format_init_gclass(GProgramFormatClass *, gpointer); -/* Initialise la classe des descriptions de fichier binaire. */ -static void py_binary_format_init_gclass(GBinFormatClass *, gpointer); +CREATE_DYN_ABSTRACT_CONSTRUCTOR(program_format, G_TYPE_PROGRAM_FORMAT, py_program_format_init_gclass); /* Initialise une instance sur la base du dérivé de GObject. */ -static int py_binary_format_init(PyObject *, PyObject *, PyObject *); +static int py_program_format_init(PyObject *, PyObject *, PyObject *); /* Indique le boutisme employé par le format binaire analysé. */ -static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *); +static SourceEndian py_program_format_get_endianness_wrapper(const GProgramFormat *); /* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */ +#if 0 /* Ajoute une information complémentaire à un format. */ -static PyObject *py_binary_format_set_flag(PyObject *, PyObject *); +static PyObject *py_program_format_set_flag(PyObject *, PyObject *); /* Retire une information complémentaire à un format. */ -static PyObject *py_binary_format_unset_flag(PyObject *, PyObject *); +static PyObject *py_program_format_unset_flag(PyObject *, PyObject *); /* Détermine si un format possède un fanion particulier. */ -static PyObject *py_binary_format_has_flag(PyObject *, PyObject *); +static PyObject *py_program_format_has_flag(PyObject *, PyObject *); /* Enregistre une adresse comme début d'une zone de code. */ -static PyObject *py_binary_format_register_code_point(PyObject *, PyObject *); +static PyObject *py_program_format_register_code_point(PyObject *, PyObject *); /* Ajoute un symbole à la collection du format binaire. */ -static PyObject *py_binary_format_add_symbol(PyObject *, PyObject *); +static PyObject *py_program_format_add_symbol(PyObject *, PyObject *); /* Retire un symbole de la collection du format binaire. */ -static PyObject *py_binary_format_remove_symbol(PyObject *, PyObject *); +static PyObject *py_program_format_remove_symbol(PyObject *, PyObject *); /* Recherche le symbole correspondant à une étiquette. */ -static PyObject *py_binary_format_find_symbol_by_label(PyObject *, PyObject *); +static PyObject *py_program_format_find_symbol_by_label(PyObject *, PyObject *); /* Recherche le symbole suivant celui lié à une adresse. */ -static PyObject *py_binary_format_find_symbol_at(PyObject *, PyObject *); +static PyObject *py_program_format_find_symbol_at(PyObject *, PyObject *); /* Recherche le symbole suivant celui lié à une adresse. */ -static PyObject *py_binary_format_find_next_symbol_at(PyObject *, PyObject *); +static PyObject *py_program_format_find_next_symbol_at(PyObject *, PyObject *); /* Recherche le symbole correspondant à une adresse. */ -static PyObject *py_binary_format_resolve_symbol(PyObject *, PyObject *); +static PyObject *py_program_format_resolve_symbol(PyObject *, PyObject *); /* Fournit les particularités du format. */ -static PyObject *py_binary_format_get_flags(PyObject *, void *); +static PyObject *py_program_format_get_flags(PyObject *, void *); /* Indique le boutisme employé par le format binaire analysé. */ -static PyObject *py_binary_format_get_endianness(PyObject *, void *); +static PyObject *py_program_format_get_endianness(PyObject *, void *); /* Fournit la liste de tous les symboles détectés. */ -static PyObject *py_binary_format_get_symbols(PyObject *, void *); - +static PyObject *py_program_format_get_symbols(PyObject *, void *); +#endif /* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */ - +#if 0 /* Etend la liste des soucis détectés avec de nouvelles infos. */ -static PyObject *py_binary_format_add_error(PyObject *, PyObject *); +static PyObject *py_program_format_add_error(PyObject *, PyObject *); /* Fournit les éléments concernant tous les soucis détectés. */ -static PyObject *py_binary_format_get_errors(PyObject *, void *); - +static PyObject *py_program_format_get_errors(PyObject *, void *); +#endif /* ---------------------------------------------------------------------------------- */ @@ -126,73 +129,10 @@ static PyObject *py_binary_format_get_errors(PyObject *, void *); /****************************************************************************** * * -* Paramètres : type = type du nouvel objet à mettre en place. * -* args = éventuelle liste d'arguments. * -* kwds = éventuel dictionnaire de valeurs mises à disposition. * -* * -* Description : Accompagne la création d'une instance dérivée en Python. * -* * -* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_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_known_format_type(); - - if (type == base) - { - result = NULL; - PyErr_Format(PyExc_RuntimeError, _("%s is an abstract class"), type->tp_name); - goto exit; - } - - /* Mise en place d'un type dédié */ - - first_time = (g_type_from_name(type->tp_name) == 0); - - gtype = build_dynamic_type(G_TYPE_BIN_FORMAT, type->tp_name, - (GClassInitFunc)py_binary_format_init_gclass, NULL, NULL); - - if (first_time) - { - status = register_class_for_dynamic_pygobject(gtype, type); - - if (!status) - { - result = NULL; - goto exit; - } - - } - - /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */ - - result = PyType_GenericNew(type, args, kwds); - - exit: - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : class = classe à initialiser. * * unused = données non utilisées ici. * * * -* Description : Initialise la classe générique des processeurs. * +* Description : Initialise la classe des formats de programmes. * * * * Retour : - * * * @@ -200,9 +140,9 @@ static PyObject *py_binary_format_new(PyTypeObject *type, PyObject *args, PyObje * * ******************************************************************************/ -static void py_binary_format_init_gclass(GBinFormatClass *class, gpointer unused) +static void py_program_format_init_gclass(GProgramFormatClass *class, gpointer unused) { - class->get_endian = py_binary_format_get_endianness_wrapper; + class->get_endian = py_program_format_get_endianness_wrapper; } @@ -221,18 +161,18 @@ static void py_binary_format_init_gclass(GBinFormatClass *class, gpointer unused * * ******************************************************************************/ -static int py_binary_format_init(PyObject *self, PyObject *args, PyObject *kwds) +static int py_program_format_init(PyObject *self, PyObject *args, PyObject *kwds) { int ret; /* Bilan de lecture des args. */ -#define BINARY_FORMAT_DOC \ - "The BinFormat class is the major poart of binary format support." \ - " It is the core class used by loading most of the binary files.\n" \ +#define PROGRAM_FORMAT_DOC \ + "The ProgramFormat class is the major part of binary format" \ + " support. It is the core class used by loading most of the binary" \ + " files.\n" \ + "\n" \ "\n" \ - "One item has to be defined as class attribute in the final" \ - " class:\n" \ - "* *_endianness*: a pychrysalide.analysis.BinContent.SourceEndian" \ - " value indicating the endianness of the format.\n" \ + "The following method has to be defined for new classes:\n" \ + "* pychrysalide.format.ProgramFormat._get_endianness().\n" \ "\n" \ "Calls to the *__init__* constructor of this abstract object expect"\ " no particular argument." @@ -259,7 +199,7 @@ static int py_binary_format_init(PyObject *self, PyObject *args, PyObject *kwds) * * ******************************************************************************/ -static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *format) +static SourceEndian py_program_format_get_endianness_wrapper(const GProgramFormat *format) { SourceEndian result; /* Boutisme à retourner */ PyGILState_STATE gstate; /* Sauvegarde d'environnement */ @@ -267,22 +207,35 @@ static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *fo PyObject *pyret; /* Valeur retournée */ int ret; /* Bilan d'une conversion */ +#define PROGRAM_FORMAT_GET_ENDIANNESS_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _get_endianness_wrapper, "$self", \ + METH_NOARGS, \ + "Abstract method used to define the endianness of the format.\n"\ + "\n" \ + "The return value is of type pychrysalide.SourceEndian," \ + " pychrysalide.SourceEndian.LITTLE by default." \ +) + result = SRE_LITTLE; gstate = PyGILState_Ensure(); pyobj = pygobject_new(G_OBJECT(format)); - if (PyObject_HasAttrString(pyobj, "_endianness")) + if (has_python_method(pyobj, "_get_endianness")) { - pyret = PyObject_GetAttrString(pyobj, "_endianness"); + pyret = run_python_method(pyobj, "_get_endianness", NULL); if (pyret != NULL) { ret = convert_to_source_endian(pyret, &result); if (ret != 1) + { + PyErr_Clear(); result = SRE_LITTLE; + } Py_DECREF(pyret); @@ -304,6 +257,7 @@ static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *fo /* ---------------------------------------------------------------------------------- */ +#if 0 /****************************************************************************** * * * Paramètres : self = serveur à manipuler. * @@ -317,18 +271,18 @@ static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *fo * * ******************************************************************************/ -static PyObject *py_binary_format_set_flag(PyObject *self, PyObject *args) +static PyObject *py_program_format_set_flag(PyObject *self, PyObject *args) { PyObject *result; /* Bilan à retourner */ unsigned int flag; /* Propriété à traiter */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Elément à manipuler */ + GProgramFormat *format; /* Elément à manipuler */ bool status; /* Bilan de l'opération */ -#define BINARY_FORMAT_SET_FLAG_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_SET_FLAG_METHOD PYTHON_METHOD_DEF \ ( \ set_flag, "$self, flag, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Add a property from a binary format.\n" \ "\n" \ "This property is one of the values listed in the" \ @@ -341,9 +295,9 @@ static PyObject *py_binary_format_set_flag(PyObject *self, PyObject *args) ret = PyArg_ParseTuple(args, "I", &flag); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - status = g_binary_format_set_flag(format, flag); + status = g_program_format_set_flag(format, flag); result = status ? Py_True : Py_False; Py_INCREF(result); @@ -366,18 +320,18 @@ static PyObject *py_binary_format_set_flag(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_unset_flag(PyObject *self, PyObject *args) +static PyObject *py_program_format_unset_flag(PyObject *self, PyObject *args) { PyObject *result; /* Bilan à retourner */ unsigned int flag; /* Propriété à traiter */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Elément à manipuler */ + GProgramFormat *format; /* Elément à manipuler */ bool status; /* Bilan de l'opération */ -#define BINARY_FORMAT_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \ ( \ unset_flag, "$self, flag, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Remove a property from a binary format.\n" \ "\n" \ "This property is one of the values listed in the" \ @@ -390,9 +344,9 @@ static PyObject *py_binary_format_unset_flag(PyObject *self, PyObject *args) ret = PyArg_ParseTuple(args, "I", &flag); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - status = g_binary_format_unset_flag(format, flag); + status = g_program_format_unset_flag(format, flag); result = status ? Py_True : Py_False; Py_INCREF(result); @@ -415,18 +369,18 @@ static PyObject *py_binary_format_unset_flag(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_has_flag(PyObject *self, PyObject *args) +static PyObject *py_program_format_has_flag(PyObject *self, PyObject *args) { PyObject *result; /* Bilan à retourner */ unsigned int flag; /* Propriété à traiter */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Elément à manipuler */ + GProgramFormat *format; /* Elément à manipuler */ bool status; /* Bilan de l'opération */ -#define BINARY_FORMAT_HAS_FLAG_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_HAS_FLAG_METHOD PYTHON_METHOD_DEF \ ( \ has_flag, "$self, flag, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Test if a binary format has a given property.\n" \ "\n" \ "This property is one of the values listed in the" \ @@ -438,9 +392,9 @@ static PyObject *py_binary_format_has_flag(PyObject *self, PyObject *args) ret = PyArg_ParseTuple(args, "I", &flag); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - status = g_binary_format_has_flag(format, flag); + status = g_program_format_has_flag(format, flag); result = status ? Py_True : Py_False; Py_INCREF(result); @@ -463,17 +417,17 @@ static PyObject *py_binary_format_has_flag(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject *args) +static PyObject *py_program_format_register_code_point(PyObject *self, PyObject *args) { unsigned long long pt; /* Adresse virtuelle du point */ DisassPriorityLevel level; /* Nature du point fourni */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ + GProgramFormat *format; /* Format de binaire manipulé */ -#define BINARY_FORMAT_REGISTER_CODE_POINT_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_REGISTER_CODE_POINT_METHOD PYTHON_METHOD_DEF \ ( \ register_code_point, "$self, point, level, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Register a virtual address as entry point or basic point.\n" \ "\n" \ "The point is an integer value for the virtual memory location" \ @@ -484,9 +438,9 @@ static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject * ret = PyArg_ParseTuple(args, "kO&", &pt, convert_to_disass_priority_level, &level); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - g_binary_format_register_code_point(format, pt, level); + g_program_format_register_code_point(format, pt, level); Py_RETURN_NONE; @@ -506,18 +460,18 @@ static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject * * * ******************************************************************************/ -static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args) +static PyObject *py_program_format_add_symbol(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ GBinSymbol *symbol; /* Enventuel symbole trouvé */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ + GProgramFormat *format; /* Format de binaire manipulé */ bool added; /* Bilan de l'appel interne */ -#define BINARY_FORMAT_ADD_SYMBOL_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_ADD_SYMBOL_METHOD PYTHON_METHOD_DEF \ ( \ add_symbol, "$self, symbol, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Register a new symbol for the format.\n" \ "\n" \ "The symbol has to be a pychrysalide.format.BinSymbol instance." \ @@ -526,10 +480,10 @@ static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args) ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); g_object_ref(G_OBJECT(symbol)); - added = g_binary_format_add_symbol(format, symbol); + added = g_program_format_add_symbol(format, symbol); result = added ? Py_True : Py_False; Py_INCREF(result); @@ -552,17 +506,17 @@ static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args) +static PyObject *py_program_format_remove_symbol(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ GBinSymbol *symbol; /* Enventuel symbole trouvé */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ + GProgramFormat *format; /* Format de binaire manipulé */ -#define BINARY_FORMAT_REMOVE_SYMBOL_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_REMOVE_SYMBOL_METHOD PYTHON_METHOD_DEF \ ( \ remove_symbol, "$self, symbol, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Unregister a symbol from the format.\n" \ "\n" \ "The symbol has to be a pychrysalide.format.BinSymbol instance." \ @@ -571,9 +525,9 @@ static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args) ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - g_binary_format_remove_symbol(format, symbol); + g_program_format_remove_symbol(format, symbol); result = Py_None; Py_INCREF(result); @@ -596,19 +550,19 @@ static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject *args) +static PyObject *py_program_format_find_symbol_by_label(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ const char *label; /* Etiquette à retrouver */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ + GProgramFormat *format; /* Format de binaire manipulé */ GBinSymbol *symbol; /* Enventuel symbole trouvé */ bool found; /* Bilan de la recherche */ -#define BINARY_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD PYTHON_METHOD_DEF \ ( \ find_symbol_by_label, "$self, label, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Find the symbol with a given label, provided as a string.\n" \ "\n" \ "The result is a pychrysalide.format.BinSymbol instance, or None" \ @@ -618,9 +572,9 @@ static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject ret = PyArg_ParseTuple(args, "s", &label); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - found = g_binary_format_find_symbol_by_label(format, label, &symbol); + found = g_program_format_find_symbol_by_label(format, label, &symbol); if (found) { @@ -651,19 +605,19 @@ static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject * * ******************************************************************************/ -static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args) +static PyObject *py_program_format_find_symbol_at(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ - GBinFormat *format; /* Format de binaire manipulé */ + GProgramFormat *format; /* Format de binaire manipulé */ exe_cv_info_t conv; /* Informations de conversion */ int ret; /* Bilan de lecture des args. */ GBinSymbol *symbol; /* Enventuel symbole trouvé */ bool found; /* Bilan de la recherche */ -#define BINARY_FORMAT_FIND_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_FIND_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \ ( \ find_symbol_at, "$self, addr, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Find the symbol located at a given address, provided as a" \ " pychrysalide.arch.vmpa instance.\n" \ "\n" \ @@ -671,14 +625,14 @@ static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args) " None if no symbol was found." \ ) - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); conv.format = G_IS_EXE_FORMAT(format) ? G_EXE_FORMAT(format) : NULL; ret = PyArg_ParseTuple(args, "O&", convert_to_vmpa_using_executable, &conv); if (!ret) return NULL; - found = g_binary_format_find_symbol_at(format, conv.vmpa, &symbol); + found = g_program_format_find_symbol_at(format, conv.vmpa, &symbol); if (found) { @@ -709,19 +663,19 @@ static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject *args) +static PyObject *py_program_format_find_next_symbol_at(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ - GBinFormat *format; /* Format de binaire manipulé */ + GProgramFormat *format; /* Format de binaire manipulé */ exe_cv_info_t conv; /* Informations de conversion */ int ret; /* Bilan de lecture des args. */ GBinSymbol *symbol; /* Enventuel symbole trouvé */ bool found; /* Bilan de la recherche */ -#define BINARY_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \ ( \ find_next_symbol_at, "$self, addr, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Find the symbol next to the one found at a given address," \ " provided as a pychrysalide.arch.vmpa instance.\n" \ "\n" \ @@ -729,14 +683,14 @@ static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject * " None if no symbol was found." \ ) - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); conv.format = G_IS_EXE_FORMAT(format) ? G_EXE_FORMAT(format) : NULL; ret = PyArg_ParseTuple(args, "O&", convert_to_vmpa_using_executable, &conv); if (!ret) return NULL; - found = g_binary_format_find_next_symbol_at(format, conv.vmpa, &symbol); + found = g_program_format_find_next_symbol_at(format, conv.vmpa, &symbol); if (found) { @@ -767,10 +721,10 @@ static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject * * * ******************************************************************************/ -static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) +static PyObject *py_program_format_resolve_symbol(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ - GBinFormat *format; /* Format de binaire manipulé */ + GProgramFormat *format; /* Format de binaire manipulé */ exe_cv_info_t conv; /* Informations de conversion */ int strict; /* Tolérance acceptée */ int ret; /* Bilan de lecture des args. */ @@ -778,10 +732,10 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) phys_t diff; /* Décalage éventuel mesuré */ bool found; /* Bilan de la recherche */ -#define BINARY_FORMAT_RESOLVE_SYMBOL_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_RESOLVE_SYMBOL_METHOD PYTHON_METHOD_DEF \ ( \ resolve_symbol, "$self, addr, strict, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Search for a position inside a symbol by a given address.\n" \ "\n" \ "The result is a couple of (pychrysalide.format.BinSymbol," \ @@ -793,14 +747,14 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) " always 0 upon success." \ ) - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); conv.format = G_IS_EXE_FORMAT(format) ? G_EXE_FORMAT(format) : NULL; ret = PyArg_ParseTuple(args, "O&p", convert_to_vmpa_using_executable, &conv, &strict); if (!ret) return NULL; - found = g_binary_format_resolve_symbol(format, conv.vmpa, strict, &symbol, &diff); + found = g_program_format_resolve_symbol(format, conv.vmpa, strict, &symbol, &diff); if (found) { @@ -835,27 +789,28 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_get_flags(PyObject *self, void *closure) +static PyObject *py_program_format_get_flags(PyObject *self, void *closure) { PyObject *result; /* Valeur à retourner */ - GBinFormat *format; /* Elément à consulter */ + GProgramFormat *format; /* Elément à consulter */ FormatFlag flags; /* Indications complémentaires */ -#define BINARY_FORMAT_FLAGS_ATTRIB PYTHON_GET_DEF_FULL \ +#define PROGRAM_FORMAT_FLAGS_ATTRIB PYTHON_GET_DEF_FULL \ ( \ - flags, py_binary_format, \ + flags, py_program_format, \ "Provide all the flags set for a format. The return value" \ " is of type pychrysalide.format.BinFormat.FormatFlag." \ ) - format = G_BIN_FORMAT(pygobject_get(self)); - flags = g_binary_format_get_flags(format); + format = G_PROGRAM_FORMAT(pygobject_get(self)); + flags = g_program_format_get_flags(format); - result = cast_with_constants_group_from_type(get_python_binary_format_type(), "FormatFlag", flags); + result = cast_with_constants_group_from_type(get_python_program_format_type(), "FormatFlag", flags); return result; } +#endif /****************************************************************************** @@ -871,29 +826,31 @@ static PyObject *py_binary_format_get_flags(PyObject *self, void *closure) * * ******************************************************************************/ -static PyObject *py_binary_format_get_endianness(PyObject *self, void *closure) +static PyObject *py_program_format_get_endianness(PyObject *self, void *closure) { PyObject *result; /* Valeur à retourner */ - GBinFormat *format; /* Elément à consulter */ + GProgramFormat *format; /* Elément à consulter */ SourceEndian endianness; /* Boutisme du format */ -#define BINARY_FORMAT_ENDIANNESS_ATTRIB PYTHON_GET_DEF_FULL \ +#define PROGRAM_FORMAT_ENDIANNESS_ATTRIB PYTHON_GET_DEF_FULL \ ( \ - endianness, py_binary_format, \ + endianness, py_program_format, \ "Endianness of the format. The return value is of type" \ - " pychrysalide.analysis.BinContent.SourceEndian." \ + " pychrysalide.SourceEndian." \ ) - format = G_BIN_FORMAT(pygobject_get(self)); - endianness = g_binary_format_get_endianness(format); + format = G_PROGRAM_FORMAT(pygobject_get(self)); + endianness = g_program_format_get_endianness(format); - result = cast_with_constants_group_from_type(get_python_binary_content_type(), "SourceEndian", endianness); + result = cast_with_constants_group_from_module("pychrysalide", "SourceEndian", endianness); return result; } +#if 0 + /****************************************************************************** * * * Paramètres : self = classe représentant un format binaire. * @@ -907,15 +864,15 @@ static PyObject *py_binary_format_get_endianness(PyObject *self, void *closure) * * ******************************************************************************/ -static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure) +static PyObject *py_program_format_get_symbols(PyObject *self, void *closure) { PyObject *result; /* Instance Python à retourner */ PyTypeObject *iterator_type; /* Type Python de l'itérateur */ PyObject *args; /* Liste des arguments d'appel */ -#define BINARY_FORMAT_SYMBOLS_ATTRIB PYTHON_GET_DEF_FULL \ +#define PROGRAM_FORMAT_SYMBOLS_ATTRIB PYTHON_GET_DEF_FULL \ ( \ - symbols, py_binary_format, \ + symbols, py_program_format, \ "Iterable list of all symbols found in the binary format.\n" \ "\n" \ "The returned iterator is a pychrysalide.format.SymIterator" \ @@ -935,13 +892,15 @@ static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure) } +#endif + /* ---------------------------------------------------------------------------------- */ /* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */ /* ---------------------------------------------------------------------------------- */ - +#if 0 /****************************************************************************** * * * Paramètres : self = architecture concernée par la procédure. * @@ -955,18 +914,18 @@ static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure) * * ******************************************************************************/ -static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args) +static PyObject *py_program_format_add_error(PyObject *self, PyObject *args) { BinaryFormatError type; /* Type d'erreur détectée */ vmpa2t *addr; /* Position d'une erreur */ const char *desc; /* Description d'une erreur */ int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format binaire manipulé */ + GProgramFormat *format; /* Format binaire manipulé */ -#define BINARY_FORMAT_ADD_ERROR_METHOD PYTHON_METHOD_DEF \ +#define PROGRAM_FORMAT_ADD_ERROR_METHOD PYTHON_METHOD_DEF \ ( \ add_error, "$self, type, addr, desc, /", \ - METH_VARARGS, py_binary_format, \ + METH_VARARGS, py_program_format, \ "Extend the list of detected errors linked to the format.\n" \ "\n" \ "The type of error has to be one of the" \ @@ -976,12 +935,12 @@ static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args) " what has failed." \ ) - ret = PyArg_ParseTuple(args, "O&O&s", convert_to_binary_format_error, &type, convert_any_to_vmpa, &addr, &desc); + ret = PyArg_ParseTuple(args, "O&O&s", convert_to_program_format_error, &type, convert_any_to_vmpa, &addr, &desc); if (!ret) return NULL; - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - g_binary_format_add_error(format, type, addr, desc); + g_program_format_add_error(format, type, addr, desc); clean_vmpa_arg(addr); @@ -1003,10 +962,10 @@ static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args) * * ******************************************************************************/ -static PyObject *py_binary_format_get_errors(PyObject *self, void *closure) +static PyObject *py_program_format_get_errors(PyObject *self, void *closure) { PyObject *result; /* Instance Python à retourner */ - GBinFormat *format; /* Format binaire manipulé */ + GProgramFormat *format; /* Format binaire manipulé */ size_t count; /* Nombre d'éléments à traiter */ size_t i; /* Boucle de parcours */ #ifndef NDEBUG @@ -1018,9 +977,9 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure) PyObject *py_type; /* Version Python du type */ PyObject *error; /* Nouvelle erreur à rajouter */ -#define BINARY_FORMAT_ERRORS_ATTRIB PYTHON_GET_DEF_FULL \ +#define PROGRAM_FORMAT_ERRORS_ATTRIB PYTHON_GET_DEF_FULL \ ( \ - errors, py_binary_format, \ + errors, py_program_format, \ "List of all detected errors which occurred while loading the binary.\n" \ "\n" \ "The result is a tuple of (pychrysalide.format.BinFormat.BinaryFormatError," \ @@ -1028,24 +987,24 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure) " description for each error." \ ) - format = G_BIN_FORMAT(pygobject_get(self)); + format = G_PROGRAM_FORMAT(pygobject_get(self)); - g_binary_format_lock_errors(format); + g_program_format_lock_errors(format); - count = g_binary_format_count_errors(format); + count = g_program_format_count_errors(format); result = PyTuple_New(count); for (i = 0; i < count; i++) { #ifndef NDEBUG - status = g_binary_format_get_error(format, i, &type, &addr, &desc); + status = g_program_format_get_error(format, i, &type, &addr, &desc); assert(status); #else - g_binary_format_get_error(format, i, &type, &addr, &desc); + g_program_format_get_error(format, i, &type, &addr, &desc); #endif - py_type = cast_with_constants_group_from_type(get_python_binary_format_type(), "BinaryFormatError", type); + py_type = cast_with_constants_group_from_type(get_python_program_format_type(), "BinaryFormatError", type); error = Py_BuildValue("OO&s", py_type, build_from_internal_vmpa, &addr, desc); Py_DECREF(py_type); @@ -1053,11 +1012,12 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure) } - g_binary_format_unlock_errors(format); + g_program_format_unlock_errors(format); return result; } +#endif /****************************************************************************** @@ -1072,51 +1032,54 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure) * * ******************************************************************************/ -PyTypeObject *get_python_binary_format_type(void) +PyTypeObject *get_python_program_format_type(void) { - static PyMethodDef py_bin_format_methods[] = { - BINARY_FORMAT_SET_FLAG_METHOD, - BINARY_FORMAT_UNSET_FLAG_METHOD, - BINARY_FORMAT_HAS_FLAG_METHOD, - BINARY_FORMAT_REGISTER_CODE_POINT_METHOD, - BINARY_FORMAT_ADD_SYMBOL_METHOD, - BINARY_FORMAT_REMOVE_SYMBOL_METHOD, - BINARY_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD, - BINARY_FORMAT_FIND_SYMBOL_AT_METHOD, - BINARY_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD, - BINARY_FORMAT_RESOLVE_SYMBOL_METHOD, - BINARY_FORMAT_ADD_ERROR_METHOD, + static PyMethodDef py_program_format_methods[] = { + PROGRAM_FORMAT_GET_ENDIANNESS_WRAPPER, + /* + PROGRAM_FORMAT_SET_FLAG_METHOD, + PROGRAM_FORMAT_UNSET_FLAG_METHOD, + PROGRAM_FORMAT_HAS_FLAG_METHOD, + PROGRAM_FORMAT_REGISTER_CODE_POINT_METHOD, + PROGRAM_FORMAT_ADD_SYMBOL_METHOD, + PROGRAM_FORMAT_REMOVE_SYMBOL_METHOD, + PROGRAM_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD, + PROGRAM_FORMAT_FIND_SYMBOL_AT_METHOD, + PROGRAM_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD, + PROGRAM_FORMAT_RESOLVE_SYMBOL_METHOD, + PROGRAM_FORMAT_ADD_ERROR_METHOD, + */ { NULL } }; - static PyGetSetDef py_bin_format_getseters[] = { - BINARY_FORMAT_FLAGS_ATTRIB, - BINARY_FORMAT_ENDIANNESS_ATTRIB, - BINARY_FORMAT_SYMBOLS_ATTRIB, - BINARY_FORMAT_ERRORS_ATTRIB, + static PyGetSetDef py_program_format_getseters[] = { + //PROGRAM_FORMAT_FLAGS_ATTRIB, + PROGRAM_FORMAT_ENDIANNESS_ATTRIB, + //PROGRAM_FORMAT_SYMBOLS_ATTRIB, + //PROGRAM_FORMAT_ERRORS_ATTRIB, { NULL } }; - static PyTypeObject py_bin_format_type = { + static PyTypeObject py_program_format_type = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pychrysalide.format.BinFormat", + .tp_name = "pychrysalide.format.ProgramFormat", .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, - .tp_doc = BINARY_FORMAT_DOC, + .tp_doc = PROGRAM_FORMAT_DOC, - .tp_methods = py_bin_format_methods, - .tp_getset = py_bin_format_getseters, + .tp_methods = py_program_format_methods, + .tp_getset = py_program_format_getseters, - .tp_init = py_binary_format_init, - .tp_new = py_binary_format_new, + .tp_init = py_program_format_init, + .tp_new = py_program_format_new, }; - return &py_bin_format_type; + return &py_program_format_type; } @@ -1133,13 +1096,13 @@ PyTypeObject *get_python_binary_format_type(void) * * ******************************************************************************/ -bool ensure_python_binary_format_is_registered(void) +bool ensure_python_program_format_is_registered(void) { PyTypeObject *type; /* Type Python 'BinFormat' */ PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ - type = get_python_binary_format_type(); + type = get_python_program_format_type(); if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) { @@ -1150,11 +1113,13 @@ bool ensure_python_binary_format_is_registered(void) if (!ensure_python_known_format_is_registered()) return false; - if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, type)) + if (!register_class_for_pygobject(dict, G_TYPE_PROGRAM_FORMAT, type)) return false; - if (!define_binary_format_constants(type)) + /* + if (!define_program_format_constants(type)) return false; + */ } @@ -1176,11 +1141,11 @@ bool ensure_python_binary_format_is_registered(void) * * ******************************************************************************/ -int convert_to_binary_format(PyObject *arg, void *dst) +int convert_to_program_format(PyObject *arg, void *dst) { int result; /* Bilan à retourner */ - result = PyObject_IsInstance(arg, (PyObject *)get_python_binary_format_type()); + result = PyObject_IsInstance(arg, (PyObject *)get_python_program_format_type()); switch (result) { @@ -1194,7 +1159,7 @@ int convert_to_binary_format(PyObject *arg, void *dst) break; case 1: - *((GBinFormat **)dst) = G_BIN_FORMAT(pygobject_get(arg)); + *((GProgramFormat **)dst) = G_PROGRAM_FORMAT(pygobject_get(arg)); break; default: diff --git a/plugins/pychrysalide/format/program.h b/plugins/pychrysalide/format/program.h index 04ac9e3..647d122 100644 --- a/plugins/pychrysalide/format/program.h +++ b/plugins/pychrysalide/format/program.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format.h - prototypes pour l'équivalent Python du fichier "format/format.h" + * program.h - prototypes pour l'équivalent Python du fichier "format/program.h" * - * Copyright (C) 2018-2020 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -22,8 +22,8 @@ */ -#ifndef _PLUGINS_PYCHRYSALIDE_FORMAT_FORMAT_H -#define _PLUGINS_PYCHRYSALIDE_FORMAT_FORMAT_H +#ifndef _PLUGINS_PYCHRYSALIDE_FORMAT_PROGRAM_H +#define _PLUGINS_PYCHRYSALIDE_FORMAT_PROGRAM_H #include <Python.h> @@ -31,29 +31,18 @@ -/* ------------------------ PARCOURS DE SYMBOLES DE BINAIRES ------------------------ */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_symbol_iterator_type(void); - -/* Prend en charge l'objet 'pychrysalide...BinSymbolIterator'. */ -bool ensure_python_binary_symbol_iterator_is_registered(void); - - - /* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */ /* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_format_type(void); +PyTypeObject *get_python_program_format_type(void); -/* Prend en charge l'objet 'pychrysalide.format.BinFormat'. */ -bool ensure_python_binary_format_is_registered(void); +/* Prend en charge l'objet 'pychrysalide.format.ProgramFormat'. */ +bool ensure_python_program_format_is_registered(void); /* Tente de convertir en format de binaire. */ -int convert_to_binary_format(PyObject *, void *); +int convert_to_program_format(PyObject *, void *); -#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_FORMAT_H */ +#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_PROGRAM_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 54a9d0c..933af30 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,18 +39,18 @@ GUI_SUBDIR = \ endif -libchrysacore_la_LIBADD = \ - analysis/libanalysis.la \ - arch/libarch.la \ - common/libcommon.la \ - core/libcore.la \ - debug/libdebug.la \ - format/libformat.la \ - glibext/libglibext.la \ - $(GTKEXT_LIBADD) \ - $(GUI_LIBADD) \ - mangling/libmangling.la \ - plugins/libplugins.la +# libchrysacore_la_LIBADD = \ +# analysis/libanalysis.la \ +# arch/libarch.la \ +# common/libcommon.la \ +# core/libcore.la \ +# debug/libdebug.la \ +# format/libformat.la \ +# glibext/libglibext.la \ +# $(GTKEXT_LIBADD) \ +# $(GUI_LIBADD) \ +# mangling/libmangling.la \ +# plugins/libplugins.la # -ldl: dladdr(), dlerror() @@ -81,6 +81,7 @@ libchrysacore4_la_LIBADD = \ arch/libarch4.la \ common/libcommon4.la \ core/libcore4.la \ + format/libformat.la \ glibext/libglibext4.la \ plugins/libplugins.la @@ -187,4 +188,4 @@ rost_LDFLAGS = $(LIBGOBJ_LIBS) -L.libs -lchrysacore #SUBDIRS = core glibext $(GTKEXT_SUBDIR) analysis arch format common debug $(GUI_SUBDIR) mangling plugins schemas -SUBDIRS = analysis arch common core glibext gtkext gui plugins +SUBDIRS = analysis arch common core format glibext gtkext gui plugins diff --git a/src/format/Makefile.am b/src/format/Makefile.am index dcd3567..3ffe24e 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -1,18 +1,9 @@ noinst_LTLIBRARIES = libformat.la -libformat_la_SOURCES = -# \ # debuggable-int.h \ # debuggable.h debuggable.c \ -# executable-int.h executable-int.c \ -# executable.h executable.c \ -# flat-int.h \ -# flat.h flat.c \ -# program-int.h \ -# program.h program.c \ -# known-int.h \ -# known.h known.c \ +# executable-int.c \ # preload-int.h \ # preload.h preload.c \ # strsym.h strsym.c \ @@ -20,6 +11,16 @@ libformat_la_SOURCES = # symbol-int.h \ # symbol.h symbol.c +libformat_la_SOURCES = \ + executable-int.h \ + executable.h executable.c \ + flat-int.h \ + flat.h flat.c \ + known-int.h \ + known.h known.c \ + program-int.h \ + program.h program.c + libformat_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) diff --git a/src/format/executable-int.h b/src/format/executable-int.h index 8722795..73b647c 100644 --- a/src/format/executable-int.h +++ b/src/format/executable-int.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * executable-int.h - prototypes de code utile aux formats d'exécutables * - * Copyright (C) 2009-2019 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -28,34 +28,38 @@ #include "executable.h" -#include "format-int.h" +#include "program-int.h" /* Indique le type d'architecture visée par le format. */ -typedef const char * (* get_target_machine_fc) (const GExeFormat *); +typedef char * (* get_target_machine_fc) (const GExecutableFormat *); +#if 0 /* Fournit l'adresse principale associée à un format. */ -typedef bool (* get_main_addr_fc) (GExeFormat *, vmpa2t *); +typedef bool (* get_main_addr_fc) (GExecutableFormat *, vmpa2t *); /* Etend la définition des portions au sein d'un binaire. */ -typedef void (* refine_portions_fc) (GExeFormat *); +typedef void (* refine_portions_fc) (GExecutableFormat *); /* Fournit l'emplacement correspondant à une position physique. */ -typedef bool (* translate_phys_fc) (GExeFormat *, phys_t, vmpa2t *); +typedef bool (* translate_phys_fc) (GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -typedef bool (* translate_virt_fc) (GExeFormat *, virt_t, vmpa2t *); +typedef bool (* translate_virt_fc) (GExecutableFormat *, virt_t, vmpa2t *); /* Fournit l'emplacement d'une section donnée. */ -typedef bool (* get_range_by_name_fc) (const GExeFormat *, const char *, mrange_t *); +typedef bool (* get_range_by_name_fc) (const GExecutableFormat *, const char *, mrange_t *); +#endif /* Format d'exécutable générique (instance) */ -struct _GExeFormat +struct _GExecutableFormat { - GBinFormat parent; /* A laisser en premier */ + GProgramFormat parent; /* A laisser en premier */ + +#if 0 GDbgFormat **debugs; /* Informations de débogage */ size_t debugs_count; /* Nombre de ces informations */ @@ -65,42 +69,52 @@ struct _GExeFormat GBinPortion *portions; /* Couches de morceaux binaires*/ GMutex mutex; /* Accès à l'arborescence */ +#endif + }; /* Format d'exécutable générique (classe) */ -struct _GExeFormatClass +struct _GExecutableFormatClass { - GBinFormatClass parent; /* A laisser en premier */ + GProgramFormatClass parent; /* A laisser en premier */ get_target_machine_fc get_machine; /* Architecture ciblée */ + +#if 0 get_main_addr_fc get_main_addr; /* Obtention d'adresse première*/ refine_portions_fc refine_portions; /* Décrit les portions binaires*/ translate_phys_fc translate_phys; /* Correspondance phys -> vmpa */ translate_virt_fc translate_virt; /* Correspondance virt -> vmpa */ - get_range_by_name_fc get_range_by_name; /* Emplacement de sections */ + get_range_by_name_fc get_range_by_name; /* Emplacement de sections */ + +#endif }; +#if 0 + /* Crée les portions potentiellement utiles aux traductions. */ -void g_executable_format_setup_portions(GExeFormat *, GtkStatusStack *); +void g_executable_format_setup_portions(GExecutableFormat *, GtkStatusStack *); /* Effectue les ultimes opérations de chargement d'un binaire. */ -bool g_executable_format_complete_loading(GExeFormat *, wgroup_id_t, GtkStatusStack *); +bool g_executable_format_complete_loading(GExecutableFormat *, wgroup_id_t, GtkStatusStack *); /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_without_virt_translate_offset_into_vmpa(const GExeFormat *, phys_t, vmpa2t *); +bool g_exe_format_without_virt_translate_offset_into_vmpa(const GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -bool g_exe_format_without_virt_translate_address_into_vmpa(const GExeFormat *, virt_t, vmpa2t *); +bool g_exe_format_without_virt_translate_address_into_vmpa(const GExecutableFormat *, virt_t, vmpa2t *); /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_offset_into_vmpa_using_portions(GExeFormat *, phys_t, vmpa2t *); +bool g_exe_format_translate_offset_into_vmpa_using_portions(GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une adresse virtuelle. */ -bool g_exe_format_translate_address_into_vmpa_using_portions(GExeFormat *, virt_t, vmpa2t *); +bool g_exe_format_translate_address_into_vmpa_using_portions(GExecutableFormat *, virt_t, vmpa2t *); + +#endif diff --git a/src/format/executable.c b/src/format/executable.c index 26c418e..187bd4e 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -25,6 +25,7 @@ #include <assert.h> +/* #include <malloc.h> #include <stdio.h> #include <stdlib.h> @@ -32,30 +33,31 @@ #include <i18n.h> - +*/ #include "executable-int.h" +/* #include "format.h" #include "../core/logs.h" #include "../plugins/pglist.h" - +*/ /* Initialise la classe des formats d'exécutables génériques. */ -static void g_executable_format_class_init(GExeFormatClass *); +static void g_executable_format_class_init(GExecutableFormatClass *); /* Initialise une instance de format d'exécutable générique. */ -static void g_executable_format_init(GExeFormat *); +static void g_executable_format_init(GExecutableFormat *); /* Supprime toutes les références externes. */ -static void g_executable_format_dispose(GExeFormat *); +static void g_executable_format_dispose(GExecutableFormat *); /* Procède à la libération totale de la mémoire. */ -static void g_executable_format_finalize(GExeFormat *); +static void g_executable_format_finalize(GExecutableFormat *); /* Indique le type défini pour un format d'exécutable générique. */ -G_DEFINE_TYPE(GExeFormat, g_executable_format, G_TYPE_BIN_FORMAT); +G_DEFINE_TYPE(GExecutableFormat, g_executable_format, G_TYPE_PROGRAM_FORMAT); /****************************************************************************** @@ -70,7 +72,7 @@ G_DEFINE_TYPE(GExeFormat, g_executable_format, G_TYPE_BIN_FORMAT); * * ******************************************************************************/ -static void g_executable_format_class_init(GExeFormatClass *klass) +static void g_executable_format_class_init(GExecutableFormatClass *klass) { GObjectClass *object; /* Autre version de la classe */ @@ -94,9 +96,9 @@ static void g_executable_format_class_init(GExeFormatClass *klass) * * ******************************************************************************/ -static void g_executable_format_init(GExeFormat *format) +static void g_executable_format_init(GExecutableFormat *format) { - g_mutex_init(&format->mutex); + //g_mutex_init(&format->mutex); } @@ -113,8 +115,10 @@ static void g_executable_format_init(GExeFormat *format) * * ******************************************************************************/ -static void g_executable_format_dispose(GExeFormat *format) +static void g_executable_format_dispose(GExecutableFormat *format) { + +#if 0 size_t i; /* Boucle de parcours */ for (i = 0; i < format->debugs_count; i++) @@ -127,6 +131,10 @@ static void g_executable_format_dispose(GExeFormat *format) g_mutex_clear(&format->mutex); +#endif + + + G_OBJECT_CLASS(g_executable_format_parent_class)->dispose(G_OBJECT(format)); } @@ -144,19 +152,28 @@ static void g_executable_format_dispose(GExeFormat *format) * * ******************************************************************************/ -static void g_executable_format_finalize(GExeFormat *format) +static void g_executable_format_finalize(GExecutableFormat *format) { +#if 0 + if (format->debugs != NULL) free(format->debugs); if (format->user_portions != NULL) free(format->user_portions); +#endif + + + G_OBJECT_CLASS(g_executable_format_parent_class)->finalize(G_OBJECT(format)); } + +#if 0 + /****************************************************************************** * * * Paramètres : format = informations chargées à compléter. * @@ -170,7 +187,7 @@ static void g_executable_format_finalize(GExeFormat *format) * * ******************************************************************************/ -void g_exe_format_add_debug_info(GExeFormat *format, GDbgFormat *info) +void g_executable_format_add_debug_info(GExecutableFormat *format, GDbgFormat *info) { const char *desc; /* Description humaine associée*/ @@ -200,7 +217,7 @@ void g_exe_format_add_debug_info(GExeFormat *format, GDbgFormat *info) * * ******************************************************************************/ -size_t g_exe_format_count_debug_info(const GExeFormat *format) +size_t g_executable_format_count_debug_info(const GExecutableFormat *format) { return format->debugs_count; @@ -220,7 +237,7 @@ size_t g_exe_format_count_debug_info(const GExeFormat *format) * * ******************************************************************************/ -GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *format, size_t index) +GDbgFormat *g_executable_format_get_debug_info(const GExecutableFormat *format, size_t index) { GDbgFormat *result; /* Format à retourner */ @@ -237,10 +254,12 @@ GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *format, size_t index) } +#endif + /****************************************************************************** * * -* Paramètres : format = informations chargées à consulter. * +* Paramètres : format = description du format exécutable à consulter. * * * * Description : Indique le type d'architecture visée par le format. * * * @@ -250,13 +269,24 @@ GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *format, size_t index) * * ******************************************************************************/ -const char *g_exe_format_get_target_machine(const GExeFormat *format) +char *g_executable_format_get_target_machine(const GExecutableFormat *format) { - return G_EXE_FORMAT_GET_CLASS(format)->get_machine(format); + char *result; /* Désignation à retourner */ + GExecutableFormatClass *class; /* Classe de l'instance */ + + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); + + result = class->get_machine(format); + + //assert(result != NULL); + + return result; } +#if 0 + /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * @@ -270,15 +300,15 @@ const char *g_exe_format_get_target_machine(const GExeFormat *format) * * ******************************************************************************/ -bool g_exe_format_get_main_address(GExeFormat *format, vmpa2t *addr) +bool g_executable_format_get_main_address(GExecutableFormat *format, vmpa2t *addr) { bool result; /* Bilan à retourner */ GBinFormat *base; /* Version d'instance parente */ result = false; - if (G_EXE_FORMAT_GET_CLASS(format)->get_main_addr != NULL) - result = G_EXE_FORMAT_GET_CLASS(format)->get_main_addr(format, addr); + if (G_EXECUTABLE_FORMAT_GET_CLASS(format)->get_main_addr != NULL) + result = G_EXECUTABLE_FORMAT_GET_CLASS(format)->get_main_addr(format, addr); if (!result) { @@ -287,7 +317,7 @@ bool g_exe_format_get_main_address(GExeFormat *format, vmpa2t *addr) g_rw_lock_reader_lock(&base->pt_lock); if (base->pt_count[DPL_ENTRY_POINT] > 0) - result = g_exe_format_translate_address_into_vmpa(format, base->start_points[DPL_ENTRY_POINT][0], addr); + result = g_executable_format_translate_address_into_vmpa(format, base->start_points[DPL_ENTRY_POINT][0], addr); g_rw_lock_reader_unlock(&base->pt_lock); @@ -311,11 +341,11 @@ bool g_exe_format_get_main_address(GExeFormat *format, vmpa2t *addr) * * ******************************************************************************/ -void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *status) +void g_executable_format_setup_portions(GExecutableFormat *format, GtkStatusStack *status) { vmpa2t addr; /* Emplacement vide de sens */ phys_t length; /* Taille de portion globale */ - GExeFormatClass *class; /* Classe de l'instance */ + GExecutableFormatClass *class; /* Classe de l'instance */ size_t i; /* Boucle de parcours */ /** @@ -327,7 +357,7 @@ void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *stat format->portions = g_binary_portion_new(BPC_RAW, &addr, length); - class = G_EXE_FORMAT_GET_CLASS(format); + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); if (class->refine_portions != NULL) class->refine_portions(format); @@ -335,7 +365,7 @@ void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *stat for (i = 0; i < format->user_count; i++) { g_object_ref(G_OBJECT(format->user_portions[i])); - g_exe_format_include_portion(format, format->user_portions[i], NULL); + g_executable_format_include_portion(format, format->user_portions[i], NULL); } } @@ -355,7 +385,7 @@ void g_executable_format_setup_portions(GExeFormat *format, GtkStatusStack *stat * * ******************************************************************************/ -bool g_executable_format_complete_loading(GExeFormat *format, wgroup_id_t gid, GtkStatusStack *status) +bool g_executable_format_complete_loading(GExecutableFormat *format, wgroup_id_t gid, GtkStatusStack *status) { bool result; /* Bilan à faire remonter */ size_t count; /* Qté d'infos supplémentaires */ @@ -366,11 +396,11 @@ bool g_executable_format_complete_loading(GExeFormat *format, wgroup_id_t gid, G attach_debug_format(format); - count = g_exe_format_count_debug_info(format); + count = g_executable_format_count_debug_info(format); for (i = 0; i < count && result; i++) { - dbg = g_exe_format_get_debug_info(format, i); + dbg = g_executable_format_get_debug_info(format, i); result = g_known_format_analyze(G_KNOWN_FORMAT(dbg), gid, status); @@ -396,7 +426,7 @@ bool g_executable_format_complete_loading(GExeFormat *format, wgroup_id_t gid, G * * ******************************************************************************/ -void g_exe_format_register_user_portion(GExeFormat *format, GBinPortion *portion) +void g_executable_format_register_user_portion(GExecutableFormat *format, GBinPortion *portion) { g_mutex_lock(&format->mutex); @@ -423,7 +453,7 @@ void g_exe_format_register_user_portion(GExeFormat *format, GBinPortion *portion * * ******************************************************************************/ -void g_exe_format_include_portion(GExeFormat *format, GBinPortion *portion, const vmpa2t *origin) +void g_executable_format_include_portion(GExecutableFormat *format, GBinPortion *portion, const vmpa2t *origin) { phys_t available; /* Taille totale du bianire */ const mrange_t *range; /* Emplacement de la portion */ @@ -501,7 +531,7 @@ void g_exe_format_include_portion(GExeFormat *format, GBinPortion *portion, cons * * ******************************************************************************/ -GBinPortion *g_exe_format_get_portions(GExeFormat *format) +GBinPortion *g_executable_format_get_portions(GExecutableFormat *format) { GBinPortion *result; /* Instance à retourner */ @@ -533,11 +563,11 @@ GBinPortion *g_exe_format_get_portions(GExeFormat *format) * * ******************************************************************************/ -bool g_exe_format_translate_offset_into_vmpa(GExeFormat *format, phys_t off, vmpa2t *pos) +bool g_executable_format_translate_offset_into_vmpa(GExecutableFormat *format, phys_t off, vmpa2t *pos) { bool result; /* Bilan à retourner */ - result = G_EXE_FORMAT_GET_CLASS(format)->translate_phys(format, off, pos); + result = G_EXECUTABLE_FORMAT_GET_CLASS(format)->translate_phys(format, off, pos); return result; @@ -558,11 +588,11 @@ bool g_exe_format_translate_offset_into_vmpa(GExeFormat *format, phys_t off, vmp * * ******************************************************************************/ -bool g_exe_format_translate_address_into_vmpa(GExeFormat *format, virt_t addr, vmpa2t *pos) +bool g_executable_format_translate_address_into_vmpa(GExecutableFormat *format, virt_t addr, vmpa2t *pos) { bool result; /* Bilan à retourner */ - result = G_EXE_FORMAT_GET_CLASS(format)->translate_virt(format, addr, pos); + result = G_EXECUTABLE_FORMAT_GET_CLASS(format)->translate_virt(format, addr, pos); return result; @@ -583,12 +613,12 @@ bool g_exe_format_translate_address_into_vmpa(GExeFormat *format, virt_t addr, v * * ******************************************************************************/ -bool g_exe_format_get_section_range_by_name(const GExeFormat *format, const char *name, mrange_t *range) +bool g_executable_format_get_section_range_by_name(const GExecutableFormat *format, const char *name, mrange_t *range) { bool result; /* Bilan à retourner */ - GExeFormatClass *class; /* Classe de l'instance */ + GExecutableFormatClass *class; /* Classe de l'instance */ - class = G_EXE_FORMAT_GET_CLASS(format); + class = G_EXECUTABLE_FORMAT_GET_CLASS(format); if (class->get_range_by_name == NULL) result = false; @@ -599,3 +629,5 @@ bool g_exe_format_get_section_range_by_name(const GExeFormat *format, const char return result; } + +#endif diff --git a/src/format/executable.h b/src/format/executable.h index 4f5abc7..6695b92 100644 --- a/src/format/executable.h +++ b/src/format/executable.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * executable.h - prototypes pour le support des formats d'exécutables * - * Copyright (C) 2009-2019 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -25,87 +25,89 @@ #define _FORMAT_EXECUTABLE_H -#include <glib-object.h> +#include "../glibext/helpers.h" -#include "debuggable.h" -#include "../glibext/gbinportion.h" +#define G_TYPE_EXECUTABLE_FORMAT (g_executable_format_get_type()) + +DECLARE_GTYPE(GExecutableFormat, g_executable_format, G, EXECUTABLE_FORMAT); -#define G_TYPE_EXE_FORMAT g_executable_format_get_type() -#define G_EXE_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_EXE_FORMAT, GExeFormat)) -#define G_IS_EXE_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_EXE_FORMAT)) -#define G_EXE_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_EXE_FORMAT, GExeFormatClass)) -#define G_IS_EXE_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_EXE_FORMAT)) -#define G_EXE_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_EXE_FORMAT, GExeFormatClass)) +/* Indique le type d'architecture visée par le format. */ +char *g_executable_format_get_target_machine(const GExecutableFormat *); + -/* Format d'exécutable générique (instance) */ -typedef struct _GExeFormat GExeFormat; -/* Format d'exécutable générique (classe) */ -typedef struct _GExeFormatClass GExeFormatClass; + +#if 0 + + +/* +#include "debuggable.h" +#include "../glibext/gbinportion.h" +*/ -/* Indique le type défini pour un format d'exécutable générique. */ -GType g_executable_format_get_type(void); /* Rajoute des informations de débogage à un exécutable. */ -void g_exe_format_add_debug_info(GExeFormat *, GDbgFormat *); +void g_executable_format_add_debug_info(GExecutableFormat *, GDbgFormat *); /* Compte le nombre de formats de débogage liés à l'exécutable. */ -size_t g_exe_format_count_debug_info(const GExeFormat *); +size_t g_executable_format_count_debug_info(const GExecutableFormat *); /* Fournit un format de débogage attaché à l'exécutable. */ -GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *, size_t); +GDbgFormat *g_executable_format_get_debug_info(const GExecutableFormat *, size_t); /* Indique le type d'architecture visée par le format. */ -const char *g_exe_format_get_target_machine(const GExeFormat *); +//const char *g_executable_format_get_target_machine(const GExecutableFormat *); /* Fournit l'adresse principale associée à un format. */ -bool g_exe_format_get_main_address(GExeFormat *, vmpa2t *); +bool g_executable_format_get_main_address(GExecutableFormat *, vmpa2t *); /* Enregistre une portion artificielle pour le format. */ -void g_exe_format_register_user_portion(GExeFormat *, GBinPortion *); +void g_executable_format_register_user_portion(GExecutableFormat *, GBinPortion *); /* Procède à l'enregistrement d'une portion dans un format. */ -void g_exe_format_include_portion(GExeFormat *, GBinPortion *, const vmpa2t *); +void g_executable_format_include_portion(GExecutableFormat *, GBinPortion *, const vmpa2t *); /* Fournit la première couche des portions composent le binaire. */ -GBinPortion *g_exe_format_get_portions(GExeFormat *); +GBinPortion *g_executable_format_get_portions(GExecutableFormat *); /* Fournit les espaces mémoires des portions exécutables. */ -mrange_t *g_exe_format_get_x_ranges(GExeFormat *, size_t *); +mrange_t *g_executable_format_get_x_ranges(GExecutableFormat *, size_t *); /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_offset_into_vmpa(GExeFormat *, phys_t, vmpa2t *); +bool g_executable_format_translate_offset_into_vmpa(GExecutableFormat *, phys_t, vmpa2t *); /* Fournit l'emplacement correspondant à une position physique. */ -bool g_exe_format_translate_address_into_vmpa(GExeFormat *, virt_t, vmpa2t *); +bool g_executable_format_translate_address_into_vmpa(GExecutableFormat *, virt_t, vmpa2t *); -#define g_exe_format_translate_offset_into_address(fmt, off, addr) \ +#define g_executable_format_translate_offset_into_address(fmt, off, addr) \ ({ \ bool __result; \ vmpa2t __pos; \ - __result = g_exe_format_translate_offset_into_vmpa(fmt, off, &__pos); \ + __result = g_executable_format_translate_offset_into_vmpa(fmt, off, &__pos); \ *addr = get_virt_addr(&__pos); \ __result; \ }) -#define g_exe_format_translate_address_into_offset(fmt, addr, off) \ +#define g_executable_format_translate_address_into_offset(fmt, addr, off) \ ({ \ bool __result; \ vmpa2t __pos; \ - __result = g_exe_format_translate_address_into_vmpa(fmt, addr, &__pos); \ + __result = g_executable_format_translate_address_into_vmpa(fmt, addr, &__pos); \ *off = get_phy_addr(&__pos); \ __result; \ }) /* Fournit l'emplacement d'une section donnée. */ -bool g_exe_format_get_section_range_by_name(const GExeFormat *, const char *, mrange_t *); +bool g_executable_format_get_section_range_by_name(const GExecutableFormat *, const char *, mrange_t *); + +#endif diff --git a/src/format/flat-int.h b/src/format/flat-int.h index d785e5f..2630ef9 100644 --- a/src/format/flat-int.h +++ b/src/format/flat-int.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat-int.h - prototypes de code utile aux formats d'exécutables à plat * - * Copyright (C) 2018 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -35,7 +35,7 @@ /* Format d'exécutable à plat (instance) */ struct _GFlatFormat { - GExeFormat parent; /* A laisser en premier */ + GExecutableFormat parent; /* A laisser en premier */ char *machine; /* Architecture imposée */ SourceEndian endian; /* Boutisme imposé */ @@ -45,10 +45,14 @@ struct _GFlatFormat /* Format d'exécutable à plat (classe) */ struct _GFlatFormatClass { - GExeFormatClass parent; /* A laisser en premier */ + GExecutableFormatClass parent; /* A laisser en premier */ }; +/* Met en place une nouvelle instance de format de à plat. */ +bool g_flat_format_create(GFlatFormat *, GBinContent *, const char *, SourceEndian); + + #endif /* _FORMAT_FLAT_INT_H */ diff --git a/src/format/flat.c b/src/format/flat.c index 6b8b074..26dd22b 100644 --- a/src/format/flat.c +++ b/src/format/flat.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat.c - support des formats à plat * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -32,6 +32,9 @@ +/* ------------------------- DEFINITION D'UN NOUVEAU FORMAT ------------------------- */ + + /* Initialise la classe des formats d'exécutables à plat. */ static void g_flat_format_class_init(GFlatFormatClass *); @@ -44,28 +47,47 @@ static void g_flat_format_dispose(GFlatFormat *); /* Procède à la libération totale de la mémoire. */ static void g_flat_format_finalize(GFlatFormat *); + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + /* Indique la désignation interne du format. */ static char *g_flat_format_get_key(const GFlatFormat *); /* Fournit une description humaine du format. */ static char *g_flat_format_get_description(const GFlatFormat *); + +#if 0 + /* Assure l'interprétation d'un format en différé. */ static bool g_flat_format_analyze(GFlatFormat *, wgroup_id_t, GtkStatusStack *); +#endif + /* Informe quant au boutisme utilisé. */ static SourceEndian g_flat_format_get_endianness(const GFlatFormat *); /* Indique le type d'architecture visée par le format. */ -static const char *g_flat_format_get_target_machine(const GFlatFormat *); +static char *g_flat_format_get_target_machine(const GFlatFormat *); + +#if 0 /* Fournit l'adresse principale associée à un format à plat. */ static bool g_flat_format_get_main_address(GFlatFormat *, vmpa2t *); +#endif + + + +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION D'UN NOUVEAU FORMAT */ +/* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour un format d'exécutable à plat. */ -G_DEFINE_TYPE(GFlatFormat, g_flat_format, G_TYPE_EXE_FORMAT); +G_DEFINE_TYPE(GFlatFormat, g_flat_format, G_TYPE_EXECUTABLE_FORMAT); /****************************************************************************** @@ -84,8 +106,8 @@ static void g_flat_format_class_init(GFlatFormatClass *klass) { GObjectClass *object; /* Autre version de la classe */ GKnownFormatClass *known; /* Version de format connu */ - GBinFormatClass *fmt; /* Version en format basique */ - GExeFormatClass *exe; /* Version en exécutable */ + GProgramFormatClass *prgm; /* Version en format basique */ + GExecutableFormatClass *exe; /* Version en exécutable */ object = G_OBJECT_CLASS(klass); @@ -97,20 +119,29 @@ static void g_flat_format_class_init(GFlatFormatClass *klass) known->get_key = (known_get_key_fc)g_flat_format_get_key; known->get_desc = (known_get_desc_fc)g_flat_format_get_description; + + +#if 0 + known->analyze = (known_analyze_fc)g_flat_format_analyze; - fmt = G_BIN_FORMAT_CLASS(klass); +#endif + + prgm = G_PROGRAM_FORMAT_CLASS(klass); - fmt->get_endian = (format_get_endian_fc)g_flat_format_get_endianness; + prgm->get_endian = (program_get_endian_fc)g_flat_format_get_endianness; - exe = G_EXE_FORMAT_CLASS(klass); + exe = G_EXECUTABLE_FORMAT_CLASS(klass); exe->get_machine = (get_target_machine_fc)g_flat_format_get_target_machine; +#if 0 exe->get_main_addr = (get_main_addr_fc)g_flat_format_get_main_address; exe->translate_phys = (translate_phys_fc)g_exe_format_translate_offset_into_vmpa_using_portions; exe->translate_virt = (translate_virt_fc)g_exe_format_translate_address_into_vmpa_using_portions; +#endif + } @@ -178,8 +209,10 @@ static void g_flat_format_finalize(GFlatFormat *format) /****************************************************************************** * * * Paramètres : content = contenu binaire à parcourir. * +* machine = architecture déterminée pour le code. * + endian = boutisme à observer pour les données. * * * -* Description : Prend en charge un nouveau format à plat. * +* Description : Crée une nouvelle instance de format à plat. * * * * Retour : Adresse de la structure mise en place ou NULL en cas d'échec.* * * @@ -187,22 +220,53 @@ static void g_flat_format_finalize(GFlatFormat *format) * * ******************************************************************************/ -GExeFormat *g_flat_format_new(GBinContent *content, const char *machine, SourceEndian endian) +GFlatFormat *g_flat_format_new(GBinContent *content, const char *machine, SourceEndian endian) { GFlatFormat *result; /* Structure à retourner */ result = g_object_new(G_TYPE_FLAT_FORMAT, NULL); - g_known_format_set_content(G_KNOWN_FORMAT(result), content); + if (!g_flat_format_create(result, content, machine, endian)) + g_clear_object(&result); - result->machine = strdup(machine); - result->endian = endian; + return result; - return G_EXE_FORMAT(result); +} + + +/****************************************************************************** +* * +* Paramètres : format = description du format connu à consulter. * +* content = contenu binaire à parcourir. * +* * +* Description : Met en place une nouvelle instance de format de à plat. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_flat_format_create(GFlatFormat *format, GBinContent *content, const char *machine, SourceEndian endian) +{ + bool result; /* Bilan à retourner */ + + result = g_known_format_create(G_KNOWN_FORMAT(format), content); + + format->machine = strdup(machine); + format->endian = endian; + + return result; } + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * @@ -249,6 +313,10 @@ static char *g_flat_format_get_description(const GFlatFormat *format) } + + +#if 0 + /****************************************************************************** * * * Paramètres : format = format chargé dont l'analyse est lancée. * @@ -269,12 +337,14 @@ static bool g_flat_format_analyze(GFlatFormat *format, wgroup_id_t gid, GtkStatu result = true; - g_executable_format_setup_portions(G_EXE_FORMAT(format), status); + g_executable_format_setup_portions(G_EXECUTABLE_FORMAT(format), status); return result; } +#endif + /****************************************************************************** * * @@ -290,14 +360,18 @@ static bool g_flat_format_analyze(GFlatFormat *format, wgroup_id_t gid, GtkStatu static SourceEndian g_flat_format_get_endianness(const GFlatFormat *format) { - return format->endian; + SourceEndian result; /* Valeur à retourner */ + + result = format->endian; + + return result; } /****************************************************************************** * * -* Paramètres : format = informations chargées à consulter. * +* Paramètres : format = description du format exécutable à consulter. * * * * Description : Indique le type d'architecture visée par le format. * * * @@ -307,17 +381,17 @@ static SourceEndian g_flat_format_get_endianness(const GFlatFormat *format) * * ******************************************************************************/ -static const char *g_flat_format_get_target_machine(const GFlatFormat *format) +static char *g_flat_format_get_target_machine(const GFlatFormat *format) { - const char *result; /* Identifiant à retourner */ + char *result; /* Identifiant à retourner */ - result = format->machine; + result = strdup(format->machine); return result; } - +#if 0 /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * @@ -350,3 +424,5 @@ static bool g_flat_format_get_main_address(GFlatFormat *format, vmpa2t *addr) return result; } + +#endif diff --git a/src/format/flat.h b/src/format/flat.h index 83c5e3c..2168221 100644 --- a/src/format/flat.h +++ b/src/format/flat.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat.h - prototypes pour le support des formats à plat * - * Copyright (C) 2018 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -25,34 +25,19 @@ #define _FORMAT_FLAT_H -#include <glib-object.h> - - -#include "executable.h" #include "../analysis/content.h" +#include "../glibext/helpers.h" -#define G_TYPE_FLAT_FORMAT g_flat_format_get_type() -#define G_FLAT_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FLAT_FORMAT, GFlatFormat)) -#define G_IS_FLAT_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FLAT_FORMAT)) -#define G_FLAT_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FLAT_FORMAT, GFlatFormatClass)) -#define G_IS_FLAT_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FLAT_FORMAT)) -#define G_FLAT_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_FLAT_FORMAT, GFlatFormatClass)) - - -/* Format d'exécutable à plat (instance) */ -typedef struct _GFlatFormat GFlatFormat; +#define G_TYPE_FLAT_FORMAT (g_flat_format_get_type()) -/* Format d'exécutable à plat (classe) */ -typedef struct _GFlatFormatClass GFlatFormatClass; +DECLARE_GTYPE(GFlatFormat, g_flat_format, G, FLAT_FORMAT); -/* Indique le type défini pour un format d'exécutable à plat. */ -GType g_flat_format_get_type(void); -/* Prend en charge un nouveau format à plat. */ -GExeFormat *g_flat_format_new(GBinContent *, const char *, SourceEndian); +/* Crée une nouvelle instance de format à plat. */ +GFlatFormat *g_flat_format_new(GBinContent *, const char *, SourceEndian); diff --git a/src/format/known-int.h b/src/format/known-int.h index 3328a96..bac0c5c 100644 --- a/src/format/known-int.h +++ b/src/format/known-int.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * known-int.h - prototypes utiles aux formats binaires reconnus * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -26,7 +26,7 @@ #include "known.h" -#include "../analysis/storage/storage.h" +//#include "../analysis/storage/storage.h" @@ -36,6 +36,7 @@ typedef char * (* known_get_key_fc) (const GKnownFormat *); /* Fournit une description humaine du format. */ typedef char * (* known_get_desc_fc) (const GKnownFormat *); +#if 0 /*Assure l'interprétation d'un format en différé. */ typedef bool (* known_analyze_fc) (GKnownFormat *, wgroup_id_t, GtkStatusStack *); @@ -47,6 +48,7 @@ typedef bool (* load_known_fc) (GKnownFormat *, GObjectStorage *, packed_buffer_ /* Sauvegarde un format dans une mémoire tampon. */ typedef bool (* store_known_fc) (GKnownFormat *, GObjectStorage *, packed_buffer_t *); +#endif /* Format binaire générique (instance) */ @@ -66,14 +68,20 @@ struct _GKnownFormatClass known_get_key_fc get_key; /* Désignation interne */ known_get_desc_fc get_desc; /* Désignation humaine */ +#if 0 known_analyze_fc analyze; /* Interprétation du format */ known_complete_analysis_fc complete; /* Terminaison d'analyse */ load_known_fc load; /* Chargement depuis un tampon */ store_known_fc store; /* Conservation dans un tampon */ +#endif }; +/* Met en place un nouveau contenu binaire à analyser. */ +bool g_known_format_create(GKnownFormat *, GBinContent *); + + #endif /* _FORMAT_KNOWN_INT_H */ diff --git a/src/format/known.c b/src/format/known.c index 7512ae1..c32a00b 100644 --- a/src/format/known.c +++ b/src/format/known.c @@ -28,8 +28,8 @@ #include "known-int.h" -#include "../analysis/storage/serialize-int.h" -#include "../plugins/pglist.h" +//#include "../analysis/storage/serialize-int.h" +//#include "../plugins/pglist.h" @@ -43,7 +43,7 @@ static void g_known_format_class_init(GKnownFormatClass *); static void g_known_format_init(GKnownFormat *); /* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_known_format_serializable_init(GSerializableObjectInterface *); +//static void g_known_format_serializable_init(GSerializableObjectInterface *); /* Supprime toutes les références externes. */ static void g_known_format_dispose(GKnownFormat *); @@ -56,6 +56,7 @@ static void g_known_format_finalize(GKnownFormat *); /* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ +#if 0 /* Charge un format depuis une mémoire tampon. */ static bool _g_known_format_load(GKnownFormat *, GObjectStorage *, packed_buffer_t *); @@ -67,7 +68,7 @@ static bool _g_known_format_store(GKnownFormat *, GObjectStorage *, packed_buffe /* Sauvegarde un format dans une mémoire tampon. */ static bool g_known_format_store(GKnownFormat *, GObjectStorage *, packed_buffer_t *); - +#endif /* ---------------------------------------------------------------------------------- */ @@ -76,8 +77,9 @@ static bool g_known_format_store(GKnownFormat *, GObjectStorage *, packed_buffer /* Indique le type défini pour un format binaire générique. */ -G_DEFINE_TYPE_WITH_CODE(GKnownFormat, g_known_format, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_known_format_serializable_init)); +//G_DEFINE_TYPE_WITH_CODE(GKnownFormat, g_known_format, G_TYPE_OBJECT, +// G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_known_format_serializable_init)); +G_DEFINE_TYPE(GKnownFormat, g_known_format, G_TYPE_OBJECT); /****************************************************************************** @@ -101,8 +103,10 @@ static void g_known_format_class_init(GKnownFormatClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_known_format_dispose; object->finalize = (GObjectFinalizeFunc)g_known_format_finalize; + /* klass->load = (load_known_fc)_g_known_format_load; klass->store = (store_known_fc)_g_known_format_store; + */ } @@ -126,6 +130,7 @@ static void g_known_format_init(GKnownFormat *format) } +#if 0 /****************************************************************************** * * * Paramètres : iface = interface GLib à initialiser. * @@ -144,6 +149,7 @@ static void g_known_format_serializable_init(GSerializableObjectInterface *iface iface->store = (store_serializable_object_cb)g_known_format_store; } +#endif /****************************************************************************** @@ -188,24 +194,27 @@ static void g_known_format_finalize(GKnownFormat *format) /****************************************************************************** * * -* Paramètres : format = description du format connu à consulter. * +* Paramètres : format = description du format connu à consulter. * * content = contenu binaire à parcourir. * * * -* Description : Définit le contenu binaire à analyser. * +* Description : Met en place un nouveau contenu binaire à analyser. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -void g_known_format_set_content(GKnownFormat *format, GBinContent *content) +bool g_known_format_create(GKnownFormat *format, GBinContent *content) { - assert(format->content == NULL); + bool result; /* Bilan à retourner */ - g_object_ref_sink(G_OBJECT(content)); + result = true; format->content = content; + ref_object(content); + + return result; } @@ -251,8 +260,13 @@ GBinContent *g_known_format_get_content(const GKnownFormat *format) char *g_known_format_get_key(const GKnownFormat *format) { char *result; /* Désignation à retourner */ + GKnownFormatClass *class; /* Classe de l'instance */ + + class = G_KNOWN_FORMAT_GET_CLASS(format); + + result = class->get_key(format); - result = G_KNOWN_FORMAT_GET_CLASS(format)->get_key(format); + //assert(result != NULL); return result; @@ -274,14 +288,21 @@ char *g_known_format_get_key(const GKnownFormat *format) char *g_known_format_get_description(const GKnownFormat *format) { char *result; /* Description à retourner */ + GKnownFormatClass *class; /* Classe de l'instance */ + + class = G_KNOWN_FORMAT_GET_CLASS(format); - result = G_KNOWN_FORMAT_GET_CLASS(format)->get_desc(format); + result = class->get_desc(format); + + //assert(result != NULL); return result; } +#if 0 + /****************************************************************************** * * * Paramètres : format = format chargé dont l'analyse est lancée. * @@ -343,13 +364,15 @@ void g_known_format_complete_analysis(GKnownFormat *format, wgroup_id_t gid, Gtk } +#endif + /* ---------------------------------------------------------------------------------- */ /* CONSERVATION ET RECHARGEMENT DES DONNEES */ /* ---------------------------------------------------------------------------------- */ - +#if 0 /****************************************************************************** * * * Paramètres : operand = élément GLib à constuire. * @@ -468,3 +491,4 @@ static bool g_known_format_store(GKnownFormat *format, GObjectStorage *storage, return result; } +#endif diff --git a/src/format/known.h b/src/format/known.h index dcc8669..3da433a 100644 --- a/src/format/known.h +++ b/src/format/known.h @@ -25,36 +25,16 @@ #define _FORMAT_KNOWN_H -#include <glib-object.h> -#include <stdbool.h> - - #include "../analysis/content.h" -#include "../glibext/delayed.h" -#include "../glibext/notifier.h" - - +#include "../glibext/helpers.h" -#define G_TYPE_KNOWN_FORMAT g_known_format_get_type() -#define G_KNOWN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_KNOWN_FORMAT, GKnownFormat)) -#define G_IS_KNOWN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_KNOWN_FORMAT)) -#define G_KNOWN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_KNOWN_FORMAT, GKnownFormatClass)) -#define G_IS_KNOWN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_KNOWN_FORMAT)) -#define G_KNOWN_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_KNOWN_FORMAT, GKnownFormatClass)) -/* Format binaire générique (instance) */ -typedef struct _GKnownFormat GKnownFormat; +#define G_TYPE_KNOWN_FORMAT (g_known_format_get_type()) -/* Format binaire générique (classe) */ -typedef struct _GKnownFormatClass GKnownFormatClass; +DECLARE_GTYPE(GKnownFormat, g_known_format, G, KNOWN_FORMAT); -/* Indique le type défini pour un format binaire générique. */ -GType g_known_format_get_type(void); - -/* Définit le contenu binaire à analyser. */ -void g_known_format_set_content(GKnownFormat *, GBinContent *); /* Fournit une référence vers le contenu binaire analysé. */ GBinContent *g_known_format_get_content(const GKnownFormat *); @@ -65,12 +45,16 @@ char *g_known_format_get_key(const GKnownFormat *); /* Fournit une description humaine du format. */ char *g_known_format_get_description(const GKnownFormat *); +#if 0 + /* Assure l'interprétation d'un format en différé. */ bool g_known_format_analyze(GKnownFormat *, wgroup_id_t, GtkStatusStack *); /* Réalise un traitement post-désassemblage. */ void g_known_format_complete_analysis(GKnownFormat *, wgroup_id_t, GtkStatusStack *); +#endif + #endif /* _FORMAT_KNOWN_H */ diff --git a/src/format/program-int.h b/src/format/program-int.h index f18bb24..958c6ff 100644 --- a/src/format/program-int.h +++ b/src/format/program-int.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format-int.h - prototypes utiles aux formats binaires + * program-int.h - prototypes internes pour le support des différents formats de programmes * - * Copyright (C) 2009-2018 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -21,14 +21,53 @@ */ -#ifndef _FORMAT_FORMAT_INT_H -#define _FORMAT_FORMAT_INT_H +#ifndef _FORMAT_PROGRAM_INT_H +#define _FORMAT_PROGRAM_INT_H -#include "format.h" +#include "program.h" #include "known-int.h" + + + +/* Indique le boutisme employé par le format binaire analysé. */ +typedef SourceEndian (* program_get_endian_fc) (const GProgramFormat *); + + +/* Format de programme générique (instance) */ +struct _GProgramFormat +{ + GKnownFormat parent; /* A laisser en premier */ + +}; + +/* Format de programme générique (classe) */ +struct _GProgramFormatClass +{ + GKnownFormatClass parent; /* A laisser en premier */ + + program_get_endian_fc get_endian; /* Boutisme employé */ + +}; + + + + + + + + + + + + + + + +#if 0 + #include "preload.h" #include "../glibext/objhole.h" #include "../mangling/demangler.h" @@ -38,9 +77,6 @@ /* ------------------------ TRAITEMENT INDIVIDUEL DE FORMATS ------------------------ */ -/* Indique le boutisme employé par le format binaire analysé. */ -typedef SourceEndian (* format_get_endian_fc) (const GBinFormat *); - /* Rythme des allocations pour les entrées de code */ #define EXTRA_POINT_BLOCK 20 @@ -120,8 +156,6 @@ struct _GBinFormatClass { GKnownFormatClass parent; /* A laisser en premier */ - format_get_endian_fc get_endian; /* Boutisme employé */ - /* Signaux */ void (* symbol_added) (GBinFormat *, GBinSymbol *); @@ -156,5 +190,8 @@ GDataType *g_binary_format_decode_type(const GBinFormat *, const char *); GBinRoutine *g_binary_format_decode_routine(const GBinFormat *, const char *); +#endif + + -#endif /* _FORMAT_FORMAT_INT_H */ +#endif /* _FORMAT_PROGRAM_INT_H */ diff --git a/src/format/program.c b/src/format/program.c index d126236..3624496 100644 --- a/src/format/program.c +++ b/src/format/program.c @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format.c - support des différents formats binaires + * program.c - support des différents formats de programmes * - * Copyright (C) 2009-2020 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -21,40 +21,45 @@ */ -#include "format.h" +#include "program.h" -#include <assert.h> -#include <malloc.h> -#include <string.h> +//#include <assert.h> +//#include <malloc.h> +//#include <string.h> -#include "format-int.h" +#include "program-int.h" + +/* #include "preload.h" #include "../arch/processor.h" #include "../common/sort.h" #include "../core/demanglers.h" #include "../plugins/pglist.h" +*/ /* Initialise la classe des formats binaires génériques. */ -static void g_binary_format_class_init(GBinFormatClass *); +static void g_program_format_class_init(GProgramFormatClass *); /* Initialise une instance de format binaire générique. */ -static void g_binary_format_init(GBinFormat *); +static void g_program_format_init(GProgramFormat *); /* Supprime toutes les références externes. */ -static void g_binary_format_dispose(GBinFormat *); +static void g_program_format_dispose(GProgramFormat *); /* Procède à la libération totale de la mémoire. */ -static void g_binary_format_finalize(GBinFormat *); +static void g_program_format_finalize(GProgramFormat *); + +#if 0 /* Charge les plages de couvertures depuis une mémoire tampon. */ -static bool g_binary_format_load_start_points(GBinFormat *, packed_buffer_t *); +static bool g_program_format_load_start_points(GProgramFormat *, packed_buffer_t *); /* Sauvegarde les points de départ enregistrés pour un format. */ -static bool g_binary_format_store_start_points(GBinFormat *, packed_buffer_t *); +static bool g_program_format_store_start_points(GProgramFormat *, packed_buffer_t *); @@ -62,13 +67,13 @@ static bool g_binary_format_store_start_points(GBinFormat *, packed_buffer_t *); /* Retire un symbole de la collection du format binaire. */ -static void _g_binary_format_remove_symbol(GBinFormat *, size_t); +static void _g_program_format_remove_symbol(GProgramFormat *, size_t); /* Recherche le symbole associé à une adresse. */ -static bool _g_binary_format_find_symbol(const GBinFormat *, const vmpa2t *, __compar_fn_t, size_t *, GBinSymbol **); +static bool _g_program_format_find_symbol(const GProgramFormat *, const vmpa2t *, __compar_fn_t, size_t *, GBinSymbol **); /* Recherche un symbole particulier. */ -static bool __g_binary_format_find_symbol(const GBinFormat *, const void *, __compar_fn_t, size_t *, GBinSymbol **); +static bool __g_program_format_find_symbol(const GProgramFormat *, const void *, __compar_fn_t, size_t *, GBinSymbol **); @@ -76,10 +81,10 @@ static bool __g_binary_format_find_symbol(const GBinFormat *, const void *, __co /* Charge les erreurs de chargement depuis une mémoire tampon. */ -static bool g_binary_format_load_errors(GBinFormat *, packed_buffer_t *); +static bool g_program_format_load_errors(GProgramFormat *, packed_buffer_t *); /* Sauvegarde les erreurs de chargement dans une mémoire tampon. */ -static bool g_binary_format_store_errors(GBinFormat *, packed_buffer_t *); +static bool g_program_format_store_errors(GProgramFormat *, packed_buffer_t *); @@ -87,17 +92,18 @@ static bool g_binary_format_store_errors(GBinFormat *, packed_buffer_t *); /* Charge un format depuis une mémoire tampon. */ -static bool g_binary_format_load(GBinFormat *, GObjectStorage *, packed_buffer_t *); +static bool g_program_format_load(GProgramFormat *, GObjectStorage *, packed_buffer_t *); /* Sauvegarde un format dans une mémoire tampon. */ -static bool g_binary_format_store(GBinFormat *, GObjectStorage *, packed_buffer_t *); +static bool g_program_format_store(GProgramFormat *, GObjectStorage *, packed_buffer_t *); +#endif /* Indique le type défini pour un format binaire générique. */ -G_DEFINE_TYPE(GBinFormat, g_binary_format, G_TYPE_KNOWN_FORMAT); +G_DEFINE_TYPE(GProgramFormat, g_program_format, G_TYPE_KNOWN_FORMAT); /****************************************************************************** @@ -112,25 +118,27 @@ G_DEFINE_TYPE(GBinFormat, g_binary_format, G_TYPE_KNOWN_FORMAT); * * ******************************************************************************/ -static void g_binary_format_class_init(GBinFormatClass *klass) +static void g_program_format_class_init(GProgramFormatClass *klass) { GObjectClass *object; /* Autre version de la classe */ - GKnownFormatClass *known; /* Version de classe parente */ + //GKnownFormatClass *known; /* Version de classe parente */ object = G_OBJECT_CLASS(klass); - object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_format_dispose; - object->finalize = (GObjectFinalizeFunc)g_binary_format_finalize; + object->dispose = (GObjectFinalizeFunc/* ! */)g_program_format_dispose; + object->finalize = (GObjectFinalizeFunc)g_program_format_finalize; + +#if 0 known = G_KNOWN_FORMAT_CLASS(klass); - known->load = (load_known_fc)g_binary_format_load; - known->store = (load_known_fc)g_binary_format_store; + known->load = (load_known_fc)g_program_format_load; + known->store = (load_known_fc)g_program_format_store; g_signal_new("symbol-added", G_TYPE_BIN_FORMAT, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GBinFormatClass, symbol_added), + G_STRUCT_OFFSET(GProgramFormatClass, symbol_added), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); @@ -138,11 +146,13 @@ static void g_binary_format_class_init(GBinFormatClass *klass) g_signal_new("symbol-removed", G_TYPE_BIN_FORMAT, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GBinFormatClass, symbol_removed), + G_STRUCT_OFFSET(GProgramFormatClass, symbol_removed), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); +#endif + } @@ -158,8 +168,10 @@ static void g_binary_format_class_init(GBinFormatClass *klass) * * ******************************************************************************/ -static void g_binary_format_init(GBinFormat *format) +static void g_program_format_init(GProgramFormat *format) { + +#if 0 fmt_extra_data_t *extra; /* Données insérées à modifier */ extra = GET_BIN_FORMAT_EXTRA(format); @@ -184,6 +196,8 @@ static void g_binary_format_init(GBinFormat *format) g_atomic_int_set(&format->error_locked, 0); #endif +#endif + } @@ -199,8 +213,10 @@ static void g_binary_format_init(GBinFormat *format) * * ******************************************************************************/ -static void g_binary_format_dispose(GBinFormat *format) +static void g_program_format_dispose(GProgramFormat *format) { +#if 0 + size_t i; /* Boucle de parcours */ g_rw_lock_clear(&format->pt_lock); @@ -216,7 +232,10 @@ static void g_binary_format_dispose(GBinFormat *format) g_mutex_clear(&format->error_mutex); - G_OBJECT_CLASS(g_binary_format_parent_class)->dispose(G_OBJECT(format)); +#endif + + + G_OBJECT_CLASS(g_program_format_parent_class)->dispose(G_OBJECT(format)); } @@ -233,8 +252,10 @@ static void g_binary_format_dispose(GBinFormat *format) * * ******************************************************************************/ -static void g_binary_format_finalize(GBinFormat *format) +static void g_program_format_finalize(GProgramFormat *format) { +#if 0 + DisassPriorityLevel i; /* Boucle de parcours #1 */ size_t k; /* Boucle de parcours #2 */ @@ -255,11 +276,21 @@ static void g_binary_format_finalize(GBinFormat *format) } - G_OBJECT_CLASS(g_binary_format_parent_class)->finalize(G_OBJECT(format)); +#endif + + + + G_OBJECT_CLASS(g_program_format_parent_class)->finalize(G_OBJECT(format)); } + + + + +#if 0 + /****************************************************************************** * * * Paramètres : format = format à venir modifier. * @@ -273,7 +304,7 @@ static void g_binary_format_finalize(GBinFormat *format) * * ******************************************************************************/ -bool g_binary_format_set_flag(GBinFormat *format, FormatFlag flag) +bool g_program_format_set_flag(GProgramFormat *format, FormatFlag flag) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -306,7 +337,7 @@ bool g_binary_format_set_flag(GBinFormat *format, FormatFlag flag) * * ******************************************************************************/ -bool g_binary_format_unset_flag(GBinFormat *format, FormatFlag flag) +bool g_program_format_unset_flag(GProgramFormat *format, FormatFlag flag) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -339,7 +370,7 @@ bool g_binary_format_unset_flag(GBinFormat *format, FormatFlag flag) * * ******************************************************************************/ -bool g_binary_format_has_flag(const GBinFormat *format, FormatFlag flag) +bool g_program_format_has_flag(const GProgramFormat *format, FormatFlag flag) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -369,7 +400,7 @@ bool g_binary_format_has_flag(const GBinFormat *format, FormatFlag flag) * * ******************************************************************************/ -FormatFlag g_binary_format_get_flags(const GBinFormat *format) +FormatFlag g_program_format_get_flags(const GProgramFormat *format) { FormatFlag result; /* Fanions à retourner */ fmt_extra_data_t *extra; /* Données insérées à modifier */ @@ -386,6 +417,8 @@ FormatFlag g_binary_format_get_flags(const GBinFormat *format) } +#endif + /****************************************************************************** * * @@ -399,17 +432,22 @@ FormatFlag g_binary_format_get_flags(const GBinFormat *format) * * ******************************************************************************/ -SourceEndian g_binary_format_get_endianness(const GBinFormat *format) +SourceEndian g_program_format_get_endianness(const GProgramFormat *format) { SourceEndian result; /* Boutisme à retourner */ + GProgramFormatClass *class; /* Classe de l'instance */ + + class = G_PROGRAM_FORMAT_GET_CLASS(format); - result = G_BIN_FORMAT_GET_CLASS(format)->get_endian(format); + result = class->get_endian(format); return result; } +#if 0 + /****************************************************************************** * * * Paramètres : format = description de l'exécutable à compléter. * @@ -424,7 +462,7 @@ SourceEndian g_binary_format_get_endianness(const GBinFormat *format) * * ******************************************************************************/ -void g_binary_format_register_code_point(GBinFormat *format, virt_t pt, DisassPriorityLevel level) +void g_program_format_register_code_point(GProgramFormat *format, virt_t pt, DisassPriorityLevel level) { assert(level < DPL_COUNT); @@ -459,7 +497,7 @@ void g_binary_format_register_code_point(GBinFormat *format, virt_t pt, DisassPr * * ******************************************************************************/ -static bool g_binary_format_load_start_points(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_load_start_points(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ DisassPriorityLevel i; /* Boucle de parcours #1 */ @@ -512,7 +550,7 @@ static bool g_binary_format_load_start_points(GBinFormat *format, packed_buffer_ * * ******************************************************************************/ -static bool g_binary_format_store_start_points(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_store_start_points(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ DisassPriorityLevel i; /* Boucle de parcours #1 */ @@ -555,7 +593,7 @@ static bool g_binary_format_store_start_points(GBinFormat *format, packed_buffer * * ******************************************************************************/ -void g_binary_format_preload_disassembling_context(GBinFormat *format, GProcContext *ctx, GtkStatusStack *status) +void g_program_format_preload_disassembling_context(GProgramFormat *format, GProcContext *ctx, GtkStatusStack *status) { g_preload_info_copy(format->info, G_PRELOAD_INFO(ctx)); @@ -576,7 +614,7 @@ void g_binary_format_preload_disassembling_context(GBinFormat *format, GProcCont * * ******************************************************************************/ -void g_binary_format_activate_disassembling_context(GBinFormat *format, GProcContext *ctx, GtkStatusStack *status) +void g_program_format_activate_disassembling_context(GProgramFormat *format, GProcContext *ctx, GtkStatusStack *status) { DisassPriorityLevel i; /* Boucle de parcours #1 */ size_t k; /* Boucle de parcours #2 */ @@ -610,7 +648,7 @@ void g_binary_format_activate_disassembling_context(GBinFormat *format, GProcCon * * ******************************************************************************/ -GCompDemangler *g_binary_format_get_demangler(const GBinFormat *format) +GCompDemangler *g_program_format_get_demangler(const GProgramFormat *format) { GCompDemangler *result; /* Décodeur à retourner */ @@ -637,7 +675,7 @@ GCompDemangler *g_binary_format_get_demangler(const GBinFormat *format) * * ******************************************************************************/ -GDataType *g_binary_format_decode_type(const GBinFormat *format, const char *desc) +GDataType *g_program_format_decode_type(const GProgramFormat *format, const char *desc) { GDataType *result; /* Construction à remonter */ GCompDemangler *demangler; /* Accès plus lisible */ @@ -667,7 +705,7 @@ GDataType *g_binary_format_decode_type(const GBinFormat *format, const char *des * * ******************************************************************************/ -GBinRoutine *g_binary_format_decode_routine(const GBinFormat *format, const char *desc) +GBinRoutine *g_program_format_decode_routine(const GProgramFormat *format, const char *desc) { GBinRoutine *result; /* Construction à remonter */ GCompDemangler *demangler; /* Accès plus lisible */ @@ -708,7 +746,7 @@ GBinRoutine *g_binary_format_decode_routine(const GBinFormat *format, const char * * ******************************************************************************/ -void g_binary_format_lock_unlock_symbols_rd(GBinFormat *format, bool state) +void g_program_format_lock_unlock_symbols_rd(GProgramFormat *format, bool state) { #ifndef NDEBUG gint test; /* Test de valeur courante */ @@ -746,7 +784,7 @@ void g_binary_format_lock_unlock_symbols_rd(GBinFormat *format, bool state) * * ******************************************************************************/ -void g_binary_format_lock_unlock_symbols_wr(GBinFormat *format, bool state) +void g_program_format_lock_unlock_symbols_wr(GProgramFormat *format, bool state) { if (state) { @@ -778,7 +816,7 @@ void g_binary_format_lock_unlock_symbols_wr(GBinFormat *format, bool state) * * ******************************************************************************/ #ifndef NDEBUG -void g_binary_format_check_for_symbols_lock(const GBinFormat *format) +void g_program_format_check_for_symbols_lock(const GProgramFormat *format) { assert(g_atomic_int_get(&format->sym_locked) > 0); @@ -798,7 +836,7 @@ void g_binary_format_check_for_symbols_lock(const GBinFormat *format) * * ******************************************************************************/ -unsigned int g_binary_format_get_symbols_stamp(const GBinFormat *format) +unsigned int g_program_format_get_symbols_stamp(const GProgramFormat *format) { return format->sym_stamp; @@ -817,7 +855,7 @@ unsigned int g_binary_format_get_symbols_stamp(const GBinFormat *format) * * ******************************************************************************/ -size_t g_binary_format_count_symbols(const GBinFormat *format) +size_t g_program_format_count_symbols(const GProgramFormat *format) { assert(g_atomic_int_get(&format->sym_locked) > 0); @@ -839,7 +877,7 @@ size_t g_binary_format_count_symbols(const GBinFormat *format) * * ******************************************************************************/ -GBinSymbol *g_binary_format_get_symbol(const GBinFormat *format, size_t index) +GBinSymbol *g_program_format_get_symbol(const GProgramFormat *format, size_t index) { GBinSymbol *result; /* Symbole à retourner */ @@ -877,7 +915,7 @@ GBinSymbol *g_binary_format_get_symbol(const GBinFormat *format, size_t index) * * ******************************************************************************/ -bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) +bool g_program_format_add_symbol(GProgramFormat *format, GBinSymbol *symbol) { bool result; /* Statut d'ajout à retourner */ #ifndef NDEBUG @@ -887,7 +925,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) size_t index; /* Indice du point d'insertion */ /** - * Pour que les fonctions de recherche basées sur _g_binary_format_find_symbol() + * Pour que les fonctions de recherche basées sur _g_program_format_find_symbol() * fassent bien leur office, il faut que les symboles soient triés. * * Cependant, les localisations à satisfaire lors d'une recherche recontrent @@ -912,7 +950,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) assert(has_phys_addr(addr) || g_binary_symbol_get_status(symbol) == SSS_DYNAMIC); #endif - g_binary_format_lock_unlock_symbols_wr(format, true); + g_program_format_lock_unlock_symbols_wr(format, true); /** * Avec tous les traitements parallèles, il est possible que plusieurs chemins d'exécution @@ -939,7 +977,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) else g_object_unref(G_OBJECT(symbol)); - g_binary_format_lock_unlock_symbols_wr(format, false); + g_program_format_lock_unlock_symbols_wr(format, false); if (result) g_signal_emit_by_name(format, "symbol-added", symbol); @@ -963,7 +1001,7 @@ bool g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) * * ******************************************************************************/ -bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_t count) +bool g_program_format_add_symbols(GProgramFormat *format, GBinSymbol **symbols, size_t count) { bool result; /* Statut d'ajout à retourner */ #ifndef NDEBUG @@ -977,7 +1015,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ size_t index; /* Indice du point d'insertion */ /** - * Pour que les fonctions de recherche basées sur _g_binary_format_find_symbol() + * Pour que les fonctions de recherche basées sur _g_program_format_find_symbol() * fassent bien leur office, il faut que les symboles soient triés. * * Cependant, les localisations à satisfaire lors d'une recherche recontrent @@ -1014,7 +1052,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ } #endif - g_binary_format_lock_unlock_symbols_wr(format, true); + g_program_format_lock_unlock_symbols_wr(format, true); /** * Avec tous les traitements parallèles, il est possible que plusieurs chemins d'exécution @@ -1042,7 +1080,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ } - g_binary_format_lock_unlock_symbols_wr(format, false); + g_program_format_lock_unlock_symbols_wr(format, false); if (result) for (i = 0; i < count; i++) @@ -1066,7 +1104,7 @@ bool g_binary_format_add_symbols(GBinFormat *format, GBinSymbol **symbols, size_ * * ******************************************************************************/ -static void _g_binary_format_remove_symbol(GBinFormat *format, size_t index) +static void _g_program_format_remove_symbol(GProgramFormat *format, size_t index) { assert(g_atomic_int_get(&format->sym_locked) == 1); @@ -1096,22 +1134,22 @@ static void _g_binary_format_remove_symbol(GBinFormat *format, size_t index) * * ******************************************************************************/ -void g_binary_format_remove_symbol(GBinFormat *format, GBinSymbol *symbol) +void g_program_format_remove_symbol(GProgramFormat *format, GBinSymbol *symbol) { bool found; /* Jeton de présence */ size_t index; /* Indice du point de retrait */ g_object_ref(G_OBJECT(symbol)); - g_binary_format_lock_unlock_symbols_wr(format, true); + g_program_format_lock_unlock_symbols_wr(format, true); found = bsearch_index(&symbol, format->symbols, format->sym_count, sizeof(GBinSymbol *), (__compar_fn_t)g_binary_symbol_cmp, &index); if (found) - _g_binary_format_remove_symbol(format, index); + _g_program_format_remove_symbol(format, index); - g_binary_format_lock_unlock_symbols_wr(format, false); + g_program_format_lock_unlock_symbols_wr(format, false); if (found) g_signal_emit_by_name(format, "symbol-removed", symbol); @@ -1135,7 +1173,7 @@ void g_binary_format_remove_symbol(GBinFormat *format, GBinSymbol *symbol) * * ******************************************************************************/ -bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, GBinSymbol **symbol) +bool g_program_format_find_symbol_by_label(GProgramFormat *format, const char *label, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ size_t i; /* Boucle de parcours */ @@ -1143,7 +1181,7 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, result = false; - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); for (i = 0; i < format->sym_count && !result; i++) { @@ -1163,7 +1201,7 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, } - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1186,16 +1224,16 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, * * ******************************************************************************/ -static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t *addr, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) +static bool _g_program_format_find_symbol(const GProgramFormat *format, const vmpa2t *addr, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) { /** * Pour ce qui est des justifications quant à la vérification suivante, - * se référer aux commentaires placés dans g_binary_format_add_symbol(). + * se référer aux commentaires placés dans g_program_format_add_symbol(). */ assert(has_phys_addr(addr)); - return __g_binary_format_find_symbol(format, addr, fn, index, symbol); + return __g_program_format_find_symbol(format, addr, fn, index, symbol); } @@ -1216,7 +1254,7 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t * * ******************************************************************************/ -static bool __g_binary_format_find_symbol(const GBinFormat *format, const void *key, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) +static bool __g_program_format_find_symbol(const GProgramFormat *format, const void *key, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ void *found; /* Résultat de recherches */ @@ -1268,7 +1306,7 @@ static bool __g_binary_format_find_symbol(const GBinFormat *format, const void * * * ******************************************************************************/ -bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr, size_t *index) +bool g_program_format_find_symbol_index_at(GProgramFormat *format, const vmpa2t *addr, size_t *index) { bool result; /* Bilan à retourner */ @@ -1282,11 +1320,11 @@ bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, index, NULL); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, index, NULL); - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1307,7 +1345,7 @@ bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr * * ******************************************************************************/ -bool g_binary_format_find_symbol_at(GBinFormat *format, const vmpa2t *addr, GBinSymbol **symbol) +bool g_program_format_find_symbol_at(GProgramFormat *format, const vmpa2t *addr, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ @@ -1321,11 +1359,11 @@ bool g_binary_format_find_symbol_at(GBinFormat *format, const vmpa2t *addr, GBin } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1346,7 +1384,7 @@ bool g_binary_format_find_symbol_at(GBinFormat *format, const vmpa2t *addr, GBin * * ******************************************************************************/ -bool g_binary_format_find_symbol_for(GBinFormat *format, const vmpa2t *addr, GBinSymbol **symbol) +bool g_program_format_find_symbol_for(GProgramFormat *format, const vmpa2t *addr, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ @@ -1360,11 +1398,11 @@ bool g_binary_format_find_symbol_for(GBinFormat *format, const vmpa2t *addr, GBi } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, NULL, symbol); - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1385,7 +1423,7 @@ bool g_binary_format_find_symbol_for(GBinFormat *format, const vmpa2t *addr, GBi * * ******************************************************************************/ -bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, GBinSymbol **symbol) +bool g_program_format_find_next_symbol_at(GProgramFormat *format, const vmpa2t *addr, GBinSymbol **symbol) { bool result; /* Bilan à retourner */ size_t index; /* Indice à considérer */ @@ -1400,9 +1438,9 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, } - g_binary_format_lock_symbols_rd(format); + g_program_format_lock_symbols_rd(format); - result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, &index, NULL); + result = _g_program_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, &index, NULL); if (result && (index + 1) < format->sym_count) { @@ -1417,7 +1455,7 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, result = false; } - g_binary_format_unlock_symbols_rd(format); + g_program_format_unlock_symbols_rd(format); return result; @@ -1438,7 +1476,7 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, * * ******************************************************************************/ -bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t *range, size_t *index) +bool g_program_format_find_first_symbol_inside(GProgramFormat *format, const mrange_t *range, size_t *index) { bool result; /* Bilan à retourner */ const GBinSymbol *prev; /* Symbole précédent */ @@ -1463,7 +1501,7 @@ bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t g_rw_lock_reader_lock(&format->syms_lock); - result = __g_binary_format_find_symbol(format, range, (__compar_fn_t)find_symbol, index, NULL); + result = __g_program_format_find_symbol(format, range, (__compar_fn_t)find_symbol, index, NULL); if (result) while (*index > 0) @@ -1502,15 +1540,15 @@ bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t * * ******************************************************************************/ -bool g_binary_format_resolve_symbol(GBinFormat *format, const vmpa2t *addr, bool strict, GBinSymbol **symbol, phys_t *diff) +bool g_program_format_resolve_symbol(GProgramFormat *format, const vmpa2t *addr, bool strict, GBinSymbol **symbol, phys_t *diff) { bool result; /* Bilan à retourner */ const mrange_t *range; /* Espace mémoire parcouru */ if (strict) - result = g_binary_format_find_symbol_at(format, addr, symbol); + result = g_program_format_find_symbol_at(format, addr, symbol); else - result = g_binary_format_find_symbol_for(format, addr, symbol); + result = g_program_format_find_symbol_for(format, addr, symbol); if (result) { @@ -1548,7 +1586,7 @@ bool g_binary_format_resolve_symbol(GBinFormat *format, const vmpa2t *addr, bool * * ******************************************************************************/ -void g_binary_format_lock_unlock_errors(GBinFormat *format, bool state) +void g_program_format_lock_unlock_errors(GProgramFormat *format, bool state) { if (state) { @@ -1584,11 +1622,11 @@ void g_binary_format_lock_unlock_errors(GBinFormat *format, bool state) * * ******************************************************************************/ -void g_binary_format_add_error(GBinFormat *format, BinaryFormatError type, const vmpa2t *addr, const char *desc) +void g_program_format_add_error(GProgramFormat *format, BinaryFormatError type, const vmpa2t *addr, const char *desc) { fmt_error *error; /* Raccourci de confort */ - g_binary_format_lock_errors(format); + g_program_format_lock_errors(format); format->errors = realloc(format->errors, ++format->error_count * sizeof(fmt_error)); @@ -1603,7 +1641,7 @@ void g_binary_format_add_error(GBinFormat *format, BinaryFormatError type, const else error->desc = NULL; - g_binary_format_unlock_errors(format); + g_program_format_unlock_errors(format); } @@ -1620,7 +1658,7 @@ void g_binary_format_add_error(GBinFormat *format, BinaryFormatError type, const * * ******************************************************************************/ -size_t g_binary_format_count_errors(GBinFormat *format) +size_t g_program_format_count_errors(GProgramFormat *format) { size_t result; /* Quantité à retourner */ @@ -1649,7 +1687,7 @@ size_t g_binary_format_count_errors(GBinFormat *format) * * ******************************************************************************/ -bool g_binary_format_get_error(GBinFormat *format, size_t index, BinaryFormatError *type, vmpa2t *addr, char **desc) +bool g_program_format_get_error(GProgramFormat *format, size_t index, BinaryFormatError *type, vmpa2t *addr, char **desc) { bool result; /* Bilan à retourner */ fmt_error *error; /* Raccourci de confort */ @@ -1693,7 +1731,7 @@ bool g_binary_format_get_error(GBinFormat *format, size_t index, BinaryFormatErr * * ******************************************************************************/ -static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_load_errors(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ uleb128_t value; /* Valeur ULEB128 à charger */ @@ -1701,7 +1739,7 @@ static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbu fmt_error *error; /* Raccourci de confort */ rle_string str; /* Chaîne à charger */ - g_binary_format_lock_errors(format); + g_program_format_lock_errors(format); result = unpack_uleb128(&value, pbuf); if (!result) goto exit; @@ -1736,7 +1774,7 @@ static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbu exit: - g_binary_format_unlock_errors(format); + g_program_format_unlock_errors(format); return result; @@ -1756,14 +1794,14 @@ static bool g_binary_format_load_errors(GBinFormat *format, packed_buffer_t *pbu * * ******************************************************************************/ -static bool g_binary_format_store_errors(GBinFormat *format, packed_buffer_t *pbuf) +static bool g_program_format_store_errors(GProgramFormat *format, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ size_t i; /* Boucle de parcours */ fmt_error *error; /* Raccourci de confort */ rle_string str; /* Chaîne à conserver */ - g_binary_format_lock_errors(format); + g_program_format_lock_errors(format); result = pack_uleb128((uleb128_t []){ format->error_count }, pbuf); @@ -1785,7 +1823,7 @@ static bool g_binary_format_store_errors(GBinFormat *format, packed_buffer_t *pb } - g_binary_format_unlock_errors(format); + g_program_format_unlock_errors(format); return result; @@ -1812,7 +1850,7 @@ static bool g_binary_format_store_errors(GBinFormat *format, packed_buffer_t *pb * * ******************************************************************************/ -static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) +static bool g_program_format_load(GProgramFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à consulter*/ @@ -1831,7 +1869,7 @@ static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, pa UNLOCK_GOBJECT_EXTRA(extra); if (result) - result = g_binary_format_load_start_points(format, pbuf); + result = g_program_format_load_start_points(format, pbuf); if (result) { @@ -1857,7 +1895,7 @@ static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, pa if (result) - result = g_binary_format_load_errors(format, pbuf); + result = g_program_format_load_errors(format, pbuf); return result; @@ -1878,7 +1916,7 @@ static bool g_binary_format_load(GBinFormat *format, GObjectStorage *storage, pa * * ******************************************************************************/ -static bool g_binary_format_store(GBinFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) +static bool g_program_format_store(GProgramFormat *format, GObjectStorage *storage, packed_buffer_t *pbuf) { bool result; /* Bilan à retourner */ fmt_extra_data_t *extra; /* Données insérées à consulter*/ @@ -1894,7 +1932,7 @@ static bool g_binary_format_store(GBinFormat *format, GObjectStorage *storage, p UNLOCK_GOBJECT_EXTRA(extra); if (result) - result = g_binary_format_store_start_points(format, pbuf); + result = g_program_format_store_start_points(format, pbuf); if (result) { @@ -1913,8 +1951,10 @@ static bool g_binary_format_store(GBinFormat *format, GObjectStorage *storage, p if (result) - result = g_binary_format_store_errors(format, pbuf); + result = g_program_format_store_errors(format, pbuf); return result; } + +#endif diff --git a/src/format/program.h b/src/format/program.h index f9aa430..51b7860 100644 --- a/src/format/program.h +++ b/src/format/program.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * format.h - prototypes pour le support des différents formats binaires + * program.h - prototypes pour le support des différents formats de programmes * - * Copyright (C) 2009-2020 Cyrille Bagard + * Copyright (C) 2009-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -21,10 +21,29 @@ */ -#ifndef _FORMAT_FORMAT_H -#define _FORMAT_FORMAT_H +#ifndef _FORMAT_PROGRAM_H +#define _FORMAT_PROGRAM_H +#include "../common/datatypes.h" +#include "../glibext/helpers.h" + + + +#define G_TYPE_PROGRAM_FORMAT (g_program_format_get_type()) + +DECLARE_GTYPE(GProgramFormat, g_program_format, G, PROGRAM_FORMAT); + + +/* Indique le boutisme employé par le format binaire analysé. */ +SourceEndian g_program_format_get_endianness(const GProgramFormat *); + + + + + +#if 0 + #include <glib-object.h> #include <stdbool.h> #include <sys/types.h> @@ -52,47 +71,31 @@ typedef enum _FormatFlag } FormatFlag; -#define G_TYPE_BIN_FORMAT g_binary_format_get_type() -#define G_BIN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BIN_FORMAT, GBinFormat)) -#define G_IS_BIN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BIN_FORMAT)) -#define G_BIN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BIN_FORMAT, GBinFormatClass)) -#define G_IS_BIN_FORMAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BIN_FORMAT)) -#define G_BIN_FORMAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_FORMAT, GBinFormatClass)) - -/* Format binaire générique (instance) */ -typedef struct _GBinFormat GBinFormat; - -/* Format binaire générique (classe) */ -typedef struct _GBinFormatClass GBinFormatClass; - - -/* Indique le type défini pour un format binaire générique. */ -GType g_binary_format_get_type(void); /* Ajoute une information complémentaire à un format. */ -bool g_binary_format_set_flag(GBinFormat *, FormatFlag); +bool g_program_format_set_flag(GProgramFormat *, FormatFlag); /* Retire une information complémentaire à un format. */ -bool g_binary_format_unset_flag(GBinFormat *, FormatFlag); +bool g_program_format_unset_flag(GProgramFormat *, FormatFlag); /* Détermine si un format possède un fanion particulier. */ -bool g_binary_format_has_flag(const GBinFormat *, FormatFlag); +bool g_program_format_has_flag(const GProgramFormat *, FormatFlag); /* Fournit les particularités du format. */ -FormatFlag g_binary_format_get_flags(const GBinFormat *); +FormatFlag g_program_format_get_flags(const GProgramFormat *); /* Indique le boutisme employé par le format binaire analysé. */ -SourceEndian g_binary_format_get_endianness(const GBinFormat *); +//SourceEndian g_program_format_get_endianness(const GProgramFormat *); /* Enregistre une adresse comme début d'une zone de code. */ -void g_binary_format_register_code_point(GBinFormat *, virt_t, DisassPriorityLevel); +void g_program_format_register_code_point(GProgramFormat *, virt_t, DisassPriorityLevel); /* Intègre dans un contexte les informations tirées d'un format. */ -void g_binary_format_preload_disassembling_context(GBinFormat *, GProcContext *, GtkStatusStack *); +void g_program_format_preload_disassembling_context(GProgramFormat *, GProcContext *, GtkStatusStack *); /* Définit les points de départ d'un contexte de désassemblage. */ -void g_binary_format_activate_disassembling_context(GBinFormat *, GProcContext *, GtkStatusStack *); +void g_program_format_activate_disassembling_context(GProgramFormat *, GProcContext *, GtkStatusStack *); @@ -100,7 +103,7 @@ void g_binary_format_activate_disassembling_context(GBinFormat *, GProcContext * /* Fournit le décodeur de symboles privilégié pour un format. */ -GCompDemangler *g_binary_format_get_demangler(const GBinFormat *); +GCompDemangler *g_program_format_get_demangler(const GProgramFormat *); @@ -108,60 +111,60 @@ GCompDemangler *g_binary_format_get_demangler(const GBinFormat *); /* Protège ou lève la protection de l'accès aux symboles. */ -void g_binary_format_lock_unlock_symbols_rd(GBinFormat *, bool); +void g_program_format_lock_unlock_symbols_rd(GProgramFormat *, bool); -#define g_binary_format_lock_symbols_rd(f) g_binary_format_lock_unlock_symbols_rd(f, true) -#define g_binary_format_unlock_symbols_rd(f) g_binary_format_lock_unlock_symbols_rd(f, false) +#define g_program_format_lock_symbols_rd(f) g_program_format_lock_unlock_symbols_rd(f, true) +#define g_program_format_unlock_symbols_rd(f) g_program_format_lock_unlock_symbols_rd(f, false) /* Protège ou lève la protection de l'accès aux symboles. */ -void g_binary_format_lock_unlock_symbols_wr(GBinFormat *, bool); +void g_program_format_lock_unlock_symbols_wr(GProgramFormat *, bool); -#define g_binary_format_lock_symbols_wr(f) g_binary_format_lock_unlock_symbols_wr(f, true) -#define g_binary_format_unlock_symbols_wr(f) g_binary_format_lock_unlock_symbols_wr(f, false) +#define g_program_format_lock_symbols_wr(f) g_program_format_lock_unlock_symbols_wr(f, true) +#define g_program_format_unlock_symbols_wr(f) g_program_format_lock_unlock_symbols_wr(f, false) /* Assure qu'un verrou est bien posé pour l'accès aux symboles. */ #ifndef NDEBUG -void g_binary_format_check_for_symbols_lock(const GBinFormat *); +void g_program_format_check_for_symbols_lock(const GProgramFormat *); #endif /* Fournit la marque de dernière modification des symboles. */ -unsigned int g_binary_format_get_symbols_stamp(const GBinFormat *); +unsigned int g_program_format_get_symbols_stamp(const GProgramFormat *); /* Compte le nombre de symboles représentés. */ -size_t g_binary_format_count_symbols(const GBinFormat *); +size_t g_program_format_count_symbols(const GProgramFormat *); /* Fournit un symbole lié à un format. */ -GBinSymbol *g_binary_format_get_symbol(const GBinFormat *, size_t); +GBinSymbol *g_program_format_get_symbol(const GProgramFormat *, size_t); /* Ajoute un symbole à la collection du format binaire. */ -bool g_binary_format_add_symbol(GBinFormat *, GBinSymbol *); +bool g_program_format_add_symbol(GProgramFormat *, GBinSymbol *); /* Ajoute plusieurs symboles à la collection du format binaire. */ -bool g_binary_format_add_symbols(GBinFormat *, GBinSymbol **, size_t); +bool g_program_format_add_symbols(GProgramFormat *, GBinSymbol **, size_t); /* Retire un symbole de la collection du format binaire. */ -void g_binary_format_remove_symbol(GBinFormat *, GBinSymbol *); +void g_program_format_remove_symbol(GProgramFormat *, GBinSymbol *); /* Recherche le symbole correspondant à une étiquette. */ -bool g_binary_format_find_symbol_by_label(GBinFormat *, const char *, GBinSymbol **); +bool g_program_format_find_symbol_by_label(GProgramFormat *, const char *, GBinSymbol **); /* Recherche l'indice du symbole correspondant à une adresse. */ -bool g_binary_format_find_symbol_index_at(GBinFormat *, const vmpa2t *, size_t *); +bool g_program_format_find_symbol_index_at(GProgramFormat *, const vmpa2t *, size_t *); /* Recherche le symbole correspondant à une adresse. */ -bool g_binary_format_find_symbol_at(GBinFormat *, const vmpa2t *, GBinSymbol **); +bool g_program_format_find_symbol_at(GProgramFormat *, const vmpa2t *, GBinSymbol **); /* Recherche le symbole contenant une adresse. */ -bool g_binary_format_find_symbol_for(GBinFormat *, const vmpa2t *, GBinSymbol **); +bool g_program_format_find_symbol_for(GProgramFormat *, const vmpa2t *, GBinSymbol **); /* Recherche le symbole suivant celui lié à une adresse. */ -bool g_binary_format_find_next_symbol_at(GBinFormat *, const vmpa2t *, GBinSymbol **); +bool g_program_format_find_next_symbol_at(GProgramFormat *, const vmpa2t *, GBinSymbol **); /* Recherche le premier symbole inclus dans une zone mémoire. */ -bool g_binary_format_find_first_symbol_inside(GBinFormat *, const mrange_t *, size_t *); +bool g_program_format_find_first_symbol_inside(GProgramFormat *, const mrange_t *, size_t *); /* Recherche le symbole correspondant à une adresse. */ -bool g_binary_format_resolve_symbol(GBinFormat *, const vmpa2t *, bool, GBinSymbol **, phys_t *); +bool g_program_format_resolve_symbol(GProgramFormat *, const vmpa2t *, bool, GBinSymbol **, phys_t *); @@ -181,20 +184,21 @@ typedef enum _BinaryFormatError /* Protège ou lève la protection de l'accès aux erreurs. */ -void g_binary_format_lock_unlock_errors(GBinFormat *, bool); +void g_program_format_lock_unlock_errors(GProgramFormat *, bool); -#define g_binary_format_lock_errors(f) g_binary_format_lock_unlock_errors(f, true) -#define g_binary_format_unlock_errors(f) g_binary_format_lock_unlock_errors(f, false) +#define g_program_format_lock_errors(f) g_program_format_lock_unlock_errors(f, true) +#define g_program_format_unlock_errors(f) g_program_format_lock_unlock_errors(f, false) /* Etend la liste des soucis détectés avec de nouvelles infos. */ -void g_binary_format_add_error(GBinFormat *, BinaryFormatError, const vmpa2t *, const char *); +void g_program_format_add_error(GProgramFormat *, BinaryFormatError, const vmpa2t *, const char *); /* Indique le nombre d'erreurs relevées au niveau assembleur. */ -size_t g_binary_format_count_errors(GBinFormat *); +size_t g_program_format_count_errors(GProgramFormat *); /* Fournit les éléments concernant un soucis détecté. */ -bool g_binary_format_get_error(GBinFormat *, size_t, BinaryFormatError *, vmpa2t *, char **); +bool g_program_format_get_error(GProgramFormat *, size_t, BinaryFormatError *, vmpa2t *, char **); +#endif -#endif /* _FORMAT_FORMAT_H */ +#endif /* _FORMAT_PROGRAM_H */ diff --git a/tests/format/flat.py b/tests/format/flat.py index 6924e42..f84f7a4 100644 --- a/tests/format/flat.py +++ b/tests/format/flat.py @@ -1,16 +1,11 @@ -#!/usr/bin/python3-dbg -# -*- coding: utf-8 -*- - - -# Tests minimalistes pour valider la gestion des erreurs relevées. - from chrysacase import ChrysalideTestCase -from pychrysalide.analysis import LoadedBinary +from pychrysalide import SourceEndian +#from pychrysalide.analysis import LoadedBinary from pychrysalide.analysis.contents import MemoryContent -from pychrysalide.arch import vmpa +#from pychrysalide.arch import vmpa from pychrysalide.format import FlatFormat -from pychrysalide.glibext import BinPortion +#from pychrysalide.glibext import BinPortion class TestFlatFormat(ChrysalideTestCase): @@ -24,18 +19,21 @@ class TestFlatFormat(ChrysalideTestCase): cnt = MemoryContent(data) - fmt = FlatFormat(cnt) - fmt.set_machine('armv7') + fmt = FlatFormat(cnt, 'armv7', SourceEndian.LITTLE) + + self.assertEqual(fmt.target_machine, 'armv7') + self.assertEqual(fmt.endianness, SourceEndian.LITTLE) + - base = vmpa(0, 0) + # base = vmpa(0, 0) - p = BinPortion(BinPortion.BPC_CODE, base, cnt.size) - p.rights = BinPortion.PAC_READ | BinPortion.PAC_EXEC + # p = BinPortion(BinPortion.BPC_CODE, base, cnt.size) + # p.rights = BinPortion.PAC_READ | BinPortion.PAC_EXEC - fmt.register_user_portion(p) + # fmt.register_user_portion(p) - binary = LoadedBinary(fmt) + # binary = LoadedBinary(fmt) - binary.analyze_and_wait() + # binary.analyze_and_wait() - self.assertTrue(list(binary.processor.instrs)[0].keyword == 'svc') + # self.assertTrue(list(binary.processor.instrs)[0].keyword == 'svc') diff --git a/tests/format/known.py b/tests/format/known.py index 056238f..3a51f31 100644 --- a/tests/format/known.py +++ b/tests/format/known.py @@ -1,6 +1,3 @@ -#!/usr/bin/python3-dbg -# -*- coding: utf-8 -*- - from chrysacase import ChrysalideTestCase from pychrysalide.analysis.contents import MemoryContent @@ -11,8 +8,62 @@ class TestKnownFormat(ChrysalideTestCase): """TestCase for format.KnownFormat.""" + def testCustomInstance(self): + """Validate a full custom KnownFormat implementation.""" + + data = b'\x01\x02\x03' + cnt = MemoryContent(data) + + + class CustomFormat(KnownFormat): + + def _get_key(self): + return 'tiny' + + def _get_description(self): + return 'Small description' + + cf = CustomFormat(cnt) + + self.assertEqual(cf.key, 'tiny') + self.assertEqual(cf.description, 'Small description') + + + class EmptyCustomFormat(KnownFormat): + pass + + cf = EmptyCustomFormat(cnt) + + # NotImplementedError: method implementation is missing for '_get_key' + with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_key'"): + k = cf.key + + # NotImplementedError: method implementation is missing for '_get_description' + with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_description'"): + k = cf.description + + + class BadCustomFormat(KnownFormat): + + def _get_key(self): + return 123 + + def _get_description(self): + return 456 + + cf = BadCustomFormat(cnt) + + # ValueError: unexpected value type for known format key + with self.assertRaisesRegex(ValueError, 'unexpected value type for known format key'): + k = cf.key + + # ValueError: unexpected value type for known format description + with self.assertRaisesRegex(ValueError, 'unexpected value type for known format description'): + k = cf.description + + def testKnownFormatConstructor(self): - """Build Load a simple content for a flat format.""" + """Load a simple content for a known format.""" with self.assertRaisesRegex(RuntimeError, 'pychrysalide.format.KnownFormat is an abstract class'): fmt = KnownFormat() @@ -28,17 +79,3 @@ class TestKnownFormat(ChrysalideTestCase): with self.assertRaisesRegex(TypeError, 'unable to convert the provided argument to binary content'): fmt = MyKnownFormat2(123) - - class MyKnownFormatReady(KnownFormat): - _key = 'rdy' - def __init2__(self, cnt): - super(MyKnownFormatReady, self).__init2__(cnt) - - data = b'\x00\x00\x00\xef' - - cnt = MemoryContent(data) - fmt = MyKnownFormatReady(cnt) - - self.assertIsNotNone(fmt) - - self.assertEqual(fmt.key, 'rdy') diff --git a/tests/format/program.py b/tests/format/program.py index b6aad8f..7a649b8 100644 --- a/tests/format/program.py +++ b/tests/format/program.py @@ -1,66 +1,84 @@ -#!/usr/bin/python3-dbg -# -*- coding: utf-8 -*- +from chrysacase import ChrysalideTestCase +from pychrysalide import SourceEndian +#from pychrysalide.arch import vmpa, mrange +from pychrysalide.format import ProgramFormat +#from pychrysalide.format import BinSymbol -# Tests minimalistes pour valider la gestion des erreurs relevées. +# class SimpleFormat(BinFormat): +# pass -from chrysacase import ChrysalideTestCase -from pychrysalide.arch import vmpa, mrange -from pychrysalide.format import BinFormat -from pychrysalide.format import BinSymbol -import os -import sys + +class TestProgramFormat(ChrysalideTestCase): + """TestCase for format.ProgramFormat.""" + + + def testCustomInstance(self): + """Validate a full custom ProgramFormat implementation.""" + + class CustomFormat(ProgramFormat): + + def _get_endianness(self): + return SourceEndian.BIG + + cf = CustomFormat() + + self.assertEqual(cf.endianness, SourceEndian.BIG) + + + class EmptyCustomFormat(ProgramFormat): + pass + + cf = EmptyCustomFormat() + + self.assertEqual(cf.endianness, SourceEndian.LITTLE) -class SimpleFormat(BinFormat): - pass -class TestFormatErrors(ChrysalideTestCase): - """TestCase for format.BinFormat.""" - def create_fake_symbol(self, index): - saddr = vmpa(index * 0x10, vmpa.VMPA_NO_VIRTUAL) - srange = mrange(saddr, 0x3) - symbol = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange) - return symbol + # def create_fake_symbol(self, index): + # saddr = vmpa(index * 0x10, vmpa.VMPA_NO_VIRTUAL) + # srange = mrange(saddr, 0x3) + # symbol = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange) + # return symbol - def testBasicSymbolOperations(self): - """Deal with the basic operations related to symbols in a binary format.""" + # def testBasicSymbolOperations(self): + # """Deal with the basic operations related to symbols in a binary format.""" - sf = SimpleFormat() + # sf = SimpleFormat() - self.assertTrue(len(list(sf.symbols)) == 0) + # self.assertTrue(len(list(sf.symbols)) == 0) - symbols = [ self.create_fake_symbol(i) for i in range(4) ] - s0, s1, s2, s3 = symbols + # symbols = [ self.create_fake_symbol(i) for i in range(4) ] + # s0, s1, s2, s3 = symbols - for s in symbols: - sf.add_symbol(s) + # for s in symbols: + # sf.add_symbol(s) - self.assertTrue(len(list(sf.symbols)) == len(symbols)) + # self.assertTrue(len(list(sf.symbols)) == len(symbols)) - sf.remove_symbol(s2) + # sf.remove_symbol(s2) - self.assertTrue(list(sf.symbols) == [s0, s1, s3]) + # self.assertTrue(list(sf.symbols) == [s0, s1, s3]) - def testBadParamsForAdding(self): - """Check if bad parameters fail for adding a new symbol.""" + # def testBadParamsForAdding(self): + # """Check if bad parameters fail for adding a new symbol.""" - sf = SimpleFormat() + # sf = SimpleFormat() - with self.assertRaises(TypeError): - sf.add_symbol('s') + # with self.assertRaises(TypeError): + # sf.add_symbol('s') - def testWrongRemoval(self): - """Try to remove a wrong symbol from a format.""" + # def testWrongRemoval(self): + # """Try to remove a wrong symbol from a format.""" - sf = SimpleFormat() + # sf = SimpleFormat() - s23 = self.create_fake_symbol(23) - sf.remove_symbol(s23) + # s23 = self.create_fake_symbol(23) + # sf.remove_symbol(s23) |