summaryrefslogtreecommitdiff
path: root/src/analysis/scan/matches
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/scan/matches')
-rw-r--r--src/analysis/scan/matches/Makefile.am4
-rw-r--r--src/analysis/scan/matches/area.c57
-rw-r--r--src/analysis/scan/matches/area.h85
-rw-r--r--src/analysis/scan/matches/bytes-int.h31
-rw-r--r--src/analysis/scan/matches/bytes.c595
-rw-r--r--src/analysis/scan/matches/bytes.h58
-rw-r--r--src/analysis/scan/matches/pending.c150
-rw-r--r--src/analysis/scan/matches/pending.h11
8 files changed, 685 insertions, 306 deletions
diff --git a/src/analysis/scan/matches/Makefile.am b/src/analysis/scan/matches/Makefile.am
index d6b51c6..f1a69c3 100644
--- a/src/analysis/scan/matches/Makefile.am
+++ b/src/analysis/scan/matches/Makefile.am
@@ -3,9 +3,9 @@ noinst_LTLIBRARIES = libanalysisscanmatches.la
libanalysisscanmatches_la_SOURCES = \
+ area.h area.c \
bytes-int.h \
- bytes.h bytes.c \
- pending.h pending.c
+ bytes.h bytes.c
libanalysisscanmatches_la_CFLAGS = $(LIBGOBJ_CFLAGS)
diff --git a/src/analysis/scan/matches/area.c b/src/analysis/scan/matches/area.c
new file mode 100644
index 0000000..3f512b0
--- /dev/null
+++ b/src/analysis/scan/matches/area.c
@@ -0,0 +1,57 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * area.c - conservation des localisations de correspondances
+ *
+ * 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 "area.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : a = première zone de correspondance à comparer. *
+* b = seconde zone de correspondance à comparer. *
+* *
+* Description : Etablit une comparaison entre deux zones de correspondance. *
+* *
+* Retour : Bilan de la comparaison. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int compare_match_area_as_dl_item(const dl_list_item *a, const dl_list_item *b)
+{
+ int result; /* Bilan à retourner */
+ match_area_t *area_a; /* Première zone à traiter */
+ match_area_t *area_b; /* Seconde zone à traiter */
+
+ area_a = match_area_from_item(a);
+ area_b = match_area_from_item(b);
+
+ result = sort_uint64_t(area_a->start, area_b->start);
+
+ if (result == 0)
+ result = sort_uint64_t(area_a->end, area_b->end);
+
+ return result;
+
+}
diff --git a/src/analysis/scan/matches/area.h b/src/analysis/scan/matches/area.h
new file mode 100644
index 0000000..b059b35
--- /dev/null
+++ b/src/analysis/scan/matches/area.h
@@ -0,0 +1,85 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * area.h - prototypes pour la conservation des localisations de correspondances
+ *
+ * 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_MATCHES_AREA_H
+#define _ANALYSIS_SCAN_MATCHES_AREA_H
+
+
+#include <assert.h>
+
+
+#include "../../../arch/vmpa.h"
+#include "../../../common/dllist.h"
+
+
+
+/* Couverture d'une correspondance */
+typedef struct _match_area_t
+{
+ phys_t start; /* Point de départ */
+ phys_t end; /* Point d'arrivée (exclus) */
+
+ DL_LIST_ITEM(link); /* Lien vers les maillons */
+
+ size_t mod_path_index; /* Indice de construction */
+ bool has_mod_path; /* Validité du champ précédent */
+
+} match_area_t;
+
+
+#define match_area_from_item(item) \
+ (match_area_t *)container_of(item, match_area_t, link)
+
+#define add_tail_match_area(new, head) \
+ dl_list_add_tail(new, head, match_area_t, link)
+
+#define del_match_area(item, head) \
+ dl_list_del(item, head, match_area_t, link)
+
+#define for_each_match_area(pos, head) \
+ dl_list_for_each(pos, head, match_area_t, link)
+
+#define for_each_match_area_safe(pos, head, next) \
+ dl_list_for_each_safe(pos, head, next, match_area_t, link)
+
+#define is_last_match_area(item, head) \
+ dl_list_is_last(item, head, link)
+
+#define merge_match_areas(head1, head2) \
+ dl_list_merge(head1, head2, match_area_t, link)
+
+#define sort_match_areas_no_dup(head, len, cmp, dup) \
+ ({ \
+ assert(!dl_list_empty(*(head))); \
+ dl_list_item *hmbr = &(*head)->link; \
+ sort_dl_list_no_dup(&hmbr, len, cmp, dup); \
+ match_area_from_item(hmbr); \
+ })
+
+
+/* Etablit une comparaison entre deux zones de correspondance. */
+int compare_match_area_as_dl_item(const dl_list_item *, const dl_list_item *);
+
+
+
+#endif /* _ANALYSIS_SCAN_MATCHES_AREA_H */
diff --git a/src/analysis/scan/matches/bytes-int.h b/src/analysis/scan/matches/bytes-int.h
index f57cb9f..d356208 100644
--- a/src/analysis/scan/matches/bytes-int.h
+++ b/src/analysis/scan/matches/bytes-int.h
@@ -1,6 +1,6 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * bytes-int.h - prototypes internes pour la sauvegarde d'une correspondance identifiée de suite d'octets
+ * bytes-int.h - prototypes internes pour la sauvegarde de correspondances avec des suites d'octets identifiées
*
* Copyright (C) 2022 Cyrille Bagard
*
@@ -28,35 +28,36 @@
#include "bytes.h"
-#include "../match-int.h"
+#include "../matches-int.h"
-/* Correspondance trouvée avec une chaîne (instance) */
-struct _GScanBytesMatch
+/* Correspondances trouvées avec des suite d'octets (instance) */
+struct _GScanBytesMatches
{
- GScanMatch parent; /* A laisser en premier */
+ GScanMatches parent; /* A laisser en premier */
- GBinContent *content; /* Contenu binaire de référence*/
+ GScanContext *context; /* Contexte de rattachement */
- phys_t start; /* Début du motif représenté */
- phys_t len; /* Taille du motif représenté */
+ // TODO : if NDEBUG ?
+ phys_t content_start; /* Point de début du contenu */
+ phys_t content_end; /* Point de fin du contenu */
- size_t mod_path_index; /* Indice de construction */
- bool has_mod_path; /* Validité du champ précédent */
+ match_area_t *areas; /* Zones couvertes */
+ size_t count; /* Nombre de zones */
};
-/* Correspondance trouvée avec une chaîne (classe) */
-struct _GScanBytesMatchClass
+/* Correspondances trouvées avec des suite d'octets (classe) */
+struct _GScanBytesMatchesClass
{
- GScanMatchClass parent; /* A laisser en premier */
+ GScanMatchesClass parent; /* A laisser en premier */
};
-/* Met en place une correspondance trouvée avec un motif. */
-bool g_scan_bytes_match_create(GScanBytesMatch *, GSearchPattern *, GBinContent *, phys_t, phys_t);
+/* Met en place une série de correspondances avec des octets. */
+bool g_scan_bytes_matches_create(GScanBytesMatches *, GSearchPattern *, GScanContext *);
diff --git a/src/analysis/scan/matches/bytes.c b/src/analysis/scan/matches/bytes.c
index f0b97fe..ca8c5b6 100644
--- a/src/analysis/scan/matches/bytes.c
+++ b/src/analysis/scan/matches/bytes.c
@@ -36,20 +36,20 @@
-/* --------------------- CORRESPONDANCE AVEC UNE SUITE D'OCTETS --------------------- */
+/* -------------------- CONSERVATION DE CORRESPONDANCES ETABLIES -------------------- */
-/* Initialise la classe des correspondances de chaînes. */
-static void g_scan_bytes_match_class_init(GScanBytesMatchClass *);
+/* Initialise la classe des séries de correspondances d'octets. */
+static void g_scan_bytes_matches_class_init(GScanBytesMatchesClass *);
-/* Initialise une instance de correspondance de chaîne trouvée. */
-static void g_scan_bytes_match_init(GScanBytesMatch *);
+/* Initialise une instance de série de correspondances trouvées. */
+static void g_scan_bytes_matches_init(GScanBytesMatches *);
/* Supprime toutes les références externes. */
-static void g_scan_bytes_match_dispose(GScanBytesMatch *);
+static void g_scan_bytes_matches_dispose(GScanBytesMatches *);
/* Procède à la libération totale de la mémoire. */
-static void g_scan_bytes_match_finalize(GScanBytesMatch *);
+static void g_scan_bytes_matches_finalize(GScanBytesMatches *);
@@ -57,27 +57,27 @@ static void g_scan_bytes_match_finalize(GScanBytesMatch *);
/* Affiche une correspondance au format texte. */
-static void g_scan_bytes_match_output_to_text(const GScanBytesMatch *, int);
+static void g_scan_bytes_matches_output_to_text(const GScanBytesMatches *, int);
/* Affiche une correspondance au format JSON. */
-static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *, const sized_string_t *, unsigned int, int);
+static void g_scan_bytes_matches_output_to_json(const GScanBytesMatches *, const sized_string_t *, unsigned int, int);
/* ---------------------------------------------------------------------------------- */
-/* CORRESPONDANCE AVEC UNE SUITE D'OCTETS */
+/* CONSERVATION DE CORRESPONDANCES ETABLIES */
/* ---------------------------------------------------------------------------------- */
-/* Indique le type défini pour un correspondance de chaîne identifiée. */
-G_DEFINE_TYPE(GScanBytesMatch, g_scan_bytes_match, G_TYPE_SCAN_MATCH);
+/* Indique le type défini pour une série de correspondances d'octets identifiées. */
+G_DEFINE_TYPE(GScanBytesMatches, g_scan_bytes_matches, G_TYPE_SCAN_MATCHES);
/******************************************************************************
* *
* Paramètres : klass = classe à initialiser. *
* *
-* Description : Initialise la classe des correspondances de chaînes. *
+* Description : Initialise la classe des séries de correspondances d'octets. *
* *
* Retour : - *
* *
@@ -85,29 +85,29 @@ G_DEFINE_TYPE(GScanBytesMatch, g_scan_bytes_match, G_TYPE_SCAN_MATCH);
* *
******************************************************************************/
-static void g_scan_bytes_match_class_init(GScanBytesMatchClass *klass)
+static void g_scan_bytes_matches_class_init(GScanBytesMatchesClass *klass)
{
GObjectClass *object; /* Autre version de la classe */
- GScanMatchClass *match; /* Version parente de la classe*/
+ GScanMatchesClass *matches; /* Version parente de la classe*/
object = G_OBJECT_CLASS(klass);
- object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_bytes_match_dispose;
- object->finalize = (GObjectFinalizeFunc)g_scan_bytes_match_finalize;
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_bytes_matches_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_scan_bytes_matches_finalize;
- match = G_SCAN_MATCH_CLASS(klass);
+ matches = G_SCAN_MATCHES_CLASS(klass);
- match->to_text = (output_scan_match_to_text_fc)g_scan_bytes_match_output_to_text;
- match->to_json = (output_scan_match_to_json_fc)g_scan_bytes_match_output_to_json;
+ matches->to_text = (output_scan_matches_to_text_fc)g_scan_bytes_matches_output_to_text;
+ matches->to_json = (output_scan_matches_to_json_fc)g_scan_bytes_matches_output_to_json;
}
/******************************************************************************
* *
-* Paramètres : match = instance à initialiser. *
+* Paramètres : matches = instance à initialiser. *
* *
-* Description : Initialise une instance de correspondance de chaîne trouvée. *
+* Description : Initialise une instance de série de correspondances trouvées.*
* *
* Retour : - *
* *
@@ -115,21 +115,22 @@ static void g_scan_bytes_match_class_init(GScanBytesMatchClass *klass)
* *
******************************************************************************/
-static void g_scan_bytes_match_init(GScanBytesMatch *match)
+static void g_scan_bytes_matches_init(GScanBytesMatches *matches)
{
- match->content = NULL;
+ matches->context = NULL;
- match->start = VMPA_NO_PHYSICAL;
- match->len = VMPA_NO_PHYSICAL;
+ matches->content_start = VMPA_NO_PHYSICAL;
+ matches->content_end = VMPA_NO_PHYSICAL;
- match->has_mod_path = false;
+ matches->areas = NULL;
+ matches->count = 0;
}
/******************************************************************************
* *
-* Paramètres : match = instance d'objet GLib à traiter. *
+* Paramètres : matches = instance d'objet GLib à traiter. *
* *
* Description : Supprime toutes les références externes. *
* *
@@ -139,18 +140,18 @@ static void g_scan_bytes_match_init(GScanBytesMatch *match)
* *
******************************************************************************/
-static void g_scan_bytes_match_dispose(GScanBytesMatch *match)
+static void g_scan_bytes_matches_dispose(GScanBytesMatches *matches)
{
- g_clear_object(&match->content);
+ //g_clear_object(&matches->context);
- G_OBJECT_CLASS(g_scan_bytes_match_parent_class)->dispose(G_OBJECT(match));
+ G_OBJECT_CLASS(g_scan_bytes_matches_parent_class)->dispose(G_OBJECT(matches));
}
/******************************************************************************
* *
-* Paramètres : match = instance d'objet GLib à traiter. *
+* Paramètres : matches = instance d'objet GLib à traiter. *
* *
* Description : Procède à la libération totale de la mémoire. *
* *
@@ -160,9 +161,9 @@ static void g_scan_bytes_match_dispose(GScanBytesMatch *match)
* *
******************************************************************************/
-static void g_scan_bytes_match_finalize(GScanBytesMatch *match)
+static void g_scan_bytes_matches_finalize(GScanBytesMatches *matches)
{
- G_OBJECT_CLASS(g_scan_bytes_match_parent_class)->finalize(G_OBJECT(match));
+ G_OBJECT_CLASS(g_scan_bytes_matches_parent_class)->finalize(G_OBJECT(matches));
}
@@ -170,11 +171,9 @@ static void g_scan_bytes_match_finalize(GScanBytesMatch *match)
/******************************************************************************
* *
* Paramètres : source = lien vers le motif recherché d'origine. *
-* content = contenu binaire présentant un motif reconnu. *
-* start = position de départ d'un motif détecté. *
-* len = taille du motif repéré. *
+* context = contexte associé au scan courant. *
* *
-* Description : Prend note d'une correspondance trouvée avec un motif. *
+* Description : Crée un suivi pour série de correspondances avec des octets. *
* *
* Retour : Correspondance mise en place. *
* *
@@ -182,13 +181,13 @@ static void g_scan_bytes_match_finalize(GScanBytesMatch *match)
* *
******************************************************************************/
-GScanMatch *g_scan_bytes_match_new(GSearchPattern *source, GBinContent *content, phys_t start, phys_t len)
+GScanMatches *g_scan_bytes_matches_new(GSearchPattern *source, GScanContext *context)
{
- GScanMatch *result; /* Structure à retourner */
+ GScanMatches *result; /* Structure à retourner */
- result = g_object_new(G_TYPE_SCAN_BYTES_MATCH, NULL);
+ result = g_object_new(G_TYPE_SCAN_BYTES_MATCHES, NULL);
- if (!g_scan_bytes_match_create(G_SCAN_BYTES_MATCH(result), source, content, start, len))
+ if (!g_scan_bytes_matches_create(G_SCAN_BYTES_MATCHES(result), source, context))
g_clear_object(&result);
return result;
@@ -198,13 +197,11 @@ GScanMatch *g_scan_bytes_match_new(GSearchPattern *source, GBinContent *content,
/******************************************************************************
* *
-* Paramètres : match = instance à initialiser pleinement. *
+* Paramètres : matches = instance à initialiser pleinement. *
* source = lien vers le motif recherché d'origine. *
-* content = contenu binaire présentant un motif reconnu. *
-* start = position de départ d'un motif détecté. *
-* len = taille du motif repéré. *
+* context = contexte associé au scan courant. *
* *
-* Description : Met en place une correspondance trouvée avec un motif. *
+* Description : Met en place une série de correspondances avec des octets. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -212,23 +209,33 @@ GScanMatch *g_scan_bytes_match_new(GSearchPattern *source, GBinContent *content,
* *
******************************************************************************/
-bool g_scan_bytes_match_create(GScanBytesMatch *match, GSearchPattern *source, GBinContent *content, phys_t start, phys_t len)
+bool g_scan_bytes_matches_create(GScanBytesMatches *matches, GSearchPattern *source, GScanContext *context)
{
bool result; /* Bilan à retourner */
- GScanMatch *base; /* Lien vers les infos de base */
+ GScanMatches *base; /* Lien vers les infos de base */
+ GBinContent *content; /* Contenu à manipuler */
+ vmpa2t start; /* Point de début du contenu */
+ vmpa2t end; /* Point de fin du contenu */
result = true;
- base = G_SCAN_MATCH(match);
+ base = G_SCAN_MATCHES(matches);
base->source = source;
g_object_ref(G_OBJECT(source));
- match->content = content;
- g_object_ref(G_OBJECT(content));
+ matches->context = context;
+ //g_object_ref(G_OBJECT(context));
- match->start = start;
- match->len = len;
+ content = g_scan_context_get_content(context);
+
+ g_binary_content_compute_start_pos(content, &start);
+ g_binary_content_compute_end_pos(content, &end);
+
+ matches->content_start = start.physical;
+ matches->content_end = end.physical;
+
+ g_object_unref(G_OBJECT(content));
return result;
@@ -237,21 +244,21 @@ bool g_scan_bytes_match_create(GScanBytesMatch *match, GSearchPattern *source, G
/******************************************************************************
* *
-* Paramètres : match = informations de correspondance à consulter. *
+* Paramètres : matches = informations de correspondances à consulter. *
* *
-* Description : Fournit une référence au contenu lié à la correspondance. *
+* Description : Fournit le contexte du scan associé aux correspondances. *
* *
-* Retour : Content binaire associé au context. *
+* Retour : Contexte de scan courant. *
* *
* Remarques : - *
* *
******************************************************************************/
-GBinContent *g_scan_bytes_match_get_content(const GScanBytesMatch *match)
+GScanContext *g_scan_bytes_matches_get_context(const GScanBytesMatches *matches)
{
- GBinContent *result; /* Instance à retourner */
+ GScanContext *result; /* Instance à retourner */
- result = match->content;
+ result = matches->context;
g_object_ref(G_OBJECT(result));
@@ -262,26 +269,44 @@ GBinContent *g_scan_bytes_match_get_content(const GScanBytesMatch *match)
/******************************************************************************
* *
-* Paramètres : match = informations de correspondance à consulter. *
-* start = position de départ d'un motif détecté. [OUT] *
-* end = position d'arrivée d'un motif détecté. [OUT] *
+* Paramètres : matches = suivi de correspondances à manipuler. *
+* list = correspondances établies à mémoriser. *
+* count = taille de cette liste. *
* *
-* Description : Indique la localisation d'une correspondance établie. *
+* Description : Intègre une liste de correspondances vérifiées. *
* *
-* Retour : Taille mesurée de la correspondance. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-phys_t g_scan_bytes_match_get_location(const GScanBytesMatch *match, phys_t *start, phys_t *end)
+void g_scan_bytes_matches_set_list(GScanBytesMatches *matches, match_area_t *list, size_t count)
{
- phys_t result; /* Taille à retourner */
+ matches->areas = list;
- result = match->len;
+ matches->count = count;
- *start = match->start;
- *end = match->start + result;
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : matches = suivi de correspondances à consulter. *
+* *
+* Description : Indique le nombre de correspondances pour une définition. *
+* *
+* Retour : Quantité de correspondances établies pour un motif entier. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_scan_bytes_matches_count(const GScanBytesMatches *matches)
+{
+ size_t result; /* Quantité à retourner */
+
+ result = matches->count;
return result;
@@ -290,28 +315,71 @@ phys_t g_scan_bytes_match_get_location(const GScanBytesMatch *match, phys_t *sta
/******************************************************************************
* *
-* Paramètres : match = informations de correspondance à compléter. *
-* index = indice de la combinaison de modificateurs ciblée. *
+* Paramètres : matches = suivi de correspondances à consulter. *
+* index = indice de la correspondance recherchée. *
* *
-* Description : Mémorise l'origine d'une correspondance à partir d'un indice.*
+* Description : Fournit les informations relatives à une correspondance. *
* *
-* Retour : - *
+* Retour : Propritétés de la correspondance visée ou NULL pour un échec.*
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const match_area_t *g_scan_bytes_matches_get(const GScanBytesMatches *matches, size_t index)
+{
+ const match_area_t *result; /* Pointeur à retourner */
+
+
+ for_each_match_area(result, matches->areas)
+ {
+ if (index == 0)
+ break;
+ }
+
+ assert(index == 0);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : matches = informations de correspondance à consulter. *
+* index = indice de la correspondance visée. *
+* start = position de départ d'un motif détecté. [OUT] *
+* end = position d'arrivée d'un motif détecté. [OUT] *
+* *
+* Description : Indique la localisation d'une correspondance établie. *
+* *
+* Retour : Taille mesurée de la correspondance. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_scan_bytes_match_remember_modifier_path(GScanBytesMatch *match, size_t index)
+phys_t g_scan_bytes_matches_get_location(const GScanBytesMatches *matches, size_t index, phys_t *start, phys_t *end)
{
- match->mod_path_index = index;
- match->has_mod_path = true;
+ phys_t result; /* Taille à retourner */
+
+ result = 0;
+
+ /*
+ result = match->len;
+
+ *start = match->start;
+ *end = match->start + result;
+ */
+
+ return result;
}
/******************************************************************************
* *
-* Paramètres : match = informations de correspondance à consulter. *
+* Paramètres : matches = informations de correspondance à consulter. *
* *
* Description : Retrouve l'origine d'une correspondance à partir d'un indice.*
* *
@@ -321,11 +389,15 @@ void g_scan_bytes_match_remember_modifier_path(GScanBytesMatch *match, size_t in
* *
******************************************************************************/
-char *g_scan_bytes_match_get_modifier_path(const GScanBytesMatch *match)
+char *g_scan_bytes_matches_get_modifier_path(const GScanBytesMatches *matches)
{
char *result; /* Combinaison à retourner */
GBytesToken *pattern; /* Autre version du motif */
+ result = NULL;
+
+ /*
+
if (match->has_mod_path)
{
pattern = G_BYTES_TOKEN(G_SCAN_MATCH(match)->source);
@@ -334,6 +406,7 @@ char *g_scan_bytes_match_get_modifier_path(const GScanBytesMatch *match)
else
result = NULL;
+ */
return result;
@@ -348,8 +421,8 @@ char *g_scan_bytes_match_get_modifier_path(const GScanBytesMatch *match)
/******************************************************************************
* *
-* Paramètres : match = définition de correspondance à manipuler. *
-* fd = canal d'écriture. *
+* Paramètres : matches = définition de correspondance à manipuler. *
+* fd = canal d'écriture. *
* *
* Description : Affiche une correspondance au format texte. *
* *
@@ -359,91 +432,105 @@ char *g_scan_bytes_match_get_modifier_path(const GScanBytesMatch *match)
* *
******************************************************************************/
-static void g_scan_bytes_match_output_to_text(const GScanBytesMatch *match, int fd)
+static void g_scan_bytes_matches_output_to_text(const GScanBytesMatches *matches, int fd)
{
+ GBinContent *content; /* Contenu binaire analysé */
+ GScanMatches *base; /* Lien vers les infos de base */
+ const char *name; /* Désignation du motif ciblé */
+ match_area_t *iter; /* Boucle de parcours #1 */
char value[2 + ULLONG_MAXLEN]; /* Impression de la position */
int ret; /* Bilan d'une conversion */
- GScanMatch *base; /* Lien vers les infos de base */
- const char *name; /* Désignation du motif ciblé */
vmpa2t pos; /* Tête de lecture */
+ phys_t len; /* Taille d'une correspondance */
const bin_t *data; /* Accès aux données brutes */
phys_t k; /* Boucle de parcours #2 */
- /* Position dans le binaire (hexadécimal) */
+ content = g_scan_context_get_content(matches->context);
- ret = snprintf(value, ULLONG_MAXLEN, "0x%llx", (unsigned long long)match->start);
+ base = G_SCAN_MATCHES(matches);
- if (ret > 0)
- write(fd, value, ret);
+ name = g_search_pattern_get_name(base->source);
- else
+ for_each_match_area(iter, matches->areas)
{
- log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!");
- write(fd, "\"<error>\"", 9);
- }
-
- write(fd, ":", 1);
+ /* Position dans le binaire (hexadécimal) */
- /* Affichage de la désignation */
+ ret = snprintf(value, ULLONG_MAXLEN, "0x%llx", (unsigned long long)iter->start);
- write(fd, "$", 1);
+ if (ret > 0)
+ write(fd, value, ret);
- base = G_SCAN_MATCH(match);
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!");
+ write(fd, "\"<error>\"", 9);
+ }
- name = g_search_pattern_get_name(base->source);
+ write(fd, ":", 1);
- /**
- * Les fonctionnalités Yara d'origine autorisent les variables anonymes '$'.
- *
- * Cette absence de nom est supportée ici.
- */
+ /* Affichage de la désignation */
- if (name != NULL)
- write(fd, name, strlen(name));
+ write(fd, "$", 1);
- write(fd, ": ", 2);
+ /**
+ * Les fonctionnalités Yara d'origine autorisent les variables anonymes '$'.
+ *
+ * Cette absence de nom est supportée ici.
+ */
- /* Affichage du contenu */
+ if (name != NULL)
+ write(fd, name, strlen(name));
- init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
+ write(fd, ": ", 2);
- data = g_binary_content_get_raw_access(match->content, &pos, match->len);
+ /* Affichage du contenu */
- for (k = 0; k < match->len; k++)
- {
- if (isprint(data[k]))
- write(fd, &data[k], 1);
+ init_vmpa(&pos, iter->start, VMPA_NO_VIRTUAL);
- else
- {
- write(fd, "\\x", 2);
+ len = iter->end - iter->start;
- ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]);
+ data = g_binary_content_get_raw_access(content, &pos, len);
+ assert(data != NULL);
- if (ret > 0)
- {
- assert(ret == 2);
- write(fd, value, ret);
- }
+ for (k = 0; k < len; k++)
+ {
+ if (isprint(data[k]))
+ write(fd, &data[k], 1);
else
{
- log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
- write(fd, "??", 2);
+ write(fd, "\\x", 2);
+
+ ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]);
+
+ if (ret > 0)
+ {
+ assert(ret == 2);
+ write(fd, value, ret);
+ }
+
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
+ write(fd, "??", 2);
+ }
+
}
}
+ write(fd, "\n", 1);
+
}
- write(fd, "\n", 1);
+ g_object_unref(G_OBJECT(content));
}
/******************************************************************************
* *
-* Paramètres : match = définition de correspondance à manipuler. *
+* Paramètres : matches = définition de correspondance à manipuler. *
* padding = éventuel bourrage initial à placer ou NULL. *
* level = profondeur actuelle. *
* fd = canal d'écriture. *
@@ -456,188 +543,246 @@ static void g_scan_bytes_match_output_to_text(const GScanBytesMatch *match, int
* *
******************************************************************************/
-static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *match, const sized_string_t *padding, unsigned int level, int fd)
+static void g_scan_bytes_matches_output_to_json(const GScanBytesMatches *matches, const sized_string_t *padding, unsigned int level, int fd)
{
unsigned int i; /* Boucle de parcours #1 */
- vmpa2t pos; /* Tête de lecture */
char value[4 + ULLONG_MAXLEN]; /* Impression de la position */
int ret; /* Bilan d'une conversion */
+ GBinContent *content; /* Contenu binaire analysé */
+ match_area_t *iter; /* Boucle de parcours #1 */
+ vmpa2t pos; /* Tête de lecture */
+ phys_t len; /* Taille d'une correspondance */
const bin_t *data; /* Accès aux données brutes */
phys_t k; /* Boucle de parcours #2 */
- /* Position dans le binaire (décimal) */
+ /* Nombre de correspondances */
for (i = 0; i < level; i++)
write(fd, padding->data, padding->len);
- write(fd, "\"offset\": ", 10);
+ write(fd, "\"match_count\": ", 15);
- ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)match->start);
+ ret = snprintf(value, ULLONG_MAXLEN, "%zu", matches->count);
if (ret > 0)
write(fd, value, ret);
else
{
- log_simple_message(LMT_EXT_ERROR, "Error while converting offset!");
+ log_simple_message(LMT_EXT_ERROR, "Error while converting value!");
write(fd, "null", 4);
}
write(fd, ",\n", 2);
- /* Position dans le binaire (hexadécimal) */
+ /* Détail des correspondances */
for (i = 0; i < level; i++)
write(fd, padding->data, padding->len);
- write(fd, "\"offset_hex\": ", 14);
+ write(fd, "\"matches\": [\n", 13);
- ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)match->start);
+ content = g_scan_context_get_content(matches->context);
- if (ret > 0)
- write(fd, value, ret);
-
- else
+ for_each_match_area(iter, matches->areas)
{
- log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!");
- write(fd, "null", 4);
- }
-
- write(fd, ",\n", 2);
+ /* Marqueur de début */
- /* Affichage du contenu brut */
+ for (i = 0; i < (level + 1); i++)
+ write(fd, padding->data, padding->len);
- for (i = 0; i < level; i++)
- write(fd, padding->data, padding->len);
+ write(fd, "{\n", 2);
- write(fd, "\"content\": \"", 12);
+ /* Position dans le binaire (décimal) */
- init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
+ for (i = 0; i < (level + 2); i++)
+ write(fd, padding->data, padding->len);
- data = g_binary_content_get_raw_access(match->content, &pos, match->len);
- assert(data != NULL);
+ write(fd, "\"offset\": ", 10);
- for (k = 0; k < match->len; k++)
- {
- if (data[k] == '\\')
- write(fd, "\\\\", 2);
+ ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)iter->start);
- else if (isprint(data[k]))
- write(fd, &data[k], 1);
+ if (ret > 0)
+ write(fd, value, ret);
else
{
- write(fd, "\\u", 2);
+ log_simple_message(LMT_EXT_ERROR, "Error while converting offset!");
+ write(fd, "null", 4);
+ }
- /**
- * Cf. https://datatracker.ietf.org/doc/html/rfc8259#section-7
- */
- ret = snprintf(value, ULLONG_MAXLEN, "%04hhx", data[k]);
+ write(fd, ",\n", 2);
- if (ret > 0)
- {
- assert(ret == 4);
- write(fd, value, ret);
- }
+ /* Position dans le binaire (hexadécimal) */
- else
- {
- log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
- write(fd, "??", 2);
- }
+ for (i = 0; i < (level + 2); i++)
+ write(fd, padding->data, padding->len);
- }
+ write(fd, "\"offset_hex\": ", 14);
- }
+ ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)iter->start);
- write(fd, "\",\n", 3);
+ if (ret > 0)
+ write(fd, value, ret);
- /* Affichage du contenu en version humainement lisible */
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!");
+ write(fd, "null", 4);
+ }
- for (i = 0; i < level; i++)
- write(fd, padding->data, padding->len);
+ write(fd, ",\n", 2);
- write(fd, "\"content_str\": \"", 16);
+ /* Affichage du contenu brut */
- init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
+ for (i = 0; i < (level + 2); i++)
+ write(fd, padding->data, padding->len);
- data = g_binary_content_get_raw_access(match->content, &pos, match->len);
- assert(data != NULL);
+ write(fd, "\"content\": \"", 12);
- for (k = 0; k < match->len; k++)
- {
- if (data[k] == '\\')
- write(fd, "\\\\", 2);
+ init_vmpa(&pos, iter->start, VMPA_NO_VIRTUAL);
- else if (isprint(data[k]))
- write(fd, &data[k], 1);
+ len = iter->end - iter->start;
- else
+ data = g_binary_content_get_raw_access(content, &pos, len);
+ assert(data != NULL);
+
+ for (k = 0; k < len; k++)
{
- write(fd, "\\\\x", 3);
+ if (data[k] == '\\')
+ write(fd, "\\\\", 2);
- ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]);
+ else if (isprint(data[k]))
+ write(fd, &data[k], 1);
- if (ret > 0)
+ else
{
- assert(ret == 2);
- write(fd, value, ret);
+ write(fd, "\\u", 2);
+
+ /**
+ * Cf. https://datatracker.ietf.org/doc/html/rfc8259#section-7
+ */
+ ret = snprintf(value, ULLONG_MAXLEN, "%04hhx", data[k]);
+
+ if (ret > 0)
+ {
+ assert(ret == 4);
+ write(fd, value, ret);
+ }
+
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
+ write(fd, "??", 2);
+ }
+
}
+ }
+
+ write(fd, "\",\n", 3);
+
+ /* Affichage du contenu en version humainement lisible */
+
+ for (i = 0; i < (level + 2); i++)
+ write(fd, padding->data, padding->len);
+
+ write(fd, "\"content_str\": \"", 16);
+
+ init_vmpa(&pos, iter->start, VMPA_NO_VIRTUAL);
+
+ data = g_binary_content_get_raw_access(content, &pos, len);
+ assert(data != NULL);
+
+ for (k = 0; k < len; k++)
+ {
+ if (data[k] == '\\')
+ write(fd, "\\\\", 2);
+
+ else if (isprint(data[k]))
+ write(fd, &data[k], 1);
+
else
{
- log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
- write(fd, "??", 2);
+ write(fd, "\\\\x", 3);
+
+ ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]);
+
+ if (ret > 0)
+ {
+ assert(ret == 2);
+ write(fd, value, ret);
+ }
+
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
+ write(fd, "??", 2);
+ }
+
}
}
- }
+ write(fd, "\",\n", 3);
- write(fd, "\",\n", 3);
+ /* Affichage du contenu brut */
- /* Affichage du contenu brut */
+ for (i = 0; i < (level + 2); i++)
+ write(fd, padding->data, padding->len);
- for (i = 0; i < level; i++)
- write(fd, padding->data, padding->len);
+ write(fd, "\"length\": ", 10);
- write(fd, "\"length\": ", 10);
+ ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)len);
- init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
+ if (ret > 0)
+ write(fd, value, ret);
- ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)match->len);
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
+ write(fd, "-1", 2);
+ }
- if (ret > 0)
- write(fd, value, ret);
+ write(fd, ",\n", 2);
- else
- {
- log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
- write(fd, "-1", 2);
- }
+ /* Affichage du contenu brut (hexadécimal) */
- write(fd, ",\n", 2);
+ for (i = 0; i < (level + 2); i++)
+ write(fd, padding->data, padding->len);
- /* Affichage du contenu brut (hexadécimal) */
+ write(fd, "\"length_hex\": ", 14);
- for (i = 0; i < level; i++)
- write(fd, padding->data, padding->len);
+ ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)len);
- write(fd, "\"length_hex\": ", 14);
+ if (ret > 0)
+ write(fd, value, ret);
- init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
+ write(fd, "\"0xffffffffffffffff\"", 20);
+ }
- ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)match->len);
+ write(fd, "\n", 1);
- if (ret > 0)
- write(fd, value, ret);
+ /* Marqueur de fin */
+
+ for (i = 0; i < (level + 1); i++)
+ write(fd, padding->data, padding->len);
+
+ if (is_last_match_area(iter, matches->areas))
+ write(fd, "}\n", 2);
+ else
+ write(fd, "},\n", 3);
- else
- {
- log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
- write(fd, "\"0xffffffffffffffff\"", 20);
}
- write(fd, "\n", 1);
+ g_object_unref(G_OBJECT(content));
+
+ for (i = 0; i < level; i++)
+ write(fd, padding->data, padding->len);
+
+ write(fd, "]\n", 2);
}
diff --git a/src/analysis/scan/matches/bytes.h b/src/analysis/scan/matches/bytes.h
index bd7425d..9e046aa 100644
--- a/src/analysis/scan/matches/bytes.h
+++ b/src/analysis/scan/matches/bytes.h
@@ -1,6 +1,6 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * bytes.h - prototypes pour la sauvegarde d'une correspondance identifiée de suite d'octets
+ * bytes.h - prototypes pour la sauvegarde de correspondances avec des suites d'octets identifiées
*
* Copyright (C) 2022 Cyrille Bagard
*
@@ -28,43 +28,53 @@
#include <glib-object.h>
-#include "../match.h"
-#include "../../content.h"
+#include "area.h"
+#include "../context.h"
+#include "../matches.h"
-#define G_TYPE_SCAN_BYTES_MATCH g_scan_bytes_match_get_type()
-#define G_SCAN_BYTES_MATCH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_BYTES_MATCH, GScanBytesMatch))
-#define G_IS_SCAN_BYTES_MATCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_BYTES_MATCH))
-#define G_SCAN_BYTES_MATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_BYTES_MATCH, GScanBytesMatchClass))
-#define G_IS_SCAN_BYTES_MATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_BYTES_MATCH))
-#define G_SCAN_BYTES_MATCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_BYTES_MATCH, GScanBytesMatchClass))
+/* -------------------- CONSERVATION DE CORRESPONDANCES ETABLIES -------------------- */
-/* Correspondance trouvée avec une chaîne (instance) */
-typedef struct _GScanBytesMatch GScanBytesMatch;
+#define G_TYPE_SCAN_BYTES_MATCHES g_scan_bytes_matches_get_type()
+#define G_SCAN_BYTES_MATCHES(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SCAN_BYTES_MATCHES, GScanBytesMatches))
+#define G_IS_SCAN_BYTES_MATCHES(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SCAN_BYTES_MATCHES))
+#define G_SCAN_BYTES_MATCHES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_SCAN_BYTES_MATCHES, GScanBytesMatchesClass))
+#define G_IS_SCAN_BYTES_MATCHES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_SCAN_BYTES_MATCHES))
+#define G_SCAN_BYTES_MATCHES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_SCAN_BYTES_MATCHES, GScanBytesMatchesClass))
-/* Correspondance trouvée avec une chaîne (classe) */
-typedef struct _GScanBytesMatchClass GScanBytesMatchClass;
+/* Correspondances trouvées avec des suite d'octets (instance) */
+typedef struct _GScanBytesMatches GScanBytesMatches;
-/* Indique le type défini pour un correspondance de chaîne identifiée. */
-GType g_scan_bytes_match_get_type(void);
+/* Correspondances trouvées avec des suite d'octets (classe) */
+typedef struct _GScanBytesMatchesClass GScanBytesMatchesClass;
-/* Prend note d'une correspondance trouvée avec un motif. */
-GScanMatch *g_scan_bytes_match_new(GSearchPattern *, GBinContent *, phys_t, phys_t);
-/* Fournit une référence au contenu lié à la correspondance. */
-GBinContent *g_scan_bytes_match_get_content(const GScanBytesMatch *);
+/* Indique le type défini pour une série de correspondances d'octets identifiées. */
+GType g_scan_bytes_matches_get_type(void);
-/* Indique la localisation d'une correspondance établie. */
-phys_t g_scan_bytes_match_get_location(const GScanBytesMatch *, phys_t *, phys_t *);
+/* Crée un suivi pour série de correspondances avec des octets. */
+GScanMatches *g_scan_bytes_matches_new(GSearchPattern *, GScanContext *);
+
+/* Fournit le contexte du scan associé aux correspondances. */
+GScanContext *g_scan_bytes_matches_get_context(const GScanBytesMatches *);
+
+/* Intègre une liste de correspondances vérifiées. */
+void g_scan_bytes_matches_set_list(GScanBytesMatches *, match_area_t *, size_t);
-/* Mémorise l'origine d'une correspondance à partir d'un indice. */
-void g_scan_bytes_match_remember_modifier_path(GScanBytesMatch *, size_t);
+/* Indique le nombre de correspondances pour une définition. */
+size_t g_scan_bytes_matches_count(const GScanBytesMatches *);
+
+/* Fournit les informations relatives à une correspondance. */
+const match_area_t *g_scan_bytes_matches_get(const GScanBytesMatches *, size_t);
+
+/* Indique la localisation d'une correspondance établie. */
+phys_t g_scan_bytes_matches_get_location(const GScanBytesMatches *, size_t, phys_t *, phys_t *);
/* Retrouve l'origine d'une correspondance à partir d'un indice. */
-char *g_scan_bytes_match_get_modifier_path(const GScanBytesMatch *);
+char *g_scan_bytes_matches_get_modifier_path(const GScanBytesMatches *);
diff --git a/src/analysis/scan/matches/pending.c b/src/analysis/scan/matches/pending.c
index 57c63d7..c653257 100644
--- a/src/analysis/scan/matches/pending.c
+++ b/src/analysis/scan/matches/pending.c
@@ -33,6 +33,8 @@
+
+
/* ------------------------- MEMORISATION D'UNE ZONE BORNEE ------------------------- */
@@ -48,6 +50,8 @@ static int compare_match_area(const match_area_t *, const match_area_t *);
+
+
/* ---------------------------------------------------------------------------------- */
/* MEMORISATION D'UNE ZONE BORNEE */
/* ---------------------------------------------------------------------------------- */
@@ -55,6 +59,104 @@ static int compare_match_area(const match_area_t *, const match_area_t *);
/******************************************************************************
* *
+* Paramètres : allocator = allocateur dédié à l'ensemble de zones. *
+* start = point de départ d'une nouvelle correspondance. *
+* length = taille de la zone couverte. *
+* *
+* Description : Crée une nouvelle structure de suivi de correspondance. *
+* *
+* Retour : Structure initialisée mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static match_area_t *create_match_area(GUMemCache *allocator, phys_t start, phys_t length)
+{
+ match_area_t *result; /* Zone à retourner */
+
+ result = g_umem_cache_alloc(allocator);
+
+ DL_LIST_ITEM_INIT(&result->link);
+
+ result->start = start;
+ result->end = start + length;
+
+ assert(matches->content_start <= result->start);
+ assert(result->end <= matches->content_end);
+
+ result->ttl = 1;
+
+ result->has_mod_path = false;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : allocator = allocateur dédié à l'ensemble de zones. *
+* start = point de départ d'une nouvelle correspondance. *
+* length = taille de la zone couverte. *
+* index = indice de construction pour le motif concerné. *
+* *
+* Description : Crée une nouvelle structure de suivi de correspondance. *
+* *
+* Retour : Structure initialisée mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static match_area_t *create_match_area_with_path(GUMemCache *allocator, phys_t start, phys_t length, size_t index)
+{
+ match_area_t *result; /* Zone à retourner */
+
+ result = g_umem_cache_alloc(allocator);
+
+ DL_LIST_ITEM_INIT(&result->link);
+
+ result->start = start;
+ result->end = start + length;
+
+ assert(matches->content_start <= result->start);
+ assert(result->end <= matches->content_end);
+
+ result->ttl = 1;
+
+ result->mod_path_index = index;
+ result->has_mod_path = true;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : area = zone de suivi à supprimer. *
+* allocator = allocateur dédié à l'ensemble de zones. *
+* *
+* Description : Supprime une structure de suivi de correspondance. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void delete_match_area(match_area_t *area, GUMemCache *allocator)
+{
+ // TODO : assert(alone)
+
+ g_umem_cache_free(allocator, area);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : a = pointeur vers la première zone à analyser. *
* b = pointeur vers la seconde zone à analyser. *
* *
@@ -114,6 +216,7 @@ void init_pending_matches(pending_matches_t *matches, const phys_t *start, const
matches->content_start = *start;
matches->content_end = *end;
+ matches->allocator = NULL;
matches->areas = NULL;
matches->allocated = 0;
matches->used = 0;
@@ -275,27 +378,12 @@ match_area_t * const *get_all_pending_matches(const pending_matches_t *matches,
void add_pending_match(pending_matches_t *matches, phys_t start, phys_t length)
{
- match_area_t *area; /* Zone à initialiser */
-
- if (matches->used == matches->allocated)
- {
- matches->allocated += PENDING_ALLOC_SIZE;
-
- matches->areas = realloc(matches->areas, matches->allocated * sizeof(match_area_t));
-
- }
-
- area = &matches->areas[matches->used++];
+ match_area_t *area; /* Nouvelle zone à intégrer */
- area->start = start;
- area->end = start + length;
+ area = create_match_area(matches->allocator, start, length);
- assert(matches->content_start <= area->start);
- assert(area->end <= matches->content_end);
-
- area->ttl = 1;
-
- area->has_mod_path = false;
+ dl_list_add_tail(area, &matches->areas, match_area_t, link);
+ matches->used++;
}
@@ -317,28 +405,12 @@ void add_pending_match(pending_matches_t *matches, phys_t start, phys_t length)
void add_pending_match_with_path(pending_matches_t *matches, phys_t start, phys_t length, size_t index)
{
- match_area_t *area; /* Zone à initialiser */
-
- if (matches->used == matches->allocated)
- {
- matches->allocated += PENDING_ALLOC_SIZE;
-
- matches->areas = realloc(matches->areas, matches->allocated * sizeof(match_area_t));
-
- }
-
- area = &matches->areas[matches->used++];
-
- area->start = start;
- area->end = start + length;
-
- assert(matches->content_start <= area->start);
- assert(area->end <= matches->content_end);
+ match_area_t *area; /* Nouvelle zone à intégrer */
- area->ttl = 1;
+ area = create_match_area_with_path(matches->allocator, start, length, index);
- area->mod_path_index = index;
- area->has_mod_path = true;
+ dl_list_add_tail(area, &matches->areas, match_area_t, link);
+ matches->used++;
}
diff --git a/src/analysis/scan/matches/pending.h b/src/analysis/scan/matches/pending.h
index f4ac7a2..e430ca1 100644
--- a/src/analysis/scan/matches/pending.h
+++ b/src/analysis/scan/matches/pending.h
@@ -21,7 +21,7 @@
*/
-#ifndef _ANALYSIS_SCAN_MATCHES_PENDING_H
+#if 0 //ndef _ANALYSIS_SCAN_MATCHES_PENDING_H
#define _ANALYSIS_SCAN_MATCHES_PENDING_H
@@ -30,12 +30,20 @@
#include "../../content.h"
+#include "../../../common/dllist.h"
+
+
+
+// TODO : move vers ByteMatch
+typedef int GUMemCache;
/* Couverture d'une correspondance */
typedef struct _match_area_t
{
+ DL_LIST_ITEM(link); /* Lien vers les maillons */
+
phys_t start; /* Point de départ */
phys_t end; /* Point d'arrivée (exclus) */
@@ -52,6 +60,7 @@ typedef struct _pending_matches_t
phys_t content_start; /* Point de début du contenu */
phys_t content_end; /* Point de fin du contenu */
+ GUMemCache *allocator; /* Allocateur pour zones */
match_area_t *areas; /* Zones couvertes */
size_t allocated; /* Nombre d'allocations */
size_t used; /* Nombre de zones */