summaryrefslogtreecommitdiff
path: root/src/analysis/scan/matches
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-02-20 08:11:17 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-02-20 08:11:17 (GMT)
commit26f93f593542cc550107744e92f95e9516e7435e (patch)
tree058cf883324274965356beb42398c387c0e49217 /src/analysis/scan/matches
parent30e56f25772247d76c7775d32ccd5b5a0661d3bf (diff)
Share GObject instances between scan contexts and matches.
Diffstat (limited to 'src/analysis/scan/matches')
-rw-r--r--src/analysis/scan/matches/bytes-int.h10
-rw-r--r--src/analysis/scan/matches/bytes.c98
-rw-r--r--src/analysis/scan/matches/bytes.h5
3 files changed, 10 insertions, 103 deletions
diff --git a/src/analysis/scan/matches/bytes-int.h b/src/analysis/scan/matches/bytes-int.h
index d356208..f6239e3 100644
--- a/src/analysis/scan/matches/bytes-int.h
+++ b/src/analysis/scan/matches/bytes-int.h
@@ -37,12 +37,6 @@ struct _GScanBytesMatches
{
GScanMatches parent; /* A laisser en premier */
- GScanContext *context; /* Contexte de rattachement */
-
- // TODO : if NDEBUG ?
- phys_t content_start; /* Point de début du contenu */
- phys_t content_end; /* Point de fin du contenu */
-
match_area_t *areas; /* Zones couvertes */
size_t count; /* Nombre de zones */
@@ -56,9 +50,5 @@ struct _GScanBytesMatchesClass
};
-/* Met en place une série de correspondances avec des octets. */
-bool g_scan_bytes_matches_create(GScanBytesMatches *, GSearchPattern *, GScanContext *);
-
-
#endif /* _ANALYSIS_SCAN_MATCHES_BYTES_INT_H */
diff --git a/src/analysis/scan/matches/bytes.c b/src/analysis/scan/matches/bytes.c
index c4c43bc..218121d 100644
--- a/src/analysis/scan/matches/bytes.c
+++ b/src/analysis/scan/matches/bytes.c
@@ -117,11 +117,6 @@ static void g_scan_bytes_matches_class_init(GScanBytesMatchesClass *klass)
static void g_scan_bytes_matches_init(GScanBytesMatches *matches)
{
- matches->context = NULL;
-
- matches->content_start = VMPA_NO_PHYSICAL;
- matches->content_end = VMPA_NO_PHYSICAL;
-
matches->areas = NULL;
matches->count = 0;
@@ -142,8 +137,6 @@ static void g_scan_bytes_matches_init(GScanBytesMatches *matches)
static void g_scan_bytes_matches_dispose(GScanBytesMatches *matches)
{
- //g_clear_object(&matches->context);
-
G_OBJECT_CLASS(g_scan_bytes_matches_parent_class)->dispose(G_OBJECT(matches));
}
@@ -170,8 +163,7 @@ static void g_scan_bytes_matches_finalize(GScanBytesMatches *matches)
/******************************************************************************
* *
-* Paramètres : source = lien vers le motif recherché d'origine. *
-* context = contexte associé au scan courant. *
+* Paramètres : - *
* *
* Description : Crée un suivi pour série de correspondances avec des octets. *
* *
@@ -181,87 +173,12 @@ static void g_scan_bytes_matches_finalize(GScanBytesMatches *matches)
* *
******************************************************************************/
-GScanMatches *g_scan_bytes_matches_new(GSearchPattern *source, GScanContext *context)
+GScanMatches *g_scan_bytes_matches_new(void)
{
GScanMatches *result; /* Structure à retourner */
result = g_object_new(G_TYPE_SCAN_BYTES_MATCHES, NULL);
- if (!g_scan_bytes_matches_create(G_SCAN_BYTES_MATCHES(result), source, context))
- g_clear_object(&result);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : matches = instance à initialiser pleinement. *
-* source = lien vers le motif recherché d'origine. *
-* context = contexte associé au scan courant. *
-* *
-* Description : Met en place une série de correspondances avec des octets. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool g_scan_bytes_matches_create(GScanBytesMatches *matches, GSearchPattern *source, GScanContext *context)
-{
- bool result; /* Bilan à retourner */
- GScanMatches *base; /* Lien vers les infos de base */
- GBinContent *content; /* Contenu à manipuler */
- vmpa2t start; /* Point de début du contenu */
- vmpa2t end; /* Point de fin du contenu */
-
- result = true;
-
- base = G_SCAN_MATCHES(matches);
-
- base->source = source;
- g_object_ref(G_OBJECT(source));
-
- matches->context = context;
- //g_object_ref(G_OBJECT(context));
-
- content = g_scan_context_get_content(context);
-
- g_binary_content_compute_start_pos(content, &start);
- g_binary_content_compute_end_pos(content, &end);
-
- matches->content_start = start.physical;
- matches->content_end = end.physical;
-
- g_object_unref(G_OBJECT(content));
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : matches = informations de correspondances à consulter. *
-* *
-* Description : Fournit le contexte du scan associé aux correspondances. *
-* *
-* Retour : Contexte de scan courant. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GScanContext *g_scan_bytes_matches_get_context(const GScanBytesMatches *matches)
-{
- GScanContext *result; /* Instance à retourner */
-
- result = matches->context;
-
- g_object_ref(G_OBJECT(result));
-
return result;
}
@@ -433,8 +350,8 @@ char *g_scan_bytes_matches_get_modifier_path(const GScanBytesMatches *matches)
static void g_scan_bytes_matches_output_to_text(const GScanBytesMatches *matches, int fd)
{
- GBinContent *content; /* Contenu binaire analysé */
GScanMatches *base; /* Lien vers les infos de base */
+ GBinContent *content; /* Contenu binaire analysé */
const char *name; /* Désignation du motif ciblé */
match_area_t *iter; /* Boucle de parcours #1 */
char value[2 + ULLONG_MAXLEN]; /* Impression de la position */
@@ -444,10 +361,10 @@ static void g_scan_bytes_matches_output_to_text(const GScanBytesMatches *matches
const bin_t *data; /* Accès aux données brutes */
phys_t k; /* Boucle de parcours #2 */
- content = g_scan_context_get_content(matches->context);
-
base = G_SCAN_MATCHES(matches);
+ content = g_scan_context_get_content(base->context);
+
name = g_search_pattern_get_name(base->source);
for_each_match_area(iter, matches->areas)
@@ -547,6 +464,7 @@ static void g_scan_bytes_matches_output_to_json(const GScanBytesMatches *matches
unsigned int i; /* Boucle de parcours #1 */
char value[4 + ULLONG_MAXLEN]; /* Impression de la position */
int ret; /* Bilan d'une conversion */
+ GScanMatches *base; /* Lien vers les infos de base */
GBinContent *content; /* Contenu binaire analysé */
match_area_t *iter; /* Boucle de parcours #1 */
vmpa2t pos; /* Tête de lecture */
@@ -581,7 +499,9 @@ static void g_scan_bytes_matches_output_to_json(const GScanBytesMatches *matches
write(fd, "\"matches\": [\n", 13);
- content = g_scan_context_get_content(matches->context);
+ base = G_SCAN_MATCHES(matches);
+
+ content = g_scan_context_get_content(base->context);
for_each_match_area(iter, matches->areas)
{
diff --git a/src/analysis/scan/matches/bytes.h b/src/analysis/scan/matches/bytes.h
index 9e046aa..50f60a4 100644
--- a/src/analysis/scan/matches/bytes.h
+++ b/src/analysis/scan/matches/bytes.h
@@ -56,10 +56,7 @@ typedef struct _GScanBytesMatchesClass GScanBytesMatchesClass;
GType g_scan_bytes_matches_get_type(void);
/* Crée un suivi pour série de correspondances avec des octets. */
-GScanMatches *g_scan_bytes_matches_new(GSearchPattern *, GScanContext *);
-
-/* Fournit le contexte du scan associé aux correspondances. */
-GScanContext *g_scan_bytes_matches_get_context(const GScanBytesMatches *);
+GScanMatches *g_scan_bytes_matches_new(void);
/* Intègre une liste de correspondances vérifiées. */
void g_scan_bytes_matches_set_list(GScanBytesMatches *, match_area_t *, size_t);