diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2024-11-15 10:01:42 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2024-11-15 10:01:42 (GMT) |
commit | 671f61ec87f5e8d762ea890aabbc62c777e1c4f9 (patch) | |
tree | 1517f5fc5d00c8fd04872b35571556b021866f14 /plugins/pychrysalide/format/flat.c | |
parent | 3e21278480a25552401644cd0dc168e3588508dd (diff) |
Restore a skeleton of support for file formats.
Diffstat (limited to 'plugins/pychrysalide/format/flat.c')
-rw-r--r-- | plugins/pychrysalide/format/flat.c | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/plugins/pychrysalide/format/flat.c b/plugins/pychrysalide/format/flat.c index 4df3646..a115c57 100644 --- a/plugins/pychrysalide/format/flat.c +++ b/plugins/pychrysalide/format/flat.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * flat.c - équivalent Python du fichier "format/flat.c" * - * Copyright (C) 2018-2019 Cyrille Bagard + * Copyright (C) 2018-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -28,43 +28,46 @@ #include <pygobject.h> -#include <format/flat.h> +#include <format/flat-int.h> #include "executable.h" #include "../access.h" +#include "../constants.h" #include "../helpers.h" #include "../analysis/content.h" -/* Crée un nouvel objet Python de type 'FlatFormat'. */ -static PyObject *py_flat_format_new(PyTypeObject *, PyObject *, PyObject *); +CREATE_DYN_CONSTRUCTOR(flat_format, G_TYPE_FLAT_FORMAT); + + +/* Initialise une instance sur la base du dérivé de GObject. */ +static int py_flat_format_init(PyObject *, PyObject *, PyObject *); /****************************************************************************** * * -* Paramètres : type = type de l'objet à instancier. * +* Paramètres : self = objet à initialiser (théoriquement). * * args = arguments fournis à l'appel. * * kwds = arguments de type key=val fournis. * * * -* Description : Crée un nouvel objet Python de type 'FlatFormat'. * +* Description : Initialise une instance sur la base du dérivé de GObject. * * * -* Retour : Instance Python mise en place. * +* Retour : 0. * * * * Remarques : - * * * ******************************************************************************/ -static PyObject *py_flat_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static int py_flat_format_init(PyObject *self, PyObject *args, PyObject *kwds) { - PyObject *result; /* Instance à retourner */ GBinContent *content; /* Instance GLib du contenu */ const char *machine; /* Identifiant d'architecture */ - unsigned int endian; /* Boutisme de l'architecture */ + SourceEndian endian; /* Boutisme de l'architecture */ int ret; /* Bilan de lecture des args. */ - GExeFormat *format; /* Création GLib à transmettre */ + GFlatFormat *format; /* Création GLib à transmettre */ #define FLAT_FORMAT_DOC \ "FlatFormat is suitable for all executable contents without a proper" \ @@ -75,27 +78,30 @@ static PyObject *py_flat_format_new(PyTypeObject *type, PyObject *args, PyObject " FlatFormat(content, machine, endian)" \ "\n" \ "Where content is a pychrysalide.analysis.BinContent object, machine" \ - " defines the target architecture and endian provides the right" \ - " endianness of the data." + " defines the target architecture as a string value and endian provides"\ + " the right endianness of the data, as pychrysalide.SourceEndian value." - ret = PyArg_ParseTuple(args, "O&sI", convert_to_binary_content, &content, &machine, &endian); - if (!ret) return NULL; + /* Récupération des paramètres */ - format = g_flat_format_new(content, machine, endian); + ret = PyArg_ParseTuple(args, "O&sO&", + convert_to_binary_content, &content, + &machine, + convert_to_source_endian, &endian); + if (!ret) return -1; - if (format == NULL) - { - result = Py_None; - Py_INCREF(result); - } + /* Initialisation d'un objet GLib */ - else - { - result = pygobject_new(G_OBJECT(format)); - g_object_unref(format); - } + ret = forward_pygobjet_init(self); + if (ret == -1) return -1; - return result; + /* Eléments de base */ + + format = G_FLAT_FORMAT(pygobject_get(self)); + + if (!g_flat_format_create(format, content, machine, endian)) + return -1; + + return 0; } @@ -135,7 +141,9 @@ PyTypeObject *get_python_flat_format_type(void) .tp_methods = py_flat_format_methods, .tp_getset = py_flat_format_getseters, - .tp_new = py_flat_format_new + + .tp_init = py_flat_format_init, + .tp_new = py_flat_format_new, }; |