summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext/portion.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/glibext/portion.c')
-rw-r--r--plugins/pychrysalide/glibext/portion.c195
1 files changed, 68 insertions, 127 deletions
diff --git a/plugins/pychrysalide/glibext/portion.c b/plugins/pychrysalide/glibext/portion.c
index 70eb314..d95308c 100644
--- a/plugins/pychrysalide/glibext/portion.c
+++ b/plugins/pychrysalide/glibext/portion.c
@@ -1,6 +1,6 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * binportion.c - équivalent Python du fichier "glibext/gbinportion.c"
+ * portion.c - équivalent Python du fichier "glibext/portion.c"
*
* Copyright (C) 2019-2020 Cyrille Bagard
*
@@ -22,15 +22,14 @@
*/
-#include "binportion.h"
+#include "portion.h"
#include <pygobject.h>
#include <i18n.h>
-#include <glibext/gbinportion-int.h>
-#include <plugins/dt.h>
+#include <glibext/portion-int.h>
#include "constants.h"
@@ -40,13 +39,13 @@
-/* Accompagne la création d'une instance dérivée en Python. */
-static PyObject *py_bin_portion_new(PyTypeObject *, PyObject *, PyObject *);
+CREATE_DYN_CONSTRUCTOR(binary_portion, G_TYPE_BINARY_PORTION);
+
/* Initialise une instance sur la base du dérivé de GObject. */
-static int py_bin_portion_init(PyObject *, PyObject *, PyObject *);
+static int py_binary_portion_init(PyObject *, PyObject *, PyObject *);
-/* Effectue une comparaison avec un objet Python 'BinPortion'. */
+/* Effectue une comparaison avec un objet Python BinaryPortion. */
static PyObject *py_binary_portion_richcompare(PyObject *, PyObject *, int);
/* Assure qu'une portion ne dépasse pas une position donnée. */
@@ -77,66 +76,6 @@ static int py_binary_portion_set_rights(PyObject *, PyObject *, void *);
/******************************************************************************
* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Accompagne la création d'une instance dérivée en Python. *
-* *
-* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_bin_portion_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Objet à retourner */
- PyTypeObject *base; /* Type de base à dériver */
- bool first_time; /* Evite les multiples passages*/
- GType gtype; /* Nouveau type de processeur */
- bool status; /* Bilan d'un enregistrement */
-
- /* Validations diverses */
-
- base = get_python_binary_portion_type();
-
- if (type == base)
- goto simple_way;
-
- /* Mise en place d'un type dédié */
-
- first_time = (g_type_from_name(type->tp_name) == 0);
-
- gtype = build_dynamic_type(G_TYPE_BIN_PORTION, type->tp_name, NULL, NULL, NULL);
-
- if (first_time)
- {
- status = register_class_for_dynamic_pygobject(gtype, type);
-
- if (!status)
- {
- result = NULL;
- goto exit;
- }
-
- }
-
- /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
-
- simple_way:
-
- result = PyType_GenericNew(type, args, kwds);
-
- exit:
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
@@ -149,33 +88,30 @@ static PyObject *py_bin_portion_new(PyTypeObject *type, PyObject *args, PyObject
* *
******************************************************************************/
-static int py_bin_portion_init(PyObject *self, PyObject *args, PyObject *kwds)
+static int py_binary_portion_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- const char *code; /* Identifiant de couleur */
vmpa2t *addr; /* Emplacement de portion */
unsigned long long size; /* Taille de la portion */
int ret; /* Bilan de lecture des args. */
- GBinPortion *portion; /* Portion à manipuler */
+ GBinaryPortion *portion; /* Portion à manipuler */
- static char *kwlist[] = { "code", "addr", "size", NULL };
+ static char *kwlist[] = { "addr", "size", NULL };
#define BINARY_PORTION_DOC \
- "The BinPortion object handles parts of binaries usually formally" \
+ "The BinaryPortion object handles parts of binaries usually formally" \
" identified in binary formats, like program segments or sections for ELF" \
" files for example.\n" \
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " BinPortion(code, addr, size)" \
+ " BinaryPortion(addr, size)" \
"\n" \
- "Where code is the CSS class style for the rendering color to use, addr is" \
- " the starting point of the portion in memory, as a pychrysalide.arch.vmpa" \
- " value, and size is the size of the portion." \
+ "Where *addr* is the starting point of the portion in memory, as a" \
+ " pychrysalide.arch.vmpa value, and *size* is the size of the portion."
/* Récupération des paramètres */
- ret = PyArg_ParseTupleAndKeywords(args, kwds, "sO&K", kwlist,
- &code, convert_any_to_vmpa, &addr, &size);
+ ret = PyArg_ParseTupleAndKeywords(args, kwds, "O&K", kwlist, convert_any_to_vmpa, &addr, &size);
if (!ret) return -1;
/* Initialisation d'un objet GLib */
@@ -189,11 +125,13 @@ static int py_bin_portion_init(PyObject *self, PyObject *args, PyObject *kwds)
/* Eléments de base */
- portion = G_BIN_PORTION(pygobject_get(self));
-
- portion->code = strdup(code);
+ portion = G_BINARY_PORTION(pygobject_get(self));
- init_mrange(&portion->range, addr, size);
+ if (!g_binary_portion_create(portion, addr, size))
+ {
+ clean_vmpa_arg(addr);
+ return -1;
+ }
clean_vmpa_arg(addr);
@@ -208,7 +146,7 @@ static int py_bin_portion_init(PyObject *self, PyObject *args, PyObject *kwds)
* b = second object Python à consulter. *
* op = type de comparaison menée. *
* *
-* Description : Effectue une comparaison avec un objet Python 'BinPortion'. *
+* Description : Effectue une comparaison avec un objet Python BinaryPortion. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -220,8 +158,8 @@ static PyObject *py_binary_portion_richcompare(PyObject *a, PyObject *b, int op)
{
PyObject *result; /* Bilan à retourner */
int ret; /* Bilan de lecture des args. */
- const GBinPortion *portion_a; /* Premier élément à traiter */
- const GBinPortion *portion_b; /* Second élément à traiter */
+ const GBinaryPortion *portion_a; /* Premier élément à traiter */
+ const GBinaryPortion *portion_b; /* Second élément à traiter */
int status; /* Résultat d'une comparaison */
ret = PyObject_IsInstance(b, (PyObject *)get_python_binary_portion_type());
@@ -231,8 +169,8 @@ static PyObject *py_binary_portion_richcompare(PyObject *a, PyObject *b, int op)
goto cmp_done;
}
- portion_a = G_BIN_PORTION(pygobject_get(a));
- portion_b = G_BIN_PORTION(pygobject_get(b));
+ portion_a = G_BINARY_PORTION(pygobject_get(a));
+ portion_b = G_BINARY_PORTION(pygobject_get(b));
status = g_binary_portion_compare(&portion_a, &portion_b);
@@ -265,16 +203,16 @@ static PyObject *py_binary_portion_limit_range(PyObject *self, PyObject *args)
PyObject *result; /* Trouvailles à retourner */
unsigned long long max; /* Taille maximale à accorder */
int ret; /* Bilan de lecture des args. */
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
bool status; /* Bilan de la modification */
-#define BINARY_SYMBOL_LIMIT_RANGE_METHOD PYTHON_METHOD_DEF \
+#define BINARY_PORTION_LIMIT_RANGE_METHOD PYTHON_METHOD_DEF \
( \
limit_range, "$self, max, /", \
METH_VARARGS, py_binary_portion, \
"Ensure the portion range does not cross a boundary size.\n" \
"\n" \
- "An integer value is expected as the maximum size of the" \
+ "An *max* integer value is expected as the maximum size of the" \
" portion.\n" \
"\n" \
"A boolean value indicating the success of the operation is" \
@@ -284,7 +222,7 @@ static PyObject *py_binary_portion_limit_range(PyObject *self, PyObject *args)
ret = PyArg_ParseTuple(args, "K", &max);
if (!ret) return NULL;
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
status = g_binary_portion_limit_range(portion, max);
@@ -311,24 +249,27 @@ static PyObject *py_binary_portion_limit_range(PyObject *self, PyObject *args)
static PyObject *py_binary_portion_include(PyObject *self, PyObject *args)
{
- GBinPortion *sub; /* Sous-portion à inclure */
+ GBinaryPortion *sub; /* Sous-portion à inclure */
int ret; /* Bilan de lecture des args. */
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
-#define BINARY_SYMBOL_INCLUDE_METHOD PYTHON_METHOD_DEF \
-( \
- include, "$self, sub, /", \
- METH_VARARGS, py_binary_portion, \
- "Include another binary portion as a child item.\n" \
- "\n" \
- "The sub portion has to be a pychrysalide.glibext.BinPortion" \
- " instance." \
+#define BINARY_PORTION_INCLUDE_METHOD PYTHON_METHOD_DEF \
+( \
+ include, "$self, sub, /", \
+ METH_VARARGS, py_binary_portion, \
+ "Include another binary portion as a child item.\n" \
+ "\n" \
+ "The provided *sub* portion has to be a" \
+ " pychrysalide.glibext.BinaryPortion instance." \
+ "\n" \
+ "The returned value is a boolean value providing the" \
+ " status of the operation." \
)
ret = PyArg_ParseTuple(args, "O&", convert_to_binary_portion, &sub);
if (!ret) return NULL;
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
g_object_ref(G_OBJECT(sub));
g_binary_portion_include(portion, sub);
@@ -354,7 +295,7 @@ static PyObject *py_binary_portion_include(PyObject *self, PyObject *args)
static PyObject *py_binary_portion_get_desc(PyObject *self, void *closure)
{
PyObject *result; /* Résultat à retourner */
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
const char *desc; /* Description récupérée */
#define BINARY_PORTION_DESC_ATTRIB PYTHON_GETSET_DEF_FULL \
@@ -364,7 +305,7 @@ static PyObject *py_binary_portion_get_desc(PyObject *self, void *closure)
" simple string." \
)
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
desc = g_binary_portion_get_desc(portion);
@@ -391,7 +332,7 @@ static PyObject *py_binary_portion_get_desc(PyObject *self, void *closure)
static int py_binary_portion_set_desc(PyObject *self, PyObject *value, void *closure)
{
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
const char *desc; /* Description à définir */
if (!PyUnicode_Check(value))
@@ -400,7 +341,7 @@ static int py_binary_portion_set_desc(PyObject *self, PyObject *value, void *clo
return -1;
}
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
desc = PyUnicode_DATA(value);
@@ -427,7 +368,7 @@ static int py_binary_portion_set_desc(PyObject *self, PyObject *value, void *clo
static PyObject *py_binary_portion_get_range(PyObject *self, void *closure)
{
PyObject *result; /* Résultat à retourner */
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
const mrange_t *range; /* Espace de couverture */
#define BINARY_PORTION_RANGE_ATTRIB PYTHON_GET_DEF_FULL \
@@ -438,7 +379,7 @@ static PyObject *py_binary_portion_get_range(PyObject *self, void *closure)
"This property is a pychrysalide.arch.mrange instance." \
)
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
range = g_binary_portion_get_range(portion);
@@ -465,7 +406,7 @@ static PyObject *py_binary_portion_get_range(PyObject *self, void *closure)
static PyObject *py_binary_portion_get_continuation(PyObject *self, void *closure)
{
PyObject *result; /* Résultat à retourner */
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
bool status; /* Bilan d'une consultation */
#define BINARY_PORTION_CONTINUATION_ATTRIB PYTHON_GETSET_DEF_FULL \
@@ -478,7 +419,7 @@ static PyObject *py_binary_portion_get_continuation(PyObject *self, void *closur
" several parts when included in the portion tree." \
)
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
status = g_binary_portion_is_continuation(portion);
@@ -506,7 +447,7 @@ static PyObject *py_binary_portion_get_continuation(PyObject *self, void *closur
static int py_binary_portion_set_continuation(PyObject *self, PyObject *value, void *closure)
{
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
bool status; /* Valeur à manipuler */
if (!PyBool_Check(value))
@@ -515,7 +456,7 @@ static int py_binary_portion_set_continuation(PyObject *self, PyObject *value, v
return -1;
}
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
status = (value == Py_True);
@@ -542,17 +483,17 @@ static int py_binary_portion_set_continuation(PyObject *self, PyObject *value, v
static PyObject *py_binary_portion_get_rights(PyObject *self, void *closure)
{
PyObject *result; /* Résultat à retourner */
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
PortionAccessRights rights; /* Bilan d'une consultation */
#define BINARY_PORTION_RIGHTS_ATTRIB PYTHON_GETSET_DEF_FULL \
( \
rights, py_binary_portion, \
"Access rights declared for the binary portion, as a" \
- " pychrysalide.glibext.BinPortion.PortionAccessRights value." \
+ " pychrysalide.glibext.BinaryPortion.PortionAccessRights value."\
)
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
rights = g_binary_portion_get_rights(portion);
@@ -579,13 +520,13 @@ static PyObject *py_binary_portion_get_rights(PyObject *self, void *closure)
static int py_binary_portion_set_rights(PyObject *self, PyObject *value, void *closure)
{
- GBinPortion *portion; /* Version GLib du type */
+ GBinaryPortion *portion; /* Version GLib du type */
PortionAccessRights rights; /* Valeur à manipuler */
if (convert_to_portion_access_rights(value, &rights) != 1)
return -1;
- portion = G_BIN_PORTION(pygobject_get(self));
+ portion = G_BINARY_PORTION(pygobject_get(self));
g_binary_portion_set_rights(portion, rights);
@@ -609,8 +550,8 @@ static int py_binary_portion_set_rights(PyObject *self, PyObject *value, void *c
PyTypeObject *get_python_binary_portion_type(void)
{
static PyMethodDef py_binary_portion_methods[] = {
- BINARY_SYMBOL_LIMIT_RANGE_METHOD,
- BINARY_SYMBOL_INCLUDE_METHOD,
+ BINARY_PORTION_LIMIT_RANGE_METHOD,
+ BINARY_PORTION_INCLUDE_METHOD,
{ NULL }
};
@@ -626,7 +567,7 @@ PyTypeObject *get_python_binary_portion_type(void)
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.glibext.BinPortion",
+ .tp_name = "pychrysalide.glibext.BinaryPortion",
.tp_basicsize = sizeof(PyGObject),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
@@ -638,8 +579,8 @@ PyTypeObject *get_python_binary_portion_type(void)
.tp_methods = py_binary_portion_methods,
.tp_getset = py_binary_portion_getseters,
- .tp_init = py_bin_portion_init,
- .tp_new = py_bin_portion_new,
+ .tp_init = py_binary_portion_init,
+ .tp_new = py_binary_portion_new,
};
@@ -652,7 +593,7 @@ PyTypeObject *get_python_binary_portion_type(void)
* *
* Paramètres : module = module dont la définition est à compléter. *
* *
-* Description : Prend en charge l'objet 'pychrysalide.glibext.BinPortion'. *
+* Description : Prend en charge l'objet 'pychrysalide.glibext.BinaryPortion'.*
* *
* Retour : Bilan de l'opération. *
* *
@@ -662,7 +603,7 @@ PyTypeObject *get_python_binary_portion_type(void)
bool ensure_python_binary_portion_is_registered(void)
{
- PyTypeObject *type; /* Type Python 'BinPortion' */
+ PyTypeObject *type; /* Type Python 'BinaryPortion' */
PyObject *module; /* Module à recompléter */
PyObject *dict; /* Dictionnaire du module */
@@ -674,7 +615,7 @@ bool ensure_python_binary_portion_is_registered(void)
dict = PyModule_GetDict(module);
- if (!register_class_for_pygobject(dict, G_TYPE_BIN_PORTION, type))
+ if (!register_class_for_pygobject(dict, G_TYPE_BINARY_PORTION, type))
return false;
if (!define_binary_portion_constants(type))
@@ -718,7 +659,7 @@ int convert_to_binary_portion(PyObject *arg, void *dst)
break;
case 1:
- *((GBinPortion **)dst) = G_BIN_PORTION(pygobject_get(arg));
+ *((GBinaryPortion **)dst) = G_BINARY_PORTION(pygobject_get(arg));
break;
default: