diff options
Diffstat (limited to 'plugins')
26 files changed, 2949 insertions, 9 deletions
diff --git a/plugins/dalvik/operands/pool.c b/plugins/dalvik/operands/pool.c index 6bb1323..821ca5b 100644 --- a/plugins/dalvik/operands/pool.c +++ b/plugins/dalvik/operands/pool.c @@ -281,7 +281,7 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *operand, GBuff if (type != NULL) { - tmp = g_data_type_to_string(type); + tmp = g_data_type_to_string(type, true); g_object_unref(G_OBJECT(type)); g_buffer_line_append_text(line, BLC_ASSEMBLY, "<", 1, RTT_HOOK, NULL); @@ -313,7 +313,7 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *operand, GBuff if (field != NULL) { - tmp = g_binary_variable_to_string(field, false); + tmp = g_binary_variable_to_string(field, true); g_object_unref(G_OBJECT(field)); g_buffer_line_append_text(line, BLC_ASSEMBLY, "<", 1, RTT_HOOK, NULL); @@ -346,7 +346,7 @@ static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *operand, GBuff if (routine != NULL) { - tmp = g_binary_routine_to_string(routine); + tmp = g_binary_routine_to_string(routine, true); g_object_unref(G_OBJECT(routine)); g_buffer_line_append_text(line, BLC_ASSEMBLY, "<", 1, RTT_HOOK, NULL); diff --git a/plugins/dexbnf/type.c b/plugins/dexbnf/type.c index 29ba0a8..ff9af09 100644 --- a/plugins/dexbnf/type.c +++ b/plugins/dexbnf/type.c @@ -113,8 +113,7 @@ static GDataType *dtd_full_class_name(input_buffer *buffer) result = g_class_enum_type_new(CET_CLASS, name); - g_data_type_set_namespace(result, ns); - g_object_unref(ns); + g_data_type_set_namespace(result, ns, "."); } while (1); diff --git a/plugins/pychrysalide/analysis/Makefile.am b/plugins/pychrysalide/analysis/Makefile.am index edac3c0..3d7ac51 100644 --- a/plugins/pychrysalide/analysis/Makefile.am +++ b/plugins/pychrysalide/analysis/Makefile.am @@ -15,7 +15,8 @@ libpychrysaanalysis_la_SOURCES = \ libpychrysaanalysis_la_LIBADD = \ contents/libpychrysaanalysiscontents.la \ - db/libpychrysaanalysisdb.la + db/libpychrysaanalysisdb.la \ + types/libpychrysaanalysistypes.la libpychrysaanalysis_la_LDFLAGS = @@ -30,4 +31,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJE AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = contents db +SUBDIRS = contents db types diff --git a/plugins/pychrysalide/analysis/routine.c b/plugins/pychrysalide/analysis/routine.c index d0abd72..f8bc009 100644 --- a/plugins/pychrysalide/analysis/routine.c +++ b/plugins/pychrysalide/analysis/routine.c @@ -79,7 +79,7 @@ static PyObject *py_binary_routine_to_str(PyObject *self) routine = G_BIN_ROUTINE(pygobject_get(self)); - desc = g_binary_routine_to_string(routine); + desc = g_binary_routine_to_string(routine, true); result = PyUnicode_FromString(desc); diff --git a/plugins/pychrysalide/analysis/type.c b/plugins/pychrysalide/analysis/type.c index 1d9e9f0..146e490 100644 --- a/plugins/pychrysalide/analysis/type.c +++ b/plugins/pychrysalide/analysis/type.c @@ -61,7 +61,7 @@ static PyObject *py_data_type_to_str(PyObject *self) type = G_DATA_TYPE(pygobject_get(self)); - desc = _g_data_type_to_string(type, false); + desc = g_data_type_to_string(type, true); result = PyUnicode_FromString(desc); diff --git a/plugins/pychrysalide/analysis/types/Makefile.am b/plugins/pychrysalide/analysis/types/Makefile.am new file mode 100644 index 0000000..53ae320 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/Makefile.am @@ -0,0 +1,29 @@ + +noinst_LTLIBRARIES = libpychrysaanalysistypes.la + +libpychrysaanalysistypes_la_SOURCES = \ + array.h array.c \ + basic.h basic.c \ + cse.h cse.c \ + encaps.h encaps.c \ + expr.h expr.c \ + literal.h literal.c \ + module.h module.c \ + override.h override.c \ + proto.h proto.c \ + template.h template.c + +libpychrysaanalysistypes_la_LDFLAGS = + + +devdir = $(includedir)/chrysalide-$(subdir) + +dev_HEADERS = $(libpychrysaanalysistypes_la_SOURCES:%c=) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I$(top_srcdir)/src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/plugins/pychrysalide/analysis/types/array.c b/plugins/pychrysalide/analysis/types/array.c new file mode 100644 index 0000000..d021e16 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/array.c @@ -0,0 +1,414 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * array.c - équivalent Python du fichier "analysis/types/array.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "array.h" + + +#include <pygobject.h> +#include <string.h> + + +#include <i18n.h> +#include <analysis/types/array.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'ArrayType'. */ +static PyObject *py_array_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le type des membres du tableau. */ +static PyObject *py_array_type_get_members_type(PyObject *, void *); + +/* Indique si la dimension du tableau est chiffrée. */ +static PyObject *py_array_type_is_numbered(PyObject *, void *); + +/* Fournit la dimension associée au tableau. */ +static PyObject *py_array_type_get_dimension(PyObject *, void *); + +/* Fournit la dimension associée au tableau. */ +static PyObject *py_array_type_get_dimension_number(PyObject *, void *); + +/* Définit la dimension associée au tableau. */ +static int py_array_type_set_dimension_number(PyObject *, PyObject *, void *); + +/* Fournit la dimension associée au tableau. */ +static PyObject *py_array_type_get_dimension_expression(PyObject *, void *); + +/* Définit la dimension associée au tableau. */ +static int py_array_type_set_dimension_expression(PyObject *, PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'ArrayType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_array_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + PyObject *members_obj; /* Objet du type d'éléments */ + int ret; /* Bilan de lecture des args. */ + GDataType *members; /* Version GLib du type */ + GDataType *dtype; /* Version GLib du type */ + + ret = PyArg_ParseTuple(args, "O!", get_python_data_type_type(), &members_obj); + if (!ret) return NULL; + + members = G_DATA_TYPE(pygobject_get(members_obj)); + + dtype = g_array_type_new(members); + result = pygobject_new(G_OBJECT(dtype)); + g_object_unref(dtype); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type des membres du tableau. * +* * +* Retour : Instance d'un autre type. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_array_type_get_members_type(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GArrayType *type; /* Version GLib du type */ + GDataType *members; /* Type des membres du tableau */ + + type = G_ARRAY_TYPE(pygobject_get(self)); + + members = g_array_type_get_members_type(type); + + result = pygobject_new(G_OBJECT(members)); + + g_object_unref(members); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique si la dimension du tableau est chiffrée. * +* * +* Retour : Py_True si la dimension est chiffrée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_array_type_is_numbered(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GArrayType *type; /* Version GLib du type */ + bool status; /* Nature de la dimension liée */ + + type = G_ARRAY_TYPE(pygobject_get(self)); + + status = g_array_type_is_dimension_numbered(type); + + result = status ? Py_True : Py_False; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit la dimension associée au tableau. * +* * +* Retour : Dimension de nature variable. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_array_type_get_dimension(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GArrayType *type; /* Version GLib du type */ + bool status; /* Nature de la dimension liée */ + + type = G_ARRAY_TYPE(pygobject_get(self)); + + status = g_array_type_is_dimension_numbered(type); + + if (status) + result = py_array_type_get_dimension_number(self, NULL); + else + result = py_array_type_get_dimension_expression(self, NULL); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit la dimension associée au tableau. * +* * +* Retour : Dimension positive ou nulle. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_array_type_get_dimension_number(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GArrayType *type; /* Version GLib du type */ + ssize_t dim; /* Taille du tableau */ + + type = G_ARRAY_TYPE(pygobject_get(self)); + + dim = g_array_type_get_dimension_number(type); + + result = PyLong_FromSsize_t(dim); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit la dimension associée au tableau. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_array_type_set_dimension_number(PyObject *self, PyObject *value, void *closure) +{ + GArrayType *type; /* Version GLib du type */ + + if (!PyLong_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a number.")); + return -1; + } + + type = G_ARRAY_TYPE(pygobject_get(self)); + + g_array_type_set_dimension_number(type, PyLong_AsSsize_t(value)); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit la dimension associée au tableau. * +* * +* Retour : Expression de dimension. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_array_type_get_dimension_expression(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GArrayType *type; /* Version GLib du type */ + const char *dim; /* Taille du tableau */ + + type = G_ARRAY_TYPE(pygobject_get(self)); + + dim = g_array_type_get_dimension_expression(type); + + result = PyUnicode_FromString(dim); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit la dimension associée au tableau. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_array_type_set_dimension_expression(PyObject *self, PyObject *value, void *closure) +{ + GArrayType *type; /* Version GLib du type */ + + if (!PyUnicode_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string.")); + return -1; + } + + type = G_ARRAY_TYPE(pygobject_get(self)); + + g_array_type_set_dimension_expression(type, strdup(PyUnicode_DATA(value))); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_array_type_type(void) +{ + static PyMethodDef py_array_type_methods[] = { + { NULL } + }; + + static PyGetSetDef py_array_type_getseters[] = { + { + "members", py_array_type_get_members_type, NULL, + "Provide the type of each members of the array.", NULL + }, + { + "numbered", py_array_type_is_numbered, NULL, + "Tell if the dimension of the array is a number.", NULL + }, + { + "dimension", py_array_type_get_dimension, NULL, + "Provide the array dimension.", NULL + }, + { + "dimension_number", py_array_type_get_dimension_number, py_array_type_set_dimension_number, + "Give access to the array dimension as number.", NULL + }, + { + "dimension_expression", py_array_type_get_dimension_expression, py_array_type_set_dimension_expression, + "Give access to the array dimension as expression.", NULL + }, + { NULL } + }; + + static PyTypeObject py_array_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.ArrayType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide array type", + + .tp_methods = py_array_type_methods, + .tp_getset = py_array_type_getseters, + .tp_new = (newfunc)py_array_type_new + + }; + + return &py_array_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....types.ArrayType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_array_type(PyObject *module) +{ + PyTypeObject *py_array_type_type; /* Type Python 'ArrayType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_array_type_type = get_python_array_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_ARRAY_TYPE, py_array_type_type, get_python_data_type_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/array.h b/plugins/pychrysalide/analysis/types/array.h new file mode 100644 index 0000000..8762548 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/array.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * array.h - prototypes pour l'équivalent Python du fichier "analysis/types/array.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_ARRAY_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_ARRAY_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_array_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.ArrayType'. */ +bool register_python_array_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_ARRAY_H */ diff --git a/plugins/pychrysalide/analysis/types/basic.c b/plugins/pychrysalide/analysis/types/basic.c new file mode 100644 index 0000000..e3bde6e --- /dev/null +++ b/plugins/pychrysalide/analysis/types/basic.c @@ -0,0 +1,250 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * basic.c - équivalent Python du fichier "analysis/types/basic.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "basic.h" + + +#include <pygobject.h> + + +#include <i18n.h> +#include <analysis/types/basic.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'BasicType'. */ +static PyObject *py_basic_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le type de base géré par le type. */ +static PyObject *py_basic_type_get_base_type(PyObject *, void *); + +/* Définit les constantes pour les types de base. */ +static bool py_basic_type_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'BasicType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_basic_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + unsigned long base; /* Type de base à créer */ + int ret; /* Bilan de lecture des args. */ + GDataType *dtype; /* Version GLib du type */ + + ret = PyArg_ParseTuple(args, "k", &base); + if (!ret) return NULL; + + if (base >= BTP_INVALID) + { + PyErr_SetString(PyExc_TypeError, _("Bad basic type.")); + return NULL; + } + + dtype = g_basic_type_new(base); + result = pygobject_new(G_OBJECT(dtype)); + g_object_unref(dtype); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type de base géré par le type. * +* * +* Retour : Type basique. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_basic_type_get_base_type(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GBasicType *type; /* Version GLib du type */ + BaseType base; /* Type de base à renvoyer */ + + type = G_BASIC_TYPE(pygobject_get(self)); + + base = g_basic_type_get_base_type(type); + + result = PyLong_FromUnsignedLong(base); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_basic_type_type(void) +{ + static PyMethodDef py_basic_type_methods[] = { + { NULL } + }; + + static PyGetSetDef py_basic_type_getseters[] = { + { + "base", py_basic_type_get_base_type, NULL, + "Provide the internal identifier of the basic type.", NULL + }, + { NULL } + }; + + static PyTypeObject py_basic_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.BasicType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide basic type", + + .tp_methods = py_basic_type_methods, + .tp_getset = py_basic_type_getseters, + .tp_new = (newfunc)py_basic_type_new + + }; + + return &py_basic_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les types de base. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_basic_type_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, BTP_VOID); + result &= PyDict_AddIntMacro(obj_type, BTP_WCHAR_T); + result &= PyDict_AddIntMacro(obj_type, BTP_BOOL); + result &= PyDict_AddIntMacro(obj_type, BTP_CHAR); + result &= PyDict_AddIntMacro(obj_type, BTP_SCHAR); + result &= PyDict_AddIntMacro(obj_type, BTP_UCHAR); + result &= PyDict_AddIntMacro(obj_type, BTP_SHORT); + result &= PyDict_AddIntMacro(obj_type, BTP_USHORT); + result &= PyDict_AddIntMacro(obj_type, BTP_INT); + result &= PyDict_AddIntMacro(obj_type, BTP_UINT); + result &= PyDict_AddIntMacro(obj_type, BTP_LONG); + result &= PyDict_AddIntMacro(obj_type, BTP_ULONG); + result &= PyDict_AddIntMacro(obj_type, BTP_LONG_LONG); + result &= PyDict_AddIntMacro(obj_type, BTP_ULONG_LONG); + result &= PyDict_AddIntMacro(obj_type, BTP_INT128); + result &= PyDict_AddIntMacro(obj_type, BTP_UINT128); + result &= PyDict_AddIntMacro(obj_type, BTP_FLOAT); + result &= PyDict_AddIntMacro(obj_type, BTP_DOUBLE); + result &= PyDict_AddIntMacro(obj_type, BTP_LONG_DOUBLE); + result &= PyDict_AddIntMacro(obj_type, BTP_FLOAT128); + result &= PyDict_AddIntMacro(obj_type, BTP_ELLIPSIS); + result &= PyDict_AddIntMacro(obj_type, BTP_754R_64); + result &= PyDict_AddIntMacro(obj_type, BTP_754R_128); + result &= PyDict_AddIntMacro(obj_type, BTP_754R_32); + result &= PyDict_AddIntMacro(obj_type, BTP_754R_16); + result &= PyDict_AddIntMacro(obj_type, BTP_CHAR32_T); + result &= PyDict_AddIntMacro(obj_type, BTP_CHAR16_T); + + result &= PyDict_AddIntMacro(obj_type, BTP_INVALID); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....types.BasicType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_basic_type(PyObject *module) +{ + PyTypeObject *py_basic_type_type; /* Type Python 'BasicType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_basic_type_type = get_python_basic_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_BASIC_TYPE, py_basic_type_type, get_python_data_type_type())) + return false; + + if (!py_basic_type_define_constants(py_basic_type_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/basic.h b/plugins/pychrysalide/analysis/types/basic.h new file mode 100644 index 0000000..ced9312 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/basic.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * basic.h - prototypes pour l'équivalent Python du fichier "analysis/types/basic.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_BASIC_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_BASIC_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_basic_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.BasicType'. */ +bool register_python_basic_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_BASIC_H */ diff --git a/plugins/pychrysalide/analysis/types/cse.c b/plugins/pychrysalide/analysis/types/cse.c new file mode 100644 index 0000000..ff3984f --- /dev/null +++ b/plugins/pychrysalide/analysis/types/cse.c @@ -0,0 +1,269 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * cse.c - équivalent Python du fichier "analysis/types/cse.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "cse.h" + + +#include <pygobject.h> + + +#include <i18n.h> +#include <analysis/types/cse.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'ClassEnumType'. */ +static PyObject *py_class_enum_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le type pris en compte géré par le type. */ +static PyObject *py_class_enum_type_get_base_type(PyObject *, void *); + +/* Donne la désignation de la classe / structure / énumération. */ +static PyObject *py_class_enum_type_get_name(PyObject *, void *); + +/* Définit les constantes pour les types de classe/énumération. */ +static bool py_class_enum_type_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'ClassEnumType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_class_enum_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + unsigned long base; /* Type de base à créer */ + const char *name; /* Désignation humaine */ + int ret; /* Bilan de lecture des args. */ + GDataType *dtype; /* Version GLib du type */ + + ret = PyArg_ParseTuple(args, "ks", &base, &name); + if (!ret) return NULL; + + if (base >= CET_COUNT) + { + PyErr_SetString(PyExc_TypeError, _("Bad basic type.")); + return NULL; + } + + dtype = g_class_enum_type_new(base, strdup(name)); + result = pygobject_new(G_OBJECT(dtype)); + g_object_unref(dtype); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type pris en compte géré par le type. * +* * +* Retour : Type pris en compte. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_class_enum_type_get_base_type(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GClassEnumType *type; /* Version GLib du type */ + ClassEnumType base; /* Type de base à renvoyer */ + + type = G_CLASS_ENUM_TYPE(pygobject_get(self)); + + base = g_class_enum_type_get_base(type); + + result = PyLong_FromUnsignedLong(base); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Donne la désignation de la classe / structure / énumération. * +* * +* Retour : Chaîne de caractères. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_class_enum_type_get_name(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GClassEnumType *type; /* Version GLib du type */ + const char *name; /* Désignation humaine */ + + type = G_CLASS_ENUM_TYPE(pygobject_get(self)); + + name = g_class_enum_type_get_name(type); + + result = PyUnicode_FromString(name); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_class_enum_type_type(void) +{ + static PyMethodDef py_class_enum_type_methods[] = { + { NULL } + }; + + static PyGetSetDef py_class_enum_type_getseters[] = { + { + "base", py_class_enum_type_get_base_type, NULL, + "Provide the internal identifier of the type.", NULL + }, + { + "name", py_class_enum_type_get_name, NULL, + "Provide the name of the type.", NULL + }, + { NULL } + }; + + static PyTypeObject py_class_enum_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.ClassEnumType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide basic type", + + .tp_methods = py_class_enum_type_methods, + .tp_getset = py_class_enum_type_getseters, + .tp_new = (newfunc)py_class_enum_type_new + + }; + + return &py_class_enum_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les types de classe/énumération. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_class_enum_type_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, CET_UNKNOWN); + result &= PyDict_AddIntMacro(obj_type, CET_STRUCT); + result &= PyDict_AddIntMacro(obj_type, CET_ENUM); + result &= PyDict_AddIntMacro(obj_type, CET_CLASS); + result &= PyDict_AddIntMacro(obj_type, CET_NAMESPACE); + result &= PyDict_AddIntMacro(obj_type, CET_VIRTUAL_TABLE); + result &= PyDict_AddIntMacro(obj_type, CET_VIRTUAL_STRUCT); + + result &= PyDict_AddIntMacro(obj_type, CET_COUNT); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....ClassEnumType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_class_enum_type(PyObject *module) +{ + PyTypeObject *py_class_enum_type_type; /* Type Python 'ClassEnumType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_class_enum_type_type = get_python_class_enum_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_CLASS_ENUM_TYPE, + py_class_enum_type_type, get_python_data_type_type())) + return false; + + if (!py_class_enum_type_define_constants(py_class_enum_type_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/cse.h b/plugins/pychrysalide/analysis/types/cse.h new file mode 100644 index 0000000..26d25d6 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/cse.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * cse.h - prototypes pour l'équivalent Python du fichier "analysis/types/cse.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_CSE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_CSE_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_class_enum_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.ClassEnumType'. */ +bool register_python_class_enum_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_CSE_H */ diff --git a/plugins/pychrysalide/analysis/types/encaps.c b/plugins/pychrysalide/analysis/types/encaps.c new file mode 100644 index 0000000..6fa1487 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/encaps.c @@ -0,0 +1,262 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * encaps.c - équivalent Python du fichier "analysis/types/encaps.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "encaps.h" + + +#include <pygobject.h> + + +#include <analysis/types/encaps.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'EncapsulatedType'. */ +static PyObject *py_encapsulated_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le type encapsulée dans le type. */ +static PyObject *py_encapsulated_type_get_item(PyObject *, void *); + +/* Définit les constantes pour les types d'encapsulation. */ +static bool py_encapsulated_type_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'EncapsulatedType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_encapsulated_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + EncapsulationType encapsulation; /* Type d'encapsulation */ + PyObject *encaps_obj; /* Objet du type encapsulé */ + int ret; /* Bilan de lecture des args. */ + GDataType *encapsulated; /* Type encapsulé */ + GDataType *dtype; /* Version GLib du type */ + + ret = PyArg_ParseTuple(args, "kO!", &encapsulation, get_python_data_type_type(), &encaps_obj); + if (!ret) return NULL; + + encapsulated = G_DATA_TYPE(pygobject_get(encaps_obj)); + + dtype = g_encapsulated_type_new(encapsulation, encapsulated); + result = pygobject_new(G_OBJECT(dtype)); + g_object_unref(dtype); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type d'encapsulation gérée par le type. * +* * +* Retour : Type d'encapsulation gérée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_encapsulated_type_get_etype(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GEncapsulatedType *type; /* Version GLib du type */ + EncapsulationType encapsulation; /* Type d'encapsulation */ + + type = G_ENCAPSULATED_TYPE(pygobject_get(self)); + + encapsulation = g_encapsulated_type_get_etype(type); + + result = PyLong_FromUnsignedLong(encapsulation); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type encapsulée dans le type. * +* * +* Retour : Sous-type encapsulé dans le type. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_encapsulated_type_get_item(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GEncapsulatedType *type; /* Version GLib du type */ + GDataType *encapsulated; /* Type encapsulé */ + + type = G_ENCAPSULATED_TYPE(pygobject_get(self)); + + encapsulated = g_encapsulated_type_get_item(type); + + result = pygobject_new(G_OBJECT(encapsulated)); + + g_object_unref(encapsulated); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_encapsulated_type_type(void) +{ + static PyMethodDef py_encapsulated_type_methods[] = { + { NULL } + }; + + static PyGetSetDef py_encapsulated_type_getseters[] = { + { + "etype", py_encapsulated_type_get_etype, NULL, + "Provide the encapsultion type.", NULL + }, + { + "item", py_encapsulated_type_get_item, NULL, + "Provide the encapsulted type.", NULL + }, + { NULL } + }; + + static PyTypeObject py_encapsulated_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.EncapsulatedType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide encapsulated type", + + .tp_methods = py_encapsulated_type_methods, + .tp_getset = py_encapsulated_type_getseters, + .tp_new = (newfunc)py_encapsulated_type_new + + }; + + return &py_encapsulated_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les types d'encapsulation. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_encapsulated_type_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, ECT_POINTER); + result &= PyDict_AddIntMacro(obj_type, ECT_REFERENCE); + result &= PyDict_AddIntMacro(obj_type, ECT_RVALUE_REF); + result &= PyDict_AddIntMacro(obj_type, ECT_COMPLEX); + result &= PyDict_AddIntMacro(obj_type, ECT_IMAGINARY); + + result &= PyDict_AddIntMacro(obj_type, ECT_COUNT); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....EncapsulatedType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_encapsulated_type(PyObject *module) +{ + PyTypeObject *py_encapsulated_type_type;/* Type 'EncapsulatedType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_encapsulated_type_type = get_python_encapsulated_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_ENCAPSULATED_TYPE, + py_encapsulated_type_type, get_python_data_type_type())) + return false; + + if (!py_encapsulated_type_define_constants(py_encapsulated_type_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/encaps.h b/plugins/pychrysalide/analysis/types/encaps.h new file mode 100644 index 0000000..227527e --- /dev/null +++ b/plugins/pychrysalide/analysis/types/encaps.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * encaps.h - prototypes pour l'équivalent Python du fichier "analysis/types/encaps.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_ENCAPS_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_ENCAPS_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_encapsulated_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.EncapsulatedType'. */ +bool register_python_encapsulated_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_ENCAPS_H */ diff --git a/plugins/pychrysalide/analysis/types/expr.c b/plugins/pychrysalide/analysis/types/expr.c new file mode 100644 index 0000000..2988af9 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/expr.c @@ -0,0 +1,185 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * expr.c - équivalent Python du fichier "analysis/types/expr.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "expr.h" + + +#include <pygobject.h> +#include <string.h> + + +#include <analysis/types/expr.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'ExprType'. */ +static PyObject *py_expr_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit la valeur d'un type fourni sous forme de caractères. */ +static PyObject *py_expr_type_get_value(PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'ExprType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_expr_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + const char *value; /* Valeur brute de l'expression*/ + int ret; /* Bilan de lecture des args. */ + GDataType *dtype; /* Version GLib du type */ + + ret = PyArg_ParseTuple(args, "s", &value); + if (!ret) return NULL; + + dtype = g_expr_type_new(strdup(value)); + result = pygobject_new(G_OBJECT(dtype)); + g_object_unref(dtype); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit la valeur d'un type fourni sous forme de caractères. * +* * +* Retour : Chaîne formant une expression. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_expr_type_get_value(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GExprType *type; /* Version GLib du type */ + const char *value; /* Valeur exprimée */ + + type = G_EXPR_TYPE(pygobject_get(self)); + + value = g_expr_type_get_value(type); + + result = PyUnicode_FromString(value); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_expr_type_type(void) +{ + static PyMethodDef py_expr_type_methods[] = { + { NULL } + }; + + static PyGetSetDef py_expr_type_getseters[] = { + { + "value", py_expr_type_get_value, NULL, + "Provide the value of the expression type.", NULL + }, + { NULL } + }; + + static PyTypeObject py_expr_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.ExprType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide expr type", + + .tp_methods = py_expr_type_methods, + .tp_getset = py_expr_type_getseters, + .tp_new = (newfunc)py_expr_type_new + + }; + + return &py_expr_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....types.ExprType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_expr_type(PyObject *module) +{ + PyTypeObject *py_expr_type_type; /* Type Python 'ExprType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_expr_type_type = get_python_expr_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_EXPR_TYPE, py_expr_type_type, get_python_data_type_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/expr.h b/plugins/pychrysalide/analysis/types/expr.h new file mode 100644 index 0000000..4764892 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/expr.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * expr.h - prototypes pour l'équivalent Python du fichier "analysis/types/expr.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_EXPR_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_EXPR_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_expr_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.ExprType'. */ +bool register_python_expr_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_EXPR_H */ diff --git a/plugins/pychrysalide/analysis/types/literal.c b/plugins/pychrysalide/analysis/types/literal.c new file mode 100644 index 0000000..7523153 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/literal.c @@ -0,0 +1,135 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * literal.c - équivalent Python du fichier "analysis/types/literal.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "literal.h" + + +#include <pygobject.h> + + +#include <analysis/types/literal.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'LiteralType'. */ +static PyObject *py_literal_type_new(PyTypeObject *, PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'LiteralType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_literal_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_literal_type_type(void) +{ + static PyMethodDef py_literal_type_methods[] = { + { NULL } + }; + + static PyGetSetDef py_literal_type_getseters[] = { + { NULL } + }; + + static PyTypeObject py_literal_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.LiteralType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide literal type", + + .tp_methods = py_literal_type_methods, + .tp_getset = py_literal_type_getseters, + .tp_new = (newfunc)py_literal_type_new + + }; + + return &py_literal_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....types.LiteralType'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_literal_type(PyObject *module) +{ + PyTypeObject *py_literal_type_type; /* Type 'LiteralType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_literal_type_type = get_python_literal_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_LITERAL_TYPE, py_literal_type_type, get_python_data_type_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/literal.h b/plugins/pychrysalide/analysis/types/literal.h new file mode 100644 index 0000000..8340093 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/literal.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * literal.h - prototypes pour l'équivalent Python du fichier "analysis/types/literal.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_LITERAL_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_LITERAL_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_literal_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.LiteralType'. */ +bool register_python_literal_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_LITERAL_H */ diff --git a/plugins/pychrysalide/analysis/types/module.c b/plugins/pychrysalide/analysis/types/module.c new file mode 100644 index 0000000..1566014 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/module.c @@ -0,0 +1,107 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire types en tant que module + * + * Copyright (C) 2014-2017 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "module.h" + + +#include <assert.h> + + +#include "array.h" +#include "basic.h" +#include "cse.h" +#include "encaps.h" +#include "expr.h" +#include "literal.h" +#include "override.h" +#include "proto.h" +#include "template.h" +#include "../../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'types' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_analysis_types_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_types_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.analysis.types", + .m_doc = "Python module for Chrysalide.analysis.types", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_types_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_types_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.types"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "types", module); + if (ret != 0) goto loading_failed; + + result = register_python_array_type(module); + if (result) result = register_python_basic_type(module); + if (result) result = register_python_class_enum_type(module); + if (result) result = register_python_expr_type(module); + if (result) result = register_python_encapsulated_type(module); + if (result) result = register_python_literal_type(module); + if (result) result = register_python_override_type(module); + if (result) result = register_python_proto_type(module); + if (result) result = register_python_template_type(module); + + if (result) + register_access_to_python_module("pychrysalide.analysis.types", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/analysis/types/module.h b/plugins/pychrysalide/analysis/types/module.h new file mode 100644 index 0000000..2c6824d --- /dev/null +++ b/plugins/pychrysalide/analysis/types/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire types en tant que module + * + * Copyright (C) 2014-2017 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_MODULE_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Ajoute le module 'types' au module Python. */ +bool add_analysis_types_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_MODULE_H */ diff --git a/plugins/pychrysalide/analysis/types/override.c b/plugins/pychrysalide/analysis/types/override.c new file mode 100644 index 0000000..17e32e3 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/override.c @@ -0,0 +1,247 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * override.c - équivalent Python du fichier "analysis/types/override.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "override.h" + + +#include <pygobject.h> + + +#include <analysis/types/override.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'OverrideType'. */ +static PyObject *py_override_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le type de base comportant la fonction virtuelle. */ +static PyObject *py_override_type_get_base(PyObject *, void *); + +/* Fournit les décalages appliquée pour une fonction virtuelle. */ +static PyObject *py_override_type_get_offsets(PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'OverrideType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_override_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type de base comportant la fonction virtuelle. * +* * +* Retour : Type de base traité. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_override_type_get_base(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GOverrideType *type; /* Version GLib du type */ + GDataType *base; /* Base du type */ + + type = G_OVERRIDE_TYPE(pygobject_get(self)); + + base = g_override_type_get_base(type); + + result = pygobject_new(G_OBJECT(base)); + + g_object_unref(base); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit les décalages appliquée pour une fonction virtuelle. * +* * +* Retour : Liste des décalages. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_override_type_get_offsets(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GOverrideType *type; /* Version GLib du type */ + call_offset_t off0; /* Infos du premier décalage */ + call_offset_t off1; /* Infos du second décalage */ + bool with_covariant; /* Validité du second champ */ + PyObject *offset; /* Transcription intermédiaire */ + + type = G_OVERRIDE_TYPE(pygobject_get(self)); + + with_covariant = g_override_type_get_offsets(type, &off0, &off1);; + + result = PyTuple_New(with_covariant ? 2 : 1); + + if (off0.virtual) + { + offset = PyTuple_New(2); + PyTuple_SetItem(result, 0, PyLong_FromSsize_t(off0.values[0])); + PyTuple_SetItem(result, 1, PyLong_FromSsize_t(off0.values[1])); + } + else + { + offset = PyTuple_New(1); + PyTuple_SetItem(result, 0, PyLong_FromSsize_t(off0.values[0])); + } + + PyTuple_SetItem(result, 0, offset); + + if (with_covariant) + { + if (off1.virtual) + { + offset = PyTuple_New(2); + PyTuple_SetItem(result, 0, PyLong_FromSsize_t(off1.values[0])); + PyTuple_SetItem(result, 1, PyLong_FromSsize_t(off1.values[1])); + } + else + { + offset = PyTuple_New(1); + PyTuple_SetItem(result, 0, PyLong_FromSsize_t(off1.values[0])); + } + + PyTuple_SetItem(result, 1, offset); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_override_type_type(void) +{ + static PyMethodDef py_override_type_methods[] = { + { NULL } + }; + + static PyGetSetDef py_override_type_getseters[] = { + { + "base", py_override_type_get_base, NULL, + "Provide the base of the override type.", NULL + }, + { + "offsets", py_override_type_get_offsets, NULL, + "Provide the offsets of the override type.", NULL + }, + { NULL } + }; + + static PyTypeObject py_override_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.OverrideType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide override type", + + .tp_methods = py_override_type_methods, + .tp_getset = py_override_type_getseters, + .tp_new = (newfunc)py_override_type_new + + }; + + return &py_override_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....OverrideType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_override_type(PyObject *module) +{ + PyTypeObject *py_override_type_type;/* Type 'OverrideType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_override_type_type = get_python_override_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_OVERRIDE_TYPE, + py_override_type_type, get_python_data_type_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/override.h b/plugins/pychrysalide/analysis/types/override.h new file mode 100644 index 0000000..2e874ca --- /dev/null +++ b/plugins/pychrysalide/analysis/types/override.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * override.h - prototypes pour l'équivalent Python du fichier "analysis/types/override.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_OVERRIDE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_OVERRIDE_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_override_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.OverrideType'. */ +bool register_python_override_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_OVERRIDE_H */ diff --git a/plugins/pychrysalide/analysis/types/proto.c b/plugins/pychrysalide/analysis/types/proto.c new file mode 100644 index 0000000..ac60deb --- /dev/null +++ b/plugins/pychrysalide/analysis/types/proto.c @@ -0,0 +1,314 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * proto.c - équivalent Python du fichier "analysis/types/proto.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "proto.h" + + +#include <pygobject.h> + + +#include <i18n.h> +#include <analysis/types/proto.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'ProtoType'. */ +static PyObject *py_proto_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Ajoute un argument à un prototype. */ +static PyObject *py_proto_type_add_arg(PyObject *, PyObject *); + +/* Fournit le type de retour d'un prototype. */ +static PyObject *py_proto_type_get_return_type(PyObject *, void *); + +/* Définit le type de retour d'un prototype. */ +static int py_proto_type_set_return_type(PyObject *, PyObject *, void *); + +/* Fournit les arguments du prototype. */ +static PyObject *py_proto_type_get_args(PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'ProtoType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_proto_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + GDataType *dtype; /* Version GLib du type */ + + dtype = g_proto_type_new(); + result = pygobject_new(G_OBJECT(dtype)); + g_object_unref(dtype); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = projet d'étude à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Ajoute un argument à un prototype. * +* * +* Retour : Py_None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_proto_type_add_arg(PyObject *self, PyObject *args) +{ + PyObject *arg_obj; /* Objet du type d'argument */ + int ret; /* Bilan de lecture des args. */ + GDataType *arg; /* Version GLib du type */ + GProtoType *type; /* Version GLib du type */ + + ret = PyArg_ParseTuple(args, "O!", get_python_data_type_type(), &arg_obj); + if (!ret) return NULL; + + type = G_PROTO_TYPE(pygobject_get(self)); + + arg = G_DATA_TYPE(pygobject_get(arg_obj)); + + g_object_ref(G_OBJECT(arg)); + g_proto_type_add_arg(type, arg); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type de retour d'un prototype. * +* * +* Retour : Indication sur le type de retour en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_proto_type_get_return_type(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GProtoType *type; /* Version GLib du type */ + GDataType *ret; /* Type de retour du prototype */ + + type = G_PROTO_TYPE(pygobject_get(self)); + + ret = g_proto_type_get_return_type(type); + + result = pygobject_new(G_OBJECT(ret)); + + g_object_unref(ret); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit le type de retour d'un prototype. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_proto_type_set_return_type(PyObject *self, PyObject *value, void *closure) +{ + GProtoType *type; /* Version GLib du type */ + GDataType *ret; /* Type de retour du prototype */ + + if (!PyObject_IsInstance(value, (PyObject *)get_python_data_type_type())) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a GDataType.")); + return -1; + } + + type = G_PROTO_TYPE(pygobject_get(self)); + + ret = G_DATA_TYPE(pygobject_get(value)); + + g_object_ref(ret); + g_proto_type_set_return_type(type, ret); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit les arguments du prototype. * +* * +* Retour : Liste de types d'arguments. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_proto_type_get_args(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GProtoType *type; /* Version GLib du type */ + size_t count; /* Nombre d'arguments */ + size_t i; /* Boucle de parcours */ + GDataType *arg; /* Argument du prototype */ + + type = G_PROTO_TYPE(pygobject_get(self)); + + count = g_proto_type_count_args(type); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + arg = g_proto_type_get_arg(type, i); + + PyTuple_SetItem(result, i, pygobject_new(G_OBJECT(arg))); + + g_object_unref(arg); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_proto_type_type(void) +{ + static PyMethodDef py_proto_type_methods[] = { + { + "add_arg", py_proto_type_add_arg, + METH_VARARGS, + "add_arg($self, type, /)\n--\n\nAdd an extra argument to the prototype." + }, + { NULL } + }; + + static PyGetSetDef py_proto_type_getseters[] = { + { + "return", py_proto_type_get_return_type, py_proto_type_set_return_type, + "Provide the return type of the prototype.", NULL + }, + { + "args", py_proto_type_get_args, NULL, + "Give all arguments of the prototype.", NULL + }, + { NULL } + }; + + static PyTypeObject py_proto_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.ProtoType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide proto type", + + .tp_methods = py_proto_type_methods, + .tp_getset = py_proto_type_getseters, + .tp_new = (newfunc)py_proto_type_new + + }; + + return &py_proto_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....types.ProtoType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_proto_type(PyObject *module) +{ + PyTypeObject *py_proto_type_type; /* Type Python 'ProtoType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_proto_type_type = get_python_proto_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_PROTO_TYPE, py_proto_type_type, get_python_data_type_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/proto.h b/plugins/pychrysalide/analysis/types/proto.h new file mode 100644 index 0000000..4e98df2 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/proto.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * proto.h - prototypes pour l'équivalent Python du fichier "analysis/types/proto.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_PROTO_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_PROTO_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_proto_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.ProtoType'. */ +bool register_python_proto_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_PROTO_H */ diff --git a/plugins/pychrysalide/analysis/types/template.c b/plugins/pychrysalide/analysis/types/template.c new file mode 100644 index 0000000..b8b13fb --- /dev/null +++ b/plugins/pychrysalide/analysis/types/template.c @@ -0,0 +1,311 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * template.c - équivalent Python du fichier "analysis/types/template.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "template.h" + + +#include <pygobject.h> +#include <string.h> + + +#include <i18n.h> +#include <analysis/types/template.h> + + +#include "../type.h" +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'TemplateType'. */ +static PyObject *py_template_type_new(PyTypeObject *, PyObject *, PyObject *); + +/* Ajoute un paramètre à un gabarit. */ +static PyObject *py_template_type_add_param(PyObject *, PyObject *); + +/* Indique la désignation principale du type. */ +static PyObject *py_template_type_get_name(PyObject *, void *); + +/* Précise la désignation principale du type. */ +static int py_template_type_set_name(PyObject *, PyObject *, void *); + +/* Fournit les arguments du gabarit. */ +static PyObject *py_template_type_get_params(PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'TemplateType'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_template_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + GDataType *dtype; /* Version GLib du type */ + + dtype = g_template_type_new(); + result = pygobject_new(G_OBJECT(dtype)); + g_object_unref(dtype); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = projet d'étude à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Ajoute un paramètre à un gabarit. * +* * +* Retour : Py_None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_template_type_add_param(PyObject *self, PyObject *args) +{ + PyObject *param_obj; /* Objet du type de paramètre */ + int ret; /* Bilan de lecture des args. */ + GDataType *param; /* Version GLib du type */ + GTemplateType *type; /* Version GLib du type */ + + ret = PyArg_ParseTuple(args, "O!", get_python_data_type_type(), ¶m_obj); + if (!ret) return NULL; + + type = G_TEMPLATE_TYPE(pygobject_get(self)); + + param = G_DATA_TYPE(pygobject_get(param_obj)); + + g_object_ref(G_OBJECT(param)); + g_template_type_add_param(type, param); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique la désignation principale du type. * +* * +* Retour : Désignation humaine du type. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_template_type_get_name(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GTemplateType *type; /* Version GLib du type */ + const char *name; /* Désignation humaine */ + + type = G_TEMPLATE_TYPE(pygobject_get(self)); + + name = g_template_type_get_name(type); + + result = PyUnicode_FromString(name); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Précise la désignation principale du type. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_template_type_set_name(PyObject *self, PyObject *value, void *closure) +{ + GTemplateType *type; /* Version GLib du type */ + + if (!PyUnicode_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string.")); + return -1; + } + + type = G_TEMPLATE_TYPE(pygobject_get(self)); + + g_template_type_set_name(type, strdup(PyUnicode_DATA(value))); + + return 0; + +} + + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit les arguments du gabarit. * +* * +* Retour : Liste de types de paramètres. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_template_type_get_params(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GTemplateType *type; /* Version GLib du type */ + size_t count; /* Nombre de paramètres */ + size_t i; /* Boucle de parcours */ + GDataType *param; /* Paramètre du gabarit */ + + type = G_TEMPLATE_TYPE(pygobject_get(self)); + + count = g_template_type_count_params(type); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + param = g_template_type_get_param(type, i); + + PyTuple_SetItem(result, i, pygobject_new(G_OBJECT(param))); + + g_object_unref(param); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_template_type_type(void) +{ + static PyMethodDef py_template_type_methods[] = { + { + "add_param", py_template_type_add_param, + METH_VARARGS, + "add_param($self, type, /)\n--\n\nAdd an extra parameter to the template type." + }, + { NULL } + }; + + static PyGetSetDef py_template_type_getseters[] = { + { + "name", py_template_type_get_name, py_template_type_set_name, + "Give access to the name of the template type.", NULL + }, + { + "params", py_template_type_get_params, NULL, + "Give all parameters of the template type.", NULL + }, + { NULL } + }; + + static PyTypeObject py_template_type_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.types.TemplateType", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide template type", + + .tp_methods = py_template_type_methods, + .tp_getset = py_template_type_getseters, + .tp_new = (newfunc)py_template_type_new + + }; + + return &py_template_type_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....TemplateType'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_template_type(PyObject *module) +{ + PyTypeObject *py_template_type_type; /* Type Python 'TemplateType' */ + PyObject *dict; /* Dictionnaire du module */ + + py_template_type_type = get_python_template_type_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_TEMPLATE_TYPE, + py_template_type_type, get_python_data_type_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/types/template.h b/plugins/pychrysalide/analysis/types/template.h new file mode 100644 index 0000000..d5665e1 --- /dev/null +++ b/plugins/pychrysalide/analysis/types/template.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * template.h - templatetypes pour l'équivalent Python du fichier "analysis/types/template.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_TEMPLATE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_TEMPLATE_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_template_type_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.types.TemplateType'. */ +bool register_python_template_type(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_TEMPLATE_H */ |