diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2023-09-12 04:43:02 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2023-09-12 04:45:25 (GMT) |
commit | fed4c10b9bb1c6f99440dba3839a1e7b56b40359 (patch) | |
tree | d544bde345c16a5eff19c0f9a074c09b366f7dbe /src/analysis/scan/patterns/token.c | |
parent | 155c500b8933d2c7269215ea1d141d341de0a44f (diff) |
Save current state with some ROST extra features.
Diffstat (limited to 'src/analysis/scan/patterns/token.c')
-rw-r--r-- | src/analysis/scan/patterns/token.c | 140 |
1 files changed, 116 insertions, 24 deletions
diff --git a/src/analysis/scan/patterns/token.c b/src/analysis/scan/patterns/token.c index cc2d87a..1b2ee8a 100644 --- a/src/analysis/scan/patterns/token.c +++ b/src/analysis/scan/patterns/token.c @@ -25,6 +25,7 @@ #include <assert.h> +#include <ctype.h> #include <stdio.h> @@ -116,6 +117,11 @@ static void g_string_token_class_init(GStringTokenClass *klass) static void g_string_token_init(GStringToken *token) { token->root = NULL; + token->slow = 0; + token->need_backward = false; + + token->fullword = false; + token->private = false; } @@ -160,8 +166,10 @@ static void g_string_token_finalize(GStringToken *token) /****************************************************************************** * * -* Paramètres : token = encadrement de motif à initialiser pleinement. * -* root = représentation du motif à recherche. * +* 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. * * * @@ -171,7 +179,7 @@ static void g_string_token_finalize(GStringToken *token) * * ******************************************************************************/ -bool g_string_token_create(GStringToken *token, GScanTokenNode *root) +bool g_string_token_create(GStringToken *token, GScanTokenNode *root, bool fullword, bool private) { bool result; /* Bilan à retourner */ @@ -180,6 +188,9 @@ bool g_string_token_create(GStringToken *token, GScanTokenNode *root) token->root = root; g_object_ref(G_OBJECT(root)); + token->fullword = fullword; + token->private = private; + return result; } @@ -187,39 +198,74 @@ bool g_string_token_create(GStringToken *token, GScanTokenNode *root) /****************************************************************************** * * -* Paramètres : token = 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). * +* Paramètres : token = encadrement de motif à consulter. * * * -* Description : Inscrit la définition d'un motif dans un moteur de recherche.* +* Description : Indique si seuls des mots entiers sont retenus des analyses. * * * -* Retour : Bilan de l'opération à renvoyer. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -bool g_string_token_enroll__old(GStringToken *token, GScanContext *context, GEngineBackend *backend, size_t maxsize) +bool g_string_token_target_fullword(const GStringToken *token) { - bool result; /* Statut à retourner */ - GStringTokenClass *class; /* Classe de l'instance */ + bool result; /* Statut à renvoyer */ + + result = token->fullword; - assert(g_engine_backend_get_atom_max_size(backend) == maxsize); + return result; - class = G_STRING_TOKEN_GET_CLASS(token); +} - result = class->enroll(token, context, backend, maxsize); + +/****************************************************************************** +* * +* 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_string_token_is_private(const GStringToken *token) +{ + bool result; /* Statut à renvoyer */ + + result = token->private; return result; } + +/****************************************************************************** +* * +* Paramètres : token = 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). * +* * +* Description : Inscrit la définition d'un motif dans un moteur de recherche.* +* * +* Retour : Bilan de l'opération à renvoyer. * +* * +* Remarques : - * +* * +******************************************************************************/ + 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); + token->need_backward = g_scan_token_node_setup_tree(token->root); + + result = g_scan_token_node_enroll(token->root, context, backend, maxsize, &token->slow); + + printf("need backward? %d\n", token->need_backward); return result; @@ -241,19 +287,59 @@ bool g_string_token_enroll(GStringToken *token, GScanContext *context, GEngineBa * * ******************************************************************************/ -void g_string_token_check__old(const GStringToken *token, GScanContext *context, GBinContent *content, pending_matches_t *matches) +void g_string_token_check(const GStringToken *token, GScanContext *context, GBinContent *content, pending_matches_t *matches) { - GStringTokenClass *class; /* Classe de l'instance */ + size_t p; /* Boucle de parcours #3 */ + match_area_t *pending; /* Correspondance à traiter */ + vmpa2t pos; /* Tête de lecture */ + const bin_t *byte; /* Octet à valider */ - class = G_STRING_TOKEN_GET_CLASS(token); + g_scan_token_node_check_forward(token->root, context, content, matches); - class->check(token, context, content, matches); + if (token->need_backward) + g_scan_token_node_check_backward(token->root, context, content, matches); -} + sort_and_filter_pending_matches(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); + if (token->fullword) + { + reset_pending_matches_ttl(matches); + + for (p = 0; p < matches->used; p++) + { + pending = &matches->areas[p]; + + /* Validation de l'octet précédent, s'il existe */ + if (pending->start > matches->content_start) + { + init_vmpa(&pos, pending->start - 1, VMPA_NO_VIRTUAL); + + byte = g_binary_content_get_raw_access(content, &pos, 1); + + if (isalnum(*byte)) + continue; + + } + + /* Validation de l'octet suivant, s'il existe */ + if (pending->end < matches->content_end) + { + init_vmpa(&pos, pending->end, VMPA_NO_VIRTUAL); + + byte = g_binary_content_get_raw_access(content, &pos, 1); + + if (isalnum(*byte)) + continue; + + } + + keep_pending_match(pending); + + } + + purge_pending_matches(matches); + + } } @@ -284,6 +370,9 @@ static void g_string_token_output_to_text(const GStringToken *pattern, GScanCont size_t count; /* Quantité de cette liste */ size_t i; /* Boucle de parcours */ + if (g_string_token_is_private(pattern)) + return; + matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern), &count); for (i = 0; i < count; i++) @@ -318,6 +407,9 @@ static void g_string_token_output_to_json(const GStringToken *pattern, GScanCont size_t k; /* Boucle de parcours #2 */ bool trailing; /* Virgule finale */ + if (g_string_token_is_private(pattern)) + return; + matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern), &count); /* Nombre de correspondances */ |