diff options
Diffstat (limited to 'src/analysis/scan/patterns/token.c')
-rw-r--r-- | src/analysis/scan/patterns/token.c | 176 |
1 files changed, 100 insertions, 76 deletions
diff --git a/src/analysis/scan/patterns/token.c b/src/analysis/scan/patterns/token.c index e5eb287..76a5e66 100644 --- a/src/analysis/scan/patterns/token.c +++ b/src/analysis/scan/patterns/token.c @@ -248,7 +248,6 @@ bool g_bytes_token_is_private(const GBytesToken *token) /****************************************************************************** * * * 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). * * * @@ -260,13 +259,37 @@ bool g_bytes_token_is_private(const GBytesToken *token) * * ******************************************************************************/ -bool g_bytes_token_enroll(GBytesToken *token, GScanContext *context, GEngineBackend *backend, size_t maxsize) +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, context, backend, maxsize, &token->slow); + 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; @@ -276,8 +299,6 @@ bool g_bytes_token_enroll(GBytesToken *token, GScanContext *context, GEngineBack /****************************************************************************** * * * Paramètres : token = définition de la bribe à manipuler. * -* context = contexte de l'analyse à mener. * -* content = accès au contenu brut pour vérifications (optim.) * * matches = suivi des correspondances à consolider. * * * * Description : Transforme les correspondances locales en trouvailles. * @@ -288,60 +309,98 @@ bool g_bytes_token_enroll(GBytesToken *token, GScanContext *context, GEngineBack * * ******************************************************************************/ -void g_bytes_token_check(const GBytesToken *token, GScanContext *context, GBinContent *content, pending_matches_t *matches) +void g_bytes_token_check(const GBytesToken *token, GScanBytesMatches *matches) { - size_t p; /* Boucle de parcours #3 */ - match_area_t *pending; /* Correspondance à traiter */ + scan_node_check_params_t params; /* Rassemblement de paramètres */ + vmpa2t start; /* Point de début du contenu */ + vmpa2t end; /* Point de fin du contenu */ + match_area_t *area; /* Correspondance à valider */ + match_area_t *next; /* Correspondance suivante */ vmpa2t pos; /* Tête de lecture */ const bin_t *byte; /* Octet à valider */ - g_scan_token_node_check_forward(token->root, context, content, matches); + /* Définition d'un contexte */ + + params.context = g_scan_bytes_matches_get_context(matches); + params.content = g_scan_context_get_content(params.context); + params.allocator = g_umem_slice_new(sizeof(match_area_t)); + + g_binary_content_compute_start_pos(params.content, &start); + g_binary_content_compute_end_pos(params.content, &end); + + params.content_start = start.physical; + params.content_end = end.physical; + + // 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, ¶ms); if (token->need_backward) - g_scan_token_node_check_backward(token->root, context, content, matches); + g_scan_token_node_check_backward(token->root, ¶ms); - sort_and_filter_pending_matches(matches); + // REMME ? sort_and_filter_pending_matches(matches); if (token->fullword) { - reset_pending_matches_ttl(matches); - - for (p = 0; p < matches->used; p++) + for_each_match_area_safe(area, ¶ms.main_areas, next) { - pending = &matches->areas[p]; - /* Validation de l'octet précédent, s'il existe */ - if (pending->start > matches->content_start) + if (area->start > params.content_start) { - init_vmpa(&pos, pending->start - 1, VMPA_NO_VIRTUAL); + init_vmpa(&pos, area->start - 1, VMPA_NO_VIRTUAL); - byte = g_binary_content_get_raw_access(content, &pos, 1); + byte = g_binary_content_get_raw_access(params.content, &pos, 1); if (isalnum(*byte)) + { + del_match_area(area, ¶ms.main_areas); + assert(¶ms.main_count > 0); + params.main_count--; continue; + } } /* Validation de l'octet suivant, s'il existe */ - if (pending->end < matches->content_end) + if (area->end < params.content_end) { - init_vmpa(&pos, pending->end, VMPA_NO_VIRTUAL); + init_vmpa(&pos, area->end, VMPA_NO_VIRTUAL); - byte = g_binary_content_get_raw_access(content, &pos, 1); + byte = g_binary_content_get_raw_access(params.content, &pos, 1); if (isalnum(*byte)) + { + del_match_area(area, ¶ms.main_areas); + assert(¶ms.main_count > 0); + params.main_count--; continue; + } } - keep_pending_match(pending); - } - purge_pending_matches(matches); - } + g_scan_bytes_matches_set_list(matches, params.main_areas, params.main_count); + + g_object_unref(G_OBJECT(params.context)); + g_object_unref(G_OBJECT(params.content)); + //g_object_unref(G_OBJECT(params.allocator)); + } @@ -394,17 +453,20 @@ char *g_bytes_token_get_modifier_path(const GBytesToken *token, size_t index) static void g_bytes_token_output_to_text(const GBytesToken *pattern, GScanContext *context, int fd) { - const GScanMatch **matches; /* Correspondances établies */ - size_t count; /* Quantité de cette liste */ - size_t i; /* Boucle de parcours */ + GScanMatches *matches; /* Correspondances établies */ if (g_bytes_token_is_private(pattern)) return; - matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern), &count); + matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern)); - for (i = 0; i < count; i++) - g_scan_match_output_to_text(matches[i], fd); + if (matches != NULL) + { + g_scan_matches_output_to_text(matches, fd); + + g_object_unref(G_OBJECT(matches)); + + } } @@ -427,57 +489,19 @@ static void g_bytes_token_output_to_text(const GBytesToken *pattern, GScanContex static void g_bytes_token_output_to_json(const GBytesToken *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 */ + GScanMatches *matches; /* Correspondances établies */ if (g_bytes_token_is_private(pattern)) return; - 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); + matches = g_scan_context_get_full_matches(context, G_SEARCH_PATTERN(pattern)); - 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++) + if (matches != NULL) { - trailing = ((k + 1) < count); - - g_scan_match_output_to_json(matches[k], padding, level + 1, fd, trailing); + g_scan_matches_output_to_json(matches, padding, level, fd); + + g_object_unref(G_OBJECT(matches)); } - for (i = 0; i < level; i++) - write(fd, padding->data, padding->len); - - write(fd, "]\n", 2); - } |