summaryrefslogtreecommitdiff
path: root/src/analysis/scan/patterns
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/scan/patterns')
-rw-r--r--src/analysis/scan/patterns/Makefile.am30
-rw-r--r--src/analysis/scan/patterns/backend-int.h78
-rw-r--r--src/analysis/scan/patterns/backend.c311
-rw-r--r--src/analysis/scan/patterns/backend.h79
-rw-r--r--src/analysis/scan/patterns/backends/Makefile.am29
-rw-r--r--src/analysis/scan/patterns/backends/acism-int.h206
-rw-r--r--src/analysis/scan/patterns/backends/acism.c1522
-rw-r--r--src/analysis/scan/patterns/backends/acism.h59
-rw-r--r--src/analysis/scan/patterns/backends/bitap-int.h132
-rw-r--r--src/analysis/scan/patterns/backends/bitap.c2785
-rw-r--r--src/analysis/scan/patterns/backends/bitap.h59
-rw-r--r--src/analysis/scan/patterns/backends/hyperscan-int.h67
-rw-r--r--src/analysis/scan/patterns/backends/hyperscan.c1063
-rw-r--r--src/analysis/scan/patterns/backends/hyperscan.h59
-rw-r--r--src/analysis/scan/patterns/customizer-int.h58
-rw-r--r--src/analysis/scan/patterns/customizer.c377
-rw-r--r--src/analysis/scan/patterns/customizer.h65
-rw-r--r--src/analysis/scan/patterns/modarg.h91
-rw-r--r--src/analysis/scan/patterns/modifier-int.h71
-rw-r--r--src/analysis/scan/patterns/modifier.c278
-rw-r--r--src/analysis/scan/patterns/modifier.h73
-rw-r--r--src/analysis/scan/patterns/modifiers/Makefile.am23
-rw-r--r--src/analysis/scan/patterns/modifiers/hex.c296
-rw-r--r--src/analysis/scan/patterns/modifiers/hex.h58
-rw-r--r--src/analysis/scan/patterns/modifiers/list-int.h54
-rw-r--r--src/analysis/scan/patterns/modifiers/list.c438
-rw-r--r--src/analysis/scan/patterns/modifiers/list.h68
-rw-r--r--src/analysis/scan/patterns/modifiers/lower.c301
-rw-r--r--src/analysis/scan/patterns/modifiers/lower.h58
-rw-r--r--src/analysis/scan/patterns/modifiers/pipe-int.h54
-rw-r--r--src/analysis/scan/patterns/modifiers/pipe.c405
-rw-r--r--src/analysis/scan/patterns/modifiers/pipe.h68
-rw-r--r--src/analysis/scan/patterns/modifiers/plain.c289
-rw-r--r--src/analysis/scan/patterns/modifiers/plain.h58
-rw-r--r--src/analysis/scan/patterns/modifiers/rev.c291
-rw-r--r--src/analysis/scan/patterns/modifiers/rev.h58
-rw-r--r--src/analysis/scan/patterns/modifiers/upper.c301
-rw-r--r--src/analysis/scan/patterns/modifiers/upper.h58
-rw-r--r--src/analysis/scan/patterns/modifiers/wide.c291
-rw-r--r--src/analysis/scan/patterns/modifiers/wide.h58
-rw-r--r--src/analysis/scan/patterns/modifiers/xor.c438
-rw-r--r--src/analysis/scan/patterns/modifiers/xor.h58
-rw-r--r--src/analysis/scan/patterns/patid.h36
-rw-r--r--src/analysis/scan/patterns/token-int.h62
-rw-r--r--src/analysis/scan/patterns/token.c491
-rw-r--r--src/analysis/scan/patterns/token.h75
-rw-r--r--src/analysis/scan/patterns/tokens/Makefile.am26
-rw-r--r--src/analysis/scan/patterns/tokens/atom.c543
-rw-r--r--src/analysis/scan/patterns/tokens/atom.h88
-rw-r--r--src/analysis/scan/patterns/tokens/hex-int.h56
-rw-r--r--src/analysis/scan/patterns/tokens/hex.c259
-rw-r--r--src/analysis/scan/patterns/tokens/hex.h59
-rw-r--r--src/analysis/scan/patterns/tokens/node-int.h108
-rw-r--r--src/analysis/scan/patterns/tokens/node.c675
-rw-r--r--src/analysis/scan/patterns/tokens/node.h127
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/Makefile.am24
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/any-int.h60
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/any.c765
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/any.h61
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/choice-int.h54
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/choice.c646
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/choice.h61
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/masked-int.h64
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/masked.c1135
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/masked.h63
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/not-int.h57
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/not.c416
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/not.h59
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/plain-int.h64
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/plain.c1377
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/plain.h83
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/sequence-int.h58
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/sequence.c504
-rw-r--r--src/analysis/scan/patterns/tokens/nodes/sequence.h67
-rw-r--r--src/analysis/scan/patterns/tokens/offset.c438
-rw-r--r--src/analysis/scan/patterns/tokens/offset.h111
-rw-r--r--src/analysis/scan/patterns/tokens/plain-int.h56
-rw-r--r--src/analysis/scan/patterns/tokens/plain.c266
-rw-r--r--src/analysis/scan/patterns/tokens/plain.h59
79 files changed, 20368 insertions, 0 deletions
diff --git a/src/analysis/scan/patterns/Makefile.am b/src/analysis/scan/patterns/Makefile.am
new file mode 100644
index 0000000..989a562
--- /dev/null
+++ b/src/analysis/scan/patterns/Makefile.am
@@ -0,0 +1,30 @@
+
+noinst_LTLIBRARIES = libanalysisscanpatterns.la
+
+
+libanalysisscanpatterns_la_SOURCES = \
+ backend-int.h \
+ backend.h backend.c \
+ customizer-int.h \
+ customizer.h customizer.c \
+ modarg.h \
+ modifier-int.h \
+ modifier.h modifier.c \
+ patid.h \
+ token-int.h \
+ token.h token.c
+
+libanalysisscanpatterns_la_LIBADD = \
+ backends/libanalysisscanpatternsbackends.la \
+ modifiers/libanalysisscanpatternsmodifiers.la \
+ tokens/libanalysisscanpatternstokens.la
+
+libanalysisscanpatterns_la_CFLAGS = $(LIBGOBJ_CFLAGS) $(LIBPYTHON_INTERPRETER_CFLAGS)
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
+
+dev_HEADERS = $(libanalysisscanpatterns_la_SOURCES:%c=)
+
+
+SUBDIRS = backends modifiers tokens
diff --git a/src/analysis/scan/patterns/backend-int.h b/src/analysis/scan/patterns/backend-int.h
new file mode 100644
index 0000000..aeabe1b
--- /dev/null
+++ b/src/analysis/scan/patterns/backend-int.h
@@ -0,0 +1,78 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * backend-int.h - prototypes internes pour une méthode de recherches au sein d'un contenu binaire
+ *
+ * Copyright (C) 2022 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_PATTERNS_BACKEND_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKEND_INT_H
+
+
+#include "backend.h"
+
+
+
+/* Indique la taille maximale des suites d'octets recherchées. */
+typedef size_t (* get_backend_atom_max_size_fc) (const GEngineBackend *);
+
+/* Inscrit dans le moteur une chaîne de caractères à rechercher. */
+typedef patid_t (* enroll_plain_into_backend_fc) (GEngineBackend *, const uint8_t *, size_t, uint32_t [2]);
+
+/* Met en ordre les derniers détails avant un premier scan. */
+typedef bool (* warm_up_backend_fc) (GEngineBackend *);
+
+/* Récupère les identifiants finaux pour un motif recherché. */
+typedef patid_t (* build_backend_plain_pattern_id_fc) (const GEngineBackend *, const uint32_t [2]);
+
+/* Détermine le nombre d'identifiants constitués. */
+typedef size_t (* count_backend_plain_pattern_ids_fc) (const GEngineBackend *);
+
+/* Parcours un contenu binaire à la recherche de motifs. */
+typedef void (* run_backend_scan_fc) (const GEngineBackend *, GScanContext *);
+
+/* Imprime quelques faits quant aux éléments mis en place. */
+typedef void (* output_backend_stats_fc) (const GEngineBackend *);
+
+
+/* Méthode de traitement d'un contenu binaire pour recherches (instance) */
+struct _GEngineBackend
+{
+ GObject parent; /* A laisser en premier */
+
+};
+
+/* Méthode de traitement d'un contenu binaire pour recherches (classe) */
+struct _GEngineBackendClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+ get_backend_atom_max_size_fc get_max_size; /* Taille maximale d'atome */
+ enroll_plain_into_backend_fc enroll_plain; /* Inscription simpl e */
+ warm_up_backend_fc warm_up; /* Préchauffage avant analyse */
+ build_backend_plain_pattern_id_fc build_id; /* Définition d'identifiant*/
+ count_backend_plain_pattern_ids_fc count_ids; /* Décompte des id. */
+ run_backend_scan_fc run_scan; /* Lancement d'une analyse */
+ output_backend_stats_fc output; /* Impression de statistiques */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKEND_INT_H */
diff --git a/src/analysis/scan/patterns/backend.c b/src/analysis/scan/patterns/backend.c
new file mode 100644
index 0000000..a887600
--- /dev/null
+++ b/src/analysis/scan/patterns/backend.c
@@ -0,0 +1,311 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * backend.c - méthode de recherches au sein d'un contenu binaire
+ *
+ * Copyright (C) 2022 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 "backend.h"
+
+
+#include "backend-int.h"
+
+
+
+/* Initialise la classe des méthodes de recherche pour binaire. */
+static void g_engine_backend_class_init(GEngineBackendClass *);
+
+/* Initialise une instance de méthode de recherche pour binaire. */
+static void g_engine_backend_init(GEngineBackend *);
+
+/* Supprime toutes les références externes. */
+static void g_engine_backend_dispose(GEngineBackend *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_engine_backend_finalize(GEngineBackend *);
+
+
+
+/* Indique le type défini pour une méthode de recherche dans du binaire. */
+G_DEFINE_TYPE(GEngineBackend, g_engine_backend, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des méthodes de recherche pour binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_engine_backend_class_init(GEngineBackendClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_engine_backend_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_engine_backend_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance à initialiser. *
+* *
+* Description : Initialise une instance de méthode de recherche pour binaire.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_engine_backend_init(GEngineBackend *backend)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_engine_backend_dispose(GEngineBackend *backend)
+{
+ G_OBJECT_CLASS(g_engine_backend_parent_class)->dispose(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_engine_backend_finalize(GEngineBackend *backend)
+{
+ G_OBJECT_CLASS(g_engine_backend_parent_class)->finalize(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Indique la taille maximale des suites d'octets recherchées. *
+* *
+* Retour : Valeur strictement positive. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_engine_backend_get_atom_max_size(const GEngineBackend *backend)
+{
+ size_t result; /* Taille à faire connaître */
+ GEngineBackendClass *class; /* Classe à activer */
+
+ class = G_ENGINE_BACKEND_GET_CLASS(backend);
+
+ result = class->get_max_size(backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* plain = chaîne de caractères classique à intégrer. *
+* len = taille de cette chaîne. *
+* tmp_id = identifiants temporaires vers le motif. [OUT] *
+* *
+* Description : Inscrit dans le moteur une chaîne de caractères à rechercher.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_engine_backend_enroll_plain_pattern(GEngineBackend *backend, const uint8_t *plain, size_t len, uint32_t tmp_id[2])
+{
+ bool result; /* Bilan à retourner */
+ GEngineBackendClass *class; /* Classe à activer */
+
+ class = G_ENGINE_BACKEND_GET_CLASS(backend);
+
+ result = class->enroll_plain(backend, plain, len, tmp_id);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Met en ordre les derniers détails avant un premier scan. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_engine_backend_warm_up(GEngineBackend *backend)
+{
+ bool result; /* Bilan à retourner */
+ GEngineBackendClass *class; /* Classe à activer */
+
+ class = G_ENGINE_BACKEND_GET_CLASS(backend);
+
+ if (class->warm_up != NULL)
+ result = class->warm_up(backend);
+ else
+ result = true;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* tmp_id = identifiants temporaires vers le motif. [OUT] *
+* *
+* Description : Récupère les identifiants finaux pour un motif recherché. *
+* *
+* Retour : Identifiant constitué ou INVALID_PATTERN_ID en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+patid_t g_engine_backend_build_plain_pattern_id(const GEngineBackend *backend, const uint32_t tmp_id[2])
+{
+ patid_t result; /* Identifiant à retourner */
+ GEngineBackendClass *class; /* Classe à activer */
+
+ class = G_ENGINE_BACKEND_GET_CLASS(backend);
+
+ result = class->build_id(backend, tmp_id);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* *
+* Description : Détermine le nombre d'identifiants constitués. *
+* *
+* Retour : Quantité de gestionnaires de suivi à prévoir. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_engine_backend_count_plain_pattern_ids(const GEngineBackend *backend)
+{
+ size_t result; /* Quantité à retourner */
+ GEngineBackendClass *class; /* Classe à activer */
+
+ class = G_ENGINE_BACKEND_GET_CLASS(backend);
+
+ result = class->count_ids(backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_engine_backend_run_scan(const GEngineBackend *backend, GScanContext *context)
+{
+ GEngineBackendClass *class; /* Classe à activer */
+
+ class = G_ENGINE_BACKEND_GET_CLASS(backend);
+
+ class->run_scan(backend, context);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Imprime quelques faits quant aux éléments mis en place. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_engine_backend_output_stats(const GEngineBackend *backend)
+{
+ GEngineBackendClass *class; /* Classe à activer */
+
+ class = G_ENGINE_BACKEND_GET_CLASS(backend);
+
+ if (class->output != NULL)
+ class->output(backend);
+
+}
diff --git a/src/analysis/scan/patterns/backend.h b/src/analysis/scan/patterns/backend.h
new file mode 100644
index 0000000..3f9be03
--- /dev/null
+++ b/src/analysis/scan/patterns/backend.h
@@ -0,0 +1,79 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * backend.h - prototypes pour une méthode de recherches au sein d'un contenu binaire
+ *
+ * Copyright (C) 2022 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_PATTERNS_BACKEND_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKEND_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+
+#include "../context.h"
+#include "../../content.h"
+
+
+
+#define G_TYPE_ENGINE_BACKEND g_engine_backend_get_type()
+#define G_ENGINE_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_ENGINE_BACKEND, GEngineBackend))
+#define G_IS_ENGINE_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_ENGINE_BACKEND))
+#define G_ENGINE_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ENGINE_BACKEND, GEngineBackendClass))
+#define G_IS_ENGINE_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ENGINE_BACKEND))
+#define G_ENGINE_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ENGINE_BACKEND, GEngineBackendClass))
+
+
+/* Méthode de traitement d'un contenu binaire pour recherches (instance) */
+typedef struct _GEngineBackend GEngineBackend;
+
+/* Méthode de traitement d'un contenu binaire pour recherches (classe) */
+typedef struct _GEngineBackendClass GEngineBackendClass;
+
+
+/* Indique le type défini pour une méthode de recherche dans du binaire. */
+GType g_engine_backend_get_type(void);
+
+/* Indique la taille maximale des suites d'octets recherchées. */
+size_t g_engine_backend_get_atom_max_size(const GEngineBackend *);
+
+/* Inscrit dans le moteur une chaîne de caractères à rechercher. */
+bool g_engine_backend_enroll_plain_pattern(GEngineBackend *, const uint8_t *, size_t, uint32_t [2]);
+
+/* Met en ordre les derniers détails avant un premier scan. */
+bool g_engine_backend_warm_up(GEngineBackend *);
+
+/* Récupère les identifiants finaux pour un motif recherché. */
+patid_t g_engine_backend_build_plain_pattern_id(const GEngineBackend *, const uint32_t [2]);
+
+/* Détermine le nombre d'identifiants constitués. */
+size_t g_engine_backend_count_plain_pattern_ids(const GEngineBackend *);
+
+/* Parcours un contenu binaire à la recherche de motifs. */
+void g_engine_backend_run_scan(const GEngineBackend *, GScanContext *);
+
+/* Imprime quelques faits quant aux éléments mis en place. */
+void g_engine_backend_output_stats(const GEngineBackend *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKEND_H */
diff --git a/src/analysis/scan/patterns/backends/Makefile.am b/src/analysis/scan/patterns/backends/Makefile.am
new file mode 100644
index 0000000..23b0163
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/Makefile.am
@@ -0,0 +1,29 @@
+
+noinst_LTLIBRARIES = libanalysisscanpatternsbackends.la
+
+
+libanalysisscanpatternsbackends_la_SOURCES = \
+ acism-int.h \
+ acism.h acism.c \
+ bitap-int.h \
+ bitap.h bitap.c \
+ hyperscan-int.h \
+ hyperscan.h hyperscan.c
+
+# Cf. https://www.gnu.org/software/automake/manual/html_node/Per_002dObject-Flags.html
+
+AM_CFLAGS = $(LIBGOBJ_CFLAGS) $(LIBHS_CFLAGS)
+
+
+
+#AM_CFLAGS:=$(filter-out -O2,$(AM_CFLAGS))
+
+
+#bitap.lo: AM_CFLAGS += -Ofast -march=native -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1 #-mavx512bw
+#bitap.lo: AM_CFLAGS += -O3 -march=native -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1 #-mavx512bw
+bitap.lo: AM_CFLAGS += -g -march=native -mno-vzeroupper -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
+
+dev_HEADERS = $(libanalysisscanpatternsbackends_la_SOURCES:%c=)
diff --git a/src/analysis/scan/patterns/backends/acism-int.h b/src/analysis/scan/patterns/backends/acism-int.h
new file mode 100644
index 0000000..c4a72ca
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/acism-int.h
@@ -0,0 +1,206 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * acism-int.h - prototypes internes pour la méthode de recherche basée sur l'algorithme Aho-Corasick Interleaved State-transition Matrix
+ *
+ * Copyright (C) 2022 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_PATTERNS_BACKENDS_ACISM_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKENDS_ACISM_INT_H
+
+
+#include "acism.h"
+
+
+#include <stdint.h>
+
+
+#include "../backend-int.h"
+#include "../../../../common/bits.h"
+
+
+
+//#define __USE_BYTE_FREQ
+//#define __SORT_BEFORE_BITMASK
+
+
+#define ACSIM_ATOM_SIZE 7
+
+
+
+/* Définition d'une portion de cible */
+typedef struct _acism_source_t
+{
+ /**
+ * Champs renseignés dans g_acism_backend_setup_for().
+ */
+
+ const uint8_t *atoms; /* Motif remarquable */
+ size_t len; /* Nombre d'octets considérés */
+
+ /**
+ * Champs renseignés dans g_acism_backend_build_trie().
+ */
+
+ bool is_first; /* Première instance rencontrée*/
+
+ union
+ {
+ uint32_t coverage[2]; /* Départ et quantité de suivis*/
+ struct
+ {
+ size_t first_source; /* Indice de première source */
+ uint32_t index; /* Position dans la liste */
+ };
+ };
+
+} acism_source_t;
+
+#define SOURCE_COVERAGE_START 0
+#define SOURCE_COVERAGE_COUNT 1
+#define SOURCE_COVERAGE_END 1
+
+/* Etude de la fréquence des octets pour attribution des codes */
+typedef struct _acism_freq_rank_t
+{
+ unsigned int frequency; /* Occurrences d'un octet */
+ uint8_t rank; /* Valeur dudit octet */
+
+} acism_freq_rank_t;
+
+/* Identifiant unique pour une valeur 8 bits donnée (max 257) */
+typedef uint16_t acism_code_t;
+
+#define MIN_ACISM_CODE 0
+#define MAX_ACISM_CODE 0xffff
+
+#define ROOT_STATE_INDEX 0
+
+/* Noeud de l'arborescence brute */
+typedef struct _acism_trie_node_t
+{
+ struct _acism_trie_node_t *parent; /* Noeud parent pour remontée */
+ struct _acism_trie_node_t *sibling; /* Noeud de même niveau suivant*/
+ struct _acism_trie_node_t *child; /* Noeud de lecture suivant */
+ struct _acism_trie_node_t *suffix_link; /* Retour en cas d'échec */
+
+ bin_t data; /* Donnée brute représentée */
+ acism_code_t code; /* Identifiant du noeud */
+
+ acism_code_t min_child_code; /* Plus petit code suivant */
+ acism_code_t max_child_code; /* Plus grand code suivant */
+ size_t children_count; /* Nombre de codes suivants */
+
+ size_t matched_atom; /* Indice de correspondance */
+
+ size_t state_index; /* Indice de le tableau final */
+
+} acism_trie_node_t;
+
+#if __LONG_WIDTH__ < 64
+
+/* Cellule du tableau compressé final */
+typedef struct _acism_state_t
+{
+ union
+ {
+ /* Indice 0 */
+ struct
+ {
+ unsigned int match : 1; /* Correspondance ici */
+ unsigned int unused : 4; /* Espace encore disponible */
+ unsigned int atom_size : 3; /* Taille d'atome représenté */
+ unsigned int suffix : 1; /* Correspondance ailleurs */
+ };
+
+ /* Indice 1 et + */
+ unsigned int code : 9; /* Position depuis la base */
+
+ };
+
+ unsigned int index : 23; /* Indice de saut */
+
+} acism_state_t;
+
+#else
+
+/* Cellule du tableau compressé final */
+typedef union _acism_state_t
+{
+ /* Indice 0 */
+ struct
+ {
+ uint8_t match : 1; /* Correspondance ici */
+ uint8_t single_source : 1; /* Unique source à notifier */
+ uint8_t atom_size; /* Indice de saut */
+ uint8_t suffix : 1; /* Correspondance ailleurs */
+ };
+
+ /* Indice 1 et + */
+ uint32_t code; /* Position depuis la base */
+
+ /* Tous */
+ struct
+ {
+ uint32_t any; /* Saut de bits */
+ uint32_t index; /* Indice de saut */
+ };
+
+} acism_state_t;
+
+#endif
+
+/* Méthode de recherche basée sur l'algorithme Acism (instance) */
+struct _GAcismBackend
+{
+ GEngineBackend parent; /* A laisser en premier */
+
+#ifdef __USE_BYTE_FREQ
+ acism_code_t codes_for_bytes[256]; /* Traduction octets -> codes */
+ acism_code_t codes_count; /* Quantité de traductions */
+#endif
+
+ acism_source_t *sources; /* Liste de motifs remarquables*/
+ size_t sources_count; /* Quantité de ces motifs */
+
+ size_t nchars; /* Taille cumulée des motifs */
+
+#ifdef __USE_BYTE_FREQ
+ acism_freq_rank_t frequencies[256]; /* Fréquences des octets */
+#endif
+
+ acism_trie_node_t *nodes; /* Liste de noeuds */
+ size_t nodes_used; /* Nombre de noeuds utilisés */
+
+ bitfield_t *bitmap_usage; /* Localisation des usages */
+ acism_state_t *states; /* Tableau de transitions */
+ uint32_t *coverages; /* Bornes de suivi de positions*/
+
+};
+
+/* Méthode de recherche basée sur l'algorithme Acism (classe) */
+struct _GAcismBackendClass
+{
+ GEngineBackendClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKENDS_ACISM_INT_H */
diff --git a/src/analysis/scan/patterns/backends/acism.c b/src/analysis/scan/patterns/backends/acism.c
new file mode 100644
index 0000000..53bad11
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/acism.c
@@ -0,0 +1,1522 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * acism.c - méthode de recherche basée sur l'algorithme Aho-Corasick Interleaved State-transition Matrix
+ *
+ * Copyright (C) 2022 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 "acism.h"
+
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#include "acism-int.h"
+#include "../../../../common/sort.h"
+
+
+
+/* ---------------------- IMPLANTATION D'UNE NOUVELLE APPROCHE ---------------------- */
+
+
+/* Initialise la classe des méthodes basée sur ACISM. */
+static void g_acism_backend_class_init(GAcismBackendClass *);
+
+/* Initialise une instance de méthodes basée sur ACISM. */
+static void g_acism_backend_init(GAcismBackend *);
+
+/* Supprime toutes les références externes. */
+static void g_acism_backend_dispose(GAcismBackend *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_acism_backend_finalize(GAcismBackend *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Indique la taille maximale des suites d'octets recherchées. */
+size_t g_acism_backend_get_atom_max_size(const GAcismBackend *);
+
+/* Intègre un motif limité de contenu à rechercher. */
+static void g_acism_backend_setup_for(GAcismBackend *, const uint8_t *, size_t, uint32_t [2]);
+
+/* Inscrit dans le moteur une chaîne de caractères à rechercher. */
+static bool g_acism_backend_enroll_plain_pattern(GAcismBackend *, const uint8_t *, size_t, uint32_t [2]);
+
+#ifdef __USE_BYTE_FREQ
+
+/* Compare un niveau de fréquence avec un autre. */
+static int compare_byte_frequencies(const acism_freq_rank_t *, const acism_freq_rank_t *);
+
+/* Détermine les identifiants de chaque valeur 8 bits utile. */
+static void g_acism_backend_define_codes(GAcismBackend *);
+
+#endif
+
+/* Construit l'arborescence de noeuds de lecture. */
+static void g_acism_backend_build_trie(GAcismBackend *);
+
+/* Construit l'arborescence de noeuds de lecture. */
+static void g_acism_backend_build_suffix_links(GAcismBackend *);
+
+#ifdef __SORT_BEFORE_BITMASK
+
+/* Compare des noeuds selon l'espace de codes couvert. */
+static int compare_node_according_to_code_range(const acism_trie_node_t **, const acism_trie_node_t **);
+
+#endif
+
+/* Organise la convertion de l'arborescence en tableau. */
+static void g_acism_backend_prepare_interleave_array(GAcismBackend *);
+
+/* Compresse l'arborescence dans un tableau de position. */
+static void g_acism_backend_build_interleave_array(GAcismBackend *);
+
+/* Met en ordre les derniers détails avant un premier scan. */
+static bool g_acism_backend_warm_up(GAcismBackend *);
+
+/* Récupère les identifiants finaux pour un motif recherché. */
+static patid_t g_acism_backend_build_plain_pattern_id(const GAcismBackend *, const uint32_t [2]);
+
+/* Détermine le nombre d'identifiants constitués. */
+static size_t g_acism_backend_count_plain_pattern_ids(const GAcismBackend *);
+
+/* Parcours un contenu binaire à la recherche de motifs. */
+static void g_acism_backend_run_scan(const GAcismBackend *, GScanContext *);
+
+/* Affiche les caractéristques d'un noeud et de ses enfants. */
+static void visit_and_output_node(const acism_trie_node_t *, unsigned int);
+
+/* Imprime quelques faits quant aux éléments mis en place. */
+static void g_acism_backend_output_stats(const GAcismBackend *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLANTATION D'UNE NOUVELLE APPROCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour un moteur de recherche pour données. */
+G_DEFINE_TYPE(GAcismBackend, g_acism_backend, G_TYPE_ENGINE_BACKEND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des méthodes basée sur ACISM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_class_init(GAcismBackendClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GEngineBackendClass *backend; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_acism_backend_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_acism_backend_finalize;
+
+ backend = G_ENGINE_BACKEND_CLASS(klass);
+
+ backend->get_max_size = (get_backend_atom_max_size_fc)g_acism_backend_get_atom_max_size;
+ backend->enroll_plain = (enroll_plain_into_backend_fc)g_acism_backend_enroll_plain_pattern;
+ backend->warm_up = (warm_up_backend_fc)g_acism_backend_warm_up;
+ backend->build_id = (build_backend_plain_pattern_id_fc)g_acism_backend_build_plain_pattern_id;
+ backend->count_ids = (count_backend_plain_pattern_ids_fc)g_acism_backend_count_plain_pattern_ids;
+ backend->run_scan = (run_backend_scan_fc)g_acism_backend_run_scan;
+ backend->output = (output_backend_stats_fc)g_acism_backend_output_stats;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance à initialiser. *
+* *
+* Description : Initialise une instance de méthodes basée sur ACISM. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_init(GAcismBackend *backend)
+{
+#ifdef __USE_BYTE_FREQ
+ size_t i; /* Boucle de parcours #1 */
+ acism_freq_rank_t *iter; /* Boucle de parcours #2 */
+#endif
+
+#ifdef __USE_BYTE_FREQ
+ memset(backend->codes_for_bytes, 0, 256 * sizeof(acism_code_t));
+#endif
+
+ backend->nchars = 0;
+
+#ifdef __USE_BYTE_FREQ
+ for (i = 0, iter = backend->frequencies; i < 256; i++, iter++)
+ {
+ iter->frequency = 0;
+ iter->rank = i;
+ }
+#endif
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_dispose(GAcismBackend *backend)
+{
+ G_OBJECT_CLASS(g_acism_backend_parent_class)->dispose(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_finalize(GAcismBackend *backend)
+{
+ if (backend->sources != NULL)
+ free(backend->sources);
+
+ if (backend->nodes != NULL)
+ free(backend->nodes);
+
+ if (backend->bitmap_usage != NULL)
+ delete_bit_field(backend->bitmap_usage);
+
+ if (backend->states != NULL)
+ free(backend->states);
+
+ if (backend->coverages != NULL)
+ free(backend->coverages);
+
+ G_OBJECT_CLASS(g_acism_backend_parent_class)->finalize(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée une méthode de recherche basée sur l'algorithme Acism. *
+* *
+* Retour : Méthode mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GEngineBackend *g_acism_backend_new(void)
+{
+ GAcismBackend *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_ACISM_BACKEND, NULL);
+
+ return G_ENGINE_BACKEND(result);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Indique la taille maximale des suites d'octets recherchées. *
+* *
+* Retour : Valeur strictement positive. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_acism_backend_get_atom_max_size(const GAcismBackend *backend)
+{
+ size_t result; /* Taille à faire connaître */
+
+ result = ACSIM_ATOM_SIZE;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* pattern = chaîne de caractères classique à intégrer. *
+* len = taille de cette chaîne. *
+* tmp_id = identifiants temporaires vers le motif. [OUT] *
+* *
+* Description : Intègre un motif limité de contenu à rechercher. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_setup_for(GAcismBackend *backend, const uint8_t *pattern, size_t len, uint32_t tmp_id[2])
+{
+ size_t current; /* Indice de source courante */
+ acism_source_t *source; /* Définition à mémoriser */
+
+ /**
+ * Les motifs '\x00\x00\x00\x00abcd1234' et '\x01\x01\x01\x01abcd1234'
+ * peuvent constituer deux cibles différentes, mais ils comportent
+ * normalement la même séquence atomique à rechercher : 'abcd1234'.
+ *
+ * Chaque motif 'abcd1234' proposé est enregistré ici, et se verra in fine
+ * attribuer un identifiant propre. Le regroupement des motifs identiques
+ * et la constitution des identifiants finaux sont réalisés au moment de la
+ * construction de l'arborescence de recherche.
+ */
+
+ /* Pré-inscription pour l'extérieur */
+
+ current = backend->sources_count;
+
+ tmp_id[0] = current;
+ tmp_id[1] = 0; /* Non utilisé */
+
+ /* Inscription en interne */
+
+ backend->sources = realloc(backend->sources, ++backend->sources_count * sizeof(acism_source_t));
+
+ source = &backend->sources[current];
+
+ source->atoms = pattern;
+ source->len = len;
+
+ backend->nchars += len;
+
+#ifdef __USE_BYTE_FREQ
+ for (i = 0; i < len; i++)
+ backend->frequencies[pattern[i]].frequency++;
+#endif
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* plain = chaîne de caractères classique à intégrer. *
+* len = taille de cette chaîne. *
+* tmp_id = identifiants temporaires vers le motif. [OUT] *
+* *
+* Description : Inscrit dans le moteur une chaîne de caractères à rechercher.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_acism_backend_enroll_plain_pattern(GAcismBackend *backend, const uint8_t *plain, size_t len, uint32_t tmp_id[2])
+{
+ bool result; /* Bilan à retourner */
+
+ assert(len <= ACSIM_ATOM_SIZE);
+
+ result = true;
+
+ /**
+ * Le traitement différé des chaînes à rechercher permet deux choses :
+ * - la construction d'une table de permutation ;
+ * - le décompte des noeuds à allouer (en une seule fois).
+ *
+ * Si l'intention du premier point est louable (densifier les champs de bits
+ * pour allouer moins et tenir plus facilement dans le cache du CPU), la
+ * permetutation est extrèmement coûteuse pendant la phase de scan
+ * (une lecture supplémentaire par octet de données scannées).
+ *
+ * Le second point reste valable (à priori).
+ *
+ * L'appel à la fonction g_acism_backend_setup_for() demeure donc, et l'arbre
+ * est construit dans un second temps. La distinction de cette fonction avec
+ * la procédure d'enrôlement permet potentiellement d'étuer une bascule à
+ * moindre coût un jour.
+ */
+
+ g_acism_backend_setup_for(backend, plain, len, tmp_id);
+
+ return result;
+
+}
+
+
+#ifdef __USE_BYTE_FREQ
+
+
+/******************************************************************************
+* *
+* Paramètres : a = premier élément à comparer. *
+* b = second élément à comparer. *
+* *
+* Description : Compare un niveau de fréquence avec un autre. *
+* *
+* Retour : Bilan de la comparaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int compare_byte_frequencies(const acism_freq_rank_t *a, const acism_freq_rank_t *b)
+{
+ int result; /* Bilan à retourner */
+
+ /**
+ * Afin d'obtenir les plus grosses fréquences en premier,
+ * l'ordre de comparaison est inversé : b < a ?
+ */
+
+ result = sort_unsigned_long(b->frequency, a->frequency);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Détermine les identifiants de chaque valeur 8 bits utile. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_define_codes(GAcismBackend *backend)
+{
+ size_t i; /* Boucle de parcours #1 */
+ acism_freq_rank_t *iter; /* Boucle de parcours #2 */
+
+ /**
+ * La redistribution des valeurs d'octet va permettre de compacter
+ * par la suite les masques de cellules utilisées pour construire
+ * le plus petit tableau des états.
+ *
+ * L'idée est de grouper le plus possible les états (représentés
+ * par un indice) autour de l'état 0.
+ */
+
+ qsort(backend->frequencies, 256, sizeof(acism_freq_rank_t), (__compar_fn_t)compare_byte_frequencies);
+
+ /* 0 == racine */
+ backend->codes_count++;
+
+ for (i = 0, iter = backend->frequencies; i < 256; i++, iter++)
+ {
+ if (iter->frequency == 0)
+ break;
+
+ backend->codes_for_bytes[iter->rank] = backend->codes_count++;
+
+ }
+
+}
+
+
+#endif
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Construit l'arborescence de noeuds de lecture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_build_trie(GAcismBackend *backend)
+{
+ size_t i; /* Boucle de parcours #1 */
+ acism_trie_node_t *next; /* Prochain noeud disponible */
+ acism_trie_node_t *node; /* Tête de parcours */
+ acism_source_t *source; /* Définition à mémoriser */
+ size_t k; /* Boucle de parcours #2 */
+ acism_code_t code; /* Identifiant de symbole */
+ acism_trie_node_t *parent; /* Sauvegarde d'un accès */
+ uint32_t current_start; /* Indice de gestionnaire */
+
+ backend->nodes = calloc(backend->nchars + 1, sizeof(acism_trie_node_t));
+
+ for (i = 0; i < (backend->nchars + 1); i++)
+ {
+ backend->nodes[i].min_child_code = MAX_ACISM_CODE;
+ backend->nodes[i].max_child_code = MIN_ACISM_CODE;
+ }
+
+ next = backend->nodes + 1;
+
+ for (i = 0; i < backend->sources_count; i++)
+ {
+ node = backend->nodes;
+
+ source = &backend->sources[i];
+
+ /* Parcours des noeuds contenus */
+
+ for (k = 0; k < source->len && node->child != NULL; k++)
+ {
+#ifdef __USE_BYTE_FREQ
+ code = backend->codes_for_bytes[source->atoms[k]];
+#else
+ code = 1 + source->atoms[k];
+#endif
+
+ /* Insertion d'un nouveau noeud au début des enfants */
+ if (code < node->child->code)
+ {
+ next->parent = node;
+ next->suffix_link = node;
+ next->data = source->atoms[k];
+ next->code = code;
+
+ next->sibling = node->child;
+ node->child = next++;
+
+ if (code < node->min_child_code) node->min_child_code = code;
+ if (code > node->max_child_code) node->max_child_code = code;
+ node->children_count++;
+
+ node = node->child;
+
+ k++;
+ break;
+
+ }
+
+ parent = node;
+
+ /* Recherche du point d'insertion idéal */
+ for (node = node->child;
+ node->sibling != NULL && code >= node->sibling->code;
+ node = node->sibling);
+
+ /* Si le noeud idéal n'existe pas, insertion ordonnée */
+ if (code > node->code)
+ {
+ next->parent = parent;
+ next->suffix_link = parent;
+ next->data = source->atoms[k];
+ next->code = code;
+
+ next->sibling = node->sibling;
+ node->sibling = next++;
+
+ if (code < parent->min_child_code) parent->min_child_code = code;
+ if (code > parent->max_child_code) parent->max_child_code = code;
+ parent->children_count++;
+
+ node = node->sibling;
+
+ k++;
+ break;
+
+ }
+
+ }
+
+ /* Si un atome (partiellement ?) identique a déjà été inscrit */
+ if (k == source->len)
+ {
+ /**
+ * L'atome déjà inscrit est plus long, et on se trouve ici dans le
+ * parcours de l'arborescence qui mène à sa conclusion, sans
+ * inscription d'une fin de parcours au point courant.
+ */
+ if (node->matched_atom == 0)
+ goto register_leaf;
+
+ /**
+ * Rattachement au motif strictement identique.
+ */
+ else
+ {
+ assert(backend->sources[node->matched_atom - 1].is_first);
+
+ source->is_first = false;
+ source->first_source = node->matched_atom - 1;
+ source->index = backend->sources[source->first_source].coverage[SOURCE_COVERAGE_COUNT]++;
+
+ }
+
+ }
+
+ else
+ {
+ /* Creéation d'une nouvelle branche avec le reliquat */
+ for (; k < source->len; k++)
+ {
+#ifdef __USE_BYTE_FREQ
+ code = backend->codes_for_bytes[source->atoms[k]];
+#else
+ code = 1 + source->atoms[k];
+#endif
+
+ next->parent = node;
+ next->suffix_link = node;
+ next->data = source->atoms[k];
+ next->code = code;
+
+ node->child = next++;
+
+ if (code < node->min_child_code) node->min_child_code = code;
+ if (code > node->max_child_code) node->max_child_code = code;
+ node->children_count++;
+
+ node = node->child;
+
+ }
+
+ register_leaf:
+
+ node->matched_atom = i + 1;
+
+ source->is_first = true;
+ source->coverage[SOURCE_COVERAGE_COUNT] = 1;
+
+ }
+
+ }
+
+ backend->nodes_used = next - backend->nodes;
+
+ /* Construction des bases pour identifiants */
+
+ current_start = 0;
+
+ for (i = 0; i < backend->sources_count; i++)
+ {
+ source = &backend->sources[i];
+
+ if (source->is_first)
+ {
+ source->coverage[SOURCE_COVERAGE_START] = current_start;
+
+ current_start += source->coverage[SOURCE_COVERAGE_COUNT];
+
+ }
+
+ }
+
+ assert(current_start == backend->sources_count);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Construit l'arborescence de noeuds de lecture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_build_suffix_links(GAcismBackend *backend)
+{
+ size_t max_pos; /* Tête de lecture finale */
+ acism_trie_node_t **stack; /* Pile des noeuds à traiter */
+ size_t rd_pos; /* Tête de lecture */
+ size_t wr_pos; /* Tête d'écriture */
+ acism_trie_node_t *node; /* Noeud à traiter */
+ acism_trie_node_t *parent; /* Noeud parent de la chaîne */
+ acism_trie_node_t *iter; /* Boucle de parcours */
+
+ max_pos = backend->nodes_used;
+
+ stack = calloc(max_pos, sizeof(acism_trie_node_t *));
+
+ /* Initialisation du parcours */
+
+ rd_pos = 0;
+ wr_pos = 0;
+
+ stack[wr_pos++] = &backend->nodes[0];
+
+ assert(backend->nodes->sibling == NULL);
+
+ /* Traitement manuel de démarrage pour éviter une condition en [0] */
+
+ for (iter = backend->nodes->child; iter != NULL; iter = iter->sibling)
+ stack[wr_pos++] = iter;
+
+ rd_pos++;
+
+ /* Suivi des liens déjà en place */
+
+ while (rd_pos < max_pos)
+ {
+ assert(rd_pos < wr_pos);
+
+ node = stack[rd_pos++];
+
+ /* Remontée jusqu'à la découverte d'un lien d'intérêt */
+
+ for (parent = node->suffix_link; parent != NULL; parent = parent->suffix_link)
+ {
+ for (iter = parent->child; iter != NULL; iter = iter->sibling)
+ if (iter->code == node->code && iter != node)
+ {
+ node->suffix_link = iter;
+ break;
+ }
+
+ if (iter != NULL)
+ break;
+
+ }
+
+ if (parent == NULL /* && node != &backend->nodes [0] */)
+ node->suffix_link = backend->nodes;
+
+ /* Inscription des noeuds suivants */
+
+ for (iter = node->child; iter != NULL; iter = iter->sibling)
+ stack[wr_pos++] = iter;
+
+ }
+
+ /* Sortie propre */
+
+ free(stack);
+
+}
+
+
+#ifdef __SORT_BEFORE_BITMASK
+
+
+/******************************************************************************
+* *
+* Paramètres : a = premier élément à comparer. *
+* b = second élément à comparer. *
+* *
+* Description : Compare des noeuds selon l'espace de codes couvert. *
+* *
+* Retour : Bilan de la comparaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int compare_node_according_to_code_range(const acism_trie_node_t **a, const acism_trie_node_t **b)
+{
+ int result; /* Bilan à retourner */
+ const acism_trie_node_t *_a; /* Autre vision de l'élément #1*/
+ const acism_trie_node_t *_b; /* Autre vision de l'élément #1*/
+ acism_code_t range_a; /* Espacement des codes #1 */
+ acism_code_t range_b; /* Espacement des codes #2 */
+
+ result = 0;
+
+ _a = *a;
+ _b = *b;
+
+ if (_a->child == NULL)
+ result = (_b->child == NULL ? 0 : 1);
+
+ else if (_b->child == NULL)
+ result = (_a->child == NULL ? 0 : -1);
+
+ else
+ {
+ assert(_a->min_child_code <= _a->max_child_code);
+ range_a = _a->max_child_code - _a->min_child_code;
+
+ assert(_b->min_child_code <= _b->max_child_code);
+ range_b = _b->max_child_code - _b->min_child_code;
+
+ result = sort_unsigned_long(range_b, range_a);
+
+ if (result == 0)
+ result = sort_unsigned_long(_b->children_count, _a->children_count);
+
+ }
+
+ return result;
+
+}
+
+
+#endif
+
+
+#if 1
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Organise la convertion de l'arborescence en tableau. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_prepare_interleave_array(GAcismBackend *backend)
+{
+#ifdef __SORT_BEFORE_BITMASK
+ acism_trie_node_t **list; /* Liste de noeuds alloués */
+#endif
+ size_t i; /* Boucle de parcours #1 */
+ size_t last_free_state; /* Dernier emplacement dispo. */
+ size_t full_size; /* Cartographie entière */
+ bitfield_t *global_usage; /* Cartographie des usages */
+#ifndef NDEBUG
+ size_t pops[3]; /* Décomptes individuels */
+ size_t bsum; /* Somme de tous les bits */
+#endif
+ bitfield_t *usage; /* Cartographie locale */
+ acism_trie_node_t *node; /* Noeud en cours de traitement*/
+ size_t highest; /* Poids du bit le plus fort */
+ acism_trie_node_t *iter; /* Boucle de parcours #2 */
+ size_t first_freedom_word; /* Premier mot avec des dispos.*/
+ size_t free_state; /* Emplacement libre trouvé */
+
+ /* Préparation de la liste de noeuds à inscrire */
+
+#ifdef __SORT_BEFORE_BITMASK
+
+ list = calloc(backend->nodes_used, sizeof(acism_trie_node_t *));
+
+ for (i = 0; i < backend->nodes_used; i++)
+ list[i] = backend->nodes + i;
+
+ qsort(list + 1, backend->nodes_used - 1, sizeof(acism_trie_node_t *),
+ (__compar_fn_t)compare_node_according_to_code_range);
+
+#endif
+
+ /* Insertion des noeuds dans l'ordre prévu */
+
+ last_free_state = 257;
+ full_size = last_free_state + 257;
+ global_usage = create_bit_field(full_size, false);
+
+#ifndef NDEBUG
+
+ pops[0] = 0;
+ pops[1] = 0;
+ pops[2] = 0;
+
+ bsum = 0;
+
+#endif
+
+ usage = create_bit_field(257, false);
+
+ for (i = 0; i < backend->nodes_used; i++)
+ {
+#ifdef __SORT_BEFORE_BITMASK
+ node = list[i];
+#else
+ node = backend->nodes + i;
+#endif
+
+ /* Préparation du masque du noeud */
+
+ truncate_bit_field(&usage, 257);
+
+ reset_all_in_bit_field(usage);
+
+ set_in_bit_field(usage, 0, 1);
+
+#ifndef NDEBUG
+ pops[0]++;
+#endif
+
+ highest = 0;
+
+ for (iter = node->child; iter != NULL; iter = iter->sibling)
+ {
+ set_in_bit_field(usage, iter->code, 1);
+
+#ifndef NDEBUG
+ pops[0]++;
+#endif
+
+ if (iter->code > highest)
+ highest = iter->code;
+
+ }
+
+#ifndef NDEBUG
+ pops[1] += popcount_for_bit_field(usage);
+#endif
+
+ assert(popcount_for_bit_field(usage) == (node->children_count + 1));
+
+ truncate_bit_field(&usage, ++highest);
+
+ /* Recherche d'une position idéale */
+
+ if (i == 0)
+ {
+ first_freedom_word = 0;
+ free_state = 0;
+ }
+
+ else
+ free_state = find_interleaving_index_for_acism(global_usage, usage, &first_freedom_word);
+
+ /* Suivi global */
+
+ assert(!test_in_bit_field(global_usage, free_state));
+
+ or_bit_field_at(global_usage, usage, free_state);
+
+#ifndef NDEBUG
+ bsum += node->children_count + 1;
+ assert(popcount_for_bit_field(global_usage) == bsum);
+#endif
+
+ node->state_index = free_state;
+
+ if ((free_state + 257) > last_free_state)
+ {
+ last_free_state += 257;
+ full_size += 257;
+ resize_bit_field(&global_usage, full_size);
+ }
+
+ }
+
+ /* Sotie encadrée */
+
+#ifndef NDEBUG
+
+ pops[2] = popcount_for_bit_field(global_usage);
+
+ assert(pops[0] == pops[1]);
+ assert(pops[0] == pops[2]);
+
+#endif
+
+ backend->bitmap_usage = global_usage;
+
+ delete_bit_field(usage);
+
+#ifdef __SORT_BEFORE_BITMASK
+ free(list);
+#endif
+
+}
+
+
+#else
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Organise la convertion de l'arborescence en tableau. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_prepare_interleave_array(GAcismBackend *backend)
+{
+ size_t max_pos; /* Tête de lecture finale */
+ acism_trie_node_t **stack; /* Pile des noeuds à traiter */
+ size_t last_free_state; /* Dernier emplacement dispo. */
+ size_t full_size; /* Cartographie entière */
+ bitfield_t *global_usage; /* Cartographie des usages */
+ bitfield_t *usage; /* Cartographie locale */
+ size_t rd_pos; /* Tête de lecture */
+ size_t wr_pos; /* Tête d'écriture */
+ size_t first_freedom_word; /* Premier mot avec des dispos.*/
+ acism_trie_node_t *node; /* Noeud à traiter */
+ acism_trie_node_t *iter; /* Boucle de parcours */
+ size_t free_state; /* Emplacement libre trouvé */
+
+ max_pos = backend->nodes_used;
+
+ stack = calloc(max_pos, sizeof(acism_trie_node_t *));
+
+ last_free_state = 257;
+ full_size = last_free_state + 257;
+ global_usage = create_bit_field(full_size, false);
+
+ usage = create_bit_field(257, false);
+
+ /* Initialisation du parcours */
+
+ rd_pos = 0;
+ wr_pos = 0;
+
+ stack[wr_pos++] = &backend->nodes[0];
+
+ assert(backend->nodes->sibling == NULL);
+
+ /* Traitement manuel de démarrage pour éviter une condition en [0] */
+
+ set_in_bit_field(global_usage, 0, 1);
+
+ for (iter = backend->nodes->child; iter != NULL; iter = iter->sibling)
+ {
+ set_in_bit_field(global_usage, iter->code, 1);
+ stack[wr_pos++] = iter;
+ }
+
+ rd_pos++;
+
+ first_freedom_word = 0;
+
+ /* Suivi des liens déjà en place */
+
+ while (rd_pos < max_pos)
+ {
+ assert(rd_pos < wr_pos);
+
+ node = stack[rd_pos++];
+
+ /* Préparation du masque du noeud et inscription des noeuds suivants */
+
+ reset_all_in_bit_field(usage);
+
+ set_in_bit_field(usage, 0, 1);
+
+ for (iter = node->child; iter != NULL; iter = iter->sibling)
+ {
+ set_in_bit_field(usage, iter->code, 1);
+ stack[wr_pos++] = iter;
+ }
+
+ assert(popcount_for_bit_field(usage) == (node->children_count + 1));
+
+ /* Recherche d'une position idéale */
+
+ free_state = find_interleaving_index_for_acism(global_usage, usage, &first_freedom_word);
+
+ /* Suivi global */
+
+ assert(!test_in_bit_field(global_usage, free_state));
+
+ or_bit_field_at(global_usage, usage, free_state);
+
+ node->state_index = free_state;
+
+ if ((free_state + 257) > last_free_state)
+ {
+ last_free_state += 257;
+ full_size += 257;
+ resize_bit_field(&global_usage, full_size);
+ }
+
+ }
+
+ /* Sotie encadrée */
+
+ backend->bitmap_usage = global_usage;
+
+ delete_bit_field(usage);
+
+ free(stack);
+
+}
+
+
+#endif
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Compresse l'arborescence dans un tableau de position. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_build_interleave_array(GAcismBackend *backend)
+{
+ size_t maxsize; /* Taille maximale du tableau */
+ size_t i; /* Boucle de parcours #1 */
+ acism_trie_node_t *node; /* Noeud à transcrire */
+ acism_state_t *base; /* Base d'une série de cellules*/
+ uint32_t *coverage; /* Couverture des inscriptions */
+ acism_source_t *source; /* Définition originelle */
+ acism_trie_node_t *iter; /* Sous-noeud à inscrire #2 */
+ acism_trie_node_t *child; /* Sous-noeud à inscrire #3 */
+ uint16_t offset; /* Décalage local */
+
+ maxsize = get_bit_field_size(backend->bitmap_usage);
+
+ backend->states = calloc(maxsize, sizeof(acism_state_t));
+ backend->coverages = calloc(maxsize, 2 * sizeof(uint32_t));
+
+ for (i = 0; i < backend->nodes_used; i++)
+ {
+ node = &backend->nodes[i];
+ base = backend->states + node->state_index;
+
+ assert(base[0].code == 0);
+ assert(base[0].index == 0);
+
+ if (node->matched_atom > 0)
+ {
+ source = &backend->sources[node->matched_atom - 1];
+
+ base[0].match = 1;
+ base[0].single_source = source->coverage[SOURCE_COVERAGE_COUNT] == 1 ? 1 : 0;
+ base[0].atom_size = backend->sources[node->matched_atom - 1].len - 1;
+
+ coverage = &backend->coverages[node->state_index * 2];
+
+ coverage[SOURCE_COVERAGE_START] = source->coverage[SOURCE_COVERAGE_START];
+ coverage[SOURCE_COVERAGE_END] = coverage[SOURCE_COVERAGE_START] \
+ + source->coverage[SOURCE_COVERAGE_COUNT];
+
+ for (iter = node->parent->suffix_link; iter != NULL; iter = iter->suffix_link)
+ {
+ for (child = iter->child; child != NULL; child = child->sibling)
+ if (child->code == node->code && child->matched_atom > 0)
+ break;
+
+ if (child != NULL)
+ {
+ base[0].suffix = 1;
+ break;
+ }
+
+ }
+
+ }
+
+ base[0].index = i == 0 ? 0 : node->suffix_link->state_index;
+
+ for (child = node->child; child != NULL; child = child->sibling)
+ {
+ offset = child->code;
+
+ assert(base[offset].code == 0);
+ assert(base[offset].index == 0);
+
+ base[offset].code = child->code;
+ base[offset].index = child->state_index;
+
+ }
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Met en ordre les derniers détails avant un premier scan. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_acism_backend_warm_up(GAcismBackend *backend)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+#ifdef __USE_BYTE_FREQ
+
+ /**
+ * Attribue un identifiant unique pour chaque octet présent dans les
+ * motifs recherchés.
+ */
+ g_acism_backend_define_codes(backend);
+
+#endif
+
+ /**
+ * Construit une arborescence de lecture à partir des différents
+ * octets présents dans les motifs.
+ *
+ * Les couvertures des futurs tableaux de correspondances sont
+ * établies au passage, ouvrant la voie aux définitions d'identifiant
+ * pour les motifs enregistrés.
+ */
+ g_acism_backend_build_trie(backend);
+
+ /**
+ * Met en place les liens suivis en cas d'échec de correspondance
+ * lors de la lecture d'un octet supplémentaire.
+ */
+ g_acism_backend_build_suffix_links(backend);
+
+ /**
+ * Conversion de l'arborescence en tableau plat et compressé.
+ */
+
+ g_acism_backend_prepare_interleave_array(backend);
+
+ g_acism_backend_build_interleave_array(backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* tmp_id = identifiants temporaires vers le motif. [OUT] *
+* *
+* Description : Récupère les identifiants finaux pour un motif recherché. *
+* *
+* Retour : Identifiant constitué ou INVALID_PATTERN_ID en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static patid_t g_acism_backend_build_plain_pattern_id(const GAcismBackend *backend, const uint32_t tmp_id[2])
+{
+ patid_t result; /* Identifiant à retourner */
+ acism_source_t *source; /* Motif d'origine concerné */
+ acism_source_t *reference; /* Renvoi vers un même motif */
+
+ assert(tmp_id[0] < backend->sources_count);
+
+ /**
+ * L'indicateur tmp_id[1] n'est pas utilisé ici.
+ */
+
+ source = backend->sources + tmp_id[0];
+
+ if (source->is_first)
+ result = source->coverage[SOURCE_COVERAGE_START];
+
+ else
+ {
+ reference = backend->sources + source->first_source;
+
+ assert(source->index < reference->coverage[SOURCE_COVERAGE_COUNT]);
+
+ result = reference->coverage[SOURCE_COVERAGE_START] + source->index;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* *
+* Description : Détermine le nombre d'identifiants constitués. *
+* *
+* Retour : Quantité de gestionnaires de suivi à prévoir. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static size_t g_acism_backend_count_plain_pattern_ids(const GAcismBackend *backend)
+{
+ size_t result; /* Quantité à retourner */
+
+ result = backend->sources_count;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_run_scan(const GAcismBackend *backend, GScanContext *context)
+{
+ GBinContent *content; /* Contenu binaire manipulé */
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+#ifdef __USE_BYTE_FREQ
+ acism_code_t codes_for_bytes[256]; /* Copie des codes d'accès */
+#endif
+ acism_state_t *root; /* Racine de l'arborescence */
+ uint32_t *coverages; /* Bornes de suivi de positions*/
+ unsigned int state; /* Tête de lecture courante */
+ phys_t i; /* Boucle de parcours #1 */
+ acism_code_t code; /* Code du caractère courant */
+ unsigned int next; /* Prochaine tête à valider */
+ acism_state_t next_state; /* Prochaine tête à valider */
+ uint32_t k; /* Boucle de parcours #2 */
+ uint32_t final_k; /* Dernier indice à traiter */
+ unsigned int iter; /* Boucle de parcours #3 */
+ acism_state_t test_state; /* Test de validité alternative*/
+ acism_state_t sub_state; /* Test de validité alternative*/
+
+ content = g_scan_context_get_content(context);
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ /* Suivi via l'arborescence aplatie */
+
+#ifdef __USE_BYTE_FREQ
+ memcpy(&codes_for_bytes, backend->codes_for_bytes, 256 * sizeof(acism_code_t));
+#endif
+
+ root = backend->states;
+ if (root == NULL) goto done;
+
+ coverages = backend->coverages;
+
+ state = ROOT_STATE_INDEX;
+
+ for (i = 0; i < dlen; i++)
+ {
+#ifdef __USE_BYTE_FREQ
+ code = codes_for_bytes[data[i]];
+#else
+ code = 1 + data[i];
+#endif
+
+ /* Déplacement de la tête de lecture dans l'arborescence */
+
+ retry:
+
+ next = state + code;
+
+ if (root[next].code == code)
+ {
+ next = root[next].index;
+ next_state = root[next];
+ }
+
+ else if (state != ROOT_STATE_INDEX)
+ {
+ state = root[state].index;
+ goto retry;
+ }
+
+ else
+ continue;
+
+ /* Remontée d'éventuels résultats */
+
+ if (next_state.match)
+ {
+ k = coverages[next * 2 + SOURCE_COVERAGE_START];
+
+ if (next_state.single_source)
+ g_scan_context_store_atom_match_end(context, k, i);
+ //g_umem_slice_put_uint64(matches[0/*k*/], i - next_state.atom_size);
+
+ else
+ {
+ final_k = coverages[next * 2 + SOURCE_COVERAGE_END];
+
+ for (; k < final_k; k++)
+ g_scan_context_store_atom_match_end(context, k, i);
+ //g_umem_slice_put_uint64(matches[0/*k*/], i - next_state.atom_size);
+
+ }
+
+ if (next_state.suffix)
+ {
+ for (iter = root[state].index; ; iter = root[iter].index)
+ {
+ test_state = root[iter + code];
+
+ if (test_state.code == code)
+ {
+ sub_state = root[test_state.index];
+
+ if (sub_state.match)
+ {
+ assert(sub_state.atom_size < next_state.atom_size);
+
+ k = coverages[test_state.index * 2 + SOURCE_COVERAGE_START];
+
+ if (sub_state.single_source)
+ g_scan_context_store_atom_match_end(context, k, i);
+ //g_umem_slice_put_uint64(matches[0/*k*/], i - sub_state.atom_size);
+
+ else
+ {
+ final_k = coverages[test_state.index * 2 + SOURCE_COVERAGE_END];
+
+ for (; k < final_k; k++)
+ g_scan_context_store_atom_match_end(context, k, i);
+ //g_umem_slice_put_uint64(matches[0/*k*/], i - sub_state.atom_size);
+
+ }
+
+ }
+
+ }
+
+ if (iter == ROOT_STATE_INDEX)
+ break;
+
+ }
+
+ }
+
+
+ }
+
+ /* Bascule au caractère suivant */
+
+ state = next;
+
+ }
+
+ done:
+
+ g_object_unref(G_OBJECT(content));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'arborescence à traiter. *
+* level = profondeur courante. *
+* *
+* Description : Affiche les caractéristques d'un noeud et de ses enfants. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void visit_and_output_node(const acism_trie_node_t *node, unsigned int level)
+{
+ unsigned int i; /* Boucle de parcours #1 */
+ acism_trie_node_t *iter; /* Boucle de parcours #2 */
+
+ for (i = 0; i < level; i++)
+ printf(" ");
+
+ printf(" '%c' (code=%hhu)\n", node->data, node->code);
+
+ for (iter = node->child; iter != NULL; iter = iter->sibling)
+ visit_and_output_node(iter, level + 1);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Imprime quelques faits quant aux éléments mis en place. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_acism_backend_output_stats(const GAcismBackend *backend)
+{
+ printf("nodes used: %zu\n", backend->nodes_used);
+
+ printf("full_size: %zu (real: %zu)\n",
+ get_bit_field_size(backend->bitmap_usage),
+ popcount_for_bit_field(backend->bitmap_usage));
+
+ visit_and_output_node(backend->nodes, 0);
+
+}
diff --git a/src/analysis/scan/patterns/backends/acism.h b/src/analysis/scan/patterns/backends/acism.h
new file mode 100644
index 0000000..837022a
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/acism.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * acism.h - prototypes pour la méthode de recherche basée sur l'algorithme Aho-Corasick Interleaved State-transition Matrix
+ *
+ * Copyright (C) 2022 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_PATTERNS_BACKENDS_ACISM_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKENDS_ACISM_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "../backend.h"
+
+
+
+#define G_TYPE_ACISM_BACKEND g_acism_backend_get_type()
+#define G_ACISM_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_ACISM_BACKEND, GAcismBackend))
+#define G_IS_ACISM_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_ACISM_BACKEND))
+#define G_ACISM_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ACISM_BACKEND, GAcismBackendClass))
+#define G_IS_ACISM_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ACISM_BACKEND))
+#define G_ACISM_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ACISM_BACKEND, GAcismBackendClass))
+
+
+/* Méthode de recherche basée sur l'algorithme Acism (instance) */
+typedef struct _GAcismBackend GAcismBackend;
+
+/* Méthode de recherche basée sur l'algorithme Acism (classe) */
+typedef struct _GAcismBackendClass GAcismBackendClass;
+
+
+/* Indique le type défini pour un moteur de recherche pour données. */
+GType g_acism_backend_get_type(void);
+
+/* Crée une méthode de recherche basée sur l'algorithme Acism. */
+GEngineBackend *g_acism_backend_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKENDS_ACISM_H */
diff --git a/src/analysis/scan/patterns/backends/bitap-int.h b/src/analysis/scan/patterns/backends/bitap-int.h
new file mode 100644
index 0000000..ea739b4
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/bitap-int.h
@@ -0,0 +1,132 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * bitap-int.h - prototypes internes pour la méthode de recherche basée sur l'algorithme Bitap
+ *
+ * Copyright (C) 2022 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_PATTERNS_BACKENDS_BITAP_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKENDS_BITAP_INT_H
+
+
+#include "bitap.h"
+
+
+#include <immintrin.h>
+
+
+#include "../backend-int.h"
+#include "../../../../common/cpu.h"
+#include "../../../../../config.h"
+
+
+
+#define BITAP_ATOM_SIZE 7
+
+
+#ifdef HAVE_AVX2
+
+/* Suivi d'un groupe de chaînes */
+typedef struct _grouped_strings_avx2_t
+{
+ __m256i pattern_masks[256]; /* Programmation de détections */
+ __m256i found_masks; /* Masques multiples d'alerte */
+
+ __m256i R; /* Résultats courants */
+
+ size_t m[32]; /* Taille des chaînes */
+
+ patid_t found_id[32]; /* Indice des résultats */
+
+ size_t available; /* Nombre de places disponibles*/
+ size_t used; /* Quantité de places utilisées*/
+
+} grouped_strings_avx2_t;
+
+/* Suivi de l'ensemble de chaînes */
+typedef struct _group_manager_avx2_t
+{
+ grouped_strings_avx2_t **strings_8; /* Chaînes de taille 8 max */
+ size_t count_8; /* Quantité de ces chaînes */
+
+} group_manager_avx2_t;
+
+#endif
+
+#ifdef HAVE_AVX512_F
+
+/* Suivi d'un groupe de chaînes */
+typedef struct _grouped_strings_avx512_t
+{
+ __m512i pattern_masks[256]; /* Programmation de détections */
+ __m512i found_masks; /* Masques multiples d'alerte */
+
+ __m512i R; /* Résultats courants */
+
+ size_t m[64]; /* Taille des chaînes */
+
+ patid_t found_id[64]; /* Indice des résultats */
+
+ size_t used; /* Quantité de places utilisées*/
+ size_t available; /* Nombre de places disponibles*/
+
+} grouped_strings_avx512_t;
+
+/* Suivi de l'ensemble de chaînes */
+typedef struct _group_manager_avx512_t
+{
+ grouped_strings_avx512_t **strings_8; /* Chaînes de taille 8 max */
+ size_t count_8; /* Quantité de ces chaînes */
+
+} group_manager_avx512_t;
+
+#endif
+
+
+/* Méthode de recherche basée sur l'algorithme Bitap (instance) */
+struct _GBitapBackend
+{
+ GEngineBackend parent; /* A laisser en premier */
+
+ CPUSMIDFeature optimization; /* Mode de calculs */
+
+#if defined HAVE_AVX2 || defined HAVE_AVX512_F
+ union
+ {
+# ifdef HAVE_AVX2
+ group_manager_avx2_t manager_avx2; /* Gestionnaire pour AVX2 */
+# endif
+# ifdef HAVE_AVX512_F
+ group_manager_avx512_t manager_avx512;/* Gestionnaire pour AVX-512 */
+# endif
+ };
+#endif
+
+};
+
+/* Méthode de recherche basée sur l'algorithme Bitap (classe) */
+struct _GBitapBackendClass
+{
+ GEngineBackendClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKENDS_BITAP_INT_H */
diff --git a/src/analysis/scan/patterns/backends/bitap.c b/src/analysis/scan/patterns/backends/bitap.c
new file mode 100644
index 0000000..af50c6d
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/bitap.c
@@ -0,0 +1,2785 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * bitap.c - méthode de recherche basée sur l'algorithme Bitap
+ *
+ * Copyright (C) 2022 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 "bitap.h"
+
+
+#include <alloca.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sched.h>
+
+
+#include "bitap-int.h"
+#include "../../../../core/logs.h"
+//#include "../../matches/bytes.h"
+
+
+
+/* ---------------------- IMPLANTATION D'UNE NOUVELLE APPROCHE ---------------------- */
+
+
+/* Initialise la classe des méthodes basée sur Bitmap. */
+static void g_bitap_backend_class_init(GBitapBackendClass *);
+
+/* Initialise une instance de méthodes basée sur Bitmap. */
+static void g_bitap_backend_init(GBitapBackend *);
+
+/* Supprime toutes les références externes. */
+static void g_bitap_backend_dispose(GBitapBackend *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_bitap_backend_finalize(GBitapBackend *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Indique la taille maximale des suites d'octets recherchées. */
+size_t g_bitap_backend_get_atom_max_size(const GBitapBackend *);
+
+/* Inscrit dans le moteur une chaîne de caractères à rechercher. */
+static patid_t g_bitap_backend_enroll_plain_pattern(GBitapBackend *, GScanContext *, const uint8_t *, size_t);
+
+/* Parcours un contenu binaire à la recherche de motifs. */
+static void g_bitap_backend_run_scan(const GBitapBackend *, GScanContext *);
+
+/* Imprime quelques faits quant aux éléments mis en place. */
+static void g_bitap_backend_output_stats(const GBitapBackend *);
+
+
+
+/* ---------------------- OPTIMISATIONS POUR ARCHITECTURE AVX2 ---------------------- */
+
+
+#ifdef HAVE_AVX2
+
+/* Indique la valeur portée par une expression rationnelle. */
+static void extend_grouped_strings_avx2(grouped_strings_avx2_t ***, size_t *);
+
+/* Inscrit dans le moteur une chaîne de caractères à rechercher. */
+static patid_t enroll_plain_pattern_avx2(GBitapBackend *, GScanContext *, const bin_t *, size_t);
+
+/* Parcours un contenu binaire à la recherche de motifs. */
+static void run_scan_avx2(const GBitapBackend *, GScanContext *, const bin_t *, phys_t);
+
+#endif
+
+
+
+/* --------------------- OPTIMISATIONS POUR ARCHITECTURE AVX512 --------------------- */
+
+
+#ifdef HAVE_AVX512_F
+
+/* Indique la valeur portée par une expression rationnelle. */
+static void extend_grouped_strings_avx512(grouped_strings_avx512_t ***, size_t *);
+
+/* Inscrit dans le moteur une chaîne de caractères à rechercher. */
+static patid_t enroll_plain_pattern_avx512(GBitapBackend *, GScanContext *, const bin_t *, size_t);
+
+/* Parcours un contenu binaire à la recherche de motifs. */
+static void run_scan_avx512(const GBitapBackend *, GScanContext *, const bin_t *, phys_t);
+
+#endif
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLANTATION D'UNE NOUVELLE APPROCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour un moteur de recherche pour données. */
+G_DEFINE_TYPE(GBitapBackend, g_bitap_backend, G_TYPE_ENGINE_BACKEND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des méthodes basée sur Bitmap. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bitap_backend_class_init(GBitapBackendClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GEngineBackendClass *backend; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_bitap_backend_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_bitap_backend_finalize;
+
+ backend = G_ENGINE_BACKEND_CLASS(klass);
+
+ backend->get_max_size = (get_backend_atom_max_size_fc)g_bitap_backend_get_atom_max_size;
+ backend->enroll_plain = (enroll_plain_into_backend_fc)g_bitap_backend_enroll_plain_pattern;
+ backend->run_scan = (run_backend_scan_fc)g_bitap_backend_run_scan;
+ backend->output = (output_backend_stats_fc)g_bitap_backend_output_stats;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance à initialiser. *
+* *
+* Description : Initialise une instance de méthodes basée sur Bitmap. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bitap_backend_init(GBitapBackend *backend)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bitap_backend_dispose(GBitapBackend *backend)
+{
+ G_OBJECT_CLASS(g_bitap_backend_parent_class)->dispose(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bitap_backend_finalize(GBitapBackend *backend)
+{
+ G_OBJECT_CLASS(g_bitap_backend_parent_class)->finalize(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée une méthode de recherche basée sur l'algorithme Bitap. *
+* *
+* Retour : Méthode mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GEngineBackend *g_bitap_backend_new(void)
+{
+ GBitapBackend *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_BITAP_BACKEND, NULL);
+
+ return G_ENGINE_BACKEND(result);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Indique la taille maximale des suites d'octets recherchées. *
+* *
+* Retour : Valeur strictement positive. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_bitap_backend_get_atom_max_size(const GBitapBackend *backend)
+{
+ size_t result; /* Taille à faire connaître */
+
+ result = BITAP_ATOM_SIZE;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = contexte de l'analyse à mener. *
+* plain = chaîne de caractères classique à intégrer. *
+* len = taille de cette chaîne. *
+* *
+* Description : Inscrit dans le moteur une chaîne de caractères à rechercher.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static patid_t g_bitap_backend_enroll_plain_pattern(GBitapBackend *backend, GScanContext *context, const uint8_t *plain, size_t len)
+{
+ patid_t result; /* Identifiant à retourner */
+
+#ifdef HAVE_AVX512_F
+ if (0)
+ result = enroll_plain_pattern_avx512(backend, context, plain, len);
+ else
+#endif
+
+#ifdef HAVE_AVX2
+ if (0)
+ result = enroll_plain_pattern_avx2(backend, context, plain, len);
+ else
+#endif
+
+ result = INVALID_PATTERN_ID;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bitap_backend_run_scan(const GBitapBackend *backend, GScanContext *context)
+{
+ cpu_set_t old_mask; /* Cartographie des CPU #1 */
+ int ret; /* Bilan d'un appel */
+ unsigned int cpu; /* Processeur courant */
+ cpu_set_t new_mask; /* Cartographie des CPU #2 */
+ GBinContent *content; /* Contenu binaire manipulé */
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+
+ ret = sched_getaffinity(0, sizeof(cpu_set_t), &old_mask);
+
+ if (ret != 0)
+ {
+ LOG_ERROR_N("sched_getaffinity");
+ goto exit;
+ }
+
+ ret = getcpu(&cpu, NULL);
+
+ if (ret != 0)
+ {
+ LOG_ERROR_N("get_cpu");
+ goto exit;
+ }
+
+ CPU_ZERO(&new_mask);
+ CPU_SET(cpu, &new_mask);
+
+ ret = sched_setaffinity(0, sizeof(cpu_set_t), &new_mask);
+
+ if (ret != 0)
+ {
+ LOG_ERROR_N("sched_setaffinity");
+ goto exit;
+ }
+
+ content = g_scan_context_get_content(context);
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ assert(data != NULL);
+
+
+
+
+#ifdef HAVE_AVX512_F
+ if (0)
+ run_scan_avx512(backend, context, data, dlen);
+ else
+#endif
+
+#ifdef HAVE_AVX2
+ if (0)
+ run_scan_avx2(backend, context, data, dlen);
+ else
+#endif
+
+ ;
+
+ g_object_unref(G_OBJECT(content));
+
+ exit:
+
+ ;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Imprime quelques faits quant aux éléments mis en place. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bitap_backend_output_stats(const GBitapBackend *backend)
+{
+ printf("hello here!\n");
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* OPTIMISATIONS POUR ARCHITECTURE AVX2 */
+/* ---------------------------------------------------------------------------------- */
+
+
+/**
+ * Cf. https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#techs=AVX,AVX2
+ */
+
+#ifdef HAVE_AVX2
+
+/******************************************************************************
+* *
+* Paramètres : strings = ensemble de groupes constitués. [OUT] *
+* count = nombre de groupes courant. [OUT] *
+* *
+* Description : Indique la valeur portée par une expression rationnelle. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void extend_grouped_strings_avx2(grouped_strings_avx2_t ***strings, size_t *count)
+{
+ grouped_strings_avx2_t *new; /* Zone supplémentaire */
+ size_t i; /* Boucle de parcours */
+
+ /* Définition d'un nouvel élément vierge */
+
+ new = aligned_alloc(256, sizeof(grouped_strings_avx2_t));
+
+ for (i = 0; i < 256; i++)
+ new->pattern_masks[i] = _mm256_set1_epi8(~0);
+
+ new->found_masks = _mm256_set1_epi8(~0);
+
+ new->R = _mm256_set1_epi8(~1);
+
+ for (i = 0; i < 32; i++)
+ {
+ new->m[i] = 0;
+
+ new->found_id[i] = INVALID_PATTERN_ID;
+
+ }
+
+ new->available = 32;
+ new->used = 0;
+
+ /* Inscription */
+
+ *strings = realloc(*strings, ++(*count) * sizeof(grouped_strings_avx2_t *));
+
+ (*strings)[*count - 1] = new;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = contexte de l'analyse à mener. *
+* plain = chaîne de caractères classique à intégrer. *
+* plen = taille de cette chaîne. *
+* *
+* Description : Inscrit dans le moteur une chaîne de caractères à rechercher.*
+* *
+* Retour : Indice de résultats pour le motif. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static patid_t enroll_plain_pattern_avx2(GBitapBackend *backend, GScanContext *context, const bin_t *plain, size_t plen)
+{
+ patid_t result; /* Identifiant à retourner */
+ grouped_strings_avx2_t ***strings; /* Groupe de chaînes visé */
+ size_t *count; /* Taille de ce groupe */
+ grouped_strings_avx2_t *last; /* Dernier groupe à remplir */
+ size_t n; /* Indice dans le groupe */
+ size_t i; /* Boucle de parcours */
+ __m256i *letter; /* Lettre à marquer */
+
+ /* Sélection du groupe de travail adéquat */
+
+ strings = &backend->manager_avx2.strings_8;
+ count = &backend->manager_avx2.count_8;
+
+ /* Préparation de la place nécessaire */
+
+ if (*count == 0)
+ {
+ extend_grouped_strings_avx2(strings, count);
+
+ last = (*strings)[0];
+
+ }
+
+ else
+ {
+ last = (*strings)[*count - 1];
+
+ if (last->used == last->available)
+ {
+ extend_grouped_strings_avx2(strings, count);
+ last = (*strings)[*count - 1];
+ }
+
+ }
+
+ /* Intégration d'une nouvelle chaîne */
+
+ n = last->used++;
+
+ last->m[n] = plen;
+
+ result = 0; // FIXME g_scan_context_get_new_pattern_id(context);
+
+ last->found_id[n] = result;
+
+ ((uint8_t *)&last->found_masks)[n] = (1 << plen);
+
+ for (i = 0; i < plen; i++)
+ {
+ letter = last->pattern_masks + plain[i];
+ ((uint8_t *)letter)[n] &= ~(1 << i);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* data = données à analyser. *
+* dlen = quantité de ces données. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void run_scan_avx2(const GBitapBackend *backend, GScanContext *context, const bin_t *data, phys_t dlen)
+{
+ const group_manager_avx2_t *manager; /* Accès simplifié */
+
+ register __m256i zero asm("ymm11"); /* Constante 0 sur 256 bits */
+ size_t k; /* Boucle de parcours #1 */
+ grouped_strings_avx2_t group; /* Copie pour accès locaux */
+
+ register __m256i R asm("ymm12"); /* Résultats courants */
+ register __m256i found_masks asm("ymm10"); /* Vérifications accélérées */
+
+ //__m256i pre_shift_mask; /* Préparation de décalage */
+ //phys_t i; /* Boucle de parcours #2 */
+
+
+
+
+ const bin_t *iter;
+ const bin_t *maxiter;
+ //phys_t i; /* Boucle de parcours #2 */
+
+ volatile register __m256i xxxx; /* Test de correspondances */
+
+
+ __m256i test; /* Test de correspondances */
+ __m256i test2; /* Test de correspondances */
+ __m256i status; /* Statut d'une comparaison */
+
+ int masks[10];
+
+ int mask; /* Masque d'accès rapide */
+ size_t j; /* Boucle de parcours #3 */
+
+
+ int ret;
+
+ //return;
+
+ /* Initialisations diverses */
+
+ manager = &backend->manager_avx2;
+
+ zero = _mm256_set1_epi16(0);
+
+ asm volatile ("nop;nop;nop;nop;nop;nop;nop;nop;nop;");
+
+ xxxx = _mm256_set1_epi8(~1);
+
+ asm volatile ("nop;nop;nop;nop;nop;nop;nop;nop;nop;");
+
+ /* Recherches des chaînes de moins de 8 caractères */
+
+ printf(" --- manager->count_8: %zu\n", manager->count_8);
+
+ ret = 0;
+
+ for (k = 0; k < manager->count_8; k++)
+ {
+ memcpy(&group, manager->strings_8[k], sizeof(grouped_strings_avx2_t));
+
+ //printf(" --- group.used: %zu\n", group.used);
+
+
+ asm volatile
+ (
+ /*
+ * R = _mm256_set1_epi8(~1);
+ *
+ */
+
+ "movabs $0xfefefefefefefefe, %%rax ; "
+ "vpbroadcastq %%rax, %[STATE] ; "
+
+ /*
+ *
+ */
+
+ "vmovdqa %[FOUND_SRC], %[FOUND_DST] ; "
+
+ : [STATE] "=v"(R),
+ [FOUND_DST] "=v"(found_masks)
+ : [FOUND_SRC] "m"(group.found_masks)
+ : "memory", "rax"
+
+ );
+
+
+
+
+ //pre_shift_mask = _mm256_set1_epi8(0xef);
+
+ maxiter = data + dlen;
+
+
+
+ for (iter = data; (iter + 10) < maxiter; iter += 10)
+ {
+
+ //printf("--- %llx <-> %c\n", (unsigned long long)(iter - data), *iter);
+
+
+ asm volatile
+ (
+#if 0
+
+ /*
+ * R = _mm256_or_si256(R, group.pattern_masks[data[i]]);
+ *
+ * Latency : 1-9
+ * Throughput : 0.5
+ * #Uops : 1-2
+ * Port Usage : 1*p015+1*p23
+ *
+ */
+
+ "vpor %[PATTERN], %[STATE], %[STATE] ; "
+
+#else
+
+ /*
+ * %ymm = group.pattern_masks[data[i]];
+ *
+ * Latency : 5-8
+ * Throughput : 0.5
+ * #Uops : 1
+ * Port Usage : 1*p23
+ *
+ */
+
+ "vmovdqa %[PATTERN0], %%ymm0 ; "
+ "vmovdqa %[PATTERN1], %%ymm1 ; "
+ "vmovdqa %[PATTERN2], %%ymm2 ; "
+ "vmovdqa %[PATTERN3], %%ymm3 ; "
+ "vmovdqa %[PATTERN4], %%ymm4 ; "
+ "vmovdqa %[PATTERN5], %%ymm5 ; "
+ "vmovdqa %[PATTERN6], %%ymm6 ; "
+ "vmovdqa %[PATTERN7], %%ymm7 ; "
+ "vmovdqa %[PATTERN7], %%ymm8 ; "
+ "vmovdqa %[PATTERN7], %%ymm9 ; "
+
+ /*
+ * R = _mm256_or_si256(R, %ymm);
+ *
+ * Latency : 1
+ * Throughput : 0.33
+ * #Uops : 1
+ * Port Usage : 1*p015
+ *
+ */
+
+ "vpor %%ymm0, %[STATE], %[STATE] ; "
+
+#endif
+
+ /*
+ * R = _mm256_add_epi8(R, R);
+ *
+ * Latency : 1
+ * Throughput : 0.3
+ * #Uops : 1
+ * Port Usage : 1*p015
+ *
+ */
+
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ /*
+ * test = _mm256_and_si256(R, group.found_masks);
+ *
+ * Latency : 1
+ * Throughput : 0.33
+ * #Uops : 1
+ * Port Usage : 1*p015
+ *
+ */
+
+ "vpand %[FOUND], %[STATE], %%ymm0 ; "
+
+ /* Déroulemets... */
+
+ "vpor %%ymm1, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm2, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm3, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm4, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm5, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm6, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm7, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm8, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpor %%ymm9, %[STATE], %[STATE] ; "
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ "vpand %[FOUND], %[STATE], %%ymm1 ; "
+ "vpand %[FOUND], %[STATE], %%ymm2 ; "
+ "vpand %[FOUND], %[STATE], %%ymm3 ; "
+ "vpand %[FOUND], %[STATE], %%ymm4 ; "
+ "vpand %[FOUND], %[STATE], %%ymm5 ; "
+ "vpand %[FOUND], %[STATE], %%ymm6 ; "
+ "vpand %[FOUND], %[STATE], %%ymm7 ; "
+ "vpand %[FOUND], %[STATE], %%ymm8 ; "
+ "vpand %[FOUND], %[STATE], %%ymm9 ; "
+
+
+
+
+
+ /*
+ * status = _mm256_cmpeq_epi8(test, zero);
+ *
+ * Latency : 1
+ * Throughput : 0.5
+ * #Uops : 1
+ * Port Usage : 1*p01
+ *
+ */
+
+ "vpcmpeqb %%ymm0, %[NUL], %%ymm0 ; "
+
+ /*
+ * mask = _mm256_movemask_epi8(status);
+ *
+ * Latency : <5
+ * Throughput : 1
+ * #Uops : 1
+ * Port Usage : 1*p0
+ *
+ */
+
+ "vpmovmskb %%ymm0, %[MASK0] ; "
+
+
+
+
+
+ "vpcmpeqb %%ymm1, %[NUL], %%ymm1 ; "
+ "vpcmpeqb %%ymm2, %[NUL], %%ymm2 ; "
+ "vpcmpeqb %%ymm3, %[NUL], %%ymm3 ; "
+ "vpcmpeqb %%ymm4, %[NUL], %%ymm4 ; "
+ "vpcmpeqb %%ymm5, %[NUL], %%ymm5 ; "
+ "vpcmpeqb %%ymm6, %[NUL], %%ymm6 ; "
+ "vpcmpeqb %%ymm7, %[NUL], %%ymm7 ; "
+ "vpcmpeqb %%ymm8, %[NUL], %%ymm8 ; "
+ "vpcmpeqb %%ymm9, %[NUL], %%ymm9 ; "
+
+
+ "vpmovmskb %%ymm1, %[MASK1] ; "
+ "vpmovmskb %%ymm2, %[MASK2] ; "
+ "vpmovmskb %%ymm3, %[MASK3] ; "
+ "vpmovmskb %%ymm4, %[MASK4] ; "
+ "vpmovmskb %%ymm5, %[MASK5] ; "
+ "vpmovmskb %%ymm6, %[MASK6] ; "
+ "vpmovmskb %%ymm7, %[MASK7] ; "
+ "vpmovmskb %%ymm8, %[MASK8] ; "
+ "vpmovmskb %%ymm9, %[MASK9] ; "
+
+
+
+
+
+
+
+
+
+
+ //"vmovdqa %%ymm7, %[OUTPUT] ; "
+
+ //"vmovdqa %%ymm8, %[OUTPUT2] ; "
+
+ : [STATE] "+v"(R),
+ [OUTPUT] "=v"(test),
+ [OUTPUT2] "=v"(test2),
+ [MASK0] "=r"(mask),
+ [MASK1] "=r"(mask),
+ [MASK2] "=r"(mask),
+ [MASK3] "=r"(mask),
+ [MASK4] "=r"(mask),
+ [MASK5] "=r"(mask),
+ [MASK6] "=r"(mask),
+ [MASK7] "=r"(mask),
+ [MASK8] "=r"(mask),
+ [MASK9] "=r"(mask),
+ [NUL] "+v"(zero)
+ : [PATTERN0] "m"(group./*manager->strings_8[k]->*/pattern_masks[*iter]),
+ [PATTERN1] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 1)]),
+ [PATTERN2] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 2)]),
+ [PATTERN3] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 3)]),
+ [PATTERN4] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 4)]),
+ [PATTERN5] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 5)]),
+ [PATTERN6] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 6)]),
+ [PATTERN7] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 7)]),
+ [PATTERN8] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 8)]),
+ [PATTERN9] "m"(group./*manager->strings_8[k]->*/pattern_masks[*(iter + 9)]),
+ [FOUND] "v"(found_masks)
+ : "memory", "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7", "ymm8", "ymm9"
+
+ );
+
+
+ /*
+ printf(" test: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx ... %02hhx %02hhx %02hhx %02hhx\n",
+ ((uint8_t *)&test)[0],
+ ((uint8_t *)&test)[1],
+ ((uint8_t *)&test)[2],
+ ((uint8_t *)&test)[3],
+ ((uint8_t *)&test)[4],
+ ((uint8_t *)&test)[5],
+ ((uint8_t *)&test)[6],
+ ((uint8_t *)&test)[7],
+ ((uint8_t *)&test)[16],
+ ((uint8_t *)&test)[17],
+ ((uint8_t *)&test)[18],
+ ((uint8_t *)&test)[19]);
+
+ printf(" test2: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx ... %02hhx %02hhx %02hhx %02hhx\n",
+ ((uint8_t *)&test2)[0],
+ ((uint8_t *)&test2)[1],
+ ((uint8_t *)&test2)[2],
+ ((uint8_t *)&test2)[3],
+ ((uint8_t *)&test2)[4],
+ ((uint8_t *)&test2)[5],
+ ((uint8_t *)&test2)[6],
+ ((uint8_t *)&test2)[7],
+ ((uint8_t *)&test2)[16],
+ ((uint8_t *)&test2)[17],
+ ((uint8_t *)&test2)[18],
+ ((uint8_t *)&test2)[19]);
+ */
+
+#if 0
+ //printf(" > %c\n", data[i]);
+
+ R = _mm256_or_si256(R, group.pattern_masks[*iter]);
+
+ //printf("group pattern: %hhx\n", *((uint8_t *)&group.pattern_masks[data[i]]));
+
+ //printf("R: %hhx\n", *((uint8_t *)&R));
+
+ //R = _mm256_and_si256(R, pre_shift_mask);
+
+ //printf("R after and: %hhx\n", *((uint8_t *)&R));
+
+ R = _mm256_add_epi8(R, R);
+ //R = _mm256_slli_si256(R, 1);
+
+ //printf("R after shift: %hhx\n", *((uint8_t *)&R));
+
+ test = _mm256_and_si256(R, group.found_masks);
+
+#if 1
+ status = _mm256_cmpeq_epi8(test, zero);
+
+ mask = _mm256_movemask_epi8(status);
+#else
+ //mask = _mm256_movemask_epi8(test) ^ 0xffffffff;
+ mask = _mm256_movemask_epi8(test);
+#endif
+
+
+#endif
+
+
+ //printf(" mask : %x\n", mask);
+
+ if (mask != 0)
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == 1)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ /** TODO : update call
+ g_scan_context_register_atom_match(context,
+ group.found_id[j],
+ (iter - data) + 1 - group.m[j]);
+ **/
+
+ }
+
+ mask >>= 1;
+
+ }
+
+ }
+
+
+
+
+
+#if 0
+ for (; iter < maxiter; iter++)
+ {
+
+ //printf("--- %llx <-> %c\n", (unsigned long long)(iter - data), *iter);
+
+
+ asm volatile
+ (
+ /*
+ * R = _mm256_or_si256(R, group.pattern_masks[data[i]]);
+ *
+ * Latency : 1
+ * Throughput : 0.33
+ * #Uops : 1
+ * Port Usage : 1*p015
+ *
+ */
+
+ "vpor %[PATTERN], %[STATE], %[STATE] ; "
+
+ /*
+ * R = _mm256_add_epi8(R, R);
+ *
+ * Latency : 1
+ * Throughput : 0.3
+ * #Uops : 1
+ * Port Usage : 1*p015
+ *
+ */
+
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ /*
+ * test = _mm256_and_si256(R, group.found_masks);
+ *
+ * Latency : 1
+ * Throughput : 0.33
+ * #Uops : 1
+ * Port Usage : 1*p015
+ *
+ */
+
+ "vpand %[FOUND], %[STATE], %%ymm7 ; "
+
+ /*
+ * status = _mm256_cmpeq_epi8(test, zero);
+ *
+ * Latency : 1
+ * Throughput : 0.5
+ * #Uops : 1
+ * Port Usage : 1*p01
+ *
+ */
+
+ "vpcmpeqb %%ymm7, %[NUL], %%ymm8 ; "
+
+ /*
+ * mask = _mm256_movemask_epi8(status);
+ *
+ * Latency : <5
+ * Throughput : 1
+ * #Uops : 1
+ * Port Usage : 1*p0
+ *
+ */
+
+ "vpmovmskb %%ymm8, %[MASK0] ; "
+
+
+ //"vmovdqa %%ymm7, %[OUTPUT] ; "
+
+ //"vmovdqa %%ymm8, %[OUTPUT2] ; "
+
+ : [STATE] "+v"(R),
+ [OUTPUT] "=v"(test),
+ [OUTPUT2] "=v"(test2),
+ [MASK0] "=r"(mask),
+ [NUL] "+v"(zero)
+ : [PATTERN] "m"(group./*manager->strings_8[k]->*/pattern_masks[*iter]),
+ [FOUND] "v"(found_masks)
+ : "memory", "ymm7", "ymm8"
+
+ );
+
+
+ /*
+ printf(" test: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx ... %02hhx %02hhx %02hhx %02hhx\n",
+ ((uint8_t *)&test)[0],
+ ((uint8_t *)&test)[1],
+ ((uint8_t *)&test)[2],
+ ((uint8_t *)&test)[3],
+ ((uint8_t *)&test)[4],
+ ((uint8_t *)&test)[5],
+ ((uint8_t *)&test)[6],
+ ((uint8_t *)&test)[7],
+ ((uint8_t *)&test)[16],
+ ((uint8_t *)&test)[17],
+ ((uint8_t *)&test)[18],
+ ((uint8_t *)&test)[19]);
+
+ printf(" test2: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx ... %02hhx %02hhx %02hhx %02hhx\n",
+ ((uint8_t *)&test2)[0],
+ ((uint8_t *)&test2)[1],
+ ((uint8_t *)&test2)[2],
+ ((uint8_t *)&test2)[3],
+ ((uint8_t *)&test2)[4],
+ ((uint8_t *)&test2)[5],
+ ((uint8_t *)&test2)[6],
+ ((uint8_t *)&test2)[7],
+ ((uint8_t *)&test2)[16],
+ ((uint8_t *)&test2)[17],
+ ((uint8_t *)&test2)[18],
+ ((uint8_t *)&test2)[19]);
+ */
+
+#if 0
+ //printf(" > %c\n", data[i]);
+
+ R = _mm256_or_si256(R, group.pattern_masks[*iter]);
+
+ //printf("group pattern: %hhx\n", *((uint8_t *)&group.pattern_masks[data[i]]));
+
+ //printf("R: %hhx\n", *((uint8_t *)&R));
+
+ //R = _mm256_and_si256(R, pre_shift_mask);
+
+ //printf("R after and: %hhx\n", *((uint8_t *)&R));
+
+ R = _mm256_add_epi8(R, R);
+ //R = _mm256_slli_si256(R, 1);
+
+ //printf("R after shift: %hhx\n", *((uint8_t *)&R));
+
+ test = _mm256_and_si256(R, group.found_masks);
+
+#if 1
+ status = _mm256_cmpeq_epi8(test, zero);
+
+ mask = _mm256_movemask_epi8(status);
+#else
+ //mask = _mm256_movemask_epi8(test) ^ 0xffffffff;
+ mask = _mm256_movemask_epi8(test);
+#endif
+
+
+#endif
+
+
+ //printf(" mask : %x\n", mask);
+
+ if (mask != 0)
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == 1)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ /** TODO : update call
+ g_scan_context_register_atom_match(context,
+ group.found_id[j],
+ (iter - data) + 1 - group.m[j]);
+ **/
+
+ }
+
+ mask >>= 1;
+
+ }
+
+ }
+
+#endif
+
+
+ }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+
+
+#if 0
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* content = données binaires à analyser. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void run_scan_avx2(const GBitapBackend *backend, GScanContext *context, GBinContent *content)
+{
+ const group_manager_avx2_t *manager; /* Accès simplifié */
+
+ grouped_strings_avx2_t groups[10]; /* Copie pour accès locaux */
+
+
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+ __m256i zero; /* Constante 0 sur 256 bits */
+ size_t k; /* Boucle de parcours #1 */
+
+ grouped_strings_avx2_t group; /* Copie pour accès locaux */
+ __m256i R; /* Résultats courants */
+ __m256i pre_shift_mask; /* Préparation de décalage */
+ phys_t i; /* Boucle de parcours #2 */
+ __m256i test; /* Test de correspondances */
+ __m256i status; /* Statut d'une comparaison */
+ int mask; /* Masque d'accès rapide */
+ size_t j; /* Boucle de parcours #3 */
+
+ uint32_t leaves;
+ int ret;
+
+
+ phys_t old_i;
+ phys_t p;
+
+ //return;
+
+ /* Initialisations diverses */
+
+ manager = &backend->manager_avx2;
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ zero = _mm256_set1_epi16(0);
+
+ /* Recherches des chaînes de moins de 8 caractères */
+
+ printf(" --- manager->count_8: %zu\n", manager->count_8);
+
+ ret = 0;
+
+ //for (k = 0; k < manager->count_8; k++)
+ // memcpy(&groups[k], manager->strings_8[k], sizeof(grouped_strings_avx2_t));
+
+
+ for (i = 0; i < dlen; )
+ {
+
+ //printf(" --- %llx\n", (unsigned long long)i);
+
+ p = i + 4096;
+
+ if (p > dlen)
+ p = dlen;
+
+ old_i = i;
+
+ printf("old_i: %llx\n", (unsigned long long)old_i);
+
+ for (k = 0; k < manager->count_8; k++)
+ {
+
+ group = *manager->strings_8[k];
+
+ R = group.R;
+
+ for (i = old_i ; i < p; i++)
+ {
+
+ //group = &groups[k];
+
+ //printf(" k: %zu i: %llx\n", k, (unsigned long long)i);
+
+ //R = group.R;//_mm256_set1_epi8(~1);
+
+ R = _mm256_or_si256(R, group.pattern_masks[data[i]]);
+
+ R = _mm256_add_epi8(R, R);
+
+ test = _mm256_and_si256(R, group.found_masks);
+
+#if 0
+ status = _mm256_cmpeq_epi8(test, zero);
+
+ mask = _mm256_movemask_epi8(status);
+#else
+ //mask = _mm256_movemask_epi8(test) ^ 0xffffffff;
+ mask = _mm256_movemask_epi8(test);
+#endif
+
+ if (mask != 0xffffffff)
+ {
+ leaves = group.leaves;
+
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == 0)
+ {
+ if (leaves & 0x1) //group.leaves & (1u << j))
+ ;//define_full_match_avx2(backend, context, content, &group, j, i + 1);
+
+ }
+
+ mask >>= 1;
+
+ leaves >>= 1;
+
+ }
+
+ }
+
+ group.R = R;//_mm256_set1_epi8(~1);
+
+ memcpy(manager->strings_8[k], &group, sizeof(grouped_strings_avx2_t));
+
+ }
+
+
+ }
+
+ }
+
+ printf("oh: %d\n", ret);
+
+
+}
+
+
+#else
+
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* content = données binaires à analyser. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void run_scan_avx2(const GBitapBackend *backend, GScanContext *context, GBinContent *content)
+{
+ const group_manager_avx2_t *manager; /* Accès simplifié */
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+ __m256i zero; /* Constante 0 sur 256 bits */
+ size_t k; /* Boucle de parcours #1 */
+ grouped_strings_avx2_t group; /* Copie pour accès locaux */
+ __m256i R; /* Résultats courants */
+ __m256i pre_shift_mask; /* Préparation de décalage */
+ phys_t i; /* Boucle de parcours #2 */
+ __m256i test; /* Test de correspondances */
+ __m256i status; /* Statut d'une comparaison */
+ int mask; /* Masque d'accès rapide */
+ size_t j; /* Boucle de parcours #3 */
+
+ uint32_t leaves;
+ int ret;
+
+ //return;
+
+ /* Initialisations diverses */
+
+ manager = &backend->manager_avx2;
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ zero = _mm256_set1_epi16(0);
+
+ /* Recherches des chaînes de moins de 8 caractères */
+
+ printf(" --- manager->count_8: %zu\n", manager->count_8);
+
+ ret = 0;
+
+ for (k = 0; k < manager->count_8; k++)
+ {
+ memcpy(&group, manager->strings_8[k], sizeof(grouped_strings_avx2_t));
+
+ //printf(" --- group.used: %zu\n", group.used);
+
+ R = _mm256_set1_epi8(~1);
+
+ //pre_shift_mask = _mm256_set1_epi8(0xef);
+
+ for (i = 0; i < dlen; ++i)
+ {
+ //printf(" > %c\n", data[i]);
+
+ R = _mm256_or_si256(R, group.pattern_masks[data[i]]);
+
+ //printf("group pattern: %hhx\n", *((uint8_t *)&group.pattern_masks[data[i]]));
+
+ //printf("R: %hhx\n", *((uint8_t *)&R));
+
+ //R = _mm256_and_si256(R, pre_shift_mask);
+
+ //printf("R after and: %hhx\n", *((uint8_t *)&R));
+
+ R = _mm256_add_epi8(R, R);
+ //R = _mm256_slli_si256(R, 1);
+
+ //printf("R after shift: %hhx\n", *((uint8_t *)&R));
+
+ test = _mm256_and_si256(R, group.found_masks);
+
+#if 0
+ status = _mm256_cmpeq_epi8(test, zero);
+
+ mask = _mm256_movemask_epi8(status);
+#else
+ //mask = _mm256_movemask_epi8(test) ^ 0xffffffff;
+ mask = _mm256_movemask_epi8(test);
+#endif
+
+ if (mask != 0xffffffff)
+ {
+ leaves = group.leaves;
+
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == 0)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ if (leaves & 0x1) //group.leaves & (1u << j))
+ define_full_match_avx2(backend, context, content, &group, j, i + 1);
+ //else
+ //{
+ // ret++;
+ //printf("%x\n", (unsigned int)i + 1);
+ //}
+ //else
+ // g_scan_context_register_sub_match(context, group.found_id[j], i + 1 - group.m[j]);
+
+ }
+
+ mask >>= 1;
+
+ leaves >>= 1;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ printf("oh: %d\n", ret);
+
+ /* Recherches des chaînes de moins de 16 caractères */
+
+ for (k = 0; k < manager->count_16; k++)
+ {
+ memcpy(&group, manager->strings_16[k], sizeof(grouped_strings_avx2_t));
+
+ R = _mm256_set1_epi16(~1);
+
+ for (i = 0; i < dlen; ++i)
+ {
+ R = _mm256_or_si256(R, group.pattern_masks[data[i]]);
+ R = _mm256_slli_epi16(R, 1);
+
+ test = _mm256_and_si256(R, group.found_masks);
+
+ status = _mm256_cmpeq_epi16(test, zero);
+
+ mask = _mm256_movemask_epi8(status);
+
+ if (mask != 0)
+ for (j = 0; j < group.used; j++)
+ {
+ if (mask & 0x3)
+ {
+ assert((i + 1) >= group.m[j]);
+
+ if (group.leaves & (1llu << j))
+ define_full_match_avx2(backend, context, content, &group, j, i + 1);
+ else
+ ;//g_scan_context_register_sub_match(context, group.found_id[j], i + 1 - group.m[j]);
+
+ }
+
+ mask >>= 2;
+
+ }
+
+ }
+
+ }
+
+}
+
+#endif
+
+
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* OPTIMISATIONS POUR ARCHITECTURE AVX512 */
+/* ---------------------------------------------------------------------------------- */
+
+
+/**
+ * Cf. https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#techs=AVX_512
+ * - https://agner.org/optimize/
+ * - https://uops.info/table.html
+ */
+
+#ifdef HAVE_AVX512_F
+
+/******************************************************************************
+* *
+* Paramètres : strings = ensemble de groupes constitués. [OUT] *
+* count = nombre de groupes courant. [OUT] *
+* *
+* Description : Indique la valeur portée par une expression rationnelle. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void extend_grouped_strings_avx512(grouped_strings_avx512_t ***strings, size_t *count)
+{
+ grouped_strings_avx512_t *new; /* Zone supplémentaire */
+ size_t i; /* Boucle de parcours */
+
+ /* Définition d'un nouvel élément vierge */
+
+ new = aligned_alloc(0x1000, sizeof(grouped_strings_avx512_t));
+
+ for (i = 0; i < 256; i++)
+ new->pattern_masks[i] = _mm512_set1_epi8(~0);
+
+ new->found_masks = _mm512_set1_epi8(~0);
+
+ new->R = _mm512_set1_epi8(~1);
+
+ for (i = 0; i < 64; i++)
+ {
+ new->m[i] = 0;
+
+ new->found_id[i] = INVALID_PATTERN_ID;
+
+ }
+
+ new->available = 64;
+ new->used = 0;
+
+ /* Inscription */
+
+ *strings = realloc(*strings, ++(*count) * sizeof(grouped_strings_avx512_t *));
+
+ (*strings)[*count - 1] = new;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = contexte de l'analyse à mener. *
+* plain = chaîne de caractères classique à intégrer. *
+* plen = taille de cette chaîne. *
+* *
+* Description : Inscrit dans le moteur une chaîne de caractères à rechercher.*
+* *
+* Retour : Indice de résultats pour le motif. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static patid_t enroll_plain_pattern_avx512(GBitapBackend *backend, GScanContext *context, const bin_t *plain, size_t plen)
+{
+ patid_t result; /* Identifiant à retourner */
+ grouped_strings_avx512_t ***strings; /* Groupe de chaînes visé */
+ size_t *count; /* Taille de ce groupe */
+ grouped_strings_avx512_t *last; /* Dernier groupe à remplir */
+ size_t n; /* Indice dans le groupe */
+ size_t i; /* Boucle de parcours */
+ __m512i *letter; /* Lettre à marquer */
+
+ /* Sélection du groupe de travail adéquat */
+
+ strings = &backend->manager_avx512.strings_8;
+ count = &backend->manager_avx512.count_8;
+
+ /* Préparation de la place nécessaire */
+
+ if (*count == 0)
+ {
+ extend_grouped_strings_avx512(strings, count);
+
+ last = (*strings)[0];
+
+ }
+
+ else
+ {
+ last = (*strings)[*count - 1];
+
+ if (last->used == last->available)
+ {
+ extend_grouped_strings_avx512(strings, count);
+ last = (*strings)[*count - 1];
+ }
+
+ }
+
+ /* Intégration d'une nouvelle chaîne */
+
+ n = last->used++;
+
+ last->m[n] = plen;
+
+ result = 0; // FIXME g_scan_context_get_new_pattern_id(context);
+
+ last->found_id[n] = result;
+
+ ((uint8_t *)&last->found_masks)[n] = (1 << plen);
+
+ for (i = 0; i < plen; i++)
+ {
+ letter = last->pattern_masks + plain[i];
+ ((uint8_t *)letter)[n] &= ~(1 << i);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* data = données à analyser. *
+* dlen = quantité de ces données. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void run_scan_avx512(const GBitapBackend *backend, GScanContext *context, const bin_t *data, phys_t dlen)
+{
+ const group_manager_avx512_t *manager; /* Accès simplifié */
+
+ //register __m512i zero asm("zmm19"); /* Constante 0 sur 512 bits */
+
+ //__m512i shift8_mask; /* Masque pour décalage manuel */
+
+
+ size_t k; /* Boucle de parcours #1 */
+ /*__attribute__((aligned(0x1000)))*/ grouped_strings_avx512_t group; /* Copie pour accès locaux */
+ //void *grpptr;
+ //grouped_strings_avx512_t *_group; /* Copie pour accès locaux */
+
+ int ret;
+
+
+ register __m512i R asm("zmm28"); /* Résultats courants */
+ register __m512i found_masks asm("zmm21"); /* Vérifications accélérées */
+
+
+ register __mmask64 test_mask asm("k6");
+
+
+ register const bin_t *iter asm("rsi");
+ register const bin_t *maxiter/* asm("rdi")*/;
+ //phys_t i; /* Boucle de parcours #2 */
+
+
+ //__m512i test;
+
+ __mmask64 mask; /* Masque d'accès rapide */
+ size_t j; /* Boucle de parcours #3 */
+
+
+ /* Initialisations diverses */
+
+ manager = &backend->manager_avx512;
+
+
+
+
+ /* Recherches des chaînes de moins de 8 caractères */
+
+ //asm volatile ("nop; nop; nop; nop; nop; nop; nop; ");
+
+ //zero = _mm512_set1_epi8(0);
+
+ //asm volatile ("nop; nop; nop; nop; nop; nop; nop; ");
+
+ //shift8_mask = _mm512_set1_epi8(0x7f);
+
+
+
+#define WORK_ON_COPY
+
+ for (k = 0; k < manager->count_8; k++)
+ {
+#ifdef WORK_ON_COPY
+ memcpy(&group, manager->strings_8[k], sizeof(grouped_strings_avx512_t));
+
+#else
+
+ grpptr = alloca(sizeof(grouped_strings_avx512_t) + 0x1000);
+
+ _group = grpptr + 0x1000 - (((unsigned long)grpptr) % 0x1000);
+
+ //_group = manager->strings_8[k];
+
+ memcpy(_group, manager->strings_8[k], sizeof(grouped_strings_avx512_t));
+
+ ret = mlock(_group, sizeof(grouped_strings_avx512_t));
+
+ printf("ret = %d\n", ret);
+#endif
+
+
+
+ //printf(" --- group %p -- used: %zu (sz: %zu)\n", &group, group.used, sizeof(grouped_strings_avx512_t));
+ //printf(" --- group.used: %zu (sz: %zu)\n", group.used, sizeof(grouped_strings_avx512_t));
+
+
+ asm volatile
+ (
+ /*
+ * R = _mm512_set1_epi8(~1);
+ *
+ */
+
+ "movabs $0xfefefefefefefefe, %%rax ; "
+ "vpbroadcastq %%rax, %[STATE] ; "
+
+ "movabs $0xffffffffffffffff, %%rax ; "
+ "kmovq %%rax, %[KMASK] ; "
+
+ /*
+ *
+ */
+
+ "vmovdqa64 %[FOUND_SRC], %[FOUND_DST] ; "
+
+ : [STATE] "=v"(R),
+ [KMASK] "=Yk"(test_mask),
+ [FOUND_DST] "=v"(found_masks)
+#ifdef WORK_ON_COPY
+ : [FOUND_SRC] "m"(group.found_masks)
+#else
+ : [FOUND_SRC] "m"(_group->found_masks)
+#endif
+ : "memory", "rax"
+
+ );
+
+
+
+
+
+
+
+ //for (i = 0; i < dlen; i++)
+
+ maxiter = data + dlen;
+
+ for (iter = data; iter < maxiter; iter++)
+ {
+
+ //printf("--- %llx <-> %c\n", (unsigned long long)(iter - data), *iter);
+
+
+ asm volatile goto
+ (
+ /*
+ * R = _mm512_or_si512(R, group.pattern_masks[*iter]);
+ *
+ * Latency : 1-9
+ * Throughput : 0.5
+ * #Uops : 1-2
+ * Port Usage : 1*p05+1*p23
+ *
+ */
+
+ "vpord %[PATTERN], %[STATE], %[STATE] ; "
+
+ /*
+ * R = _mm512_add_epi8(R, R);
+ *
+ * Latency : 1
+ * Throughput : 0.5
+ * #Uops : 1
+ * Port Usage : 1*p05
+ *
+ */
+
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ /*
+ * mask = _mm512_test_epi8_mask(R, group.found_masks);
+ *
+ * Latency : 3
+ * Throughput : 1
+ * #Uops : 2
+ * Port Usage : 1*p23+1*p5
+ *
+ */
+
+ /******************************
+ * Version 0
+
+ ******************/
+
+ //"vptestmb %[FOUND], %[STATE], %%k7 ; "
+
+ /******************************
+ * Version 1
+
+ "vmovdqa64 %[STATE], %%zmm12 ; "
+
+ "vptestmb %[FOUND], %%zmm12, %%k7 ; "
+
+ ******************/
+
+ /******************************
+ * Version 2
+
+ "vpandd %[STATE], %[FOUND], %%zmm12 ; "
+
+ "vpcmpneqb %[NUL], %%zmm12, %%k7 ; "
+
+ ******************/
+
+
+ "vmovdqa64 %[STATE], %%zmm12 ; "
+
+ "vptestmb %[FOUND], %%zmm12, %%k7 ; "
+
+
+ "ktestq %[KMASK], %%k7 ; "
+
+ "jc %l[next_iter] ; "
+
+
+
+
+
+ /*
+ * (suite)
+ *
+ * Latency : 3
+ * Throughput : 1
+ * #Uops : 1
+ * Port Usage : 1*p5
+ *
+ */
+
+ "kmovq %%k7, %[MASK0] ; "
+
+ //"vmovdqa64 %%zmm12, %[OUTPUT] ; "
+
+ //"nop; nop; nop; nop; nop; nop; nop; nop; "
+ //"nop; nop; nop; nop; nop; nop; nop; nop; "
+
+ : [STATE] "+v"(R),
+ //[OUTPUT] "=v"(test),
+ [MASK0] "=r"(mask)
+ //[NUL] "=v"(zero)
+#ifdef WORK_ON_COPY
+ : [PATTERN] "m"(group.pattern_masks[*iter]),
+#else
+ : [PATTERN] "m"(_group->pattern_masks[*iter]),
+#endif
+ [FOUND] "v"(found_masks),
+ [KMASK] "Yk"(test_mask)
+ : "memory", "k7", "zmm12"
+ : next_iter
+
+ );
+
+
+
+
+ /*
+ printf(" found mask: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&group.found_masks)[0],
+ ((uint8_t *)&group.found_masks)[1],
+ ((uint8_t *)&group.found_masks)[2],
+ ((uint8_t *)&group.found_masks)[3],
+ ((uint8_t *)&group.found_masks)[4],
+ ((uint8_t *)&group.found_masks)[5],
+ ((uint8_t *)&group.found_masks)[6],
+ ((uint8_t *)&group.found_masks)[7]);
+
+
+ printf(" test: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&test)[0],
+ ((uint8_t *)&test)[1],
+ ((uint8_t *)&test)[2],
+ ((uint8_t *)&test)[3],
+ ((uint8_t *)&test)[4],
+ ((uint8_t *)&test)[5],
+ ((uint8_t *)&test)[6],
+ ((uint8_t *)&test)[7]);
+
+
+ printf(" -> mask: 0x%llx\n", (unsigned long long)mask);
+ */
+
+
+#ifdef WORK_ON_COPY
+
+ //if (mask != 0xffffffffffffffffllu)
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == 0)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ /** TODO : update call
+ g_scan_context_register_atom_match(context,
+ group.found_id[j],
+ (iter - data) + 1 - group.m[j]);
+ **/
+
+ }
+
+ mask >>= 1;
+
+ }
+
+#else
+
+# error "WEFEF"
+
+ if (mask != 0xffffffffffffffffllu)
+ for (j = 0; j < _group->used; j++)
+ {
+ if ((mask & 0x1) == 0)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ /** TODO : update call
+ g_scan_context_register_atom_match(context,
+ _group->found_id[j],
+ (iter - data) + 1 - _group->m[j]);
+ **/
+
+ }
+
+ mask >>= 1;
+
+ }
+
+#endif
+
+
+ next_iter:
+
+ //;
+
+ //iter++;
+
+ }
+
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* content = données binaires à analyser. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void run_scan_avx512____good_asm_perfs(const GBitapBackend *backend, GScanContext *context, GBinContent *content)
+{
+ const group_manager_avx512_t *manager; /* Accès simplifié */
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+
+
+ //__m512i shift8_mask; /* Masque pour décalage manuel */
+
+
+ size_t k; /* Boucle de parcours #1 */
+ grouped_strings_avx512_t group; /* Copie pour accès locaux */
+
+ register __m512i found_masks asm("zmm21"); /* Vérifications accélérées */
+
+
+ //register volatile __m512i zero/* asm("zmm19")*/; /* Constante 0 sur 512 bits */
+ register __m512i R asm("zmm28"); /* Résultats courants */
+
+ //int counter;
+
+ const bin_t *iter;
+ const bin_t *maxiter;
+ //phys_t i; /* Boucle de parcours #2 */
+
+
+ __m512i test;
+
+ __mmask64 mask; /* Masque d'accès rapide */
+ size_t j; /* Boucle de parcours #3 */
+
+
+ //register __m512i z30 asm("zmm30");
+
+
+ //return;
+
+
+ //counter = 0;
+
+ //return;
+
+ /* Initialisations diverses */
+
+ manager = &backend->manager_avx512;
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ /* Recherches des chaînes de moins de 8 caractères */
+
+ printf(" --- manager512->count_8: %zu\n", manager->count_8);
+
+ asm volatile ("nop; nop; nop; nop; nop; nop; nop; ");
+
+ //zero = _mm512_set1_epi8(0);
+
+ asm volatile ("nop; nop; nop; nop; nop; nop; nop; ");
+
+ //shift8_mask = _mm512_set1_epi8(0x7f);
+
+
+ for (k = 0; k < manager->count_8; k++)
+ {
+ memcpy(&group, manager->strings_8[k], sizeof(grouped_strings_avx512_t));
+
+
+
+
+ //printf(" --- group %p -- used: %zu (sz: %zu)\n", &group, group.used, sizeof(grouped_strings_avx512_t));
+ //printf(" --- group.used: %zu (sz: %zu)\n", group.used, sizeof(grouped_strings_avx512_t));
+
+
+ asm volatile
+ (
+ /*
+ * R = _mm512_set1_epi8(~1);
+ *
+ */
+
+ "movabs $0xfefefefefefefefe, %%rax ; "
+ "vpbroadcastq %%rax, %[STATE] ; "
+
+ /*
+ *
+ */
+
+ "vmovdqa64 %[FOUND_SRC], %[FOUND_DST] ; "
+
+ : [STATE] "=v"(R),
+ [FOUND_DST] "=v"(found_masks)
+ : [FOUND_SRC] "m"(group.found_masks)
+ : "memory", "rax"
+
+ );
+
+
+
+
+
+
+
+ //for (i = 0; i < dlen; i++)
+
+ maxiter = data + dlen;
+
+ for (iter = data; iter < maxiter; iter++)
+ {
+
+ //printf("--- %llx <-> %c\n", (unsigned long long)(iter - data), *iter);
+
+
+ asm volatile
+ (
+
+ /*
+ * R = _mm512_or_si512(R, group.pattern_masks[*iter]);
+ *
+ * Latency : 1-9
+ * Throughput : 0.5
+ * #Uops : 1-2
+ * Port Usage : 1*p05+1*p23
+ *
+ */
+
+ "vpord %[PATTERN], %[STATE], %[STATE] ; "
+
+ /*
+ * R = _mm512_add_epi8(R, R);
+ *
+ * Latency : 1
+ * Throughput : 0.5
+ * #Uops : 1
+ * Port Usage : 1*p05
+ *
+ */
+
+ "vpaddb %[STATE], %[STATE], %[STATE] ; "
+
+ /*
+ * mask = _mm512_test_epi8_mask(R, group.found_masks);
+ *
+ * Latency : 3
+ * Throughput : 1
+ * #Uops : 2
+ * Port Usage : 1*p23+1*p5
+ *
+ */
+
+ /******************************
+ * Version 0
+
+ ******************/
+
+ "vptestmb %[FOUND], %[STATE], %%k7 ; "
+
+ /******************************
+ * Version 1
+
+ "vmovdqa64 %[STATE], %%zmm12 ; "
+
+ "vptestmb %[FOUND], %%zmm12, %%k0 ; "
+
+ ******************/
+
+ /******************************
+ * Version 2
+
+ "vpandd %[STATE], %[FOUND], %%zmm12 ; "
+
+ "vpcmpneqb %[NUL], %%zmm12, %%k7 ; "
+
+ ******************/
+
+ /*
+ * (suite)
+ *
+ * Latency : 3
+ * Throughput : 1
+ * #Uops : 1
+ * Port Usage : 1*p5
+ *
+ */
+
+ "kmovq %%k7, %[MASK0] ; "
+
+ //"vmovdqa64 %%zmm12, %[OUTPUT] ; "
+
+ //"nop; nop; nop; nop; nop; nop; nop; nop; "
+ //"nop; nop; nop; nop; nop; nop; nop; nop; "
+
+ : [STATE] "+v"(R),
+ [OUTPUT] "=v"(test),
+ [MASK0] "=r"(mask)/*,
+ [NUL] "+v"(zero)*/
+ : [PATTERN] "v"(group.pattern_masks[*iter]),
+ [FOUND] "v"(found_masks)
+ : "memory", "k0", "zmm12"
+
+ );
+
+
+
+
+ /*
+ printf(" found mask: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&group.found_masks)[0],
+ ((uint8_t *)&group.found_masks)[1],
+ ((uint8_t *)&group.found_masks)[2],
+ ((uint8_t *)&group.found_masks)[3],
+ ((uint8_t *)&group.found_masks)[4],
+ ((uint8_t *)&group.found_masks)[5],
+ ((uint8_t *)&group.found_masks)[6],
+ ((uint8_t *)&group.found_masks)[7]);
+
+
+ printf(" test: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&test)[0],
+ ((uint8_t *)&test)[1],
+ ((uint8_t *)&test)[2],
+ ((uint8_t *)&test)[3],
+ ((uint8_t *)&test)[4],
+ ((uint8_t *)&test)[5],
+ ((uint8_t *)&test)[6],
+ ((uint8_t *)&test)[7]);
+
+
+ printf(" -> mask: 0x%llx\n", (unsigned long long)mask);
+ */
+
+#if 0
+
+ /*
+ printf(" R: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&R)[0],
+ ((uint8_t *)&R)[1],
+ ((uint8_t *)&R)[2],
+ ((uint8_t *)&R)[3],
+ ((uint8_t *)&R)[4],
+ ((uint8_t *)&R)[5],
+ ((uint8_t *)&R)[6],
+ ((uint8_t *)&R)[7]);
+
+ printf(" found mask: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&group.found_masks)[0],
+ ((uint8_t *)&group.found_masks)[1],
+ ((uint8_t *)&group.found_masks)[2],
+ ((uint8_t *)&group.found_masks)[3],
+ ((uint8_t *)&group.found_masks)[4],
+ ((uint8_t *)&group.found_masks)[5],
+ ((uint8_t *)&group.found_masks)[6],
+ ((uint8_t *)&group.found_masks)[7]);
+ */
+
+ /*
+
+ printf(" test: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&test)[0],
+ ((uint8_t *)&test)[1],
+ ((uint8_t *)&test)[2],
+ ((uint8_t *)&test)[3],
+ ((uint8_t *)&test)[4],
+ ((uint8_t *)&test)[5],
+ ((uint8_t *)&test)[6],
+ ((uint8_t *)&test)[7]);
+
+ */
+
+#endif
+
+
+
+
+
+# define TEST_MASK 0xffffffffffffffffllu
+# define TEST_BIT 0
+
+
+ //printf("mask: %llx\n", (unsigned long long)mask);
+
+
+ if (mask != TEST_MASK)
+ {
+ //printf("mask: %llx\n", (unsigned long long)mask);
+
+ //counter++;
+ //printf("Ouhc: %p - %x\n", &group, *((uint8_t *)&mask));
+ //printf("Ouhc: %x\n", 1);
+ //asm("vzeroupper;");
+ //printf("Ouhc: %hhx\n", R[0]);
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == TEST_BIT)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ //printf(">> FOUND %zu @ %x !!!!!!!!!!!!!!\n", j, (unsigned int)i + 1);
+ printf(">> FOUND %zu @ %x !!!!!!!!!!!!!!\n", j, (unsigned int)(iter - data) + 1);
+
+
+ }
+
+ mask >>= 1;
+ //printf("> mask: %llx\n", (unsigned long long)mask);
+
+ }
+
+
+
+ }
+
+
+
+ }
+
+ //printf("%hhx\n", ((uint8_t *)&R)[0], ((uint8_t *)&mask)[0]);
+
+ }
+
+ //printf("counter=%d\n", counter);
+
+
+}
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* content = données binaires à analyser. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void run_scan_avx512_best_test(const GBitapBackend *backend, GScanContext *context, GBinContent *content)
+{
+ const group_manager_avx512_t *manager; /* Accès simplifié */
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+
+
+ //__m512i shift8_mask; /* Masque pour décalage manuel */
+
+
+ size_t k; /* Boucle de parcours #1 */
+ grouped_strings_avx512_t group; /* Copie pour accès locaux */
+
+ //register __m512i zero; /* Constante 0 sur 512 bits */
+ register __m512i R; /* Résultats courants */
+
+ //int counter;
+
+ const bin_t *iter;
+ const bin_t *maxiter;
+ //phys_t i; /* Boucle de parcours #2 */
+
+
+ //__m512i test;
+
+ __mmask64 mask; /* Masque d'accès rapide */
+ size_t j; /* Boucle de parcours #3 */
+
+ //return;
+
+
+ //counter = 0;
+
+ //return;
+
+ /* Initialisations diverses */
+
+ manager = &backend->manager_avx512;
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ /* Recherches des chaînes de moins de 8 caractères */
+
+ printf(" --- manager512->count_8: %zu\n", manager->count_8);
+
+ //zero = _mm512_set1_epi8(0);
+
+ //shift8_mask = _mm512_set1_epi8(0x7f);
+
+
+
+ for (k = 0; k < manager->count_8; k++)
+ {
+ memcpy(&group, manager->strings_8[k], sizeof(grouped_strings_avx512_t));
+
+ //printf(" --- group %p -- used: %zu (sz: %zu)\n", &group, group.used, sizeof(grouped_strings_avx512_t));
+ //printf(" --- group.used: %zu (sz: %zu)\n", group.used, sizeof(grouped_strings_avx512_t));
+
+ R = _mm512_set1_epi8(~1);
+
+
+
+ /* vpord zmm, zmm, zmm : latence 1, 1*p05 */
+ //R = _mm512_or_si512(R, group.pattern_masks[data[0]]);
+
+ //for (i = 0; i < dlen; i++)
+
+ maxiter = data + dlen;
+
+ for (iter = data; iter < maxiter; iter++)
+ {
+
+ //printf("--- %llx <-> %c\n", (unsigned long long)(iter - data), *iter);
+
+
+ //R = _mm512_or_si512(R, group.pattern_masks[data[i]]);
+ R = _mm512_or_si512(R, group.pattern_masks[*iter]);
+
+
+#if 1
+ /* vpaddb zmm, zmm, zmm : latence 1, 1*p05 */
+ R = _mm512_add_epi8(R, R);
+#else
+ /* vpandd zmm, zmm, zmm : latence 1, 1*p5 */
+ R = _mm512_and_si512(R, shift8_mask);
+ /* vpslldq zmm, zmm, imm8 : latence 1, 1*p5 */
+ R = _mm512_bslli_epi128(R, 1);
+
+#endif
+
+ /*
+ printf(" R: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&R)[0],
+ ((uint8_t *)&R)[1],
+ ((uint8_t *)&R)[2],
+ ((uint8_t *)&R)[3],
+ ((uint8_t *)&R)[4],
+ ((uint8_t *)&R)[5],
+ ((uint8_t *)&R)[6],
+ ((uint8_t *)&R)[7]);
+
+ printf(" found mask: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&group.found_masks)[0],
+ ((uint8_t *)&group.found_masks)[1],
+ ((uint8_t *)&group.found_masks)[2],
+ ((uint8_t *)&group.found_masks)[3],
+ ((uint8_t *)&group.found_masks)[4],
+ ((uint8_t *)&group.found_masks)[5],
+ ((uint8_t *)&group.found_masks)[6],
+ ((uint8_t *)&group.found_masks)[7]);
+ */
+
+#if 1
+ /* vptestmb k, zmm, zmm : latence 3, 1*p5 */
+ mask = _mm512_test_epi8_mask(R, group.found_masks);
+
+
+ //test = _mm512_add_epi64(R, zero);
+
+ //mask = _mm512_test_epi8_mask(test, group.found_masks);
+
+
+
+
+
+# define TEST_MASK 0xffffffffffffffffllu
+# define TEST_BIT 0
+
+ /* comparaison : != */
+
+
+#else
+ /* vpandd zmm, zmm, zmm : latence 1, 1*p05 */
+ test = _mm512_and_si512(R, group.found_masks);
+
+
+ printf(" test: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&test)[0],
+ ((uint8_t *)&test)[1],
+ ((uint8_t *)&test)[2],
+ ((uint8_t *)&test)[3],
+ ((uint8_t *)&test)[4],
+ ((uint8_t *)&test)[5],
+ ((uint8_t *)&test)[6],
+ ((uint8_t *)&test)[7]);
+
+ /* vpmovb2m k, zmm : latence 3 (au lieu de 1 !?), 1*p0 */
+ //mask = _mm512_movepi8_mask(test);
+
+# define TEST_MASK 0
+# define TEST_BIT 0
+
+
+ //test = _mm512_popcnt_epi8(test);
+
+#endif
+
+
+ //printf(" final mask: %16llx\n", (unsigned long long)mask);
+
+
+
+ //R = _mm512_or_si512(R, group.pattern_masks[data[i + 1]]);
+
+#if 1
+
+
+ if (mask != TEST_MASK)
+ {
+ //counter++;
+ //printf("Ouhc: %p - %x\n", &group, *((uint8_t *)&mask));
+ printf("Ouhc: %p\n", &group);
+ //printf("Ouhc: %hhx\n", R[0]);
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == TEST_BIT)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ //printf(">> FOUND %zu @ %x !!!!!!!!!!!!!!\n", j, (unsigned int)i + 1);
+ printf(">> FOUND %zu @ %x !!!!!!!!!!!!!!\n", j, (unsigned int)(iter - data) + 1);
+
+
+ }
+
+ mask >>= 1;
+
+ }
+
+
+
+ }
+
+
+#else
+
+ if (_mm512_reduce_or_epi64(test) != 0)
+ {
+ for (j = 0; j < group.used; j++)
+ {
+ if (((uint8_t *)&test)[j] == 0)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ printf(">> FOUND %zu @ %x !!!!!!!!!!!!!!\n", j, (unsigned int)i + 1);
+
+ }
+
+
+ }
+
+ }
+
+#endif
+
+
+ }
+
+ //printf("%hhx\n", ((uint8_t *)&R)[0], ((uint8_t *)&mask)[0]);
+
+ }
+
+ //printf("counter=%d\n", counter);
+
+
+}
+
+
+
+
+
+static void run_scan_avx512__saved(const GBitapBackend *backend, GScanContext *context, GBinContent *content)
+{
+ const group_manager_avx512_t *manager; /* Accès simplifié */
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+
+
+ __m512i shift8_mask; /* Masque pour décalage manuel */
+
+
+ size_t k; /* Boucle de parcours #1 */
+ grouped_strings_avx512_t group; /* Copie pour accès locaux */
+
+
+ __m512i R; /* Résultats courants */
+
+ //int counter;
+
+ phys_t i; /* Boucle de parcours #2 */
+
+
+ __m512i test;
+
+ __mmask64 mask; /* Masque d'accès rapide */
+ size_t j; /* Boucle de parcours #3 */
+
+
+
+ //counter = 0;
+
+ //return;
+
+ /* Initialisations diverses */
+
+ manager = &backend->manager_avx512;
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ /* Recherches des chaînes de moins de 8 caractères */
+
+ printf(" --- manager512->count_8: %zu\n", manager->count_8);
+
+
+
+ shift8_mask = _mm512_set1_epi8(0x7f);
+
+
+ for (k = 0; k < manager->count_8; k++)
+ {
+ memcpy(&group, manager->strings_8[k], sizeof(grouped_strings_avx512_t));
+
+ //printf(" --- group %p -- used: %zu (sz: %zu)\n", &group, group.used, sizeof(grouped_strings_avx512_t));
+ //printf(" --- group.used: %zu (sz: %zu)\n", group.used, sizeof(grouped_strings_avx512_t));
+
+ R = _mm512_set1_epi8(~1);
+
+ /* vpord zmm, zmm, zmm : latence 1, 1*p05 */
+ R = _mm512_or_si512(R, group.pattern_masks[data[0]]);
+
+ for (i = 0; i < dlen; i++)
+ {
+
+ /*
+ printf("--- %llx <-> %c\n", (unsigned long long)i, data[i]);
+
+ printf(" R: %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&R)[0],
+ ((uint8_t *)&R)[1],
+ ((uint8_t *)&R)[2],
+ ((uint8_t *)&R)[3]);
+
+ printf(" mask: %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&group.pattern_masks[data[i]])[0],
+ ((uint8_t *)&group.pattern_masks[data[i]])[1],
+ ((uint8_t *)&group.pattern_masks[data[i]])[2],
+ ((uint8_t *)&group.pattern_masks[data[i]])[3]);
+ */
+
+ //R = _mm512_or_si512(R, group.pattern_masks[data[i]]);
+
+ /*
+ printf(" R: %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&R)[0],
+ ((uint8_t *)&R)[1],
+ ((uint8_t *)&R)[2],
+ ((uint8_t *)&R)[3]);
+ */
+
+#if 1
+ /* vpaddb zmm, zmm, zmm : latence 1, 1*p05 */
+ R = _mm512_add_epi8(R, R);
+#else
+ /* vpandd zmm, zmm, zmm : latence 1, 1*p5 */
+ R = _mm512_and_si512(R, shift8_mask);
+ /* vpslldq zmm, zmm, imm8 : latence 1, 1*p5 */
+ R = _mm512_bslli_epi128(R, 1);
+
+#endif
+
+#if 1
+ /* vptestmb k, zmm, zmm : latence 3, 1*p5 */
+ mask = _mm512_test_epi8_mask(R, group.found_masks);
+#else
+ test = _mm512_and_si512(R, group.found_masks);
+ test = _mm512_popcnt_epi8(test);
+
+#endif
+
+ /*
+ printf(" found mask: %hhx %hhx %hhx %hhx\n",
+ ((uint8_t *)&group.found_masks)[0],
+ ((uint8_t *)&group.found_masks)[1],
+ ((uint8_t *)&group.found_masks)[2],
+ ((uint8_t *)&group.found_masks)[3]);
+
+ printf(" final mask: %16llx\n", (unsigned long long)mask);
+ */
+
+
+ R = _mm512_or_si512(R, group.pattern_masks[data[i + 1]]);
+
+#if 1
+
+ if (mask != 0xffffffffffffffffllu)
+ {
+ //counter++;
+ //printf("Ouhc: %p - %x\n", &group, *((uint8_t *)&mask));
+ //printf("Ouhc: %p\n", &group);
+ for (j = 0; j < group.used; j++)
+ {
+ if ((mask & 0x1) == 0)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ printf(">> FOUND %zu @ %x !!!!!!!!!!!!!!\n", j, (unsigned int)i + 1);
+
+
+ }
+
+ mask >>= 1;
+
+ }
+
+
+
+ }
+
+
+#else
+
+ if (_mm512_reduce_or_epi64(test) != 0)
+ {
+ for (j = 0; j < group.used; j++)
+ {
+ if (((uint8_t *)&test)[j] == 0)
+ {
+ //assert((i + 1) >= group.m[j]);
+
+ printf(">> FOUND %zu @ %x !!!!!!!!!!!!!!\n", j, (unsigned int)i + 1);
+
+ }
+
+
+ }
+
+ }
+
+#endif
+
+
+ }
+
+ //printf("%hhx\n", ((uint8_t *)&R)[0], ((uint8_t *)&mask)[0]);
+
+ }
+
+ //printf("counter=%d\n", counter);
+
+
+}
+#endif
+
+
+
+#endif
diff --git a/src/analysis/scan/patterns/backends/bitap.h b/src/analysis/scan/patterns/backends/bitap.h
new file mode 100644
index 0000000..1cb384c
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/bitap.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * bitap.h - prototypes pour la méthode de recherche basée sur l'algorithme Bitap
+ *
+ * Copyright (C) 2022 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_PATTERNS_BACKENDS_BITAP_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKENDS_BITAP_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "../backend.h"
+
+
+
+#define G_TYPE_BITAP_BACKEND g_bitap_backend_get_type()
+#define G_BITAP_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BITAP_BACKEND, GBitapBackend))
+#define G_IS_BITAP_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BITAP_BACKEND))
+#define G_BITAP_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BITAP_BACKEND, GBitapBackendClass))
+#define G_IS_BITAP_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BITAP_BACKEND))
+#define G_BITAP_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BITAP_BACKEND, GBitapBackendClass))
+
+
+/* Méthode de recherche basée sur l'algorithme Bitap (instance) */
+typedef struct _GBitapBackend GBitapBackend;
+
+/* Méthode de recherche basée sur l'algorithme Bitap (classe) */
+typedef struct _GBitapBackendClass GBitapBackendClass;
+
+
+/* Indique le type défini pour un moteur de recherche pour données. */
+GType g_bitap_backend_get_type(void);
+
+/* Crée une méthode de recherche basée sur l'algorithme Bitap. */
+GEngineBackend *g_bitap_backend_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKENDS_BITAP_H */
diff --git a/src/analysis/scan/patterns/backends/hyperscan-int.h b/src/analysis/scan/patterns/backends/hyperscan-int.h
new file mode 100644
index 0000000..31d271b
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/hyperscan-int.h
@@ -0,0 +1,67 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hyperscan-int.h - prototypes internes pour la méthode de recherche basée sur la bibliothèque Hyperscan d'Intel
+ *
+ * Copyright (C) 2024 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_PATTERNS_BACKENDS_HYPERSCAN_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKENDS_HYPERSCAN_INT_H
+
+
+#include "hyperscan.h"
+
+
+#include "../backend-int.h"
+
+
+
+#define EXPR_COVERAGE_START 0
+#define EXPR_COVERAGE_COUNT 1
+#define EXPR_COVERAGE_END 1
+
+
+/* Méthode de recherche basée sur une bibliothèque d'Intel : Hyperscan (instance) */
+struct _GHyperscanBackend
+{
+ GEngineBackend parent; /* A laisser en premier */
+
+ const uint8_t **atoms; /* Motif remarquable */
+ size_t *lengths; /* Nombre d'octets considérés */
+ uint32_t *coverages; /* Départ et quantité de suivis*/
+ size_t allocated; /* Nombre d'éléments alloués */
+ size_t used; /* Nombre d'éléments utiles */
+
+ unsigned int *lit_ids; /* Identifiants internes */
+
+ hs_database_t *database; /* Compilation d'éléments */
+ hs_scratch_t *scratch; /* Espace de travail */
+
+};
+
+/* Méthode de recherche basée sur une bibliothèque d'Intel : Hyperscan (classe) */
+struct _GHyperscanBackendClass
+{
+ GEngineBackendClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKENDS_HYPERSCAN_INT_H */
diff --git a/src/analysis/scan/patterns/backends/hyperscan.c b/src/analysis/scan/patterns/backends/hyperscan.c
new file mode 100644
index 0000000..40a7372
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/hyperscan.c
@@ -0,0 +1,1063 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hyperscan.c - méthode de recherche basée sur la bibliothèque Hyperscan d'Intel
+ *
+ * Copyright (C) 2024 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 "hyperscan.h"
+
+
+#include <hs.h>
+#include <string.h>
+
+
+#include <i18n.h>
+
+
+#include "hyperscan-int.h"
+#include "../../../../core/logs.h"
+#include "../../../../glibext/umemslice.h" /* REMME */
+
+
+
+/* ---------------------- IMPLANTATION D'UNE NOUVELLE APPROCHE ---------------------- */
+
+
+/* Initialise la classe des méthodes basée sur Hyperscan. */
+static void g_hyperscan_backend_class_init(GHyperscanBackendClass *);
+
+/* Initialise une instance de méthodes basée sur Hyperscan. */
+static void g_hyperscan_backend_init(GHyperscanBackend *);
+
+/* Supprime toutes les références externes. */
+static void g_hyperscan_backend_dispose(GHyperscanBackend *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_hyperscan_backend_finalize(GHyperscanBackend *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/**
+ * for i in range(int(8192 / 25) + 1):
+ * print(','.join([ '% 5u' % (i * 25 + k) for k in range(25) ]) + ',')
+ */
+static const unsigned int __cached_ids[8200] = {
+
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
+ 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
+ 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
+ 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
+ 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
+ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
+ 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
+ 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
+ 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
+ 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349,
+ 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
+ 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399,
+ 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424,
+ 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449,
+ 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474,
+ 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499,
+ 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524,
+ 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549,
+ 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
+ 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599,
+ 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624,
+ 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649,
+ 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674,
+ 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699,
+ 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724,
+ 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749,
+ 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774,
+ 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799,
+ 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824,
+ 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849,
+ 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874,
+ 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899,
+ 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924,
+ 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949,
+ 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974,
+ 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999,
+ 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
+ 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049,
+ 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074,
+ 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099,
+ 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124,
+ 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149,
+ 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174,
+ 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199,
+ 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224,
+ 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249,
+ 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274,
+ 1275, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, 1299,
+ 1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308, 1309, 1310, 1311, 1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319, 1320, 1321, 1322, 1323, 1324,
+ 1325, 1326, 1327, 1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349,
+ 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, 1370, 1371, 1372, 1373, 1374,
+ 1375, 1376, 1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399,
+ 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424,
+ 1425, 1426, 1427, 1428, 1429, 1430, 1431, 1432, 1433, 1434, 1435, 1436, 1437, 1438, 1439, 1440, 1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449,
+ 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474,
+ 1475, 1476, 1477, 1478, 1479, 1480, 1481, 1482, 1483, 1484, 1485, 1486, 1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499,
+ 1500, 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 1515, 1516, 1517, 1518, 1519, 1520, 1521, 1522, 1523, 1524,
+ 1525, 1526, 1527, 1528, 1529, 1530, 1531, 1532, 1533, 1534, 1535, 1536, 1537, 1538, 1539, 1540, 1541, 1542, 1543, 1544, 1545, 1546, 1547, 1548, 1549,
+ 1550, 1551, 1552, 1553, 1554, 1555, 1556, 1557, 1558, 1559, 1560, 1561, 1562, 1563, 1564, 1565, 1566, 1567, 1568, 1569, 1570, 1571, 1572, 1573, 1574,
+ 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583, 1584, 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, 1595, 1596, 1597, 1598, 1599,
+ 1600, 1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615, 1616, 1617, 1618, 1619, 1620, 1621, 1622, 1623, 1624,
+ 1625, 1626, 1627, 1628, 1629, 1630, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649,
+ 1650, 1651, 1652, 1653, 1654, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 1662, 1663, 1664, 1665, 1666, 1667, 1668, 1669, 1670, 1671, 1672, 1673, 1674,
+ 1675, 1676, 1677, 1678, 1679, 1680, 1681, 1682, 1683, 1684, 1685, 1686, 1687, 1688, 1689, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699,
+ 1700, 1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720, 1721, 1722, 1723, 1724,
+ 1725, 1726, 1727, 1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749,
+ 1750, 1751, 1752, 1753, 1754, 1755, 1756, 1757, 1758, 1759, 1760, 1761, 1762, 1763, 1764, 1765, 1766, 1767, 1768, 1769, 1770, 1771, 1772, 1773, 1774,
+ 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790, 1791, 1792, 1793, 1794, 1795, 1796, 1797, 1798, 1799,
+ 1800, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1810, 1811, 1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823, 1824,
+ 1825, 1826, 1827, 1828, 1829, 1830, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849,
+ 1850, 1851, 1852, 1853, 1854, 1855, 1856, 1857, 1858, 1859, 1860, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874,
+ 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899,
+ 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922, 1923, 1924,
+ 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949,
+ 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974,
+ 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024,
+ 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049,
+ 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074,
+ 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099,
+ 2100, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108, 2109, 2110, 2111, 2112, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121, 2122, 2123, 2124,
+ 2125, 2126, 2127, 2128, 2129, 2130, 2131, 2132, 2133, 2134, 2135, 2136, 2137, 2138, 2139, 2140, 2141, 2142, 2143, 2144, 2145, 2146, 2147, 2148, 2149,
+ 2150, 2151, 2152, 2153, 2154, 2155, 2156, 2157, 2158, 2159, 2160, 2161, 2162, 2163, 2164, 2165, 2166, 2167, 2168, 2169, 2170, 2171, 2172, 2173, 2174,
+ 2175, 2176, 2177, 2178, 2179, 2180, 2181, 2182, 2183, 2184, 2185, 2186, 2187, 2188, 2189, 2190, 2191, 2192, 2193, 2194, 2195, 2196, 2197, 2198, 2199,
+ 2200, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224,
+ 2225, 2226, 2227, 2228, 2229, 2230, 2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238, 2239, 2240, 2241, 2242, 2243, 2244, 2245, 2246, 2247, 2248, 2249,
+ 2250, 2251, 2252, 2253, 2254, 2255, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271, 2272, 2273, 2274,
+ 2275, 2276, 2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289, 2290, 2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299,
+ 2300, 2301, 2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312, 2313, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324,
+ 2325, 2326, 2327, 2328, 2329, 2330, 2331, 2332, 2333, 2334, 2335, 2336, 2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344, 2345, 2346, 2347, 2348, 2349,
+ 2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360, 2361, 2362, 2363, 2364, 2365, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374,
+ 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399,
+ 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, 2422, 2423, 2424,
+ 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2432, 2433, 2434, 2435, 2436, 2437, 2438, 2439, 2440, 2441, 2442, 2443, 2444, 2445, 2446, 2447, 2448, 2449,
+ 2450, 2451, 2452, 2453, 2454, 2455, 2456, 2457, 2458, 2459, 2460, 2461, 2462, 2463, 2464, 2465, 2466, 2467, 2468, 2469, 2470, 2471, 2472, 2473, 2474,
+ 2475, 2476, 2477, 2478, 2479, 2480, 2481, 2482, 2483, 2484, 2485, 2486, 2487, 2488, 2489, 2490, 2491, 2492, 2493, 2494, 2495, 2496, 2497, 2498, 2499,
+ 2500, 2501, 2502, 2503, 2504, 2505, 2506, 2507, 2508, 2509, 2510, 2511, 2512, 2513, 2514, 2515, 2516, 2517, 2518, 2519, 2520, 2521, 2522, 2523, 2524,
+ 2525, 2526, 2527, 2528, 2529, 2530, 2531, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2541, 2542, 2543, 2544, 2545, 2546, 2547, 2548, 2549,
+ 2550, 2551, 2552, 2553, 2554, 2555, 2556, 2557, 2558, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2567, 2568, 2569, 2570, 2571, 2572, 2573, 2574,
+ 2575, 2576, 2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, 2587, 2588, 2589, 2590, 2591, 2592, 2593, 2594, 2595, 2596, 2597, 2598, 2599,
+ 2600, 2601, 2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616, 2617, 2618, 2619, 2620, 2621, 2622, 2623, 2624,
+ 2625, 2626, 2627, 2628, 2629, 2630, 2631, 2632, 2633, 2634, 2635, 2636, 2637, 2638, 2639, 2640, 2641, 2642, 2643, 2644, 2645, 2646, 2647, 2648, 2649,
+ 2650, 2651, 2652, 2653, 2654, 2655, 2656, 2657, 2658, 2659, 2660, 2661, 2662, 2663, 2664, 2665, 2666, 2667, 2668, 2669, 2670, 2671, 2672, 2673, 2674,
+ 2675, 2676, 2677, 2678, 2679, 2680, 2681, 2682, 2683, 2684, 2685, 2686, 2687, 2688, 2689, 2690, 2691, 2692, 2693, 2694, 2695, 2696, 2697, 2698, 2699,
+ 2700, 2701, 2702, 2703, 2704, 2705, 2706, 2707, 2708, 2709, 2710, 2711, 2712, 2713, 2714, 2715, 2716, 2717, 2718, 2719, 2720, 2721, 2722, 2723, 2724,
+ 2725, 2726, 2727, 2728, 2729, 2730, 2731, 2732, 2733, 2734, 2735, 2736, 2737, 2738, 2739, 2740, 2741, 2742, 2743, 2744, 2745, 2746, 2747, 2748, 2749,
+ 2750, 2751, 2752, 2753, 2754, 2755, 2756, 2757, 2758, 2759, 2760, 2761, 2762, 2763, 2764, 2765, 2766, 2767, 2768, 2769, 2770, 2771, 2772, 2773, 2774,
+ 2775, 2776, 2777, 2778, 2779, 2780, 2781, 2782, 2783, 2784, 2785, 2786, 2787, 2788, 2789, 2790, 2791, 2792, 2793, 2794, 2795, 2796, 2797, 2798, 2799,
+ 2800, 2801, 2802, 2803, 2804, 2805, 2806, 2807, 2808, 2809, 2810, 2811, 2812, 2813, 2814, 2815, 2816, 2817, 2818, 2819, 2820, 2821, 2822, 2823, 2824,
+ 2825, 2826, 2827, 2828, 2829, 2830, 2831, 2832, 2833, 2834, 2835, 2836, 2837, 2838, 2839, 2840, 2841, 2842, 2843, 2844, 2845, 2846, 2847, 2848, 2849,
+ 2850, 2851, 2852, 2853, 2854, 2855, 2856, 2857, 2858, 2859, 2860, 2861, 2862, 2863, 2864, 2865, 2866, 2867, 2868, 2869, 2870, 2871, 2872, 2873, 2874,
+ 2875, 2876, 2877, 2878, 2879, 2880, 2881, 2882, 2883, 2884, 2885, 2886, 2887, 2888, 2889, 2890, 2891, 2892, 2893, 2894, 2895, 2896, 2897, 2898, 2899,
+ 2900, 2901, 2902, 2903, 2904, 2905, 2906, 2907, 2908, 2909, 2910, 2911, 2912, 2913, 2914, 2915, 2916, 2917, 2918, 2919, 2920, 2921, 2922, 2923, 2924,
+ 2925, 2926, 2927, 2928, 2929, 2930, 2931, 2932, 2933, 2934, 2935, 2936, 2937, 2938, 2939, 2940, 2941, 2942, 2943, 2944, 2945, 2946, 2947, 2948, 2949,
+ 2950, 2951, 2952, 2953, 2954, 2955, 2956, 2957, 2958, 2959, 2960, 2961, 2962, 2963, 2964, 2965, 2966, 2967, 2968, 2969, 2970, 2971, 2972, 2973, 2974,
+ 2975, 2976, 2977, 2978, 2979, 2980, 2981, 2982, 2983, 2984, 2985, 2986, 2987, 2988, 2989, 2990, 2991, 2992, 2993, 2994, 2995, 2996, 2997, 2998, 2999,
+ 3000, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019, 3020, 3021, 3022, 3023, 3024,
+ 3025, 3026, 3027, 3028, 3029, 3030, 3031, 3032, 3033, 3034, 3035, 3036, 3037, 3038, 3039, 3040, 3041, 3042, 3043, 3044, 3045, 3046, 3047, 3048, 3049,
+ 3050, 3051, 3052, 3053, 3054, 3055, 3056, 3057, 3058, 3059, 3060, 3061, 3062, 3063, 3064, 3065, 3066, 3067, 3068, 3069, 3070, 3071, 3072, 3073, 3074,
+ 3075, 3076, 3077, 3078, 3079, 3080, 3081, 3082, 3083, 3084, 3085, 3086, 3087, 3088, 3089, 3090, 3091, 3092, 3093, 3094, 3095, 3096, 3097, 3098, 3099,
+ 3100, 3101, 3102, 3103, 3104, 3105, 3106, 3107, 3108, 3109, 3110, 3111, 3112, 3113, 3114, 3115, 3116, 3117, 3118, 3119, 3120, 3121, 3122, 3123, 3124,
+ 3125, 3126, 3127, 3128, 3129, 3130, 3131, 3132, 3133, 3134, 3135, 3136, 3137, 3138, 3139, 3140, 3141, 3142, 3143, 3144, 3145, 3146, 3147, 3148, 3149,
+ 3150, 3151, 3152, 3153, 3154, 3155, 3156, 3157, 3158, 3159, 3160, 3161, 3162, 3163, 3164, 3165, 3166, 3167, 3168, 3169, 3170, 3171, 3172, 3173, 3174,
+ 3175, 3176, 3177, 3178, 3179, 3180, 3181, 3182, 3183, 3184, 3185, 3186, 3187, 3188, 3189, 3190, 3191, 3192, 3193, 3194, 3195, 3196, 3197, 3198, 3199,
+ 3200, 3201, 3202, 3203, 3204, 3205, 3206, 3207, 3208, 3209, 3210, 3211, 3212, 3213, 3214, 3215, 3216, 3217, 3218, 3219, 3220, 3221, 3222, 3223, 3224,
+ 3225, 3226, 3227, 3228, 3229, 3230, 3231, 3232, 3233, 3234, 3235, 3236, 3237, 3238, 3239, 3240, 3241, 3242, 3243, 3244, 3245, 3246, 3247, 3248, 3249,
+ 3250, 3251, 3252, 3253, 3254, 3255, 3256, 3257, 3258, 3259, 3260, 3261, 3262, 3263, 3264, 3265, 3266, 3267, 3268, 3269, 3270, 3271, 3272, 3273, 3274,
+ 3275, 3276, 3277, 3278, 3279, 3280, 3281, 3282, 3283, 3284, 3285, 3286, 3287, 3288, 3289, 3290, 3291, 3292, 3293, 3294, 3295, 3296, 3297, 3298, 3299,
+ 3300, 3301, 3302, 3303, 3304, 3305, 3306, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324,
+ 3325, 3326, 3327, 3328, 3329, 3330, 3331, 3332, 3333, 3334, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3344, 3345, 3346, 3347, 3348, 3349,
+ 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3357, 3358, 3359, 3360, 3361, 3362, 3363, 3364, 3365, 3366, 3367, 3368, 3369, 3370, 3371, 3372, 3373, 3374,
+ 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399,
+ 3400, 3401, 3402, 3403, 3404, 3405, 3406, 3407, 3408, 3409, 3410, 3411, 3412, 3413, 3414, 3415, 3416, 3417, 3418, 3419, 3420, 3421, 3422, 3423, 3424,
+ 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3433, 3434, 3435, 3436, 3437, 3438, 3439, 3440, 3441, 3442, 3443, 3444, 3445, 3446, 3447, 3448, 3449,
+ 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3457, 3458, 3459, 3460, 3461, 3462, 3463, 3464, 3465, 3466, 3467, 3468, 3469, 3470, 3471, 3472, 3473, 3474,
+ 3475, 3476, 3477, 3478, 3479, 3480, 3481, 3482, 3483, 3484, 3485, 3486, 3487, 3488, 3489, 3490, 3491, 3492, 3493, 3494, 3495, 3496, 3497, 3498, 3499,
+ 3500, 3501, 3502, 3503, 3504, 3505, 3506, 3507, 3508, 3509, 3510, 3511, 3512, 3513, 3514, 3515, 3516, 3517, 3518, 3519, 3520, 3521, 3522, 3523, 3524,
+ 3525, 3526, 3527, 3528, 3529, 3530, 3531, 3532, 3533, 3534, 3535, 3536, 3537, 3538, 3539, 3540, 3541, 3542, 3543, 3544, 3545, 3546, 3547, 3548, 3549,
+ 3550, 3551, 3552, 3553, 3554, 3555, 3556, 3557, 3558, 3559, 3560, 3561, 3562, 3563, 3564, 3565, 3566, 3567, 3568, 3569, 3570, 3571, 3572, 3573, 3574,
+ 3575, 3576, 3577, 3578, 3579, 3580, 3581, 3582, 3583, 3584, 3585, 3586, 3587, 3588, 3589, 3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599,
+ 3600, 3601, 3602, 3603, 3604, 3605, 3606, 3607, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3615, 3616, 3617, 3618, 3619, 3620, 3621, 3622, 3623, 3624,
+ 3625, 3626, 3627, 3628, 3629, 3630, 3631, 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, 3640, 3641, 3642, 3643, 3644, 3645, 3646, 3647, 3648, 3649,
+ 3650, 3651, 3652, 3653, 3654, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662, 3663, 3664, 3665, 3666, 3667, 3668, 3669, 3670, 3671, 3672, 3673, 3674,
+ 3675, 3676, 3677, 3678, 3679, 3680, 3681, 3682, 3683, 3684, 3685, 3686, 3687, 3688, 3689, 3690, 3691, 3692, 3693, 3694, 3695, 3696, 3697, 3698, 3699,
+ 3700, 3701, 3702, 3703, 3704, 3705, 3706, 3707, 3708, 3709, 3710, 3711, 3712, 3713, 3714, 3715, 3716, 3717, 3718, 3719, 3720, 3721, 3722, 3723, 3724,
+ 3725, 3726, 3727, 3728, 3729, 3730, 3731, 3732, 3733, 3734, 3735, 3736, 3737, 3738, 3739, 3740, 3741, 3742, 3743, 3744, 3745, 3746, 3747, 3748, 3749,
+ 3750, 3751, 3752, 3753, 3754, 3755, 3756, 3757, 3758, 3759, 3760, 3761, 3762, 3763, 3764, 3765, 3766, 3767, 3768, 3769, 3770, 3771, 3772, 3773, 3774,
+ 3775, 3776, 3777, 3778, 3779, 3780, 3781, 3782, 3783, 3784, 3785, 3786, 3787, 3788, 3789, 3790, 3791, 3792, 3793, 3794, 3795, 3796, 3797, 3798, 3799,
+ 3800, 3801, 3802, 3803, 3804, 3805, 3806, 3807, 3808, 3809, 3810, 3811, 3812, 3813, 3814, 3815, 3816, 3817, 3818, 3819, 3820, 3821, 3822, 3823, 3824,
+ 3825, 3826, 3827, 3828, 3829, 3830, 3831, 3832, 3833, 3834, 3835, 3836, 3837, 3838, 3839, 3840, 3841, 3842, 3843, 3844, 3845, 3846, 3847, 3848, 3849,
+ 3850, 3851, 3852, 3853, 3854, 3855, 3856, 3857, 3858, 3859, 3860, 3861, 3862, 3863, 3864, 3865, 3866, 3867, 3868, 3869, 3870, 3871, 3872, 3873, 3874,
+ 3875, 3876, 3877, 3878, 3879, 3880, 3881, 3882, 3883, 3884, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3894, 3895, 3896, 3897, 3898, 3899,
+ 3900, 3901, 3902, 3903, 3904, 3905, 3906, 3907, 3908, 3909, 3910, 3911, 3912, 3913, 3914, 3915, 3916, 3917, 3918, 3919, 3920, 3921, 3922, 3923, 3924,
+ 3925, 3926, 3927, 3928, 3929, 3930, 3931, 3932, 3933, 3934, 3935, 3936, 3937, 3938, 3939, 3940, 3941, 3942, 3943, 3944, 3945, 3946, 3947, 3948, 3949,
+ 3950, 3951, 3952, 3953, 3954, 3955, 3956, 3957, 3958, 3959, 3960, 3961, 3962, 3963, 3964, 3965, 3966, 3967, 3968, 3969, 3970, 3971, 3972, 3973, 3974,
+ 3975, 3976, 3977, 3978, 3979, 3980, 3981, 3982, 3983, 3984, 3985, 3986, 3987, 3988, 3989, 3990, 3991, 3992, 3993, 3994, 3995, 3996, 3997, 3998, 3999,
+ 4000, 4001, 4002, 4003, 4004, 4005, 4006, 4007, 4008, 4009, 4010, 4011, 4012, 4013, 4014, 4015, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024,
+ 4025, 4026, 4027, 4028, 4029, 4030, 4031, 4032, 4033, 4034, 4035, 4036, 4037, 4038, 4039, 4040, 4041, 4042, 4043, 4044, 4045, 4046, 4047, 4048, 4049,
+ 4050, 4051, 4052, 4053, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 4072, 4073, 4074,
+ 4075, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4084, 4085, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4093, 4094, 4095, 4096, 4097, 4098, 4099,
+ 4100, 4101, 4102, 4103, 4104, 4105, 4106, 4107, 4108, 4109, 4110, 4111, 4112, 4113, 4114, 4115, 4116, 4117, 4118, 4119, 4120, 4121, 4122, 4123, 4124,
+ 4125, 4126, 4127, 4128, 4129, 4130, 4131, 4132, 4133, 4134, 4135, 4136, 4137, 4138, 4139, 4140, 4141, 4142, 4143, 4144, 4145, 4146, 4147, 4148, 4149,
+ 4150, 4151, 4152, 4153, 4154, 4155, 4156, 4157, 4158, 4159, 4160, 4161, 4162, 4163, 4164, 4165, 4166, 4167, 4168, 4169, 4170, 4171, 4172, 4173, 4174,
+ 4175, 4176, 4177, 4178, 4179, 4180, 4181, 4182, 4183, 4184, 4185, 4186, 4187, 4188, 4189, 4190, 4191, 4192, 4193, 4194, 4195, 4196, 4197, 4198, 4199,
+ 4200, 4201, 4202, 4203, 4204, 4205, 4206, 4207, 4208, 4209, 4210, 4211, 4212, 4213, 4214, 4215, 4216, 4217, 4218, 4219, 4220, 4221, 4222, 4223, 4224,
+ 4225, 4226, 4227, 4228, 4229, 4230, 4231, 4232, 4233, 4234, 4235, 4236, 4237, 4238, 4239, 4240, 4241, 4242, 4243, 4244, 4245, 4246, 4247, 4248, 4249,
+ 4250, 4251, 4252, 4253, 4254, 4255, 4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274,
+ 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293, 4294, 4295, 4296, 4297, 4298, 4299,
+ 4300, 4301, 4302, 4303, 4304, 4305, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324,
+ 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 4347, 4348, 4349,
+ 4350, 4351, 4352, 4353, 4354, 4355, 4356, 4357, 4358, 4359, 4360, 4361, 4362, 4363, 4364, 4365, 4366, 4367, 4368, 4369, 4370, 4371, 4372, 4373, 4374,
+ 4375, 4376, 4377, 4378, 4379, 4380, 4381, 4382, 4383, 4384, 4385, 4386, 4387, 4388, 4389, 4390, 4391, 4392, 4393, 4394, 4395, 4396, 4397, 4398, 4399,
+ 4400, 4401, 4402, 4403, 4404, 4405, 4406, 4407, 4408, 4409, 4410, 4411, 4412, 4413, 4414, 4415, 4416, 4417, 4418, 4419, 4420, 4421, 4422, 4423, 4424,
+ 4425, 4426, 4427, 4428, 4429, 4430, 4431, 4432, 4433, 4434, 4435, 4436, 4437, 4438, 4439, 4440, 4441, 4442, 4443, 4444, 4445, 4446, 4447, 4448, 4449,
+ 4450, 4451, 4452, 4453, 4454, 4455, 4456, 4457, 4458, 4459, 4460, 4461, 4462, 4463, 4464, 4465, 4466, 4467, 4468, 4469, 4470, 4471, 4472, 4473, 4474,
+ 4475, 4476, 4477, 4478, 4479, 4480, 4481, 4482, 4483, 4484, 4485, 4486, 4487, 4488, 4489, 4490, 4491, 4492, 4493, 4494, 4495, 4496, 4497, 4498, 4499,
+ 4500, 4501, 4502, 4503, 4504, 4505, 4506, 4507, 4508, 4509, 4510, 4511, 4512, 4513, 4514, 4515, 4516, 4517, 4518, 4519, 4520, 4521, 4522, 4523, 4524,
+ 4525, 4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4535, 4536, 4537, 4538, 4539, 4540, 4541, 4542, 4543, 4544, 4545, 4546, 4547, 4548, 4549,
+ 4550, 4551, 4552, 4553, 4554, 4555, 4556, 4557, 4558, 4559, 4560, 4561, 4562, 4563, 4564, 4565, 4566, 4567, 4568, 4569, 4570, 4571, 4572, 4573, 4574,
+ 4575, 4576, 4577, 4578, 4579, 4580, 4581, 4582, 4583, 4584, 4585, 4586, 4587, 4588, 4589, 4590, 4591, 4592, 4593, 4594, 4595, 4596, 4597, 4598, 4599,
+ 4600, 4601, 4602, 4603, 4604, 4605, 4606, 4607, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624,
+ 4625, 4626, 4627, 4628, 4629, 4630, 4631, 4632, 4633, 4634, 4635, 4636, 4637, 4638, 4639, 4640, 4641, 4642, 4643, 4644, 4645, 4646, 4647, 4648, 4649,
+ 4650, 4651, 4652, 4653, 4654, 4655, 4656, 4657, 4658, 4659, 4660, 4661, 4662, 4663, 4664, 4665, 4666, 4667, 4668, 4669, 4670, 4671, 4672, 4673, 4674,
+ 4675, 4676, 4677, 4678, 4679, 4680, 4681, 4682, 4683, 4684, 4685, 4686, 4687, 4688, 4689, 4690, 4691, 4692, 4693, 4694, 4695, 4696, 4697, 4698, 4699,
+ 4700, 4701, 4702, 4703, 4704, 4705, 4706, 4707, 4708, 4709, 4710, 4711, 4712, 4713, 4714, 4715, 4716, 4717, 4718, 4719, 4720, 4721, 4722, 4723, 4724,
+ 4725, 4726, 4727, 4728, 4729, 4730, 4731, 4732, 4733, 4734, 4735, 4736, 4737, 4738, 4739, 4740, 4741, 4742, 4743, 4744, 4745, 4746, 4747, 4748, 4749,
+ 4750, 4751, 4752, 4753, 4754, 4755, 4756, 4757, 4758, 4759, 4760, 4761, 4762, 4763, 4764, 4765, 4766, 4767, 4768, 4769, 4770, 4771, 4772, 4773, 4774,
+ 4775, 4776, 4777, 4778, 4779, 4780, 4781, 4782, 4783, 4784, 4785, 4786, 4787, 4788, 4789, 4790, 4791, 4792, 4793, 4794, 4795, 4796, 4797, 4798, 4799,
+ 4800, 4801, 4802, 4803, 4804, 4805, 4806, 4807, 4808, 4809, 4810, 4811, 4812, 4813, 4814, 4815, 4816, 4817, 4818, 4819, 4820, 4821, 4822, 4823, 4824,
+ 4825, 4826, 4827, 4828, 4829, 4830, 4831, 4832, 4833, 4834, 4835, 4836, 4837, 4838, 4839, 4840, 4841, 4842, 4843, 4844, 4845, 4846, 4847, 4848, 4849,
+ 4850, 4851, 4852, 4853, 4854, 4855, 4856, 4857, 4858, 4859, 4860, 4861, 4862, 4863, 4864, 4865, 4866, 4867, 4868, 4869, 4870, 4871, 4872, 4873, 4874,
+ 4875, 4876, 4877, 4878, 4879, 4880, 4881, 4882, 4883, 4884, 4885, 4886, 4887, 4888, 4889, 4890, 4891, 4892, 4893, 4894, 4895, 4896, 4897, 4898, 4899,
+ 4900, 4901, 4902, 4903, 4904, 4905, 4906, 4907, 4908, 4909, 4910, 4911, 4912, 4913, 4914, 4915, 4916, 4917, 4918, 4919, 4920, 4921, 4922, 4923, 4924,
+ 4925, 4926, 4927, 4928, 4929, 4930, 4931, 4932, 4933, 4934, 4935, 4936, 4937, 4938, 4939, 4940, 4941, 4942, 4943, 4944, 4945, 4946, 4947, 4948, 4949,
+ 4950, 4951, 4952, 4953, 4954, 4955, 4956, 4957, 4958, 4959, 4960, 4961, 4962, 4963, 4964, 4965, 4966, 4967, 4968, 4969, 4970, 4971, 4972, 4973, 4974,
+ 4975, 4976, 4977, 4978, 4979, 4980, 4981, 4982, 4983, 4984, 4985, 4986, 4987, 4988, 4989, 4990, 4991, 4992, 4993, 4994, 4995, 4996, 4997, 4998, 4999,
+ 5000, 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5010, 5011, 5012, 5013, 5014, 5015, 5016, 5017, 5018, 5019, 5020, 5021, 5022, 5023, 5024,
+ 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5033, 5034, 5035, 5036, 5037, 5038, 5039, 5040, 5041, 5042, 5043, 5044, 5045, 5046, 5047, 5048, 5049,
+ 5050, 5051, 5052, 5053, 5054, 5055, 5056, 5057, 5058, 5059, 5060, 5061, 5062, 5063, 5064, 5065, 5066, 5067, 5068, 5069, 5070, 5071, 5072, 5073, 5074,
+ 5075, 5076, 5077, 5078, 5079, 5080, 5081, 5082, 5083, 5084, 5085, 5086, 5087, 5088, 5089, 5090, 5091, 5092, 5093, 5094, 5095, 5096, 5097, 5098, 5099,
+ 5100, 5101, 5102, 5103, 5104, 5105, 5106, 5107, 5108, 5109, 5110, 5111, 5112, 5113, 5114, 5115, 5116, 5117, 5118, 5119, 5120, 5121, 5122, 5123, 5124,
+ 5125, 5126, 5127, 5128, 5129, 5130, 5131, 5132, 5133, 5134, 5135, 5136, 5137, 5138, 5139, 5140, 5141, 5142, 5143, 5144, 5145, 5146, 5147, 5148, 5149,
+ 5150, 5151, 5152, 5153, 5154, 5155, 5156, 5157, 5158, 5159, 5160, 5161, 5162, 5163, 5164, 5165, 5166, 5167, 5168, 5169, 5170, 5171, 5172, 5173, 5174,
+ 5175, 5176, 5177, 5178, 5179, 5180, 5181, 5182, 5183, 5184, 5185, 5186, 5187, 5188, 5189, 5190, 5191, 5192, 5193, 5194, 5195, 5196, 5197, 5198, 5199,
+ 5200, 5201, 5202, 5203, 5204, 5205, 5206, 5207, 5208, 5209, 5210, 5211, 5212, 5213, 5214, 5215, 5216, 5217, 5218, 5219, 5220, 5221, 5222, 5223, 5224,
+ 5225, 5226, 5227, 5228, 5229, 5230, 5231, 5232, 5233, 5234, 5235, 5236, 5237, 5238, 5239, 5240, 5241, 5242, 5243, 5244, 5245, 5246, 5247, 5248, 5249,
+ 5250, 5251, 5252, 5253, 5254, 5255, 5256, 5257, 5258, 5259, 5260, 5261, 5262, 5263, 5264, 5265, 5266, 5267, 5268, 5269, 5270, 5271, 5272, 5273, 5274,
+ 5275, 5276, 5277, 5278, 5279, 5280, 5281, 5282, 5283, 5284, 5285, 5286, 5287, 5288, 5289, 5290, 5291, 5292, 5293, 5294, 5295, 5296, 5297, 5298, 5299,
+ 5300, 5301, 5302, 5303, 5304, 5305, 5306, 5307, 5308, 5309, 5310, 5311, 5312, 5313, 5314, 5315, 5316, 5317, 5318, 5319, 5320, 5321, 5322, 5323, 5324,
+ 5325, 5326, 5327, 5328, 5329, 5330, 5331, 5332, 5333, 5334, 5335, 5336, 5337, 5338, 5339, 5340, 5341, 5342, 5343, 5344, 5345, 5346, 5347, 5348, 5349,
+ 5350, 5351, 5352, 5353, 5354, 5355, 5356, 5357, 5358, 5359, 5360, 5361, 5362, 5363, 5364, 5365, 5366, 5367, 5368, 5369, 5370, 5371, 5372, 5373, 5374,
+ 5375, 5376, 5377, 5378, 5379, 5380, 5381, 5382, 5383, 5384, 5385, 5386, 5387, 5388, 5389, 5390, 5391, 5392, 5393, 5394, 5395, 5396, 5397, 5398, 5399,
+ 5400, 5401, 5402, 5403, 5404, 5405, 5406, 5407, 5408, 5409, 5410, 5411, 5412, 5413, 5414, 5415, 5416, 5417, 5418, 5419, 5420, 5421, 5422, 5423, 5424,
+ 5425, 5426, 5427, 5428, 5429, 5430, 5431, 5432, 5433, 5434, 5435, 5436, 5437, 5438, 5439, 5440, 5441, 5442, 5443, 5444, 5445, 5446, 5447, 5448, 5449,
+ 5450, 5451, 5452, 5453, 5454, 5455, 5456, 5457, 5458, 5459, 5460, 5461, 5462, 5463, 5464, 5465, 5466, 5467, 5468, 5469, 5470, 5471, 5472, 5473, 5474,
+ 5475, 5476, 5477, 5478, 5479, 5480, 5481, 5482, 5483, 5484, 5485, 5486, 5487, 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495, 5496, 5497, 5498, 5499,
+ 5500, 5501, 5502, 5503, 5504, 5505, 5506, 5507, 5508, 5509, 5510, 5511, 5512, 5513, 5514, 5515, 5516, 5517, 5518, 5519, 5520, 5521, 5522, 5523, 5524,
+ 5525, 5526, 5527, 5528, 5529, 5530, 5531, 5532, 5533, 5534, 5535, 5536, 5537, 5538, 5539, 5540, 5541, 5542, 5543, 5544, 5545, 5546, 5547, 5548, 5549,
+ 5550, 5551, 5552, 5553, 5554, 5555, 5556, 5557, 5558, 5559, 5560, 5561, 5562, 5563, 5564, 5565, 5566, 5567, 5568, 5569, 5570, 5571, 5572, 5573, 5574,
+ 5575, 5576, 5577, 5578, 5579, 5580, 5581, 5582, 5583, 5584, 5585, 5586, 5587, 5588, 5589, 5590, 5591, 5592, 5593, 5594, 5595, 5596, 5597, 5598, 5599,
+ 5600, 5601, 5602, 5603, 5604, 5605, 5606, 5607, 5608, 5609, 5610, 5611, 5612, 5613, 5614, 5615, 5616, 5617, 5618, 5619, 5620, 5621, 5622, 5623, 5624,
+ 5625, 5626, 5627, 5628, 5629, 5630, 5631, 5632, 5633, 5634, 5635, 5636, 5637, 5638, 5639, 5640, 5641, 5642, 5643, 5644, 5645, 5646, 5647, 5648, 5649,
+ 5650, 5651, 5652, 5653, 5654, 5655, 5656, 5657, 5658, 5659, 5660, 5661, 5662, 5663, 5664, 5665, 5666, 5667, 5668, 5669, 5670, 5671, 5672, 5673, 5674,
+ 5675, 5676, 5677, 5678, 5679, 5680, 5681, 5682, 5683, 5684, 5685, 5686, 5687, 5688, 5689, 5690, 5691, 5692, 5693, 5694, 5695, 5696, 5697, 5698, 5699,
+ 5700, 5701, 5702, 5703, 5704, 5705, 5706, 5707, 5708, 5709, 5710, 5711, 5712, 5713, 5714, 5715, 5716, 5717, 5718, 5719, 5720, 5721, 5722, 5723, 5724,
+ 5725, 5726, 5727, 5728, 5729, 5730, 5731, 5732, 5733, 5734, 5735, 5736, 5737, 5738, 5739, 5740, 5741, 5742, 5743, 5744, 5745, 5746, 5747, 5748, 5749,
+ 5750, 5751, 5752, 5753, 5754, 5755, 5756, 5757, 5758, 5759, 5760, 5761, 5762, 5763, 5764, 5765, 5766, 5767, 5768, 5769, 5770, 5771, 5772, 5773, 5774,
+ 5775, 5776, 5777, 5778, 5779, 5780, 5781, 5782, 5783, 5784, 5785, 5786, 5787, 5788, 5789, 5790, 5791, 5792, 5793, 5794, 5795, 5796, 5797, 5798, 5799,
+ 5800, 5801, 5802, 5803, 5804, 5805, 5806, 5807, 5808, 5809, 5810, 5811, 5812, 5813, 5814, 5815, 5816, 5817, 5818, 5819, 5820, 5821, 5822, 5823, 5824,
+ 5825, 5826, 5827, 5828, 5829, 5830, 5831, 5832, 5833, 5834, 5835, 5836, 5837, 5838, 5839, 5840, 5841, 5842, 5843, 5844, 5845, 5846, 5847, 5848, 5849,
+ 5850, 5851, 5852, 5853, 5854, 5855, 5856, 5857, 5858, 5859, 5860, 5861, 5862, 5863, 5864, 5865, 5866, 5867, 5868, 5869, 5870, 5871, 5872, 5873, 5874,
+ 5875, 5876, 5877, 5878, 5879, 5880, 5881, 5882, 5883, 5884, 5885, 5886, 5887, 5888, 5889, 5890, 5891, 5892, 5893, 5894, 5895, 5896, 5897, 5898, 5899,
+ 5900, 5901, 5902, 5903, 5904, 5905, 5906, 5907, 5908, 5909, 5910, 5911, 5912, 5913, 5914, 5915, 5916, 5917, 5918, 5919, 5920, 5921, 5922, 5923, 5924,
+ 5925, 5926, 5927, 5928, 5929, 5930, 5931, 5932, 5933, 5934, 5935, 5936, 5937, 5938, 5939, 5940, 5941, 5942, 5943, 5944, 5945, 5946, 5947, 5948, 5949,
+ 5950, 5951, 5952, 5953, 5954, 5955, 5956, 5957, 5958, 5959, 5960, 5961, 5962, 5963, 5964, 5965, 5966, 5967, 5968, 5969, 5970, 5971, 5972, 5973, 5974,
+ 5975, 5976, 5977, 5978, 5979, 5980, 5981, 5982, 5983, 5984, 5985, 5986, 5987, 5988, 5989, 5990, 5991, 5992, 5993, 5994, 5995, 5996, 5997, 5998, 5999,
+ 6000, 6001, 6002, 6003, 6004, 6005, 6006, 6007, 6008, 6009, 6010, 6011, 6012, 6013, 6014, 6015, 6016, 6017, 6018, 6019, 6020, 6021, 6022, 6023, 6024,
+ 6025, 6026, 6027, 6028, 6029, 6030, 6031, 6032, 6033, 6034, 6035, 6036, 6037, 6038, 6039, 6040, 6041, 6042, 6043, 6044, 6045, 6046, 6047, 6048, 6049,
+ 6050, 6051, 6052, 6053, 6054, 6055, 6056, 6057, 6058, 6059, 6060, 6061, 6062, 6063, 6064, 6065, 6066, 6067, 6068, 6069, 6070, 6071, 6072, 6073, 6074,
+ 6075, 6076, 6077, 6078, 6079, 6080, 6081, 6082, 6083, 6084, 6085, 6086, 6087, 6088, 6089, 6090, 6091, 6092, 6093, 6094, 6095, 6096, 6097, 6098, 6099,
+ 6100, 6101, 6102, 6103, 6104, 6105, 6106, 6107, 6108, 6109, 6110, 6111, 6112, 6113, 6114, 6115, 6116, 6117, 6118, 6119, 6120, 6121, 6122, 6123, 6124,
+ 6125, 6126, 6127, 6128, 6129, 6130, 6131, 6132, 6133, 6134, 6135, 6136, 6137, 6138, 6139, 6140, 6141, 6142, 6143, 6144, 6145, 6146, 6147, 6148, 6149,
+ 6150, 6151, 6152, 6153, 6154, 6155, 6156, 6157, 6158, 6159, 6160, 6161, 6162, 6163, 6164, 6165, 6166, 6167, 6168, 6169, 6170, 6171, 6172, 6173, 6174,
+ 6175, 6176, 6177, 6178, 6179, 6180, 6181, 6182, 6183, 6184, 6185, 6186, 6187, 6188, 6189, 6190, 6191, 6192, 6193, 6194, 6195, 6196, 6197, 6198, 6199,
+ 6200, 6201, 6202, 6203, 6204, 6205, 6206, 6207, 6208, 6209, 6210, 6211, 6212, 6213, 6214, 6215, 6216, 6217, 6218, 6219, 6220, 6221, 6222, 6223, 6224,
+ 6225, 6226, 6227, 6228, 6229, 6230, 6231, 6232, 6233, 6234, 6235, 6236, 6237, 6238, 6239, 6240, 6241, 6242, 6243, 6244, 6245, 6246, 6247, 6248, 6249,
+ 6250, 6251, 6252, 6253, 6254, 6255, 6256, 6257, 6258, 6259, 6260, 6261, 6262, 6263, 6264, 6265, 6266, 6267, 6268, 6269, 6270, 6271, 6272, 6273, 6274,
+ 6275, 6276, 6277, 6278, 6279, 6280, 6281, 6282, 6283, 6284, 6285, 6286, 6287, 6288, 6289, 6290, 6291, 6292, 6293, 6294, 6295, 6296, 6297, 6298, 6299,
+ 6300, 6301, 6302, 6303, 6304, 6305, 6306, 6307, 6308, 6309, 6310, 6311, 6312, 6313, 6314, 6315, 6316, 6317, 6318, 6319, 6320, 6321, 6322, 6323, 6324,
+ 6325, 6326, 6327, 6328, 6329, 6330, 6331, 6332, 6333, 6334, 6335, 6336, 6337, 6338, 6339, 6340, 6341, 6342, 6343, 6344, 6345, 6346, 6347, 6348, 6349,
+ 6350, 6351, 6352, 6353, 6354, 6355, 6356, 6357, 6358, 6359, 6360, 6361, 6362, 6363, 6364, 6365, 6366, 6367, 6368, 6369, 6370, 6371, 6372, 6373, 6374,
+ 6375, 6376, 6377, 6378, 6379, 6380, 6381, 6382, 6383, 6384, 6385, 6386, 6387, 6388, 6389, 6390, 6391, 6392, 6393, 6394, 6395, 6396, 6397, 6398, 6399,
+ 6400, 6401, 6402, 6403, 6404, 6405, 6406, 6407, 6408, 6409, 6410, 6411, 6412, 6413, 6414, 6415, 6416, 6417, 6418, 6419, 6420, 6421, 6422, 6423, 6424,
+ 6425, 6426, 6427, 6428, 6429, 6430, 6431, 6432, 6433, 6434, 6435, 6436, 6437, 6438, 6439, 6440, 6441, 6442, 6443, 6444, 6445, 6446, 6447, 6448, 6449,
+ 6450, 6451, 6452, 6453, 6454, 6455, 6456, 6457, 6458, 6459, 6460, 6461, 6462, 6463, 6464, 6465, 6466, 6467, 6468, 6469, 6470, 6471, 6472, 6473, 6474,
+ 6475, 6476, 6477, 6478, 6479, 6480, 6481, 6482, 6483, 6484, 6485, 6486, 6487, 6488, 6489, 6490, 6491, 6492, 6493, 6494, 6495, 6496, 6497, 6498, 6499,
+ 6500, 6501, 6502, 6503, 6504, 6505, 6506, 6507, 6508, 6509, 6510, 6511, 6512, 6513, 6514, 6515, 6516, 6517, 6518, 6519, 6520, 6521, 6522, 6523, 6524,
+ 6525, 6526, 6527, 6528, 6529, 6530, 6531, 6532, 6533, 6534, 6535, 6536, 6537, 6538, 6539, 6540, 6541, 6542, 6543, 6544, 6545, 6546, 6547, 6548, 6549,
+ 6550, 6551, 6552, 6553, 6554, 6555, 6556, 6557, 6558, 6559, 6560, 6561, 6562, 6563, 6564, 6565, 6566, 6567, 6568, 6569, 6570, 6571, 6572, 6573, 6574,
+ 6575, 6576, 6577, 6578, 6579, 6580, 6581, 6582, 6583, 6584, 6585, 6586, 6587, 6588, 6589, 6590, 6591, 6592, 6593, 6594, 6595, 6596, 6597, 6598, 6599,
+ 6600, 6601, 6602, 6603, 6604, 6605, 6606, 6607, 6608, 6609, 6610, 6611, 6612, 6613, 6614, 6615, 6616, 6617, 6618, 6619, 6620, 6621, 6622, 6623, 6624,
+ 6625, 6626, 6627, 6628, 6629, 6630, 6631, 6632, 6633, 6634, 6635, 6636, 6637, 6638, 6639, 6640, 6641, 6642, 6643, 6644, 6645, 6646, 6647, 6648, 6649,
+ 6650, 6651, 6652, 6653, 6654, 6655, 6656, 6657, 6658, 6659, 6660, 6661, 6662, 6663, 6664, 6665, 6666, 6667, 6668, 6669, 6670, 6671, 6672, 6673, 6674,
+ 6675, 6676, 6677, 6678, 6679, 6680, 6681, 6682, 6683, 6684, 6685, 6686, 6687, 6688, 6689, 6690, 6691, 6692, 6693, 6694, 6695, 6696, 6697, 6698, 6699,
+ 6700, 6701, 6702, 6703, 6704, 6705, 6706, 6707, 6708, 6709, 6710, 6711, 6712, 6713, 6714, 6715, 6716, 6717, 6718, 6719, 6720, 6721, 6722, 6723, 6724,
+ 6725, 6726, 6727, 6728, 6729, 6730, 6731, 6732, 6733, 6734, 6735, 6736, 6737, 6738, 6739, 6740, 6741, 6742, 6743, 6744, 6745, 6746, 6747, 6748, 6749,
+ 6750, 6751, 6752, 6753, 6754, 6755, 6756, 6757, 6758, 6759, 6760, 6761, 6762, 6763, 6764, 6765, 6766, 6767, 6768, 6769, 6770, 6771, 6772, 6773, 6774,
+ 6775, 6776, 6777, 6778, 6779, 6780, 6781, 6782, 6783, 6784, 6785, 6786, 6787, 6788, 6789, 6790, 6791, 6792, 6793, 6794, 6795, 6796, 6797, 6798, 6799,
+ 6800, 6801, 6802, 6803, 6804, 6805, 6806, 6807, 6808, 6809, 6810, 6811, 6812, 6813, 6814, 6815, 6816, 6817, 6818, 6819, 6820, 6821, 6822, 6823, 6824,
+ 6825, 6826, 6827, 6828, 6829, 6830, 6831, 6832, 6833, 6834, 6835, 6836, 6837, 6838, 6839, 6840, 6841, 6842, 6843, 6844, 6845, 6846, 6847, 6848, 6849,
+ 6850, 6851, 6852, 6853, 6854, 6855, 6856, 6857, 6858, 6859, 6860, 6861, 6862, 6863, 6864, 6865, 6866, 6867, 6868, 6869, 6870, 6871, 6872, 6873, 6874,
+ 6875, 6876, 6877, 6878, 6879, 6880, 6881, 6882, 6883, 6884, 6885, 6886, 6887, 6888, 6889, 6890, 6891, 6892, 6893, 6894, 6895, 6896, 6897, 6898, 6899,
+ 6900, 6901, 6902, 6903, 6904, 6905, 6906, 6907, 6908, 6909, 6910, 6911, 6912, 6913, 6914, 6915, 6916, 6917, 6918, 6919, 6920, 6921, 6922, 6923, 6924,
+ 6925, 6926, 6927, 6928, 6929, 6930, 6931, 6932, 6933, 6934, 6935, 6936, 6937, 6938, 6939, 6940, 6941, 6942, 6943, 6944, 6945, 6946, 6947, 6948, 6949,
+ 6950, 6951, 6952, 6953, 6954, 6955, 6956, 6957, 6958, 6959, 6960, 6961, 6962, 6963, 6964, 6965, 6966, 6967, 6968, 6969, 6970, 6971, 6972, 6973, 6974,
+ 6975, 6976, 6977, 6978, 6979, 6980, 6981, 6982, 6983, 6984, 6985, 6986, 6987, 6988, 6989, 6990, 6991, 6992, 6993, 6994, 6995, 6996, 6997, 6998, 6999,
+ 7000, 7001, 7002, 7003, 7004, 7005, 7006, 7007, 7008, 7009, 7010, 7011, 7012, 7013, 7014, 7015, 7016, 7017, 7018, 7019, 7020, 7021, 7022, 7023, 7024,
+ 7025, 7026, 7027, 7028, 7029, 7030, 7031, 7032, 7033, 7034, 7035, 7036, 7037, 7038, 7039, 7040, 7041, 7042, 7043, 7044, 7045, 7046, 7047, 7048, 7049,
+ 7050, 7051, 7052, 7053, 7054, 7055, 7056, 7057, 7058, 7059, 7060, 7061, 7062, 7063, 7064, 7065, 7066, 7067, 7068, 7069, 7070, 7071, 7072, 7073, 7074,
+ 7075, 7076, 7077, 7078, 7079, 7080, 7081, 7082, 7083, 7084, 7085, 7086, 7087, 7088, 7089, 7090, 7091, 7092, 7093, 7094, 7095, 7096, 7097, 7098, 7099,
+ 7100, 7101, 7102, 7103, 7104, 7105, 7106, 7107, 7108, 7109, 7110, 7111, 7112, 7113, 7114, 7115, 7116, 7117, 7118, 7119, 7120, 7121, 7122, 7123, 7124,
+ 7125, 7126, 7127, 7128, 7129, 7130, 7131, 7132, 7133, 7134, 7135, 7136, 7137, 7138, 7139, 7140, 7141, 7142, 7143, 7144, 7145, 7146, 7147, 7148, 7149,
+ 7150, 7151, 7152, 7153, 7154, 7155, 7156, 7157, 7158, 7159, 7160, 7161, 7162, 7163, 7164, 7165, 7166, 7167, 7168, 7169, 7170, 7171, 7172, 7173, 7174,
+ 7175, 7176, 7177, 7178, 7179, 7180, 7181, 7182, 7183, 7184, 7185, 7186, 7187, 7188, 7189, 7190, 7191, 7192, 7193, 7194, 7195, 7196, 7197, 7198, 7199,
+ 7200, 7201, 7202, 7203, 7204, 7205, 7206, 7207, 7208, 7209, 7210, 7211, 7212, 7213, 7214, 7215, 7216, 7217, 7218, 7219, 7220, 7221, 7222, 7223, 7224,
+ 7225, 7226, 7227, 7228, 7229, 7230, 7231, 7232, 7233, 7234, 7235, 7236, 7237, 7238, 7239, 7240, 7241, 7242, 7243, 7244, 7245, 7246, 7247, 7248, 7249,
+ 7250, 7251, 7252, 7253, 7254, 7255, 7256, 7257, 7258, 7259, 7260, 7261, 7262, 7263, 7264, 7265, 7266, 7267, 7268, 7269, 7270, 7271, 7272, 7273, 7274,
+ 7275, 7276, 7277, 7278, 7279, 7280, 7281, 7282, 7283, 7284, 7285, 7286, 7287, 7288, 7289, 7290, 7291, 7292, 7293, 7294, 7295, 7296, 7297, 7298, 7299,
+ 7300, 7301, 7302, 7303, 7304, 7305, 7306, 7307, 7308, 7309, 7310, 7311, 7312, 7313, 7314, 7315, 7316, 7317, 7318, 7319, 7320, 7321, 7322, 7323, 7324,
+ 7325, 7326, 7327, 7328, 7329, 7330, 7331, 7332, 7333, 7334, 7335, 7336, 7337, 7338, 7339, 7340, 7341, 7342, 7343, 7344, 7345, 7346, 7347, 7348, 7349,
+ 7350, 7351, 7352, 7353, 7354, 7355, 7356, 7357, 7358, 7359, 7360, 7361, 7362, 7363, 7364, 7365, 7366, 7367, 7368, 7369, 7370, 7371, 7372, 7373, 7374,
+ 7375, 7376, 7377, 7378, 7379, 7380, 7381, 7382, 7383, 7384, 7385, 7386, 7387, 7388, 7389, 7390, 7391, 7392, 7393, 7394, 7395, 7396, 7397, 7398, 7399,
+ 7400, 7401, 7402, 7403, 7404, 7405, 7406, 7407, 7408, 7409, 7410, 7411, 7412, 7413, 7414, 7415, 7416, 7417, 7418, 7419, 7420, 7421, 7422, 7423, 7424,
+ 7425, 7426, 7427, 7428, 7429, 7430, 7431, 7432, 7433, 7434, 7435, 7436, 7437, 7438, 7439, 7440, 7441, 7442, 7443, 7444, 7445, 7446, 7447, 7448, 7449,
+ 7450, 7451, 7452, 7453, 7454, 7455, 7456, 7457, 7458, 7459, 7460, 7461, 7462, 7463, 7464, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 7474,
+ 7475, 7476, 7477, 7478, 7479, 7480, 7481, 7482, 7483, 7484, 7485, 7486, 7487, 7488, 7489, 7490, 7491, 7492, 7493, 7494, 7495, 7496, 7497, 7498, 7499,
+ 7500, 7501, 7502, 7503, 7504, 7505, 7506, 7507, 7508, 7509, 7510, 7511, 7512, 7513, 7514, 7515, 7516, 7517, 7518, 7519, 7520, 7521, 7522, 7523, 7524,
+ 7525, 7526, 7527, 7528, 7529, 7530, 7531, 7532, 7533, 7534, 7535, 7536, 7537, 7538, 7539, 7540, 7541, 7542, 7543, 7544, 7545, 7546, 7547, 7548, 7549,
+ 7550, 7551, 7552, 7553, 7554, 7555, 7556, 7557, 7558, 7559, 7560, 7561, 7562, 7563, 7564, 7565, 7566, 7567, 7568, 7569, 7570, 7571, 7572, 7573, 7574,
+ 7575, 7576, 7577, 7578, 7579, 7580, 7581, 7582, 7583, 7584, 7585, 7586, 7587, 7588, 7589, 7590, 7591, 7592, 7593, 7594, 7595, 7596, 7597, 7598, 7599,
+ 7600, 7601, 7602, 7603, 7604, 7605, 7606, 7607, 7608, 7609, 7610, 7611, 7612, 7613, 7614, 7615, 7616, 7617, 7618, 7619, 7620, 7621, 7622, 7623, 7624,
+ 7625, 7626, 7627, 7628, 7629, 7630, 7631, 7632, 7633, 7634, 7635, 7636, 7637, 7638, 7639, 7640, 7641, 7642, 7643, 7644, 7645, 7646, 7647, 7648, 7649,
+ 7650, 7651, 7652, 7653, 7654, 7655, 7656, 7657, 7658, 7659, 7660, 7661, 7662, 7663, 7664, 7665, 7666, 7667, 7668, 7669, 7670, 7671, 7672, 7673, 7674,
+ 7675, 7676, 7677, 7678, 7679, 7680, 7681, 7682, 7683, 7684, 7685, 7686, 7687, 7688, 7689, 7690, 7691, 7692, 7693, 7694, 7695, 7696, 7697, 7698, 7699,
+ 7700, 7701, 7702, 7703, 7704, 7705, 7706, 7707, 7708, 7709, 7710, 7711, 7712, 7713, 7714, 7715, 7716, 7717, 7718, 7719, 7720, 7721, 7722, 7723, 7724,
+ 7725, 7726, 7727, 7728, 7729, 7730, 7731, 7732, 7733, 7734, 7735, 7736, 7737, 7738, 7739, 7740, 7741, 7742, 7743, 7744, 7745, 7746, 7747, 7748, 7749,
+ 7750, 7751, 7752, 7753, 7754, 7755, 7756, 7757, 7758, 7759, 7760, 7761, 7762, 7763, 7764, 7765, 7766, 7767, 7768, 7769, 7770, 7771, 7772, 7773, 7774,
+ 7775, 7776, 7777, 7778, 7779, 7780, 7781, 7782, 7783, 7784, 7785, 7786, 7787, 7788, 7789, 7790, 7791, 7792, 7793, 7794, 7795, 7796, 7797, 7798, 7799,
+ 7800, 7801, 7802, 7803, 7804, 7805, 7806, 7807, 7808, 7809, 7810, 7811, 7812, 7813, 7814, 7815, 7816, 7817, 7818, 7819, 7820, 7821, 7822, 7823, 7824,
+ 7825, 7826, 7827, 7828, 7829, 7830, 7831, 7832, 7833, 7834, 7835, 7836, 7837, 7838, 7839, 7840, 7841, 7842, 7843, 7844, 7845, 7846, 7847, 7848, 7849,
+ 7850, 7851, 7852, 7853, 7854, 7855, 7856, 7857, 7858, 7859, 7860, 7861, 7862, 7863, 7864, 7865, 7866, 7867, 7868, 7869, 7870, 7871, 7872, 7873, 7874,
+ 7875, 7876, 7877, 7878, 7879, 7880, 7881, 7882, 7883, 7884, 7885, 7886, 7887, 7888, 7889, 7890, 7891, 7892, 7893, 7894, 7895, 7896, 7897, 7898, 7899,
+ 7900, 7901, 7902, 7903, 7904, 7905, 7906, 7907, 7908, 7909, 7910, 7911, 7912, 7913, 7914, 7915, 7916, 7917, 7918, 7919, 7920, 7921, 7922, 7923, 7924,
+ 7925, 7926, 7927, 7928, 7929, 7930, 7931, 7932, 7933, 7934, 7935, 7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943, 7944, 7945, 7946, 7947, 7948, 7949,
+ 7950, 7951, 7952, 7953, 7954, 7955, 7956, 7957, 7958, 7959, 7960, 7961, 7962, 7963, 7964, 7965, 7966, 7967, 7968, 7969, 7970, 7971, 7972, 7973, 7974,
+ 7975, 7976, 7977, 7978, 7979, 7980, 7981, 7982, 7983, 7984, 7985, 7986, 7987, 7988, 7989, 7990, 7991, 7992, 7993, 7994, 7995, 7996, 7997, 7998, 7999,
+ 8000, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009, 8010, 8011, 8012, 8013, 8014, 8015, 8016, 8017, 8018, 8019, 8020, 8021, 8022, 8023, 8024,
+ 8025, 8026, 8027, 8028, 8029, 8030, 8031, 8032, 8033, 8034, 8035, 8036, 8037, 8038, 8039, 8040, 8041, 8042, 8043, 8044, 8045, 8046, 8047, 8048, 8049,
+ 8050, 8051, 8052, 8053, 8054, 8055, 8056, 8057, 8058, 8059, 8060, 8061, 8062, 8063, 8064, 8065, 8066, 8067, 8068, 8069, 8070, 8071, 8072, 8073, 8074,
+ 8075, 8076, 8077, 8078, 8079, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099,
+ 8100, 8101, 8102, 8103, 8104, 8105, 8106, 8107, 8108, 8109, 8110, 8111, 8112, 8113, 8114, 8115, 8116, 8117, 8118, 8119, 8120, 8121, 8122, 8123, 8124,
+ 8125, 8126, 8127, 8128, 8129, 8130, 8131, 8132, 8133, 8134, 8135, 8136, 8137, 8138, 8139, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149,
+ 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 8159, 8160, 8161, 8162, 8163, 8164, 8165, 8166, 8167, 8168, 8169, 8170, 8171, 8172, 8173, 8174,
+ 8175, 8176, 8177, 8178, 8179, 8180, 8181, 8182, 8183, 8184, 8185, 8186, 8187, 8188, 8189, 8190, 8191, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199,
+
+};
+
+
+
+/* Indique la taille maximale des suites d'octets recherchées. */
+size_t g_hyperscan_backend_get_atom_max_size(const GHyperscanBackend *);
+
+/* Inscrit dans le moteur une chaîne de caractères à rechercher. */
+static bool g_hyperscan_backend_enroll_plain_pattern(GHyperscanBackend *, const uint8_t *, size_t, uint32_t [2]);
+
+/* Met en ordre les derniers détails avant un premier scan. */
+static bool g_hyperscan_backend_warm_up(GHyperscanBackend *);
+
+/* Récupère les identifiants finaux pour un motif recherché. */
+static patid_t g_hyperscan_backend_build_plain_pattern_id(const GHyperscanBackend *, const uint32_t [2]);
+
+/* Détermine le nombre d'identifiants constitués. */
+static size_t g_hyperscan_backend_count_plain_pattern_ids(const GHyperscanBackend *);
+
+/* Informations utiles au traitement d'un événement */
+typedef struct _hyperscan_context_t
+{
+ const size_t *lengths; /* Nombre d'octets considérés */
+ const uint32_t *coverages; /* Départ et quantité de suivis*/
+
+#ifndef NDEBUG
+ size_t used; /* Nombre d'éléments utiles */
+ const unsigned int *lit_ids; /* Identifiants internes */
+#endif
+
+ GUMemSlice **matches; /* Zones d'enregistrements */
+
+} hyperscan_context_t;
+
+/* Prend note d'une correspondance trouvée par Hyperscan. */
+static int handle_hyperscan_match_event(unsigned int, unsigned long long, unsigned long long, unsigned int, GScanContext *context/*const hyperscan_context_t *context*/);
+
+/* Parcours un contenu binaire à la recherche de motifs. */
+static void g_hyperscan_backend_run_scan(const GHyperscanBackend *, GScanContext *);
+
+/* Imprime quelques faits quant aux éléments mis en place. */
+static void g_hyperscan_backend_output_stats(const GHyperscanBackend *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLANTATION D'UNE NOUVELLE APPROCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour un moteur de recherche pour données. */
+G_DEFINE_TYPE(GHyperscanBackend, g_hyperscan_backend, G_TYPE_ENGINE_BACKEND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des méthodes basée sur Hyperscan. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hyperscan_backend_class_init(GHyperscanBackendClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GEngineBackendClass *backend; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_hyperscan_backend_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_hyperscan_backend_finalize;
+
+ backend = G_ENGINE_BACKEND_CLASS(klass);
+
+ backend->get_max_size = (get_backend_atom_max_size_fc)g_hyperscan_backend_get_atom_max_size;
+ backend->enroll_plain = (enroll_plain_into_backend_fc)g_hyperscan_backend_enroll_plain_pattern;
+ backend->warm_up = (warm_up_backend_fc)g_hyperscan_backend_warm_up;
+ backend->build_id = (build_backend_plain_pattern_id_fc)g_hyperscan_backend_build_plain_pattern_id;
+ backend->count_ids = (count_backend_plain_pattern_ids_fc)g_hyperscan_backend_count_plain_pattern_ids;
+ backend->run_scan = (run_backend_scan_fc)g_hyperscan_backend_run_scan;
+ backend->output = (output_backend_stats_fc)g_hyperscan_backend_output_stats;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance à initialiser. *
+* *
+* Description : Initialise une instance de méthodes basée sur Hyperscan. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hyperscan_backend_init(GHyperscanBackend *backend)
+{
+ backend->atoms = NULL;
+ backend->lengths = NULL;
+ backend->coverages = NULL;
+ backend->allocated = 0;
+ backend->used = 0;
+
+ backend->database = NULL;
+ backend->scratch = NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hyperscan_backend_dispose(GHyperscanBackend *backend)
+{
+ G_OBJECT_CLASS(g_hyperscan_backend_parent_class)->dispose(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hyperscan_backend_finalize(GHyperscanBackend *backend)
+{
+ if (backend->atoms != NULL)
+ free(backend->atoms);
+
+ if (backend->lengths != NULL)
+ free(backend->lengths);
+
+ if (backend->coverages != NULL)
+ free(backend->coverages);
+
+ if (backend->scratch != NULL)
+ hs_free_scratch(backend->scratch);
+
+ if (backend->database != NULL)
+ hs_free_database(backend->database);
+
+ G_OBJECT_CLASS(g_hyperscan_backend_parent_class)->finalize(G_OBJECT(backend));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée une méthode de recherche avec la bibliothèque Hyperscan.*
+* *
+* Retour : Méthode mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GEngineBackend *g_hyperscan_backend_new(void)
+{
+ GHyperscanBackend *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_HYPERSCAN_BACKEND, NULL);
+
+ return G_ENGINE_BACKEND(result);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Indique la taille maximale des suites d'octets recherchées. *
+* *
+* Retour : Valeur strictement positive. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_hyperscan_backend_get_atom_max_size(const GHyperscanBackend *backend)
+{
+ size_t result; /* Taille à faire connaître */
+
+ result = ~0;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* plain = chaîne de caractères classique à intégrer. *
+* len = taille de cette chaîne. *
+* tmp_id = identifiants temporaires vers le motif. [OUT] *
+* *
+* Description : Inscrit dans le moteur une chaîne de caractères à rechercher.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_hyperscan_backend_enroll_plain_pattern(GHyperscanBackend *backend, const uint8_t *plain, size_t len, uint32_t tmp_id[2])
+{
+ bool result; /* Bilan à retourner */
+ size_t i; /* Boucle de parcours */
+ int ret; /* Bilan d'une comparaison */
+
+ result = true;
+
+ /*Recherche d'un motif déjà sollicité */
+
+ i = backend->used;
+
+ /*
+ for (i = 0; i < backend->used; i++)
+ {
+ if (backend->lengths[i] != len)
+ continue;
+
+ ret = memcmp(backend->atoms[i], plain, backend->lengths[i]);
+
+ if (ret == 0)
+ {
+ tmp_id[0] = i;
+ tmp_id[1] = backend->coverages[i * 2 + EXPR_COVERAGE_COUNT];
+
+ backend->coverages[i * 2 + EXPR_COVERAGE_COUNT]++;
+ break;
+
+ }
+
+ }
+ */
+
+ /* Introduction d'un nouveau motif au besoin */
+
+ if (i == backend->used)
+ {
+ if (backend->used == backend->allocated)
+ {
+ if (backend->allocated == 0)
+ backend->allocated = 6400;
+ else
+ backend->allocated *= 2;
+
+ backend->atoms = realloc(backend->atoms, backend->allocated * sizeof(const uint8_t *));
+ backend->lengths = realloc(backend->lengths, backend->allocated * sizeof(size_t));
+ backend->coverages = realloc(backend->coverages, backend->allocated * 2 * sizeof(uint32_t));
+
+ }
+
+ backend->atoms[i] = plain;
+ backend->lengths[i] = len;
+ backend->coverages[i * 2 + EXPR_COVERAGE_COUNT] = 1;
+
+ backend->used++;
+
+ tmp_id[0] = i;
+ tmp_id[1] = 0;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à préparer. *
+* *
+* Description : Met en ordre les derniers détails avant un premier scan. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+#include <fcntl.h>
+#include "../../../../common/io.h"
+
+static bool g_hyperscan_backend_warm_up(GHyperscanBackend *backend)
+{
+ bool result; /* Bilan à retourner */
+ uint32_t current_start; /* Indice de gestionnaire */
+ size_t i; /* Boucle de parcours */
+ hs_compile_error_t *error; /* Compléments d'information */
+ hs_error_t ret; /* Code de retour */
+
+ hs_platform_info_t platform;
+
+ result = false;
+
+ /* Mise à jour de la couverture des gestionnaires de suivi */
+
+ current_start = 0;
+
+ for (i = 0; i < backend->used; i++)
+ {
+ backend->coverages[i * 2 + EXPR_COVERAGE_START] = current_start;
+ backend->coverages[i * 2 + EXPR_COVERAGE_END] += current_start;
+
+ current_start = backend->coverages[i * 2 + EXPR_COVERAGE_END];
+
+ }
+
+ /* Enregistrement des expressions à prendre en compte */
+
+#if 0
+ backend->lit_ids = malloc(backend->used * sizeof(unsigned));
+
+ for (i = 0; i < backend->used; i++)
+ backend->lit_ids[i] = i;
+
+#else
+
+ backend->lit_ids = __cached_ids;
+
+#endif
+
+
+ //hs_populate_platform(&platform);
+
+ //platform.tune = 1;
+
+ //platform.cpu_features = HS_CPU_FEATURES_AVX512;
+
+#if 0
+
+ ret = hs_compile_lit_multi((const char *const *)backend->atoms, NULL, backend->lit_ids, backend->lengths,
+ backend->used, HS_MODE_BLOCK, NULL, &backend->database, &error);
+
+
+ //printf("ret: %d -vs- %d\n", ret, HS_SUCCESS);
+
+ if (ret != HS_SUCCESS)
+ {
+ log_variadic_message(LMT_EXT_ERROR, _("Unable to compile %zu patterns: \"%s\""),
+ backend->used, error->message);
+ printf("FAILED: %s\n", error->message);
+ hs_free_compile_error(error);
+ goto exit;
+ }
+
+ do
+ {
+ char *bytes;
+ size_t length;
+ int fd;
+
+ ret = hs_serialize_database(backend->database, &bytes, &length);
+ printf("ret: %d -vs- %d\n", ret, HS_SUCCESS);
+
+ fd = open("/tmp/compiled.bin", O_WRONLY | O_CREAT | O_TRUNC, 0600);
+
+ safe_write(fd, bytes, length);
+
+ close(fd);
+
+ }
+ while (0);
+
+
+#else
+
+ char *bytes;
+ size_t length;
+ bool status;
+ int fd;
+
+ length = 674216;
+ bytes = malloc(length);
+
+ fd = open("/tmp/compiled.bin", O_RDONLY);
+
+ status = safe_read(fd, bytes, length);
+
+ close(fd);
+
+ //printf("status: %d\n", status);
+
+ ret = hs_deserialize_database(bytes, length, &backend->database);
+ //printf("ret: %d -vs- %d\n", ret, HS_SUCCESS);
+
+
+
+#endif
+
+
+
+#if 0
+ do
+ {
+ //hs_platform_info_t platform;
+ char *__info;
+
+ //hs_populate_platform(&platform);
+
+ printf("TUNE: %u\n", platform.tune);
+
+ printf("CPU: %llx - AVX2? %d - AVX512? %d\n", platform.cpu_features,
+ platform.cpu_features & HS_CPU_FEATURES_AVX2,
+ platform.cpu_features & HS_CPU_FEATURES_AVX512);
+
+ hs_database_info(backend->database, &__info);
+
+ printf("INFO: %s\n", __info);
+
+ }
+ while (0);
+#endif
+
+ /* Création d'un espace de travail */
+
+ ret = hs_alloc_scratch(backend->database, &backend->scratch);
+
+ //printf("ret: %d -vs- %d\n", ret, HS_SUCCESS);
+
+ if (ret != HS_SUCCESS)
+ {
+ log_variadic_message(LMT_EXT_ERROR, _("Unable to allocate scratch space"));
+ goto exit;
+ }
+
+ result = true;
+
+ exit:
+
+ //printf("result: %d\n", result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* tmp_id = identifiants temporaires vers le motif. [OUT] *
+* *
+* Description : Récupère les identifiants finaux pour un motif recherché. *
+* *
+* Retour : Identifiant constitué ou INVALID_PATTERN_ID en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static patid_t g_hyperscan_backend_build_plain_pattern_id(const GHyperscanBackend *backend, const uint32_t tmp_id[2])
+{
+ patid_t result; /* Identifiant à retourner */
+ size_t index; /* Indice reconstitué */
+
+ assert(tmp_id[0] < backend->used);
+
+ index = tmp_id[0] * 2;
+
+ result = backend->coverages[index + EXPR_COVERAGE_START] + tmp_id[1];
+
+ assert(result < backend->coverages[index + EXPR_COVERAGE_END]);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* *
+* Description : Détermine le nombre d'identifiants constitués. *
+* *
+* Retour : Quantité de gestionnaires de suivi à prévoir. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static size_t g_hyperscan_backend_count_plain_pattern_ids(const GHyperscanBackend *backend)
+{
+ size_t result; /* Quantité à retourner */
+
+ if (backend->used == 0)
+ result = 0;
+ else
+ result = backend->coverages[(backend->used - 1) * 2 + EXPR_COVERAGE_END];
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* *
+* Description : Prend note d'une correspondance trouvée par Hyperscan. *
+* *
+* Retour : 0 afin de poursuivre les recherches. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int handle_hyperscan_match_event(unsigned int id, unsigned long long from, unsigned long long to, unsigned int flags, GScanContext *context/*const hyperscan_context_t *context*/)
+{
+
+ g_scan_context_store_atom_match_end(context, id, to);
+
+ return 0;
+
+#if 0
+
+ phys_t offset; /* Point de départ établi */
+ const uint32_t *coverage_base; /* Base des suivis */
+ uint32_t k; /* Boucle de parcours */
+ uint32_t final_k; /* Dernier indice à traiter */
+
+ //return 0;
+
+#ifndef NDEBUG
+ assert(id < context->used);
+ assert(id == context->lit_ids[id]);
+#endif
+
+ offset = to - context->lengths[id];
+
+ coverage_base = context->coverages + id * 2;
+
+ k = coverage_base[EXPR_COVERAGE_START];
+ final_k = coverage_base[EXPR_COVERAGE_END];
+
+ for (; k < final_k; k++)
+ g_umem_slice_put_uint64(context->matches[0/*k*/], offset);
+
+ return 0;
+
+#endif
+
+}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à manipuler. *
+* context = lieu d'enregistrement des résultats. *
+* *
+* Description : Parcours un contenu binaire à la recherche de motifs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hyperscan_backend_run_scan(const GHyperscanBackend *backend, GScanContext *context)
+{
+ GBinContent *content; /* Contenu binaire manipulé */
+ phys_t dlen; /* Quantité de données */
+ vmpa2t pos; /* Point de départ ciblé */
+ const bin_t *data; /* Données à analyser */
+#ifndef NDEBUG
+ size_t count; /* Nombre de zones prévues */
+#endif
+ hyperscan_context_t hcontext; /* Rassemblement d'informations*/
+ GUMemSlice **matches; /* Zones d'enregistrements */
+ hs_error_t ret; /* Code de retour */
+
+ /* Récupération d'un accès aux données */
+
+ content = g_scan_context_get_content(context);
+
+ dlen = g_binary_content_compute_size(content);
+
+ g_binary_content_compute_start_pos(content, &pos);
+ data = g_binary_content_get_raw_access(content, &pos, dlen);
+
+ /* Préparation de l'accès aux éléments utiles */
+
+ hcontext.lengths = backend->lengths;
+ hcontext.coverages = backend->coverages;
+
+#ifndef NDEBUG
+ hcontext.used = backend->used;
+ hcontext.lit_ids = backend->lit_ids;
+#endif
+
+ /*
+#ifndef NDEBUG
+ matches = g_scan_context_get_match_storages(context, &count);
+ assert(count == backend->used);
+#else
+ matches = g_scan_context_get_match_storages(context, (size_t []){ 0 });
+#endif
+ */
+ matches = NULL; /* REMME */
+
+ hcontext.matches = matches;
+
+ /* Lancement de l'analyse */
+
+ ret = hs_scan(backend->database, (const char *)data, dlen,
+ 0 /* Arg. inutilisé */, backend->scratch,
+ (match_event_handler)handle_hyperscan_match_event, /*&h*/context);
+
+
+ //printf("ret ok? %d\n", ret == HS_SUCCESS);
+
+
+
+ g_object_unref(G_OBJECT(content));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : backend = moteur de recherche à consulter. *
+* *
+* Description : Imprime quelques faits quant aux éléments mis en place. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hyperscan_backend_output_stats(const GHyperscanBackend *backend)
+{
+ printf("TODO: %s\n", __FUNCTION__);
+
+}
diff --git a/src/analysis/scan/patterns/backends/hyperscan.h b/src/analysis/scan/patterns/backends/hyperscan.h
new file mode 100644
index 0000000..d8c0f92
--- /dev/null
+++ b/src/analysis/scan/patterns/backends/hyperscan.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hyperscan.h - prototypes pour la méthode de recherche basée sur la bibliothèque Hyperscan d'Intel
+ *
+ * Copyright (C) 2024 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_PATTERNS_BACKENDS_HYPERSCAN_H
+#define _ANALYSIS_SCAN_PATTERNS_BACKENDS_HYPERSCAN_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "../backend.h"
+
+
+
+#define G_TYPE_HYPERSCAN_BACKEND g_hyperscan_backend_get_type()
+#define G_HYPERSCAN_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_HYPERSCAN_BACKEND, GHyperscanBackend))
+#define G_IS_HYPERSCAN_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_HYPERSCAN_BACKEND))
+#define G_HYPERSCAN_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_HYPERSCAN_BACKEND, GHyperscanBackendClass))
+#define G_IS_HYPERSCAN_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_HYPERSCAN_BACKEND))
+#define G_HYPERSCAN_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_HYPERSCAN_BACKEND, GHyperscanBackendClass))
+
+
+/* Méthode de recherche basée sur une bibliothèque d'Intel : Hyperscan (instance) */
+typedef struct _GHyperscanBackend GHyperscanBackend;
+
+/* Méthode de recherche basée sur une bibliothèque d'Intel : Hyperscan (classe) */
+typedef struct _GHyperscanBackendClass GHyperscanBackendClass;
+
+
+/* Indique le type défini pour un moteur de recherche pour données. */
+GType g_hyperscan_backend_get_type(void);
+
+/* Crée une méthode de recherche avec la bibliothèque Hyperscan. */
+GEngineBackend *g_hyperscan_backend_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_BACKENDS_HYPERSCAN_H */
diff --git a/src/analysis/scan/patterns/customizer-int.h b/src/analysis/scan/patterns/customizer-int.h
new file mode 100644
index 0000000..9d49ab6
--- /dev/null
+++ b/src/analysis/scan/patterns/customizer-int.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * customizer-int.h - prototypes internes pour la modification paramétrée d'une séquence d'octets
+ *
+ * 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_CUSTOMIZER_INT_H
+#define _ANALYSIS_SCAN_CUSTOMIZER_INT_H
+
+
+#include "customizer.h"
+#include "modifier-int.h"
+
+
+
+/* Encadrement de transformation paramétrée d'une séquence d'octets (instance) */
+struct _GScanTokenCustomizer
+{
+ GScanTokenModifier parent; /* A laisser en premier */
+
+ GScanTokenModifier *effective; /* Modificateur effectif */
+
+ modifier_arg_t *args; /* Paramètres de transformation*/
+ size_t count; /* Quantité de ces paramètres */
+
+};
+
+/* Encadrement de transformation paramétrée d'une séquence d'octets (classe) */
+struct _GScanTokenCustomizerClass
+{
+ GScanTokenModifierClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place un encadrement de transformation de motifs. */
+bool g_scan_token_customizer_create(GScanTokenCustomizer *, const modifier_arg_t *);
+
+
+
+#endif /* _ANALYSIS_SCAN_CUSTOMIZER_INT_H */
diff --git a/src/analysis/scan/patterns/customizer.c b/src/analysis/scan/patterns/customizer.c
new file mode 100644
index 0000000..9659957
--- /dev/null
+++ b/src/analysis/scan/patterns/customizer.c
@@ -0,0 +1,377 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * customizer.c - modification paramétrée d'une séquence d'octets
+ *
+ * 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 "customizer.h"
+
+
+#include <malloc.h>
+
+
+#include "customizer-int.h"
+
+
+
+/* --------------------- TRANSFORMATION PERSONNALISEE DE MOTIFS --------------------- */
+
+
+/* Initialise la classe des transformations paramétrée. */
+static void g_scan_token_customizer_class_init(GScanTokenCustomizerClass *);
+
+/* Initialise une instance de transformation paramétrée. */
+static void g_scan_token_customizer_init(GScanTokenCustomizer *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_customizer_dispose(GScanTokenCustomizer *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_customizer_finalize(GScanTokenCustomizer *);
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_token_customizer_get_name(const GScanTokenCustomizer *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_token_customizer_transform(const GScanTokenCustomizer *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* TRANSFORMATION PERSONNALISEE DE MOTIFS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transformation personnalisée d'une séquence d'octets. */
+G_DEFINE_TYPE(GScanTokenCustomizer, g_scan_token_customizer, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transformations paramétrée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_customizer_class_init(GScanTokenCustomizerClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_customizer_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_customizer_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_token_customizer_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_token_customizer_transform;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : customizer = instance à initialiser. *
+* *
+* Description : Initialise une instance de transformation paramétrée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_customizer_init(GScanTokenCustomizer *customizer)
+{
+ customizer->effective = NULL;
+
+ customizer->args = NULL;
+ customizer->count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : customizer = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_customizer_dispose(GScanTokenCustomizer *customizer)
+{
+ g_clear_object(&customizer->effective);
+
+ G_OBJECT_CLASS(g_scan_token_customizer_parent_class)->dispose(G_OBJECT(customizer));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : customizer = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_customizer_finalize(GScanTokenCustomizer *customizer)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < customizer->count; i++)
+ exit_mod_arg(&customizer->args[i]);
+
+ if (customizer->args != NULL)
+ free(customizer->args);
+
+ G_OBJECT_CLASS(g_scan_token_customizer_parent_class)->finalize(G_OBJECT(customizer));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = premier argument pour personnaliser l'opération. *
+* *
+* Description : Construit un encadrement de transformation de motifs. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_token_customizer_new(const modifier_arg_t *arg)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_TOKEN_CUSTOMIZER, NULL);
+
+ if (!g_scan_token_customizer_create(G_SCAN_TOKEN_CUSTOMIZER(result), arg))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : customizer = encadrement de motif à initialiser pleinement. *
+* arg = premier argument pour personnaliser l'opération.*
+* *
+* Description : Met en place un encadrement de transformation de motifs. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_customizer_create(GScanTokenCustomizer *customizer, const modifier_arg_t *arg)
+{
+ g_scan_token_customizer_add_extra_arg(customizer, arg);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : customizer = encadrement de motif à compléter. *
+* arg = nouvel argument pour personnaliser l'opération. *
+* *
+* Description : Ajoute un argument à l'encadrement de transformation. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_customizer_add_extra_arg(GScanTokenCustomizer *customizer, const modifier_arg_t *arg)
+{
+ customizer->args = realloc(customizer->args, ++customizer->count * sizeof(modifier_arg_t));
+
+ copy_mod_arg(&customizer->args[customizer->count - 1], arg);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : customizer = encadrement de motif à compléter. *
+* modifier = modificateur de motifs à employer en sous-main. *
+* *
+* Description : Définit le transformateur effectif pour les motifs. *
+* *
+* Retour : true si le motificateur accepte les arguments courants. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_customizer_attach_modifier(GScanTokenCustomizer *customizer, GScanTokenModifier *modifier)
+{
+ bool result; /* Validation à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = true;
+
+ for (i = 0; i < customizer->count && result; i++)
+ result = g_scan_token_modifier_can_handle_arg(modifier, &customizer->args[i]);
+
+ if (!result) goto exit;
+
+ customizer->effective = modifier;
+ g_object_ref(G_OBJECT(modifier));
+
+ exit:
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_token_customizer_get_name(const GScanTokenCustomizer *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ if (modifier->effective == NULL)
+ result = NULL;
+
+ else
+ result = g_scan_token_modifier_get_name(modifier->effective);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_customizer_transform(const GScanTokenCustomizer *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ size_t i; /* Boucle de parcours #1 */
+ sized_binary_t *extra; /* Motifs supplémentaires */
+ size_t extra_count; /* Quantité de ces motifs */
+ size_t old_dcount; /* Mémorisation avant avancées */
+ sized_binary_t *new; /* Nouvel emplacement libre */
+ size_t k; /* Boucle de parcours #2 */
+
+ *dest = NULL;
+ *dcount = 0;
+
+ for (i = 0; i < modifier->count; i++)
+ {
+ result = g_scan_token_modifier_transform_with_arg(modifier->effective,
+ src, scount,
+ &modifier->args[i],
+ &extra, &extra_count);
+ if (!result) goto exit;
+
+ old_dcount = *dcount;
+
+ *dcount += extra_count;
+ *dest = realloc(*dest, *dcount * sizeof(sized_binary_t));
+
+ new = (*dest) + old_dcount;
+
+ for (k = 0; k < extra_count; k++, new++)
+ copy_szstr(*new, extra[k]);
+
+ free(extra);
+
+ }
+
+ exit:
+
+ if (!result)
+ {
+ for (i = 0; i < *dcount; i++)
+ exit_szstr(dest[i]);
+
+ if (*dest != NULL)
+ free(*dest);
+
+ *dest = NULL;
+ *dcount = 0;
+
+ }
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/customizer.h b/src/analysis/scan/patterns/customizer.h
new file mode 100644
index 0000000..845d9ff
--- /dev/null
+++ b/src/analysis/scan/patterns/customizer.h
@@ -0,0 +1,65 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * customizer.h - prototypes pour la modification paramétrée d'une séquence d'octets
+ *
+ * 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_CUSTOMIZER_H
+#define _ANALYSIS_SCAN_CUSTOMIZER_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "modifier.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_CUSTOMIZER g_scan_token_customizer_get_type()
+#define G_SCAN_TOKEN_CUSTOMIZER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_CUSTOMIZER, GScanTokenCustomizer))
+#define G_IS_SCAN_TOKEN_CUSTOMIZER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_CUSTOMIZER))
+#define G_SCAN_TOKEN_CUSTOMIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_CUSTOMIZER, GScanTokenCustomizerClass))
+#define G_IS_SCAN_TOKEN_CUSTOMIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_CUSTOMIZER))
+#define G_SCAN_TOKEN_CUSTOMIZER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_CUSTOMIZER, GScanTokenCustomizerClass))
+
+
+/* Encadrement de transformation paramétrée d'une séquence d'octets (instance) */
+typedef struct _GScanTokenCustomizer GScanTokenCustomizer;
+
+/* Encadrement de transformation paramétrée d'une séquence d'octets (classe) */
+typedef struct _GScanTokenCustomizerClass GScanTokenCustomizerClass;
+
+
+/* Indique le type défini pour une transformation personnalisée d'une séquence d'octets. */
+GType g_scan_token_customizer_get_type(void);
+
+/* Construit un encadrement de transformation de motifs. */
+GScanTokenModifier *g_scan_token_customizer_new(const modifier_arg_t *);
+
+/* Ajoute un argument à l'encadrement de transformation. */
+void g_scan_token_customizer_add_extra_arg(GScanTokenCustomizer *, const modifier_arg_t *);
+
+/* Définit le transformateur effectif pour les motifs. */
+bool g_scan_token_customizer_attach_modifier(GScanTokenCustomizer *, GScanTokenModifier *);
+
+
+
+#endif /* _ANALYSIS_SCAN_CUSTOMIZER_H */
diff --git a/src/analysis/scan/patterns/modarg.h b/src/analysis/scan/patterns/modarg.h
new file mode 100644
index 0000000..d96e137
--- /dev/null
+++ b/src/analysis/scan/patterns/modarg.h
@@ -0,0 +1,91 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * modarg.h - prototypes pour la conservation d'arguments pour modificateurs
+ *
+ * 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_MODARG_H
+#define _ANALYSIS_SCAN_MODARG_H
+
+
+#include <stdbool.h>
+
+
+#include "../../../common/szstr.h"
+
+
+
+/* Types d'arguments pris en charge */
+typedef enum _ModifierArgType
+{
+ MAT_BOOLEAN, /* Valeur booléenne */
+ MAT_SIGNED_INTEGER, /* Nombre entier 64 bits #1 */
+ MAT_UNSIGNED_INTEGER, /* Nombre entier 64 bits #2 */
+ MAT_STRING, /* Chaîne de caractères */
+ MAT_RANGE, /* Séquence d'entiers */
+
+} ModifierArgType;
+
+/* Argument pour modificateur de motif */
+typedef struct _modifier_arg_t
+{
+ ModifierArgType type; /* Type de valeur portée */
+
+ union
+ {
+ bool boolean; /* Valeur booléenne */
+ long long s_integer; /* Valeur entière 64 bits */
+ unsigned long long u_integer; /* Valeur entière 64 bits */
+ sized_string_t string; /* Chaîne de caractères */
+
+ struct
+ {
+ long long start; /* Point de départ */
+ long long end; /* Point d'arrivée */
+
+ } range;
+
+ } value;
+
+} modifier_arg_t;
+
+
+#define exit_mod_arg(a) \
+ do \
+ { \
+ if ((a)->type == MAT_STRING) \
+ exit_szstr(&(a)->value.string); \
+ } \
+ while (0)
+
+#define copy_mod_arg(d, s) \
+ do \
+ { \
+ (d)->type = (s)->type; \
+ if ((s)->type == MAT_STRING) \
+ szstrdup(&(d)->value.string, &(s)->value.string); \
+ else \
+ *(d) = *(s); \
+ } \
+ while (0)
+
+
+
+#endif /* _ANALYSIS_SCAN_MODARG_H */
diff --git a/src/analysis/scan/patterns/modifier-int.h b/src/analysis/scan/patterns/modifier-int.h
new file mode 100644
index 0000000..c9b3a36
--- /dev/null
+++ b/src/analysis/scan/patterns/modifier-int.h
@@ -0,0 +1,71 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * modifier-int.h - prototypes internes pour la modification d'une séquence d'octets pour un motif recherché
+ *
+ * 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_MODIFIER_INT_H
+#define _ANALYSIS_SCAN_MODIFIER_INT_H
+
+
+#include "modifier.h"
+
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+typedef char * (* get_scan_modifier_name_fc) (const GScanTokenModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+typedef bool (* transform_scan_token_fc) (const GScanTokenModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Détermine si un argument est bien toléré par un modificateur. */
+typedef bool (* can_token_modifier_handle_arg) (const GScanTokenModifier *, const modifier_arg_t *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+typedef bool (* transform_scan_token_with_fc) (const GScanTokenModifier *, const sized_binary_t *, size_t, const modifier_arg_t *, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+typedef char * (* get_modifier_path) (const GScanTokenModifier *, size_t *);
+
+
+/* Transformation d'une séquence d'octets en une ou plusieurs autres formes (instance) */
+struct _GScanTokenModifier
+{
+ GObject parent; /* A laisser en premier */
+
+};
+
+/* Transformation d'une séquence d'octets en une ou plusieurs autres formes (classe) */
+struct _GScanTokenModifierClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+ get_scan_modifier_name_fc get_name; /* Fourniture du nom d'appel */
+
+ transform_scan_token_fc transform; /* Opération de transformation */
+ can_token_modifier_handle_arg can_handle; /* Support d'argument donné */
+ transform_scan_token_with_fc transform_with; /* Opération encadrée */
+ get_modifier_path get_path; /* Rappel d'une combinaison */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_MODIFIER_INT_H */
diff --git a/src/analysis/scan/patterns/modifier.c b/src/analysis/scan/patterns/modifier.c
new file mode 100644
index 0000000..9efd404
--- /dev/null
+++ b/src/analysis/scan/patterns/modifier.c
@@ -0,0 +1,278 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * modifier.c - modification d'une séquence d'octets pour un motif recherché
+ *
+ * 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 "modifier.h"
+
+
+#include "modifier-int.h"
+
+
+
+/* Initialise la classe des transformations d'octets. */
+static void g_scan_token_modifier_class_init(GScanTokenModifierClass *);
+
+/* Initialise une instance de transformation d'octets. */
+static void g_scan_token_modifier_init(GScanTokenModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_modifier_dispose(GScanTokenModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_modifier_finalize(GScanTokenModifier *);
+
+
+
+/* Indique le type défini pour une transformation d'une séquence d'octets. */
+G_DEFINE_TYPE(GScanTokenModifier, g_scan_token_modifier, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transformations d'octets. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_modifier_class_init(GScanTokenModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_modifier_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transformation d'octets. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_modifier_init(GScanTokenModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_modifier_dispose(GScanTokenModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_token_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_modifier_finalize(GScanTokenModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_token_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_scan_token_modifier_get_name(const GScanTokenModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+ GScanTokenModifierClass *class; /* Classe à activer */
+
+ class = G_SCAN_TOKEN_MODIFIER_GET_CLASS(modifier);
+
+ result = class->get_name(modifier);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_modifier_transform(const GScanTokenModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ GScanTokenModifierClass *class; /* Classe à activer */
+
+ class = G_SCAN_TOKEN_MODIFIER_GET_CLASS(modifier);
+
+ result = class->transform(modifier, src, scount, dest, dcount);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* arg = argument de personnalisation. *
+* *
+* Description : Détermine si un argument est bien toléré par un modificateur.*
+* *
+* Retour : Bilan de la consultation : support ou non. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_modifier_can_handle_arg(const GScanTokenModifier *modifier, const modifier_arg_t *arg)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ GScanTokenModifierClass *class; /* Classe à activer */
+
+ class = G_SCAN_TOKEN_MODIFIER_GET_CLASS(modifier);
+
+ if (class->can_handle == NULL)
+ result = false;
+ else
+ result = class->can_handle(modifier, arg);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* arg = argument de personnalisation. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_modifier_transform_with_arg(const GScanTokenModifier *modifier, const sized_binary_t *src, size_t scount, const modifier_arg_t *arg, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ GScanTokenModifierClass *class; /* Classe à activer */
+
+ result = false;
+
+ if (!g_scan_token_modifier_can_handle_arg(modifier, arg))
+ goto exit;
+
+ class = G_SCAN_TOKEN_MODIFIER_GET_CLASS(modifier);
+
+ if (class->transform_with != NULL)
+ result = class->transform_with(modifier, src, scount, arg, dest, dcount);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_scan_token_modifier_get_path(const GScanTokenModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+ GScanTokenModifierClass *class; /* Classe à activer */
+
+ class = G_SCAN_TOKEN_MODIFIER_GET_CLASS(modifier);
+
+ result = class->get_path(modifier, index);
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifier.h b/src/analysis/scan/patterns/modifier.h
new file mode 100644
index 0000000..9030a72
--- /dev/null
+++ b/src/analysis/scan/patterns/modifier.h
@@ -0,0 +1,73 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * modifier.h - prototypes pour la modification d'une séquence d'octets pour un motif recherché
+ *
+ * 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_MODIFIER_H
+#define _ANALYSIS_SCAN_MODIFIER_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+
+#include "modarg.h"
+#include "../../../common/szstr.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_MODIFIER g_scan_token_modifier_get_type()
+#define G_SCAN_TOKEN_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_MODIFIER, GScanTokenModifier))
+#define G_IS_SCAN_TOKEN_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_MODIFIER))
+#define G_SCAN_TOKEN_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_MODIFIER, GScanTokenModifierClass))
+#define G_IS_SCAN_TOKEN_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_MODIFIER))
+#define G_SCAN_TOKEN_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_MODIFIER, GScanTokenModifierClass))
+
+
+/* Transformation d'une séquence d'octets en une ou plusieurs autres formes (instance) */
+typedef struct _GScanTokenModifier GScanTokenModifier;
+
+/* Transformation d'une séquence d'octets en une ou plusieurs autres formes (classe) */
+typedef struct _GScanTokenModifierClass GScanTokenModifierClass;
+
+
+/* Indique le type défini pour une transformation d'une séquence d'octets. */
+GType g_scan_token_modifier_get_type(void);
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+char *g_scan_token_modifier_get_name(const GScanTokenModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+bool g_scan_token_modifier_transform(const GScanTokenModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Détermine si un argument est bien toléré par un modificateur. */
+bool g_scan_token_modifier_can_handle_arg(const GScanTokenModifier *, const modifier_arg_t *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+bool g_scan_token_modifier_transform_with_arg(const GScanTokenModifier *, const sized_binary_t *, size_t, const modifier_arg_t *, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+char *g_scan_token_modifier_get_path(const GScanTokenModifier *, size_t *);
+
+
+
+#endif /* _ANALYSIS_SCAN_MODIFIER_H */
diff --git a/src/analysis/scan/patterns/modifiers/Makefile.am b/src/analysis/scan/patterns/modifiers/Makefile.am
new file mode 100644
index 0000000..da046b9
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/Makefile.am
@@ -0,0 +1,23 @@
+
+noinst_LTLIBRARIES = libanalysisscanpatternsmodifiers.la
+
+
+libanalysisscanpatternsmodifiers_la_SOURCES = \
+ hex.h hex.c \
+ list-int.h \
+ list.h list.c \
+ lower.h lower.c \
+ pipe-int.h \
+ pipe.h pipe.c \
+ plain.h plain.c \
+ rev.h rev.c \
+ upper.h upper.c \
+ wide.h wide.c \
+ xor.h xor.c
+
+libanalysisscanpatternsmodifiers_la_CFLAGS = $(LIBGOBJ_CFLAGS)
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
+
+dev_HEADERS = $(libanalysisscanpatternsmodifiers_la_SOURCES:%c=)
diff --git a/src/analysis/scan/patterns/modifiers/hex.c b/src/analysis/scan/patterns/modifiers/hex.c
new file mode 100644
index 0000000..4a41c7d
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/hex.c
@@ -0,0 +1,296 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex.c - transformation en version hexadécimale d'une séquence d'octets
+ *
+ * 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 "hex.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "../modifier-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des transformations en hexadécimal. */
+static void g_scan_hex_modifier_class_init(GScanHexModifierClass *klass);
+
+/* Initialise une instance de transformation en hexadécimal. */
+static void g_scan_hex_modifier_init(GScanHexModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_hex_modifier_dispose(GScanHexModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_hex_modifier_finalize(GScanHexModifier *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_hex_modifier_get_name(const GScanHexModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_hex_modifier_transform(const GScanHexModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_hex_modifier_get_path(const GScanHexModifier *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transformation d'une séquence d'octets dans sa version hexadécimale. */
+G_DEFINE_TYPE(GScanHexModifier, g_scan_hex_modifier, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transformations en hexadécimal. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_modifier_class_init(GScanHexModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_hex_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_hex_modifier_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_hex_modifier_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_hex_modifier_transform;
+ modifier->get_path = (get_modifier_path)g_scan_hex_modifier_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transformation en hexadécimal. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_modifier_init(GScanHexModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_modifier_dispose(GScanHexModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_hex_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_modifier_finalize(GScanHexModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_hex_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un modificateur fournistant une vue hexadécimale. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_hex_modifier_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_HEX_MODIFIER, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_hex_modifier_get_name(const GScanHexModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("hex");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_hex_modifier_transform(const GScanHexModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours #1 */
+ const sized_binary_t *_src; /* Source courante */
+ size_t k; /* Boucle de parcours #2 */
+
+ static char *alphabet = "0123456789abcdef";
+
+ result = true;
+
+ *dcount = scount;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++, binary++)
+ {
+ _src = src + i;
+
+ binary->len = _src->len * 2;
+ binary->data = malloc(binary->len);
+
+ for (k = 0; k < _src->len; k++)
+ {
+ binary->data[k * 2 + 0] = alphabet[_src->data[k] >> 4];
+ binary->data[k * 2 + 1] = alphabet[_src->data[k] & 0xf];
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_hex_modifier_get_path(const GScanHexModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (*index > 0)
+ {
+ result = NULL;
+ (*index)--;
+ }
+
+ else
+ result = strdup("hex");
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/hex.h b/src/analysis/scan/patterns/modifiers/hex.h
new file mode 100644
index 0000000..1a9b410
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/hex.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex.h - prototypes pour la transformation en version hexadécimale d'une séquence d'octets
+ *
+ * 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_PATTERNS_MODIFIERS_HEX_H
+#define _ANALYSIS_SCAN_PATTERNS_MODIFIERS_HEX_H
+
+
+#include <glib-object.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_HEX_MODIFIER g_scan_hex_modifier_get_type()
+#define G_SCAN_HEX_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_HEX_MODIFIER, GScanHexModifier))
+#define G_IS_SCAN_HEX_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_HEX_MODIFIER))
+#define G_SCAN_HEX_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_HEX_MODIFIER, GScanHexModifierClass))
+#define G_IS_SCAN_HEX_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_HEX_MODIFIER))
+#define G_SCAN_HEX_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_HEX_MODIFIER, GScanHexModifierClass))
+
+
+/* Transformation d'une séquence d'octets dans sa version hexadécimale (instance) */
+typedef GScanTokenModifier GScanHexModifier;
+
+/* Transformation d'une séquence d'octets dans sa version hexadécimale (classe) */
+typedef GScanTokenModifierClass GScanHexModifierClass;
+
+
+/* Indique le type défini pour une transformation d'une séquence d'octets dans sa version hexadécimale. */
+GType g_scan_hex_modifier_get_type(void);
+
+/* Construit un modificateur fournistant une vue hexadécimale. */
+GScanTokenModifier *g_scan_hex_modifier_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_MODIFIERS_HEX_H */
diff --git a/src/analysis/scan/patterns/modifiers/list-int.h b/src/analysis/scan/patterns/modifiers/list-int.h
new file mode 100644
index 0000000..3ba253e
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/list-int.h
@@ -0,0 +1,54 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * list-int.h - prototypes internes pour la gestion d'une liste de transformateurs
+ *
+ * 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_MODIFIERS_LIST_INT_H
+#define _ANALYSIS_SCAN_MODIFIERS_LIST_INT_H
+
+
+#include "list.h"
+
+
+#include "../modifier-int.h"
+
+
+
+/* Liste de transformations d'une séquence d'octets (instance) */
+struct _GScanModifierList
+{
+ GScanTokenModifier parent; /* A laisser en premier */
+
+ GScanTokenModifier **modifiers; /* Liste de transformateurs */
+ size_t count; /* Taille de cette liste */
+
+};
+
+/* Liste de transformations d'une séquence d'octets (classe) */
+struct _GScanModifierListClass
+{
+ GScanTokenModifierClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_MODIFIERS_LIST_INT_H */
diff --git a/src/analysis/scan/patterns/modifiers/list.c b/src/analysis/scan/patterns/modifiers/list.c
new file mode 100644
index 0000000..86fd19f
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/list.c
@@ -0,0 +1,438 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * list.c - gestion d'une liste de transformateurs
+ *
+ * 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 "list.h"
+
+
+#include <assert.h>
+#include <malloc.h>
+
+
+#include "list-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des liste de transformations d'octets. */
+static void g_scan_modifier_list_class_init(GScanModifierListClass *);
+
+/* Initialise une instance de liste de transformations d'octets. */
+static void g_scan_modifier_list_init(GScanModifierList *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_modifier_list_dispose(GScanModifierList *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_modifier_list_finalize(GScanModifierList *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_modifier_list_get_name(const GScanModifierList *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_modifier_list_transform(const GScanModifierList *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_modifier_list_get_path(const GScanModifierList *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une série de transformations d'octets. */
+G_DEFINE_TYPE(GScanModifierList, g_scan_modifier_list, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des liste de transformations d'octets. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_list_class_init(GScanModifierListClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_modifier_list_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_modifier_list_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_modifier_list_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_modifier_list_transform;
+ modifier->get_path = (get_modifier_path)g_scan_modifier_list_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = instance à initialiser. *
+* *
+* Description : Initialise une instance de liste de transformations d'octets.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_list_init(GScanModifierList *list)
+{
+ list->modifiers = NULL;
+ list->count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_list_dispose(GScanModifierList *list)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < list->count; i++)
+ g_clear_object(&list->modifiers[i]);
+
+ G_OBJECT_CLASS(g_scan_modifier_list_parent_class)->dispose(G_OBJECT(list));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_list_finalize(GScanModifierList *list)
+{
+ if (list->modifiers != NULL)
+ free(list->modifiers);
+
+ G_OBJECT_CLASS(g_scan_modifier_list_parent_class)->finalize(G_OBJECT(list));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit une liste de modificateurs d'octets. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_modifier_list_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_MODIFIER_LIST, NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste de modificateurs à étendre. *
+* modifier = modificateur à intégrer. *
+* *
+* Description : Intègre un nouveau transformateur dans une liste. *
+* *
+* Retour : Bilan de l'ajout : false si un élément similaire est déjà là.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_modifier_list_add(GScanModifierList *list, GScanTokenModifier *modifier)
+{
+ bool result; /* Bilan à retourner */
+ char *name; /* Désignation du modificateur */
+ size_t i; /* Boucle de parcours */
+ char *other; /* Désignation de ses collègues*/
+
+ /* Recherche d'une redondance */
+
+ /**
+ * Note : deux listes identiques passent sans soucis.
+ * TODO : comparer les transformateurs ?
+ */
+
+ result = true;
+
+ if (!G_IS_SCAN_MODIFIER_LIST(modifier))
+ {
+ name = g_scan_token_modifier_get_name(modifier);
+
+ for (i = 0; i < list->count && result; i++)
+ {
+ if (G_IS_SCAN_MODIFIER_LIST(list->modifiers[i]))
+ continue;
+
+ other = g_scan_token_modifier_get_name(list->modifiers[i]);
+
+ result = (strcmp(name, other) != 0);
+
+ free(other);
+
+ }
+
+ free(name);
+
+ }
+
+ if (!result)
+ goto done;
+
+ /* Inclusion dans la liste */
+
+ list->modifiers = realloc(list->modifiers, ++list->count * sizeof(GScanTokenModifier *));
+
+ list->modifiers[list->count - 1] = modifier;
+ g_object_ref(G_OBJECT(modifier));
+
+ done:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = série à consulter. *
+* *
+* Description : Indique le nombre de transformateurs intégrés dans la liste. *
+* *
+* Retour : Nombre de modificateurs représentés. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_scan_modifier_list_count(const GScanModifierList *list)
+{
+ size_t result; /* Quantité à retourner */
+
+ result = list->count;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = série à consulter. *
+* index = indice du paramètre à retourner. *
+* *
+* Description : Fournit un transformateur donné de la liste. *
+* *
+* Retour : Modificateur inclus dans la liste ou NULL si mauvais indice. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_modifier_list_get(const GScanModifierList *list, size_t index)
+{
+ GScanTokenModifier *result; /* Instance à retourner */
+
+ assert(index < list->count);
+
+ if (index < list->count)
+ {
+ result = list->modifiers[index];
+ g_object_ref(G_OBJECT(result));
+ }
+
+ else
+ result = NULL;
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_modifier_list_get_name(const GScanModifierList *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("(list)");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_modifier_list_transform(const GScanModifierList *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ size_t i; /* Boucle de parcours #1 */
+ sized_binary_t *extra; /* Motifs supplémentaires */
+ size_t extra_count; /* Quantité de ces motifs */
+ sized_binary_t *new; /* Nouvel emplacement libre */
+ size_t k; /* Boucle de parcours #2 */
+
+ *dest = NULL;
+ *dcount = 0;
+
+ for (i = 0; i < modifier->count; i++)
+ {
+ result = g_scan_token_modifier_transform(modifier->modifiers[i], src, scount, &extra, &extra_count);
+ if (!result) goto exit;
+
+ *dcount += extra_count;
+ *dest = realloc(*dest, *dcount * sizeof(sized_binary_t));
+
+ new = (*dest) + *dcount - extra_count;
+
+ for (k = 0; k < extra_count; k++, new++)
+ copy_szstr(*new, extra[k]);
+
+ free(extra);
+
+ }
+
+ exit:
+
+ if (!result)
+ {
+ for (i = 0; i < *dcount; i++)
+ exit_szstr(dest[i]);
+
+ if (*dest != NULL)
+ free(*dest);
+
+ *dest = NULL;
+ *dcount = 0;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_modifier_list_get_path(const GScanModifierList *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+ size_t i; /* Boucle de parcours #1 */
+
+ result = NULL;
+
+ for (i = 0; i < modifier->count && result == NULL; i++)
+ result = g_scan_token_modifier_get_path(modifier->modifiers[i], index);
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/list.h b/src/analysis/scan/patterns/modifiers/list.h
new file mode 100644
index 0000000..abd1eae
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/list.h
@@ -0,0 +1,68 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * list.h - prototypes pour la gestion d'une liste de transformateurs
+ *
+ * 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_MODIFIERS_LIST_H
+#define _ANALYSIS_SCAN_MODIFIERS_LIST_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_MODIFIER_LIST g_scan_modifier_list_get_type()
+#define G_SCAN_MODIFIER_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_MODIFIER_LIST, GScanModifierList))
+#define G_IS_SCAN_MODIFIER_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_MODIFIER_LIST))
+#define G_SCAN_MODIFIER_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_MODIFIER_LIST, GScanModifierListClass))
+#define G_IS_SCAN_MODIFIER_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_MODIFIER_LIST))
+#define G_SCAN_MODIFIER_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_MODIFIER_LIST, GScanModifierListClass))
+
+
+/* Liste de transformations d'une séquence d'octets (instance) */
+typedef struct _GScanModifierList GScanModifierList;
+
+/* Liste de transformations d'une séquence d'octets (classe) */
+typedef struct _GScanModifierListClass GScanModifierListClass;
+
+
+/* Indique le type défini pour une série de transformations d'octets. */
+GType g_scan_modifier_list_get_type(void);
+
+/* Construit une liste de modificateurs d'octets. */
+GScanTokenModifier *g_scan_modifier_list_new(void);
+
+/* Intègre un nouveau transformateur dans une liste. */
+bool g_scan_modifier_list_add(GScanModifierList *, GScanTokenModifier *);
+
+/* Indique le nombre de transformateurs intégrés dans la liste. */
+size_t g_scan_modifier_list_count(const GScanModifierList *);
+
+/* Fournit un transformateur donné de la liste. */
+GScanTokenModifier *g_scan_modifier_list_get(const GScanModifierList *, size_t);
+
+
+
+#endif /* _ANALYSIS_SCAN_MODIFIERS_LIST_H */
diff --git a/src/analysis/scan/patterns/modifiers/lower.c b/src/analysis/scan/patterns/modifiers/lower.c
new file mode 100644
index 0000000..3904c52
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/lower.c
@@ -0,0 +1,301 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * lower.c - transformation d'une séquence d'octets par passage en minuscules
+ *
+ * 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 "lower.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "../modifier-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des transmissions en minuscules. */
+static void g_scan_lower_modifier_class_init(GScanLowerModifierClass *klass);
+
+/* Initialise une instance de transmission en minuscules. */
+static void g_scan_lower_modifier_init(GScanLowerModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_lower_modifier_dispose(GScanLowerModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_lower_modifier_finalize(GScanLowerModifier *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_lower_modifier_get_name(const GScanLowerModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_lower_modifier_transform(const GScanLowerModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_lower_modifier_get_path(const GScanLowerModifier *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transformation par bascule en minuscules. */
+G_DEFINE_TYPE(GScanLowerModifier, g_scan_lower_modifier, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transmissions en minuscules. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_lower_modifier_class_init(GScanLowerModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_lower_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_lower_modifier_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_lower_modifier_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_lower_modifier_transform;
+ modifier->get_path = (get_modifier_path)g_scan_lower_modifier_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transmission en minuscules. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_lower_modifier_init(GScanLowerModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_lower_modifier_dispose(GScanLowerModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_lower_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_lower_modifier_finalize(GScanLowerModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_lower_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un modificateur livrant des octets en minuscules. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_lower_modifier_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_LOWER_MODIFIER, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_lower_modifier_get_name(const GScanLowerModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("lower");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_lower_modifier_transform(const GScanLowerModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours #1 */
+ const sized_binary_t *_src; /* Source courante */
+ size_t k; /* Boucle de parcours #2 */
+
+ result = true;
+
+ *dcount = scount;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++, binary++)
+ {
+ _src = src + i;
+
+ binary->len = _src->len;
+ binary->data = malloc(binary->len);
+
+ for (k = 0; k < _src->len; k++)
+ switch (_src->data[k])
+ {
+ case 'A' ... 'Z':
+ binary->data[k] = _src->data[k] + 0x20;
+ break;
+
+ default:
+ binary->data[k] = _src->data[k];
+ break;
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_lower_modifier_get_path(const GScanLowerModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (*index > 0)
+ {
+ result = NULL;
+ (*index)--;
+ }
+
+ else
+ result = strdup("lower");
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/lower.h b/src/analysis/scan/patterns/modifiers/lower.h
new file mode 100644
index 0000000..d361340
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/lower.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * lower.h - prototypes pour la transformation d'une séquence d'octets par passage en minuscules
+ *
+ * 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_PATTERNS_MODIFIERS_LOWER_H
+#define _ANALYSIS_SCAN_PATTERNS_MODIFIERS_LOWER_H
+
+
+#include <glib-object.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_LOWER_MODIFIER g_scan_lower_modifier_get_type()
+#define G_SCAN_LOWER_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_LOWER_MODIFIER, GScanLowerModifier))
+#define G_IS_SCAN_LOWER_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_LOWER_MODIFIER))
+#define G_SCAN_LOWER_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_LOWER_MODIFIER, GScanLowerModifierClass))
+#define G_IS_SCAN_LOWER_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_LOWER_MODIFIER))
+#define G_SCAN_LOWER_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_LOWER_MODIFIER, GScanLowerModifierClass))
+
+
+/* Transformation d'une séquence d'octets par passage en minuscules (instance) */
+typedef GScanTokenModifier GScanLowerModifier;
+
+/* Transformation d'une séquence d'octets par passage en minuscules (classe) */
+typedef GScanTokenModifierClass GScanLowerModifierClass;
+
+
+/* Indique le type défini pour une transformation par bascule en minuscules. */
+GType g_scan_lower_modifier_get_type(void);
+
+/* Construit un modificateur livrant des octets en minuscules. */
+GScanTokenModifier *g_scan_lower_modifier_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_MODIFIERS_LOWER_H */
diff --git a/src/analysis/scan/patterns/modifiers/pipe-int.h b/src/analysis/scan/patterns/modifiers/pipe-int.h
new file mode 100644
index 0000000..63c4d97
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/pipe-int.h
@@ -0,0 +1,54 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * pipe-int.h - prototypes internes pour la gestion de combinaisons de transformateurs
+ *
+ * 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_MODIFIERS_PIPE_INT_H
+#define _ANALYSIS_SCAN_MODIFIERS_PIPE_INT_H
+
+
+#include "pipe.h"
+
+
+#include "../modifier-int.h"
+
+
+
+/* Enchainement combinatoire de transformations d'octets (instance) */
+struct _GScanModifierPipe
+{
+ GScanTokenModifier parent; /* A laisser en premier */
+
+ GScanTokenModifier **modifiers; /* Pipee de transformateurs */
+ size_t count; /* Taille de cette pipee */
+
+};
+
+/* Enchainement combinatoire de transformations d'octets (classe) */
+struct _GScanModifierPipeClass
+{
+ GScanTokenModifierClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_MODIFIERS_PIPE_INT_H */
diff --git a/src/analysis/scan/patterns/modifiers/pipe.c b/src/analysis/scan/patterns/modifiers/pipe.c
new file mode 100644
index 0000000..7c659ea
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/pipe.c
@@ -0,0 +1,405 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * pipe.c - gestion de combinaisons de transformateurs
+ *
+ * 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 "pipe.h"
+
+
+#include <assert.h>
+#include <malloc.h>
+
+
+#include "pipe-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des pipee de transformations d'octets. */
+static void g_scan_modifier_pipe_class_init(GScanModifierPipeClass *);
+
+/* Initialise une instance de pipee de transformations d'octets. */
+static void g_scan_modifier_pipe_init(GScanModifierPipe *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_modifier_pipe_dispose(GScanModifierPipe *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_modifier_pipe_finalize(GScanModifierPipe *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_modifier_pipe_get_name(const GScanModifierPipe *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_modifier_pipe_transform(const GScanModifierPipe *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_modifier_pipe_get_path(const GScanModifierPipe *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une série de transformations d'octets. */
+G_DEFINE_TYPE(GScanModifierPipe, g_scan_modifier_pipe, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des pipee de transformations d'octets. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_pipe_class_init(GScanModifierPipeClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_modifier_pipe_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_modifier_pipe_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_modifier_pipe_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_modifier_pipe_transform;
+ modifier->get_path = (get_modifier_path)g_scan_modifier_pipe_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pipe = instance à initialiser. *
+* *
+* Description : Initialise une instance de pipee de transformations d'octets.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_pipe_init(GScanModifierPipe *pipe)
+{
+ pipe->modifiers = NULL;
+ pipe->count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pipe = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_pipe_dispose(GScanModifierPipe *pipe)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < pipe->count; i++)
+ g_clear_object(&pipe->modifiers[i]);
+
+ G_OBJECT_CLASS(g_scan_modifier_pipe_parent_class)->dispose(G_OBJECT(pipe));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pipe = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_modifier_pipe_finalize(GScanModifierPipe *pipe)
+{
+ if (pipe->modifiers != NULL)
+ free(pipe->modifiers);
+
+ G_OBJECT_CLASS(g_scan_modifier_pipe_parent_class)->finalize(G_OBJECT(pipe));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit une pipee de modificateurs d'octets. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_modifier_pipe_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_MODIFIER_PIPE, NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pipe = pipee de modificateurs à étendre. *
+* modifier = modificateur à intégrer. *
+* *
+* Description : Intègre un nouveau transformateur à enchaîner. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_modifier_pipe_add(GScanModifierPipe *pipe, GScanTokenModifier *modifier)
+{
+ pipe->modifiers = realloc(pipe->modifiers, ++pipe->count * sizeof(GScanTokenModifier *));
+
+ pipe->modifiers[pipe->count - 1] = modifier;
+ g_object_ref(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pipe = série à consulter. *
+* *
+* Description : Indique le nombre de transformateurs intégrés dans la série. *
+* *
+* Retour : Nombre de modificateurs représentés. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_scan_modifier_pipe_count(const GScanModifierPipe *pipe)
+{
+ size_t result; /* Quantité à retourner */
+
+ result = pipe->count;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pipe = série à consulter. *
+* index = indice du paramètre à retourner. *
+* *
+* Description : Fournit un transformateur donné de la série. *
+* *
+* Retour : Modificateur inclus dans la pipee ou NULL si mauvais indice. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_modifier_pipe_get(const GScanModifierPipe *pipe, size_t index)
+{
+ GScanTokenModifier *result; /* Instance à retourner */
+
+ assert(index < pipe->count);
+
+ if (index < pipe->count)
+ {
+ result = pipe->modifiers[index];
+ g_object_ref(G_OBJECT(result));
+ }
+
+ else
+ result = NULL;
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_modifier_pipe_get_name(const GScanModifierPipe *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("(pipe)");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_modifier_pipe_transform(const GScanModifierPipe *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ size_t i; /* Boucle de parcours #1 */
+ sized_binary_t *tmp_in; /* Motifs supplémentaires */
+ size_t tmp_in_count; /* Quantité de ces motifs */
+ sized_binary_t *tmp_out; /* Motifs supplémentaires */
+ size_t tmp_out_count; /* Quantité de ces motifs */
+ size_t k; /* Boucle de parcours #2 */
+
+ for (i = 0; i < modifier->count; i++)
+ {
+ if (i == 0)
+ result = g_scan_token_modifier_transform(modifier->modifiers[i],
+ src, scount, &tmp_out, &tmp_out_count);
+
+ else
+ {
+ tmp_in = tmp_out;
+ tmp_in_count = tmp_out_count;
+
+ result = g_scan_token_modifier_transform(modifier->modifiers[i],
+ tmp_in, tmp_in_count, &tmp_out, &tmp_out_count);
+
+ for (k = 0; k < tmp_in_count; k++)
+ exit_szstr(&tmp_in[k]);
+
+ if (tmp_in != NULL)
+ free(tmp_in);
+
+ }
+
+ if (!result)
+ break;
+
+ }
+
+ if (!result)
+ {
+ for (k = 0; k < tmp_out_count; k++)
+ exit_szstr(&tmp_out[k]);
+
+ if (tmp_out != NULL)
+ free(tmp_out);
+
+ *dest = NULL;
+ *dcount = 0;
+
+ }
+ else
+ {
+ *dcount += tmp_out_count;
+ *dest = tmp_out;
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_modifier_pipe_get_path(const GScanModifierPipe *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+ size_t i; /* Boucle de parcours #1 */
+
+ result = NULL;
+
+ for (i = 0; i < modifier->count && result == NULL; i++)
+ result = g_scan_token_modifier_get_path(modifier->modifiers[i], index);
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/pipe.h b/src/analysis/scan/patterns/modifiers/pipe.h
new file mode 100644
index 0000000..8f9ca48
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/pipe.h
@@ -0,0 +1,68 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * pipe.h - prototypes pour la gestion de combinaisons de transformateurs
+ *
+ * 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_MODIFIERS_PIPE_H
+#define _ANALYSIS_SCAN_MODIFIERS_PIPE_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_MODIFIER_PIPE g_scan_modifier_pipe_get_type()
+#define G_SCAN_MODIFIER_PIPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_MODIFIER_PIPE, GScanModifierPipe))
+#define G_IS_SCAN_MODIFIER_PIPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_MODIFIER_PIPE))
+#define G_SCAN_MODIFIER_PIPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_MODIFIER_PIPE, GScanModifierPipeClass))
+#define G_IS_SCAN_MODIFIER_PIPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_MODIFIER_PIPE))
+#define G_SCAN_MODIFIER_PIPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_MODIFIER_PIPE, GScanModifierPipeClass))
+
+
+/* Enchainement combinatoire de transformations d'octets (instance) */
+typedef struct _GScanModifierPipe GScanModifierPipe;
+
+/* Enchainement combinatoire de transformations d'octets (classe) */
+typedef struct _GScanModifierPipeClass GScanModifierPipeClass;
+
+
+/* Indique le type défini pour une série de transformations d'octets. */
+GType g_scan_modifier_pipe_get_type(void);
+
+/* Construit une pipee de modificateurs d'octets. */
+GScanTokenModifier *g_scan_modifier_pipe_new(void);
+
+/* Intègre un nouveau transformateur à enchaîner. */
+void g_scan_modifier_pipe_add(GScanModifierPipe *, GScanTokenModifier *);
+
+/* Indique le nombre de transformateurs intégrés dans la série. */
+size_t g_scan_modifier_pipe_count(const GScanModifierPipe *);
+
+/* Fournit un transformateur donné de la pipee. */
+GScanTokenModifier *g_scan_modifier_pipe_get(const GScanModifierPipe *, size_t);
+
+
+
+#endif /* _ANALYSIS_SCAN_MODIFIERS_PIPE_H */
diff --git a/src/analysis/scan/patterns/modifiers/plain.c b/src/analysis/scan/patterns/modifiers/plain.c
new file mode 100644
index 0000000..ad09129
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/plain.c
@@ -0,0 +1,289 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain.c - transmission à l'identique d'une séquence d'octets
+ *
+ * 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 "plain.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "../modifier-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des transmissions à l'identique. */
+static void g_scan_plain_modifier_class_init(GScanPlainModifierClass *klass);
+
+/* Initialise une instance de transmission à l'identique. */
+static void g_scan_plain_modifier_init(GScanPlainModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_plain_modifier_dispose(GScanPlainModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_plain_modifier_finalize(GScanPlainModifier *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_plain_modifier_get_name(const GScanPlainModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_plain_modifier_transform(const GScanPlainModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_plain_modifier_get_path(const GScanPlainModifier *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transmission à l'identique d'une séquence d'octets. */
+G_DEFINE_TYPE(GScanPlainModifier, g_scan_plain_modifier, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transmissions à l'identique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_modifier_class_init(GScanPlainModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_plain_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_plain_modifier_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_plain_modifier_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_plain_modifier_transform;
+ modifier->get_path = (get_modifier_path)g_scan_plain_modifier_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transmission à l'identique. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_modifier_init(GScanPlainModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_modifier_dispose(GScanPlainModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_plain_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_modifier_finalize(GScanPlainModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_plain_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un modificateur livrant des octets à l'identique. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_plain_modifier_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_PLAIN_MODIFIER, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_plain_modifier_get_name(const GScanPlainModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("plain");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_plain_modifier_transform(const GScanPlainModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours */
+ const sized_binary_t *_src; /* Source courante */
+
+ result = true;
+
+ *dcount = scount;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++, binary++)
+ {
+ _src = src + i;
+
+ binary->len = _src->len;
+ binary->data = malloc(binary->len);
+
+ memcpy(binary->data, _src->data, _src->len);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_plain_modifier_get_path(const GScanPlainModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (*index > 0)
+ {
+ result = NULL;
+ (*index)--;
+ }
+
+ else
+ result = strdup("plain");
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/plain.h b/src/analysis/scan/patterns/modifiers/plain.h
new file mode 100644
index 0000000..ecabefd
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/plain.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain.h - prototypes pour la transmission à l'identique d'une séquence d'octets
+ *
+ * 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_PATTERNS_MODIFIERS_PLAIN_H
+#define _ANALYSIS_SCAN_PATTERNS_MODIFIERS_PLAIN_H
+
+
+#include <glib-object.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_PLAIN_MODIFIER g_scan_plain_modifier_get_type()
+#define G_SCAN_PLAIN_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_PLAIN_MODIFIER, GScanPlainModifier))
+#define G_IS_SCAN_PLAIN_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_PLAIN_MODIFIER))
+#define G_SCAN_PLAIN_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_PLAIN_MODIFIER, GScanPlainModifierClass))
+#define G_IS_SCAN_PLAIN_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_PLAIN_MODIFIER))
+#define G_SCAN_PLAIN_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_PLAIN_MODIFIER, GScanPlainModifierClass))
+
+
+/* Transmission à l'identique d'une séquence d'octets (instance) */
+typedef GScanTokenModifier GScanPlainModifier;
+
+/* Transmission à l'identique d'une séquence d'octets (classe) */
+typedef GScanTokenModifierClass GScanPlainModifierClass;
+
+
+/* Indique le type défini pour une transmission à l'identique d'une séquence d'octets. */
+GType g_scan_plain_modifier_get_type(void);
+
+/* Construit un modificateur livrant des octets à l'identique. */
+GScanTokenModifier *g_scan_plain_modifier_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_MODIFIERS_PLAIN_H */
diff --git a/src/analysis/scan/patterns/modifiers/rev.c b/src/analysis/scan/patterns/modifiers/rev.c
new file mode 100644
index 0000000..ef4d5fa
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/rev.c
@@ -0,0 +1,291 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * rev.c - transormation via inversement d'une séquence d'octets
+ *
+ * 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 "rev.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "../modifier-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des transmissions via inversement. */
+static void g_scan_reverse_modifier_class_init(GScanReverseModifierClass *klass);
+
+/* Initialise une instance de transmission via inversement. */
+static void g_scan_reverse_modifier_init(GScanReverseModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_reverse_modifier_dispose(GScanReverseModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_reverse_modifier_finalize(GScanReverseModifier *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_reverse_modifier_get_name(const GScanReverseModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_reverse_modifier_transform(const GScanReverseModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_reverse_modifier_get_path(const GScanReverseModifier *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transormation via inversement d'une séquence d'octets. */
+G_DEFINE_TYPE(GScanReverseModifier, g_scan_reverse_modifier, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transmissions via inversement. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_reverse_modifier_class_init(GScanReverseModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_reverse_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_reverse_modifier_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_reverse_modifier_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_reverse_modifier_transform;
+ modifier->get_path = (get_modifier_path)g_scan_reverse_modifier_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transmission via inversement. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_reverse_modifier_init(GScanReverseModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_reverse_modifier_dispose(GScanReverseModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_reverse_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_reverse_modifier_finalize(GScanReverseModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_reverse_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un modificateur livrant des octets inversés. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_reverse_modifier_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_REVERSE_MODIFIER, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_reverse_modifier_get_name(const GScanReverseModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("rev");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_reverse_modifier_transform(const GScanReverseModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours #1 */
+ const sized_binary_t *_src; /* Source courante */
+ size_t k; /* Boucle de parcours #2 */
+
+ result = true;
+
+ *dcount = scount;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++, binary++)
+ {
+ _src = src + i;
+
+ binary->len = _src->len;
+ binary->data = malloc(binary->len);
+
+ for (k = 0; k < _src->len; k++)
+ binary->data[_src->len - k - 1] = _src->data[k];
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_reverse_modifier_get_path(const GScanReverseModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (*index > 0)
+ {
+ result = NULL;
+ (*index)--;
+ }
+
+ else
+ result = strdup("rev");
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/rev.h b/src/analysis/scan/patterns/modifiers/rev.h
new file mode 100644
index 0000000..5b4e398
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/rev.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * rev.h - prototypes pour la transormation via inversement d'une séquence d'octets
+ *
+ * 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_PATTERNS_MODIFIERS_REV_H
+#define _ANALYSIS_SCAN_PATTERNS_MODIFIERS_REV_H
+
+
+#include <glib-object.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_REVERSE_MODIFIER g_scan_reverse_modifier_get_type()
+#define G_SCAN_REVERSE_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_REVERSE_MODIFIER, GScanReverseModifier))
+#define G_IS_SCAN_REVERSE_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_REVERSE_MODIFIER))
+#define G_SCAN_REVERSE_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_REVERSE_MODIFIER, GScanReverseModifierClass))
+#define G_IS_SCAN_REVERSE_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_REVERSE_MODIFIER))
+#define G_SCAN_REVERSE_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_REVERSE_MODIFIER, GScanReverseModifierClass))
+
+
+/* Transormation via inversement d'une séquence d'octets (instance) */
+typedef GScanTokenModifier GScanReverseModifier;
+
+/* Transormation via inversement d'une séquence d'octets (classe) */
+typedef GScanTokenModifierClass GScanReverseModifierClass;
+
+
+/* Indique le type défini pour une transormation via inversement d'une séquence d'octets. */
+GType g_scan_reverse_modifier_get_type(void);
+
+/* Construit un modificateur livrant des octets inversés. */
+GScanTokenModifier *g_scan_reverse_modifier_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_MODIFIERS_REV_H */
diff --git a/src/analysis/scan/patterns/modifiers/upper.c b/src/analysis/scan/patterns/modifiers/upper.c
new file mode 100644
index 0000000..9d1086b
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/upper.c
@@ -0,0 +1,301 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * upper.c - transformation d'une séquence d'octets par passage en majuscules
+ *
+ * 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 "upper.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "../modifier-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des transmissions en majuscules. */
+static void g_scan_upper_modifier_class_init(GScanUpperModifierClass *klass);
+
+/* Initialise une instance de transmission en majuscules. */
+static void g_scan_upper_modifier_init(GScanUpperModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_upper_modifier_dispose(GScanUpperModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_upper_modifier_finalize(GScanUpperModifier *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_upper_modifier_get_name(const GScanUpperModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_upper_modifier_transform(const GScanUpperModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_upper_modifier_get_path(const GScanUpperModifier *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transformation par bascule en majuscules. */
+G_DEFINE_TYPE(GScanUpperModifier, g_scan_upper_modifier, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transmissions en majuscules. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_upper_modifier_class_init(GScanUpperModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_upper_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_upper_modifier_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_upper_modifier_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_upper_modifier_transform;
+ modifier->get_path = (get_modifier_path)g_scan_upper_modifier_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transmission en majuscules. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_upper_modifier_init(GScanUpperModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_upper_modifier_dispose(GScanUpperModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_upper_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_upper_modifier_finalize(GScanUpperModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_upper_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un modificateur livrant des octets en majuscules. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_upper_modifier_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_UPPER_MODIFIER, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_upper_modifier_get_name(const GScanUpperModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("upper");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_upper_modifier_transform(const GScanUpperModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours #1 */
+ const sized_binary_t *_src; /* Source courante */
+ size_t k; /* Boucle de parcours #2 */
+
+ result = true;
+
+ *dcount = scount;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++, binary++)
+ {
+ _src = src + i;
+
+ binary->len = _src->len;
+ binary->data = malloc(binary->len);
+
+ for (k = 0; k < _src->len; k++)
+ switch (_src->data[k])
+ {
+ case 'a' ... 'z':
+ binary->data[k] = _src->data[k] - 0x20;
+ break;
+
+ default:
+ binary->data[k] = _src->data[k];
+ break;
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_upper_modifier_get_path(const GScanUpperModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (*index > 0)
+ {
+ result = NULL;
+ (*index)--;
+ }
+
+ else
+ result = strdup("upper");
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/upper.h b/src/analysis/scan/patterns/modifiers/upper.h
new file mode 100644
index 0000000..4666312
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/upper.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * upper.h - prototypes pour la transformation d'une séquence d'octets par passage en majuscules
+ *
+ * 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_PATTERNS_MODIFIERS_UPPER_H
+#define _ANALYSIS_SCAN_PATTERNS_MODIFIERS_UPPER_H
+
+
+#include <glib-object.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_UPPER_MODIFIER g_scan_upper_modifier_get_type()
+#define G_SCAN_UPPER_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_UPPER_MODIFIER, GScanUpperModifier))
+#define G_IS_SCAN_UPPER_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_UPPER_MODIFIER))
+#define G_SCAN_UPPER_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_UPPER_MODIFIER, GScanUpperModifierClass))
+#define G_IS_SCAN_UPPER_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_UPPER_MODIFIER))
+#define G_SCAN_UPPER_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_UPPER_MODIFIER, GScanUpperModifierClass))
+
+
+/* Transformation d'une séquence d'octets par passage en majuscules (instance) */
+typedef GScanTokenModifier GScanUpperModifier;
+
+/* Transformation d'une séquence d'octets par passage en majuscules (classe) */
+typedef GScanTokenModifierClass GScanUpperModifierClass;
+
+
+/* Indique le type défini pour une transformation par bascule en majuscules. */
+GType g_scan_upper_modifier_get_type(void);
+
+/* Construit un modificateur livrant des octets en majuscules. */
+GScanTokenModifier *g_scan_upper_modifier_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_MODIFIERS_UPPER_H */
diff --git a/src/analysis/scan/patterns/modifiers/wide.c b/src/analysis/scan/patterns/modifiers/wide.c
new file mode 100644
index 0000000..ef252d9
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/wide.c
@@ -0,0 +1,291 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * wide.c - transcription d'une séquence d'octets en UTF-16
+ *
+ * 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 "wide.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "../modifier-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des transcriptions en UTF-16. */
+static void g_scan_wide_modifier_class_init(GScanWideModifierClass *klass);
+
+/* Initialise une instance de transcription en UTF-16. */
+static void g_scan_wide_modifier_init(GScanWideModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_wide_modifier_dispose(GScanWideModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_wide_modifier_finalize(GScanWideModifier *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_wide_modifier_get_name(const GScanWideModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_wide_modifier_transform(const GScanWideModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_wide_modifier_get_path(const GScanWideModifier *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transcription d'une séquence d'octets en UTF-16. */
+G_DEFINE_TYPE(GScanWideModifier, g_scan_wide_modifier, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transcriptions en UTF-16. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_wide_modifier_class_init(GScanWideModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_wide_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_wide_modifier_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_wide_modifier_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_wide_modifier_transform;
+ modifier->get_path = (get_modifier_path)g_scan_wide_modifier_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transcription en UTF-16. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_wide_modifier_init(GScanWideModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_wide_modifier_dispose(GScanWideModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_wide_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_wide_modifier_finalize(GScanWideModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_wide_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un modificateur livrant des octets en UTF-16. *
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_wide_modifier_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_WIDE_MODIFIER, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_wide_modifier_get_name(const GScanWideModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("wide");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_wide_modifier_transform(const GScanWideModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours #1 */
+ const sized_binary_t *_src; /* Source courante */
+ size_t k; /* Boucle de parcours #2 */
+
+ result = true;
+
+ *dcount = scount;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++, binary++)
+ {
+ _src = src + i;
+
+ binary->len = _src->len * 2;
+ binary->data = calloc(binary->len * 2, sizeof(bin_t));
+
+ for (k = 0; k < _src->len; k++)
+ binary->data[k * 2] = _src->data[k];
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_wide_modifier_get_path(const GScanWideModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (*index > 0)
+ {
+ result = NULL;
+ (*index)--;
+ }
+
+ else
+ result = strdup("wide");
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/wide.h b/src/analysis/scan/patterns/modifiers/wide.h
new file mode 100644
index 0000000..deb92a4
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/wide.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * wide.h - prototypes pour la transcription d'une séquence d'octets en UTF-16
+ *
+ * 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_PATTERNS_MODIFIERS_WIDE_H
+#define _ANALYSIS_SCAN_PATTERNS_MODIFIERS_WIDE_H
+
+
+#include <glib-object.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_WIDE_MODIFIER g_scan_wide_modifier_get_type()
+#define G_SCAN_WIDE_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_WIDE_MODIFIER, GScanWideModifier))
+#define G_IS_SCAN_WIDE_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_WIDE_MODIFIER))
+#define G_SCAN_WIDE_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_WIDE_MODIFIER, GScanWideModifierClass))
+#define G_IS_SCAN_WIDE_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_WIDE_MODIFIER))
+#define G_SCAN_WIDE_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_WIDE_MODIFIER, GScanWideModifierClass))
+
+
+/* Transcription d'une séquence d'octets en UTF-16 (instance) */
+typedef GScanTokenModifier GScanWideModifier;
+
+/* Transcription d'une séquence d'octets en UTF-16 (classe) */
+typedef GScanTokenModifierClass GScanWideModifierClass;
+
+
+/* Indique le type défini pour une transcription d'une séquence d'octets en UTF-16. */
+GType g_scan_wide_modifier_get_type(void);
+
+/* Construit un modificateur livrant des octets en UTF-16. */
+GScanTokenModifier *g_scan_wide_modifier_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_MODIFIERS_WIDE_H */
diff --git a/src/analysis/scan/patterns/modifiers/xor.c b/src/analysis/scan/patterns/modifiers/xor.c
new file mode 100644
index 0000000..d932c82
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/xor.c
@@ -0,0 +1,438 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * xor.c - transormation via opération XOR
+ *
+ * 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 "xor.h"
+
+
+#include <assert.h>
+#include <malloc.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+
+#include "../modifier-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des transmissions via opération XOR. */
+static void g_scan_xor_modifier_class_init(GScanXorModifierClass *klass);
+
+/* Initialise une instance de transmission via opération XOR. */
+static void g_scan_xor_modifier_init(GScanXorModifier *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_xor_modifier_dispose(GScanXorModifier *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_xor_modifier_finalize(GScanXorModifier *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Fournit le nom d'appel d'un modificateur pour motif. */
+static char *g_scan_xor_modifier_get_name(const GScanXorModifier *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_xor_modifier_transform(const GScanXorModifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *);
+
+/* Détermine si un argument est bien toléré par un modificateur. */
+static bool g_scan_xor_modifier_can_handle_arg(const GScanXorModifier *, const modifier_arg_t *);
+
+/* Transforme une séquence d'octets pour motif de recherche. */
+static bool g_scan_xor_modifier_transform_with_arg(const GScanXorModifier *, const sized_binary_t *, size_t, const modifier_arg_t *, sized_binary_t **, size_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+static char *g_scan_xor_modifier_get_path(const GScanXorModifier *, size_t *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une transormation via une opération XOR. */
+G_DEFINE_TYPE(GScanXorModifier, g_scan_xor_modifier, G_TYPE_SCAN_TOKEN_MODIFIER);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des transmissions via opération XOR. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_xor_modifier_class_init(GScanXorModifierClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenModifierClass *modifier; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_xor_modifier_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_xor_modifier_finalize;
+
+ modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass);
+
+ modifier->get_name = (get_scan_modifier_name_fc)g_scan_xor_modifier_get_name;
+
+ modifier->transform = (transform_scan_token_fc)g_scan_xor_modifier_transform;
+ modifier->can_handle = (can_token_modifier_handle_arg)g_scan_xor_modifier_can_handle_arg;
+ modifier->transform_with = (transform_scan_token_with_fc)g_scan_xor_modifier_transform_with_arg;
+ modifier->get_path = (get_modifier_path)g_scan_xor_modifier_get_path;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance à initialiser. *
+* *
+* Description : Initialise une instance de transmission via opération XOR. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_xor_modifier_init(GScanXorModifier *modifier)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_xor_modifier_dispose(GScanXorModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_xor_modifier_parent_class)->dispose(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_xor_modifier_finalize(GScanXorModifier *modifier)
+{
+ G_OBJECT_CLASS(g_scan_xor_modifier_parent_class)->finalize(G_OBJECT(modifier));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un modificateur livrant des octets traités par XOR.*
+* *
+* Retour : Mécanisme mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenModifier *g_scan_xor_modifier_new(void)
+{
+ GScanTokenModifier *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_XOR_MODIFIER, NULL);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* *
+* Description : Fournit le nom d'appel d'un modificateur pour motif. *
+* *
+* Retour : Désignation humaine. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_xor_modifier_get_name(const GScanXorModifier *modifier)
+{
+ char *result; /* Désignation à retourner */
+
+ result = strdup("xor");
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_xor_modifier_transform(const GScanXorModifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours #1 */
+ const sized_binary_t *_src; /* Source courante */
+ long long x; /* Boucle de parcours #2 */
+ size_t k; /* Boucle de parcours #3 */
+
+ result = true;
+
+ *dcount = scount * 256;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++)
+ {
+ _src = src + i;
+
+ for (x = 0; x <= 0xff; x++, binary++)
+ {
+ binary->len = _src->len;
+ binary->data = malloc(binary->len);
+
+ for (k = 0; k < _src->len; k++)
+ binary->data[k] = _src->data[k] ^ x;
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* arg = argument de personnalisation. *
+* *
+* Description : Détermine si un argument est bien toléré par un modificateur.*
+* *
+* Retour : Bilan de la consultation : support ou non. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_xor_modifier_can_handle_arg(const GScanXorModifier *modifier, const modifier_arg_t *arg)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+
+ switch (arg->type)
+ {
+ case MAT_UNSIGNED_INTEGER:
+ result = (arg->value.u_integer <= UINT8_MAX);
+ break;
+
+ case MAT_RANGE:
+ result = (INT8_MIN <= arg->value.range.start && arg->value.range.end <= INT8_MAX);
+ break;
+
+ default:
+ result = false;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à solliciter. *
+* src = séquences d'octets à traiter. *
+* scount = quantité de ces séquences. *
+* arg = argument de personnalisation. *
+* dest = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] *
+* dcount = quantité de ces séquences. *
+* *
+* Description : Transforme une séquence d'octets pour motif de recherche. *
+* *
+* Retour : Bilan de l'opération : succès ou échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_xor_modifier_transform_with_arg(const GScanXorModifier *modifier, const sized_binary_t *src, size_t scount, const modifier_arg_t *arg, sized_binary_t **dest, size_t *dcount)
+{
+ bool result; /* Bilan d'opération à renvoyer*/
+ sized_binary_t *binary; /* Raccourci vers le stockage */
+ size_t i; /* Boucle de parcours #1 */
+ const sized_binary_t *_src; /* Source courante */
+ long long x; /* Boucle de parcours #2 */
+ size_t k; /* Boucle de parcours #3 */
+
+ result = true;
+
+ switch (arg->type)
+ {
+ case MAT_UNSIGNED_INTEGER:
+
+ *dcount = scount;
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++)
+ {
+ _src = src + i;
+
+ binary->len = _src->len;
+ binary->data = malloc(binary->len);
+
+ for (k = 0; k < _src->len; k++)
+ binary->data[k] = _src->data[k] ^ arg->value.u_integer;
+
+ }
+
+ break;
+
+ case MAT_RANGE:
+
+ *dcount = scount * (arg->value.range.end - arg->value.range.start + 1);
+ *dest = malloc(*dcount * sizeof(sized_binary_t));
+
+ binary = &(*dest)[0];
+
+ for (i = 0; i < scount; i++)
+ {
+ _src = src + i;
+
+ for (x = arg->value.range.start; x <= arg->value.range.end; x++, binary++)
+ {
+ binary->len = _src->len;
+ binary->data = malloc(binary->len);
+
+ for (k = 0; k < _src->len; k++)
+ binary->data[k] = _src->data[k] ^ x;
+
+ }
+
+ }
+
+ break;
+
+ default:
+ assert(false);
+ result = false;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : modifier = modificateur à consulter. *
+* index = indice de la combinaison ciblée. [OUT] *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *g_scan_xor_modifier_get_path(const GScanXorModifier *modifier, size_t *index)
+{
+ char *result; /* Combinaison à retourner */
+ int ret; /* Bilan intermédiaire */
+
+ if (*index > 255)
+ {
+ result = NULL;
+ (*index) -= 256;
+ }
+
+ else
+ {
+ ret = asprintf(&result, "xor(0x%02hhx)", (unsigned char)*index);
+
+ if (ret == -1)
+ result = strdup("xor(0x?)");
+
+ }
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/modifiers/xor.h b/src/analysis/scan/patterns/modifiers/xor.h
new file mode 100644
index 0000000..1a3e7e6
--- /dev/null
+++ b/src/analysis/scan/patterns/modifiers/xor.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * xor.h - prototypes pour la transormation via opération XOR
+ *
+ * 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_PATTERNS_MODIFIERS_XOR_H
+#define _ANALYSIS_SCAN_PATTERNS_MODIFIERS_XOR_H
+
+
+#include <glib-object.h>
+
+
+#include "../modifier.h"
+
+
+
+#define G_TYPE_SCAN_XOR_MODIFIER g_scan_xor_modifier_get_type()
+#define G_SCAN_XOR_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_XOR_MODIFIER, GScanXorModifier))
+#define G_IS_SCAN_XOR_MODIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_XOR_MODIFIER))
+#define G_SCAN_XOR_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_XOR_MODIFIER, GScanXorModifierClass))
+#define G_IS_SCAN_XOR_MODIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_XOR_MODIFIER))
+#define G_SCAN_XOR_MODIFIER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_XOR_MODIFIER, GScanXorModifierClass))
+
+
+/* Transormation via inversement d'une séquence d'octets (instance) */
+typedef GScanTokenModifier GScanXorModifier;
+
+/* Transormation via inversement d'une séquence d'octets (classe) */
+typedef GScanTokenModifierClass GScanXorModifierClass;
+
+
+/* Indique le type défini pour une transormation via une opération XOR. */
+GType g_scan_xor_modifier_get_type(void);
+
+/* Construit un modificateur livrant des octets traités par XOR. */
+GScanTokenModifier *g_scan_xor_modifier_new(void);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_MODIFIERS_XOR_H */
diff --git a/src/analysis/scan/patterns/patid.h b/src/analysis/scan/patterns/patid.h
new file mode 100644
index 0000000..e8b7eee
--- /dev/null
+++ b/src/analysis/scan/patterns/patid.h
@@ -0,0 +1,36 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * patid.h - prototypes pour la définition d'un identifiant de motif partiel
+ *
+ * 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_PATTERNS_PATID_H
+#define _ANALYSIS_SCAN_PATTERNS_PATID_H
+
+
+
+/* Identifiant de motif intégré */
+typedef uint32_t patid_t;
+
+#define INVALID_PATTERN_ID 0xffffffff
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_PATID_H */
diff --git a/src/analysis/scan/patterns/token-int.h b/src/analysis/scan/patterns/token-int.h
new file mode 100644
index 0000000..7ba0aa4
--- /dev/null
+++ b/src/analysis/scan/patterns/token-int.h
@@ -0,0 +1,62 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * token-int.h - prototypes internes pour les bribes de recherche textuelle
+ *
+ * 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_PATTERNS_TOKEN_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKEN_INT_H
+
+
+#include "token.h"
+
+
+#include "../pattern-int.h"
+
+
+
+/* Encadrement d'une bribe de recherche textuelle (instance) */
+struct _GBytesToken
+{
+ GSearchPattern parent; /* A laisser en premier */
+
+ GScanTokenNode *root; /* Motif à rechercher */
+ size_t slow; /* Surcoût du motif */
+ bool need_backward; /* Besoin d'une seconde passe */
+
+ bool fullword; /* Cible de mots entiers ? */
+ bool private; /* Vocation privée ? */
+
+};
+
+/* Encadrement d'une bribe de recherche textuelle (classe) */
+struct _GBytesTokenClass
+{
+ GSearchPatternClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place un gestionnaire de recherche de binaire. */
+bool g_bytes_token_create(GBytesToken *, GScanTokenNode *, bool, bool);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKEN_INT_H */
diff --git a/src/analysis/scan/patterns/token.c b/src/analysis/scan/patterns/token.c
new file mode 100644
index 0000000..b3c6d53
--- /dev/null
+++ b/src/analysis/scan/patterns/token.c
@@ -0,0 +1,491 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * token.c - bribes de recherche textuelle
+ *
+ * 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 "token.h"
+
+
+#include <assert.h>
+#include <ctype.h>
+#include <stdio.h>
+
+
+#include "token-int.h"
+#include "tokens/nodes/plain.h"
+#include "../../../common/cpp.h"
+#include "../../../core/logs.h"
+
+
+
+/* ------------------------- CIBLAGE DES SEQUENCES D'OCTETS ------------------------- */
+
+
+/* Initialise la classe des bribes de recherche textuelle. */
+static void g_bytes_token_class_init(GBytesTokenClass *);
+
+/* Initialise une instance de bribe de recherche textuelle. */
+static void g_bytes_token_init(GBytesToken *);
+
+/* Supprime toutes les références externes. */
+static void g_bytes_token_dispose(GBytesToken *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_bytes_token_finalize(GBytesToken *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Affiche un motif de recherche au format texte. */
+static void g_bytes_token_output_to_text(const GBytesToken *, GScanContext *, int);
+
+/* Affiche un motif de recherche au format JSON. */
+static void g_bytes_token_output_to_json(const GBytesToken *, GScanContext *, const sized_string_t *, unsigned int, int);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* CIBLAGE DES SEQUENCES D'OCTETS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une bribe de recherche textuelle. */
+G_DEFINE_TYPE(GBytesToken, g_bytes_token, G_TYPE_SEARCH_PATTERN);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des bribes de recherche textuelle. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bytes_token_class_init(GBytesTokenClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GSearchPatternClass *pattern; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_bytes_token_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_bytes_token_finalize;
+
+ pattern = G_SEARCH_PATTERN_CLASS(klass);
+
+ pattern->to_text = (output_pattern_to_text_fc)g_bytes_token_output_to_text;
+ pattern->to_json = (output_pattern_to_json_fc)g_bytes_token_output_to_json;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = instance à initialiser. *
+* *
+* Description : Initialise une instance de bribe de recherche textuelle. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bytes_token_init(GBytesToken *token)
+{
+ token->root = NULL;
+ token->slow = 0;
+ token->need_backward = false;
+
+ token->fullword = false;
+ token->private = false;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bytes_token_dispose(GBytesToken *token)
+{
+ g_clear_object(&token->root);
+
+ G_OBJECT_CLASS(g_bytes_token_parent_class)->dispose(G_OBJECT(token));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bytes_token_finalize(GBytesToken *token)
+{
+ G_OBJECT_CLASS(g_bytes_token_parent_class)->finalize(G_OBJECT(token));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = encadrement de motif à initialiser pleinement. *
+* root = représentation du motif à recherche. *
+* fullword = limite les correspondances à des mots entiers. *
+* private = donne une vocation privée au motif de recherche. *
+* *
+* Description : Met en place un gestionnaire de recherche de binaire. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_bytes_token_create(GBytesToken *token, GScanTokenNode *root, bool fullword, bool private)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ token->root = root;
+ g_object_ref(G_OBJECT(root));
+
+ token->fullword = fullword;
+ token->private = private;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = encadrement de motif à consulter. *
+* *
+* Description : Indique si seuls des mots entiers sont retenus des analyses. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_bytes_token_target_fullword(const GBytesToken *token)
+{
+ bool result; /* Statut à renvoyer */
+
+ result = token->fullword;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = encadrement de motif à consulter. *
+* *
+* Description : Détermine si le gestionnaire est à vocation privée. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_bytes_token_is_private(const GBytesToken *token)
+{
+ bool result; /* Statut à renvoyer */
+
+ result = token->private;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_bytes_token_enroll(GBytesToken *token, GEngineBackend *backend, size_t maxsize)
+{
+ bool result; /* Statut à retourner */
+
+ token->need_backward = g_scan_token_node_setup_tree(token->root);
+
+ result = g_scan_token_node_enroll(token->root, backend, maxsize, &token->slow);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère les identifiants finaux pour un motif recherché. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_bytes_token_build_id(GBytesToken *token, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+
+ result = g_scan_token_node_build_id(token->root, backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = définition de la bribe à manipuler. *
+* matches = suivi des correspondances à consolider. *
+* params = paramètres des opérations de validation. *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_bytes_token_check(const GBytesToken *token, GScanBytesMatches *matches, scan_node_check_params_t *params)
+{
+ match_area_t *area; /* Correspondance à valider */
+ match_area_t *next; /* Correspondance suivante */
+ vmpa2t pos; /* Tête de lecture */
+ const bin_t *byte; /* Octet à valider */
+
+ /* Réinitialisation */
+
+ // TODO: offset
+
+ params->initialized = false;
+
+ params->main_areas = NULL;
+ params->main_count = 0;
+
+ params->created_areas = NULL;
+ params->created_count = 0;
+
+ params->kept_areas = NULL;
+ params->kept_count = 0;
+
+ /* Lancement des analyses */
+
+ g_scan_token_node_check_forward(token->root, params);
+
+ if (token->need_backward)
+ g_scan_token_node_check_backward(token->root, params);
+
+ // REMME ? sort_and_filter_pending_matches(matches);
+
+ if (token->fullword)
+ {
+ for_each_match_area_safe(area, &params->main_areas, next)
+ {
+ /* Validation de l'octet précédent, s'il existe */
+ if (area->start > params->content_start)
+ {
+ init_vmpa(&pos, area->start - 1, VMPA_NO_VIRTUAL);
+
+ byte = g_binary_content_get_raw_access(params->content, &pos, 1);
+
+ if (isalnum(*byte))
+ {
+ del_match_area(area, &params->main_areas);
+ assert(&params->main_count > 0);
+ params->main_count--;
+ continue;
+ }
+
+ }
+
+ /* Validation de l'octet suivant, s'il existe */
+ if (area->end < params->content_end)
+ {
+ init_vmpa(&pos, area->end, VMPA_NO_VIRTUAL);
+
+ byte = g_binary_content_get_raw_access(params->content, &pos, 1);
+
+ if (isalnum(*byte))
+ {
+ del_match_area(area, &params->main_areas);
+ assert(&params->main_count > 0);
+ params->main_count--;
+ continue;
+ }
+
+ }
+
+ }
+
+ }
+
+ g_scan_bytes_matches_set_list(matches, params->main_areas, params->main_count);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : token = définition de la bribe à consulter. *
+* index = indice de la combinaison de modificateurs ciblée. *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison gagnante. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_bytes_token_get_modifier_path(const GBytesToken *token, size_t index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (G_IS_SCAN_TOKEN_NODE_PLAIN(token->root))
+ result = g_scan_token_node_plain_get_modifier_path(G_SCAN_TOKEN_NODE_PLAIN(token->root), index);
+ else
+ result = NULL;
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : pattern = définition de motif à considérer. *
+* context = contexte de l'analyse à mener. *
+* fd = canal d'écriture. *
+* *
+* Description : Affiche un motif de recherche au format texte. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bytes_token_output_to_text(const GBytesToken *pattern, GScanContext *context, int fd)
+{
+ GScanMatches *matches; /* Correspondances établies */
+
+ if (g_bytes_token_is_private(pattern))
+ return;
+
+ matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern));
+
+ if (matches != NULL)
+ {
+ g_scan_matches_output_to_text(matches, fd);
+
+ g_object_unref(G_OBJECT(matches));
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pattern = définition de motif à considérer. *
+* context = contexte de l'analyse à mener. *
+* padding = éventuel bourrage initial à placer ou NULL. *
+* level = profondeur actuelle. *
+* fd = canal d'écriture. *
+* *
+* Description : Affiche un motif de recherche au format JSON. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_bytes_token_output_to_json(const GBytesToken *pattern, GScanContext *context, const sized_string_t *padding, unsigned int level, int fd)
+{
+ GScanMatches *matches; /* Correspondances établies */
+
+ if (g_bytes_token_is_private(pattern))
+ return;
+
+ matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern));
+
+ if (matches != NULL)
+ {
+ g_scan_matches_output_to_json(matches, padding, level, fd);
+
+ g_object_unref(G_OBJECT(matches));
+
+ }
+
+}
diff --git a/src/analysis/scan/patterns/token.h b/src/analysis/scan/patterns/token.h
new file mode 100644
index 0000000..f5b78f6
--- /dev/null
+++ b/src/analysis/scan/patterns/token.h
@@ -0,0 +1,75 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * token.h - prototypes pour les bribes de recherche textuelle
+ *
+ * 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_PATTERNS_TOKEN_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKEN_H
+
+
+#include <glib-object.h>
+
+
+#include "backend.h"
+#include "tokens/node.h"
+#include "../matches/bytes.h"
+
+
+
+#define G_TYPE_BYTES_TOKEN g_bytes_token_get_type()
+#define G_BYTES_TOKEN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BYTES_TOKEN, GBytesToken))
+#define G_IS_BYTES_TOKEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BYTES_TOKEN))
+#define G_BYTES_TOKEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BYTES_TOKEN, GBytesTokenClass))
+#define G_IS_BYTES_TOKEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BYTES_TOKEN))
+#define G_BYTES_TOKEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BYTES_TOKEN, GBytesTokenClass))
+
+
+/* Encadrement d'une bribe de recherche textuelle (instance) */
+typedef struct _GBytesToken GBytesToken;
+
+/* Encadrement d'une bribe de recherche textuelle (classe) */
+typedef struct _GBytesTokenClass GBytesTokenClass;
+
+
+/* Indique le type défini pour une bribe de recherche textuelle. */
+GType g_bytes_token_get_type(void);
+
+/* Indique si seuls des mots entiers sont retenus des analyses. */
+bool g_bytes_token_target_fullword(const GBytesToken *);
+
+/* Détermine si le gestionnaire est à vocation privée. */
+bool g_bytes_token_is_private(const GBytesToken *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+bool g_bytes_token_enroll(GBytesToken *, GEngineBackend *, size_t);
+
+/* Récupère les identifiants finaux pour un motif recherché. */
+bool g_bytes_token_build_id(GBytesToken *, GEngineBackend *);
+
+/* Transforme les correspondances locales en trouvailles. */
+void g_bytes_token_check(const GBytesToken *, GScanBytesMatches *, scan_node_check_params_t *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+char *g_bytes_token_get_modifier_path(const GBytesToken *, size_t);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKEN_H */
diff --git a/src/analysis/scan/patterns/tokens/Makefile.am b/src/analysis/scan/patterns/tokens/Makefile.am
new file mode 100644
index 0000000..f0ab3d5
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/Makefile.am
@@ -0,0 +1,26 @@
+
+noinst_LTLIBRARIES = libanalysisscanpatternstokens.la
+
+
+libanalysisscanpatternstokens_la_SOURCES = \
+ atom.h atom.c \
+ hex-int.h \
+ hex.h hex.c \
+ node-int.h \
+ node.h node.c \
+ offset.h offset.c \
+ plain-int.h \
+ plain.h plain.c
+
+libanalysisscanpatternstokens_la_LIBADD = \
+ nodes/libanalysisscanpatternstokensnodes.la
+
+libanalysisscanpatternstokens_la_CFLAGS = $(LIBGOBJ_CFLAGS)
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
+
+dev_HEADERS = $(libanalysisscanpatternstokens_la_SOURCES:%c=)
+
+
+SUBDIRS = nodes
diff --git a/src/analysis/scan/patterns/tokens/atom.c b/src/analysis/scan/patterns/tokens/atom.c
new file mode 100644
index 0000000..4f2ad67
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/atom.c
@@ -0,0 +1,543 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * atom.c - détermination d'atomes à partir de motifs
+ *
+ * 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 "atom.h"
+
+
+#include <assert.h>
+#include <malloc.h>
+#include <math.h>
+
+
+
+/**
+ * Remplacement des fonctions de <ctypes.h> dans support des locales.
+ */
+
+#define IS_CH_LETTER(ch) (('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z'))
+
+#define MAKE_CH_UPPER(ch) (ch & 0xdf)
+#define MAKE_CH_LOWER(ch) (ch | 0x20)
+
+
+
+/******************************************************************************
+* *
+* Paramètres : ch = octet dont la valeur est à analyser. *
+* seen = suivi des octets déjà rencontrés. [OUT] *
+* uniq = volume d'octets originaux à actualiser. [OUT] *
+* letters = nombre de lettres rencontrées. [OUT] *
+* *
+* Description : Note l'intêret de rechercher un octet particulier. *
+* *
+* Retour : Note positive ou négative. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int rate_byte_quality(bin_t ch, uint8_t *seen, size_t *uniq, size_t *letters)
+{
+ int result; /* Note à retourner */
+
+ switch (ch)
+ {
+ case 0x00:
+ case 0x20:
+ case 0x90:
+ case 0xcc:
+ case 0xff:
+ result = 12;
+ break;
+
+ case 'A' ... 'Z':
+ case 'a' ... 'z':
+ if (letters == NULL)
+ result = 20;
+ else
+ {
+ result = 18;
+ (*letters)++;
+ }
+ break;
+
+ default:
+ result = 20;
+ break;
+
+ }
+
+ if (seen[ch]++ == 0)
+ (*uniq)++;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : ch = octet dont la valeur est à analyser. *
+* seen = suivi des octets déjà rencontrés. [OUT] *
+* uniq = volume d'octets originaux à actualiser. [OUT] *
+* letters = nombre de lettres rencontrées. [OUT] *
+* *
+* Description : Annihile l'intêret de rechercher un octet particulier. *
+* *
+* Retour : Note positive ou négative. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int unrate_byte_quality(bin_t ch, uint8_t *seen, size_t *uniq, size_t *letters)
+{
+ int result; /* Note à retourner */
+
+ switch (ch)
+ {
+ case 0x00:
+ case 0x20:
+ case 0x90:
+ case 0xcc:
+ case 0xff:
+ result = 12;
+ break;
+
+ case 'A' ... 'Z':
+ case 'a' ... 'z':
+ if (letters == NULL)
+ result = 20;
+ else
+ {
+ result = 18;
+ assert(*letters > 0);
+ (*letters)--;
+ }
+ break;
+
+ default:
+ result = 20;
+ break;
+
+ }
+
+ if (--seen[ch] == 0)
+ {
+ assert(*uniq > 0);
+ (*uniq)--;
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : rating = note d'évaluation courante. *
+* uniq = volume d'octets originaux relevés. *
+* max = nombre d'octets considérés à la base. *
+* *
+* Description : Termine la notation d'un ensemble d'octets. *
+* *
+* Retour : Note positive ou négative. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int finish_quality_rating(int rating, size_t uniq, size_t max)
+{
+ int result; /* Note à retourner */
+ bool bad; /* Indice de mauvaise qualité */
+
+ if (uniq == 1)
+ {
+ bad = (rating % 12) == 0;
+
+ result = (bad ? -10 * max : 2);
+
+ }
+
+ else
+ result = uniq * 2;
+
+ result += rating;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : raw = définition de la bribe à enregistrer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* atom = informations de suivi constituées. [OUT] *
+* letters = nombre de lettres rencontrées. [OUT] *
+* *
+* Description : Détermine la portion idéale de recherche. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void find_best_atom(const sized_binary_t *raw, size_t maxsize, tracked_scan_atom_t *atom, size_t *letters)
+{
+ size_t i; /* Boucle de parcours #1 */
+ bin_t ch; /* Octets à étudier */
+ size_t best_letters; /* Mémorisation de décompte */
+ size_t *ptr_letters; /* Pointeur vers le décompte */
+ int raw_rating; /* Notation brute de séquence */
+ uint8_t seen[256]; /* Mémorisation des passages */
+ size_t uniq; /* Nombre d'octets originaux */
+ const bin_t *last; /* Dernier caractère étudié */
+ int best_rating; /* Meilleur notation obtenue */
+ size_t max_loop; /* Limitation des itérations */
+ size_t k; /* Boucle de parcours #2 */
+ size_t local_letters; /* Décompte courant des lettres*/
+ int local_rating; /* Notation courante */
+ const bin_t *first; /* Premier caractère étudié */
+
+ /* Si la chaîne fournie est plus petite que la taille d'un atome... */
+ if (raw->len <= maxsize)
+ {
+ atom->pos = 0;
+ atom->len = raw->len;
+ atom->rem = 0;
+
+ atom->fast_check = true;
+
+ if (letters != NULL)
+ {
+ *letters = 0;
+
+ for (i = 0; i < raw->len; i++)
+ {
+ ch = raw->data[i];
+
+ if (IS_CH_LETTER(ch))
+ (*letters)++;
+
+ }
+
+ }
+
+ }
+
+ /* ... ou si une sélection doit s'opérer */
+ else
+ {
+ /* Etablissement d'une mesure de référence à la position 0 */
+
+ atom->pos = 0;
+ atom->len = maxsize;
+
+ ptr_letters = (letters != NULL ? &best_letters : NULL);
+
+ best_letters = 0;
+ raw_rating = 0;
+
+ memset(seen, 0, sizeof(seen));
+ uniq = 0;
+
+ last = raw->static_bin_data;
+
+ for (k = 0; k < maxsize; k++)
+ raw_rating += rate_byte_quality(*last++, seen, &uniq, ptr_letters);
+
+ best_rating = finish_quality_rating(raw_rating, uniq, maxsize);
+
+ /* Parcours du reste du contenu */
+
+ max_loop = (raw->len - maxsize);
+
+ ptr_letters = (letters != NULL ? &local_letters : NULL);
+
+ local_letters = best_letters;
+ local_rating = best_rating;
+
+ first = raw->static_bin_data;
+
+ for (i = 0; i < max_loop; i++)
+ {
+ raw_rating += rate_byte_quality(*last++, seen, &uniq, ptr_letters);
+ raw_rating -= unrate_byte_quality(*first++, seen, &uniq, ptr_letters);
+
+ local_rating = finish_quality_rating(raw_rating , uniq, maxsize);
+
+ if (local_rating > best_rating)
+ {
+ atom->pos = i + 1;
+
+ best_letters = local_letters;
+ best_rating = local_rating;
+
+ }
+
+ }
+
+ /* Conclusion */
+
+ atom->rem = raw->len - atom->pos - maxsize;
+
+ atom->fast_check = false;
+
+ if (letters != NULL)
+ *letters = best_letters;
+
+ }
+
+ assert((atom->fast_check && atom->pos == 0 && atom->rem == 0)
+ || (!atom->fast_check && (atom->pos != 0 || atom->rem != 0)));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : src = chaîne ed référence à dupliquer. *
+* atom = préselection opérée en amont. *
+* count = nombre de lettres présentes. *
+* *
+* Description : Etablit la liste des cas de figures ignorant la casse. *
+* *
+* Retour : Liste de toutes les combinaisons possibles. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+sized_binary_t *make_atoms_case_insensitive(const sized_binary_t *src, const tracked_scan_atom_t *atom, size_t count)
+{
+ sized_binary_t *result; /* Liste à retourner */
+ size_t i; /* Boucle de parcours #1 */
+ size_t replaced; /* 2^(alternatives créées) */
+#ifndef NDEBUG
+ size_t check; /* Validation du compte max. */
+#endif
+ bin_t ch; /* Octet à recopier */
+ size_t k; /* Boucle de parcours #2 */
+ size_t divisor; /* Taille de la découpe */
+ size_t quotient; /* Reste de la position */
+
+ /* Création du réceptacle */
+
+ result = malloc(count * sizeof(tracked_scan_atom_t));
+
+ assert(src->len == (atom->pos + atom->len + atom->rem));
+
+ for (i = 0; i < count; i++)
+ {
+ result[i].data = malloc(src->len);
+ result[i].len = src->len;
+
+ memcpy(result[i].data, src->data, atom->pos);
+ memcpy(&result[i].data[atom->pos + atom->len], &src->data[atom->pos + atom->len], atom->rem);
+
+ }
+
+ /* Remplissage */
+
+ replaced = 2;
+
+#ifndef NDEBUG
+ check = 1;
+#endif
+
+ for (i = atom->pos; i < (atom->pos + atom->len); i++)
+ {
+ ch = src->data[i];
+
+ if (IS_CH_LETTER(ch))
+ {
+ for (k = 0; k < count; k++)
+ {
+ divisor = count / replaced;
+ quotient = k / divisor;
+
+ if ((quotient % 2) == 0)
+ result[k].data[i] = MAKE_CH_UPPER(ch);
+ else
+ result[k].data[i] = MAKE_CH_LOWER(ch);
+
+ }
+
+ replaced *= 2;
+
+#ifndef NDEBUG
+ check *= 2;
+ assert(check <= count);
+#endif
+
+ }
+ else
+ for (k = 0; k < count; k++)
+ result[k].data[i] = ch;
+
+ }
+
+ assert(check == count);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = octets partiels avec leur masque à interpréter. *
+* len = quantité d'octets à interpréter. *
+* produced = nombre de contenus générés. [OUT] *
+* *
+* Description : Etablit la liste des cas de figures avec des octets partiels.*
+* *
+* Retour : Liste de toutes les combinaisons possibles. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+sized_binary_t *make_atoms_from_masked_bytes(const masked_byte_t *bytes, size_t len, size_t *produced)
+{
+ sized_binary_t *result; /* Liste à retourner */
+ size_t seq_len; /* Taille de séquence retenue */
+ size_t repeat_times; /* Répétitions pour remplissage*/
+ sized_binary_t *maxiter; /* Borne de fin de parcours */
+ size_t i; /* Boucle de parcours #1 */
+ sized_binary_t *iter; /* Boucle de parcours #2 */
+ size_t j; /* Boucle de parcours #3 */
+ size_t k; /* Boucle de parcours #4 */
+
+ seq_len = (len > MASK_MAX_LEN_FOR_ATOMS ? MASK_MAX_LEN_FOR_ATOMS : len);
+
+ /**
+ * Si l'usage de la fonction pow() disparaît, la bibliothèque m
+ * peut être retirée de libchrysacore_la_LDFLAGS dans le Makefile
+ * principal.
+ */
+ repeat_times = pow(16, seq_len - 1);
+
+ *produced = 16 * repeat_times;
+
+ /* Création du réceptacle */
+
+ result = malloc(*produced * sizeof(tracked_scan_atom_t));
+
+ maxiter = result + *produced;
+
+ /* Remplissage */
+
+ for (i = 0; i < seq_len; i++)
+ {
+ for (iter = result; iter < maxiter; )
+ {
+ for (j = 0; j < 16; j++)
+ {
+ assert(bytes[i].mask == 0x0f || bytes[i].mask == 0xf0);
+
+ for (k = 0; k < repeat_times; k++)
+ {
+ if (i == 0)
+ {
+ iter->data = malloc(seq_len);
+ iter->len = seq_len;
+ }
+
+ if (bytes[i].mask == 0x0f)
+ iter->data[i] = bytes[i].value | (j << 4);
+ else
+ iter->data[i] = bytes[i].value | j;
+
+ iter++;
+
+ }
+
+ }
+
+ }
+
+ repeat_times /= 16;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : raw = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* atom = informations de suivi constituées. [OUT] *
+* *
+* Description : Amorce l'insertion de l'atome déterminé d'une série d'octets.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool enroll_prepared_atom(const sized_binary_t *raw, GEngineBackend *backend, tracked_scan_atom_t *atom)
+{
+ bool result; /* Statut à retourner */
+ const bin_t *data; /* Données à rechercher */
+
+ data = raw->static_bin_data + atom->pos;
+
+ result = g_engine_backend_enroll_plain_pattern(backend, data, atom->len, atom->tmp_id);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : atom = informations de suivi constituées. [OUT] *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool build_atom_pattern_id(tracked_scan_atom_t *atom, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+
+ atom->pid = g_engine_backend_build_plain_pattern_id(backend, atom->tmp_id);
+
+ result = (atom->pid != INVALID_PATTERN_ID);
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/tokens/atom.h b/src/analysis/scan/patterns/tokens/atom.h
new file mode 100644
index 0000000..1ef8f40
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/atom.h
@@ -0,0 +1,88 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * atom.h - prototypes pour la détermination d'atomes à partir de motifs
+ *
+ * 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_PATTERNS_TOKENS_ATOM_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_ATOM_H
+
+
+#include <stdbool.h>
+
+
+#include "../backend.h"
+#include "../../../../arch/vmpa.h"
+#include "../../../../common/szstr.h"
+
+
+
+/* Suivi des motifs réellement recherchés */
+typedef struct _tracked_scan_atom_t
+{
+ phys_t pos; /* Début de sélection atomique */
+ phys_t len; /* Taille de ladite sélection */
+ phys_t rem; /* Reste après l'atome */
+
+ bool fast_check; /* Besoin de vérifications ? */
+
+ uint32_t tmp_id[2]; /* Couple d'identifiants temp. */
+
+ patid_t pid; /* Identifiant de la bribe */
+
+} tracked_scan_atom_t;
+
+/* Note l'intêret de rechercher un octet particulier. */
+int rate_byte_quality(bin_t, uint8_t *, size_t *, size_t *);
+
+/* Annihile l'intêret de rechercher un octet particulier. */
+int unrate_byte_quality(bin_t, uint8_t *, size_t *, size_t *);
+
+/* Termine la notation d'un ensemble d'octets. */
+int finish_quality_rating(int, size_t, size_t);
+
+/* Détermine la portion idéale de recherche. */
+void find_best_atom(const sized_binary_t *, size_t , tracked_scan_atom_t *, size_t *);
+
+/* Etablit la liste des cas de figures ignorant la casse. */
+sized_binary_t *make_atoms_case_insensitive(const sized_binary_t *, const tracked_scan_atom_t *, size_t);
+
+/* Mémorisation d'un octet visé avec son masque */
+typedef struct _masked_byte_t
+{
+ bin_t value; /* Valeur de l'octet visé */
+ bin_t mask; /* Masque à appliquer */
+
+} masked_byte_t;
+
+#define MASK_MAX_LEN_FOR_ATOMS 2
+
+/* Etablit la liste des cas de figures avec des octets partiels. */
+sized_binary_t *make_atoms_from_masked_bytes(const masked_byte_t *, size_t, size_t *);
+
+/* Amorce l'insertion de l'atome déterminé d'une série d'octets. */
+bool enroll_prepared_atom(const sized_binary_t *, GEngineBackend *, tracked_scan_atom_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+bool build_atom_pattern_id(tracked_scan_atom_t *, GEngineBackend *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_ATOM_H */
diff --git a/src/analysis/scan/patterns/tokens/hex-int.h b/src/analysis/scan/patterns/tokens/hex-int.h
new file mode 100644
index 0000000..dca9848
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/hex-int.h
@@ -0,0 +1,56 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex-int.h - prototypes internes pour la recherche de morceaux de binaire
+ *
+ * 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_PATTERNS_TOKENS_HEX_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_HEX_INT_H
+
+
+#include "hex.h"
+
+
+#include "atom.h"
+#include "../token-int.h"
+
+
+
+/* Encadrement d'une recherche de morceaux de binaire (instance) */
+struct _GScanHexBytes
+{
+ GBytesToken parent; /* A laisser en premier */
+
+};
+
+/* Encadrement d'une recherche de morceaux de binaire (classe) */
+struct _GScanHexBytesClass
+{
+ GBytesTokenClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place un gestionnaire de recherche de binaire. */
+bool g_scan_hex_bytes_create(GScanHexBytes *, GScanTokenNode *, bool);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_HEX_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/hex.c b/src/analysis/scan/patterns/tokens/hex.c
new file mode 100644
index 0000000..89d7ca4
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/hex.c
@@ -0,0 +1,259 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex.c - recherche de morceaux de binaire
+ *
+ * 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 "hex.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "hex-int.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des recherches de texte brut. */
+static void g_scan_hex_bytes_class_init(GScanHexBytesClass *klass);
+
+/* Initialise une instance de recherche de texte brut. */
+static void g_scan_hex_bytes_init(GScanHexBytes *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_hex_bytes_dispose(GScanHexBytes *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_hex_bytes_finalize(GScanHexBytes *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Affiche un motif de recherche au format texte. */
+static void g_scan_hex_bytes_output_to_text(const GScanHexBytes *, GScanContext *, int);
+
+/* Affiche un motif de recherche au format JSON. */
+static void g_scan_hex_bytes_output_to_json(const GScanHexBytes *, GScanContext *, const sized_string_t *, unsigned int, int);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une suite d'octets à retrouver dans un binaire. */
+G_DEFINE_TYPE(GScanHexBytes, g_scan_hex_bytes, G_TYPE_BYTES_TOKEN);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des recherches de texte brut. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_bytes_class_init(GScanHexBytesClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GSearchPatternClass *pattern; /* Version de classe ancêtre */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_hex_bytes_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_hex_bytes_finalize;
+
+ pattern = G_SEARCH_PATTERN_CLASS(klass);
+
+ pattern->to_text = (output_pattern_to_text_fc)g_scan_hex_bytes_output_to_text;
+ pattern->to_json = (output_pattern_to_json_fc)g_scan_hex_bytes_output_to_json;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = instance à initialiser. *
+* *
+* Description : Initialise une instance de recherche de texte brut. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_bytes_init(GScanHexBytes *bytes)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_bytes_dispose(GScanHexBytes *bytes)
+{
+ G_OBJECT_CLASS(g_scan_hex_bytes_parent_class)->dispose(G_OBJECT(bytes));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_bytes_finalize(GScanHexBytes *bytes)
+{
+ G_OBJECT_CLASS(g_scan_hex_bytes_parent_class)->finalize(G_OBJECT(bytes));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : root = représentation du motif à recherche. *
+* private = donne une vocation privée au motif de recherche. *
+* *
+* Description : Construit un gestionnaire de recherche de texte brut. *
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GSearchPattern *g_scan_hex_bytes_new(GScanTokenNode *root, bool private)
+{
+ GSearchPattern *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_HEX_BYTES, NULL);
+
+ if (!g_scan_hex_bytes_create(G_SCAN_HEX_BYTES(result), root, private))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = encadrement de motif à initialiser pleinement. *
+* root = représentation du motif à recherche. *
+* private = donne une vocation privée au motif de recherche. *
+* *
+* Description : Met en place un gestionnaire de recherche de binaire. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_hex_bytes_create(GScanHexBytes *bytes, GScanTokenNode *root, bool private)
+{
+ bool result; /* Bilan à retourner */
+
+ result = g_bytes_token_create(G_BYTES_TOKEN(bytes), root, false, private);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : pattern = définition de motif à considérer. *
+* context = contexte de l'analyse à mener. *
+* fd = canal d'écriture. *
+* *
+* Description : Affiche un motif de recherche au format texte. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_bytes_output_to_text(const GScanHexBytes *pattern, GScanContext *context, int fd)
+{
+ G_SEARCH_PATTERN_CLASS(g_scan_hex_bytes_parent_class)->to_text(G_SEARCH_PATTERN(pattern), context, fd);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pattern = définition de motif à considérer. *
+* context = contexte de l'analyse à mener. *
+* padding = éventuel bourrage initial à placer ou NULL. *
+* level = profondeur actuelle. *
+* fd = canal d'écriture. *
+* *
+* Description : Affiche un motif de recherche au format JSON. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_hex_bytes_output_to_json(const GScanHexBytes *pattern, GScanContext *context, const sized_string_t *padding, unsigned int level, int fd)
+{
+ G_SEARCH_PATTERN_CLASS(g_scan_hex_bytes_parent_class)->to_json(G_SEARCH_PATTERN(pattern), context, padding, level, fd);
+
+ /* TODO */
+
+}
diff --git a/src/analysis/scan/patterns/tokens/hex.h b/src/analysis/scan/patterns/tokens/hex.h
new file mode 100644
index 0000000..fe5268c
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/hex.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex.h - prototypes pour la recherche de morceaux de binaire
+ *
+ * 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_PATTERNS_TOKENS_HEX_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_HEX_H
+
+
+#include <glib-object.h>
+
+
+#include "node.h"
+#include "../../pattern.h"
+
+
+
+#define G_TYPE_SCAN_HEX_BYTES g_scan_hex_bytes_get_type()
+#define G_SCAN_HEX_BYTES(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_HEX_BYTES, GScanHexBytes))
+#define G_IS_SCAN_HEX_BYTES(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_HEX_BYTES))
+#define G_SCAN_HEX_BYTES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_HEX_BYTES, GScanHexBytesClass))
+#define G_IS_SCAN_HEX_BYTES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_HEX_BYTES))
+#define G_SCAN_HEX_BYTES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_HEX_BYTES, GScanHexBytesClass))
+
+
+/* Encadrement d'une recherche de morceaux de binaire (instance) */
+typedef struct _GScanHexBytes GScanHexBytes;
+
+/* Encadrement d'une recherche de morceaux de binaire (classe) */
+typedef struct _GScanHexBytesClass GScanHexBytesClass;
+
+
+/* Indique le type défini pour une suite d'octets à retrouver dans un binaire. */
+GType g_scan_hex_bytes_get_type(void);
+
+/* Construit un gestionnaire de recherche de texte brut. */
+GSearchPattern *g_scan_hex_bytes_new(GScanTokenNode *, bool);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_HEX_H */
diff --git a/src/analysis/scan/patterns/tokens/node-int.h b/src/analysis/scan/patterns/tokens/node-int.h
new file mode 100644
index 0000000..520e2a4
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/node-int.h
@@ -0,0 +1,108 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * node-int.h - prototypes internes pour la décomposition d'un motif de recherche en atomes assemblés
+ *
+ * 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_PATTERNS_TOKENS_NODE_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODE_INT_H
+
+
+#include "node.h"
+
+
+
+/* Communique l'intérêt d'un noeud au sein d'une analyse. */
+typedef float (* compute_scan_token_node_weight_fc) (const GScanTokenNode *);
+
+/* Prend acte d'une nouvelle propriété pour le noeud. */
+typedef void (* apply_scan_token_node_flags_fc) (GScanTokenNode *, ScanTokenNodeFlags);
+
+/* Noeuds clefs de l'arborescence mise en place */
+typedef struct _scan_tree_points_t
+{
+ GScanTokenNode *first_plain; /* Premier noeud textuel */
+ GScanTokenNode *best_masked; /* Noeud masqué le plus long */
+
+} scan_tree_points_t;
+
+/* Parcourt une arborescence de noeuds et y relève des éléments. */
+typedef void (* visit_scan_token_node_fc) (GScanTokenNode *, scan_tree_points_t *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+typedef bool (* enroll_scan_token_node_fc) (GScanTokenNode *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+typedef bool (* build_scan_token_node_id_fc) (GScanTokenNode *, GEngineBackend *);
+
+typedef enum _TokenNodeCheckFlags
+{
+ TNCF_UPDATE_IN_PLACE = (1 << 0), /* Actualisation de l'entrée */
+ TNCF_CREATE_NEW = (1 << 1), /* Allocation de positions */
+ TNCF_KEEP_DISCARDED = (1 << 2), /* Inversion des résultats */
+
+} TokenNodeCheckFlags;
+
+/* Transforme les correspondances locales en trouvailles. */
+typedef void (* check_scan_token_node_fc) (const GScanTokenNode *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+/* Décomposition d'un motif de recherche en atomes (instance) */
+struct _GScanTokenNode
+{
+ GObject parent; /* A laisser en premier */
+
+ ScanTokenNodeFlags flags; /* Propriétés particulières */
+
+};
+
+/* Décomposition d'un motif de recherche en atomes (classe) */
+struct _GScanTokenNodeClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+ compute_scan_token_node_weight_fc compute_weight; /* Evaluation */
+ visit_scan_token_node_fc visit; /* Phase de répérage initial */
+ apply_scan_token_node_flags_fc apply; /* Prise en compte de fanions */
+
+ enroll_scan_token_node_fc enroll; /* Inscription d'un motif */
+ build_scan_token_node_id_fc build_id; /* Récupération d'identifiant */
+
+ check_scan_token_node_fc check_forward; /* Conversion en trouvailles */
+ check_scan_token_node_fc check_backward;/* Conversion en trouvailles */
+
+};
+
+
+/* Parcourt une arborescence de noeuds et y relève des éléments. */
+void g_scan_token_node_visit(GScanTokenNode *, scan_tree_points_t *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+bool _g_scan_token_node_enroll(GScanTokenNode *, GEngineBackend *, size_t, size_t *);
+
+/* Transforme les correspondances locales en trouvailles. */
+void _g_scan_token_node_check_forward(const GScanTokenNode *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+/* Transforme les correspondances locales en trouvailles. */
+void _g_scan_token_node_check_backward(const GScanTokenNode *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODE_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/node.c b/src/analysis/scan/patterns/tokens/node.c
new file mode 100644
index 0000000..767cc6d
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/node.c
@@ -0,0 +1,675 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * node.c - décomposition d'un motif de recherche en atomes assemblés
+ *
+ * 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 "node.h"
+
+
+#include <assert.h>
+
+
+#include "node-int.h"
+#include "nodes/any.h"
+
+
+
+/* ------------------------ DECOMPOSITION DE MOTIF RECHERCHE ------------------------ */
+
+
+/* Initialise la classe des éléments de décomposition. */
+static void g_scan_token_node_class_init(GScanTokenNodeClass *);
+
+/* Initialise une instance d'élément décomposant un motif. */
+static void g_scan_token_node_init(GScanTokenNode *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_node_dispose(GScanTokenNode *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_node_finalize(GScanTokenNode *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DECOMPOSITION DE MOTIF RECHERCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour un élément décomposant un motif d'octets à rechercher. */
+G_DEFINE_TYPE(GScanTokenNode, g_scan_token_node, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des éléments de décomposition. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_class_init(GScanTokenNodeClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_node_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_node_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance à initialiser. *
+* *
+* Description : Initialise une instance d'élément décomposant un motif. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_init(GScanTokenNode *node)
+{
+ node->flags = STNF_NONE;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_dispose(GScanTokenNode *node)
+{
+ G_OBJECT_CLASS(g_scan_token_node_parent_class)->dispose(G_OBJECT(node));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_finalize(GScanTokenNode *node)
+{
+ G_OBJECT_CLASS(g_scan_token_node_parent_class)->finalize(G_OBJECT(node));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à consulter. *
+* *
+* Description : Communique l'intérêt d'un noeud au sein d'une analyse. *
+* *
+* Retour : Poids de l'importance pour un départ de scan. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+float g_scan_token_node_compute_weight_for_scan(const GScanTokenNode *node)
+{
+ float result; /* Valeur à retourner */
+ GScanTokenNodeClass *class; /* Classe de l'instance */
+
+ class = G_SCAN_TOKEN_NODE_GET_CLASS(node);
+
+ if (class->compute_weight != NULL)
+ result = class->compute_weight(node);
+ else
+ result = 0;
+
+ return result;
+
+}
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à consulter. *
+* *
+* Description : Indique les propriétés particulières d'un noeud d'analyse. *
+* *
+* Retour : Propriétés particulières associées au noeud. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+ScanTokenNodeFlags g_scan_token_node_get_flags(const GScanTokenNode *node)
+{
+ ScanTokenNodeFlags result; /* Statut à retourner */
+
+ result = node->flags;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à mettre à jour. *
+* flags = propriétés particulières à associer au noeud. *
+* *
+* Description : Marque le noeud avec des propriétés particulières. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_set_flags(GScanTokenNode *node, ScanTokenNodeFlags flags)
+{
+ GScanTokenNodeClass *class; /* Classe de l'instance */
+
+ node->flags |= flags;
+
+ class = G_SCAN_TOKEN_NODE_GET_CLASS(node);
+
+ if (class->apply != NULL)
+ class->apply(node, flags);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = point de départ du parcours à effectuer. *
+* points = points capitaux de l'arborescence. [OUT] *
+* *
+* Description : Parcourt une arborescence de noeuds et y relève des éléments.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_visit(GScanTokenNode *node, scan_tree_points_t *points)
+{
+ GScanTokenNodeClass *class; /* Classe de l'instance */
+
+ class = G_SCAN_TOKEN_NODE_GET_CLASS(node);
+
+ if (class->visit != NULL)
+ class->visit(node, points);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = point de départ du parcours à préparer. *
+* *
+* Description : Détermine et prépare les éléments clefs d'une arborescence. *
+* *
+* Retour : true si une analyse à rebourd complémentaire est requise. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_setup_tree(GScanTokenNode *node)
+{
+ bool result; /* Prévision à retourner */
+ scan_tree_points_t points; /* Repérage de points capitaux */
+ GScanTokenNode *main; /* Principal noeud d'opération */
+
+ /* Phase de localisation */
+
+ points.first_plain = NULL;
+ points.best_masked = NULL;
+
+ g_scan_token_node_visit(node, &points);
+
+ /* Phase d'application */
+
+ g_scan_token_node_set_flags(node, STNF_FIRST);
+ g_scan_token_node_set_flags(node, STNF_LAST);
+
+ if (points.first_plain != NULL)
+ main = points.first_plain;
+
+ else if (points.best_masked != NULL)
+ main = points.best_masked;
+
+ else
+ main = node;
+
+ g_scan_token_node_set_flags(main, STNF_MAIN);
+
+ result = (main != node);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool _g_scan_token_node_enroll(GScanTokenNode *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+ GScanTokenNodeClass *class; /* Classe de l'instance */
+
+ class = G_SCAN_TOKEN_NODE_GET_CLASS(node);
+
+ result = class->enroll(node, backend, maxsize, slow);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_enroll(GScanTokenNode *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+
+ assert(g_engine_backend_get_atom_max_size(backend) == maxsize);
+
+ *slow = 0;
+
+ result = _g_scan_token_node_enroll(node, backend, maxsize, slow);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_build_id(GScanTokenNode *node, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+ GScanTokenNodeClass *class; /* Classe de l'instance */
+
+ class = G_SCAN_TOKEN_NODE_GET_CLASS(node);
+
+ if (class->build_id == NULL)
+ result = true;
+ else
+ result = class->build_id(node, backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void _g_scan_token_node_check_forward(const GScanTokenNode *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ GScanTokenNodeClass *class; /* Classe de l'instance */
+
+ if (node->flags & STNF_MAIN)
+ {
+ //assert(*skip); //REMME
+ *skip = false;
+ }
+
+ class = G_SCAN_TOKEN_NODE_GET_CLASS(node);
+
+ class->check_forward(node, params, cflags, skip);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_check_forward(const GScanTokenNode *node, scan_node_check_params_t *params)
+{
+ node_search_offset_t offset; /* Espace des correspondances */
+ bool skip; /* Mise en attente des analyses*/
+ size_t ocount; /* Quantité de bornes présentes*/
+ node_offset_range_t * const *ranges_ptr;/* Bornes d'espace à parcourir */
+ size_t pcount; /* Nombre de correspondances */
+ match_area_t * const *pending_ptr; /* Correspondances actuelles */
+ size_t p; /* Boucle de parcours #2 */
+ match_area_t *pending; /* Correspondance à traiter */
+ phys_t old_end; /* Ancien point d'arrivée */
+ size_t o; /* Boucle de parcours #1 */
+ const node_offset_range_t *range; /* Bornes d'espace à parcourir */
+ phys_t new_end; /* Nouveau point d'arrivée */
+
+ init_node_search_offset(&params->offset);
+
+ skip = true;
+
+ _g_scan_token_node_check_forward(node, params, TNCF_UPDATE_IN_PLACE, &skip);
+
+
+#if 0 // FIXME
+
+ /**
+ * Si un décalage entre octets n'a pas été consommé,
+ * les résultats sont étendus à minima.
+ */
+
+ ranges_ptr = get_node_search_offset_ranges(&offset, &ocount);
+
+ if (ocount > 0)
+ {
+ /**
+ * Dans le cas où un unique noeud ne renvoie que vers un espace (par
+ * exemple : "$a = { [0] }"), il n'y a pas de résultats, donc pas
+ * d'initialisation.
+ *
+ * La réinitialisation des décomptes va tiquer pour cet état. La
+ * phase d'extension des résultats inexistants est ainsi sautée.
+ */
+ if (count_pending_matches(matches) == 0)
+ {
+
+
+ for (o = 0; o < ocount; o++)
+ {
+ range = (*ranges_ptr) + o;
+
+
+ printf("range: %u - %u\n",
+ (unsigned int)range->min,
+ (unsigned int)range->max);
+
+
+ /*
+ new_end = old_end + range->min;
+
+ if (new_end > matches->content_end)
+ new_end = matches->content_end;
+
+ add_pending_match(pending_matches_t *, phys_t, phys_t);
+
+ extend_pending_match_ending(matches, p, new_end);
+ */
+
+ }
+
+
+
+
+
+
+ goto offset_done;
+
+ }
+
+ reset_pending_matches_ttl(matches);
+
+ pending_ptr = get_all_pending_matches(matches, &pcount);
+
+ for (p = 0; p < pcount; p++)
+ {
+ pending = (*pending_ptr) + p;
+
+ old_end = pending->end;
+
+ for (o = 0; o < ocount; o++)
+ {
+ range = (*ranges_ptr) + o;
+
+ new_end = old_end + range->min;
+
+ if (new_end > matches->content_end)
+ new_end = matches->content_end;
+
+ extend_pending_match_ending(matches, p, new_end);
+
+ }
+
+ }
+
+ /**
+ * Pas besoin de purge ici puisque tous les résultats ont été traités
+ * au moins une fois, sans condition.
+ */
+ /* purge_pending_matches(matches); */
+
+ offset_done:
+
+ disable_all_ranges_in_node_search_offset(&offset);
+
+ }
+
+ assert(offset.used == 0);
+
+#endif
+
+ exit_node_search_offset(&params->offset);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void _g_scan_token_node_check_backward(const GScanTokenNode *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ GScanTokenNodeClass *class; /* Classe de l'instance */
+
+ class = G_SCAN_TOKEN_NODE_GET_CLASS(node);
+
+ class->check_backward(node, params, cflags, skip);
+
+ if (node->flags & STNF_MAIN)
+ {
+ //assert(*skip); //REMME
+ *skip = false;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_check_backward(const GScanTokenNode *node, scan_node_check_params_t *params)
+{
+ node_search_offset_t offset; /* Espace des correspondances */
+ bool skip; /* Mise en attente des analyses*/
+ size_t ocount; /* Quantité de bornes présentes*/
+ node_offset_range_t * const *ranges_ptr;/* Bornes d'espace à parcourir */
+ size_t pcount; /* Nombre de correspondances */
+ match_area_t * const *pending_ptr; /* Correspondances actuelles */
+ size_t p; /* Boucle de parcours #2 */
+ match_area_t *pending; /* Correspondance à traiter */
+ phys_t old_start; /* Ancien point d'arrivée */
+ size_t o; /* Boucle de parcours #1 */
+ const node_offset_range_t *range; /* Bornes d'espace à parcourir */
+ phys_t new_start; /* Nouveau point d'arrivée */
+
+ init_node_search_offset(&params->offset);
+
+ skip = true;
+
+ _g_scan_token_node_check_backward(node, params, TNCF_UPDATE_IN_PLACE, &skip);
+
+#if 0 // FIXME
+
+ /**
+ * Si un décalage entre octets n'a pas été consommé,
+ * les résultats sont étendus à minima.
+ */
+
+ ranges_ptr = get_node_search_offset_ranges(&offset, &ocount);
+
+ if (ocount > 0)
+ {
+ reset_pending_matches_ttl(matches);
+
+ pending_ptr = get_all_pending_matches(matches, &pcount);
+
+ for (p = 0; p < pcount; p++)
+ {
+ pending = (*pending_ptr) + p;
+
+ old_start = pending->start;
+
+ for (o = 0; o < ocount; o++)
+ {
+ range = (*ranges_ptr) + o;
+
+ if (old_start < range->min)
+ new_start = 0;
+ else
+ new_start = old_start - range->min;
+
+ if (new_start < matches->content_start)
+ new_start = matches->content_start;
+
+ extend_pending_match_beginning(matches, p, new_start);
+
+ }
+
+ }
+
+ /**
+ * Pas besoin de purge ici puisque tous les résultats ont été traités
+ * au moins une fois, sans condition.
+ */
+ /* purge_pending_matches(matches); */
+
+ disable_all_ranges_in_node_search_offset(&offset);
+
+ }
+
+ assert(offset.used == 0);
+
+#endif
+
+ exit_node_search_offset(&params->offset);
+
+}
diff --git a/src/analysis/scan/patterns/tokens/node.h b/src/analysis/scan/patterns/tokens/node.h
new file mode 100644
index 0000000..5b1a247
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/node.h
@@ -0,0 +1,127 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * node.h - prototypes pour la décomposition d'un motif de recherche en atomes assemblés
+ *
+ * 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_PATTERNS_TOKENS_NODE_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODE_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "offset.h"
+#include "../backend.h"
+#include "../../context.h"
+#include "../../matches/bytes.h"
+#include "../../../../glibext/umemslice.h"
+
+
+#define G_TYPE_SCAN_TOKEN_NODE g_scan_token_node_get_type()
+#define G_SCAN_TOKEN_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_NODE, GScanTokenNode))
+#define G_IS_SCAN_TOKEN_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_NODE))
+#define G_SCAN_TOKEN_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_NODE, GScanTokenNodeClass))
+#define G_IS_SCAN_TOKEN_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_NODE))
+#define G_SCAN_TOKEN_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_NODE, GScanTokenNodeClass))
+
+
+/* Décomposition d'un motif de recherche en atomes (instance) */
+typedef struct _GScanTokenNode GScanTokenNode;
+
+/* Décomposition d'un motif de recherche en atomes (classe) */
+typedef struct _GScanTokenNodeClass GScanTokenNodeClass;
+
+
+/* Propriétés particulières pour noeud d'analyse */
+typedef enum _ScanTokenNodeFlags
+{
+ STNF_NONE = (0 << 0), /* Absence de singularité */
+ STNF_FIRST = (1 << 0), /* Premier noeud de traitement */
+ STNF_LAST = (1 << 1), /* Dernier noeud de traitement */
+ STNF_MAIN = (1 << 2), /* Point de départ d'analyse */
+
+} ScanTokenNodeFlags;
+
+
+/* Indique le type défini pour un élément décomposant un motif d'octets à rechercher. */
+GType g_scan_token_node_get_type(void);
+
+/* Communique l'intérêt d'un noeud au sein d'une analyse. */
+float g_scan_token_node_compute_weight_for_scan(const GScanTokenNode *);
+
+
+
+/* Indique les propriétés particulières d'un noeud d'analyse. */
+ScanTokenNodeFlags g_scan_token_node_get_flags(const GScanTokenNode *);
+
+/* Marque le noeud avec des propriétés particulières. */
+void g_scan_token_node_set_flags(GScanTokenNode *, ScanTokenNodeFlags);
+
+/* Détermine et prépare les éléments clefs d'une arborescence. */
+bool g_scan_token_node_setup_tree(GScanTokenNode *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+bool g_scan_token_node_enroll(GScanTokenNode *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+bool g_scan_token_node_build_id(GScanTokenNode *, GEngineBackend *);
+
+/* Accès direct aux éléments utiles aux contrôles */
+typedef struct _scan_node_check_params_t
+{
+ GScanContext *context; /* Contexte de scan en cours */
+ GBinContent *content; /* Contenu binaire associé */
+ GUMemSlice *allocator; /* Allocateur pour zones */
+
+ phys_t content_start; /* Point de début du contenu */
+ phys_t content_end; /* Point de fin du contenu */
+
+ node_search_offset_t offset; /* Décalages à respecter */
+
+ bool initialized; /* Etat du suivi */
+
+ /* TNCF_UPDATE_IN_PLACE */
+
+ match_area_t *main_areas; /* Zones principales à analyser*/
+ size_t main_count; /* Taille de cette liste */
+
+ /* TNCF_CREATE_NEW */
+
+ match_area_t *created_areas; /* Zones principales à analyser*/
+ size_t created_count; /* Taille de cette liste */
+
+ /* TNCF_KEEP_DISCARDED */
+
+ match_area_t *kept_areas; /* Zones principales à analyser*/
+ size_t kept_count; /* Taille de cette liste */
+
+} scan_node_check_params_t;
+
+/* Transforme les correspondances locales en trouvailles. */
+void g_scan_token_node_check_forward(const GScanTokenNode *, scan_node_check_params_t *);
+
+/* Transforme les correspondances locales en trouvailles. */
+void g_scan_token_node_check_backward(const GScanTokenNode *, scan_node_check_params_t *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODE_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/Makefile.am b/src/analysis/scan/patterns/tokens/nodes/Makefile.am
new file mode 100644
index 0000000..b5da1ee
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/Makefile.am
@@ -0,0 +1,24 @@
+
+noinst_LTLIBRARIES = libanalysisscanpatternstokensnodes.la
+
+
+libanalysisscanpatternstokensnodes_la_SOURCES = \
+ any-int.h \
+ any.h any.c \
+ choice-int.h \
+ choice.h choice.c \
+ masked-int.h \
+ masked.h masked.c \
+ not-int.h \
+ not.h not.c \
+ plain-int.h \
+ plain.h plain.c \
+ sequence-int.h \
+ sequence.h sequence.c
+
+libanalysisscanpatternstokensnodes_la_CFLAGS = $(LIBGOBJ_CFLAGS)
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
+
+dev_HEADERS = $(libanalysisscanpatternstokensnodes_la_SOURCES:%c=)
diff --git a/src/analysis/scan/patterns/tokens/nodes/any-int.h b/src/analysis/scan/patterns/tokens/nodes/any-int.h
new file mode 100644
index 0000000..dd2e2e7
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/any-int.h
@@ -0,0 +1,60 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * any-int.h - prototypes internes pour une suite d'octets quelconques
+ *
+ * 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_PATTERNS_TOKENS_NODES_ANY_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_ANY_INT_H
+
+
+#include "any.h"
+
+
+#include "../atom.h"
+#include "../node-int.h"
+
+
+
+/* Espace constitué d'un ou plusieurs octets quelconques (instance) */
+struct _GScanTokenNodeAny
+{
+ GScanTokenNode parent; /* A laisser en premier */
+
+ phys_t min; /* Quantité minimale */
+ phys_t max; /* Quantité maximale */
+ bool has_max; /* Quantité définie ? */
+
+};
+
+/* Espace constitué d'un ou plusieurs octets quelconques (classe) */
+struct _GScanTokenNodeAnyClass
+{
+ GScanTokenNodeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place un noeud pointant une série d'octets. */
+bool g_scan_token_node_any_create(GScanTokenNodeAny *, const phys_t *, const phys_t *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_ANY_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/any.c b/src/analysis/scan/patterns/tokens/nodes/any.c
new file mode 100644
index 0000000..4334fff
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/any.c
@@ -0,0 +1,765 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * any.c - suite d'octets quelconques
+ *
+ * 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 "any.h"
+
+
+#include <assert.h>
+
+
+#include "any-int.h"
+
+
+
+/* ------------------------ DECOMPOSITION DE MOTIF RECHERCHE ------------------------ */
+
+
+/* Initialise la classe des séries d'octets quelconques. */
+static void g_scan_token_node_any_class_init(GScanTokenNodeAnyClass *);
+
+/* Initialise une instance de série d'octets quelconques. */
+static void g_scan_token_node_any_init(GScanTokenNodeAny *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_node_any_dispose(GScanTokenNodeAny *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_node_any_finalize(GScanTokenNodeAny *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+static bool g_scan_token_node_any_enroll(GScanTokenNodeAny *, GEngineBackend *, size_t, size_t *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_any_check_forward(const GScanTokenNodeAny *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_any_check_backward(const GScanTokenNodeAny *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DECOMPOSITION DE MOTIF RECHERCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une série d'octets quelconque, vide ou non. */
+G_DEFINE_TYPE(GScanTokenNodeAny, g_scan_token_node_any, G_TYPE_SCAN_TOKEN_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des séries d'octets quelconques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_any_class_init(GScanTokenNodeAnyClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenNodeClass *node; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_node_any_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_node_any_finalize;
+
+ node = G_SCAN_TOKEN_NODE_CLASS(klass);
+
+ node->apply = (apply_scan_token_node_flags_fc)NULL;
+ node->visit = (visit_scan_token_node_fc)NULL;
+ node->enroll = (enroll_scan_token_node_fc)g_scan_token_node_any_enroll;
+ node->check_forward = (check_scan_token_node_fc)g_scan_token_node_any_check_forward;
+ node->check_backward = (check_scan_token_node_fc)g_scan_token_node_any_check_backward;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : any = instance à initialiser. *
+* *
+* Description : Initialise une instance de série d'octets quelconques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_any_init(GScanTokenNodeAny *any)
+{
+ any->min = 0;
+ any->has_max = false;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : any = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_any_dispose(GScanTokenNodeAny *any)
+{
+ G_OBJECT_CLASS(g_scan_token_node_any_parent_class)->dispose(G_OBJECT(any));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : any = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_any_finalize(GScanTokenNodeAny *any)
+{
+ G_OBJECT_CLASS(g_scan_token_node_any_parent_class)->finalize(G_OBJECT(any));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : min = éventuelle quantité minimale à retrouver. *
+* max = éventuelle quantité maximale à retrouver. *
+* *
+* Description : Construit un noeud pointant une série d'octets quelconques. *
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenNode *g_scan_token_node_any_new(const phys_t *min, const phys_t *max)
+{
+ GScanTokenNode *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_TOKEN_NODE_ANY, NULL);
+
+ if (!g_scan_token_node_any_create(G_SCAN_TOKEN_NODE_ANY(result), min, max))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : any = séquence d'octets quelconques à initialiser pleinement.*
+* min = éventuelle quantité minimale à retrouver. *
+* max = éventuelle quantité maximale à retrouver. *
+* *
+* Description : Met en place un noeud pointant une série d'octets. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_any_create(GScanTokenNodeAny *any, const phys_t *min, const phys_t *max)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ if (min != NULL)
+ any->min = *min;
+ else
+ any->min = 0;
+
+ if (max != NULL)
+ {
+ any->max = *max;
+
+ result = (any->min <= any->max);
+
+ if (result && any->min == any->max)
+ result = (any->min > 0);
+
+ }
+
+ any->has_max = (max != NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : any = séquence d'octets quelconques à étendre. *
+* extra = étendue supplémentaire à intégrer. *
+* *
+* Description : Etend un noeud pointant une série d'octets. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_any_merge(GScanTokenNodeAny *any, GScanTokenNodeAny *extra)
+{
+ any->min += extra->min;
+
+ if (any->has_max && extra->has_max)
+ any->max += extra->max;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_any_enroll(GScanTokenNodeAny *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+ bool forced; /* Inclusion dans un scan ? */
+
+ result = true;
+
+ forced = (g_scan_token_node_get_flags(G_SCAN_TOKEN_NODE(node)) & STNF_MAIN);
+
+ if (forced)
+ *slow += (maxsize * 4);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_any_check_forward(const GScanTokenNodeAny *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ ScanTokenNodeFlags flags; /* Particularités du noeud */
+ bool forced; /* Inclusion dans un scan ? */
+ phys_t size; /* Quantité d'octets considérés*/
+ phys_t match_size; /* Taille de correspondance */
+ phys_t i; /* Boucle de parcours #1 */
+ match_area_t *space; /* Nouvelle zone à intégrer */
+ match_area_t *area; /* Correspondance à valider */
+ match_area_t *next; /* Correspondance suivante */
+ phys_t after; /* Espace disposible après */
+ phys_t min_end; /* Fin la plus proche possible */
+ phys_t max_end; /* Fin la plus éloignée trouvée*/
+ bool updated; /* Existence de correspondance */
+ size_t rcount; /* Quantité de bornes présentes*/
+ const node_offset_range_t *ranges; /* Bornes d'espace à parcourir */
+ size_t r; /* Boucle de parcours #2 */
+ phys_t updated_edge; /* Nouvelle bordure de motif */
+ match_area_t *new_area; /* Copie de correspondance */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ flags = g_scan_token_node_get_flags(G_SCAN_TOKEN_NODE(node));
+
+ forced = (flags & STNF_MAIN);
+
+ assert((!params->initialized && forced) || (params->initialized & !forced));
+
+ /**
+ * La situation forcée correspond au cas particulier d'une définition
+ * complètement abstraite : ??, ?? ??, etc.
+ */
+ if (forced)
+ {
+ size = params->content_end - params->content_start;
+
+ if (node->has_max && 0 /* greedy ? */)
+ {
+ match_size = node->max;
+
+ if (match_size > size)
+ match_size = node->min;
+
+ }
+ else
+ match_size = node->min;
+
+ /**
+ * Si le contenu binaire est trop petit pour contenir au moins un enregistrement,
+ * aucune correspondance n'est enregistrée. Comme le noeud est le principale, ie.
+ * seul et unique, l'analyse s'arrête ensuite d'elle même.
+ *
+ * Si le contenu binaire est suffisamment large, des espaces sont créés et l'analyse
+ * se termine ensuite. La conservation des espaces n'est donc pas utile, ni réalisée.
+ */
+
+ if (match_size <= size)
+ {
+ size -= (match_size - 1);
+
+ assert(cflags & TNCF_UPDATE_IN_PLACE);
+
+ for (i = 0; i < size; i++)
+ {
+ space = g_umem_slice_alloc(params->allocator);
+
+ space->start = params->content_start + i;
+ space->end = space->start + match_size;
+
+ add_tail_match_area(space, &params->main_areas);
+
+ }
+
+ params->main_count += size;
+
+ }
+
+ }
+
+ /**
+ * Situation usuelle : des espaces séparent deux noeuds.
+ */
+ else
+ {
+ assert(params->initialized);
+
+ /**
+ * Les espaces existants sont à compléter. La présence de tels espaces
+ * restant à traiter peut provenir d'un aiguillage imposé par un motif
+ * tel que :
+ *
+ * ( aa ?? ?? | bb cc dd ) [0-5] ee ee
+ *
+ * Deux espaces sont à considérer avant de rechercher des octets ee :
+ * [2-7] et [0-5].
+ *
+ * Note : ces espaces peuvent être disjoints.
+ *
+ * Si aucun espace n'est en place, un est créé.
+ */
+
+ extend_node_search_offset(&params->offset, node->min, node->max, node->has_max);
+
+ /**
+ * Si un décalage enregistré ne peut être consommé par un noeud, les
+ * résultats sont étendus ici à minima ou maxima.
+ */
+
+ if (flags & STNF_LAST)
+ {
+ assert(offsets_exist(&params->offset));
+
+ if (0x0) printf(" LIST : %p (sz = %zu)\n", params->main_areas, params->main_count);
+
+ for_each_match_area_safe(area, &params->main_areas, next)
+ {
+ assert(area->end <= params->content_end);
+
+ after = params->content_end - area->end;
+
+ if (0x0) printf("---------- iter @ %u -> %u\n", (unsigned int)area->start, (unsigned int)area->end);
+
+ min_end = params->content_end;
+ max_end = params->content_start;
+
+ updated = false;
+
+ ranges = get_node_search_offset_ranges_2(&params->offset, &rcount);
+
+ for (r = 0; r < rcount; r++)
+ {
+ if (ranges[r].min > after)
+ continue;
+
+ updated_edge = area->end + ranges[r].min;
+
+ if (updated_edge < min_end)
+ min_end = updated_edge;
+
+ if (ranges[r].has_max)
+ {
+ if (ranges[r].max > after)
+ updated_edge = params->content_end;
+ else
+ updated_edge = area->end + ranges[r].max;
+
+ if (updated_edge > max_end)
+ max_end = updated_edge;
+
+ }
+
+ updated = true;
+
+ }
+
+ if (updated)
+ {
+ /**
+ * Si seuls les rejets sont d'intérêt, les correspondances établies
+ * ne se voient pas mises à jours ni retirées.
+ */
+
+ if ((cflags & TNCF_KEEP_DISCARDED) == 0)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ area->end = (1 /* greedy */ ? min_end : max_end);
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->end = (1 /* greedy */ ? min_end : max_end);
+
+ add_tail_match_area(new_area, &params->created_areas);
+ params->created_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ else
+ {
+ /**
+ * Si la liste principale doit être mise à jour...
+ */
+
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ del_match_area(area, &params->main_areas);
+ assert(params->main_count > 0);
+ params->main_count--;
+ }
+
+ /**
+ * Au cas où le rejet est d'intérêt, l'absence de correspondance
+ * est conservée dans une liste dédiée.
+ */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ add_tail_match_area(area, &params->kept_areas);
+ params->kept_count++;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->end = (1 /* greedy */ ? min_end : max_end);
+
+ add_tail_match_area(new_area, &params->kept_areas);
+ params->kept_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ }
+
+ disable_all_ranges_in_node_search_offset(&params->offset);
+
+ }
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_any_check_backward(const GScanTokenNodeAny *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ ScanTokenNodeFlags flags; /* Particularités du noeud */
+#ifndef NDEBUG
+ bool forced; /* Inclusion dans un scan ? */
+#endif
+ match_area_t *area; /* Correspondance à valider */
+ match_area_t *next; /* Correspondance suivante */
+ phys_t before; /* Espace disposible avant */
+ phys_t min_start; /* Début le plus proche trouvé */
+ phys_t max_start; /* Début le plus distant trouvé*/
+ bool updated; /* Existence de correspondance */
+ size_t rcount; /* Quantité de bornes présentes*/
+ const node_offset_range_t *ranges; /* Bornes d'espace à parcourir */
+ size_t r; /* Boucle de parcours */
+ phys_t updated_edge; /* Nouvelle bordure de motif */
+ match_area_t *new_area; /* Copie de correspondance */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ /**
+ * En lecture à rebourd, au moins un noeud a été solicité pour analyse (lors
+ * du sens de lecture normal). Donc l'initialisation a déjà dû avoir lieu.
+ */
+
+ assert(params->initialized);
+
+ flags = g_scan_token_node_get_flags(G_SCAN_TOKEN_NODE(node));
+
+ /**
+ * Si les recherches associées au noeud ont été forcées, alors les traitements
+ * liés ont déjà été effectués, et l'appel de cette fonction aurait dû être sauté.
+ */
+#ifndef NDEBUG
+ forced = (flags & STNF_MAIN);
+ assert(!forced);
+#endif
+
+ /**
+ * Les considérations pour l'extension des espaces en place sont identiques
+ * à celles formulées dans la fonction g_scan_token_node_any_check_forward().
+ */
+
+ extend_node_search_offset(&params->offset, node->min, node->max, node->has_max);
+
+ /**
+ * Si un décalage enregistré ne peut être consommé par un noeud, les
+ * résultats sont étendus ici à minima ou maxima.
+ */
+
+ if (flags & STNF_FIRST)
+ {
+ assert(offsets_exist(&params->offset));
+
+ if (0x0) printf(" LIST : %p (sz = %zu)\n", params->main_areas, params->main_count);
+
+ for_each_match_area_safe(area, &params->main_areas, next)
+ {
+ assert(params->content_start <= area->start);
+
+ before = area->start - params->content_start;
+
+ if (0x0) printf("---------- iter @ %u -> %u\n", (unsigned int)area->start, (unsigned int)area->end);
+
+ min_start = params->content_start;
+ max_start = params->content_end;
+
+ updated = false;
+
+ ranges = get_node_search_offset_ranges_2(&params->offset, &rcount);
+
+ for (r = 0; r < rcount; r++)
+ {
+ if (ranges[r].min > before)
+ continue;
+
+ updated_edge = area->start - ranges[r].min;
+
+ if (updated_edge > min_start)
+ min_start = updated_edge;
+
+ if (ranges[r].has_max)
+ {
+ if (ranges[r].max > before)
+ updated_edge = params->content_start;
+ else
+ updated_edge = area->start - ranges[r].max;
+
+ if (updated_edge < max_start)
+ max_start = updated_edge;
+
+ }
+
+ updated = true;
+
+ }
+
+ if (updated)
+ {
+ /**
+ * Si seuls les rejets sont d'intérêt, les correspondances établies
+ * ne se voient pas mises à jours ni retirées.
+ */
+
+ if ((cflags & TNCF_KEEP_DISCARDED) == 0)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ area->start = (1 /* greedy */ ? min_start : max_start);
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->start = (1 /* greedy */ ? min_start : max_start);
+
+ add_tail_match_area(new_area, &params->created_areas);
+ params->created_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ else
+ {
+ /**
+ * Si la liste principale doit être mise à jour...
+ */
+
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ del_match_area(area, &params->main_areas);
+ assert(params->main_count > 0);
+ params->main_count--;
+ }
+
+ /**
+ * Au cas où le rejet est d'intérêt, l'absence de correspondance
+ * est conservée dans une liste dédiée.
+ */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ add_tail_match_area(area, &params->kept_areas);
+ params->kept_count++;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->start = (1 /* greedy */ ? min_start : max_start);
+
+ add_tail_match_area(new_area, &params->kept_areas);
+ params->kept_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ }
+
+ disable_all_ranges_in_node_search_offset(&params->offset);
+
+ }
+
+}
diff --git a/src/analysis/scan/patterns/tokens/nodes/any.h b/src/analysis/scan/patterns/tokens/nodes/any.h
new file mode 100644
index 0000000..9b2233f
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/any.h
@@ -0,0 +1,61 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * any.h - prototypes pour une suite d'octets quelconques
+ *
+ * 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_PATTERNS_TOKENS_NODES_ANY_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_ANY_H
+
+
+#include <glib-object.h>
+
+
+#include "../node.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_NODE_ANY g_scan_token_node_any_get_type()
+#define G_SCAN_TOKEN_NODE_ANY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_NODE_ANY, GScanTokenNodeAny))
+#define G_IS_SCAN_TOKEN_NODE_ANY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_NODE_ANY))
+#define G_SCAN_TOKEN_NODE_ANY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_NODE_ANY, GScanTokenNodeAnyClass))
+#define G_IS_SCAN_TOKEN_NODE_ANY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_NODE_ANY))
+#define G_SCAN_TOKEN_NODE_ANY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_NODE_ANY, GScanTokenNodeAnyClass))
+
+
+/* Espace constitué d'un ou plusieurs octets quelconques (instance) */
+typedef struct _GScanTokenNodeAny GScanTokenNodeAny;
+
+/* Espace constitué d'un ou plusieurs octets quelconques (classe) */
+typedef struct _GScanTokenNodeAnyClass GScanTokenNodeAnyClass;
+
+
+/* Indique le type défini pour une série d'octets quelconque, vide ou non. */
+GType g_scan_token_node_any_get_type(void);
+
+/* Construit un noeud pointant une série d'octets quelconques. */
+GScanTokenNode *g_scan_token_node_any_new(const phys_t *, const phys_t *);
+
+/* Etend un noeud pointant une série d'octets. */
+void g_scan_token_node_any_merge(GScanTokenNodeAny *, GScanTokenNodeAny *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_ANY_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/choice-int.h b/src/analysis/scan/patterns/tokens/nodes/choice-int.h
new file mode 100644
index 0000000..77a4058
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/choice-int.h
@@ -0,0 +1,54 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * choice-int.h - prototypes internes pour des décompositions alternatives de motif de recherche
+ *
+ * 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_PATTERNS_TOKENS_NODES_CHOICE_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_CHOICE_INT_H
+
+
+#include "choice.h"
+
+
+#include "../node-int.h"
+
+
+
+/* Décompositions alternatives de motif de recherche (instance) */
+struct _GScanTokenNodeChoice
+{
+ GScanTokenNode parent; /* A laisser en premier */
+
+ GScanTokenNode **children; /* Sous-noeuds à représenter */
+ size_t count; /* Taille de cette liste */
+
+};
+
+/* Décompositions alternatives de motif de recherche (classe) */
+struct _GScanTokenNodeChoiceClass
+{
+ GScanTokenNodeClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_CHOICE_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/choice.c b/src/analysis/scan/patterns/tokens/nodes/choice.c
new file mode 100644
index 0000000..2a5e5f5
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/choice.c
@@ -0,0 +1,646 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * choice.c - décompositions alternatives de motif de recherche
+ *
+ * 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 "choice.h"
+
+
+#include <assert.h>
+
+
+#include "choice-int.h"
+
+
+
+/* ------------------------ DECOMPOSITION DE MOTIF RECHERCHE ------------------------ */
+
+
+/* Initialise la classe des décompositions alternatives. */
+static void g_scan_token_node_choice_class_init(GScanTokenNodeChoiceClass *);
+
+/* Initialise une instance de décompositions alternatives. */
+static void g_scan_token_node_choice_init(GScanTokenNodeChoice *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_node_choice_dispose(GScanTokenNodeChoice *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_node_choice_finalize(GScanTokenNodeChoice *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Communique l'intérêt d'un noeud au sein d'une analyse. */
+static float g_scan_token_node_choice_compute_weight_for_scan(const GScanTokenNodeChoice *);
+
+/* Prend acte d'une nouvelle propriété pour le noeud. */
+static void g_scan_token_node_choice_apply_flags(GScanTokenNodeChoice *, ScanTokenNodeFlags);
+
+/* Parcourt une arborescence de noeuds et y relève des éléments. */
+static void g_scan_token_node_choice_visit(GScanTokenNodeChoice *, scan_tree_points_t *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+static bool g_scan_token_node_choice_build_id(GScanTokenNodeChoice *, GEngineBackend *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_choice_check_forward(const GScanTokenNodeChoice *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_choice_check_backward(const GScanTokenNodeChoice *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DECOMPOSITION DE MOTIF RECHERCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour des décompositions alternatives de motif de recherche. */
+G_DEFINE_TYPE(GScanTokenNodeChoice, g_scan_token_node_choice, G_TYPE_SCAN_TOKEN_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des décompositions alternatives. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_class_init(GScanTokenNodeChoiceClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenNodeClass *node; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_node_choice_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_node_choice_finalize;
+
+ node = G_SCAN_TOKEN_NODE_CLASS(klass);
+
+ node->compute_weight = (compute_scan_token_node_weight_fc)g_scan_token_node_choice_compute_weight_for_scan;
+ node->apply = (apply_scan_token_node_flags_fc)g_scan_token_node_choice_apply_flags;
+ node->visit = (visit_scan_token_node_fc)g_scan_token_node_choice_visit;
+ node->enroll = (enroll_scan_token_node_fc)g_scan_token_node_choice_enroll;
+ node->build_id = (build_scan_token_node_id_fc)g_scan_token_node_choice_build_id;
+ node->check_forward = (check_scan_token_node_fc)g_scan_token_node_choice_check_forward;
+ node->check_backward = (check_scan_token_node_fc)g_scan_token_node_choice_check_backward;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : choice = instance à initialiser. *
+* *
+* Description : Initialise une instance de décompositions alternatives. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_init(GScanTokenNodeChoice *choice)
+{
+ choice->children = NULL;
+ choice->count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : choice = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_dispose(GScanTokenNodeChoice *choice)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < choice->count; i++)
+ g_clear_object(&choice->children[i]);
+
+ G_OBJECT_CLASS(g_scan_token_node_choice_parent_class)->dispose(G_OBJECT(choice));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : choice = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_finalize(GScanTokenNodeChoice *choice)
+{
+ if (choice->children != NULL)
+ free(choice->children);
+
+ G_OBJECT_CLASS(g_scan_token_node_choice_parent_class)->finalize(G_OBJECT(choice));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit une série de décompositions alternatives de motif. *
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenNode *g_scan_token_node_choice_new(void)
+{
+ GScanTokenNode *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_TOKEN_NODE_CHOICE, NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : choice = ensemble de noeuds à compléter. *
+* node = nouveau noeud à intégrer. *
+* *
+* Description : Ajoute un noeud à aux décompositions alternatives de motif. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_choice_add(GScanTokenNodeChoice *choice, GScanTokenNode *node)
+{
+ choice->children = realloc(choice->children, ++choice->count * sizeof(GScanTokenNode *));
+
+ choice->children[choice->count - 1] = node;
+ g_object_ref(G_OBJECT(node));
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à consulter. *
+* *
+* Description : Communique l'intérêt d'un noeud au sein d'une analyse. *
+* *
+* Retour : Poids de l'importance pour un départ de scan. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static float g_scan_token_node_choice_compute_weight_for_scan(const GScanTokenNodeChoice *node)
+{
+ float result; /* Valeur à retourner */
+ size_t weight_count; /* Nombre de comptabilisations */
+ size_t i; /* Boucle de parcours */
+ float weight; /* Nouveau poids à intégrer */
+
+ result = 0;
+
+ weight_count = 0;
+
+ for (i = 0; i < node->count; i++)
+ {
+ weight = g_scan_token_node_compute_weight_for_scan(node->children[i]);
+
+ if (weight > 0)
+ {
+ result += weight;
+ weight_count++;
+ }
+
+ }
+
+ if (weight_count != node->count)
+ result = 0;
+ else
+ result /= weight_count;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à mettre à jour. *
+* flags = propriétés particulières à associer au noeud. *
+* *
+* Description : Prend acte d'une nouvelle propriété pour le noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_apply_flags(GScanTokenNodeChoice *node, ScanTokenNodeFlags flags)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < node->count; i++)
+ g_scan_token_node_set_flags(node->children[i], flags);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = point de départ du parcours à effectuer. *
+* points = points capitaux de l'arborescence. [OUT] *
+* *
+* Description : Parcourt une arborescence de noeuds et y relève des éléments.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_visit(GScanTokenNodeChoice *node, scan_tree_points_t *points)
+{
+ size_t first_plain_count; /* Décompte de noeuds textuels */
+ size_t i; /* Boucle de parcours */
+ scan_tree_points_t tmp_points; /* Synthèse d'analyse locale */
+
+ if (points->first_plain != NULL)
+ return;
+
+ first_plain_count = 0;
+
+ for (i = 0; i < node->count; i++)
+ {
+ tmp_points.first_plain = NULL;
+ tmp_points.best_masked = NULL;
+
+ g_scan_token_node_visit(node->children[i], &tmp_points);
+
+ if (tmp_points.first_plain != NULL)
+ first_plain_count++;
+
+ }
+
+ if (first_plain_count == node->count)
+ points->first_plain = G_SCAN_TOKEN_NODE(node);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_choice_enroll(GScanTokenNodeChoice *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = true;
+
+ for (i = 0; i < node->count && result; i++)
+ result = _g_scan_token_node_enroll(node->children[i], backend, maxsize, slow);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_choice_build_id(GScanTokenNodeChoice *node, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours #1 */
+
+ result = true;
+
+ for (i = 0; i < node->count && result; i++)
+ result = g_scan_token_node_build_id(node->children[i], backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_check_forward(const GScanTokenNodeChoice *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ bool initialized; /* Initialisation du suivi ? */
+ match_area_t *collected_areas; /* Zones mises en place ici */
+ size_t collected_count; /* Quantité de ces zones */
+ TokenNodeCheckFlags local_cflags; /* Particularités nouvelles */
+ size_t i; /* Boucle de parcours */
+ scan_node_check_params_t local_params; /* Rassemblement de paramètres */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ /* Lancement des sous-traitements */
+
+ initialized = false;
+
+ collected_areas = NULL;
+ collected_count = 0;
+
+ local_cflags = (cflags & ~TNCF_UPDATE_IN_PLACE) | TNCF_CREATE_NEW;
+
+ for (i = 0; i < node->count; i++)
+ {
+ local_params = *params;
+
+ local_params.created_areas = NULL;
+ local_params.created_count = 0;
+
+ local_params.kept_areas = NULL;
+ local_params.kept_count = 0;
+
+ if ((cflags & TNCF_CREATE_NEW) == 0 && (i + 1) == node->count)
+ local_cflags = cflags;
+
+ _g_scan_token_node_check_forward(node->children[i], &local_params, local_cflags, skip);
+
+ initialized |= local_params.initialized;
+
+ if (local_cflags & TNCF_KEEP_DISCARDED)
+ {
+ merge_match_areas(&collected_areas, &local_params.kept_areas);
+ collected_count += local_params.kept_count;
+ }
+
+ else if (local_cflags & TNCF_CREATE_NEW)
+ {
+ merge_match_areas(&collected_areas, &local_params.created_areas);
+ collected_count += local_params.created_count;
+ }
+
+ else
+ {
+ assert(local_cflags & TNCF_UPDATE_IN_PLACE);
+
+ merge_match_areas(&collected_areas, &local_params.main_areas);
+ collected_count += local_params.main_count;
+
+ }
+
+ }
+
+ /* Enregistrement des résultats finaux */
+
+ if (collected_count > 1)
+ sort_match_areas_no_dup(&collected_areas, &collected_count, compare_match_area_as_dl_item, NULL);
+
+ if (0x0) printf("[%s] collected: #%zu (bis)\n", __FUNCTION__, collected_count);
+
+ params->initialized = initialized;
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ params->kept_areas = collected_areas;
+ params->kept_count = collected_count;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ params->created_areas = collected_areas;
+ params->created_count = collected_count;
+ }
+
+ else
+ {
+ assert(cflags & TNCF_UPDATE_IN_PLACE);
+
+ params->main_areas = collected_areas;
+ params->main_count = collected_count;
+
+ }
+
+
+
+
+
+ /// TODO : gestion des offets en sortie : ajout (+ ajout d'un test en Python)
+
+
+
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_choice_check_backward(const GScanTokenNodeChoice *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ match_area_t *collected_areas; /* Zones mises en place ici */
+ size_t collected_count; /* Quantité de ces zones */
+ TokenNodeCheckFlags local_cflags; /* Particularités nouvelles */
+ size_t i; /* Boucle de parcours */
+ scan_node_check_params_t local_params; /* Rassemblement de paramètres */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ /**
+ * En lecture à rebourd, au moins un noeud a été solicité pour analyse (lors
+ * du sens de lecture normal). Donc l'initialisation a déjà dû avoir lieu.
+ */
+
+ assert(params->initialized);
+
+ /* Lancement des sous-traitements */
+
+ collected_areas = NULL;
+ collected_count = 0;
+
+ local_cflags = (cflags & ~TNCF_UPDATE_IN_PLACE) | TNCF_CREATE_NEW;
+
+ for (i = 0; i < node->count; i++)
+ {
+ local_params = *params;
+
+ local_params.created_areas = NULL;
+ local_params.created_count = 0;
+
+ local_params.kept_areas = NULL;
+ local_params.kept_count = 0;
+
+ if ((cflags & TNCF_CREATE_NEW) == 0 && (i + 1) == node->count)
+ local_cflags = cflags;
+
+ _g_scan_token_node_check_backward(node->children[i], &local_params, local_cflags, skip);
+
+ if (local_cflags & TNCF_KEEP_DISCARDED)
+ {
+ merge_match_areas(&collected_areas, &local_params.kept_areas);
+ collected_count += local_params.kept_count;
+ }
+
+ else if (local_cflags & TNCF_CREATE_NEW)
+ {
+ merge_match_areas(&collected_areas, &local_params.created_areas);
+ collected_count += local_params.created_count;
+ }
+
+ else
+ {
+ assert(local_cflags & TNCF_UPDATE_IN_PLACE);
+
+ merge_match_areas(&collected_areas, &local_params.main_areas);
+ collected_count += local_params.main_count;
+
+ }
+
+ }
+
+ /* Enregistrement des résultats finaux */
+
+ if (collected_count > 1)
+ sort_match_areas_no_dup(&collected_areas, &collected_count, compare_match_area_as_dl_item, NULL);
+
+ if (0x0) printf("[%s] collected: #%zu (bis)\n", __FUNCTION__, collected_count);
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ params->kept_areas = collected_areas;
+ params->kept_count = collected_count;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ params->created_areas = collected_areas;
+ params->created_count = collected_count;
+ }
+
+ else
+ {
+ assert(cflags & TNCF_UPDATE_IN_PLACE);
+
+ params->main_areas = collected_areas;
+ params->main_count = collected_count;
+
+ }
+
+
+
+
+
+ /// TODO : gestion des offets en sortie : ajout (+ ajout d'un test en Python)
+
+
+
+
+
+
+}
diff --git a/src/analysis/scan/patterns/tokens/nodes/choice.h b/src/analysis/scan/patterns/tokens/nodes/choice.h
new file mode 100644
index 0000000..e793b1e
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/choice.h
@@ -0,0 +1,61 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * choice.h - prototypes pour des décompositions alternatives de motif de recherche
+ *
+ * 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_PATTERNS_TOKENS_NODES_CHOICE_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_CHOICE_H
+
+
+#include <glib-object.h>
+
+
+#include "../node.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_NODE_CHOICE g_scan_token_node_choice_get_type()
+#define G_SCAN_TOKEN_NODE_CHOICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_NODE_CHOICE, GScanTokenNodeChoice))
+#define G_IS_SCAN_TOKEN_NODE_CHOICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_NODE_CHOICE))
+#define G_SCAN_TOKEN_NODE_CHOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_NODE_CHOICE, GScanTokenNodeChoiceClass))
+#define G_IS_SCAN_TOKEN_NODE_CHOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_NODE_CHOICE))
+#define G_SCAN_TOKEN_NODE_CHOICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_NODE_CHOICE, GScanTokenNodeChoiceClass))
+
+
+/* Décompositions alternatives de motif de recherche (instance) */
+typedef struct _GScanTokenNodeChoice GScanTokenNodeChoice;
+
+/* Décompositions alternatives de motif de recherche (classe) */
+typedef struct _GScanTokenNodeChoiceClass GScanTokenNodeChoiceClass;
+
+
+/* Indique le type défini pour des décompositions alternatives de motif de recherche. */
+GType g_scan_token_node_choice_get_type(void);
+
+/* Construit une série de décompositions alternatives de motif. */
+GScanTokenNode *g_scan_token_node_choice_new(void);
+
+/* Ajoute un noeud à aux décompositions alternatives de motif. */
+void g_scan_token_node_choice_add(GScanTokenNodeChoice *, GScanTokenNode *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_CHOICE_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/masked-int.h b/src/analysis/scan/patterns/tokens/nodes/masked-int.h
new file mode 100644
index 0000000..5fcc330
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/masked-int.h
@@ -0,0 +1,64 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * masked-int.h - prototypes internes pour la gestion d'une recherche de motif partielle
+ *
+ * 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_PATTERNS_TOKENS_NODES_MASKED_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_MASKED_INT_H
+
+
+#include "masked.h"
+
+
+#include "../node-int.h"
+
+
+
+/* Bribe de motif partielle pour recherches (instance) */
+struct _GScanTokenNodeMasked
+{
+ GScanTokenNode parent; /* A laisser en premier */
+
+ masked_byte_t *bytes; /* Série d'octets masqués */
+ size_t len; /* Taille de cette série */
+
+ sized_binary_t *raw; /* Liste de motifs à couvrir */
+ size_t raw_count; /* Taille de cette liste */
+
+ tracked_scan_atom_t *enrolled_atoms; /* Atomes correspondants */
+ size_t enrolled_count; /* Quantité avec identifiant */
+
+};
+
+/* Bribe de motif partielle pour recherches (classe) */
+struct _GScanTokenNodeMaskedClass
+{
+ GScanTokenNodeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place une bribe de motif partielle. */
+bool g_scan_token_node_masked_create(GScanTokenNodeMasked *, const masked_byte_t *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_MASKED_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/masked.c b/src/analysis/scan/patterns/tokens/nodes/masked.c
new file mode 100644
index 0000000..5194cb8
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/masked.c
@@ -0,0 +1,1135 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * masked.c - gestion d'une recherche de motif partielle
+ *
+ * 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 "masked.h"
+
+
+#include <assert.h>
+
+
+#include "masked-int.h"
+#include "../../backends/bitap.h"
+
+
+
+/* ------------------------ DECOMPOSITION DE MOTIF RECHERCHE ------------------------ */
+
+
+/* Initialise la classe des bribes de motif partielles. */
+static void g_scan_token_node_masked_class_init(GScanTokenNodeMaskedClass *);
+
+/* Initialise une instance de bribe de motif partielle. */
+static void g_scan_token_node_masked_init(GScanTokenNodeMasked *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_node_masked_dispose(GScanTokenNodeMasked *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_node_masked_finalize(GScanTokenNodeMasked *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Parcourt une arborescence de noeuds et y relève des éléments. */
+static void g_scan_token_node_masked_visit(GScanTokenNodeMasked *, scan_tree_points_t *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+static bool g_scan_token_node_masked_enroll(GScanTokenNodeMasked *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+static bool g_scan_token_node_masked_build_id(GScanTokenNodeMasked *, GEngineBackend *);
+
+/* Détermine si un contenu d'intérêt est présent à une position. */
+static bool check_scan_token_node_masked_content(const masked_byte_t *, size_t, phys_t, GBinContent *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_masked_check_forward(const GScanTokenNodeMasked *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_masked_check_backward(const GScanTokenNodeMasked *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DECOMPOSITION DE MOTIF RECHERCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour un noeud représentant une bribe partielle à retrouver. */
+G_DEFINE_TYPE(GScanTokenNodeMasked, g_scan_token_node_masked, G_TYPE_SCAN_TOKEN_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des bribes de motif partielles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_masked_class_init(GScanTokenNodeMaskedClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenNodeClass *node; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_node_masked_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_node_masked_finalize;
+
+ node = G_SCAN_TOKEN_NODE_CLASS(klass);
+
+ node->apply = (apply_scan_token_node_flags_fc)NULL;
+ node->visit = (visit_scan_token_node_fc)g_scan_token_node_masked_visit;
+ node->enroll = (enroll_scan_token_node_fc)g_scan_token_node_masked_enroll;
+ node->build_id = (build_scan_token_node_id_fc)g_scan_token_node_masked_build_id;
+ node->check_forward = (check_scan_token_node_fc)g_scan_token_node_masked_check_forward;
+ node->check_backward = (check_scan_token_node_fc)g_scan_token_node_masked_check_backward;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : masked = instance à initialiser. *
+* *
+* Description : Initialise une instance de bribe de motif partielle. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_masked_init(GScanTokenNodeMasked *masked)
+{
+ masked->bytes = NULL;
+ masked->len = 0;
+
+ masked->raw = NULL;
+ masked->raw_count = 0;
+
+ masked->enrolled_atoms = NULL;
+ masked->enrolled_count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : masked = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_masked_dispose(GScanTokenNodeMasked *masked)
+{
+ G_OBJECT_CLASS(g_scan_token_node_masked_parent_class)->dispose(G_OBJECT(masked));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : masked = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_masked_finalize(GScanTokenNodeMasked *masked)
+{
+ size_t i; /* Boucle de parcours */
+
+ if (masked->bytes != NULL)
+ free(masked->bytes);
+
+ for (i = 0; i < masked->raw_count; i++)
+ exit_szstr(&masked->raw[i]);
+
+ if (masked->raw != NULL)
+ free(masked->raw);
+
+ if (masked->enrolled_atoms != NULL)
+ free(masked->enrolled_atoms);
+
+ G_OBJECT_CLASS(g_scan_token_node_masked_parent_class)->finalize(G_OBJECT(masked));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : byte = valeur masquée à intégrer. *
+* *
+* Description : Construit une bribe de motif partielle. *
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenNode *g_scan_token_node_masked_new(const masked_byte_t *byte)
+{
+ GScanTokenNode *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_TOKEN_NODE_MASKED, NULL);
+
+ if (!g_scan_token_node_masked_create(G_SCAN_TOKEN_NODE_MASKED(result), byte))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : masked = bribe partielle à initialiser pleinement. *
+* byte = valeur masquée à intégrer. *
+* *
+* Description : Met en place une bribe de motif partielle. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_masked_create(GScanTokenNodeMasked *masked, const masked_byte_t *byte)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ g_scan_token_node_masked_add(masked, byte);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : masked = ensemble de noeuds à compléter. *
+* byte = valeur masquée à intégrer. *
+* *
+* Description : Enregistre la valeur d'octet à rechercher avec son masque. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_masked_add(GScanTokenNodeMasked *masked, const masked_byte_t *byte)
+{
+ assert((byte->value & 0x0f) == 0 || (byte->value & 0xf0) == 0);
+
+ masked->bytes = realloc(masked->bytes, ++masked->len * sizeof(masked_byte_t));
+
+ masked->bytes[masked->len - 1] = *byte;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : node = point de départ du parcours à effectuer. *
+* points = points capitaux de l'arborescence. [OUT] *
+* *
+* Description : Parcourt une arborescence de noeuds et y relève des éléments.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_masked_visit(GScanTokenNodeMasked *node, scan_tree_points_t *points)
+{
+ GScanTokenNodeMasked *other; /* Concurrence à mesurer */
+
+ if (points->best_masked == NULL)
+ points->best_masked = G_SCAN_TOKEN_NODE(node);
+
+ else
+ {
+ other = G_SCAN_TOKEN_NODE_MASKED(points->best_masked);
+
+ if (node->len > other->len)
+ points->best_masked = G_SCAN_TOKEN_NODE(node);
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_masked_enroll(GScanTokenNodeMasked *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+ bool forced; /* Inclusion dans un scan ? */
+ //size_t len_to_enroll; /* Taille à considérer */
+ size_t i; /* Boucle de parcours */
+
+ result = true;
+
+ forced = (g_scan_token_node_get_flags(G_SCAN_TOKEN_NODE(node)) & STNF_MAIN);
+
+ if (forced)
+ {
+ *slow += (maxsize * 2);
+
+ node->raw = make_atoms_from_masked_bytes(node->bytes, node->len, &node->raw_count);
+
+ /**
+ * Dans le cas bien précis de l'usage de l'algorithme Bitap pour les recherches
+ * dans le contenu binaire à analyser, on tire parti du coût nul des recherches
+ * multiples pour une même position.
+ */
+
+ if (G_IS_BITAP_BACKEND(backend))
+ {
+ //len_to_enroll = (node->len < maxsize ? node->len : maxsize);
+
+ /* TODO */
+ assert(false);
+
+
+ node->enrolled_count = 1;
+
+ }
+
+ else
+ {
+ node->enrolled_atoms = malloc(node->raw_count * sizeof(tracked_scan_atom_t));
+ node->enrolled_count = node->raw_count;
+
+ for (i = 0; i < node->enrolled_count && result; i++)
+ {
+ find_best_atom(&node->raw[i], maxsize, &node->enrolled_atoms[i], NULL);
+
+ /**
+ * Correction : si l'atome ne représente qu'une vue partielle,
+ * la validation rapide ne peut s'appliquer.
+ */
+ if (node->enrolled_atoms[i].fast_check)
+ node->enrolled_atoms[i].fast_check = (node->enrolled_atoms[i].len == node->len);
+
+ result = enroll_prepared_atom(&node->raw[i], backend, &node->enrolled_atoms[i]);
+
+ }
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_masked_build_id(GScanTokenNodeMasked *node, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours #1 */
+
+ result = true;
+
+ for (i = 0; i < node->enrolled_count && result; i++)
+ result = build_atom_pattern_id(&node->enrolled_atoms[i], backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = octets partiels avec leur masque à interpréter. *
+* len = quantité d'octets à interpréter. *
+* start = point d'analyse à respecter. *
+* content = accès au contenu brut pour vérifications (optim.) *
+* *
+* Description : Détermine si un contenu d'intérêt est présent à une position.*
+* *
+* Retour : Bilan de l'analyse : true pour une correspondance. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool check_scan_token_node_masked_content(const masked_byte_t *bytes, size_t len, phys_t start, GBinContent *content)
+{
+ bool result; /* Bilan à retourner */
+ vmpa2t pos; /* Position dans les données */
+ const bin_t *ptr; /* Accès aux données brutes */
+ size_t i; /* Boucle de parcours */
+
+ result = false;
+
+ init_vmpa(&pos, start, VMPA_NO_VIRTUAL);
+
+ ptr = g_binary_content_get_raw_access(content, &pos, len);
+
+ for (i = 0; i < len; i++)
+ {
+ if ((ptr[i] & bytes[i].mask) != bytes[i].value)
+ break;
+ }
+
+ result = (i == len);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_masked_check_forward(const GScanTokenNodeMasked *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+#ifndef NDEBUG
+ bool forced; /* Inclusion dans un scan ? */
+#endif
+ match_area_t **areas; /* Liste de zones à constituer */
+ size_t *count; /* Taille de cette liste */
+ bool copy; /* Besoin d'une copie ? */
+ bool inverted; /* Inversion des bilans ? */
+ size_t i; /* Boucle de parcours #1 */
+ const tracked_scan_atom_t *atom; /* Atome correspondant */
+ match_area_t *atoms; /* Localisations des bribes */
+ bool first_round; /* Premier tour de traitement */
+ match_area_t *area; /* Correspondance à valider */
+ match_area_t *next; /* Correspondance suivante */
+ phys_t start; /* Début potentiel de motif */
+ bool status; /* Bilan d'une correspondance */
+ phys_t after; /* Espace disposible après */
+ phys_t min_end; /* Fin la plus proche possible */
+ phys_t max_end; /* Fin la plus éloignée trouvée*/
+ bool updated; /* Existence de correspondance */
+ size_t rcount; /* Quantité de bornes présentes*/
+ const node_offset_range_t *ranges; /* Bornes d'espace à parcourir */
+ size_t r; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t p; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t updated_edge; /* Nouvelle bordure de motif */
+ match_area_t *new_area; /* Copie de correspondance */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ /**
+ * Si l'analyse arrive à un ou plusieurs octets masqués, soit il s'agit du
+ * premier noeud, et la génération d'atomes a été forcée pour obtenir des
+ * points de départ, soit des correspondances ont été établies au préalable,
+ * et il ne doit alors pas y avoir d'atome mis en place (si l'initialisation
+ * ne provient pas d'une mise en place artificielle par une inversion NOT).
+ */
+#ifndef NDEBUG
+ forced = (g_scan_token_node_get_flags(G_SCAN_TOKEN_NODE(node)) & STNF_MAIN);
+ assert((!params->initialized && forced) || (params->initialized && (!forced || cflags & TNCF_KEEP_DISCARDED)));
+#endif
+
+ if (!params->initialized)
+ {
+ /* Destinations établies une fois pour toutes */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ areas = &params->kept_areas;
+ count = &params->kept_count;
+
+ copy = false;
+ inverted = true;
+
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ areas = &params->created_areas;
+ count = &params->created_count;
+
+ copy = true;
+ inverted = false;
+
+ }
+
+ else
+ {
+ assert(cflags & TNCF_UPDATE_IN_PLACE);
+
+ areas = &params->main_areas;
+ count = &params->main_count;
+
+ copy = false;
+ inverted = false;
+
+ }
+
+ /* Parcours des combinaisons enregistrées */
+
+ for (i = 0; i < node->enrolled_count; i++)
+ {
+ atom = &node->enrolled_atoms[i];
+
+ atoms = g_scan_context_get_atom_matches(params->context, atom->pid);
+
+ first_round = (*count == 0);
+
+ if (atom->fast_check)
+ {
+ /**
+ * Toutes les correspondances sont validées d'office car le motif identifié
+ * correspondant au motif complet.
+ */
+
+ if (!inverted)
+ {
+ for_each_match_area(area, atoms)
+ {
+ /**
+ * La modification de la zone d'origine est possible dans tous les cas
+ * car cette zone a été allouée de façon dédiée à un type de correspondances
+ * et ne sera pas réutilisée comme autre source de correspondance ailleurs.
+ */
+
+ assert(area->end >= atom->len);
+
+ area->start = area->end - atom->len;
+
+ (*count)++;
+
+ }
+
+ }
+
+ else
+ atoms = NULL;
+
+ }
+
+ else
+ {
+ for_each_match_area_safe(area, &atoms, next)
+ {
+ start = area->end - atom->len - atom->pos;
+
+ status = check_scan_token_node_masked_content(node->bytes, node->len,
+ start, params->content);
+
+ if (status)
+ {
+ /**
+ * La modification de la zone d'origine est possible dans tous les cas
+ * car cette zone a été allouée de façon dédiée à un type de correspondances
+ * et ne sera pas réutilisée comme autre source de correspondance ailleurs.
+ */
+
+ if (!inverted)
+ {
+ area->start = start;
+ area->end += atom->rem;
+
+ (*count)++;
+
+ }
+ else
+ del_match_area(area, &atoms);
+
+ }
+
+ else
+ {
+ /**
+ * Les principes de modifications restent valables, même inversés.
+ */
+ if (inverted)
+ {
+ area->start = start;
+ area->end += atom->rem;
+
+ (*count)++;
+
+ }
+ else
+ del_match_area(area, &atoms);
+
+ }
+
+ }
+
+
+ }
+
+ /* Mise à jour de la liste */
+
+ if (atoms != NULL)
+ {
+ if (first_round)
+ *areas = atoms;
+
+ else
+ merge_match_areas(areas, &atoms);
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Poursuite des traitements sur des correspondances déjà amorcées, impliquant
+ * des comparaisons entières de motifs.
+ */
+ else
+ {
+ if (0x0) printf(" LIST : %p (sz = %zu)\n", params->main_areas, params->main_count);
+
+ for_each_match_area_safe(area, &params->main_areas, next)
+ {
+ assert(area->end <= params->content_end);
+
+ after = params->content_end - area->end;
+
+ if (0x0) printf("---------- iter @ %u -> %u\n", (unsigned int)area->start, (unsigned int)area->end);
+
+ /**
+ * S'il s'avère qu'il existe de multiples correspondances dans l'espace
+ * analysé, c'est la prise en compte d'une éventuelle avarice quant aux
+ * distances consommées qui va sélectionner la position d'une bribe de
+ * correspondance retenue.
+ *
+ * Par exemple, deux correspondances '?1 ?1 [1-3] ?2 ?2' peuvent être
+ * valides pour un même contenu :
+ *
+ * aa.bbb -> correspondance 'aa.bb'
+ * ^
+ *
+ * aa.bbb -> correspondance 'aa..bb'
+ * ^
+ */
+
+ min_end = params->content_end;
+ max_end = params->content_start;
+
+ updated = false;
+
+ /* Souplesse dans les positions ? */
+ if (offsets_exist(&params->offset))
+ {
+ ranges = get_node_search_offset_ranges_2(&params->offset, &rcount);
+
+ for (r = 0; r < rcount; r++)
+ {
+ assert(ranges[r].has_max);
+ assert((ranges[r].max - ranges[r].min) <= MAX_RANGE_FOR_MANUAL_CHECK);
+
+ for (p = ranges[r].min; p <= ranges[r].max; p++)
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près de
+ * la fin du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if ((p + node->len) > after)
+ break;
+
+ status = check_scan_token_node_masked_content(node->bytes, node->len,
+ area->end + p, params->content);
+
+ if (status)
+ {
+ updated_edge = area->end + p + node->len;
+
+ if (updated_edge < min_end)
+ min_end = updated_edge;
+
+ if (updated_edge > max_end)
+ max_end = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ /* Position immédiatement attendue */
+ else
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près de
+ * la fin du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if (node->len <= after)
+ {
+ status = check_scan_token_node_masked_content(node->bytes, node->len,
+ area->end, params->content);
+
+ if (status)
+ {
+ updated_edge = area->end + node->len;
+
+ min_end = updated_edge;
+ max_end = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ if (updated)
+ {
+ /**
+ * Si seuls les rejets sont d'intérêt, les correspondances établies
+ * ne se voient pas mises à jours ni retirées.
+ */
+
+ if ((cflags & TNCF_KEEP_DISCARDED) == 0)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ area->end = (1 /* greedy */ ? min_end : max_end);
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->end = (1 /* greedy */ ? min_end : max_end);
+
+ add_tail_match_area(new_area, &params->created_areas);
+ params->created_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ else
+ {
+ /**
+ * Si la liste principale doit être mise à jour...
+ */
+
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ del_match_area(area, &params->main_areas);
+ assert(params->main_count > 0);
+ params->main_count--;
+ }
+
+ /**
+ * Au cas où le rejet est d'intérêt, l'absence de correspondance
+ * est conservée dans une liste dédiée.
+ */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ add_tail_match_area(area, &params->kept_areas);
+ params->kept_count++;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->end = (1 /* greedy */ ? min_end : max_end);
+
+ add_tail_match_area(new_area, &params->kept_areas);
+ params->kept_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ }
+
+ }
+
+ params->initialized = true;
+
+ disable_all_ranges_in_node_search_offset(&params->offset);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_masked_check_backward(const GScanTokenNodeMasked *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+#ifndef NDEBUG
+ bool forced; /* Inclusion dans un scan ? */
+#endif
+
+
+
+ bool status; /* Bilan d'une correspondance */
+
+
+ match_area_t *area; /* Correspondance à valider */
+ match_area_t *next; /* Correspondance suivante */
+ phys_t before; /* Espace disposible avant */
+ phys_t min_start; /* Début le plus proche trouvé */
+ phys_t max_start; /* Début le plus distant trouvé*/
+ bool updated; /* Existence de correspondance */
+ size_t rcount; /* Quantité de bornes présentes*/
+ const node_offset_range_t *ranges; /* Bornes d'espace à parcourir */
+ size_t r; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t p; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t updated_edge; /* Nouvelle bordure de motif */
+ match_area_t *new_area; /* Copie de correspondance */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ /**
+ * En lecture à rebourd, au moins un noeud a été solicité pour analyse (lors
+ * du sens de lecteur normal). Donc l'initialisation a déjà dû avoir lieu.
+ */
+ assert(params->initialized);
+
+ /**
+ * Si les recherches associées au noeud ont été forcées, alors les traitements
+ * liés ont déjà été effectués, et l'appel de cette fonction aurait dû être sauté.
+ */
+#ifndef NDEBUG
+ forced = (g_scan_token_node_get_flags(G_SCAN_TOKEN_NODE(node)) & STNF_MAIN);
+ assert(!forced);
+#endif
+
+
+
+
+ /**
+ * .............
+ */
+ if (0)
+ {
+
+
+ ;
+
+
+
+ }
+
+ /**
+ * Poursuite des traitements sur des correspondances déjà amorcées, impliquant
+ * des comparaisons entières de motifs.
+ */
+ else
+ {
+ if (0x0) printf(" LIST : %p (sz = %zu)\n", params->main_areas, params->main_count);
+
+ for_each_match_area_safe(area, &params->main_areas, next)
+ {
+ assert(params->content_start <= area->start);
+
+ before = area->start - params->content_start;
+
+ if (0x0) printf("---------- iter @ %u -> %u\n", (unsigned int)area->start, (unsigned int)area->end);
+
+ /**
+ * Il ne peut y avoir qu'une seule séquence d'octets à un même
+ * emplacement. En revanche, des modificateurs peuvent construire
+ * possédant une même base, mais offrant des suffixes différents
+ * (par exemple, un marqueur nul UTF-16 final en complément).
+ *
+ * L'ensemble des combinaisons produites doit ainsi être exploré.
+ */
+
+ min_start = params->content_start;
+ max_start = params->content_end;
+
+ updated = false;
+
+ /* Souplesse dans les positions ? */
+ if (offsets_exist(&params->offset))
+ {
+ ranges = get_node_search_offset_ranges_2(&params->offset, &rcount);
+
+ for (r = 0; r < rcount; r++)
+ {
+ assert(ranges[r].has_max);
+ assert((ranges[r].max - ranges[r].min) <= MAX_RANGE_FOR_MANUAL_CHECK);
+
+ for (p = ranges[r].min; p <= ranges[r].max; p++)
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près de
+ * la fin du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if ((p + node->len) > before)
+ break;
+
+ status = check_scan_token_node_masked_content(node->bytes, node->len,
+ area->start - node->len - p,
+ params->content);
+
+ if (status)
+ {
+ updated_edge = area->start - node->len - p;
+
+ if (updated_edge > min_start)
+ min_start = updated_edge;
+
+ if (updated_edge < max_start)
+ max_start = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ /* Position immédiatement attendue */
+ else
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près du
+ * début du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if (node->len <= before)
+ {
+ status = check_scan_token_node_masked_content(node->bytes, node->len,
+ area->start - node->len,
+ params->content);
+
+ if (status)
+ {
+ updated_edge = area->start - node->len;
+
+ if (updated_edge > min_start)
+ min_start = updated_edge;
+
+ if (updated_edge < max_start)
+ max_start = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ if (updated)
+ {
+ /**
+ * Si seuls les rejets sont d'intérêt, les correspondances établies
+ * ne se voient pas mises à jours ni retirées.
+ */
+
+ if ((cflags & TNCF_KEEP_DISCARDED) == 0)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ area->start = (1 /* greedy */ ? min_start : max_start);
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->start = (1 /* greedy */ ? min_start : max_start);
+
+ add_tail_match_area(new_area, &params->created_areas);
+ params->created_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ else
+ {
+ /**
+ * Si la liste principale doit être mise à jour...
+ */
+
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ del_match_area(area, &params->main_areas);
+ assert(params->main_count > 0);
+ params->main_count--;
+ }
+
+ /**
+ * Au cas où le rejet est d'intérêt, l'absence de correspondance
+ * est conservée dans une liste dédiée.
+ */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ add_tail_match_area(area, &params->kept_areas);
+ params->kept_count++;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->start = (1 /* greedy */ ? min_start : max_start);
+
+ add_tail_match_area(new_area, &params->kept_areas);
+ params->kept_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ }
+
+ }
+
+ disable_all_ranges_in_node_search_offset(&params->offset);
+
+}
diff --git a/src/analysis/scan/patterns/tokens/nodes/masked.h b/src/analysis/scan/patterns/tokens/nodes/masked.h
new file mode 100644
index 0000000..04a05bc
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/masked.h
@@ -0,0 +1,63 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * masked.h - prototypes pour la gestion d'une recherche de motif partielle
+ *
+ * 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_PATTERNS_TOKENS_NODES_MASKED_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_MASKED_H
+
+
+#include <glib-object.h>
+
+
+#include "../atom.h"
+#include "../node.h"
+#include "../../../../../arch/archbase.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_NODE_MASKED g_scan_token_node_masked_get_type()
+#define G_SCAN_TOKEN_NODE_MASKED(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_NODE_MASKED, GScanTokenNodeMasked))
+#define G_IS_SCAN_TOKEN_NODE_MASKED(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_NODE_MASKED))
+#define G_SCAN_TOKEN_NODE_MASKED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_NODE_MASKED, GScanTokenNodeMaskedClass))
+#define G_IS_SCAN_TOKEN_NODE_MASKED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_NODE_MASKED))
+#define G_SCAN_TOKEN_NODE_MASKED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_NODE_MASKED, GScanTokenNodeMaskedClass))
+
+
+/* Bribe de motif partielle pour recherches (instance) */
+typedef struct _GScanTokenNodeMasked GScanTokenNodeMasked;
+
+/* Bribe de motif partielle pour recherches (classe) */
+typedef struct _GScanTokenNodeMaskedClass GScanTokenNodeMaskedClass;
+
+
+/* Indique le type défini pour un noeud représentant une bribe partielle à retrouver. */
+GType g_scan_token_node_masked_get_type(void);
+
+/* Construit une bribe de motif partielle. */
+GScanTokenNode *g_scan_token_node_masked_new(const masked_byte_t *);
+
+/* Enregistre la valeur d'octet à rechercher avec son masque. */
+void g_scan_token_node_masked_add(GScanTokenNodeMasked *, const masked_byte_t *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_MASKED_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/not-int.h b/src/analysis/scan/patterns/tokens/nodes/not-int.h
new file mode 100644
index 0000000..5f92afd
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/not-int.h
@@ -0,0 +1,57 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * not-int.h - prototypes internes pour l'inversion de résultats de correspondances établis
+ *
+ * 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_PATTERNS_TOKENS_NODES_NOT_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_NOT_INT_H
+
+
+#include "not.h"
+
+
+#include "../node-int.h"
+
+
+
+/* Inversion de résultats de correspondances établis (instance) */
+struct _GScanTokenNodeNot
+{
+ GScanTokenNode parent; /* A laisser en premier */
+
+ GScanTokenNode *child; /* Sous-noeud à considérer */
+
+};
+
+/* Inversion de résultats de correspondances établis (classe) */
+struct _GScanTokenNodeNotClass
+{
+ GScanTokenNodeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place une inversion de résultats de correspondances. */
+bool g_scan_token_node_not_create(GScanTokenNodeNot *, GScanTokenNode *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_NOT_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/not.c b/src/analysis/scan/patterns/tokens/nodes/not.c
new file mode 100644
index 0000000..81fce28
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/not.c
@@ -0,0 +1,416 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * not.c - inversion de résultats de correspondances établis
+ *
+ * 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 "not.h"
+
+
+#include <assert.h>
+
+
+#include "not-int.h"
+
+
+
+/* ------------------------ DECOMPOSITION DE MOTIF RECHERCHE ------------------------ */
+
+
+/* Initialise la classe des inversions de correspondances. */
+static void g_scan_token_node_not_class_init(GScanTokenNodeNotClass *);
+
+/* Initialise une instance d'inversion de correspondances. */
+static void g_scan_token_node_not_init(GScanTokenNodeNot *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_node_not_dispose(GScanTokenNodeNot *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_node_not_finalize(GScanTokenNodeNot *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Prend acte d'une nouvelle propriété pour le noeud. */
+static void g_scan_token_node_not_apply_flags(GScanTokenNodeNot *, ScanTokenNodeFlags);
+
+/* Parcourt une arborescence de noeuds et y relève des éléments. */
+static void g_scan_token_node_not_visit(GScanTokenNodeNot *, scan_tree_points_t *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+static bool g_scan_token_node_not_enroll(GScanTokenNodeNot *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+static bool g_scan_token_node_not_build_id(GScanTokenNodeNot *, GEngineBackend *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_not_check_forward(const GScanTokenNodeNot *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_not_check_backward(const GScanTokenNodeNot *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DECOMPOSITION DE MOTIF RECHERCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une inversion des résultats de correspondances. */
+G_DEFINE_TYPE(GScanTokenNodeNot, g_scan_token_node_not, G_TYPE_SCAN_TOKEN_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des inversions de correspondances. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_class_init(GScanTokenNodeNotClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenNodeClass *node; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_node_not_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_node_not_finalize;
+
+ node = G_SCAN_TOKEN_NODE_CLASS(klass);
+
+ node->apply = (apply_scan_token_node_flags_fc)g_scan_token_node_not_apply_flags;
+ node->visit = (visit_scan_token_node_fc)g_scan_token_node_not_visit;
+ node->enroll = (enroll_scan_token_node_fc)g_scan_token_node_not_enroll;
+ node->build_id = (build_scan_token_node_id_fc)g_scan_token_node_not_build_id;
+ node->check_forward = (check_scan_token_node_fc)g_scan_token_node_not_check_forward;
+ node->check_backward = (check_scan_token_node_fc)g_scan_token_node_not_check_backward;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : not = instance à initialiser. *
+* *
+* Description : Initialise une instance d'inversion de correspondances. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_init(GScanTokenNodeNot *not)
+{
+ not->child = NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : not = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_dispose(GScanTokenNodeNot *not)
+{
+ g_clear_object(&not->child);
+
+ G_OBJECT_CLASS(g_scan_token_node_not_parent_class)->dispose(G_OBJECT(not));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : not = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_finalize(GScanTokenNodeNot *not)
+{
+ G_OBJECT_CLASS(g_scan_token_node_not_parent_class)->finalize(G_OBJECT(not));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : child = noeud dont les résultats sont à écarter. *
+* *
+* Description : Construit une inversion de résultats de correspondances. *
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenNode *g_scan_token_node_not_new(GScanTokenNode *child)
+{
+ GScanTokenNode *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_TOKEN_NODE_NOT, NULL);
+
+ if (!g_scan_token_node_not_create(G_SCAN_TOKEN_NODE_NOT(result), child))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : not = encadrement d'inversion à initialiser pleinement. *
+* child = noeud dont les résultats sont à écarter. *
+* *
+* Description : Met en place une inversion de résultats de correspondances. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_not_create(GScanTokenNodeNot *not, GScanTokenNode *child)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ not->child = child;
+ g_object_ref(G_OBJECT(child));
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à mettre à jour. *
+* flags = propriétés particulières à associer au noeud. *
+* *
+* Description : Prend acte d'une nouvelle propriété pour le noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_apply_flags(GScanTokenNodeNot *node, ScanTokenNodeFlags flags)
+{
+ g_scan_token_node_set_flags(node->child, flags);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = point de départ du parcours à effectuer. *
+* points = points capitaux de l'arborescence. [OUT] *
+* *
+* Description : Parcourt une arborescence de noeuds et y relève des éléments.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_visit(GScanTokenNodeNot *node, scan_tree_points_t *points)
+{
+ g_scan_token_node_visit(node->child, points);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_not_enroll(GScanTokenNodeNot *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+
+ result = _g_scan_token_node_enroll(node->child, backend, maxsize, slow);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_not_build_id(GScanTokenNodeNot *node, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+
+ result = g_scan_token_node_build_id(node->child, backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_check_forward(const GScanTokenNodeNot *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+
+#if 0
+
+
+ bool initialized; /* Initialisation du suivi ? */
+ phys_t i; /* Boucle de parcours */
+
+
+ /*
+
+ ?????????????????????????
+
+
+ if (*skip)
+ return;
+ */
+
+
+
+ initialized = are_pending_matches_initialized(matches);
+
+
+ //printf("TOTO......(init done? %d)\n", initialized);
+
+
+
+ if (!initialized)
+ {
+ for (i = matches->content_start; i < matches->content_end; i++)
+ add_pending_match(matches, i, 0);
+
+ set_pending_matches_initialized(matches);
+
+ }
+
+ _g_scan_token_node_check_forward(node->child, context, content, matches, offset, !not, skip);
+
+
+#endif
+
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_not_check_backward(const GScanTokenNodeNot *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+
+
+
+ if (*skip)
+ return;
+
+
+
+ printf("TODO\n");
+ assert(0);
+
+
+
+}
diff --git a/src/analysis/scan/patterns/tokens/nodes/not.h b/src/analysis/scan/patterns/tokens/nodes/not.h
new file mode 100644
index 0000000..58630e8
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/not.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * not.h - prototypes pour l'inversion de résultats de correspondances établis
+ *
+ * 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_PATTERNS_TOKENS_NODES_NOT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_NOT_H
+
+
+#include <glib-object.h>
+
+
+#include "../node.h"
+#include "../../../../../arch/archbase.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_NODE_NOT g_scan_token_node_not_get_type()
+#define G_SCAN_TOKEN_NODE_NOT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_NODE_NOT, GScanTokenNodeNot))
+#define G_IS_SCAN_TOKEN_NODE_NOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_NODE_NOT))
+#define G_SCAN_TOKEN_NODE_NOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_NODE_NOT, GScanTokenNodeNotClass))
+#define G_IS_SCAN_TOKEN_NODE_NOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_NODE_NOT))
+#define G_SCAN_TOKEN_NODE_NOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_NODE_NOT, GScanTokenNodeNotClass))
+
+
+/* Inversion de résultats de correspondances établis (instance) */
+typedef struct _GScanTokenNodeNot GScanTokenNodeNot;
+
+/* Inversion de résultats de correspondances établis (classe) */
+typedef struct _GScanTokenNodeNotClass GScanTokenNodeNotClass;
+
+
+/* Indique le type défini pour une inversion des résultats de correspondances. */
+GType g_scan_token_node_not_get_type(void);
+
+/* Construit une inversion de résultats de correspondances. */
+GScanTokenNode *g_scan_token_node_not_new(GScanTokenNode *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_NOT_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/plain-int.h b/src/analysis/scan/patterns/tokens/nodes/plain-int.h
new file mode 100644
index 0000000..2077c6f
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/plain-int.h
@@ -0,0 +1,64 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain-int.h - prototypes internes pour la gestion d'une recherche de motif textuel
+ *
+ * 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_PATTERNS_TOKENS_NODES_PLAIN_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_PLAIN_INT_H
+
+
+#include "plain.h"
+
+
+#include "../atom.h"
+#include "../node-int.h"
+
+
+
+/* Bribe de motif textuelle pour recherches (instance) */
+struct _GScanTokenNodePlain
+{
+ GScanTokenNode parent; /* A laisser en premier */
+
+ sized_binary_t orig; /* Motif d'origine avant modifs*/
+ GScanTokenModifier *modifier; /* Transformateur pour le motif*/
+ ScanPlainNodeFlags flags; /* Fanions associés au motif */
+
+ sized_binary_t *raw; /* Liste de motifs à couvrir */
+ tracked_scan_atom_t *atoms; /* Atomes correspondants */
+ size_t count; /* Taille de cette liste */
+
+};
+
+/* Bribe de motif textuelle pour recherches (instance) */
+struct _GScanTokenNodePlainClass
+{
+ GScanTokenNodeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place un noeud représentant un motif textuel. */
+bool g_scan_token_node_plain_create(GScanTokenNodePlain *, const sized_binary_t *, GScanTokenModifier *, ScanPlainNodeFlags);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_PLAIN_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/plain.c b/src/analysis/scan/patterns/tokens/nodes/plain.c
new file mode 100644
index 0000000..5dd45df
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/plain.c
@@ -0,0 +1,1377 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain.c - gestion d'une recherche de motif textuel
+ *
+ * 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 "plain.h"
+
+
+#include <assert.h>
+
+
+#include "plain-int.h"
+#include "../../../../../common/extstr.h"
+
+
+
+/* ------------------------ DECOMPOSITION DE MOTIF RECHERCHE ------------------------ */
+
+
+/* Initialise la classe des noeuds pour motif textuel. */
+static void g_scan_token_node_plain_class_init(GScanTokenNodePlainClass *);
+
+/* Initialise une instance de noeud pour motif textuel. */
+static void g_scan_token_node_plain_init(GScanTokenNodePlain *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_node_plain_dispose(GScanTokenNodePlain *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_node_plain_finalize(GScanTokenNodePlain *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Communique l'intérêt d'un noeud au sein d'une analyse. */
+static float g_scan_token_node_plain_compute_weight_for_scan(const GScanTokenNodePlain *);
+
+/* Parcourt une arborescence de noeuds et y relève des éléments. */
+static void g_scan_token_node_plain_visit(GScanTokenNodePlain *, scan_tree_points_t *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+static bool g_scan_token_node_plain_enroll(GScanTokenNodePlain *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+static bool g_scan_token_node_plain_build_id(GScanTokenNodePlain *, GEngineBackend *);
+
+/* Détermine si un contenu d'intérêt est présent à une position. */
+static bool check_scan_token_node_plain_content(const sized_binary_t *, const tracked_scan_atom_t *, bool, phys_t, GBinContent *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_plain_check_forward(const GScanTokenNodePlain *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_plain_check_backward(const GScanTokenNodePlain *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DECOMPOSITION DE MOTIF RECHERCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour un noeud représentant une bribe de texte à retrouver. */
+G_DEFINE_TYPE(GScanTokenNodePlain, g_scan_token_node_plain, G_TYPE_SCAN_TOKEN_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des noeuds pour motif textuel. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_plain_class_init(GScanTokenNodePlainClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenNodeClass *node; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_node_plain_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_node_plain_finalize;
+
+ node = G_SCAN_TOKEN_NODE_CLASS(klass);
+
+ node->compute_weight = (compute_scan_token_node_weight_fc)g_scan_token_node_plain_compute_weight_for_scan;
+ node->apply = (apply_scan_token_node_flags_fc)NULL;
+ node->visit = (visit_scan_token_node_fc)g_scan_token_node_plain_visit;
+ node->enroll = (enroll_scan_token_node_fc)g_scan_token_node_plain_enroll;
+ node->build_id = (build_scan_token_node_id_fc)g_scan_token_node_plain_build_id;
+ node->check_forward = (check_scan_token_node_fc)g_scan_token_node_plain_check_forward;
+ node->check_backward = (check_scan_token_node_fc)g_scan_token_node_plain_check_backward;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plain = instance à initialiser. *
+* *
+* Description : Initialise une instance de noeud pour motif textuel. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_plain_init(GScanTokenNodePlain *plain)
+{
+ init_szstr(&plain->orig);
+ plain->modifier = NULL;
+ plain->flags = SPNF_NONE;
+
+ plain->raw = NULL;
+ plain->atoms = NULL;
+ plain->count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plain = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_plain_dispose(GScanTokenNodePlain *plain)
+{
+ g_clear_object(&plain->modifier);
+
+ G_OBJECT_CLASS(g_scan_token_node_plain_parent_class)->dispose(G_OBJECT(plain));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plain = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_plain_finalize(GScanTokenNodePlain *plain)
+{
+ size_t i; /* Boucle de parcours */
+
+ exit_szstr(&plain->orig);
+
+ for (i = 0; i < plain->count; i++)
+ exit_szstr(&plain->raw[i]);
+
+ if (plain->raw != NULL)
+ free(plain->raw);
+
+ if (plain->atoms != NULL)
+ free(plain->atoms);
+
+ G_OBJECT_CLASS(g_scan_token_node_plain_parent_class)->finalize(G_OBJECT(plain));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : text = texte brut à rechercher. *
+* modifier = transformateur éventuel à solliciter. *
+* flags = particularités à prendre en considération. *
+* *
+* Description : Construit un noeud représentant un motif textuel. *
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenNode *g_scan_token_node_plain_new(const sized_binary_t *text, GScanTokenModifier *modifier, ScanPlainNodeFlags flags)
+{
+ GScanTokenNode *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_TOKEN_NODE_PLAIN, NULL);
+
+ if (!g_scan_token_node_plain_create(G_SCAN_TOKEN_NODE_PLAIN(result), text, modifier, flags))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plain = encadrement de motif à initialiser pleinement. *
+* text = texte brut à rechercher. *
+* modifier = transformateur éventuel à solliciter. *
+* flags = particularités à prendre en considération. *
+* *
+* Description : Met en place un noeud représentant un motif textuel. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_plain_create(GScanTokenNodePlain *plain, const sized_binary_t *text, GScanTokenModifier *modifier, ScanPlainNodeFlags flags)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ szstrdup(&plain->orig, text);
+
+ if (modifier != NULL)
+ {
+ plain->modifier = modifier;
+ g_object_ref(G_OBJECT(modifier));
+ }
+
+ plain->flags = flags;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plain = noeud de motif textuel à consulter. *
+* *
+* Description : Indique les propriétés particulières d'un noeud de texte. *
+* *
+* Retour : Propriétés particulières associées au noeud. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+ScanPlainNodeFlags g_scan_token_node_plain_get_flags(const GScanTokenNodePlain *plain)
+{
+ ScanPlainNodeFlags result; /* Statut à retourner */
+
+ result = plain->flags;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à consulter. *
+* index = indice de la combinaison de modificateurs ciblée. *
+* *
+* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
+* *
+* Retour : Version humainement lisible de la combinaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *g_scan_token_node_plain_get_modifier_path(const GScanTokenNodePlain *node, size_t index)
+{
+ char *result; /* Combinaison à retourner */
+
+ if (node->modifier == NULL)
+ result = strdup("plain");
+
+ else
+ result = g_scan_token_modifier_get_path(node->modifier, (size_t []){ index });
+
+ return result;
+
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à consulter. *
+* *
+* Description : Communique l'intérêt d'un noeud au sein d'une analyse. *
+* *
+* Retour : Poids de l'importance pour un départ de scan. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static float g_scan_token_node_plain_compute_weight_for_scan(const GScanTokenNodePlain *node)
+{
+ float result; /* Valeur à retourner */
+
+ result = node->orig.len;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = point de départ du parcours à effectuer. *
+* points = points capitaux de l'arborescence. [OUT] *
+* *
+* Description : Parcourt une arborescence de noeuds et y relève des éléments.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_plain_visit(GScanTokenNodePlain *node, scan_tree_points_t *points)
+{
+ GScanTokenNode *candidate; /* Autre version du noeud */
+ float node_weight; /* Poids du noeud courant */
+ float other_weight; /* Poids de l'autre noeud */
+
+ if (points->first_plain == NULL)
+ points->first_plain = G_SCAN_TOKEN_NODE(node);
+
+ else
+ {
+ candidate = G_SCAN_TOKEN_NODE(node);
+
+ node_weight = g_scan_token_node_compute_weight_for_scan(candidate);
+ other_weight = g_scan_token_node_compute_weight_for_scan(points->first_plain);
+
+ if (node_weight >= other_weight)
+ points->first_plain = candidate;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* context = contexte de l'analyse à mener. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_plain_enroll(GScanTokenNodePlain *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours #1 */
+ tracked_scan_atom_t atom; /* Atome identifié */
+ size_t letters; /* Nombre de lettres présentes */
+ size_t k; /* Boucle de parcours #2 */
+ size_t extra_count; /* Quantité pour l'exhaustivité*/
+ sized_binary_t *extra; /* Couverture supplémntaire */
+ size_t remaining; /* Quantité restant à traiter */
+
+ /* Génération d'une base de chaînes à couvrir */
+
+ if (node->modifier == NULL)
+ {
+ node->raw = malloc(sizeof(sized_binary_t));
+ node->count = 1;
+
+ szstrdup(&node->raw[0], &node->orig);
+
+ result = true;
+
+ }
+ else
+ result = g_scan_token_modifier_transform(node->modifier, &node->orig, 1, &node->raw, &node->count);
+
+ if (!result)
+ goto exit;
+
+ /* Préparation pour la mémorisation des atomes */
+
+ node->atoms = malloc(node->count * sizeof(tracked_scan_atom_t));
+
+ /* Validation du besoin effectif dans les cas extrèmes */
+
+
+
+ // TODO : if (orig.len < ...)
+
+
+
+ /* Recherche des atomes */
+
+ for (i = 0; i < node->count; i++)
+ {
+ if (node->flags & SPNF_CASE_INSENSITIVE)
+ {
+ find_best_atom(&node->raw[i], maxsize, &atom, &letters);
+
+ if (letters == 0)
+ node->atoms[i] = atom;
+
+ /* Insertion des nouvelles combinaisons pour couvrir toutes les casses */
+ else
+ {
+ /* extra_count = 2^letters */
+ for (k = 1, extra_count = 2; k < letters; k++, extra_count *= 2)
+ ;
+
+ extra = make_atoms_case_insensitive(&node->raw[i], &atom, extra_count);
+
+ remaining = node->count - i - 1;
+
+ node->count += (extra_count - 1);
+
+ node->raw = realloc(node->raw, node->count * sizeof(sized_binary_t));
+
+ memmove(&node->raw[i + extra_count], &node->raw[i + 1], remaining * sizeof(sized_binary_t));
+
+ for (k = 0; k < extra_count; k++)
+ node->raw[i + k] = extra[k];
+
+ free(extra);
+
+ node->atoms = realloc(node->atoms, node->count * sizeof(tracked_scan_atom_t));
+
+ for (k = 0; k < extra_count; k++)
+ node->atoms[i + k] = atom;
+
+ i += extra_count - 1;
+
+ }
+
+ }
+
+ else
+ find_best_atom(&node->raw[i], maxsize, &node->atoms[i], &letters);
+
+ }
+
+ /* Enregistrements en masse */
+
+ for (i = 0; i < node->count && result; i++)
+ result = enroll_prepared_atom(&node->raw[i], backend, &node->atoms[i]);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_plain_build_id(GScanTokenNodePlain *node, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours #1 */
+
+ result = true;
+
+ for (i = 0; i < node->count && result; i++)
+ result = build_atom_pattern_id(&node->atoms[i], backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : raw = contneu brut à retrouver idéalement. *
+* atom = contenu brut représentatif ciblé. *
+* nocase = marque un éventuel désintérêt pour la casse. *
+* start = point d'analyse à respecter. *
+* content = accès au contenu brut pour vérifications (optim.) *
+* *
+* Description : Détermine si un contenu d'intérêt est présent à une position.*
+* *
+* Retour : Bilan de l'analyse : true pour une correspondance. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool check_scan_token_node_plain_content(const sized_binary_t *raw, const tracked_scan_atom_t *atom, bool nocase, phys_t start, GBinContent *content)
+{
+ bool result; /* Bilan à retourner */
+ vmpa2t pos; /* Position dans les données */
+ const bin_t *ptr; /* Accès aux données brutes */
+ int ret; /* Bilan d'une comparaison */
+
+ result = false;
+
+ init_vmpa(&pos, start, VMPA_NO_VIRTUAL);
+
+ /* Validation du motif intégral */
+
+ if (atom == NULL)
+ {
+ ptr = g_binary_content_get_raw_access(content, &pos, raw->len);
+
+ /**
+ * Si la partion atomique recherchée est trouvée en début de contenu,
+ * le reste du motif de recherche va déborder. L'accès correspondant
+ * est donc refusé, et cette situation est prise en compte ici.
+ */
+ if (ptr == NULL) goto done;
+
+ if (nocase)
+ ret = memcasecmp(raw->data, ptr, raw->len);
+ else
+ ret = memcmp(raw->data, ptr, raw->len);
+
+ result = (ret == 0);
+
+ }
+
+ /* Validation des extrémités */
+
+ else
+ {
+ /* Validation du contenu avant l'atome */
+
+ if (atom->pos > 0)
+ {
+ ptr = g_binary_content_get_raw_access(content, &pos, atom->pos);
+
+ /**
+ * Si la partion atomique recherchée est trouvée en début de contenu,
+ * le reste du motif de recherche va déborder. L'accès correspondant
+ * est donc refusé, et cette situation est prise en compte ici.
+ */
+ if (ptr == NULL) goto done;
+
+ if (nocase)
+ ret = memcasecmp(raw->data, ptr, atom->pos);
+ else
+ ret = memcmp(raw->data, ptr, atom->pos);
+
+ if (ret != 0) goto done;
+
+ }
+
+ /* Validation du contenu après l'atome */
+
+ if (atom->rem > 0)
+ {
+ advance_vmpa(&pos, atom->len);
+
+ ptr = g_binary_content_get_raw_access(content, &pos, atom->rem);
+
+ /**
+ * Si la partion atomique recherchée est trouvée en fin de contenu,
+ * le reste du motif de recherche va déborder. L'accès correspondant
+ * est donc refusé, et cette situation est prise en compte ici.
+ */
+ if (ptr == NULL) goto done;
+
+ if (nocase)
+ ret = memcasecmp(raw->data + atom->pos + atom->len, ptr, atom->rem);
+ else
+ ret = memcmp(raw->data + atom->pos + atom->len, ptr, atom->rem);
+
+ if (ret != 0) goto done;
+
+ }
+
+ result = true;
+
+ }
+
+ done:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_plain_check_forward(const GScanTokenNodePlain *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ bool track_path; /* Conservation du chemin */
+ bool nocase; /* Pas d'intérêt pour la casse */
+ match_area_t **areas; /* Liste de zones à constituer */
+ size_t *count; /* Taille de cette liste */
+ bool copy; /* Besoin d'une copie ? */
+ bool inverted; /* Inversion des bilans ? */
+ size_t i; /* Boucle de parcours #1 */
+ const tracked_scan_atom_t *atom; /* Atome correspondant */
+ match_area_t *atoms; /* Localisations des bribes */
+ bool first_round; /* Premier tour de traitement */
+ match_area_t *area; /* Correspondance à valider */
+ const sized_binary_t *raw; /* Données brutes d'origine */
+ match_area_t *next; /* Correspondance suivante */
+ phys_t start; /* Début potentiel de motif */
+ bool status; /* Bilan d'une correspondance */
+ phys_t after; /* Espace disposible après */
+ phys_t min_end; /* Fin la plus proche possible */
+ phys_t max_end; /* Fin la plus éloignée trouvée*/
+ bool updated; /* Existence de correspondance */
+ size_t rcount; /* Quantité de bornes présentes*/
+ const node_offset_range_t *ranges; /* Bornes d'espace à parcourir */
+ size_t r; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t p; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t updated_edge; /* Nouvelle bordure de motif */
+ match_area_t *new_area; /* Copie de correspondance */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ track_path = (G_SCAN_TOKEN_NODE(node)->flags & STNF_MAIN);
+
+ nocase = (node->flags & SPNF_CASE_INSENSITIVE);
+
+ /**
+ * Création de premières marques de correspondances.
+ */
+ if (!params->initialized)
+ {
+ /* Destinations établies une fois pour toutes */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ areas = &params->kept_areas;
+ count = &params->kept_count;
+
+ copy = false;
+ inverted = true;
+
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ areas = &params->created_areas;
+ count = &params->created_count;
+
+ copy = true;
+ inverted = false;
+
+ }
+
+ else
+ {
+ assert(cflags & TNCF_UPDATE_IN_PLACE);
+
+ areas = &params->main_areas;
+ count = &params->main_count;
+
+ copy = false;
+ inverted = false;
+
+ }
+
+ /* Parcours des combinaisons enregistrées */
+
+ for (i = 0; i < node->count; i++)
+ {
+ atom = &node->atoms[i];
+
+ atoms = g_scan_context_get_atom_matches(params->context, atom->pid);
+
+ first_round = (*count == 0);
+
+ if (atom->fast_check)
+ {
+ /**
+ * Toutes les correspondances sont validées d'office car le motif identifié
+ * correspondant au motif complet.
+ */
+
+ if (!inverted)
+ {
+ for_each_match_area(area, atoms)
+ {
+ /**
+ * La modification de la zone d'origine est possible dans tous les cas
+ * car cette zone a été allouée de façon dédiée à un type de correspondances
+ * et ne sera pas réutilisée comme autre source de correspondance ailleurs.
+ */
+
+ assert(area->end >= atom->len);
+
+ area->start = area->end - atom->len;
+
+ (*count)++;
+
+ }
+
+ }
+
+ else
+ atoms = NULL;
+
+ }
+
+ else
+ {
+ raw = &node->raw[i];
+
+ for_each_match_area_safe(area, &atoms, next)
+ {
+ start = area->end - atom->len - atom->pos;
+
+ status = check_scan_token_node_plain_content(raw, atom, nocase, start, params->content);
+
+ if (status)
+ {
+ /**
+ * La modification de la zone d'origine est possible dans tous les cas
+ * car cette zone a été allouée de façon dédiée à un type de correspondances
+ * et ne sera pas réutilisée comme autre source de correspondance ailleurs.
+ */
+
+ if (!inverted)
+ {
+ area->start = start;
+ area->end += atom->rem;
+
+ (*count)++;
+
+ }
+ else
+ del_match_area(area, &atoms);
+
+ }
+
+ else
+ {
+ /**
+ * Les principes de modifications restent valables, même inversés.
+ */
+ if (inverted)
+ {
+ area->start = start;
+ area->end += atom->rem;
+
+ (*count)++;
+
+ }
+ else
+ del_match_area(area, &atoms);
+
+ }
+
+ }
+
+
+ }
+
+ /* Mise à jour de la liste */
+
+ if (atoms != NULL)
+ {
+ if (first_round)
+ *areas = atoms;
+
+ else
+ merge_match_areas(areas, &atoms);
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Poursuite des traitements sur des correspondances déjà amorcées, impliquant
+ * des comparaisons entières de motifs.
+ */
+ else
+ {
+ if (0x0) printf(" LIST : %p (sz = %zu)\n", params->main_areas, params->main_count);
+
+ for_each_match_area_safe(area, &params->main_areas, next)
+ {
+ assert(area->end <= params->content_end);
+
+ after = params->content_end - area->end;
+
+ if (0x0) printf("---------- iter @ %u -> %u\n", (unsigned int)area->start, (unsigned int)area->end);
+
+ /**
+ * Il ne peut y avoir qu'une seule séquence d'octets à un même
+ * emplacement. En revanche, des modificateurs peuvent construire
+ * possédant une même base, mais offrant des suffixes différents
+ * (par exemple, un marqueur nul UTF-16 final en complément).
+ *
+ * L'ensemble des combinaisons produites doit ainsi être exploré.
+ */
+
+ /**
+ * Par ailleurs, même si une base de couples uniques est assurée,
+ * la constitution d'un ensemble de noeuds peut amener une redondance
+ * dans les emplacements de correspondances ; ces doublons éventuels
+ * sont alors filtrés par un appel à sort_match_areas_no_dup().
+ *
+ * Par exemple, pour la séquence d'octets analysés suivante :
+ *
+ * aaa....bbb
+ *
+ * La définition { (61 61 | 61 61 61) [4-5] 62 62 62 } peut établir
+ * les correspondances suivantes :
+ *
+ * aa.....bbb -> couple pending[x] (0;2) puis (0;10)
+ * ^
+ * aa....bbb -> couple pending[y] (1;3) puis (1;10)
+ * ^
+ * aaa....bbb -> couple pending[z] (0;3) puis (0;10)
+ * ^
+ *
+ * Par ailleurs, une même base de départ peut conduire à plusieurs
+ * zones de correspondances.
+ *
+ * Par exemple, pour la séquence d'octets analysés suivante :
+ *
+ * aa..bb..bb
+ *
+ * La définition { 61 61 [2-6] 62 62 } peut établir
+ * les correspondances suivantes :
+ *
+ * aa..bb..bb -> couple pending[x] (0;2) puis (0;6)
+ * ^
+ * aa..bb..bb -> couple pending[x] (0;2) puis (0;10)
+ * ^
+ */
+
+ /**
+ * Dans la première situation, c'est la bribe 62 62 62 qui fait l'objet
+ * d'une recherche de motifs. Les autres bribes sont recherchées
+ * manuellement ici, car l'espace de séparation est léger (inférieur à
+ * MAX_RANGE_FOR_MANUAL_CHECK).
+ *
+ * La seconde situation bénéficie de recherches automatisées pour
+ * l'ensemble des motifs, du fait d'une valeur de séparation plus
+ * importante.
+ *
+ * Dans les deux cas, l'espace de séparation est entièrement considéré.
+ * La sélection de la correspondance à retour s'établit selon un
+ * paramètre de configuation : doit-on être avare sur les distances
+ * consommées ou non ?
+ */
+
+ min_end = params->content_end;
+ max_end = params->content_start;
+
+ updated = false;
+
+ for (i = 0; i < node->count; i++)
+ {
+ raw = &node->raw[i];
+
+ /* Souplesse dans les positions ? */
+ if (offsets_exist(&params->offset))
+ {
+ ranges = get_node_search_offset_ranges_2(&params->offset, &rcount);
+
+ for (r = 0; r < rcount; r++)
+ {
+ assert(ranges[r].has_max);
+ assert((ranges[r].max - ranges[r].min) <= MAX_RANGE_FOR_MANUAL_CHECK);
+
+ for (p = ranges[r].min; p <= ranges[r].max; p++)
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près de
+ * la fin du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if ((p + raw->len) > after)
+ break;
+
+ status = check_scan_token_node_plain_content(raw, NULL, nocase,
+ area->end + p, params->content);
+
+ if (status)
+ {
+ updated_edge = area->end + p + raw->len;
+
+ if (updated_edge < min_end)
+ min_end = updated_edge;
+
+ if (updated_edge > max_end)
+ max_end = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ /* Position immédiatement attendue */
+ else
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près de
+ * la fin du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if (raw->len > after)
+ continue;
+
+ status = check_scan_token_node_plain_content(raw, NULL, nocase, area->end, params->content);
+
+ if (status)
+ {
+ updated_edge = area->end + raw->len;
+
+ if (updated_edge < min_end)
+ min_end = updated_edge;
+
+ if (updated_edge > max_end)
+ max_end = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ if (updated)
+ {
+ /**
+ * Si seuls les rejets sont d'intérêt, les correspondances établies
+ * ne se voient pas mises à jours ni retirées.
+ */
+
+ if ((cflags & TNCF_KEEP_DISCARDED) == 0)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ area->end = (1 /* greedy */ ? min_end : max_end);
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->end = (1 /* greedy */ ? min_end : max_end);
+
+ add_tail_match_area(new_area, &params->created_areas);
+ params->created_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ else
+ {
+ /**
+ * Si la liste principale doit être mise à jour...
+ */
+
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ del_match_area(area, &params->main_areas);
+ assert(params->main_count > 0);
+ params->main_count--;
+ }
+
+ /**
+ * Au cas où le rejet est d'intérêt, l'absence de correspondance
+ * est conservée dans une liste dédiée.
+ */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ add_tail_match_area(area, &params->kept_areas);
+ params->kept_count++;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->end = (1 /* greedy */ ? min_end : max_end);
+
+ add_tail_match_area(new_area, &params->kept_areas);
+ params->kept_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ }
+
+ }
+
+ params->initialized = true;
+
+ disable_all_ranges_in_node_search_offset(&params->offset);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_plain_check_backward(const GScanTokenNodePlain *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+
+
+
+
+
+ bool track_path; /* Conservation du chemin */
+ bool nocase; /* Pas d'intérêt pour la casse */
+
+
+
+
+ size_t i; /* Boucle de parcours #1 */
+
+
+ const sized_binary_t *raw; /* Données brutes d'origine */
+
+
+ bool status; /* Bilan d'une correspondance */
+
+
+
+
+
+ match_area_t *area; /* Correspondance à valider */
+ match_area_t *next; /* Correspondance suivante */
+ phys_t before; /* Espace disposible avant */
+ phys_t min_start; /* Début le plus proche trouvé */
+ phys_t max_start; /* Début le plus distant trouvé*/
+ bool updated; /* Existence de correspondance */
+ size_t rcount; /* Quantité de bornes présentes*/
+ const node_offset_range_t *ranges; /* Bornes d'espace à parcourir */
+ size_t r; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t p; /* Boucle de parcours #xxxxxxxxxxxx*/
+ phys_t updated_edge; /* Nouvelle bordure de motif */
+ match_area_t *new_area; /* Copie de correspondance */
+
+ if (0x0) printf("=================== CHECK :: %s (skip? %d)\n", __FUNCTION__, *skip);
+
+ if (*skip)
+ return;
+
+ /**
+ * En lecture à rebourd, au moins un noeud a été solicité pour analyse (lors
+ * du sens de lecture normal). Donc l'initialisation a déjà dû avoir lieu.
+ */
+
+ assert(params->initialized);
+
+ track_path = (G_SCAN_TOKEN_NODE(node)->flags & STNF_MAIN);
+
+ nocase = (node->flags & SPNF_CASE_INSENSITIVE);
+
+
+
+ /**
+ * .............
+ */
+ if (0)
+ {
+
+
+ ;
+
+
+
+ }
+
+ /**
+ * Poursuite des traitements sur des correspondances déjà amorcées, impliquant
+ * des comparaisons entières de motifs.
+ */
+ else
+ {
+ if (0x0) printf(" LIST : %p (sz = %zu)\n", params->main_areas, params->main_count);
+
+ for_each_match_area_safe(area, &params->main_areas, next)
+ {
+ assert(params->content_start <= area->start);
+
+ before = area->start - params->content_start;
+
+ if (0x0) printf("---------- iter @ %u -> %u\n", (unsigned int)area->start, (unsigned int)area->end);
+
+ /**
+ * Il ne peut y avoir qu'une seule séquence d'octets à un même
+ * emplacement. En revanche, des modificateurs peuvent construire
+ * possédant une même base, mais offrant des suffixes différents
+ * (par exemple, un marqueur nul UTF-16 final en complément).
+ *
+ * L'ensemble des combinaisons produites doit ainsi être exploré.
+ */
+
+ min_start = params->content_start;
+ max_start = params->content_end;
+
+ updated = false;
+
+ for (i = 0; i < node->count; i++)
+ {
+ raw = &node->raw[i];
+
+ /* Souplesse dans les positions ? */
+ if (offsets_exist(&params->offset))
+ {
+ ranges = get_node_search_offset_ranges_2(&params->offset, &rcount);
+
+ for (r = 0; r < rcount; r++)
+ {
+ assert(ranges[r].has_max);
+ assert((ranges[r].max - ranges[r].min) <= MAX_RANGE_FOR_MANUAL_CHECK);
+
+ for (p = ranges[r].min; p <= ranges[r].max; p++)
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près de
+ * la fin du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if ((p + raw->len) > before)
+ break;
+
+ status = check_scan_token_node_plain_content(raw, NULL, nocase,
+ area->start - raw->len - p,
+ params->content);
+
+ if (status)
+ {
+ updated_edge = area->start - raw->len - p;
+
+ if (updated_edge > min_start)
+ min_start = updated_edge;
+
+ if (updated_edge < max_start)
+ max_start = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ }
+
+ /* Position immédiatement attendue */
+ else
+ {
+ /**
+ * Si la fin d'une correspondance potentielle est trop près du
+ * début du contenu binaire et ne peut contenir le motif
+ * représenté, alors la corresponance est écartée sans appel.
+ */
+ if (raw->len > before)
+ continue;
+
+ status = check_scan_token_node_plain_content(raw, NULL, nocase,
+ area->start - raw->len,
+ params->content);
+
+ if (status)
+ {
+ updated_edge = area->start - raw->len;
+
+ if (updated_edge > min_start)
+ min_start = updated_edge;
+
+ if (updated_edge < max_start)
+ max_start = updated_edge;
+
+ updated = true;
+
+ }
+
+ }
+
+ }
+
+ if (updated)
+ {
+ /**
+ * Si seuls les rejets sont d'intérêt, les correspondances établies
+ * ne se voient pas mises à jours ni retirées.
+ */
+
+ if ((cflags & TNCF_KEEP_DISCARDED) == 0)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ area->start = (1 /* greedy */ ? min_start : max_start);
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->start = (1 /* greedy */ ? min_start : max_start);
+
+ add_tail_match_area(new_area, &params->created_areas);
+ params->created_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ else
+ {
+ /**
+ * Si la liste principale doit être mise à jour...
+ */
+
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ del_match_area(area, &params->main_areas);
+ assert(params->main_count > 0);
+ params->main_count--;
+ }
+
+ /**
+ * Au cas où le rejet est d'intérêt, l'absence de correspondance
+ * est conservée dans une liste dédiée.
+ */
+
+ if (cflags & TNCF_KEEP_DISCARDED)
+ {
+ if (cflags & TNCF_UPDATE_IN_PLACE)
+ {
+ add_tail_match_area(area, &params->kept_areas);
+ params->kept_count++;
+ }
+
+ else if (cflags & TNCF_CREATE_NEW)
+ {
+ new_area = g_umem_slice_alloc(params->allocator);
+
+ *new_area = *area;
+
+ new_area->start = (1 /* greedy */ ? min_start : max_start);
+
+ add_tail_match_area(new_area, &params->kept_areas);
+ params->kept_count++;
+
+ }
+
+#ifndef NDEBUG
+ else
+ assert(false);
+#endif
+
+ }
+
+ }
+
+ }
+
+ }
+
+ disable_all_ranges_in_node_search_offset(&params->offset);
+
+}
diff --git a/src/analysis/scan/patterns/tokens/nodes/plain.h b/src/analysis/scan/patterns/tokens/nodes/plain.h
new file mode 100644
index 0000000..abf71de
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/plain.h
@@ -0,0 +1,83 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain.h - prototypes pour la gestion d'une recherche de motif textuel
+ *
+ * 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_PATTERNS_TOKENS_NODES_PLAIN_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_PLAIN_H
+
+
+#include <glib-object.h>
+
+
+#include "../node.h"
+#include "../../modifier.h"
+#include "../../../../../common/szstr.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_NODE_PLAIN g_scan_token_node_plain_get_type()
+#define G_SCAN_TOKEN_NODE_PLAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_NODE_PLAIN, GScanTokenNodePlain))
+#define G_IS_SCAN_TOKEN_NODE_PLAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_NODE_PLAIN))
+#define G_SCAN_TOKEN_NODE_PLAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_NODE_PLAIN, GScanTokenNodePlainClass))
+#define G_IS_SCAN_TOKEN_NODE_PLAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_NODE_PLAIN))
+#define G_SCAN_TOKEN_NODE_PLAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_NODE_PLAIN, GScanTokenNodePlainClass))
+
+
+/* Bribe de motif textuelle pour recherches (instance) */
+typedef struct _GScanTokenNodePlain GScanTokenNodePlain;
+
+/* Bribe de motif textuelle pour recherches (classe) */
+typedef struct _GScanTokenNodePlainClass GScanTokenNodePlainClass;
+
+
+/* Propriétés d'un élément textuel à rechercher */
+typedef enum _ScanPlainNodeFlags
+{
+ SPNF_NONE = (0 << 0), /* Aucune particularité */
+ SPNF_CASE_INSENSITIVE = (1 << 0), /* Ignorance de la casse */
+
+ /**
+ * Les deux propriétés suivantes sont récupérées et traitées
+ * au niveau du Token propriétaire.
+ */
+
+ SPNF_FULLWORD = (1 << 1), /* Recherche de mot entier */
+ SPNF_PRIVATE = (1 << 2), /* Marque privative */
+
+} ScanPlainNodeFlags;
+
+
+/* Indique le type défini pour un noeud représentant une bribe de texte à retrouver. */
+GType g_scan_token_node_plain_get_type(void);
+
+/* Construit un noeud représentant un motif textuel. */
+GScanTokenNode *g_scan_token_node_plain_new(const sized_binary_t *, GScanTokenModifier *, ScanPlainNodeFlags);
+
+/* Indique les propriétés particulières d'un noeud de texte. */
+ScanPlainNodeFlags g_scan_token_node_plain_get_flags(const GScanTokenNodePlain *);
+
+/* Retrouve l'origine d'une correspondance à partir d'un indice. */
+char *g_scan_token_node_plain_get_modifier_path(const GScanTokenNodePlain *, size_t);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_PLAIN_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/sequence-int.h b/src/analysis/scan/patterns/tokens/nodes/sequence-int.h
new file mode 100644
index 0000000..f0ea6ae
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/sequence-int.h
@@ -0,0 +1,58 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * sequence-int.h - prototypes internes pour des décompositions séquentielles de motif de recherche
+ *
+ * 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_PATTERNS_TOKENS_NODES_SEQUENCE_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_SEQUENCE_INT_H
+
+
+#include "sequence.h"
+
+
+#include "../node-int.h"
+
+
+
+/* Décompositions séquentielles de motif de recherche (instance) */
+struct _GScanTokenNodeSequence
+{
+ GScanTokenNode parent; /* A laisser en premier */
+
+ GScanTokenNode **children; /* Sous-noeuds à représenter */
+ size_t count; /* Taille de cette liste */
+
+};
+
+/* Décompositions séquentielles de motif de recherche (classe) */
+struct _GScanTokenNodeSequenceClass
+{
+ GScanTokenNodeClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place une série de décompositions séquentielles. */
+bool g_scan_token_node_sequence_create(GScanTokenNodeSequence *, GScanTokenNode *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_SEQUENCE_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/nodes/sequence.c b/src/analysis/scan/patterns/tokens/nodes/sequence.c
new file mode 100644
index 0000000..394c877
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/sequence.c
@@ -0,0 +1,504 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * sequence.c - décompositions séquentielles de motif de recherche
+ *
+ * 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 "sequence.h"
+
+
+#include <assert.h>
+
+
+#include "any.h"
+#include "sequence-int.h"
+
+
+
+/* ------------------------ DECOMPOSITION DE MOTIF RECHERCHE ------------------------ */
+
+
+/* Initialise la classe des décompositions séquentielles. */
+static void g_scan_token_node_sequence_class_init(GScanTokenNodeSequenceClass *);
+
+/* Initialise une instance de décompositions séquentielles. */
+static void g_scan_token_node_sequence_init(GScanTokenNodeSequence *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_token_node_sequence_dispose(GScanTokenNodeSequence *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_token_node_sequence_finalize(GScanTokenNodeSequence *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Prend acte d'une nouvelle propriété pour le noeud. */
+static void g_scan_token_node_sequence_apply_flags(GScanTokenNodeSequence *, ScanTokenNodeFlags);
+
+/* Parcourt une arborescence de noeuds et y relève des éléments. */
+static void g_scan_token_node_sequence_visit(GScanTokenNodeSequence *node, scan_tree_points_t *);
+
+/* Inscrit la définition d'un motif dans un moteur de recherche. */
+static bool g_scan_token_node_sequence_enroll(GScanTokenNodeSequence *, GEngineBackend *, size_t, size_t *);
+
+/* Récupère un identifiant final pour un atome d'octets. */
+static bool g_scan_token_node_sequence_build_id(GScanTokenNodeSequence *, GEngineBackend *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_sequence_check_forward(const GScanTokenNodeSequence *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+/* Transforme les correspondances locales en trouvailles. */
+static void g_scan_token_node_sequence_check_backward(const GScanTokenNodeSequence *, scan_node_check_params_t *, TokenNodeCheckFlags, bool *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DECOMPOSITION DE MOTIF RECHERCHE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour des décompositions séquentielles de motif de recherche. */
+G_DEFINE_TYPE(GScanTokenNodeSequence, g_scan_token_node_sequence, G_TYPE_SCAN_TOKEN_NODE);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des décompositions séquentielles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_class_init(GScanTokenNodeSequenceClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GScanTokenNodeClass *node; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_token_node_sequence_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_token_node_sequence_finalize;
+
+ node = G_SCAN_TOKEN_NODE_CLASS(klass);
+
+ node->apply = (apply_scan_token_node_flags_fc)g_scan_token_node_sequence_apply_flags;
+ node->visit = (visit_scan_token_node_fc)g_scan_token_node_sequence_visit;
+ node->enroll = (enroll_scan_token_node_fc)g_scan_token_node_sequence_enroll;
+ node->build_id = (build_scan_token_node_id_fc)g_scan_token_node_sequence_build_id;
+ node->check_forward = (check_scan_token_node_fc)g_scan_token_node_sequence_check_forward;
+ node->check_backward = (check_scan_token_node_fc)g_scan_token_node_sequence_check_backward;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : sequence = instance à initialiser. *
+* *
+* Description : Initialise une instance de décompositions séquentielles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_init(GScanTokenNodeSequence *sequence)
+{
+ sequence->children = NULL;
+ sequence->count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : sequence = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_dispose(GScanTokenNodeSequence *sequence)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < sequence->count; i++)
+ g_clear_object(&sequence->children[i]);
+
+ G_OBJECT_CLASS(g_scan_token_node_sequence_parent_class)->dispose(G_OBJECT(sequence));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : sequence = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_finalize(GScanTokenNodeSequence *sequence)
+{
+ if (sequence->children != NULL)
+ free(sequence->children);
+
+ G_OBJECT_CLASS(g_scan_token_node_sequence_parent_class)->finalize(G_OBJECT(sequence));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : child = noeud dont les résultats sont à écarter. *
+* *
+* Description : Construit une série de décompositions séquentielles de motif.*
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenNode *g_scan_token_node_sequence_new(GScanTokenNode *child)
+{
+ GScanTokenNode *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_TOKEN_NODE_SEQUENCE, NULL);
+
+ if (!g_scan_token_node_sequence_create(G_SCAN_TOKEN_NODE_SEQUENCE(result), child))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : sequence = décompositions à initialiser pleinement. *
+* child = noeud dont les résultats sont à écarter. *
+* *
+* Description : Met en place une série de décompositions séquentielles. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_token_node_sequence_create(GScanTokenNodeSequence *sequence, GScanTokenNode *child)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ g_scan_token_node_sequence_add(sequence, child);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : sequence = ensemble de noeuds à compléter. *
+* child = nouveau noeud à intégrer. *
+* *
+* Description : Ajoute un noeud à aux décompositions séquentielles de motif. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_scan_token_node_sequence_add(GScanTokenNodeSequence *sequence, GScanTokenNode *child)
+{
+ bool processed; /* Intégration traitée ? */
+ GScanTokenNode *last; /* Dernier noeud inscrit */
+
+ processed = false;
+
+ if (sequence->count > 0)
+ {
+ last = sequence->children[sequence->count - 1];
+
+ if (G_IS_SCAN_TOKEN_NODE_ANY(last) && G_IS_SCAN_TOKEN_NODE_ANY(child))
+ {
+ g_scan_token_node_any_merge(G_SCAN_TOKEN_NODE_ANY(last), G_SCAN_TOKEN_NODE_ANY(child));
+ processed = true;
+ }
+
+ }
+
+ if (!processed)
+ {
+ sequence->children = realloc(sequence->children, ++sequence->count * sizeof(GScanTokenNode *));
+
+ sequence->children[sequence->count - 1] = child;
+ g_object_ref(G_OBJECT(child));
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : sequence = ensemble de noeuds à consulter. *
+* *
+* Description : Indique le nombre de noeuds intégrés dans la séquence. *
+* *
+* Retour : Nombre de noeuds représentés. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_scan_token_node_sequence_count(const GScanTokenNodeSequence *sequence)
+{
+ size_t result; /* Quantité à retourner */
+
+ result = sequence->count;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : sequence = ensemble de noeuds à consulter. *
+* index = indice du noeud à retourner. *
+* *
+* Description : Fournit un noeud donné d'une décomposition séquentielle. *
+* *
+* Retour : Noeud inclus dans l'ensemble ou NULL si mauvais indice. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GScanTokenNode *g_scan_token_node_sequence_get(const GScanTokenNodeSequence *sequence, size_t index)
+{
+ GScanTokenNode *result; /* Instance à retourner */
+
+ assert(index < sequence->count);
+
+ if (index < sequence->count)
+ {
+ result = sequence->children[index];
+ g_object_ref(G_OBJECT(result));
+ }
+
+ else
+ result = NULL;
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud de motif à mettre à jour. *
+* flags = propriétés particulières à associer au noeud. *
+* *
+* Description : Prend acte d'une nouvelle propriété pour le noeud. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_apply_flags(GScanTokenNodeSequence *node, ScanTokenNodeFlags flags)
+{
+ size_t i; /* Boucle de parcours */
+
+ if (node->count == 1)
+ g_scan_token_node_set_flags(node->children[0], flags);
+
+ else if (node->count > 1)
+ {
+ g_scan_token_node_set_flags(node->children[0], flags & ~STNF_LAST);
+
+ for (i = 1; i < (node->count - 1); i++)
+ g_scan_token_node_set_flags(node->children[i], flags & ~(STNF_FIRST | STNF_LAST));
+
+ g_scan_token_node_set_flags(node->children[node->count - 1], flags & ~STNF_FIRST);
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = point de départ du parcours à effectuer. *
+* points = points capitaux de l'arborescence. [OUT] *
+* *
+* Description : Parcourt une arborescence de noeuds et y relève des éléments.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_visit(GScanTokenNodeSequence *node, scan_tree_points_t *points)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < node->count; i++)
+ g_scan_token_node_visit(node->children[i], points);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à enregistrer. *
+* backend = moteur de recherche à préchauffer. *
+* maxsize = taille max. des atomes (mise en commun optimisée). *
+* slow = niveau de ralentissement induit (0 = idéal). [OUT] *
+* *
+* Description : Inscrit la définition d'un motif dans un moteur de recherche.*
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_sequence_enroll(GScanTokenNodeSequence *node, GEngineBackend *backend, size_t maxsize, size_t *slow)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours */
+
+ result = true;
+
+ for (i = 0; i < node->count && result; i++)
+ result = _g_scan_token_node_enroll(node->children[i], backend, maxsize, slow);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à peaufiner. *
+* backend = moteur de recherche à préchauffer. *
+* *
+* Description : Récupère un identifiant final pour un atome d'octets. *
+* *
+* Retour : Bilan de l'opération à renvoyer. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_scan_token_node_sequence_build_id(GScanTokenNodeSequence *node, GEngineBackend *backend)
+{
+ bool result; /* Statut à retourner */
+ size_t i; /* Boucle de parcours #1 */
+
+ result = true;
+
+ for (i = 0; i < node->count && result; i++)
+ result = g_scan_token_node_build_id(node->children[i], backend);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_check_forward(const GScanTokenNodeSequence *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < node->count; i++)
+ _g_scan_token_node_check_forward(node->children[i], params, cflags, skip);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = définition de la bribe à manipuler. *
+* params = accès direct aux éléments utiles aux validations. *
+* cflags = altérations de traitement à respecter. *
+* skip = détermine si l'analyse est différée. [OUT] *
+* *
+* Description : Transforme les correspondances locales en trouvailles. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_token_node_sequence_check_backward(const GScanTokenNodeSequence *node, scan_node_check_params_t *params, TokenNodeCheckFlags cflags, bool *skip)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = node->count; i > 0 ; i--)
+ _g_scan_token_node_check_backward(node->children[i - 1], params, cflags, skip);
+
+}
diff --git a/src/analysis/scan/patterns/tokens/nodes/sequence.h b/src/analysis/scan/patterns/tokens/nodes/sequence.h
new file mode 100644
index 0000000..12df9d1
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/nodes/sequence.h
@@ -0,0 +1,67 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * sequence.h - prototypes pour des décompositions séquentielles de motif de recherche
+ *
+ * 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_PATTERNS_TOKENS_NODES_SEQUENCE_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_SEQUENCE_H
+
+
+#include <glib-object.h>
+
+
+#include "../node.h"
+
+
+
+#define G_TYPE_SCAN_TOKEN_NODE_SEQUENCE g_scan_token_node_sequence_get_type()
+#define G_SCAN_TOKEN_NODE_SEQUENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_TOKEN_NODE_SEQUENCE, GScanTokenNodeSequence))
+#define G_IS_SCAN_TOKEN_NODE_SEQUENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_TOKEN_NODE_SEQUENCE))
+#define G_SCAN_TOKEN_NODE_SEQUENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_TOKEN_NODE_SEQUENCE, GScanTokenNodeSequenceClass))
+#define G_IS_SCAN_TOKEN_NODE_SEQUENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_TOKEN_NODE_SEQUENCE))
+#define G_SCAN_TOKEN_NODE_SEQUENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_TOKEN_NODE_SEQUENCE, GScanTokenNodeSequenceClass))
+
+
+/* Décompositions séquentielles de motif de recherche (instance) */
+typedef struct _GScanTokenNodeSequence GScanTokenNodeSequence;
+
+/* Décompositions séquentielles de motif de recherche (classe) */
+typedef struct _GScanTokenNodeSequenceClass GScanTokenNodeSequenceClass;
+
+
+/* Indique le type défini pour des décompositions séquentielles de motif de recherche. */
+GType g_scan_token_node_sequence_get_type(void);
+
+/* Construit une série de décompositions séquentielles de motif. */
+GScanTokenNode *g_scan_token_node_sequence_new(GScanTokenNode *);
+
+/* Ajoute un noeud à aux décompositions séquentielles de motif. */
+void g_scan_token_node_sequence_add(GScanTokenNodeSequence *, GScanTokenNode *);
+
+/* Indique le nombre de noeuds intégrés dans la séquence. */
+size_t g_scan_token_node_sequence_count(const GScanTokenNodeSequence *);
+
+/* Fournit un noeud donné d'une décomposition séquentielle. */
+GScanTokenNode *g_scan_token_node_sequence_get(const GScanTokenNodeSequence *, size_t);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_NODES_SEQUENCE_H */
diff --git a/src/analysis/scan/patterns/tokens/offset.c b/src/analysis/scan/patterns/tokens/offset.c
new file mode 100644
index 0000000..0a4fd91
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/offset.c
@@ -0,0 +1,438 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * offset.c - décomposition d'un motif de recherche en atomes assemblés
+ *
+ * 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 "offset.h"
+
+
+#include <assert.h>
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : range = bornes décrivant un espace quelconque. *
+* available = espace restant disponible. *
+* min = point de départ pour parcourir une zone. [OUT] *
+* max = point d'arrivée pour parcourir une zone. [OUT] *
+* *
+* Description : Fournit les bornes d'une zone à analyser. *
+* *
+* Retour : true si assez d'espace est disponible, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool get_node_offset_range(const node_offset_range_t *range, phys_t len, phys_t available, phys_t *min, phys_t *max)
+{
+ bool result; /* Bilan à retourner */
+
+ if ((len + range->min) > available)
+ result = false;
+
+ else
+ {
+ result = true;
+
+ *min = range->min;
+ *max = range->max;
+
+ if ((len + *max) > available)
+ {
+ *max = available - len;
+ assert(*max >= *min);
+ }
+
+ }
+
+ return result;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = suivi de tolérances bornées à initialiser. *
+* *
+* Description : Initialise une mémorisation d'intervales de tolérance. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void init_node_search_offset(node_search_offset_t *offset)
+{
+ offset->ranges = NULL;
+ offset->allocated = 0;
+
+ offset->gen_ptr = NULL;
+
+ offset->used = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : dest = suivi de tolérances bornées à initialiser. [OUT] *
+* src = suivi de tolérances bornées à copier. *
+* *
+* Description : Copie une mémorisation d'intervales entre positions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void copy_node_search_offset(node_search_offset_t *dest, const node_search_offset_t *src)
+{
+ init_node_search_offset(dest);
+
+ switch (src->used)
+ {
+ case 0:
+ dest->gen_ptr = NULL;
+ break;
+
+ case 1:
+ dest->range = src->range;
+ dest->gen_ptr = &dest->range;
+ break;
+
+ default:
+ dest->ranges = malloc(src->used * sizeof(node_offset_range_t));
+ memcpy(dest->ranges, src->ranges, src->used * sizeof(node_offset_range_t));
+ dest->gen_ptr = dest->ranges;;
+ break;
+
+ }
+
+ dest->used = src->used;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : dest = suivi de tolérances bornées à initialiser. [OUT] *
+* src = suivi de tolérances bornées à copier. *
+* *
+* Description : Fusionne une mémorisation d'intervales entre positions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void merge_node_search_offset(node_search_offset_t *dest, const node_search_offset_t *src)
+{
+ node_offset_range_t * const *list; /* Liste d'intervales à copier */
+ size_t i; /* Boucle de parcours */
+
+ if ((dest->used + src->used) > 1 && (dest->used + src->used) > dest->allocated)
+ {
+ dest->allocated += src->used;
+
+ dest->ranges = realloc(dest->ranges, dest->allocated * sizeof(node_offset_range_t));
+
+ }
+
+ list = get_node_search_offset_ranges(src, (size_t []){ 0 });
+
+ for (i = 0; i < src->used; i++)
+ add_range_to_node_search_offset(dest, (*list)[i].min, (*list)[i].max, NULL);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = suivi de tolérances bornées à terminer. *
+* *
+* Description : Met fin à une mémorisation d'intervales de tolérance. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void exit_node_search_offset(node_search_offset_t *offset)
+{
+ if (offset->ranges != NULL)
+ free(offset->ranges);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = suivi de tolérances bornées à consulter. *
+* count = nombre de bornes enregistrées. [OUT] *
+* *
+* Description : Fournit la liste des tolérances bornées établies à présent. *
+* *
+* Retour : Liste d'intervales en lecture seule. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+node_offset_range_t * const *get_node_search_offset_ranges(const node_search_offset_t *offset, size_t *count)
+{
+ node_offset_range_t * const *result; /* Série à renvoyer */
+
+ result = &offset->gen_ptr;
+
+ *count = offset->used;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = suivi de tolérances bornées à consulter. *
+* count = nombre de bornes enregistrées. [OUT] *
+* *
+* Description : Fournit la liste des tolérances bornées établies à présent. *
+* *
+* Retour : Liste d'intervales en lecture seule. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const node_offset_range_t * const get_node_search_offset_ranges_2(const node_search_offset_t *offset, size_t *count)
+{
+ node_offset_range_t *result; /* Série à renvoyer */
+
+ result = offset->gen_ptr;
+
+ *count = offset->used;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = suivi de tolérances bornées à consulter. *
+* min = point de départ pour parcourir une zone. *
+* max = point d'arrivée pour parcourir une zone. *
+* datasize = taille maximale pour définir une inversion NOT. *
+* *
+* Description : Ajoute un nouvel espace borné aux décalages tolérés. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void add_range_to_node_search_offset(node_search_offset_t *offset, phys_t min, phys_t max, const phys_t *datasize)
+{
+ bool not; /* Traduction de la taille */
+ size_t needed; /* Nombre d'emplacements requis*/
+
+ not = (datasize != NULL);
+
+ /* Si le réceptacle unique peut être employé... */
+ if (offset->used == 0 && !not)
+ {
+ offset->range.min = min;
+ offset->range.max = max;
+
+ offset->used = 1;
+
+ offset->gen_ptr = &offset->range;
+
+ }
+
+ /* Sinon le groupe dynamique est sollicité */
+ else
+ {
+ needed = offset->used + (not ? 2 : 1);
+
+ if (needed > offset->allocated)
+ {
+ offset->ranges = realloc(offset->ranges, needed * sizeof(node_offset_range_t));
+ offset->allocated = needed;
+ }
+
+ /* Bascule d'un éventuel intervale courant */
+ if (offset->used == 1)
+ {
+ offset->ranges[0].min = offset->range.min;
+ offset->ranges[0].max = offset->range.max;
+ }
+
+ if (not)
+ {
+ if (min > 0)
+ {
+ offset->ranges[offset->used].min = 0;
+ offset->ranges[offset->used].max = min - 1;
+
+ offset->used++;
+
+ }
+
+ if ((max + 1) < *datasize)
+ {
+ offset->ranges[offset->used].min = max + 1;
+ offset->ranges[offset->used].max = *datasize - (max + 1);
+
+ offset->used++;
+
+ }
+
+ }
+ else
+ {
+ offset->ranges[offset->used].min = min;
+ offset->ranges[offset->used].max = max;
+
+ offset->used++;
+
+ }
+
+ offset->gen_ptr = offset->ranges;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = suivi de tolérances bornées à consulter. *
+* min = point de départ pour parcourir une zone. *
+* max = point d'arrivée pour parcourir une zone. *
+* has_max = validité de la valeur maximale transmise. *
+* *
+* Description : Etend les décalages tolérés avec un nouvel espace. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void extend_node_search_offset(node_search_offset_t *offset, phys_t min, phys_t max, bool has_max)
+{
+ size_t i; /* Boucle de parcours */
+
+ switch (offset->used)
+ {
+ /* Si le réceptacle unique peut être employé... */
+ case 0:
+
+ offset->range.min = min;
+ offset->range.max = max;
+ offset->range.has_max = has_max;
+
+ offset->used = 1;
+
+ offset->gen_ptr = &offset->range;
+
+ break;
+
+ /* Si un espace unique est enregistré */
+ case 1:
+
+ offset->range.min += min;
+ offset->range.max += max;
+ offset->range.has_max &= has_max;
+
+ break;
+
+ /* Sinon le groupe dynamique est sollicité */
+ default:
+
+ for (i = 0; i < offset->used; i++)
+ {
+ offset->ranges[i].min += min;
+ offset->ranges[i].max += max;
+ offset->ranges[i].has_max &= has_max;
+ }
+
+ break;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = suivi de tolérances bornées à consulter. *
+* last = dernière position validée. *
+* pos = nouvelle position potentielle. *
+* *
+* Description : Indique si une position est comprise dans un intervale. *
+* *
+* Retour : Bilan de la détermination. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool does_node_search_offset_include_pos_forward(const node_search_offset_t *offset, phys_t last, phys_t pos)
+{
+ bool result; /* Bilan à retourner */
+ size_t i; /* Boucle de parcours */
+ const node_offset_range_t *range; /* Accès rapide aux infos. */
+
+ result = false;
+
+ for (i = 0; i < offset->used; i++)
+ {
+ range = &offset->gen_ptr[i];
+
+ result = ((last + range->min) <= pos && pos <= (last + range->max));
+ if (result) break;
+
+ }
+
+ return result;
+
+}
diff --git a/src/analysis/scan/patterns/tokens/offset.h b/src/analysis/scan/patterns/tokens/offset.h
new file mode 100644
index 0000000..130aaea
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/offset.h
@@ -0,0 +1,111 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * offset.h - prototypes pour la prise en compte des espaces entre octets dans un motif de recherche
+ *
+ * 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_PATTERNS_TOKENS_OFFSET_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_OFFSET_H
+
+
+#include <stdbool.h>
+
+#include "../../../../arch/vmpa.h"
+
+
+
+/* Mémorisation d'une souplesse dans les positions visées */
+typedef struct _node_offset_range_t
+{
+ /**
+ * Les deux champs ci-après font bien référence à des positions absolues,
+ * et non à des bornes d'espace, lorsque les résultats de correspondances
+ * sont encore non initialisés.
+ *
+ * Ensuite ces bornes représentent bien un espace séparant les résultats
+ * issus de deux noeuds.
+ */
+ phys_t min; /* Position minimale */
+ phys_t max; /* Position maximale */
+ bool has_max; /* Quantité définie ? */
+
+} node_offset_range_t;
+
+
+/* Fournit les bornes d'une zone à analyser. */
+bool get_node_offset_range(const node_offset_range_t *, phys_t, phys_t, phys_t *, phys_t *);
+
+
+
+#define MAX_RANGE_FOR_MANUAL_CHECK 5
+
+
+
+/* Mémorisation d'une souplesse dans les positions visées */
+typedef struct _node_search_offset_t
+{
+ node_offset_range_t range; /* Bornes de décalage uniques */
+
+ node_offset_range_t *ranges; /* Bornes de décalage multiples*/
+ size_t allocated; /* Nombre d'allocations */
+
+ node_offset_range_t *gen_ptr; /* Accès générique à la liste */
+
+ size_t used; /* Nombre de bornes présentes */
+
+} node_search_offset_t;
+
+
+/* Initialise une mémorisation d'intervales de tolérance. */
+void init_node_search_offset(node_search_offset_t *);
+
+/* Copie une mémorisation d'intervales entre positions. */
+void copy_node_search_offset(node_search_offset_t *, const node_search_offset_t *);
+
+/* Fusionne une mémorisation d'intervales entre positions. */
+void merge_node_search_offset(node_search_offset_t *, const node_search_offset_t *);
+
+/* Met fin à une mémorisation d'intervales de tolérance. */
+void exit_node_search_offset(node_search_offset_t *);
+
+#define offsets_exist(off) \
+ ((off)->used > 0)
+
+
+/* Fournit la liste des tolérances bornées établies à présent. */
+/* TODO : supprimer un niveau d'indirection */
+node_offset_range_t * const *get_node_search_offset_ranges(const node_search_offset_t *, size_t *);
+const node_offset_range_t * const get_node_search_offset_ranges_2(const node_search_offset_t *, size_t *);
+
+/* Ajoute un nouvel espace borné aux décalages tolérés. */
+void add_range_to_node_search_offset(node_search_offset_t *, phys_t, phys_t, const phys_t *);
+
+/* Etend les décalages tolérés avec un nouvel espace. */
+void extend_node_search_offset(node_search_offset_t *, phys_t, phys_t, bool);
+
+#define disable_all_ranges_in_node_search_offset(off) \
+ (off)->used = 0
+
+/* Indique si une position est comprise dans un intervale. */
+bool does_node_search_offset_include_pos_forward(const node_search_offset_t *, phys_t, phys_t);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_OFFSET_H */
diff --git a/src/analysis/scan/patterns/tokens/plain-int.h b/src/analysis/scan/patterns/tokens/plain-int.h
new file mode 100644
index 0000000..b0ef106
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/plain-int.h
@@ -0,0 +1,56 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain-int.h - prototypes internes pour la recherche d'une chaîne de caractères brute
+ *
+ * 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_PATTERNS_TOKENS_PLAIN_INT_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_PLAIN_INT_H
+
+
+#include "plain.h"
+
+
+#include "atom.h"
+#include "../token-int.h"
+
+
+
+/* Encadrement d'une recherche de texte brut (instance) */
+struct _GScanPlainBytes
+{
+ GBytesToken parent; /* A laisser en premier */
+
+};
+
+/* Encadrement d'une recherche de texte brut (classe) */
+struct _GScanPlainBytesClass
+{
+ GBytesTokenClass parent; /* A laisser en premier */
+
+};
+
+
+/* Met en place un gestionnaire de recherche de texte brut. */
+bool g_scan_plain_bytes_create(GScanPlainBytes *, GScanTokenNode *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_PLAIN_INT_H */
diff --git a/src/analysis/scan/patterns/tokens/plain.c b/src/analysis/scan/patterns/tokens/plain.c
new file mode 100644
index 0000000..3d6c39d
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/plain.c
@@ -0,0 +1,266 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain.c - recherche d'une chaîne de caractères brute
+ *
+ * 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 "plain.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "plain-int.h"
+#include "nodes/plain.h"
+
+
+
+/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */
+
+
+/* Initialise la classe des recherches de texte brut. */
+static void g_scan_plain_bytes_class_init(GScanPlainBytesClass *klass);
+
+/* Initialise une instance de recherche de texte brut. */
+static void g_scan_plain_bytes_init(GScanPlainBytes *);
+
+/* Supprime toutes les références externes. */
+static void g_scan_plain_bytes_dispose(GScanPlainBytes *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_scan_plain_bytes_finalize(GScanPlainBytes *);
+
+
+
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Affiche un motif de recherche au format texte. */
+static void g_scan_plain_bytes_output_to_text(const GScanPlainBytes *, GScanContext *, int);
+
+/* Affiche un motif de recherche au format JSON. */
+static void g_scan_plain_bytes_output_to_json(const GScanPlainBytes *, GScanContext *, const sized_string_t *, unsigned int, int);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RECHERCHE D'UN MOTIF DE TEXTE BRUT */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une suite d'octets à retrouver dans un binaire. */
+G_DEFINE_TYPE(GScanPlainBytes, g_scan_plain_bytes, G_TYPE_BYTES_TOKEN);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des recherches de texte brut. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_bytes_class_init(GScanPlainBytesClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GSearchPatternClass *pattern; /* Version de classe ancêtre */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_plain_bytes_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_plain_bytes_finalize;
+
+ pattern = G_SEARCH_PATTERN_CLASS(klass);
+
+ pattern->to_text = (output_pattern_to_text_fc)g_scan_plain_bytes_output_to_text;
+ pattern->to_json = (output_pattern_to_json_fc)g_scan_plain_bytes_output_to_json;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = instance à initialiser. *
+* *
+* Description : Initialise une instance de recherche de texte brut. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_bytes_init(GScanPlainBytes *bytes)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_bytes_dispose(GScanPlainBytes *bytes)
+{
+ G_OBJECT_CLASS(g_scan_plain_bytes_parent_class)->dispose(G_OBJECT(bytes));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_bytes_finalize(GScanPlainBytes *bytes)
+{
+ G_OBJECT_CLASS(g_scan_plain_bytes_parent_class)->finalize(G_OBJECT(bytes));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : root = représentation du motif à recherche. *
+* *
+* Description : Construit un gestionnaire de recherche de texte brut. *
+* *
+* Retour : Mécanismes mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GSearchPattern *g_scan_plain_bytes_new(GScanTokenNode *root)
+{
+ GSearchPattern *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_PLAIN_BYTES, NULL);
+
+ if (!g_scan_plain_bytes_create(G_SCAN_PLAIN_BYTES(result), root))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bytes = encadrement de motif à initialiser pleinement. *
+* root = représentation du motif à recherche. *
+* *
+* Description : Met en place un gestionnaire de recherche de texte brut. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_plain_bytes_create(GScanPlainBytes *bytes, GScanTokenNode *root)
+{
+ bool result; /* Bilan à retourner */
+ ScanPlainNodeFlags flags; /* Propriétés à interpréter */
+ bool fullword; /* Cible de mots entiers ? */
+ bool private; /* Vocation privée ? */
+
+ flags = g_scan_token_node_plain_get_flags(G_SCAN_TOKEN_NODE_PLAIN(root));
+
+ fullword = (flags & SPNF_FULLWORD);
+ private = (flags & SPNF_PRIVATE);
+
+ result = g_bytes_token_create(G_BYTES_TOKEN(bytes), root, fullword, private);
+
+ return result;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : pattern = définition de motif à considérer. *
+* context = contexte de l'analyse à mener. *
+* fd = canal d'écriture. *
+* *
+* Description : Affiche un motif de recherche au format texte. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_bytes_output_to_text(const GScanPlainBytes *pattern, GScanContext *context, int fd)
+{
+ G_SEARCH_PATTERN_CLASS(g_scan_plain_bytes_parent_class)->to_text(G_SEARCH_PATTERN(pattern), context, fd);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pattern = définition de motif à considérer. *
+* context = contexte de l'analyse à mener. *
+* padding = éventuel bourrage initial à placer ou NULL. *
+* level = profondeur actuelle. *
+* fd = canal d'écriture. *
+* *
+* Description : Affiche un motif de recherche au format JSON. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_scan_plain_bytes_output_to_json(const GScanPlainBytes *pattern, GScanContext *context, const sized_string_t *padding, unsigned int level, int fd)
+{
+ G_SEARCH_PATTERN_CLASS(g_scan_plain_bytes_parent_class)->to_json(G_SEARCH_PATTERN(pattern), context, padding, level, fd);
+
+ /* TODO */
+
+}
diff --git a/src/analysis/scan/patterns/tokens/plain.h b/src/analysis/scan/patterns/tokens/plain.h
new file mode 100644
index 0000000..6ff48d7
--- /dev/null
+++ b/src/analysis/scan/patterns/tokens/plain.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * plain.h - prototypes pour la recherche d'une chaîne de caractères brute
+ *
+ * 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_PATTERNS_TOKENS_PLAIN_H
+#define _ANALYSIS_SCAN_PATTERNS_TOKENS_PLAIN_H
+
+
+#include <glib-object.h>
+
+
+#include "node.h"
+#include "../../pattern.h"
+
+
+
+#define G_TYPE_SCAN_PLAIN_BYTES g_scan_plain_bytes_get_type()
+#define G_SCAN_PLAIN_BYTES(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_PLAIN_BYTES, GScanPlainBytes))
+#define G_IS_SCAN_PLAIN_BYTES(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_PLAIN_BYTES))
+#define G_SCAN_PLAIN_BYTES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_PLAIN_BYTES, GScanPlainBytesClass))
+#define G_IS_SCAN_PLAIN_BYTES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_PLAIN_BYTES))
+#define G_SCAN_PLAIN_BYTES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_PLAIN_BYTES, GScanPlainBytesClass))
+
+
+/* Représentation d'une suite d'octets à retrouver (instance) */
+typedef struct _GScanPlainBytes GScanPlainBytes;
+
+/* Représentation d'une suite d'octets à retrouver (classe) */
+typedef struct _GScanPlainBytesClass GScanPlainBytesClass;
+
+
+/* Indique le type défini pour une suite d'octets à retrouver dans un binaire. */
+GType g_scan_plain_bytes_get_type(void);
+
+/* Construit un gestionnaire de recherche de texte brut. */
+GSearchPattern *g_scan_plain_bytes_new(GScanTokenNode *);
+
+
+
+#endif /* _ANALYSIS_SCAN_PATTERNS_TOKENS_PLAIN_H */