diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2024-01-21 22:36:47 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2024-01-21 22:36:47 (GMT) |
commit | 0ff1e52622828663d01f98c97f2cd8eccb8facf8 (patch) | |
tree | 88b5fcf2412f863276876d0b8ad8db91903f3758 /src/analysis/scan/exprs | |
parent | 0fac40d5a5752e8d7b92f57ea3cfa089f13a2d1f (diff) |
Refactor the scan match storage.
Diffstat (limited to 'src/analysis/scan/exprs')
-rw-r--r-- | src/analysis/scan/exprs/handler.c | 55 | ||||
-rw-r--r-- | src/analysis/scan/exprs/handler.h | 4 | ||||
-rw-r--r-- | src/analysis/scan/exprs/setcounter.c | 15 |
3 files changed, 47 insertions, 27 deletions
diff --git a/src/analysis/scan/exprs/handler.c b/src/analysis/scan/exprs/handler.c index ecc5a21..d40d00f 100644 --- a/src/analysis/scan/exprs/handler.c +++ b/src/analysis/scan/exprs/handler.c @@ -268,6 +268,8 @@ ScanHandlerType g_scan_pattern_handler_get_handler_type(const GScanPatternHandle } +#if 0 /* FIXME */ + /****************************************************************************** * * * Paramètres : handler = instance à initialiser pleinement. * @@ -323,6 +325,7 @@ GScanMatch **g_scan_pattern_handler_get_all_matches(const GScanPatternHandler *h return result; } +#endif @@ -425,7 +428,6 @@ static bool g_scan_pattern_handler_reduce_to_boolean(const GScanPatternHandler * static bool g_scan_pattern_handler_count_items(const GScanPatternHandler *expr, GScanContext *ctx, size_t *count) { bool result; /* Bilan à retourner */ - size_t partial; /* Décompte partiel */ size_t i; /* Boucle de parcours */ result = true; @@ -435,10 +437,7 @@ static bool g_scan_pattern_handler_count_items(const GScanPatternHandler *expr, *count = 0; for (i = 0; i < expr->count; i++) - { - g_scan_context_get_full_matches(ctx, expr->patterns[i], &partial); - *count += partial; - } + *count += g_scan_context_count_full_matches(ctx, expr->patterns[i]); return result; @@ -465,11 +464,8 @@ static bool g_scan_pattern_handler_get_item(const GScanPatternHandler *expr, siz bool result; /* Bilan à retourner */ size_t i; /* Boucle de parcours */ size_t count; /* Quantité de correspondances */ - const GScanMatch **matches; /* Correspondances en place */ - const GScanBytesMatch *match; /* Correspondance ciblée */ - phys_t start; /* Point de départ du motif */ - phys_t end; /* Point d'arrivée du motif */ - phys_t len; /* Taille du motif */ + GScanBytesMatches *matches; /* Correspondances d'un motif */ + const match_area_t *area; /* Zone de correspondance */ GBinContent *content; /* Contenu binaire à relire */ vmpa2t pos; /* Tête de lecture */ const bin_t *data; /* Accès aux données brutes */ @@ -483,7 +479,7 @@ static bool g_scan_pattern_handler_get_item(const GScanPatternHandler *expr, siz for (i = 0; i < expr->count; i++) { - matches = g_scan_context_get_full_matches(ctx, expr->patterns[i], &count); + count = g_scan_context_count_full_matches(ctx, expr->patterns[i]); if (index < count) break; @@ -494,51 +490,62 @@ static bool g_scan_pattern_handler_get_item(const GScanPatternHandler *expr, siz if (i == expr->count) goto done; - result = G_IS_SCAN_BYTES_MATCH(matches[index]); - if (!result) goto done; + /* Identification de la correspondance concernée */ - match = G_SCAN_BYTES_MATCH(matches[index]); + matches = g_scan_context_get_full_matches(ctx, expr->patterns[i]); + if (matches == NULL) goto done; - /* Traitement adapté de la requête */ + area = g_scan_bytes_matches_get(matches, index); + if (area == NULL) goto done_with_matches; - len = g_scan_bytes_match_get_location(match, &start, &end); + /* Traitement adapté de la requête */ switch (expr->type) { case SHT_RAW: - content = g_scan_bytes_match_get_content(match); + content = g_scan_context_get_content(ctx); - init_vmpa(&pos, start, VMPA_NO_VIRTUAL); + init_vmpa(&pos, area->start, VMPA_NO_VIRTUAL); - data = g_binary_content_get_raw_access(content, &pos, len); + data = g_binary_content_get_raw_access(content, &pos, area->end - area->start); binary.static_bin_data = data; - binary.len = len; + binary.len = area->end - area->start; *out = g_scan_literal_expression_new(LVT_STRING, &binary); g_object_unref(G_OBJECT(content)); + result = true; break; case SHT_COUNTER: assert(false); - result = false; break; case SHT_START: - *out = g_scan_literal_expression_new(LVT_UNSIGNED_INTEGER, (unsigned long long []){ start }); + *out = g_scan_literal_expression_new(LVT_UNSIGNED_INTEGER, + (unsigned long long []){ area->start }); + result = true; break; case SHT_LENGTH: - *out = g_scan_literal_expression_new(LVT_UNSIGNED_INTEGER, (unsigned long long []){ len }); + *out = g_scan_literal_expression_new(LVT_UNSIGNED_INTEGER, + (unsigned long long []){ area->end - area->start }); + result = true; break; case SHT_END: - *out = g_scan_literal_expression_new(LVT_UNSIGNED_INTEGER, (unsigned long long []){ end }); + *out = g_scan_literal_expression_new(LVT_UNSIGNED_INTEGER, + (unsigned long long []){ area->end }); + result = true; break; } + done_with_matches: + + g_object_unref(G_OBJECT(matches)); + done: return result; diff --git a/src/analysis/scan/exprs/handler.h b/src/analysis/scan/exprs/handler.h index 24c4e8f..96e9301 100644 --- a/src/analysis/scan/exprs/handler.h +++ b/src/analysis/scan/exprs/handler.h @@ -65,9 +65,13 @@ GScanExpression *g_scan_pattern_handler_new(GSearchPattern ** const, size_t, Sca /* Indique le type de manipulation de correspondances spécifié. */ ScanHandlerType g_scan_pattern_handler_get_handler_type(const GScanPatternHandler *); +#if 0 /* FIXME */ + /* Fournit la liste de toutes les correspondances représentées. */ GScanMatch **g_scan_pattern_handler_get_all_matches(const GScanPatternHandler *, GScanContext *, size_t *); +#endif + #endif /* _ANALYSIS_SCAN_EXPRS_HANDLER_H */ diff --git a/src/analysis/scan/exprs/setcounter.c b/src/analysis/scan/exprs/setcounter.c index 14e7676..da37746 100644 --- a/src/analysis/scan/exprs/setcounter.c +++ b/src/analysis/scan/exprs/setcounter.c @@ -319,6 +319,7 @@ static ScanReductionState g_scan_set_match_counter_reduce(const GScanSetMatchCou ScanReductionState result; /* Etat synthétisé à retourner */ size_t matched; /* Qté de motifs avec résultats*/ size_t i; /* Boucle de parcours */ + GScanMatches *matches; /* Série de correspondances */ size_t count; /* Quantité de correspondances */ bool status; /* Bilan d'évaluation finale */ @@ -328,10 +329,18 @@ static ScanReductionState g_scan_set_match_counter_reduce(const GScanSetMatchCou for (i = 0; i < expr->count; i++) { - g_scan_context_get_full_matches(ctx, expr->patterns[i], &count); + matches = g_scan_context_get_full_matches(ctx, expr->patterns[i]); - if (count > 0) - matched++; + if (matches != NULL) + { + count = g_scan_matches_count(matches); + + if (count > 0) + matched++; + + g_object_unref(G_OBJECT(matches)); + + } } |