summaryrefslogtreecommitdiff
path: root/src/analysis/scan/exprs/handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/scan/exprs/handler.c')
-rw-r--r--src/analysis/scan/exprs/handler.c87
1 files changed, 78 insertions, 9 deletions
diff --git a/src/analysis/scan/exprs/handler.c b/src/analysis/scan/exprs/handler.c
index d40d00f..2706dae 100644
--- a/src/analysis/scan/exprs/handler.c
+++ b/src/analysis/scan/exprs/handler.c
@@ -124,6 +124,7 @@ static void g_scan_pattern_handler_init(GScanPatternHandler *handler)
{
handler->patterns = NULL;
handler->count = 0;
+ handler->shared = true;
handler->type = SHT_RAW;
@@ -146,8 +147,9 @@ static void g_scan_pattern_handler_dispose(GScanPatternHandler *handler)
{
size_t i; /* Boucle de parcours */
- for (i = 0; i < handler->count; i++)
- g_clear_object(&handler->patterns[i]);
+ if (!handler->shared)
+ for (i = 0; i < handler->count; i++)
+ g_clear_object(&handler->ref_patterns[i]);
G_OBJECT_CLASS(g_scan_pattern_handler_parent_class)->dispose(G_OBJECT(handler));
@@ -190,13 +192,79 @@ static void g_scan_pattern_handler_finalize(GScanPatternHandler *handler)
* *
******************************************************************************/
+GScanExpression *g_scan_pattern_handler_new_shared(const GSearchPattern ** const patterns, size_t count, ScanHandlerType type)
+{
+ GScanExpression *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_SCAN_PATTERN_HANDLER, NULL);
+
+ if (!g_scan_pattern_handler_create_shared(G_SCAN_PATTERN_HANDLER(result), patterns, count, type))
+ g_clear_object(&result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : handler = instance à initialiser pleinement. *
+* patterns = motifs à impliquer. *
+* count = quantité de ces motifs. *
+* type = type de manipulation attendue. *
+* *
+* Description : Met en place une manipulation de correspondances établies. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_scan_pattern_handler_create_shared(GScanPatternHandler *handler, const GSearchPattern ** const patterns, size_t count, ScanHandlerType type)
+{
+ bool result; /* Bilan à retourner */
+
+ result = g_scan_expression_create(G_SCAN_EXPRESSION(handler), SRS_WAIT_FOR_SCAN);
+ if (!result) goto exit;
+
+ handler->patterns = malloc(count * sizeof(GSearchPattern *));
+ handler->count = count;
+
+ memcpy(handler->patterns, patterns, count * sizeof(GSearchPattern *));
+
+ handler->shared = true;
+
+ handler->type = type;
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : patterns = motifs à impliquer. *
+* count = quantité de ces motifs. *
+* type = type de manipulation attendue. *
+* *
+* Description : Met en place une manipulation de correspondances établies. *
+* *
+* Retour : Expression mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
GScanExpression *g_scan_pattern_handler_new(GSearchPattern ** const patterns, size_t count, ScanHandlerType type)
{
GScanExpression *result; /* Structure à retourner */
result = g_object_new(G_TYPE_SCAN_PATTERN_HANDLER, NULL);
- if (!g_scan_pattern_handler_create(G_SCAN_PATTERN_HANDLER(result), patterns, count, type))
+ if (!g_scan_pattern_handler_create_and_ref(G_SCAN_PATTERN_HANDLER(result), patterns, count, type))
g_clear_object(&result);
return result;
@@ -219,7 +287,7 @@ GScanExpression *g_scan_pattern_handler_new(GSearchPattern ** const patterns, si
* *
******************************************************************************/
-bool g_scan_pattern_handler_create(GScanPatternHandler *handler, GSearchPattern ** const patterns, size_t count, ScanHandlerType type)
+bool g_scan_pattern_handler_create_and_ref(GScanPatternHandler *handler, GSearchPattern ** const patterns, size_t count, ScanHandlerType type)
{
bool result; /* Bilan à retourner */
size_t i; /* Boucle de parcours */
@@ -230,11 +298,12 @@ bool g_scan_pattern_handler_create(GScanPatternHandler *handler, GSearchPattern
handler->patterns = malloc(count * sizeof(GSearchPattern *));
handler->count = count;
+ memcpy(handler->patterns, patterns, count * sizeof(GSearchPattern *));
+
for (i = 0; i < count; i++)
- {
- handler->patterns[i] = patterns[i];
g_object_ref(G_OBJECT(patterns[i]));
- }
+
+ handler->shared = false;
handler->type = type;
@@ -464,7 +533,7 @@ 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 */
- GScanBytesMatches *matches; /* Correspondances d'un motif */
+ GScanMatches *matches; /* Correspondances d'un motif */
const match_area_t *area; /* Zone de correspondance */
GBinContent *content; /* Contenu binaire à relire */
vmpa2t pos; /* Tête de lecture */
@@ -495,7 +564,7 @@ static bool g_scan_pattern_handler_get_item(const GScanPatternHandler *expr, siz
matches = g_scan_context_get_full_matches(ctx, expr->patterns[i]);
if (matches == NULL) goto done;
- area = g_scan_bytes_matches_get(matches, index);
+ area = g_scan_bytes_matches_get(G_SCAN_BYTES_MATCHES(matches), index);
if (area == NULL) goto done_with_matches;
/* Traitement adapté de la requête */