summaryrefslogtreecommitdiff
path: root/src/analysis/scan/patterns/token.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/scan/patterns/token.c')
-rw-r--r--src/analysis/scan/patterns/token.c180
1 files changed, 175 insertions, 5 deletions
diff --git a/src/analysis/scan/patterns/token.c b/src/analysis/scan/patterns/token.c
index d8a5cbc..cc2d87a 100644
--- a/src/analysis/scan/patterns/token.c
+++ b/src/analysis/scan/patterns/token.c
@@ -25,12 +25,18 @@
#include <assert.h>
+#include <stdio.h>
#include "token-int.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_string_token_class_init(GStringTokenClass *);
@@ -45,6 +51,22 @@ static void g_string_token_finalize(GStringToken *);
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Affiche un motif de recherche au format texte. */
+static void g_string_token_output_to_text(const GStringToken *, GScanContext *, int);
+
+/* Affiche un motif de recherche au format JSON. */
+static void g_string_token_output_to_json(const GStringToken *, 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(GStringToken, g_string_token, G_TYPE_SEARCH_PATTERN);
@@ -73,9 +95,8 @@ static void g_string_token_class_init(GStringTokenClass *klass)
pattern = G_SEARCH_PATTERN_CLASS(klass);
- //pattern->prepare = (prepare_pattern_fc)g_string_token_prepare;
- //pattern->analyze = (analyze_pattern_fc)g_string_token_analyze;
- //pattern->count = (count_pattern_matchs_fc);
+ pattern->to_text = (output_pattern_to_text_fc)g_string_token_output_to_text;
+ pattern->to_json = (output_pattern_to_json_fc)g_string_token_output_to_json;
}
@@ -94,6 +115,7 @@ static void g_string_token_class_init(GStringTokenClass *klass)
static void g_string_token_init(GStringToken *token)
{
+ token->root = NULL;
}
@@ -138,6 +160,33 @@ static void g_string_token_finalize(GStringToken *token)
/******************************************************************************
* *
+* Paramètres : token = encadrement de motif à initialiser pleinement. *
+* root = représentation du motif à recherche. *
+* *
+* Description : Met en place un gestionnaire de recherche de binaire. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_string_token_create(GStringToken *token, GScanTokenNode *root)
+{
+ bool result; /* Bilan à retourner */
+
+ result = true;
+
+ token->root = root;
+ g_object_ref(G_OBJECT(root));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : token = définition de la bribe à enregistrer. *
* context = contexte de l'analyse à mener. *
* backend = moteur de recherche à préchauffer. *
@@ -151,7 +200,7 @@ static void g_string_token_finalize(GStringToken *token)
* *
******************************************************************************/
-bool g_string_token_enroll(GStringToken *token, GScanContext *context, GEngineBackend *backend, size_t maxsize)
+bool g_string_token_enroll__old(GStringToken *token, GScanContext *context, GEngineBackend *backend, size_t maxsize)
{
bool result; /* Statut à retourner */
GStringTokenClass *class; /* Classe de l'instance */
@@ -166,6 +215,16 @@ bool g_string_token_enroll(GStringToken *token, GScanContext *context, GEngineBa
}
+bool g_string_token_enroll(GStringToken *token, GScanContext *context, GEngineBackend *backend, size_t maxsize)
+{
+ bool result; /* Statut à retourner */
+
+ result = g_scan_token_node_enroll(token->root, context, backend, maxsize);
+
+ return result;
+
+}
+
/******************************************************************************
* *
@@ -182,7 +241,7 @@ bool g_string_token_enroll(GStringToken *token, GScanContext *context, GEngineBa
* *
******************************************************************************/
-void g_string_token_check(const GStringToken *token, GScanContext *context, GBinContent *content, pending_matches_t *matches)
+void g_string_token_check__old(const GStringToken *token, GScanContext *context, GBinContent *content, pending_matches_t *matches)
{
GStringTokenClass *class; /* Classe de l'instance */
@@ -191,3 +250,114 @@ void g_string_token_check(const GStringToken *token, GScanContext *context, GBin
class->check(token, context, content, matches);
}
+
+void g_string_token_check(const GStringToken *token, GScanContext *context, GBinContent *content, pending_matches_t *matches)
+{
+ g_scan_token_node_check(token->root, context, content, matches, NULL);
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* 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_string_token_output_to_text(const GStringToken *pattern, GScanContext *context, int fd)
+{
+ const GScanMatch **matches; /* Correspondances établies */
+ size_t count; /* Quantité de cette liste */
+ size_t i; /* Boucle de parcours */
+
+ matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern), &count);
+
+ for (i = 0; i < count; i++)
+ g_scan_match_output_to_text(matches[i], 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_string_token_output_to_json(const GStringToken *pattern, GScanContext *context, const sized_string_t *padding, unsigned int level, int fd)
+{
+ unsigned int i; /* Boucle de parcours #1 */
+ const GScanMatch **matches; /* Correspondances établies */
+ size_t count; /* Quantité de cette liste */
+ char value[ULLONG_MAXLEN]; /* Impression de la position */
+ int ret; /* Bilan d'une conversion */
+ size_t k; /* Boucle de parcours #2 */
+ bool trailing; /* Virgule finale */
+
+ matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern), &count);
+
+ /* Nombre de correspondances */
+
+ for (i = 0; i < level; i++)
+ write(fd, padding->data, padding->len);
+
+ write(fd, "\"match_count\": ", 15);
+
+ ret = snprintf(value, ULLONG_MAXLEN, "%zu", count);
+
+ if (ret > 0)
+ write(fd, value, ret);
+
+ else
+ {
+ log_simple_message(LMT_EXT_ERROR, "Error while converting value!");
+ write(fd, "null", 4);
+ }
+
+ write(fd, ",\n", 2);
+
+ /* Détail des correspondances */
+
+ for (i = 0; i < level; i++)
+ write(fd, padding->data, padding->len);
+
+ write(fd, "\"matches\": [\n", 13);
+
+ for (k = 0; k < count; k++)
+ {
+ trailing = ((k + 1) < count);
+
+ g_scan_match_output_to_json(matches[k], padding, level + 1, fd, trailing);
+
+ }
+
+ for (i = 0; i < level; i++)
+ write(fd, padding->data, padding->len);
+
+ write(fd, "]\n", 2);
+
+}