summaryrefslogtreecommitdiff
path: root/src/analysis/types
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2012-10-12 07:28:19 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2012-10-12 07:28:19 (GMT)
commitc7a14e50bd002e3922969e9bae7816753aefb073 (patch)
treecd098d2f92880705810dfdc353dad6ad1412b2c2 /src/analysis/types
parent4a51f37982c2d5d358971e947d05786b939af88e (diff)
Reorganized types definitions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@267 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/types')
-rwxr-xr-xsrc/analysis/types/Makefile.am23
-rw-r--r--src/analysis/types/basic.c309
-rw-r--r--src/analysis/types/basic.h96
-rw-r--r--src/analysis/types/cse-int.h56
-rw-r--r--src/analysis/types/cse.c153
-rw-r--r--src/analysis/types/cse.h69
-rw-r--r--src/analysis/types/encaps.c313
-rw-r--r--src/analysis/types/encaps.h78
-rw-r--r--src/analysis/types/literal.c205
-rw-r--r--src/analysis/types/literal.h67
-rw-r--r--src/analysis/types/template.c283
-rw-r--r--src/analysis/types/template.h67
12 files changed, 1719 insertions, 0 deletions
diff --git a/src/analysis/types/Makefile.am b/src/analysis/types/Makefile.am
new file mode 100755
index 0000000..25a8a38
--- /dev/null
+++ b/src/analysis/types/Makefile.am
@@ -0,0 +1,23 @@
+
+noinst_LTLIBRARIES = libanalysistypes.la
+
+libanalysistypes_la_SOURCES = \
+ basic.h basic.c \
+ cse-int.h \
+ cse.h cse.c \
+ encaps.h encaps.c \
+ literal.h literal.c \
+ template.h template.c
+
+libanalysistypes_la_LIBADD =
+
+libanalysistypes_la_LDFLAGS =
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+SUBDIRS =
diff --git a/src/analysis/types/basic.c b/src/analysis/types/basic.c
new file mode 100644
index 0000000..436b04e
--- /dev/null
+++ b/src/analysis/types/basic.c
@@ -0,0 +1,309 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * basic.c - manipulation des types de données de base
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "basic.h"
+
+
+#include <string.h>
+
+
+#include "../type-int.h"
+
+
+
+/* Description de type basique (instance) */
+struct _GBasicType
+{
+ GDataType parent; /* A laisser en premier */
+
+ BaseType type; /* Type représenté si connu */
+
+};
+
+/* Description de type basique (classe) */
+struct _GBasicTypeClass
+{
+ GDataTypeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des types basiques. */
+static void g_basic_type_class_init(GBasicTypeClass *);
+
+/* Initialise l'instance d'un type basique. */
+static void g_basic_type_init(GBasicType *);
+
+/* Crée un copie d'un type existant. */
+static GDataType *g_basic_type_dup(const GBasicType *);
+
+/* Décrit le type fourni sous forme de caractères. */
+static char *g_basic_type_to_string(const GBasicType *);
+
+
+
+/* Indique le type défini pour un type basique. */
+G_DEFINE_TYPE(GBasicType, g_basic_type, G_TYPE_DATA_TYPE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des types basiques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_basic_type_class_init(GBasicTypeClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = instance à initialiser. *
+* *
+* Description : Initialise l'instance d'un type basique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_basic_type_init(GBasicType *type)
+{
+ GDataType *data_type; /* Version basique */
+
+ data_type = G_DATA_TYPE(type);
+
+ data_type->dup = (type_dup_fc)g_basic_type_dup;
+ data_type->to_string = (type_to_string_fc)g_basic_type_to_string;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type simple à représenter. *
+* *
+* Description : Crée une représentation de type basique. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_basic_type_new(BaseType type)
+{
+ GBasicType *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_BASIC_TYPE, NULL);
+
+ result->type = type;
+
+ return G_DATA_TYPE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à dupliquer. *
+* *
+* Description : Crée un copie d'un type existant. *
+* *
+* Retour : Nouvelle instance de type identique à celle fournie. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *g_basic_type_dup(const GBasicType *type)
+{
+ return g_basic_type_new(type->type);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à convertir. *
+* *
+* Description : Décrit le type fourni sous forme de caractères. *
+* *
+* Retour : Chaîne à libérer de la mémoire après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_basic_type_to_string(const GBasicType *type)
+{
+ const char *desc; /* Représentation à copier */
+
+ switch (type->type)
+ {
+ case BTP_VOID:
+ desc = "void";
+ break;
+
+ case BTP_WCHAR_T:
+ desc = "wchar_t";
+ break;
+
+ case BTP_BOOL:
+ desc = "bool";
+ break;
+
+ case BTP_CHAR:
+ desc = "char";
+ break;
+
+ case BTP_SCHAR:
+ desc = "signed char";
+ break;
+
+ case BTP_UCHAR:
+ desc = "unsigned char";
+ break;
+
+ case BTP_SHORT:
+ desc = "short";
+ break;
+
+ case BTP_USHORT:
+ desc = "unsigned short";
+ break;
+
+ case BTP_INT:
+ desc = "int";
+ break;
+
+ case BTP_UINT:
+ desc = "unsigned int";
+ break;
+
+ case BTP_LONG:
+ desc = "long";
+ break;
+
+ case BTP_ULONG:
+ desc = "unsigned long";
+ break;
+
+ case BTP_LONG_LONG:
+ desc = "long long";
+ break;
+
+ case BTP_ULONG_LONG:
+ desc = "unsigned long long";
+ break;
+
+ case BTP_INT128:
+ desc = "__int128";
+ break;
+
+ case BTP_UINT128:
+ desc = "unsigned __int128";
+ break;
+
+ case BTP_FLOAT:
+ desc = "float";
+ break;
+
+ case BTP_DOUBLE:
+ desc = "double";
+ break;
+
+ case BTP_LONG_DOUBLE:
+ desc = "long double";
+ break;
+
+ case BTP_FLOAT128:
+ desc = "__float128";
+ break;
+
+ case BTP_ELLIPSIS:
+ desc = "...";
+ break;
+
+ case BTP_754R_64:
+ desc = "__float754r_64";
+ break;
+
+ case BTP_754R_128:
+ desc = "__float754r_128";
+ break;
+
+ case BTP_754R_32:
+ desc = "__float754r_32";
+ break;
+
+ case BTP_754R_16:
+ desc = "__float754r_16";
+ break;
+
+ case BTP_CHAR32_T:
+ desc = "char32_t";
+ break;
+
+ case BTP_CHAR16_T:
+ desc = "char16_t";
+ break;
+
+ default:
+ case BTP_OTHER:
+ desc = "user";
+ break;
+
+ }
+
+ return strdup(desc);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à consulter. *
+* *
+* Description : Fournit le type de base géré par le type. *
+* *
+* Retour : Type basique. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+BaseType g_basic_type_get_btype(const GBasicType *type)
+{
+ return type->type;
+
+}
diff --git a/src/analysis/types/basic.h b/src/analysis/types/basic.h
new file mode 100644
index 0000000..b58e242
--- /dev/null
+++ b/src/analysis/types/basic.h
@@ -0,0 +1,96 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * basic.h - prototypes pour la manipulation des types de données de base
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_TYPES_BASIC_H
+#define _ANALYSIS_TYPES_BASIC_H
+
+
+#include <glib-object.h>
+
+
+#include "../type.h"
+
+
+
+/* Liste des types de base existants */
+typedef enum _BaseType
+{
+ BTP_VOID, /* void */
+ BTP_WCHAR_T, /* wchar_t */
+ BTP_BOOL, /* bool */
+ BTP_CHAR, /* char */
+ BTP_SCHAR, /* signed char */
+ BTP_UCHAR, /* unsigned char */
+ BTP_SHORT, /* short */
+ BTP_USHORT, /* unsigned short */
+ BTP_INT, /* int */
+ BTP_UINT, /* unsigned int */
+ BTP_LONG, /* long */
+ BTP_ULONG, /* unsigned long */
+ BTP_LONG_LONG, /* long long, __int64 */
+ BTP_ULONG_LONG, /* unsigned long long, __int64 */
+ BTP_INT128, /* __int128 */
+ BTP_UINT128, /* unsigned __int128 */
+ BTP_FLOAT, /* float */
+ BTP_DOUBLE, /* double */
+ BTP_LONG_DOUBLE, /* long double, __float80 */
+ BTP_FLOAT128, /* __float128 */
+ BTP_ELLIPSIS, /* ... */
+ BTP_754R_64, /* IEEE 754r float (64 bits) */
+ BTP_754R_128, /* IEEE 754r float (128 bits) */
+ BTP_754R_32, /* IEEE 754r float (32 bits) */
+ BTP_754R_16, /* IEEE 754r float (16 bits) */
+ BTP_CHAR32_T, /* char32_t */
+ BTP_CHAR16_T, /* char16_t */
+ BTP_OTHER /* Extension utilisateur */
+
+} BaseType;
+
+
+#define G_TYPE_BASIC_TYPE g_basic_type_get_type()
+#define G_BASIC_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_basic_type_get_type(), GBasicType))
+#define G_IS_BASIC_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_basic_type_get_type()))
+#define G_BASIC_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BASIC_TYPE, GBasicTypeClass))
+#define G_IS_BASIC_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BASIC_TYPE))
+#define G_BASIC_TYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BASIC_TYPE, GBasicTypeClass))
+
+
+/* Description de type basique (instance) */
+typedef struct _GBasicType GBasicType;
+
+/* Description de type basique (classe) */
+typedef struct _GBasicTypeClass GBasicTypeClass;
+
+
+/* Indique le type défini pour un type basique. */
+GType g_basic_type_get_type(void);
+
+/* Crée une représentation de type basique. */
+GDataType *g_basic_type_new(BaseType);
+
+/* Fournit le type de base géré par le type. */
+BaseType g_basic_type_get_btype(const GBasicType *);
+
+
+
+#endif /* _ANALYSIS_TYPES_BASIC_H */
diff --git a/src/analysis/types/cse-int.h b/src/analysis/types/cse-int.h
new file mode 100644
index 0000000..2599329
--- /dev/null
+++ b/src/analysis/types/cse-int.h
@@ -0,0 +1,56 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * cse-int.h - prototypes pour la définition interne des types classes / structures / énumérations
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_TYPES_CSE_INT_H
+#define _ANALYSIS_TYPES_CSE_INT_H
+
+
+#include "cse.h"
+#include "../type-int.h"
+
+
+
+/* Description de type classe/structure et enumeration (instance) */
+struct _GClassEnumType
+{
+ GDataType parent; /* A laisser en premier */
+
+ ClassEnumType type; /* Type représenté si connu */
+ char *name; /* Description humaine */
+
+};
+
+/* Description de type classe/structure et enumeration (classe) */
+struct _GClassEnumTypeClass
+{
+ GDataTypeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Décrit le type fourni sous forme de caractères. */
+char *g_class_enum_type_to_string(const GClassEnumType *);
+
+
+
+#endif /* _ANALYSIS_TYPES_CSE_INT_H */
diff --git a/src/analysis/types/cse.c b/src/analysis/types/cse.c
new file mode 100644
index 0000000..40d726e
--- /dev/null
+++ b/src/analysis/types/cse.c
@@ -0,0 +1,153 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * cse.c - manipulation des types classes / structures / énumérations
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "cse.h"
+
+
+#include <string.h>
+
+
+#include "cse-int.h"
+
+
+
+/* Initialise la classe des types classe ou assimilés. */
+static void g_class_enum_type_class_init(GClassEnumTypeClass *);
+
+/* Initialise l'instance d'un type classe ou assimilé. */
+static void g_class_enum_type_init(GClassEnumType *);
+
+/* Crée un copie d'un type existant. */
+static GDataType *g_class_enum_type_dup(const GClassEnumType *);
+
+
+
+/* Indique le type défini pour un type classe ou assimilé. */
+G_DEFINE_TYPE(GClassEnumType, g_class_enum_type, G_TYPE_DATA_TYPE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des types classe ou assimilés. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_class_enum_type_class_init(GClassEnumTypeClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = instance à initialiser. *
+* *
+* Description : Initialise l'instance d'un type classe ou assimilé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_class_enum_type_init(GClassEnumType *type)
+{
+ GDataType *data_type; /* Version basique */
+
+ data_type = G_DATA_TYPE(type);
+
+ data_type->dup = (type_dup_fc)g_class_enum_type_dup;
+ data_type->to_string = (type_to_string_fc)g_class_enum_type_to_string;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de structure à représenter. *
+* name = désignation humaine du type. *
+* *
+* Description : Crée une représentation de classe, structure ou énumération. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_class_enum_type_new(ClassEnumType type, const char *name)
+{
+ GClassEnumType *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_CLASS_ENUM_TYPE, NULL);
+
+ result->type = type;
+ result->name = strdup(name);
+
+ return G_DATA_TYPE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à dupliquer. *
+* *
+* Description : Crée un copie d'un type existant. *
+* *
+* Retour : Nouvelle instance de type identique à celle fournie. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *g_class_enum_type_dup(const GClassEnumType *type)
+{
+ return g_class_enum_type_new(type->type, type->name);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à convertir. *
+* *
+* Description : Décrit le type fourni sous forme de caractères. *
+* *
+* Retour : Chaîne à libérer de la mémoire après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_class_enum_type_to_string(const GClassEnumType *type)
+{
+ return strdup(type->name);
+
+}
diff --git a/src/analysis/types/cse.h b/src/analysis/types/cse.h
new file mode 100644
index 0000000..b7dc669
--- /dev/null
+++ b/src/analysis/types/cse.h
@@ -0,0 +1,69 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * cse.h - prototypes pour la manipulation des types classes / structures / énumérations
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_TYPES_CSE_H
+#define _ANALYSIS_TYPES_CSE_H
+
+
+#include <glib-object.h>
+
+
+#include "../type.h"
+
+
+
+#define G_TYPE_CLASS_ENUM_TYPE g_class_enum_type_get_type()
+#define G_CLASS_ENUM_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_class_enum_type_get_type(), GClassEnumType))
+#define G_IS_CLASS_ENUM_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_class_enum_type_get_type()))
+#define G_CLASS_ENUM_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_CLASS_ENUM_TYPE, GClassEnumTypeClass))
+#define G_IS_CLASS_ENUM_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_CLASS_ENUM_TYPE))
+#define G_CLASS_ENUM_TYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_CLASS_ENUM_TYPE, GClassEnumTypeClass))
+
+
+/* Description de type classe/structure et enumeration (instance) */
+typedef struct _GClassEnumType GClassEnumType;
+
+/* Description de type classe/structure et enumeration (classe) */
+typedef struct _GClassEnumTypeClass GClassEnumTypeClass;
+
+
+/* Type pris en compte */
+typedef enum _ClassEnumType
+{
+ CET_UNKNOWN, /* Statut inconnu */
+ CET_STRUCT, /* Structure */
+ CET_ENUM, /* Enumération */
+ CET_CLASS /* Classe */
+
+} ClassEnumType;
+
+
+/* Indique le type défini pour un type classe ou assimilé. */
+GType g_class_enum_type_get_type(void);
+
+/* Crée une représentation de classe, structure ou énumération. */
+GDataType *g_class_enum_type_new(ClassEnumType, const char *);
+
+
+
+#endif /* _ANALYSIS_TYPES_CSE_H */
diff --git a/src/analysis/types/encaps.c b/src/analysis/types/encaps.c
new file mode 100644
index 0000000..492fd46
--- /dev/null
+++ b/src/analysis/types/encaps.c
@@ -0,0 +1,313 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * encaps.c - manipulation des types de données encapsulés
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "encaps.h"
+
+
+#include "../routine.h"
+#include "../type-int.h"
+#include "../../common/extstr.h"
+
+
+
+/* Description de type encapsulé (instance) */
+struct _GEncapsulatedType
+{
+ GDataType parent; /* A laisser en premier */
+
+ EncapsulationType type; /* Encapsulation utilisée */
+ GDataType *child; /* Sous-type encadré */
+ GBinRoutine *routine; /* Routine pointée */
+
+};
+
+/* Description de type encapsulé (classe) */
+struct _GEncapsulatedTypeClass
+{
+ GDataTypeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des types encapsulés. */
+static void g_encapsulated_type_class_init(GEncapsulatedTypeClass *);
+
+/* Initialise l'instance d'un type encapsulé. */
+static void g_encapsulated_type_init(GEncapsulatedType *);
+
+/* Crée un copie d'un type existant. */
+static GDataType *g_encapsulated_type_dup(const GEncapsulatedType *);
+
+/* Décrit le type fourni sous forme de caractères. */
+static char *g_encapsulated_type_to_string(const GEncapsulatedType *);
+
+
+
+/* Indique le type défini pour un type encapsulé. */
+G_DEFINE_TYPE(GEncapsulatedType, g_encapsulated_type, G_TYPE_DATA_TYPE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des types encapsulés. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_encapsulated_type_class_init(GEncapsulatedTypeClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = instance à initialiser. *
+* *
+* Description : Initialise l'instance d'un type encapsulé. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_encapsulated_type_init(GEncapsulatedType *type)
+{
+ GDataType *data_type; /* Version basique */
+
+ data_type = G_DATA_TYPE(type);
+
+ data_type->dup = (type_dup_fc)g_encapsulated_type_dup;
+ data_type->to_string = (type_to_string_fc)g_encapsulated_type_to_string;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type d'extension à représenter. *
+* child = variable dont on doit dériver. *
+* *
+* Description : Crée une représentation de variable dérivée. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_encapsulated_type_new(EncapsulationType type, ...)
+{
+ GEncapsulatedType *result; /* Structure à retourner */
+ va_list ap; /* Liste variable d'arguments */
+
+ result = g_object_new(G_TYPE_ENCAPSULATED_TYPE, NULL);
+
+ result->type = type;
+
+ va_start(ap, type);
+
+ switch (type)
+ {
+ case ECT_ROUTINE:
+ result->routine = va_arg(ap, GBinRoutine *);
+ g_binary_routine_set_name(result->routine, "(*)");
+ break;
+
+ default:
+ result->child = va_arg(ap, GDataType *);
+ break;
+
+ }
+
+ va_end(ap);
+
+ return G_DATA_TYPE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à dupliquer. *
+* *
+* Description : Crée un copie d'un type existant. *
+* *
+* Retour : Nouvelle instance de type identique à celle fournie. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *g_encapsulated_type_dup(const GEncapsulatedType *type)
+{
+ GDataType *result; /* Nouvelle instance à renvoyer*/
+ GDataType *child; /* Copie du type interne */
+
+ switch (type->type)
+ {
+ case ECT_ROUTINE:
+ g_object_ref(G_OBJECT(type->routine));
+ result = g_encapsulated_type_new(type->type, type->routine);
+ break;
+
+ default:
+ child = g_data_type_dup(type->child);
+ result = g_encapsulated_type_new(type->type, child);
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à convertir. *
+* *
+* Description : Décrit le type fourni sous forme de caractères. *
+* *
+* Retour : Chaîne à libérer de la mémoire après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_encapsulated_type_to_string(const GEncapsulatedType *type)
+{
+ char *result; /* Chaîne finale à renvoyer */
+
+ switch (type->type)
+ {
+ case ECT_ROUTINE:
+ result = g_binary_routine_to_string(type->routine);
+ break;
+
+ default:
+ result = g_data_type_to_string(type->child);
+ break;
+
+ }
+
+ switch (type->type)
+ {
+ case ECT_POINTER:
+
+ if (G_IS_ENCAPSULATED_TYPE(type->child)
+ && G_ENCAPSULATED_TYPE(type->child)->type == ECT_ROUTINE) break;
+
+ if (!g_data_type_is_pointer(type->child, false))
+ result = stradd(result, " ");
+ result = stradd(result, "*");
+
+ break;
+
+ case ECT_REFERENCE:
+ result = stradd(result, " &");
+ break;
+ case ECT_RVALUE_REF:
+ result = stradd(result, " &&");
+ break;
+ case ECT_COMPLEX:
+ result = stradd(result, " complex");
+ break;
+ case ECT_IMAGINARY:
+ result = stradd(result, " imaginary");
+ break;
+
+ case ECT_ROUTINE: /* Pour GCC */
+ default:
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à consulter. *
+* *
+* Description : Fournit le type d'encapsulation gérée par le type. *
+* *
+* Retour : Type d'encapsulation gérée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+EncapsulationType g_encapsulated_type_get_etype(const GEncapsulatedType *type)
+{
+ return type->type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à consulter. *
+* ... = sous-type ou routine encapsulée dans le type. [OUT] *
+* *
+* Description : Fournit la routine encapsulée dans le type. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_encapsulated_type_get_item(const GEncapsulatedType *type, ...)
+{
+ va_list ap; /* Liste variable d'arguments */
+ GDataType **child; /* Adresse pour sous-type */
+ GBinRoutine **routine; /* Adresse pour routine */
+
+ va_start(ap, type);
+
+ switch (type->type)
+ {
+ case ECT_ROUTINE:
+ routine = va_arg(ap, GBinRoutine **);
+ *routine = type->routine;
+ break;
+
+ default:
+ child = va_arg(ap, GDataType **);
+ *child = type->child;
+ break;
+
+ }
+
+ va_end(ap);
+
+}
diff --git a/src/analysis/types/encaps.h b/src/analysis/types/encaps.h
new file mode 100644
index 0000000..c06767e
--- /dev/null
+++ b/src/analysis/types/encaps.h
@@ -0,0 +1,78 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * encaps.h - prototypes pour la manipulation des types de données encapsulés
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_TYPES_ENCAPS_H
+#define _ANALYSIS_TYPES_ENCAPS_H
+
+
+#include <glib-object.h>
+
+
+#include "../type.h"
+
+
+
+#define G_TYPE_ENCAPSULATED_TYPE g_encapsulated_type_get_type()
+#define G_ENCAPSULATED_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_encapsulated_type_get_type(), GEncapsulatedType))
+#define G_IS_ENCAPSULATED_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_encapsulated_type_get_type()))
+#define G_ENCAPSULATED_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ENCAPSULATED_TYPE, GEncapsulatedTypeClass))
+#define G_IS_ENCAPSULATED_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ENCAPSULATED_TYPE))
+#define G_ENCAPSULATED_TYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ENCAPSULATED_TYPE, GEncapsulatedTypeClass))
+
+
+/* Description de type encapsulé (instance) */
+typedef struct _GEncapsulatedType GEncapsulatedType;
+
+/* Description de type encapsulé (classe) */
+typedef struct _GEncapsulatedTypeClass GEncapsulatedTypeClass;
+
+
+/* Cas d'encapsulation possibles */
+typedef enum _EncapsulationType
+{
+ ECT_POINTER, /* Pointeur */
+ ECT_REFERENCE, /* Référence */
+ ECT_RVALUE_REF, /* Référence ?? (C++0x) */
+ ECT_COMPLEX, /* Complexe (C 2000) */
+ ECT_IMAGINARY, /* Imaginaire (C 2000) */
+
+ ECT_ROUTINE /* Pointeur vers une routine */
+
+} EncapsulationType;
+
+
+/* Indique le type défini pour un type encapsulé. */
+GType g_encapsulated_type_get_type(void);
+
+/* Crée une représentation de variable dérivée. */
+GDataType *g_encapsulated_type_new(EncapsulationType, ...);
+
+/* Fournit le type d'encapsulation gérée par le type. */
+EncapsulationType g_encapsulated_type_get_etype(const GEncapsulatedType *);
+
+/* Fournit la routine encapsulée dans le type. */
+void g_encapsulated_type_get_item(const GEncapsulatedType *, ...);
+
+
+
+#endif /* _ANALYSIS_TYPES_ENCAPS_H */
diff --git a/src/analysis/types/literal.c b/src/analysis/types/literal.c
new file mode 100644
index 0000000..92c8254
--- /dev/null
+++ b/src/analysis/types/literal.c
@@ -0,0 +1,205 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * literal.c - manipulation des valeurs littérales de types instanciés
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "literal.h"
+
+
+#include <stdio.h>
+#include <string.h>
+
+
+#include "basic.h"
+#include "../type-int.h"
+
+
+
+/* Description de type instancié avec une valeur litérale (instance) */
+struct _GLiteralType
+{
+ GDataType parent; /* A laisser en premier */
+
+ GDataType *orig; /* Type instancié */
+ literal_value value; /* Valeur d'instance */
+
+};
+
+/* Description de type instancié avec une valeur litérale (classe) */
+struct _GLiteralTypeClass
+{
+ GDataTypeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des types instanciés avec des valeurs. */
+static void g_literal_type_class_init(GLiteralTypeClass *);
+
+/* Initialise l'instance d'un type instancié avec une valeur. */
+static void g_literal_type_init(GLiteralType *);
+
+/* Crée un copie d'un type existant. */
+static GDataType *g_literal_type_dup(const GLiteralType *);
+
+/* Décrit le type fourni sous forme de caractères. */
+static char *g_literal_type_to_string(const GLiteralType *);
+
+
+
+/* Indique le type défini pour un type reposant sur des gabarits. */
+G_DEFINE_TYPE(GLiteralType, g_literal_type, G_TYPE_DATA_TYPE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des types instanciés avec des valeurs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_literal_type_class_init(GLiteralTypeClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = instance à initialiser. *
+* *
+* Description : Initialise l'instance d'un type instancié avec une valeur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_literal_type_init(GLiteralType *type)
+{
+ GDataType *data_type; /* Version basique */
+
+ data_type = G_DATA_TYPE(type);
+
+ data_type->dup = (type_dup_fc)g_literal_type_dup;
+ data_type->to_string = (type_to_string_fc)g_literal_type_to_string;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : orig = type d'origine instancié. *
+* value = valeur de l'instanciation. *
+* *
+* Description : Crée une représentation de type instancié avec une valeur. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_literal_type_new(GDataType *orig, literal_value value)
+{
+ GLiteralType *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_LITERAL_TYPE, NULL);
+
+ result->orig = orig;
+ result->value = value;
+
+ g_object_ref(orig);
+
+ return G_DATA_TYPE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à dupliquer. *
+* *
+* Description : Crée un copie d'un type existant. *
+* *
+* Retour : Nouvelle instance de type identique à celle fournie. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *g_literal_type_dup(const GLiteralType *type)
+{
+ GDataType *orig; /* Copie du type interne */
+
+ orig = g_data_type_dup(type->orig);
+
+ return g_literal_type_new(orig, type->value);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à convertir. *
+* *
+* Description : Décrit le type fourni sous forme de caractères. *
+* *
+* Retour : Chaîne à libérer de la mémoire après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_literal_type_to_string(const GLiteralType *type)
+{
+ char *result; /* Valeur à renvoyer */
+ size_t max; /* Longueur totale du texte */
+
+ if (G_IS_BASIC_TYPE(type->orig))
+ switch (g_basic_type_get_btype(G_BASIC_TYPE(type->orig)))
+ {
+ case BTP_BOOL:
+ result = strdup(type->value.int_val ? "true" : "false");
+ break;
+
+ case BTP_INT:
+ max = strlen("2147483647" /* INT_MAX */) + 1;
+ result = (char *)calloc(max, sizeof(char));
+ snprintf(result, max, "%d", type->value.int_val);
+ break;
+
+ default:
+ result = strdup("TODO");
+ break;
+
+ }
+ else result = strdup("???");
+
+ return result;
+
+}
diff --git a/src/analysis/types/literal.h b/src/analysis/types/literal.h
new file mode 100644
index 0000000..df279cd
--- /dev/null
+++ b/src/analysis/types/literal.h
@@ -0,0 +1,67 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * literal.h - prototypes pour la manipulation des valeurs littérales de types instanciés
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_TYPES_LITERAL_H
+#define _ANALYSIS_TYPES_LITERAL_H
+
+
+#include <glib-object.h>
+
+
+#include "../type.h"
+
+
+
+#define G_TYPE_LITERAL_TYPE g_literal_type_get_type()
+#define G_LITERAL_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_literal_type_get_type(), GLiteralType))
+#define G_IS_LITERAL_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_literal_type_get_type()))
+#define G_LITERAL_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_LITERAL_TYPE, GLiteralTypeClass))
+#define G_IS_LITERAL_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_LITERAL_TYPE))
+#define G_LITERAL_TYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_LITERAL_TYPE, GLiteralTypeClass))
+
+
+/* Description de type instancié avec une valeur litérale (instance) */
+typedef struct _GLiteralType GLiteralType;
+
+/* Description de type instancié avec une valeur litérale (classe) */
+typedef struct _GLiteralTypeClass GLiteralTypeClass;
+
+
+/* Valeurs instanciées supportées */
+typedef union _literal_value
+{
+ int int_val; /* Valeur entière */
+ float float_val; /* Valeur flottante */
+
+} literal_value;
+
+
+/* Indique le type défini pour un type instancié avec une valeur litérale. */
+GType g_literal_type_get_type(void);
+
+/* Crée une représentation de type instancié avec une valeur. */
+GDataType *g_literal_type_new(GDataType *, literal_value);
+
+
+
+#endif /* _ANALYSIS_TYPES_LITERAL_H */
diff --git a/src/analysis/types/template.c b/src/analysis/types/template.c
new file mode 100644
index 0000000..29d39bc
--- /dev/null
+++ b/src/analysis/types/template.c
@@ -0,0 +1,283 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * template.c - manipulation des types reposant sur des gabarits
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "template.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "cse-int.h"
+#include "../type-int.h"
+#include "../../common/extstr.h"
+
+
+
+/* Description de type reposant sur des gabarits (instance) */
+struct _GTemplateType
+{
+ GClassEnumType parent; /* A laisser en premier */
+
+ GDataType **models; /* Sous-types associés */
+ size_t models_count; /* Quantité de ces modèles */
+
+};
+
+/* Description de type reposant sur des gabarits (classe) */
+struct _GTemplateTypeClass
+{
+ GClassEnumTypeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe des types reposant sur des gabarits. */
+static void g_template_type_class_init(GTemplateTypeClass *);
+
+/* Initialise l'instance d'un type reposant sur des gabarits. */
+static void g_template_type_init(GTemplateType *);
+
+/* Crée un copie d'un type existant. */
+static GDataType *g_template_type_dup(const GTemplateType *);
+
+/* Décrit le type fourni sous forme de caractères. */
+static char *g_template_type_to_string(const GTemplateType *);
+
+
+
+/* Indique le type défini pour un type reposant sur des gabarits. */
+G_DEFINE_TYPE(GTemplateType, g_template_type, G_TYPE_CLASS_ENUM_TYPE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des types reposant sur des gabarits. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_template_type_class_init(GTemplateTypeClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = instance à initialiser. *
+* *
+* Description : Initialise l'instance d'un type reposant sur des gabarits. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_template_type_init(GTemplateType *type)
+{
+ GDataType *data_type; /* Version basique */
+ GClassEnumType *ce_type; /* Version basique #2 */
+
+ data_type = G_DATA_TYPE(type);
+
+ data_type->dup = (type_dup_fc)g_template_type_dup;
+ data_type->to_string = (type_to_string_fc)g_template_type_to_string;
+
+ ce_type = G_CLASS_ENUM_TYPE(type);
+
+ ce_type->type = CET_CLASS;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : name = désignation humaine du type. *
+* list = élements du modèle sur lequel doit reposer le type. *
+* *
+* Description : Crée une représentation de type reposant sur des gabarits. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_template_type_new(const char *name, GSList *list)
+{
+ GTemplateType *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_TEMPLATE_TYPE, NULL);
+
+ G_CLASS_ENUM_TYPE(result)->name = strdup(name);
+
+ g_template_type_add_params(result, list);
+
+ return G_DATA_TYPE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à dupliquer. *
+* *
+* Description : Crée un copie d'un type existant. *
+* *
+* Retour : Nouvelle instance de type identique à celle fournie. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GDataType *g_template_type_dup(const GTemplateType *type)
+{
+ GDataType *result; /* Copie à retourner */
+ GSList *list; /* Format de liste à fournir */
+ size_t i; /* Boucle de parcours */
+
+ list = NULL;
+
+ for (i = 0; i < type->models_count; i++)
+ list = g_slist_prepend(list, type->models[i]);
+
+ result = g_template_type_new(G_CLASS_ENUM_TYPE(type)->name, list);
+
+ return G_DATA_TYPE(result);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à convertir. *
+* *
+* Description : Décrit le type fourni sous forme de caractères. *
+* *
+* Retour : Chaîne à libérer de la mémoire après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_template_type_to_string(const GTemplateType *type)
+{
+ char *result; /* Valeur à renvoyer */
+ size_t i; /* Boucle de parcours */
+ char *sub; /* Sous-type à décrire */
+
+ result = g_class_enum_type_to_string(G_CLASS_ENUM_TYPE(type));
+
+ result = stradd(result, "<");
+
+ for (i = 0; i < type->models_count; i++)
+ {
+ if (i > 0) result = stradd(result, ", ");
+
+ sub = g_data_type_to_string(type->models[i]);
+ result = stradd(result, sub);
+ free(sub);
+
+ }
+
+ result = stradd(result, ">");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à mettre à jour. *
+* list = élements du modèle sur lequel doit reposer le type. *
+* *
+* Description : Ajoute une série de paramètres à un gabarit. *
+* *
+* Retour : - *
+* *
+* Remarques : La liste doit contenir des éléments dans l'ordre inverse *
+* d'apparition. De plus, elle est libérée dans cette fonction. *
+* *
+******************************************************************************/
+
+void g_template_type_add_params(GTemplateType *type, GSList *list)
+{
+ GSList *iter; /* Boucle de parcours */
+
+ list = g_slist_reverse(list);
+ for (iter = list; iter != NULL; iter = g_slist_next(iter))
+ {
+ type->models = (GDataType **)realloc(type->models,
+ ++type->models_count * sizeof(GDataType *));
+ type->models[type->models_count - 1] = G_DATA_TYPE(iter->data);
+ }
+ g_slist_free(list);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à consulter. *
+* *
+* Description : Indique le nombre de paramètres associés du gabarit. *
+* *
+* Retour : Nombre de paramètres inclus dans le gabarit. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_template_type_count_param(const GTemplateType *type)
+{
+ return type->models_count;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type à consulter. *
+* index = indice du paramètre à retourner. *
+* *
+* Description : Fournit un paramètre donné du gabarit. *
+* *
+* Retour : Type inclus dans le modèle ou NULL si mauvais indice. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDataType *g_template_type_get_param(const GTemplateType *type, size_t index)
+{
+ return (index < type->models_count ? type->models[index] : NULL);
+
+}
diff --git a/src/analysis/types/template.h b/src/analysis/types/template.h
new file mode 100644
index 0000000..8c43a03
--- /dev/null
+++ b/src/analysis/types/template.h
@@ -0,0 +1,67 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * template.h - prototypes pour la manipulation des types reposant sur des gabarits
+ *
+ * Copyright (C) 2012 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_TYPES_TEMPLATE_H
+#define _ANALYSIS_TYPES_TEMPLATE_H
+
+
+#include <glib-object.h>
+
+
+#include "../type.h"
+
+
+
+#define G_TYPE_TEMPLATE_TYPE g_template_type_get_type()
+#define G_TEMPLATE_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_template_type_get_type(), GTemplateType))
+#define G_IS_TEMPLATE_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_template_type_get_type()))
+#define G_TEMPLATE_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_TEMPLATE_TYPE, GTemplateTypeClass))
+#define G_IS_TEMPLATE_TYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_TEMPLATE_TYPE))
+#define G_TEMPLATE_TYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_TEMPLATE_TYPE, GTemplateTypeClass))
+
+
+/* Description de type reposant sur des gabarits (instance) */
+typedef struct _GTemplateType GTemplateType;
+
+/* Description de type reposant sur des gabarits (classe) */
+typedef struct _GTemplateTypeClass GTemplateTypeClass;
+
+
+/* Indique le type défini pour un type reposant sur des gabarits. */
+GType g_template_type_get_type(void);
+
+/* Crée une représentation de type reposant sur des gabarits. */
+GDataType *g_template_type_new(const char *, GSList *);
+
+/* Ajoute une série de paramètres à un gabarit. */
+void g_template_type_add_params(GTemplateType *, GSList *);
+
+/* Indique le nombre de paramètres associés du gabarit. */
+size_t g_template_type_count_param(const GTemplateType *);
+
+/* Fournit un paramètre donné du gabarit. */
+GDataType *g_template_type_get_param(const GTemplateType *, size_t);
+
+
+
+#endif /* _ANALYSIS_TYPES_TEMPLATE_H */