summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format/program.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-11-15 10:01:42 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-11-15 10:01:42 (GMT)
commit671f61ec87f5e8d762ea890aabbc62c777e1c4f9 (patch)
tree1517f5fc5d00c8fd04872b35571556b021866f14 /plugins/pychrysalide/format/program.c
parent3e21278480a25552401644cd0dc168e3588508dd (diff)
Restore a skeleton of support for file formats.
Diffstat (limited to 'plugins/pychrysalide/format/program.c')
-rw-r--r--plugins/pychrysalide/format/program.c445
1 files changed, 205 insertions, 240 deletions
diff --git a/plugins/pychrysalide/format/program.c b/plugins/pychrysalide/format/program.c
index 82c6c33..d96c2db 100644
--- a/plugins/pychrysalide/format/program.c
+++ b/plugins/pychrysalide/format/program.c
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * format.c - équivalent Python du fichier "format/format.c"
+ * program.c - équivalent Python du fichier "format/program.c"
*
- * Copyright (C) 2018-2020 Cyrille Bagard
+ * Copyright (C) 2018-2024 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -22,101 +22,104 @@
*/
-#include "format.h"
+#include "program.h"
#include <pygobject.h>
-#include <i18n.h>
-#include <format/format-int.h>
-#include <plugins/dt.h>
+#include <format/program-int.h>
+#include "known.h"
+#include "../access.h"
+#include "../constants.h"
+#include "../helpers.h"
+
+
+/*
#include "constants.h"
#include "executable.h"
-#include "known.h"
#include "symbol.h"
#include "symiter.h"
-#include "../access.h"
-#include "../helpers.h"
#include "../analysis/constants.h"
#include "../analysis/content.h"
#include "../arch/vmpa.h"
#include "../arch/constants.h"
+*/
/* ------------------------ GLUE POUR CREATION DEPUIS PYTHON ------------------------ */
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_binary_format_new(PyTypeObject *, PyObject *, PyObject *);
+/* Initialise la classe des formats de programmes. */
+static void py_program_format_init_gclass(GProgramFormatClass *, gpointer);
-/* Initialise la classe des descriptions de fichier binaire. */
-static void py_binary_format_init_gclass(GBinFormatClass *, gpointer);
+CREATE_DYN_ABSTRACT_CONSTRUCTOR(program_format, G_TYPE_PROGRAM_FORMAT, py_program_format_init_gclass);
/* Initialise une instance sur la base du dérivé de GObject. */
-static int py_binary_format_init(PyObject *, PyObject *, PyObject *);
+static int py_program_format_init(PyObject *, PyObject *, PyObject *);
/* Indique le boutisme employé par le format binaire analysé. */
-static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *);
+static SourceEndian py_program_format_get_endianness_wrapper(const GProgramFormat *);
/* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */
+#if 0
/* Ajoute une information complémentaire à un format. */
-static PyObject *py_binary_format_set_flag(PyObject *, PyObject *);
+static PyObject *py_program_format_set_flag(PyObject *, PyObject *);
/* Retire une information complémentaire à un format. */
-static PyObject *py_binary_format_unset_flag(PyObject *, PyObject *);
+static PyObject *py_program_format_unset_flag(PyObject *, PyObject *);
/* Détermine si un format possède un fanion particulier. */
-static PyObject *py_binary_format_has_flag(PyObject *, PyObject *);
+static PyObject *py_program_format_has_flag(PyObject *, PyObject *);
/* Enregistre une adresse comme début d'une zone de code. */
-static PyObject *py_binary_format_register_code_point(PyObject *, PyObject *);
+static PyObject *py_program_format_register_code_point(PyObject *, PyObject *);
/* Ajoute un symbole à la collection du format binaire. */
-static PyObject *py_binary_format_add_symbol(PyObject *, PyObject *);
+static PyObject *py_program_format_add_symbol(PyObject *, PyObject *);
/* Retire un symbole de la collection du format binaire. */
-static PyObject *py_binary_format_remove_symbol(PyObject *, PyObject *);
+static PyObject *py_program_format_remove_symbol(PyObject *, PyObject *);
/* Recherche le symbole correspondant à une étiquette. */
-static PyObject *py_binary_format_find_symbol_by_label(PyObject *, PyObject *);
+static PyObject *py_program_format_find_symbol_by_label(PyObject *, PyObject *);
/* Recherche le symbole suivant celui lié à une adresse. */
-static PyObject *py_binary_format_find_symbol_at(PyObject *, PyObject *);
+static PyObject *py_program_format_find_symbol_at(PyObject *, PyObject *);
/* Recherche le symbole suivant celui lié à une adresse. */
-static PyObject *py_binary_format_find_next_symbol_at(PyObject *, PyObject *);
+static PyObject *py_program_format_find_next_symbol_at(PyObject *, PyObject *);
/* Recherche le symbole correspondant à une adresse. */
-static PyObject *py_binary_format_resolve_symbol(PyObject *, PyObject *);
+static PyObject *py_program_format_resolve_symbol(PyObject *, PyObject *);
/* Fournit les particularités du format. */
-static PyObject *py_binary_format_get_flags(PyObject *, void *);
+static PyObject *py_program_format_get_flags(PyObject *, void *);
/* Indique le boutisme employé par le format binaire analysé. */
-static PyObject *py_binary_format_get_endianness(PyObject *, void *);
+static PyObject *py_program_format_get_endianness(PyObject *, void *);
/* Fournit la liste de tous les symboles détectés. */
-static PyObject *py_binary_format_get_symbols(PyObject *, void *);
-
+static PyObject *py_program_format_get_symbols(PyObject *, void *);
+#endif
/* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */
-
+#if 0
/* Etend la liste des soucis détectés avec de nouvelles infos. */
-static PyObject *py_binary_format_add_error(PyObject *, PyObject *);
+static PyObject *py_program_format_add_error(PyObject *, PyObject *);
/* Fournit les éléments concernant tous les soucis détectés. */
-static PyObject *py_binary_format_get_errors(PyObject *, void *);
-
+static PyObject *py_program_format_get_errors(PyObject *, void *);
+#endif
/* ---------------------------------------------------------------------------------- */
@@ -126,73 +129,10 @@ static PyObject *py_binary_format_get_errors(PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_binary_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* Validations diverses */
-
- base = get_python_known_format_type();
-
- if (type == base)
- {
- result = NULL;
- PyErr_Format(PyExc_RuntimeError, _("%s is an abstract class"), type->tp_name);
- goto exit;
- }
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_BIN_FORMAT, type->tp_name,
- (GClassInitFunc)py_binary_format_init_gclass, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
-
- if (!status)
- {
- result = NULL;
- goto exit;
- }
-
- }
-
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
-
- result = PyType_GenericNew(type, args, kwds);
-
- exit:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : class = classe à initialiser. *
* unused = données non utilisées ici. *
* *
-* Description : Initialise la classe générique des processeurs. *
+* Description : Initialise la classe des formats de programmes. *
* *
* Retour : - *
* *
@@ -200,9 +140,9 @@ static PyObject *py_binary_format_new(PyTypeObject *type, PyObject *args, PyObje
* *
******************************************************************************/
-static void py_binary_format_init_gclass(GBinFormatClass *class, gpointer unused)
+static void py_program_format_init_gclass(GProgramFormatClass *class, gpointer unused)
{
- class->get_endian = py_binary_format_get_endianness_wrapper;
+ class->get_endian = py_program_format_get_endianness_wrapper;
}
@@ -221,18 +161,18 @@ static void py_binary_format_init_gclass(GBinFormatClass *class, gpointer unused
* *
******************************************************************************/
-static int py_binary_format_init(PyObject *self, PyObject *args, PyObject *kwds)
+static int py_program_format_init(PyObject *self, PyObject *args, PyObject *kwds)
{
int ret; /* Bilan de lecture des args. */
-#define BINARY_FORMAT_DOC \
- "The BinFormat class is the major poart of binary format support." \
- " It is the core class used by loading most of the binary files.\n" \
+#define PROGRAM_FORMAT_DOC \
+ "The ProgramFormat class is the major part of binary format" \
+ " support. It is the core class used by loading most of the binary" \
+ " files.\n" \
+ "\n" \
"\n" \
- "One item has to be defined as class attribute in the final" \
- " class:\n" \
- "* *_endianness*: a pychrysalide.analysis.BinContent.SourceEndian" \
- " value indicating the endianness of the format.\n" \
+ "The following method has to be defined for new classes:\n" \
+ "* pychrysalide.format.ProgramFormat._get_endianness().\n" \
"\n" \
"Calls to the *__init__* constructor of this abstract object expect"\
" no particular argument."
@@ -259,7 +199,7 @@ static int py_binary_format_init(PyObject *self, PyObject *args, PyObject *kwds)
* *
******************************************************************************/
-static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *format)
+static SourceEndian py_program_format_get_endianness_wrapper(const GProgramFormat *format)
{
SourceEndian result; /* Boutisme à retourner */
PyGILState_STATE gstate; /* Sauvegarde d'environnement */
@@ -267,22 +207,35 @@ static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *fo
PyObject *pyret; /* Valeur retournée */
int ret; /* Bilan d'une conversion */
+#define PROGRAM_FORMAT_GET_ENDIANNESS_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _get_endianness_wrapper, "$self", \
+ METH_NOARGS, \
+ "Abstract method used to define the endianness of the format.\n"\
+ "\n" \
+ "The return value is of type pychrysalide.SourceEndian," \
+ " pychrysalide.SourceEndian.LITTLE by default." \
+)
+
result = SRE_LITTLE;
gstate = PyGILState_Ensure();
pyobj = pygobject_new(G_OBJECT(format));
- if (PyObject_HasAttrString(pyobj, "_endianness"))
+ if (has_python_method(pyobj, "_get_endianness"))
{
- pyret = PyObject_GetAttrString(pyobj, "_endianness");
+ pyret = run_python_method(pyobj, "_get_endianness", NULL);
if (pyret != NULL)
{
ret = convert_to_source_endian(pyret, &result);
if (ret != 1)
+ {
+ PyErr_Clear();
result = SRE_LITTLE;
+ }
Py_DECREF(pyret);
@@ -304,6 +257,7 @@ static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *fo
/* ---------------------------------------------------------------------------------- */
+#if 0
/******************************************************************************
* *
* Paramètres : self = serveur à manipuler. *
@@ -317,18 +271,18 @@ static SourceEndian py_binary_format_get_endianness_wrapper(const GBinFormat *fo
* *
******************************************************************************/
-static PyObject *py_binary_format_set_flag(PyObject *self, PyObject *args)
+static PyObject *py_program_format_set_flag(PyObject *self, PyObject *args)
{
PyObject *result; /* Bilan à retourner */
unsigned int flag; /* Propriété à traiter */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Elément à manipuler */
+ GProgramFormat *format; /* Elément à manipuler */
bool status; /* Bilan de l'opération */
-#define BINARY_FORMAT_SET_FLAG_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_SET_FLAG_METHOD PYTHON_METHOD_DEF \
( \
set_flag, "$self, flag, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Add a property from a binary format.\n" \
"\n" \
"This property is one of the values listed in the" \
@@ -341,9 +295,9 @@ static PyObject *py_binary_format_set_flag(PyObject *self, PyObject *args)
ret = PyArg_ParseTuple(args, "I", &flag);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- status = g_binary_format_set_flag(format, flag);
+ status = g_program_format_set_flag(format, flag);
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -366,18 +320,18 @@ static PyObject *py_binary_format_set_flag(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_unset_flag(PyObject *self, PyObject *args)
+static PyObject *py_program_format_unset_flag(PyObject *self, PyObject *args)
{
PyObject *result; /* Bilan à retourner */
unsigned int flag; /* Propriété à traiter */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Elément à manipuler */
+ GProgramFormat *format; /* Elément à manipuler */
bool status; /* Bilan de l'opération */
-#define BINARY_FORMAT_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_UNSET_FLAG_METHOD PYTHON_METHOD_DEF \
( \
unset_flag, "$self, flag, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Remove a property from a binary format.\n" \
"\n" \
"This property is one of the values listed in the" \
@@ -390,9 +344,9 @@ static PyObject *py_binary_format_unset_flag(PyObject *self, PyObject *args)
ret = PyArg_ParseTuple(args, "I", &flag);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- status = g_binary_format_unset_flag(format, flag);
+ status = g_program_format_unset_flag(format, flag);
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -415,18 +369,18 @@ static PyObject *py_binary_format_unset_flag(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_has_flag(PyObject *self, PyObject *args)
+static PyObject *py_program_format_has_flag(PyObject *self, PyObject *args)
{
PyObject *result; /* Bilan à retourner */
unsigned int flag; /* Propriété à traiter */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Elément à manipuler */
+ GProgramFormat *format; /* Elément à manipuler */
bool status; /* Bilan de l'opération */
-#define BINARY_FORMAT_HAS_FLAG_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_HAS_FLAG_METHOD PYTHON_METHOD_DEF \
( \
has_flag, "$self, flag, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Test if a binary format has a given property.\n" \
"\n" \
"This property is one of the values listed in the" \
@@ -438,9 +392,9 @@ static PyObject *py_binary_format_has_flag(PyObject *self, PyObject *args)
ret = PyArg_ParseTuple(args, "I", &flag);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- status = g_binary_format_has_flag(format, flag);
+ status = g_program_format_has_flag(format, flag);
result = status ? Py_True : Py_False;
Py_INCREF(result);
@@ -463,17 +417,17 @@ static PyObject *py_binary_format_has_flag(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject *args)
+static PyObject *py_program_format_register_code_point(PyObject *self, PyObject *args)
{
unsigned long long pt; /* Adresse virtuelle du point */
DisassPriorityLevel level; /* Nature du point fourni */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Format de binaire manipulé */
+ GProgramFormat *format; /* Format de binaire manipulé */
-#define BINARY_FORMAT_REGISTER_CODE_POINT_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_REGISTER_CODE_POINT_METHOD PYTHON_METHOD_DEF \
( \
register_code_point, "$self, point, level, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Register a virtual address as entry point or basic point.\n" \
"\n" \
"The point is an integer value for the virtual memory location" \
@@ -484,9 +438,9 @@ static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject *
ret = PyArg_ParseTuple(args, "kO&", &pt, convert_to_disass_priority_level, &level);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- g_binary_format_register_code_point(format, pt, level);
+ g_program_format_register_code_point(format, pt, level);
Py_RETURN_NONE;
@@ -506,18 +460,18 @@ static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject *
* *
******************************************************************************/
-static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args)
+static PyObject *py_program_format_add_symbol(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Format de binaire manipulé */
+ GProgramFormat *format; /* Format de binaire manipulé */
bool added; /* Bilan de l'appel interne */
-#define BINARY_FORMAT_ADD_SYMBOL_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_ADD_SYMBOL_METHOD PYTHON_METHOD_DEF \
( \
add_symbol, "$self, symbol, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Register a new symbol for the format.\n" \
"\n" \
"The symbol has to be a pychrysalide.format.BinSymbol instance." \
@@ -526,10 +480,10 @@ static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args)
ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
g_object_ref(G_OBJECT(symbol));
- added = g_binary_format_add_symbol(format, symbol);
+ added = g_program_format_add_symbol(format, symbol);
result = added ? Py_True : Py_False;
Py_INCREF(result);
@@ -552,17 +506,17 @@ static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args)
+static PyObject *py_program_format_remove_symbol(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Format de binaire manipulé */
+ GProgramFormat *format; /* Format de binaire manipulé */
-#define BINARY_FORMAT_REMOVE_SYMBOL_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_REMOVE_SYMBOL_METHOD PYTHON_METHOD_DEF \
( \
remove_symbol, "$self, symbol, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Unregister a symbol from the format.\n" \
"\n" \
"The symbol has to be a pychrysalide.format.BinSymbol instance." \
@@ -571,9 +525,9 @@ static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args)
ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- g_binary_format_remove_symbol(format, symbol);
+ g_program_format_remove_symbol(format, symbol);
result = Py_None;
Py_INCREF(result);
@@ -596,19 +550,19 @@ static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject *args)
+static PyObject *py_program_format_find_symbol_by_label(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
const char *label; /* Etiquette à retrouver */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Format de binaire manipulé */
+ GProgramFormat *format; /* Format de binaire manipulé */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
bool found; /* Bilan de la recherche */
-#define BINARY_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD PYTHON_METHOD_DEF \
( \
find_symbol_by_label, "$self, label, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Find the symbol with a given label, provided as a string.\n" \
"\n" \
"The result is a pychrysalide.format.BinSymbol instance, or None" \
@@ -618,9 +572,9 @@ static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject
ret = PyArg_ParseTuple(args, "s", &label);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- found = g_binary_format_find_symbol_by_label(format, label, &symbol);
+ found = g_program_format_find_symbol_by_label(format, label, &symbol);
if (found)
{
@@ -651,19 +605,19 @@ static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject
* *
******************************************************************************/
-static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args)
+static PyObject *py_program_format_find_symbol_at(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
- GBinFormat *format; /* Format de binaire manipulé */
+ GProgramFormat *format; /* Format de binaire manipulé */
exe_cv_info_t conv; /* Informations de conversion */
int ret; /* Bilan de lecture des args. */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
bool found; /* Bilan de la recherche */
-#define BINARY_FORMAT_FIND_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_FIND_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \
( \
find_symbol_at, "$self, addr, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Find the symbol located at a given address, provided as a" \
" pychrysalide.arch.vmpa instance.\n" \
"\n" \
@@ -671,14 +625,14 @@ static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args)
" None if no symbol was found." \
)
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
conv.format = G_IS_EXE_FORMAT(format) ? G_EXE_FORMAT(format) : NULL;
ret = PyArg_ParseTuple(args, "O&", convert_to_vmpa_using_executable, &conv);
if (!ret) return NULL;
- found = g_binary_format_find_symbol_at(format, conv.vmpa, &symbol);
+ found = g_program_format_find_symbol_at(format, conv.vmpa, &symbol);
if (found)
{
@@ -709,19 +663,19 @@ static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject *args)
+static PyObject *py_program_format_find_next_symbol_at(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
- GBinFormat *format; /* Format de binaire manipulé */
+ GProgramFormat *format; /* Format de binaire manipulé */
exe_cv_info_t conv; /* Informations de conversion */
int ret; /* Bilan de lecture des args. */
GBinSymbol *symbol; /* Enventuel symbole trouvé */
bool found; /* Bilan de la recherche */
-#define BINARY_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD PYTHON_METHOD_DEF \
( \
find_next_symbol_at, "$self, addr, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Find the symbol next to the one found at a given address," \
" provided as a pychrysalide.arch.vmpa instance.\n" \
"\n" \
@@ -729,14 +683,14 @@ static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject *
" None if no symbol was found." \
)
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
conv.format = G_IS_EXE_FORMAT(format) ? G_EXE_FORMAT(format) : NULL;
ret = PyArg_ParseTuple(args, "O&", convert_to_vmpa_using_executable, &conv);
if (!ret) return NULL;
- found = g_binary_format_find_next_symbol_at(format, conv.vmpa, &symbol);
+ found = g_program_format_find_next_symbol_at(format, conv.vmpa, &symbol);
if (found)
{
@@ -767,10 +721,10 @@ static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject *
* *
******************************************************************************/
-static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args)
+static PyObject *py_program_format_resolve_symbol(PyObject *self, PyObject *args)
{
PyObject *result; /* Valeur à retourner */
- GBinFormat *format; /* Format de binaire manipulé */
+ GProgramFormat *format; /* Format de binaire manipulé */
exe_cv_info_t conv; /* Informations de conversion */
int strict; /* Tolérance acceptée */
int ret; /* Bilan de lecture des args. */
@@ -778,10 +732,10 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args)
phys_t diff; /* Décalage éventuel mesuré */
bool found; /* Bilan de la recherche */
-#define BINARY_FORMAT_RESOLVE_SYMBOL_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_RESOLVE_SYMBOL_METHOD PYTHON_METHOD_DEF \
( \
resolve_symbol, "$self, addr, strict, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Search for a position inside a symbol by a given address.\n" \
"\n" \
"The result is a couple of (pychrysalide.format.BinSymbol," \
@@ -793,14 +747,14 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args)
" always 0 upon success." \
)
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
conv.format = G_IS_EXE_FORMAT(format) ? G_EXE_FORMAT(format) : NULL;
ret = PyArg_ParseTuple(args, "O&p", convert_to_vmpa_using_executable, &conv, &strict);
if (!ret) return NULL;
- found = g_binary_format_resolve_symbol(format, conv.vmpa, strict, &symbol, &diff);
+ found = g_program_format_resolve_symbol(format, conv.vmpa, strict, &symbol, &diff);
if (found)
{
@@ -835,27 +789,28 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_get_flags(PyObject *self, void *closure)
+static PyObject *py_program_format_get_flags(PyObject *self, void *closure)
{
PyObject *result; /* Valeur à retourner */
- GBinFormat *format; /* Elément à consulter */
+ GProgramFormat *format; /* Elément à consulter */
FormatFlag flags; /* Indications complémentaires */
-#define BINARY_FORMAT_FLAGS_ATTRIB PYTHON_GET_DEF_FULL \
+#define PROGRAM_FORMAT_FLAGS_ATTRIB PYTHON_GET_DEF_FULL \
( \
- flags, py_binary_format, \
+ flags, py_program_format, \
"Provide all the flags set for a format. The return value" \
" is of type pychrysalide.format.BinFormat.FormatFlag." \
)
- format = G_BIN_FORMAT(pygobject_get(self));
- flags = g_binary_format_get_flags(format);
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
+ flags = g_program_format_get_flags(format);
- result = cast_with_constants_group_from_type(get_python_binary_format_type(), "FormatFlag", flags);
+ result = cast_with_constants_group_from_type(get_python_program_format_type(), "FormatFlag", flags);
return result;
}
+#endif
/******************************************************************************
@@ -871,29 +826,31 @@ static PyObject *py_binary_format_get_flags(PyObject *self, void *closure)
* *
******************************************************************************/
-static PyObject *py_binary_format_get_endianness(PyObject *self, void *closure)
+static PyObject *py_program_format_get_endianness(PyObject *self, void *closure)
{
PyObject *result; /* Valeur à retourner */
- GBinFormat *format; /* Elément à consulter */
+ GProgramFormat *format; /* Elément à consulter */
SourceEndian endianness; /* Boutisme du format */
-#define BINARY_FORMAT_ENDIANNESS_ATTRIB PYTHON_GET_DEF_FULL \
+#define PROGRAM_FORMAT_ENDIANNESS_ATTRIB PYTHON_GET_DEF_FULL \
( \
- endianness, py_binary_format, \
+ endianness, py_program_format, \
"Endianness of the format. The return value is of type" \
- " pychrysalide.analysis.BinContent.SourceEndian." \
+ " pychrysalide.SourceEndian." \
)
- format = G_BIN_FORMAT(pygobject_get(self));
- endianness = g_binary_format_get_endianness(format);
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
+ endianness = g_program_format_get_endianness(format);
- result = cast_with_constants_group_from_type(get_python_binary_content_type(), "SourceEndian", endianness);
+ result = cast_with_constants_group_from_module("pychrysalide", "SourceEndian", endianness);
return result;
}
+#if 0
+
/******************************************************************************
* *
* Paramètres : self = classe représentant un format binaire. *
@@ -907,15 +864,15 @@ static PyObject *py_binary_format_get_endianness(PyObject *self, void *closure)
* *
******************************************************************************/
-static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure)
+static PyObject *py_program_format_get_symbols(PyObject *self, void *closure)
{
PyObject *result; /* Instance Python à retourner */
PyTypeObject *iterator_type; /* Type Python de l'itérateur */
PyObject *args; /* Liste des arguments d'appel */
-#define BINARY_FORMAT_SYMBOLS_ATTRIB PYTHON_GET_DEF_FULL \
+#define PROGRAM_FORMAT_SYMBOLS_ATTRIB PYTHON_GET_DEF_FULL \
( \
- symbols, py_binary_format, \
+ symbols, py_program_format, \
"Iterable list of all symbols found in the binary format.\n" \
"\n" \
"The returned iterator is a pychrysalide.format.SymIterator" \
@@ -935,13 +892,15 @@ static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure)
}
+#endif
+
/* ---------------------------------------------------------------------------------- */
/* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */
/* ---------------------------------------------------------------------------------- */
-
+#if 0
/******************************************************************************
* *
* Paramètres : self = architecture concernée par la procédure. *
@@ -955,18 +914,18 @@ static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure)
* *
******************************************************************************/
-static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args)
+static PyObject *py_program_format_add_error(PyObject *self, PyObject *args)
{
BinaryFormatError type; /* Type d'erreur détectée */
vmpa2t *addr; /* Position d'une erreur */
const char *desc; /* Description d'une erreur */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Format binaire manipulé */
+ GProgramFormat *format; /* Format binaire manipulé */
-#define BINARY_FORMAT_ADD_ERROR_METHOD PYTHON_METHOD_DEF \
+#define PROGRAM_FORMAT_ADD_ERROR_METHOD PYTHON_METHOD_DEF \
( \
add_error, "$self, type, addr, desc, /", \
- METH_VARARGS, py_binary_format, \
+ METH_VARARGS, py_program_format, \
"Extend the list of detected errors linked to the format.\n" \
"\n" \
"The type of error has to be one of the" \
@@ -976,12 +935,12 @@ static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args)
" what has failed." \
)
- ret = PyArg_ParseTuple(args, "O&O&s", convert_to_binary_format_error, &type, convert_any_to_vmpa, &addr, &desc);
+ ret = PyArg_ParseTuple(args, "O&O&s", convert_to_program_format_error, &type, convert_any_to_vmpa, &addr, &desc);
if (!ret) return NULL;
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- g_binary_format_add_error(format, type, addr, desc);
+ g_program_format_add_error(format, type, addr, desc);
clean_vmpa_arg(addr);
@@ -1003,10 +962,10 @@ static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_format_get_errors(PyObject *self, void *closure)
+static PyObject *py_program_format_get_errors(PyObject *self, void *closure)
{
PyObject *result; /* Instance Python à retourner */
- GBinFormat *format; /* Format binaire manipulé */
+ GProgramFormat *format; /* Format binaire manipulé */
size_t count; /* Nombre d'éléments à traiter */
size_t i; /* Boucle de parcours */
#ifndef NDEBUG
@@ -1018,9 +977,9 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure)
PyObject *py_type; /* Version Python du type */
PyObject *error; /* Nouvelle erreur à rajouter */
-#define BINARY_FORMAT_ERRORS_ATTRIB PYTHON_GET_DEF_FULL \
+#define PROGRAM_FORMAT_ERRORS_ATTRIB PYTHON_GET_DEF_FULL \
( \
- errors, py_binary_format, \
+ errors, py_program_format, \
"List of all detected errors which occurred while loading the binary.\n" \
"\n" \
"The result is a tuple of (pychrysalide.format.BinFormat.BinaryFormatError," \
@@ -1028,24 +987,24 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure)
" description for each error." \
)
- format = G_BIN_FORMAT(pygobject_get(self));
+ format = G_PROGRAM_FORMAT(pygobject_get(self));
- g_binary_format_lock_errors(format);
+ g_program_format_lock_errors(format);
- count = g_binary_format_count_errors(format);
+ count = g_program_format_count_errors(format);
result = PyTuple_New(count);
for (i = 0; i < count; i++)
{
#ifndef NDEBUG
- status = g_binary_format_get_error(format, i, &type, &addr, &desc);
+ status = g_program_format_get_error(format, i, &type, &addr, &desc);
assert(status);
#else
- g_binary_format_get_error(format, i, &type, &addr, &desc);
+ g_program_format_get_error(format, i, &type, &addr, &desc);
#endif
- py_type = cast_with_constants_group_from_type(get_python_binary_format_type(), "BinaryFormatError", type);
+ py_type = cast_with_constants_group_from_type(get_python_program_format_type(), "BinaryFormatError", type);
error = Py_BuildValue("OO&s", py_type, build_from_internal_vmpa, &addr, desc);
Py_DECREF(py_type);
@@ -1053,11 +1012,12 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure)
}
- g_binary_format_unlock_errors(format);
+ g_program_format_unlock_errors(format);
return result;
}
+#endif
/******************************************************************************
@@ -1072,51 +1032,54 @@ static PyObject *py_binary_format_get_errors(PyObject *self, void *closure)
* *
******************************************************************************/
-PyTypeObject *get_python_binary_format_type(void)
+PyTypeObject *get_python_program_format_type(void)
{
- static PyMethodDef py_bin_format_methods[] = {
- BINARY_FORMAT_SET_FLAG_METHOD,
- BINARY_FORMAT_UNSET_FLAG_METHOD,
- BINARY_FORMAT_HAS_FLAG_METHOD,
- BINARY_FORMAT_REGISTER_CODE_POINT_METHOD,
- BINARY_FORMAT_ADD_SYMBOL_METHOD,
- BINARY_FORMAT_REMOVE_SYMBOL_METHOD,
- BINARY_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD,
- BINARY_FORMAT_FIND_SYMBOL_AT_METHOD,
- BINARY_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD,
- BINARY_FORMAT_RESOLVE_SYMBOL_METHOD,
- BINARY_FORMAT_ADD_ERROR_METHOD,
+ static PyMethodDef py_program_format_methods[] = {
+ PROGRAM_FORMAT_GET_ENDIANNESS_WRAPPER,
+ /*
+ PROGRAM_FORMAT_SET_FLAG_METHOD,
+ PROGRAM_FORMAT_UNSET_FLAG_METHOD,
+ PROGRAM_FORMAT_HAS_FLAG_METHOD,
+ PROGRAM_FORMAT_REGISTER_CODE_POINT_METHOD,
+ PROGRAM_FORMAT_ADD_SYMBOL_METHOD,
+ PROGRAM_FORMAT_REMOVE_SYMBOL_METHOD,
+ PROGRAM_FORMAT_FIND_SYMBOL_BY_LABEL_METHOD,
+ PROGRAM_FORMAT_FIND_SYMBOL_AT_METHOD,
+ PROGRAM_FORMAT_FIND_NEXT_SYMBOL_AT_METHOD,
+ PROGRAM_FORMAT_RESOLVE_SYMBOL_METHOD,
+ PROGRAM_FORMAT_ADD_ERROR_METHOD,
+ */
{ NULL }
};
- static PyGetSetDef py_bin_format_getseters[] = {
- BINARY_FORMAT_FLAGS_ATTRIB,
- BINARY_FORMAT_ENDIANNESS_ATTRIB,
- BINARY_FORMAT_SYMBOLS_ATTRIB,
- BINARY_FORMAT_ERRORS_ATTRIB,
+ static PyGetSetDef py_program_format_getseters[] = {
+ //PROGRAM_FORMAT_FLAGS_ATTRIB,
+ PROGRAM_FORMAT_ENDIANNESS_ATTRIB,
+ //PROGRAM_FORMAT_SYMBOLS_ATTRIB,
+ //PROGRAM_FORMAT_ERRORS_ATTRIB,
{ NULL }
};
- static PyTypeObject py_bin_format_type = {
+ static PyTypeObject py_program_format_type = {
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.format.BinFormat",
+ .tp_name = "pychrysalide.format.ProgramFormat",
.tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE,
- .tp_doc = BINARY_FORMAT_DOC,
+ .tp_doc = PROGRAM_FORMAT_DOC,
- .tp_methods = py_bin_format_methods,
- .tp_getset = py_bin_format_getseters,
+ .tp_methods = py_program_format_methods,
+ .tp_getset = py_program_format_getseters,
- .tp_init = py_binary_format_init,
- .tp_new = py_binary_format_new,
+ .tp_init = py_program_format_init,
+ .tp_new = py_program_format_new,
};
- return &py_bin_format_type;
+ return &py_program_format_type;
}
@@ -1133,13 +1096,13 @@ PyTypeObject *get_python_binary_format_type(void)
* *
******************************************************************************/
-bool ensure_python_binary_format_is_registered(void)
+bool ensure_python_program_format_is_registered(void)
{
PyTypeObject *type; /* Type Python 'BinFormat' */
PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
- type = get_python_binary_format_type();
+ type = get_python_program_format_type();
if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
{
@@ -1150,11 +1113,13 @@ bool ensure_python_binary_format_is_registered(void)
if (!ensure_python_known_format_is_registered())
return false;
- if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, type))
+ if (!register_class_for_pygobject(dict, G_TYPE_PROGRAM_FORMAT, type))
return false;
- if (!define_binary_format_constants(type))
+ /*
+ if (!define_program_format_constants(type))
return false;
+ */
}
@@ -1176,11 +1141,11 @@ bool ensure_python_binary_format_is_registered(void)
* *
******************************************************************************/
-int convert_to_binary_format(PyObject *arg, void *dst)
+int convert_to_program_format(PyObject *arg, void *dst)
{
int result; /* Bilan à retourner */
- result = PyObject_IsInstance(arg, (PyObject *)get_python_binary_format_type());
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_program_format_type());
switch (result)
{
@@ -1194,7 +1159,7 @@ int convert_to_binary_format(PyObject *arg, void *dst)
break;
case 1:
- *((GBinFormat **)dst) = G_BIN_FORMAT(pygobject_get(arg));
+ *((GProgramFormat **)dst) = G_PROGRAM_FORMAT(pygobject_get(arg));
break;
default: