diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2024-11-23 15:59:19 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2024-11-23 15:59:19 (GMT) |
commit | 411f03130cf45194689bc344f19a3b77c33a31ae (patch) | |
tree | f047b62015eb37e30629398f9adcb977a5a6c6f6 /plugins | |
parent | 80d779749adf228078b61f268bf952ba91a277f0 (diff) |
Restore more features for formats.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/dex/format.c | 30 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/vmpa.c | 18 | ||||
-rw-r--r-- | plugins/pychrysalide/core.c | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/format/executable.c | 392 | ||||
-rw-r--r-- | plugins/pychrysalide/format/flat.c | 8 | ||||
-rw-r--r-- | plugins/pychrysalide/format/known.c | 173 | ||||
-rw-r--r-- | plugins/pychrysalide/format/program.c | 188 | ||||
-rw-r--r-- | plugins/pychrysalide/glibext/Makefile.am | 4 | ||||
-rw-r--r-- | plugins/pychrysalide/glibext/constants.c | 10 | ||||
-rw-r--r-- | plugins/pychrysalide/glibext/constants.h | 4 | ||||
-rw-r--r-- | plugins/pychrysalide/glibext/module.c | 4 | ||||
-rw-r--r-- | plugins/pychrysalide/glibext/portion.c | 195 | ||||
-rw-r--r-- | plugins/pychrysalide/glibext/portion.h | 12 |
13 files changed, 647 insertions, 393 deletions
diff --git a/plugins/dex/format.c b/plugins/dex/format.c index ccf21a8..f9a2410 100644 --- a/plugins/dex/format.c +++ b/plugins/dex/format.c @@ -70,9 +70,6 @@ static const char *g_dex_format_get_target_machine(const GDexFormat *); /* Etend la définition des portions au sein d'un binaire. */ static void g_dex_format_refine_portions(GDexFormat *); -/* Fournit l'emplacement d'une section donnée. */ -static bool g_dex_format_get_section_range_by_name(const GDexFormat *, const char *, mrange_t *); - @@ -166,8 +163,6 @@ static void g_dex_format_class_init(GDexFormatClass *klass) exe->translate_phys = (translate_phys_fc)g_exe_format_without_virt_translate_offset_into_vmpa; exe->translate_virt = (translate_virt_fc)g_exe_format_without_virt_translate_address_into_vmpa; - exe->get_range_by_name = (get_range_by_name_fc)g_dex_format_get_section_range_by_name; - } @@ -515,31 +510,6 @@ static void g_dex_format_refine_portions(GDexFormat *format) } -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à consulter. * -* name = nom de la section recherchée. * -* range = emplacement en mémoire à renseigner. [OUT] * -* * -* Description : Fournit l'emplacement d'une section donnée. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_dex_format_get_section_range_by_name(const GDexFormat *format, const char *name, mrange_t *range) -{ - bool result; /* Bilan à retourner */ - - result = false; - - return result; - -} - - diff --git a/plugins/pychrysalide/arch/vmpa.c b/plugins/pychrysalide/arch/vmpa.c index 20784cd..5162fac 100644 --- a/plugins/pychrysalide/arch/vmpa.c +++ b/plugins/pychrysalide/arch/vmpa.c @@ -824,13 +824,23 @@ PyObject *build_from_internal_vmpa(const vmpa2t *addr) PyTypeObject *type; /* Type à instancier */ PyObject *args; /* Liste des arguments d'appel */ - type = get_python_vmpa_type(); + if (get_phy_addr(addr) == VMPA_NO_PHYSICAL && get_virt_addr(addr) == VMPA_NO_VIRTUAL) + { + result = Py_None; + Py_INCREF(result); + } + + else + { + type = get_python_vmpa_type(); - args = Py_BuildValue("KK", get_phy_addr(addr), get_virt_addr(addr)); + args = Py_BuildValue("KK", get_phy_addr(addr), get_virt_addr(addr)); - result = PyObject_CallObject((PyObject *)type, args); + result = PyObject_CallObject((PyObject *)type, args); - Py_DECREF(args); + Py_DECREF(args); + + } return result; diff --git a/plugins/pychrysalide/core.c b/plugins/pychrysalide/core.c index c76fae4..8d69933 100644 --- a/plugins/pychrysalide/core.c +++ b/plugins/pychrysalide/core.c @@ -661,8 +661,8 @@ PyMODINIT_FUNC PyInit_pychrysalide(void) /* if (status) status = ensure_python_string_enum_is_registered(); - if (status) status = ensure_python_py_struct_is_registered(); */ + if (status) status = ensure_python_py_struct_is_registered(); if (status) status = define_data_types_constants(result); diff --git a/plugins/pychrysalide/format/executable.c b/plugins/pychrysalide/format/executable.c index d886e9a..7d05578 100644 --- a/plugins/pychrysalide/format/executable.c +++ b/plugins/pychrysalide/format/executable.c @@ -36,9 +36,10 @@ #include "program.h" #include "../access.h" #include "../helpers.h" +#include "../analysis/content.h" //#include "../arch/processor.h" -//#include "../arch/vmpa.h" -//#include "../glibext/binportion.h" +#include "../arch/vmpa.h" +#include "../glibext/portion.h" @@ -56,23 +57,35 @@ 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 *); +/* Fournit l'adresse principale associée à un format. */ +static bool py_executable_format_get_main_address_wrapper(GExecutableFormat *, vmpa2t *); + +/* Etend la définition des portions au sein d'un binaire. */ +static bool py_executable_format_refine_portions_wrapper(GExecutableFormat *); + /* ------------------------ DECLARATION DE FORMAT EXECUTABLE ------------------------ */ -/* Enregistre une portion artificielle pour le format. */ -//static PyObject *py_executable_format_register_user_portion(PyObject *, PyObject *); +/* Procède à l'enregistrement d'une portion dans un format. */ +static PyObject *py_executable_format_include_portion(PyObject *, PyObject *); /* Fournit l'emplacement correspondant à une position physique. */ -//static PyObject *py_executable_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_executable_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 *); +/* Fournit l'adresse principale associée à un format. */ +static PyObject *py_executable_format_get_main_address(PyObject *, void *); + +/* Indique le type d'architecture visée par le format. */ +static PyObject *py_executable_format_get_portions(PyObject *, void *); + /* ---------------------------------------------------------------------------------- */ @@ -97,6 +110,9 @@ static void py_executable_format_init_gclass(GExecutableFormatClass *class, gpoi { class->get_machine = py_executable_format_get_target_machine_wrapper; + class->get_main_addr = py_executable_format_get_main_address_wrapper; + class->refine_portions = py_executable_format_refine_portions_wrapper; + } @@ -116,24 +132,42 @@ static void py_executable_format_init_gclass(GExecutableFormatClass *class, gpoi static int py_executable_format_init(PyObject *self, PyObject *args, PyObject *kwds) { + GBinContent *content; /* Contenu à intégrer au format*/ int ret; /* Bilan de lecture des args. */ + GExecutableFormat *format; /* Format à manipuler */ #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" \ + "The following methods have to be defined for new classes:\n" \ "* pychrysalide.format.ExecutableFormat._get_target_machine();\n" \ + "* pychrysalide.format.ExecutableFormat._get_main_address().\n" \ "\n" \ + "The following method may be defined for new classes:\n" \ + "* pychrysalide.format.ExecutableFormat._refine_portions().\n" \ "\n" \ "Calls to the *__init__* constructor of this abstract object expect"\ - " no particular argument." + " only one argument: a binary content, provided as a" \ + " pychrysalide.analysis.BinContent instance." + + /* Récupération des paramètres */ + + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content); + if (!ret) return -1; /* Initialisation d'un objet GLib */ ret = forward_pygobjet_init(self); if (ret == -1) return -1; + /* Eléments de base */ + + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); + + if (!g_executable_format_create(format, content)) + return -1; + return 0; } @@ -203,41 +237,221 @@ static char *py_executable_format_get_target_machine_wrapper(const GExecutableFo } +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à consulter. * +* addr = adresse principale trouvée si possible. [OUT] * +* * +* Description : Fournit l'adresse principale associée à un format. * +* * +* Retour : Validité de l'adresse transmise. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_executable_format_get_main_address_wrapper(GExecutableFormat *format, vmpa2t *addr) +{ + bool result; /* Bilan à retourner */ + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ + PyObject *pyobj; /* Objet Python concerné */ + PyObject *pyret; /* Valeur retournée */ + vmpa2t *tmp; /* Zone de stockage Python */ + int ret; /* Bilan d'une conversion */ + +#define EXECUTABLE_FORMAT_GET_MAIN_ADDRESS_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _get_main_address, "$self", \ + METH_NOARGS, \ + "Abstract method used to provide the main address of code for" \ + " the executable format.\n" \ + "\n" \ + "The return value has to be a pychrysalide.arch.vmpa instance or" \ + " *None* in case of failure." \ + ) + + result = false; + + gstate = PyGILState_Ensure(); + + pyobj = pygobject_new(G_OBJECT(format)); + + if (has_python_method(pyobj, "_get_main_address")) + { + pyret = run_python_method(pyobj, "_get_main_address", NULL); + + if (pyret != NULL) + { + if (pyret == Py_None) + { + init_vmpa(addr, VMPA_NO_PHYSICAL, VMPA_NO_VIRTUAL); + result = true; + } + + else + { + ret = convert_any_to_vmpa(pyret, &tmp); + + result = (ret == 1 || ret == Py_CLEANUP_SUPPORTED); + + if (result) + { + copy_vmpa(addr, tmp); + + if (ret == Py_CLEANUP_SUPPORTED) + clean_vmpa_arg(tmp); + + } + + else + { + /** + * L'erreur Python peut être effacée. + * + * Elle sera remontée : + * - au code C via le retour (false) : + * - à Python lors de l'accès à la propriétée. + */ + PyErr_Clear(); + + } + + } + + Py_DECREF(pyret); + + } + + } + + Py_DECREF(pyobj); + + PyGILState_Release(gstate); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * +* * +* Description : Etend la définition des portions au sein d'un binaire. * +* * +* Retour : Bilan des définitions de portions. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_executable_format_refine_portions_wrapper(GExecutableFormat *format) +{ + bool result; /* Bilan à retourner */ + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ + PyObject *pyobj; /* Objet Python concerné */ + PyObject *pyret; /* Valeur retournée */ + +#define EXECUTABLE_FORMAT_REFINE_PORTIONS_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _refine_portions, "$self", \ + METH_NOARGS, \ + "Abstract method used to extend the definition of the format" \ + " with binary portions.\n" \ + "\n" \ + "Extra portions should be included with calls to" \ + " pychrysalide.format.ExecutableFormat.include_portion().\n" \ + "\n" \ + "The return value has to be a boolean value: *True* in case of" \ + " success, *False* in case of failure." \ +) + + result = true; + + gstate = PyGILState_Ensure(); + + pyobj = pygobject_new(G_OBJECT(format)); + + if (has_python_method(pyobj, "_refine_portions")) + { + pyret = run_python_method(pyobj, "_refine_portions", NULL); + + if (pyret != NULL) + { + result = (pyret == Py_True); + Py_DECREF(pyret); + } + + } + + Py_DECREF(pyobj); + + PyGILState_Release(gstate); + + return result; + +} + + /* ---------------------------------------------------------------------------------- */ /* DECLARATION DE FORMAT EXECUTABLE */ /* ---------------------------------------------------------------------------------- */ -#if 0 /****************************************************************************** * * * Paramètres : self = description de l'exécutable à consulter. * * args = arguments accompagnant l'appel. * * * -* Description : Enregistre une portion artificielle pour le format. * +* Description : Procède à l'enregistrement d'une portion dans un format. * * * -* Retour : - * +* Retour : Bilan de l'opération : True si inclusion, False sinon. * * * * Remarques : - * * * ******************************************************************************/ -static PyObject *py_executable_format_register_user_portion(PyObject *self, PyObject *args) +static PyObject *py_executable_format_include_portion(PyObject *self, PyObject *args) { - GBinPortion *portion; /* Portion binaire à conserver */ + PyObject *result; /* Bilan à retourner */ + GBinaryPortion *portion; /* Portion binaire à conserver */ + vmpa2t *origin; /* Source de l'inclusion */ int ret; /* Bilan de lecture des args. */ GExecutableFormat *format; /* Version GLib du format */ + bool status; /* Bilan de l'inclusion */ + +#define EXECUTABLE_FORMAT_INCLUDE_PORTION_METHOD PYTHON_METHOD_DEF \ +( \ + include_portion, "$self, portion, /, origin=None", \ + METH_VARARGS, py_executable_format, \ + "Register a new portion inside the content of an executable format.\n" \ + "\n" \ + "The *portion* argument is a pychrysalide.glibext.BinaryPortion" \ + " instance. The optional *origin* arguement specifies the source of the"\ + " operation, as a pychrysalide.arch.vmpa definition, which may be used" \ + " for tracking errors.\n" \ + "\n" \ + "The return value is a boolean value: *True* in case of success," \ + " *False* in case of failure." \ +) + + origin = NULL; - ret = PyArg_ParseTuple(args, "O&", convert_to_binary_portion, &portion); + ret = PyArg_ParseTuple(args, "O&|O&", convert_to_binary_portion, &portion, convert_any_to_vmpa, &origin); if (!ret) return NULL; format = G_EXECUTABLE_FORMAT(pygobject_get(self)); - g_object_ref(G_OBJECT(portion)); - g_exe_format_register_user_portion(format, portion); + status = g_executable_format_include_portion(format, portion, origin); + + result = status ? Py_True : Py_False; + Py_INCREF(result); - Py_RETURN_NONE; + if (origin != NULL) + clean_vmpa_arg(origin); + + return result; } @@ -264,13 +478,24 @@ static PyObject *py_executable_format_translate_offset_into_vmpa(PyObject *self, vmpa2t pos; /* Position complète déterminée*/ bool status; /* Bilan de l'opération */ - format = G_EXECUTABLE_FORMAT(pygobject_get(self)); - assert(format != NULL); +#define EXECUTABLE_FORMAT_TRANSLATE_OFFSET_INTO_VMPA_METHOD PYTHON_METHOD_DEF \ +( \ + translate_offset_into_vmpa, "$self, addr", \ + METH_VARARGS, py_executable_format, \ + "Translate a physical offset to a full location.\n" \ + "\n" \ + "The *off* argument is a physical offset provided as an integer value.\n" \ + "\n" \ + "The returned position is a pychrysalide.arch.vmpa instance or *None* in" \ + " case of failure." \ +) ret = PyArg_ParseTuple(args, "K", &off); if (!ret) return NULL; - status = g_exe_format_translate_offset_into_vmpa(format, off, &pos); + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); + + status = g_executable_format_translate_offset_into_vmpa(format, off, &pos); if (status) result = build_from_internal_vmpa(&pos); @@ -308,13 +533,24 @@ static PyObject *py_executable_format_translate_address_into_vmpa(PyObject *self vmpa2t pos; /* Position complète déterminée*/ bool status; /* Bilan de l'opération */ - format = G_EXECUTABLE_FORMAT(pygobject_get(self)); - assert(format != NULL); +#define EXECUTABLE_FORMAT_TRANSLATE_ADDRESS_INTO_VMPA_METHOD PYTHON_METHOD_DEF \ +( \ + translate_address_into_vmpa, "$self, addr", \ + METH_VARARGS, py_executable_format, \ + "Translate a virtual address to a full location.\n" \ + "\n" \ + "The *addr* argument is a virtual address provided as an integer value.\n" \ + "\n" \ + "The returned position is a pychrysalide.arch.vmpa instance or *None* in" \ + " case of failure." \ +) ret = PyArg_ParseTuple(args, "K", &addr); if (!ret) return NULL; - status = g_exe_format_translate_address_into_vmpa(format, addr, &pos); + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); + + status = g_executable_format_translate_address_into_vmpa(format, addr, &pos); if (status) result = build_from_internal_vmpa(&pos); @@ -328,7 +564,6 @@ static PyObject *py_executable_format_translate_address_into_vmpa(PyObject *self return result; } -#endif /****************************************************************************** @@ -382,6 +617,91 @@ static PyObject *py_executable_format_get_target_machine(PyObject *self, void *c /****************************************************************************** * * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit l'adresse principale associée à un format. * +* * +* Retour : Validité de l'adresse transmise. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_executable_format_get_main_address(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GExecutableFormat *format; /* Format exécutable manipulé */ + vmpa2t addr; /* Point d'entrée principal */ + bool status; /* Validité de l'adresse */ + +#define EXECUTABLE_FORMAT_MAIN_ADDRESS_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + main_address, py_executable_format, \ + "Main address of code for the executable format.\n" \ + "\n" \ + "This property provide a pychrysalide.arch.vmpa instance or" \ + " *None* in case of failure." \ +) + + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); + + status = g_executable_format_get_main_address(format, &addr); + + if (status) + result = build_from_internal_vmpa(&addr); + + else + { + PyErr_SetString(PyExc_AttributeError, _("unable to define a value for the main address")); + result = NULL; + } + + return result; + +} + + +/****************************************************************************** +* * +* 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_portions(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GExecutableFormat *format; /* Format exécutable manipulé */ + GBinaryPortion *portions; /* Portion principale du format*/ + +#define EXECUTABLE_FORMAT_PORTIONS_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + portions, py_executable_format, \ + "Root portion of the executable format, provided as a" \ + " pychrysalide.glibext.BinaryPortion instance." \ +) + + format = G_EXECUTABLE_FORMAT(pygobject_get(self)); + + portions = g_executable_format_get_portions(format); + + result = pygobject_new(G_OBJECT(portions)); + unref_object(portions); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * @@ -396,28 +716,18 @@ PyTypeObject *get_python_executable_format_type(void) { static PyMethodDef py_executable_format_methods[] = { EXECUTABLE_FORMAT_GET_TARGET_MACHINE_WRAPPER, -#if 0 - { - "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_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_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 + EXECUTABLE_FORMAT_GET_MAIN_ADDRESS_WRAPPER, + EXECUTABLE_FORMAT_REFINE_PORTIONS_WRAPPER, + EXECUTABLE_FORMAT_INCLUDE_PORTION_METHOD, + EXECUTABLE_FORMAT_TRANSLATE_OFFSET_INTO_VMPA_METHOD, + EXECUTABLE_FORMAT_TRANSLATE_ADDRESS_INTO_VMPA_METHOD, { NULL } }; static PyGetSetDef py_executable_format_getseters[] = { EXECUTABLE_FORMAT_TARGET_MACHINE_ATTRIB, + EXECUTABLE_FORMAT_MAIN_ADDRESS_ATTRIB, + EXECUTABLE_FORMAT_PORTIONS_ATTRIB, { NULL } }; diff --git a/plugins/pychrysalide/format/flat.c b/plugins/pychrysalide/format/flat.c index a115c57..81f0dba 100644 --- a/plugins/pychrysalide/format/flat.c +++ b/plugins/pychrysalide/format/flat.c @@ -41,7 +41,6 @@ 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 *); @@ -77,9 +76,10 @@ static int py_flat_format_init(PyObject *self, PyObject *args, PyObject *kwds) "\n" \ " FlatFormat(content, machine, endian)" \ "\n" \ - "Where content is a pychrysalide.analysis.BinContent object, machine" \ - " defines the target architecture as a string value and endian provides"\ - " the right endianness of the data, as pychrysalide.SourceEndian value." + "Where *content* is a pychrysalide.analysis.BinContent object," \ + " *machine* defines the target architecture as a string value and" \ + " *endian* provides the right endianness of the data, as a" \ + " pychrysalide.SourceEndian value." /* Récupération des paramètres */ diff --git a/plugins/pychrysalide/format/known.c b/plugins/pychrysalide/format/known.c index e38c975..5df2a8f 100644 --- a/plugins/pychrysalide/format/known.c +++ b/plugins/pychrysalide/format/known.c @@ -55,13 +55,8 @@ 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 +static bool py_known_format_analyze_wrapper(GKnownFormat *); @@ -69,10 +64,7 @@ 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 *); - -/* Réalise un traitement post-désassemblage. */ -//static PyObject *py_known_format_complete_analysis(PyObject *, PyObject *); +static PyObject *py_known_format_analyze(PyObject *, PyObject *); /* Indique la désignation interne du format. */ static PyObject *py_known_format_get_key(PyObject *, void *); @@ -108,8 +100,7 @@ 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; } @@ -143,9 +134,6 @@ static int py_known_format_init(PyObject *self, PyObject *args, PyObject *kwds) "* pychrysalide.format.KnownFormat._get_description();\n" \ "* pychrysalide.format.KnownFormat._analyze().\n" \ "\n" \ - "The following method may also be defined for new classes too:\n" \ - "* pychrysalide.format.KnownFormat._complete_analysis().\n" \ - "\n" \ "Calls to the *__init__* constructor of this abstract object expect"\ " only one argument: a binary content, provided as a" \ " pychrysalide.analysis.BinContent instance." @@ -298,12 +286,10 @@ static char *py_known_format_get_description_wrapper(const GKnownFormat *format) } -#if 0 + /****************************************************************************** * * * Paramètres : format = format chargé dont l'analyse est lancée. * -* gid = groupe de travail dédié. * -* status = barre de statut à tenir informée. * * * * Description : Assure l'interprétation d'un format en différé. * * * @@ -313,12 +299,11 @@ static char *py_known_format_get_description_wrapper(const GKnownFormat *format) * * ******************************************************************************/ -static bool py_known_format_analyze_wrapper(GKnownFormat *format, wgroup_id_t gid, GtkStatusStack *status) +static bool py_known_format_analyze_wrapper(GKnownFormat *format) { bool result; /* Bilan à retourner */ PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ - PyObject *args; /* Arguments pour l'appel */ PyObject *pyret; /* Bilan d'exécution */ #define KNOWN_FORMAT_ANALYZE_WRAPPER PYTHON_WRAPPER_DEF \ @@ -328,12 +313,8 @@ static bool py_known_format_analyze_wrapper(GKnownFormat *format, wgroup_id_t gi "Abstract method used to start the analysis of the known" \ " format and return its status.\n" \ "\n" \ - "The identifier refers to the working queue used to process" \ - " the analysis. A reference to the main status bar may also be" \ - " provided, as a pychrysalide.gtkext.StatusStack instance if" \ - " running in graphical mode or None otherwise.\n" \ - "\n" \ - "The expected result of the call is a boolean." \ + "The expected result of the call is a boolean value: *True* in" \ + " case of success, *False* in case of failure." \ ) result = false; @@ -344,16 +325,10 @@ static bool py_known_format_analyze_wrapper(GKnownFormat *format, wgroup_id_t gi if (has_python_method(pyobj, "_analyze")) { - args = PyTuple_New(2); - - PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(gid)); - PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(status))); - - pyret = run_python_method(pyobj, "_analyze", args); + pyret = run_python_method(pyobj, "_analyze", NULL); result = (pyret == Py_True); - Py_DECREF(args); Py_XDECREF(pyret); } @@ -367,71 +342,12 @@ static bool py_known_format_analyze_wrapper(GKnownFormat *format, wgroup_id_t gi } -/****************************************************************************** -* * -* Paramètres : format = format chargé dont l'analyse est lancée. * -* gid = groupe de travail dédié. * -* status = barre de statut à tenir informée. * -* * -* Description : Réalise un traitement post-désassemblage. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_known_format_complete_analysis_wrapper(GKnownFormat *format, wgroup_id_t gid, GtkStatusStack *status) -{ - PyGILState_STATE gstate; /* Sauvegarde d'environnement */ - PyObject *pyobj; /* Objet Python concerné */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *pyret; /* Bilan d'exécution */ - -#define KNOWN_FORMAT_COMPLETE_ANALYSIS_WRAPPER PYTHON_VOID_WRAPPER_DEF \ -( \ - _complete_analysis, "$self, gid, status, /", \ - METH_VARARGS, \ - "Abstract method used to complete an analysis of a known format.\n" \ - "\n" \ - "The identifier refers to the working queue used to process the" \ - " analysis. A reference to the main status bar may also be" \ - " provided, as a pychrysalide.gtkext.StatusStack instance if" \ - " running in graphical mode or None otherwise.\n" \ -) - - gstate = PyGILState_Ensure(); - - pyobj = pygobject_new(G_OBJECT(format)); - - if (has_python_method(pyobj, "_complete_analysis")) - { - args = PyTuple_New(2); - - PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(gid)); - PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(status))); - - pyret = run_python_method(pyobj, "_complete_analysis", args); - - Py_DECREF(args); - Py_XDECREF(pyret); - - } - - Py_DECREF(pyobj); - - PyGILState_Release(gstate); - -} -#endif - /* ---------------------------------------------------------------------------------- */ /* DEFINITION DU FORMAT CONNU */ /* ---------------------------------------------------------------------------------- */ -#if 0 /****************************************************************************** * * * Paramètres : self = objet représentant un format connu. * @@ -448,33 +364,24 @@ static void py_known_format_complete_analysis_wrapper(GKnownFormat *format, wgro static PyObject *py_known_format_analyze(PyObject *self, PyObject *args) { PyObject *result; /* Bilan à retourner */ - int ret; /* Bilan de lecture des args. */ GKnownFormat *format; /* Format connu manipulé */ bool status; /* Bilan de l'opération */ #define KNOWN_FORMAT_ANALYZE_METHOD PYTHON_METHOD_DEF \ ( \ - analyze, "$self, gid, status, /", \ - METH_VARARGS, py_known_format, \ + analyze, "$self", \ + METH_NOARGS, py_known_format, \ "Start the analysis of the known format and return its status." \ "\n" \ "Once this analysis is done, a few early symbols and the" \ " mapped sections are expected to be defined, if any.\n" \ "\n" \ - "The identifier refers to the working queue used to process" \ - " the analysis. A reference to the main status bar may also be" \ - " provided, as a pychrysalide.gtkext.StatusStack instance if" \ - " running in graphical mode or None otherwise.\n" \ - "\n" \ "The return value is a boolean status of the operation." \ ) - ret = PyArg_ParseTuple(args, "");//|KO!", &gid, &status); - if (!ret) return NULL; - format = G_KNOWN_FORMAT(pygobject_get(self)); - status = g_known_format_analyze(format, 0, NULL); + status = g_known_format_analyze(format); result = status ? Py_True : Py_False; Py_INCREF(result); @@ -486,58 +393,6 @@ static PyObject *py_known_format_analyze(PyObject *self, PyObject *args) /****************************************************************************** * * -* Paramètres : self = objet représentant un format connu. * -* args = arguments fournis pour l'opération. * -* * -* Description : Réalise un traitement post-désassemblage. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_known_format_complete_analysis(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à retourner */ - int ret; /* Bilan de lecture des args. */ - GKnownFormat *format; /* Format connu manipulé */ - -#define KNOWN_FORMAT_COMPLETE_ANALYSIS_METHOD PYTHON_METHOD_DEF \ -( \ - complete_analysis, "$self, gid, status, /", \ - METH_VARARGS, py_known_format, \ - "Complete an analysis of a known format.\n" \ - "\n" \ - "This process is usually done once the disassembling process" \ - " is completed.\n" \ - "\n" \ - "The identifier refers to the working queue used to process" \ - " the analysis. A reference to the main status bar may also be" \ - " provided, as a pychrysalide.gtkext.StatusStack instance if" \ - " running in graphical mode or None otherwise.\n" \ - "\n" \ - "The return value is a boolean status of the operation." \ -) - - ret = PyArg_ParseTuple(args, "");//|KO!", &gid, &status); - if (!ret) return NULL; - - format = G_KNOWN_FORMAT(pygobject_get(self)); - - g_known_format_complete_analysis(format, 0, NULL); - - result = Py_None; - Py_INCREF(result); - - return result; - -} -#endif - - -/****************************************************************************** -* * * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * @@ -718,10 +573,8 @@ 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_ANALYZE_METHOD, { NULL } }; diff --git a/plugins/pychrysalide/format/program.c b/plugins/pychrysalide/format/program.c index d96c2db..28c1540 100644 --- a/plugins/pychrysalide/format/program.c +++ b/plugins/pychrysalide/format/program.c @@ -35,6 +35,8 @@ #include "../access.h" #include "../constants.h" #include "../helpers.h" +#include "../analysis/content.h" +#include "../arch/vmpa.h" /* @@ -44,7 +46,6 @@ #include "symiter.h" #include "../analysis/constants.h" #include "../analysis/content.h" -#include "../arch/vmpa.h" #include "../arch/constants.h" */ @@ -64,6 +65,9 @@ static int py_program_format_init(PyObject *, PyObject *, PyObject *); /* Indique le boutisme employé par le format binaire analysé. */ static SourceEndian py_program_format_get_endianness_wrapper(const GProgramFormat *); +/* Fournit l'emplacement d'une section donnée. */ +static bool py_program_format_get_section_range_by_name_wrapper(const GProgramFormat *, const char *, mrange_t *); + /* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */ @@ -78,7 +82,14 @@ static PyObject *py_program_format_unset_flag(PyObject *, PyObject *); /* Détermine si un format possède un fanion particulier. */ static PyObject *py_program_format_has_flag(PyObject *, PyObject *); +#endif + + +/* Fournit l'emplacement d'une section donnée. */ +static PyObject *py_program_format_get_section_range_by_name(PyObject *, PyObject *); + +#if 0 /* Enregistre une adresse comme début d'une zone de code. */ static PyObject *py_program_format_register_code_point(PyObject *, PyObject *); @@ -143,6 +154,7 @@ static PyObject *py_program_format_get_errors(PyObject *, void *); static void py_program_format_init_gclass(GProgramFormatClass *class, gpointer unused) { class->get_endian = py_program_format_get_endianness_wrapper; + class->get_range_by_name = py_program_format_get_section_range_by_name_wrapper; } @@ -163,25 +175,42 @@ static void py_program_format_init_gclass(GProgramFormatClass *class, gpointer u static int py_program_format_init(PyObject *self, PyObject *args, PyObject *kwds) { + GBinContent *content; /* Contenu à intégrer au format*/ int ret; /* Bilan de lecture des args. */ - -#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" \ - "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." + GProgramFormat *format; /* Format à manipuler */ + +#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" \ + "The following method has to be defined for new classes:\n" \ + "* pychrysalide.format.ProgramFormat._get_endianness().\n" \ + "\n" \ + "Other optional method may be defined for new classes:\n" \ + "* pychrysalide.format.ProgramFormat._get_section_range_by_name().\n" \ + "\n" \ + "Calls to the *__init__* constructor of this abstract object expect" \ + " only one argument: a binary content, provided as a" \ + " pychrysalide.analysis.BinContent instance." + + /* Récupération des paramètres */ + + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content); + if (!ret) return -1; /* Initialisation d'un objet GLib */ ret = forward_pygobjet_init(self); if (ret == -1) return -1; + /* Eléments de base */ + + format = G_PROGRAM_FORMAT(pygobject_get(self)); + + if (!g_program_format_create(format, content)) + return -1; + return 0; } @@ -252,11 +281,84 @@ static SourceEndian py_program_format_get_endianness_wrapper(const GProgramForma } +/****************************************************************************** +* * +* Paramètres : format = description du programme à consulter. * +* name = nom de la section recherchée. * +* range = emplacement en mémoire à renseigner. [OUT] * +* * +* Description : Fournit l'emplacement d'une section donnée. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_program_format_get_section_range_by_name_wrapper(const GProgramFormat *format, const char *name, mrange_t *range) +{ + bool result; /* Bilan à retourner */ + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ + PyObject *pyobj; /* Objet Python concerné */ + PyObject *pyret; /* Valeur retournée */ + int ret; /* Bilan d'une conversion */ + +#define PROGRAM_FORMAT_GET_SECTION_RANGE_BY_NAME_WRAPPER PYTHON_WRAPPER_DEF \ +( \ + _get_section_range_by_name_wrapper, "$self, name", \ + METH_VARARGS, \ + "Abstract method used to compute the area of a section identified by" \ + " its name.\n" \ + "\n" \ + "The expected returned value is a pychrysalide.arch.mrange instance or" \ + " *None* in case of failure." \ +) + + result = false; + + gstate = PyGILState_Ensure(); + + pyobj = pygobject_new(G_OBJECT(format)); + + if (has_python_method(pyobj, "_get_section_range_by_name")) + { + pyret = run_python_method(pyobj, "_get_section_range_by_name", NULL); + + if (pyret != NULL) + { + if (pyret == Py_None) + result = false; + + else + { + ret = convert_any_to_mrange(pyret, range); + + result = (ret == 1); + + if (!result) + PyErr_Clear(); + + } + + Py_DECREF(pyret); + + } + + } + + Py_DECREF(pyobj); + + PyGILState_Release(gstate); + + return result; + +} + + /* ---------------------------------------------------------------------------------- */ /* FORMAT BINAIRE GENERIQUE */ /* ---------------------------------------------------------------------------------- */ - #if 0 /****************************************************************************** * * @@ -402,10 +504,66 @@ static PyObject *py_program_format_has_flag(PyObject *self, PyObject *args) return result; } +#endif /****************************************************************************** * * +* Paramètres : self = serveur à manipuler. * +* args = arguments d'appel non utilisés ici. * +* * +* Description : Fournit l'emplacement d'une section donnée. * +* * +* Retour : Emplacement ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_program_format_get_section_range_by_name(PyObject *self, PyObject *args) +{ + PyObject *result; /* Emplacement à retourner */ + const char *name; /* Nom de section ciblée */ + int ret; /* Bilan de lecture des args. */ + GProgramFormat *format; /* Elément à manipuler */ + mrange_t range; /* Emplacement obtenu ? */ + bool status; /* Bilan de l'opération */ + +#define PROGRAM_FORMAT_GET_SECTION_RANGE_BY_NAME_METHOD PYTHON_METHOD_DEF \ +( \ + get_section_range_by_name, "$self, name, /", \ + METH_VARARGS, py_program_format, \ + "Compute the area of a section identified by its name.\n" \ + "\n" \ + "The *name* argument is a string value.\n" \ + "\n" \ + "The returned value is a pychrysalide.arch.mrange instance or" \ + " *None* in case of failure." \ +) + + ret = PyArg_ParseTuple(args, "s", &name); + if (!ret) return NULL; + + format = G_PROGRAM_FORMAT(pygobject_get(self)); + + status = g_program_format_get_section_range_by_name(format, name, &range); + + if (status) + result = build_from_internal_mrange(&range); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + +#if 0 +/****************************************************************************** +* * * Paramètres : self = classe représentant un format. * * args = arguments fournis à l'appel. * * * @@ -1036,6 +1194,8 @@ PyTypeObject *get_python_program_format_type(void) { static PyMethodDef py_program_format_methods[] = { PROGRAM_FORMAT_GET_ENDIANNESS_WRAPPER, + PROGRAM_FORMAT_GET_SECTION_RANGE_BY_NAME_WRAPPER, + PROGRAM_FORMAT_GET_SECTION_RANGE_BY_NAME_METHOD, /* PROGRAM_FORMAT_SET_FLAG_METHOD, PROGRAM_FORMAT_UNSET_FLAG_METHOD, diff --git a/plugins/pychrysalide/glibext/Makefile.am b/plugins/pychrysalide/glibext/Makefile.am index e9c3756..8b021bb 100644 --- a/plugins/pychrysalide/glibext/Makefile.am +++ b/plugins/pychrysalide/glibext/Makefile.am @@ -2,9 +2,7 @@ noinst_LTLIBRARIES = libpychrysaglibext.la # libpychrysaglibext_la_SOURCES = \ -# constants.h constants.c \ # binarycursor.h binarycursor.c \ -# binportion.h binportion.c \ # buffercache.h buffercache.c \ # bufferline.h bufferline.c \ # comparison.h comparison.c \ @@ -24,7 +22,9 @@ noinst_LTLIBRARIES = libpychrysaglibext.la # endif libpychrysaglibext_la_SOURCES = \ + constants.h constants.c \ module.h module.c \ + portion.h portion.c \ work.h work.c \ workqueue.h workqueue.c diff --git a/plugins/pychrysalide/glibext/constants.c b/plugins/pychrysalide/glibext/constants.c index 169ffa2..90ce8cd 100644 --- a/plugins/pychrysalide/glibext/constants.c +++ b/plugins/pychrysalide/glibext/constants.c @@ -25,16 +25,18 @@ #include "constants.h" +#include <glibext/portion.h> + +/* #include <i18n.h> #include <glibext/bufferline.h> #include <glibext/comparison.h> #include <glibext/configuration.h> #include <glibext/linesegment.h> -#include <glibext/gbinportion.h> #ifdef INCLUDE_GTK_SUPPORT # include <glibext/gloadedpanel.h> #endif - +*/ #include "../helpers.h" @@ -58,6 +60,7 @@ bool define_binary_portion_constants(PyTypeObject *type) PyObject *strdict; /* Groupe de chaînes constantes*/ PyObject *values; /* Groupe de valeurs à établir */ + /* result = create_string_constants_group_to_type(type, "BinaryPortionCode", "Selector names for the CSS rendering.", &strdict); @@ -69,6 +72,7 @@ bool define_binary_portion_constants(PyTypeObject *type) if (!result) goto exit; + */ values = PyDict_New(); @@ -150,6 +154,7 @@ int convert_to_portion_access_rights(PyObject *arg, void *dst) } +#if 0 /****************************************************************************** * * * Paramètres : type = type dont le dictionnaire est à compléter. * @@ -617,3 +622,4 @@ int convert_to_scroll_position_tweak(PyObject *arg, void *dst) #endif +#endif diff --git a/plugins/pychrysalide/glibext/constants.h b/plugins/pychrysalide/glibext/constants.h index 4a4f6da..a950125 100644 --- a/plugins/pychrysalide/glibext/constants.h +++ b/plugins/pychrysalide/glibext/constants.h @@ -37,6 +37,8 @@ bool define_binary_portion_constants(PyTypeObject *); /* Tente de convertir en constante PortionAccessRights. */ int convert_to_portion_access_rights(PyObject *, void *); +#if 0 + /* Définit les constantes relatives aux lignes de tampon. */ bool define_buffer_line_constants(PyTypeObject *); @@ -68,6 +70,8 @@ int convert_to_scroll_position_tweak(PyObject *, void *); #endif +#endif + #endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_CONSTANTS_H */ diff --git a/plugins/pychrysalide/glibext/module.c b/plugins/pychrysalide/glibext/module.c index 23e7a7d..e62d587 100644 --- a/plugins/pychrysalide/glibext/module.c +++ b/plugins/pychrysalide/glibext/module.c @@ -30,7 +30,6 @@ /* #include "binarycursor.h" -#include "binportion.h" #include "buffercache.h" #include "bufferline.h" #include "bufferview.h" @@ -42,6 +41,7 @@ #include "named.h" #include "singleton.h" */ +#include "portion.h" #include "work.h" #include "workqueue.h" #include "../helpers.h" @@ -110,6 +110,7 @@ bool populate_glibext_module(void) result = true; + if (result) result = ensure_python_binary_portion_is_registered(); if (result) result = ensure_python_generic_work_is_registered(); if (result) result = ensure_python_work_queue_is_registered(); @@ -117,7 +118,6 @@ bool populate_glibext_module(void) if (result) result = ensure_python_singleton_candidate_is_registered(); if (result) result = ensure_python_binary_cursor_is_registered(); - if (result) result = ensure_python_binary_portion_is_registered(); if (result) result = ensure_python_buffer_cache_is_registered(); if (result) result = ensure_python_buffer_line_is_registered(); #ifdef INCLUDE_GTK_SUPPORT diff --git a/plugins/pychrysalide/glibext/portion.c b/plugins/pychrysalide/glibext/portion.c index 70eb314..d95308c 100644 --- a/plugins/pychrysalide/glibext/portion.c +++ b/plugins/pychrysalide/glibext/portion.c @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * binportion.c - équivalent Python du fichier "glibext/gbinportion.c" + * portion.c - équivalent Python du fichier "glibext/portion.c" * * Copyright (C) 2019-2020 Cyrille Bagard * @@ -22,15 +22,14 @@ */ -#include "binportion.h" +#include "portion.h" #include <pygobject.h> #include <i18n.h> -#include <glibext/gbinportion-int.h> -#include <plugins/dt.h> +#include <glibext/portion-int.h> #include "constants.h" @@ -40,13 +39,13 @@ -/* Accompagne la création d'une instance dérivée en Python. */ -static PyObject *py_bin_portion_new(PyTypeObject *, PyObject *, PyObject *); +CREATE_DYN_CONSTRUCTOR(binary_portion, G_TYPE_BINARY_PORTION); + /* Initialise une instance sur la base du dérivé de GObject. */ -static int py_bin_portion_init(PyObject *, PyObject *, PyObject *); +static int py_binary_portion_init(PyObject *, PyObject *, PyObject *); -/* Effectue une comparaison avec un objet Python 'BinPortion'. */ +/* Effectue une comparaison avec un objet Python BinaryPortion. */ static PyObject *py_binary_portion_richcompare(PyObject *, PyObject *, int); /* Assure qu'une portion ne dépasse pas une position donnée. */ @@ -77,66 +76,6 @@ static int py_binary_portion_set_rights(PyObject *, PyObject *, void *); /****************************************************************************** * * -* Paramètres : type = type du nouvel objet à mettre en place. * -* args = éventuelle liste d'arguments. * -* kwds = éventuel dictionnaire de valeurs mises à disposition. * -* * -* Description : Accompagne la création d'une instance dérivée en Python. * -* * -* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bin_portion_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_binary_portion_type(); - - if (type == base) - goto simple_way; - - /* Mise en place d'un type dédié */ - - first_time = (g_type_from_name(type->tp_name) == 0); - - gtype = build_dynamic_type(G_TYPE_BIN_PORTION, type->tp_name, NULL, NULL, NULL); - - if (first_time) - { - status = register_class_for_dynamic_pygobject(gtype, type); - - if (!status) - { - result = NULL; - goto exit; - } - - } - - /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */ - - simple_way: - - result = PyType_GenericNew(type, args, kwds); - - exit: - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : self = objet à initialiser (théoriquement). * * args = arguments fournis à l'appel. * * kwds = arguments de type key=val fournis. * @@ -149,33 +88,30 @@ static PyObject *py_bin_portion_new(PyTypeObject *type, PyObject *args, PyObject * * ******************************************************************************/ -static int py_bin_portion_init(PyObject *self, PyObject *args, PyObject *kwds) +static int py_binary_portion_init(PyObject *self, PyObject *args, PyObject *kwds) { - const char *code; /* Identifiant de couleur */ vmpa2t *addr; /* Emplacement de portion */ unsigned long long size; /* Taille de la portion */ int ret; /* Bilan de lecture des args. */ - GBinPortion *portion; /* Portion à manipuler */ + GBinaryPortion *portion; /* Portion à manipuler */ - static char *kwlist[] = { "code", "addr", "size", NULL }; + static char *kwlist[] = { "addr", "size", NULL }; #define BINARY_PORTION_DOC \ - "The BinPortion object handles parts of binaries usually formally" \ + "The BinaryPortion object handles parts of binaries usually formally" \ " identified in binary formats, like program segments or sections for ELF" \ " files for example.\n" \ "\n" \ "Instances can be created using the following constructor:\n" \ "\n" \ - " BinPortion(code, addr, size)" \ + " BinaryPortion(addr, size)" \ "\n" \ - "Where code is the CSS class style for the rendering color to use, addr is" \ - " the starting point of the portion in memory, as a pychrysalide.arch.vmpa" \ - " value, and size is the size of the portion." \ + "Where *addr* is the starting point of the portion in memory, as a" \ + " pychrysalide.arch.vmpa value, and *size* is the size of the portion." /* Récupération des paramètres */ - ret = PyArg_ParseTupleAndKeywords(args, kwds, "sO&K", kwlist, - &code, convert_any_to_vmpa, &addr, &size); + ret = PyArg_ParseTupleAndKeywords(args, kwds, "O&K", kwlist, convert_any_to_vmpa, &addr, &size); if (!ret) return -1; /* Initialisation d'un objet GLib */ @@ -189,11 +125,13 @@ static int py_bin_portion_init(PyObject *self, PyObject *args, PyObject *kwds) /* Eléments de base */ - portion = G_BIN_PORTION(pygobject_get(self)); - - portion->code = strdup(code); + portion = G_BINARY_PORTION(pygobject_get(self)); - init_mrange(&portion->range, addr, size); + if (!g_binary_portion_create(portion, addr, size)) + { + clean_vmpa_arg(addr); + return -1; + } clean_vmpa_arg(addr); @@ -208,7 +146,7 @@ static int py_bin_portion_init(PyObject *self, PyObject *args, PyObject *kwds) * b = second object Python à consulter. * * op = type de comparaison menée. * * * -* Description : Effectue une comparaison avec un objet Python 'BinPortion'. * +* Description : Effectue une comparaison avec un objet Python BinaryPortion. * * * * Retour : Bilan de l'opération. * * * @@ -220,8 +158,8 @@ static PyObject *py_binary_portion_richcompare(PyObject *a, PyObject *b, int op) { PyObject *result; /* Bilan à retourner */ int ret; /* Bilan de lecture des args. */ - const GBinPortion *portion_a; /* Premier élément à traiter */ - const GBinPortion *portion_b; /* Second élément à traiter */ + const GBinaryPortion *portion_a; /* Premier élément à traiter */ + const GBinaryPortion *portion_b; /* Second élément à traiter */ int status; /* Résultat d'une comparaison */ ret = PyObject_IsInstance(b, (PyObject *)get_python_binary_portion_type()); @@ -231,8 +169,8 @@ static PyObject *py_binary_portion_richcompare(PyObject *a, PyObject *b, int op) goto cmp_done; } - portion_a = G_BIN_PORTION(pygobject_get(a)); - portion_b = G_BIN_PORTION(pygobject_get(b)); + portion_a = G_BINARY_PORTION(pygobject_get(a)); + portion_b = G_BINARY_PORTION(pygobject_get(b)); status = g_binary_portion_compare(&portion_a, &portion_b); @@ -265,16 +203,16 @@ static PyObject *py_binary_portion_limit_range(PyObject *self, PyObject *args) PyObject *result; /* Trouvailles à retourner */ unsigned long long max; /* Taille maximale à accorder */ int ret; /* Bilan de lecture des args. */ - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ bool status; /* Bilan de la modification */ -#define BINARY_SYMBOL_LIMIT_RANGE_METHOD PYTHON_METHOD_DEF \ +#define BINARY_PORTION_LIMIT_RANGE_METHOD PYTHON_METHOD_DEF \ ( \ limit_range, "$self, max, /", \ METH_VARARGS, py_binary_portion, \ "Ensure the portion range does not cross a boundary size.\n" \ "\n" \ - "An integer value is expected as the maximum size of the" \ + "An *max* integer value is expected as the maximum size of the" \ " portion.\n" \ "\n" \ "A boolean value indicating the success of the operation is" \ @@ -284,7 +222,7 @@ static PyObject *py_binary_portion_limit_range(PyObject *self, PyObject *args) ret = PyArg_ParseTuple(args, "K", &max); if (!ret) return NULL; - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); status = g_binary_portion_limit_range(portion, max); @@ -311,24 +249,27 @@ static PyObject *py_binary_portion_limit_range(PyObject *self, PyObject *args) static PyObject *py_binary_portion_include(PyObject *self, PyObject *args) { - GBinPortion *sub; /* Sous-portion à inclure */ + GBinaryPortion *sub; /* Sous-portion à inclure */ int ret; /* Bilan de lecture des args. */ - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ -#define BINARY_SYMBOL_INCLUDE_METHOD PYTHON_METHOD_DEF \ -( \ - include, "$self, sub, /", \ - METH_VARARGS, py_binary_portion, \ - "Include another binary portion as a child item.\n" \ - "\n" \ - "The sub portion has to be a pychrysalide.glibext.BinPortion" \ - " instance." \ +#define BINARY_PORTION_INCLUDE_METHOD PYTHON_METHOD_DEF \ +( \ + include, "$self, sub, /", \ + METH_VARARGS, py_binary_portion, \ + "Include another binary portion as a child item.\n" \ + "\n" \ + "The provided *sub* portion has to be a" \ + " pychrysalide.glibext.BinaryPortion instance." \ + "\n" \ + "The returned value is a boolean value providing the" \ + " status of the operation." \ ) ret = PyArg_ParseTuple(args, "O&", convert_to_binary_portion, &sub); if (!ret) return NULL; - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); g_object_ref(G_OBJECT(sub)); g_binary_portion_include(portion, sub); @@ -354,7 +295,7 @@ static PyObject *py_binary_portion_include(PyObject *self, PyObject *args) static PyObject *py_binary_portion_get_desc(PyObject *self, void *closure) { PyObject *result; /* Résultat à retourner */ - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ const char *desc; /* Description récupérée */ #define BINARY_PORTION_DESC_ATTRIB PYTHON_GETSET_DEF_FULL \ @@ -364,7 +305,7 @@ static PyObject *py_binary_portion_get_desc(PyObject *self, void *closure) " simple string." \ ) - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); desc = g_binary_portion_get_desc(portion); @@ -391,7 +332,7 @@ static PyObject *py_binary_portion_get_desc(PyObject *self, void *closure) static int py_binary_portion_set_desc(PyObject *self, PyObject *value, void *closure) { - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ const char *desc; /* Description à définir */ if (!PyUnicode_Check(value)) @@ -400,7 +341,7 @@ static int py_binary_portion_set_desc(PyObject *self, PyObject *value, void *clo return -1; } - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); desc = PyUnicode_DATA(value); @@ -427,7 +368,7 @@ static int py_binary_portion_set_desc(PyObject *self, PyObject *value, void *clo static PyObject *py_binary_portion_get_range(PyObject *self, void *closure) { PyObject *result; /* Résultat à retourner */ - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ const mrange_t *range; /* Espace de couverture */ #define BINARY_PORTION_RANGE_ATTRIB PYTHON_GET_DEF_FULL \ @@ -438,7 +379,7 @@ static PyObject *py_binary_portion_get_range(PyObject *self, void *closure) "This property is a pychrysalide.arch.mrange instance." \ ) - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); range = g_binary_portion_get_range(portion); @@ -465,7 +406,7 @@ static PyObject *py_binary_portion_get_range(PyObject *self, void *closure) static PyObject *py_binary_portion_get_continuation(PyObject *self, void *closure) { PyObject *result; /* Résultat à retourner */ - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ bool status; /* Bilan d'une consultation */ #define BINARY_PORTION_CONTINUATION_ATTRIB PYTHON_GETSET_DEF_FULL \ @@ -478,7 +419,7 @@ static PyObject *py_binary_portion_get_continuation(PyObject *self, void *closur " several parts when included in the portion tree." \ ) - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); status = g_binary_portion_is_continuation(portion); @@ -506,7 +447,7 @@ static PyObject *py_binary_portion_get_continuation(PyObject *self, void *closur static int py_binary_portion_set_continuation(PyObject *self, PyObject *value, void *closure) { - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ bool status; /* Valeur à manipuler */ if (!PyBool_Check(value)) @@ -515,7 +456,7 @@ static int py_binary_portion_set_continuation(PyObject *self, PyObject *value, v return -1; } - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); status = (value == Py_True); @@ -542,17 +483,17 @@ static int py_binary_portion_set_continuation(PyObject *self, PyObject *value, v static PyObject *py_binary_portion_get_rights(PyObject *self, void *closure) { PyObject *result; /* Résultat à retourner */ - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ PortionAccessRights rights; /* Bilan d'une consultation */ #define BINARY_PORTION_RIGHTS_ATTRIB PYTHON_GETSET_DEF_FULL \ ( \ rights, py_binary_portion, \ "Access rights declared for the binary portion, as a" \ - " pychrysalide.glibext.BinPortion.PortionAccessRights value." \ + " pychrysalide.glibext.BinaryPortion.PortionAccessRights value."\ ) - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); rights = g_binary_portion_get_rights(portion); @@ -579,13 +520,13 @@ static PyObject *py_binary_portion_get_rights(PyObject *self, void *closure) static int py_binary_portion_set_rights(PyObject *self, PyObject *value, void *closure) { - GBinPortion *portion; /* Version GLib du type */ + GBinaryPortion *portion; /* Version GLib du type */ PortionAccessRights rights; /* Valeur à manipuler */ if (convert_to_portion_access_rights(value, &rights) != 1) return -1; - portion = G_BIN_PORTION(pygobject_get(self)); + portion = G_BINARY_PORTION(pygobject_get(self)); g_binary_portion_set_rights(portion, rights); @@ -609,8 +550,8 @@ static int py_binary_portion_set_rights(PyObject *self, PyObject *value, void *c PyTypeObject *get_python_binary_portion_type(void) { static PyMethodDef py_binary_portion_methods[] = { - BINARY_SYMBOL_LIMIT_RANGE_METHOD, - BINARY_SYMBOL_INCLUDE_METHOD, + BINARY_PORTION_LIMIT_RANGE_METHOD, + BINARY_PORTION_INCLUDE_METHOD, { NULL } }; @@ -626,7 +567,7 @@ PyTypeObject *get_python_binary_portion_type(void) PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pychrysalide.glibext.BinPortion", + .tp_name = "pychrysalide.glibext.BinaryPortion", .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, @@ -638,8 +579,8 @@ PyTypeObject *get_python_binary_portion_type(void) .tp_methods = py_binary_portion_methods, .tp_getset = py_binary_portion_getseters, - .tp_init = py_bin_portion_init, - .tp_new = py_bin_portion_new, + .tp_init = py_binary_portion_init, + .tp_new = py_binary_portion_new, }; @@ -652,7 +593,7 @@ PyTypeObject *get_python_binary_portion_type(void) * * * Paramètres : module = module dont la définition est à compléter. * * * -* Description : Prend en charge l'objet 'pychrysalide.glibext.BinPortion'. * +* Description : Prend en charge l'objet 'pychrysalide.glibext.BinaryPortion'.* * * * Retour : Bilan de l'opération. * * * @@ -662,7 +603,7 @@ PyTypeObject *get_python_binary_portion_type(void) bool ensure_python_binary_portion_is_registered(void) { - PyTypeObject *type; /* Type Python 'BinPortion' */ + PyTypeObject *type; /* Type Python 'BinaryPortion' */ PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ @@ -674,7 +615,7 @@ bool ensure_python_binary_portion_is_registered(void) dict = PyModule_GetDict(module); - if (!register_class_for_pygobject(dict, G_TYPE_BIN_PORTION, type)) + if (!register_class_for_pygobject(dict, G_TYPE_BINARY_PORTION, type)) return false; if (!define_binary_portion_constants(type)) @@ -718,7 +659,7 @@ int convert_to_binary_portion(PyObject *arg, void *dst) break; case 1: - *((GBinPortion **)dst) = G_BIN_PORTION(pygobject_get(arg)); + *((GBinaryPortion **)dst) = G_BINARY_PORTION(pygobject_get(arg)); break; default: diff --git a/plugins/pychrysalide/glibext/portion.h b/plugins/pychrysalide/glibext/portion.h index b27c8ea..a417c01 100644 --- a/plugins/pychrysalide/glibext/portion.h +++ b/plugins/pychrysalide/glibext/portion.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * binportion.h - prototypes pour l'équivalent Python du fichier "glibext/gbinportion.h" + * portion.h - prototypes pour l'équivalent Python du fichier "glibext/portion.h" * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -22,8 +22,8 @@ */ -#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_BINPORTION_H -#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_BINPORTION_H +#ifndef _PLUGINS_PYCHRYSALIDE_GLIBEXT_PORTION_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_PORTION_H #include <Python.h> @@ -34,7 +34,7 @@ /* Fournit un accès à une définition de type à diffuser. */ PyTypeObject *get_python_binary_portion_type(void); -/* Prend en charge l'objet 'pychrysalide.glibext.BinPortion'. */ +/* Prend en charge l'objet 'pychrysalide.glibext.BinaryPortion'. */ bool ensure_python_binary_portion_is_registered(void); /* Tente de convertir en portion de binaire. */ @@ -42,4 +42,4 @@ int convert_to_binary_portion(PyObject *, void *); -#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_BINPORTION_H */ +#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_PORTION_H */ |