summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r--plugins/pychrysalide/format/Makefile.am21
-rw-r--r--plugins/pychrysalide/format/executable.c635
-rw-r--r--plugins/pychrysalide/format/executable.h4
-rw-r--r--plugins/pychrysalide/format/flat.c66
-rw-r--r--plugins/pychrysalide/format/known.c338
-rw-r--r--plugins/pychrysalide/format/module.c20
-rw-r--r--plugins/pychrysalide/format/program.c (renamed from plugins/pychrysalide/format/format.c)627
-rw-r--r--plugins/pychrysalide/format/program.h (renamed from plugins/pychrysalide/format/format.h)29
8 files changed, 1122 insertions, 618 deletions
diff --git a/plugins/pychrysalide/format/Makefile.am b/plugins/pychrysalide/format/Makefile.am
index 337265d..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 \
- format.h format.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..f0d3d6b 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,29 +30,369 @@
#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 "../analysis/content.h"
+//#include "../arch/processor.h"
#include "../arch/vmpa.h"
-#include "../glibext/binportion.h"
+#include "../glibext/portion.h"
+
+
+
+/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
+
+
+/* Initialise la classe des formats exécutables. */
+static int py_executable_format_init_gclass(GExecutableFormatClass *, PyTypeObject *);
+
+CREATE_DYN_ABSTRACT_CONSTRUCTOR(executable_format, G_TYPE_EXECUTABLE_FORMAT);
+
+/* 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 *);
+
+/* 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_exe_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_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 *);
+
+/* 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 *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* GLUE POUR CREATION DEPUIS PYTHON */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : gclass = classe GLib à initialiser. *
+* pyclass = classe Python à initialiser. *
+* *
+* Description : Initialise la classe des formats exécutables. *
+* *
+* Retour : 0 pour indiquer un succès de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_executable_format_init_gclass(GExecutableFormatClass *gclass, PyTypeObject *pyclass)
+{
+ PY_CLASS_SET_WRAPPER(gclass->get_machine, py_executable_format_get_target_machine_wrapper);
+
+ PY_CLASS_SET_WRAPPER(gclass->get_main_addr, py_executable_format_get_main_address_wrapper);
+ PY_CLASS_SET_WRAPPER(gclass->refine_portions, py_executable_format_refine_portions_wrapper);
+
+ return 0;
+
+}
+
+
+/******************************************************************************
+* *
+* 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)
+{
+ 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 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"\
+ " 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;
+
+}
+
+
+/******************************************************************************
+* *
+* 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;
+
+}
+
+
+/******************************************************************************
+* *
+* 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;
+
+}
@@ -66,29 +406,54 @@ static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *, PyObject
* 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_exe_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. */
- GExeFormat *format; /* Version GLib du format */
-
- ret = PyArg_ParseTuple(args, "O&", convert_to_binary_portion, &portion);
+ 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&|O&", convert_to_binary_portion, &portion, convert_any_to_vmpa, &origin);
if (!ret) return NULL;
- format = G_EXE_FORMAT(pygobject_get(self));
+ format = G_EXECUTABLE_FORMAT(pygobject_get(self));
+
+ status = g_executable_format_include_portion(format, portion, origin);
- g_object_ref(G_OBJECT(portion));
- g_exe_format_register_user_portion(format, portion);
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
- Py_RETURN_NONE;
+ if (origin != NULL)
+ clean_vmpa_arg(origin);
+
+ return result;
}
@@ -106,22 +471,33 @@ 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));
- 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);
@@ -150,22 +526,33 @@ 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));
- 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);
@@ -183,6 +570,140 @@ static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *self, PyObj
/******************************************************************************
* *
+* 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;
+
+}
+
+
+/******************************************************************************
+* *
+* 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. *
@@ -195,46 +716,43 @@ 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[] = {
- {
- "register_user_portion", py_exe_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,
- 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,
- METH_VARARGS,
- "translate_address_into_vmpa($self, addr, /)\n--\n\nTranslate a physical offset to a full location."
- },
+ static PyMethodDef py_executable_format_methods[] = {
+ EXECUTABLE_FORMAT_GET_TARGET_MACHINE_WRAPPER,
+ 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_exe_format_getseters[] = {
+ static PyGetSetDef py_executable_format_getseters[] = {
+ EXECUTABLE_FORMAT_TARGET_MACHINE_ATTRIB,
+ EXECUTABLE_FORMAT_MAIN_ADDRESS_ATTRIB,
+ EXECUTABLE_FORMAT_PORTIONS_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_exe_format_methods,
- .tp_getset = py_exe_format_getseters,
+ .tp_methods = py_executable_format_methods,
+ .tp_getset = py_executable_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 +783,12 @@ 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))
+ pyg_register_class_init(G_TYPE_EXECUTABLE_FORMAT, (PyGClassInitFunc)py_executable_format_init_gclass);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_EXECUTABLE_FORMAT, type))
return false;
}
@@ -309,7 +829,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 +848,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 +911,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..81f0dba 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,45 @@
#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" \
@@ -74,28 +76,32 @@ static PyObject *py_flat_format_new(PyTypeObject *type, PyObject *args, PyObject
"\n" \
" 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."
+ "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."
- 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..856c087 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,11 +41,10 @@
/* ------------------------ 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);
+static int py_known_format_init_gclass(GKnownFormatClass *, PyTypeObject *);
+
+CREATE_DYN_ABSTRACT_CONSTRUCTOR(known_format, G_TYPE_KNOWN_FORMAT);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_known_format_init(PyObject *, PyObject *, PyObject *);
@@ -58,10 +56,7 @@ static char *py_known_format_get_key_wrapper(const GKnownFormat *);
static char *py_known_format_get_description_wrapper(const GKnownFormat *);
/* 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 *);
+static bool py_known_format_analyze_wrapper(GKnownFormat *);
@@ -71,9 +66,6 @@ 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 *);
-
/* Indique la désignation interne du format. */
static PyObject *py_known_format_get_key(PyObject *, void *);
@@ -92,87 +84,25 @@ 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. *
+* Paramètres : gclass = classe GLib à initialiser. *
+* pyclass = classe Python à initialiser. *
* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
+* Description : Initialise la classe des formats connus. *
* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
+* Retour : 0 pour indiquer un succès de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_known_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_known_format_init_gclass(GKnownFormatClass *gclass, PyTypeObject *pyclass)
{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* 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;
- }
+ PY_CLASS_SET_WRAPPER(gclass->get_key, py_known_format_get_key_wrapper);
+ PY_CLASS_SET_WRAPPER(gclass->get_desc, py_known_format_get_description_wrapper);
- }
-
- /* 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. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ PY_CLASS_SET_WRAPPER(gclass->analyze, py_known_format_analyze_wrapper);
-static void py_known_format_init_gclass(GKnownFormatClass *class, gpointer unused)
-{
- 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;
+ return 0;
}
@@ -201,18 +131,11 @@ 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" \
- "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."
@@ -231,7 +154,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 +179,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 +271,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);
@@ -354,8 +292,6 @@ static char *py_known_format_get_description_wrapper(const GKnownFormat *format)
/******************************************************************************
* *
* 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é. *
* *
@@ -365,12 +301,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 \
@@ -380,12 +315,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;
@@ -396,16 +327,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);
}
@@ -419,64 +344,6 @@ 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);
-
-}
-
-
/* ---------------------------------------------------------------------------------- */
/* DEFINITION DU FORMAT CONNU */
@@ -499,33 +366,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);
@@ -537,57 +395,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;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -615,9 +422,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 +481,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 +573,10 @@ 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,
{ NULL }
};
@@ -789,6 +637,8 @@ bool ensure_python_known_format_is_registered(void)
dict = PyModule_GetDict(module);
+ pyg_register_class_init(G_TYPE_KNOWN_FORMAT, (PyGClassInitFunc)py_known_format_init_gclass);
+
if (!register_class_for_pygobject(dict, G_TYPE_KNOWN_FORMAT, type))
return false;
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/format.c b/plugins/pychrysalide/format/program.c
index 82c6c33..57a359a 100644
--- a/plugins/pychrysalide/format/format.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,115 @@
*/
-#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 "../analysis/content.h"
+#include "../arch/vmpa.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 int py_program_format_init_gclass(GProgramFormatClass *, PyTypeObject *);
-/* 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);
/* 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 *);
+
+/* Fournit l'emplacement d'une section donnée. */
+static bool py_program_format_find_section_range_by_name_wrapper(const GProgramFormat *, const char *, mrange_t *);
/* ---------------------------- 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 *);
+#endif
+
+
+/* Fournit l'emplacement d'une section donnée. */
+static PyObject *py_program_format_find_section_range_by_name(PyObject *, PyObject *);
+
+#if 0
/* 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,83 +140,23 @@ 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. *
+* Paramètres : gclass = classe GLib à initialiser. *
+* pyclass = classe Python à initialiser. *
* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
+* Description : Initialise la classe des formats de programmes. *
* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
+* Retour : 0 pour indiquer un succès de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_program_format_init_gclass(GProgramFormatClass *gclass, PyTypeObject *pyclass)
{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* 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:
+ PY_CLASS_SET_WRAPPER(gclass->get_endian, py_program_format_get_endianness_wrapper);
+ PY_CLASS_SET_WRAPPER(gclass->find_range_by_name, py_program_format_find_section_range_by_name_wrapper);
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : class = classe à initialiser. *
-* unused = données non utilisées ici. *
-* *
-* Description : Initialise la classe générique des processeurs. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void py_binary_format_init_gclass(GBinFormatClass *class, gpointer unused)
-{
- class->get_endian = py_binary_format_get_endianness_wrapper;
+ return 0;
}
@@ -221,27 +175,44 @@ 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)
{
+ GBinContent *content; /* Contenu à intégrer au format*/
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" \
- "\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" \
- "\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._find_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;
}
@@ -259,7 +230,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 +238,109 @@ 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);
+
+ }
+
+ }
+
+ Py_DECREF(pyobj);
+
+ PyGILState_Release(gstate);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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_find_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_FIND_SECTION_RANGE_BY_NAME_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _find_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, "_find_section_range_by_name"))
+ {
+ pyret = run_python_method(pyobj, "_find_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);
@@ -303,7 +361,7 @@ static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *fo
/* FORMAT BINAIRE GENERIQUE */
/* ---------------------------------------------------------------------------------- */
-
+#if 0
/******************************************************************************
* *
* Paramètres : self = serveur à manipuler. *
@@ -317,18 +375,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 +399,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 +424,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 +448,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 +473,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 +496,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);
@@ -448,10 +506,66 @@ static PyObject *py_binary_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_find_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_FIND_SECTION_RANGE_BY_NAME_METHOD PYTHON_METHOD_DEF \
+( \
+ find_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_find_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. *
* *
@@ -463,17 +577,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 +598,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 +620,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 +640,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 +666,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 +685,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 +710,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 +732,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 +765,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 +785,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 +823,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 +843,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 +881,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 +892,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 +907,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 +949,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 +986,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 +1024,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 +1052,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 +1074,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 +1095,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 +1122,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 +1137,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 +1147,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 +1172,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 +1192,56 @@ 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_FIND_SECTION_RANGE_BY_NAME_WRAPPER,
+ PROGRAM_FORMAT_FIND_SECTION_RANGE_BY_NAME_METHOD,
+ /*
+ 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 +1258,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 +1275,15 @@ 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))
+ pyg_register_class_init(G_TYPE_PROGRAM_FORMAT, (PyGClassInitFunc)py_program_format_init_gclass);
+
+ 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 +1305,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 +1323,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/format.h b/plugins/pychrysalide/format/program.h
index 04ac9e3..647d122 100644
--- a/plugins/pychrysalide/format/format.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 */