summaryrefslogtreecommitdiff
path: root/src/analysis/scan/items/magic
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2023-08-06 16:54:57 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2023-08-06 16:54:57 (GMT)
commit4fcc35a52ccb025b6d803d85e017931cd2452960 (patch)
treee95920f16c273e41f9cae1ea2f02571c221a514e /src/analysis/scan/items/magic
parent74d062d4ec55d7ac3914bbf64b8b6c5ab52227df (diff)
Extend the ROST grammar with a first batch of new features.
Diffstat (limited to 'src/analysis/scan/items/magic')
-rw-r--r--src/analysis/scan/items/magic/Makefile.am16
-rw-r--r--src/analysis/scan/items/magic/cookie.c122
-rw-r--r--src/analysis/scan/items/magic/cookie.h44
-rw-r--r--src/analysis/scan/items/magic/mime-encoding.c270
-rw-r--r--src/analysis/scan/items/magic/mime-encoding.h58
-rw-r--r--src/analysis/scan/items/magic/mime-type.c270
-rw-r--r--src/analysis/scan/items/magic/mime-type.h58
-rw-r--r--src/analysis/scan/items/magic/type.c270
-rw-r--r--src/analysis/scan/items/magic/type.h58
9 files changed, 1166 insertions, 0 deletions
diff --git a/src/analysis/scan/items/magic/Makefile.am b/src/analysis/scan/items/magic/Makefile.am
new file mode 100644
index 0000000..1d741ff
--- /dev/null
+++ b/src/analysis/scan/items/magic/Makefile.am
@@ -0,0 +1,16 @@
+
+noinst_LTLIBRARIES = libanalysisscanitemsmagic.la
+
+
+libanalysisscanitemsmagic_la_SOURCES = \
+ cookie.h cookie.c \
+ mime-encoding.h mime-encoding.c \
+ mime-type.h mime-type.c \
+ type.h type.c
+
+libanalysisscanitemsmagic_la_CFLAGS = $(LIBGOBJ_CFLAGS) $(LIBMAGIC_CFLAGS)
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
+
+dev_HEADERS = $(libanalysisscanitemsmagic_la_SOURCES:%c=)
diff --git a/src/analysis/scan/items/magic/cookie.c b/src/analysis/scan/items/magic/cookie.c
new file mode 100644
index 0000000..41f26a0
--- /dev/null
+++ b/src/analysis/scan/items/magic/cookie.c
@@ -0,0 +1,122 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * cookie.c - chargement des motifs de reconnaissance de contenus
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "cookie.h"
+
+
+#include <assert.h>
+
+
+#include <i18n.h>
+
+
+#include "../../../../core/logs.h"
+
+
+
+/* Référence des bibliothèques de reconnaissance */
+static magic_t __magic_cookie = 0;
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Charge les motifs de reconnaissance de contenus. *
+* *
+* Retour : Bilan de l'opération de chargemement. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_magic_cookie(void)
+{
+ bool result; /* Bilan à retourner */
+ int ret; /* Bilan d'une opération */
+
+ __magic_cookie = magic_open(0);
+
+ ret = magic_load(__magic_cookie, NULL);
+ result = (ret != -1);
+
+ if (!result)
+ log_variadic_message(LMT_EXT_ERROR, _("cannot load magic database: %s"), magic_error(__magic_cookie));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Décharge les motifs de reconnaissance de contenus. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void exit_magic_cookie(void)
+{
+ magic_close(__magic_cookie);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : flags = forme de reconnaissance à préparer. *
+* *
+* Description : Fournit la référence aux mécanismes de reconnaissance. *
+* *
+* Retour : Cookie prêt à emploi. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+magic_t get_magic_cookie(int flags)
+{
+ magic_t result; /* Référence à retourner */
+#ifndef NDEBUG
+ int ret; /* Bilan de la préparation */
+#endif
+
+ result = __magic_cookie;
+ assert(result != 0);
+
+#ifndef NDEBUG
+ ret = magic_setflags(result, flags);
+ assert(ret != -1);
+#else
+ magic_setflags(result, flags);
+#endif
+
+ return result;
+
+}
diff --git a/src/analysis/scan/items/magic/cookie.h b/src/analysis/scan/items/magic/cookie.h
new file mode 100644
index 0000000..0ee2274
--- /dev/null
+++ b/src/analysis/scan/items/magic/cookie.h
@@ -0,0 +1,44 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * cookie.h - prototypes pour le chargement des motifs de reconnaissance de contenus
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_SCAN_ITEMS_MAGIC_COOKIE_H
+#define _ANALYSIS_SCAN_ITEMS_MAGIC_COOKIE_H
+
+
+#include <magic.h>
+#include <stdbool.h>
+
+
+
+/* Charge les motifs de reconnaissance de contenus. */
+bool init_magic_cookie(void);
+
+/* Décharge les motifs de reconnaissance de contenus. */
+void exit_magic_cookie(void);
+
+/* Fournit la référence aux mécanismes de reconnaissance. */
+magic_t get_magic_cookie(int);
+
+
+
+#endif /* _ANALYSIS_SCAN_ITEMS_MAGIC_COOKIE_H */
diff --git a/src/analysis/scan/items/magic/mime-encoding.c b/src/analysis/scan/items/magic/mime-encoding.c
new file mode 100644
index 0000000..935515d
--- /dev/null
+++ b/src/analysis/scan/items/magic/mime-encoding.c
@@ -0,0 +1,270 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * mime-encoding.c - reconnaissance de l'encodage d'un contenu
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "mime-encoding.h"
+
+
+#include "cookie.h"
+#include "../../item-int.h"
+#include "../../exprs/literal.h"
+
+
+
+/* ---------------------- INTRODUCTION D'UNE NOUVELLE FONCTION ---------------------- */
+
+
+/* Initialise la classe des reconnaissances de contenus. */
+static void g_scan_mime_encoding_function_class_init(GScanMimeEncodingFunctionClass *);
+
+/* Initialise une instance de reconnaissance de contenus. */
+static void g_scan_mime_encoding_function_init(GScanMimeEncodingFunction *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_mime_encoding_function_dispose(GScanMimeEncodingFunction *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_mime_encoding_function_finalize(GScanMimeEncodingFunction *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Indique le nom associé à une expression d'évaluation. */
+static char *g_scan_mime_encoding_function_get_name(const GScanMimeEncodingFunction *);
+
+/* Réduit une expression à une forme plus simple. */
+static bool g_scan_mime_encoding_function_run_call(GScanMimeEncodingFunction *, GScanExpression **, size_t, GScanContext *, GScanScope *, GObject **);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTRODUCTION D'UNE NOUVELLE FONCTION */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une reconnaissance d'encodages de contenus. */
+G_DEFINE_TYPE(GScanMimeEncodingFunction, g_scan_mime_encoding_function, G_TYPE_REGISTERED_ITEM);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des reconnaissances de contenus. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_encoding_function_class_init(GScanMimeEncodingFunctionClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GRegisteredItemClass *registered; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_mime_encoding_function_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_mime_encoding_function_finalize;
+
+ registered = G_REGISTERED_ITEM_CLASS(klass);
+
+ registered->get_name = (get_registered_item_name_fc)g_scan_mime_encoding_function_get_name;
+ registered->run_call = (run_registered_item_call_fc)g_scan_mime_encoding_function_run_call;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance à initialiser. *
+* *
+* Description : Initialise une instance de reconnaissance de contenus. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_encoding_function_init(GScanMimeEncodingFunction *func)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_encoding_function_dispose(GScanMimeEncodingFunction *func)
+{
+ G_OBJECT_CLASS(g_scan_mime_encoding_function_parent_class)->dispose(G_OBJECT(func));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_encoding_function_finalize(GScanMimeEncodingFunction *func)
+{
+ G_OBJECT_CLASS(g_scan_mime_encoding_function_parent_class)->finalize(G_OBJECT(func));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Constitue une fonction de cernement d'encodages de contenus. *
+* *
+* Retour : Fonction mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRegisteredItem *g_scan_mime_encoding_function_new(void)
+{
+ GRegisteredItem *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_MIME_ENCODING_FUNCTION, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément d'appel à consulter. *
+* *
+* Description : Indique le nom associé à une expression d'évaluation. *
+* *
+* Retour : Désignation humaine de l'expression d'évaluation. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_mime_encoding_function_get_name(const GScanMimeEncodingFunction *item)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("mime_encoding");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément d'appel à consulter. *
+* args = liste d'éventuels arguments fournis. *
+* count = taille de cette liste. *
+* ctx = contexte de suivi de l'analyse courante. *
+* scope = portée courante des variables locales. *
+* out = zone d'enregistrement de la résolution opérée. [OUT] *
+* *
+* Description : Réduit une expression à une forme plus simple. *
+* *
+* Retour : Réduction correspondante, expression déjà réduite, ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_mime_encoding_function_run_call(GScanMimeEncodingFunction *item, GScanExpression **args, size_t count, GScanContext *ctx, GScanScope *scope, GObject **out)
+{
+ bool result; /* Bilan à retourner */
+ magic_t cookie; /* Référence des bibliothèques */
+ GBinContent *content; /* Contenu à manipuler */
+ vmpa2t pos; /* Tête de lecture */
+ phys_t size; /* Quantité de données dispos. */
+ const bin_t *data; /* Accès à des données */
+ const char *desc; /* Description du contenu */
+ sized_string_t string; /* Description à diffuser */
+
+ result = (count == 0);
+ if (!result) goto exit;
+
+ cookie = get_magic_cookie(MAGIC_MIME_ENCODING);
+
+ content = g_scan_context_get_content(ctx);
+
+ g_binary_content_compute_start_pos(content, &pos);
+
+ size = g_binary_content_compute_size(content);
+
+ data = g_binary_content_get_raw_access(content, &pos, size);
+
+ desc = magic_buffer(cookie, data, size);
+
+ if (desc != NULL)
+ {
+ string.data = (char *)desc;
+ string.len = strlen(desc);
+ }
+ else
+ {
+ string.data = "";
+ string.len = 0;
+ }
+
+ *out = G_OBJECT(g_scan_literal_expression_new(LVT_STRING, &string));
+
+ g_object_unref(G_OBJECT(content));
+
+ exit:
+
+ return result;
+
+}
diff --git a/src/analysis/scan/items/magic/mime-encoding.h b/src/analysis/scan/items/magic/mime-encoding.h
new file mode 100644
index 0000000..9349d55
--- /dev/null
+++ b/src/analysis/scan/items/magic/mime-encoding.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * mime-encoding.h - prototypes pour la reconnaissance de l'encodage d'un contenu
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_SCAN_ITEMS_MAGIC_MIME_ENCODING_H
+#define _ANALYSIS_SCAN_ITEMS_MAGIC_MIME_ENCODING_H
+
+
+#include <glib-object.h>
+
+
+#include "../../item.h"
+
+
+
+#define G_TYPE_SCAN_MIME_ENCODING_FUNCTION g_scan_mime_encoding_function_get_type()
+#define G_SCAN_MIME_ENCODING_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_MIME_ENCODING_FUNCTION, GScanMimeEncodingFunction))
+#define G_IS_SCAN_MIME_ENCODING_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_MIME_ENCODING_FUNCTION))
+#define G_SCAN_MIME_ENCODING_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_MIME_ENCODING_FUNCTION, GScanMimeEncodingFunctionClass))
+#define G_IS_SCAN_MIME_ENCODING_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_MIME_ENCODING_FUNCTION))
+#define G_SCAN_MIME_ENCODING_FUNCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_MIME_ENCODING_FUNCTION, GScanMimeEncodingFunctionClass))
+
+
+/* Reconnaissance d'encodages de contenus (instance) */
+typedef GRegisteredItem GScanMimeEncodingFunction;
+
+/* Reconnaissance d'encodages de contenus (classe) */
+typedef GRegisteredItemClass GScanMimeEncodingFunctionClass;
+
+
+/* Indique le type défini pour une reconnaissance d'encodages de contenus. */
+GType g_scan_mime_encoding_function_get_type(void);
+
+/* Constitue une fonction de cernement d'encodages de contenus. */
+GRegisteredItem *g_scan_mime_encoding_function_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_ITEMS_MAGIC_MIME_ENCODING_H */
diff --git a/src/analysis/scan/items/magic/mime-type.c b/src/analysis/scan/items/magic/mime-type.c
new file mode 100644
index 0000000..95e441d
--- /dev/null
+++ b/src/analysis/scan/items/magic/mime-type.c
@@ -0,0 +1,270 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.c - reconnaissance du type MIME d'un contenu
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "mime-type.h"
+
+
+#include "cookie.h"
+#include "../../item-int.h"
+#include "../../exprs/literal.h"
+
+
+
+/* ---------------------- INTRODUCTION D'UNE NOUVELLE FONCTION ---------------------- */
+
+
+/* Initialise la classe des reconnaissances de contenus. */
+static void g_scan_mime_type_function_class_init(GScanMimeTypeFunctionClass *);
+
+/* Initialise une instance de reconnaissance de contenus. */
+static void g_scan_mime_type_function_init(GScanMimeTypeFunction *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_mime_type_function_dispose(GScanMimeTypeFunction *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_mime_type_function_finalize(GScanMimeTypeFunction *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Indique le nom associé à une expression d'évaluation. */
+static char *g_scan_mime_type_function_get_name(const GScanMimeTypeFunction *);
+
+/* Réduit une expression à une forme plus simple. */
+static bool g_scan_mime_type_function_run_call(GScanMimeTypeFunction *, GScanExpression **, size_t, GScanContext *, GScanScope *, GObject **);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTRODUCTION D'UNE NOUVELLE FONCTION */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une reconnaissance de types de contenus. */
+G_DEFINE_TYPE(GScanMimeTypeFunction, g_scan_mime_type_function, G_TYPE_REGISTERED_ITEM);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des reconnaissances de contenus. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_type_function_class_init(GScanMimeTypeFunctionClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GRegisteredItemClass *registered; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_mime_type_function_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_mime_type_function_finalize;
+
+ registered = G_REGISTERED_ITEM_CLASS(klass);
+
+ registered->get_name = (get_registered_item_name_fc)g_scan_mime_type_function_get_name;
+ registered->run_call = (run_registered_item_call_fc)g_scan_mime_type_function_run_call;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance à initialiser. *
+* *
+* Description : Initialise une instance de reconnaissance de contenus. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_type_function_init(GScanMimeTypeFunction *func)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_type_function_dispose(GScanMimeTypeFunction *func)
+{
+ G_OBJECT_CLASS(g_scan_mime_type_function_parent_class)->dispose(G_OBJECT(func));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_mime_type_function_finalize(GScanMimeTypeFunction *func)
+{
+ G_OBJECT_CLASS(g_scan_mime_type_function_parent_class)->finalize(G_OBJECT(func));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Constitue une fonction d'identification de types de contenus.*
+* *
+* Retour : Fonction mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRegisteredItem *g_scan_mime_type_function_new(void)
+{
+ GRegisteredItem *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_MIME_TYPE_FUNCTION, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément d'appel à consulter. *
+* *
+* Description : Indique le nom associé à une expression d'évaluation. *
+* *
+* Retour : Désignation humaine de l'expression d'évaluation. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_mime_type_function_get_name(const GScanMimeTypeFunction *item)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("mime_type");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément d'appel à consulter. *
+* args = liste d'éventuels arguments fournis. *
+* count = taille de cette liste. *
+* ctx = contexte de suivi de l'analyse courante. *
+* scope = portée courante des variables locales. *
+* out = zone d'enregistrement de la résolution opérée. [OUT] *
+* *
+* Description : Réduit une expression à une forme plus simple. *
+* *
+* Retour : Réduction correspondante, expression déjà réduite, ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_mime_type_function_run_call(GScanMimeTypeFunction *item, GScanExpression **args, size_t count, GScanContext *ctx, GScanScope *scope, GObject **out)
+{
+ bool result; /* Bilan à retourner */
+ magic_t cookie; /* Référence des bibliothèques */
+ GBinContent *content; /* Contenu à manipuler */
+ vmpa2t pos; /* Tête de lecture */
+ phys_t size; /* Quantité de données dispos. */
+ const bin_t *data; /* Accès à des données */
+ const char *desc; /* Description du contenu */
+ sized_string_t string; /* Description à diffuser */
+
+ result = (count == 0);
+ if (!result) goto exit;
+
+ cookie = get_magic_cookie(MAGIC_MIME_TYPE);
+
+ content = g_scan_context_get_content(ctx);
+
+ g_binary_content_compute_start_pos(content, &pos);
+
+ size = g_binary_content_compute_size(content);
+
+ data = g_binary_content_get_raw_access(content, &pos, size);
+
+ desc = magic_buffer(cookie, data, size);
+
+ if (desc != NULL)
+ {
+ string.data = (char *)desc;
+ string.len = strlen(desc);
+ }
+ else
+ {
+ string.data = "";
+ string.len = 0;
+ }
+
+ *out = G_OBJECT(g_scan_literal_expression_new(LVT_STRING, &string));
+
+ g_object_unref(G_OBJECT(content));
+
+ exit:
+
+ return result;
+
+}
diff --git a/src/analysis/scan/items/magic/mime-type.h b/src/analysis/scan/items/magic/mime-type.h
new file mode 100644
index 0000000..e02ce0f
--- /dev/null
+++ b/src/analysis/scan/items/magic/mime-type.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * mime-type.h - prototypes pour la reconnaissance du type MIME d'un contenu
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_SCAN_ITEMS_MAGIC_MIME_TYPE_H
+#define _ANALYSIS_SCAN_ITEMS_MAGIC_MIME_TYPE_H
+
+
+#include <glib-object.h>
+
+
+#include "../../item.h"
+
+
+
+#define G_TYPE_SCAN_MIME_TYPE_FUNCTION g_scan_mime_type_function_get_type()
+#define G_SCAN_MIME_TYPE_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_MIME_TYPE_FUNCTION, GScanMimeTypeFunction))
+#define G_IS_SCAN_MIME_TYPE_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_MIME_TYPE_FUNCTION))
+#define G_SCAN_MIME_TYPE_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_MIME_TYPE_FUNCTION, GScanMimeTypeFunctionClass))
+#define G_IS_SCAN_MIME_TYPE_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_MIME_TYPE_FUNCTION))
+#define G_SCAN_MIME_TYPE_FUNCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_MIME_TYPE_FUNCTION, GScanMimeTypeFunctionClass))
+
+
+/* Reconnaissance de types de contenus (instance) */
+typedef GRegisteredItem GScanMimeTypeFunction;
+
+/* Reconnaissance de types de contenus (classe) */
+typedef GRegisteredItemClass GScanMimeTypeFunctionClass;
+
+
+/* Indique le type défini pour une reconnaissance de types de contenus. */
+GType g_scan_mime_type_function_get_type(void);
+
+/* Constitue une fonction d'identification de types de contenus. */
+GRegisteredItem *g_scan_mime_type_function_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_ITEMS_MAGIC_MIME_TYPE_H */
diff --git a/src/analysis/scan/items/magic/type.c b/src/analysis/scan/items/magic/type.c
new file mode 100644
index 0000000..f87c34a
--- /dev/null
+++ b/src/analysis/scan/items/magic/type.c
@@ -0,0 +1,270 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.c - reconnaissance du type d'un contenu
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "type.h"
+
+
+#include "cookie.h"
+#include "../../item-int.h"
+#include "../../exprs/literal.h"
+
+
+
+/* ---------------------- INTRODUCTION D'UNE NOUVELLE FONCTION ---------------------- */
+
+
+/* Initialise la classe des reconnaissances de contenus. */
+static void g_scan_magic_type_function_class_init(GScanMagicTypeFunctionClass *);
+
+/* Initialise une instance de reconnaissance de contenus. */
+static void g_scan_magic_type_function_init(GScanMagicTypeFunction *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_magic_type_function_dispose(GScanMagicTypeFunction *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_magic_type_function_finalize(GScanMagicTypeFunction *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Indique le nom associé à une expression d'évaluation. */
+static char *g_scan_magic_type_function_get_name(const GScanMagicTypeFunction *);
+
+/* Réduit une expression à une forme plus simple. */
+static bool g_scan_magic_type_function_run_call(GScanMagicTypeFunction *, GScanExpression **, size_t, GScanContext *, GScanScope *, GObject **);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTRODUCTION D'UNE NOUVELLE FONCTION */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une reconnaissance de types de contenus. */
+G_DEFINE_TYPE(GScanMagicTypeFunction, g_scan_magic_type_function, G_TYPE_REGISTERED_ITEM);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des reconnaissances de contenus. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_magic_type_function_class_init(GScanMagicTypeFunctionClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GRegisteredItemClass *registered; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_magic_type_function_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_magic_type_function_finalize;
+
+ registered = G_REGISTERED_ITEM_CLASS(klass);
+
+ registered->get_name = (get_registered_item_name_fc)g_scan_magic_type_function_get_name;
+ registered->run_call = (run_registered_item_call_fc)g_scan_magic_type_function_run_call;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance à initialiser. *
+* *
+* Description : Initialise une instance de reconnaissance de contenus. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_magic_type_function_init(GScanMagicTypeFunction *func)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_magic_type_function_dispose(GScanMagicTypeFunction *func)
+{
+ G_OBJECT_CLASS(g_scan_magic_type_function_parent_class)->dispose(G_OBJECT(func));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : func = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_magic_type_function_finalize(GScanMagicTypeFunction *func)
+{
+ G_OBJECT_CLASS(g_scan_magic_type_function_parent_class)->finalize(G_OBJECT(func));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Constitue une fonction d'identification de types de contenus.*
+* *
+* Retour : Fonction mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRegisteredItem *g_scan_magic_type_function_new(void)
+{
+ GRegisteredItem *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_MAGIC_TYPE_FUNCTION, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément d'appel à consulter. *
+* *
+* Description : Indique le nom associé à une expression d'évaluation. *
+* *
+* Retour : Désignation humaine de l'expression d'évaluation. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_magic_type_function_get_name(const GScanMagicTypeFunction *item)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("type");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = élément d'appel à consulter. *
+* args = liste d'éventuels arguments fournis. *
+* count = taille de cette liste. *
+* ctx = contexte de suivi de l'analyse courante. *
+* scope = portée courante des variables locales. *
+* out = zone d'enregistrement de la résolution opérée. [OUT] *
+* *
+* Description : Réduit une expression à une forme plus simple. *
+* *
+* Retour : Réduction correspondante, expression déjà réduite, ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_magic_type_function_run_call(GScanMagicTypeFunction *item, GScanExpression **args, size_t count, GScanContext *ctx, GScanScope *scope, GObject **out)
+{
+ bool result; /* Bilan à retourner */
+ magic_t cookie; /* Référence des bibliothèques */
+ GBinContent *content; /* Contenu à manipuler */
+ vmpa2t pos; /* Tête de lecture */
+ phys_t size; /* Quantité de données dispos. */
+ const bin_t *data; /* Accès à des données */
+ const char *desc; /* Description du contenu */
+ sized_string_t string; /* Description à diffuser */
+
+ result = (count == 0);
+ if (!result) goto exit;
+
+ cookie = get_magic_cookie(MAGIC_NONE);
+
+ content = g_scan_context_get_content(ctx);
+
+ g_binary_content_compute_start_pos(content, &pos);
+
+ size = g_binary_content_compute_size(content);
+
+ data = g_binary_content_get_raw_access(content, &pos, size);
+
+ desc = magic_buffer(cookie, data, size);
+
+ if (desc != NULL)
+ {
+ string.data = (char *)desc;
+ string.len = strlen(desc);
+ }
+ else
+ {
+ string.data = "";
+ string.len = 0;
+ }
+
+ *out = G_OBJECT(g_scan_literal_expression_new(LVT_STRING, &string));
+
+ g_object_unref(G_OBJECT(content));
+
+ exit:
+
+ return result;
+
+}
diff --git a/src/analysis/scan/items/magic/type.h b/src/analysis/scan/items/magic/type.h
new file mode 100644
index 0000000..bfad213
--- /dev/null
+++ b/src/analysis/scan/items/magic/type.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.h - prototypes pour la reconnaissance du type d'un contenu
+ *
+ * Copyright (C) 2023 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ANALYSIS_SCAN_ITEMS_MAGIC_TYPE_H
+#define _ANALYSIS_SCAN_ITEMS_MAGIC_TYPE_H
+
+
+#include <glib-object.h>
+
+
+#include "../../item.h"
+
+
+
+#define G_TYPE_SCAN_MAGIC_TYPE_FUNCTION g_scan_magic_type_function_get_type()
+#define G_SCAN_MAGIC_TYPE_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_MAGIC_TYPE_FUNCTION, GScanMagicTypeFunction))
+#define G_IS_SCAN_MAGIC_TYPE_FUNCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_MAGIC_TYPE_FUNCTION))
+#define G_SCAN_MAGIC_TYPE_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_MAGIC_TYPE_FUNCTION, GScanMagicTypeFunctionClass))
+#define G_IS_SCAN_MAGIC_TYPE_FUNCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_MAGIC_TYPE_FUNCTION))
+#define G_SCAN_MAGIC_TYPE_FUNCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_MAGIC_TYPE_FUNCTION, GScanMagicTypeFunctionClass))
+
+
+/* Reconnaissance de types de contenus (instance) */
+typedef GRegisteredItem GScanMagicTypeFunction;
+
+/* Reconnaissance de types de contenus (classe) */
+typedef GRegisteredItemClass GScanMagicTypeFunctionClass;
+
+
+/* Indique le type défini pour une reconnaissance de types de contenus. */
+GType g_scan_magic_type_function_get_type(void);
+
+/* Constitue une fonction d'identification de types de contenus. */
+GRegisteredItem *g_scan_magic_type_function_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_ITEMS_MAGIC_TYPE_H */