diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2023-10-22 12:21:44 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2023-10-22 12:21:44 (GMT) |
commit | 98dab5148243637a4f2d19a7c44b0e643a0e0f8c (patch) | |
tree | aa5f22f47e01f5ff7f2e0239cae9949ab6354ac9 | |
parent | c370bb014b20654a2b7351b2a9d7e1e5a3ce92cc (diff) |
Provide the size of a rule without recomputing it.
-rw-r--r-- | plugins/pychrysalide/analysis/scan/core.c | 12 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/scan/scanner.c | 6 | ||||
-rw-r--r-- | src/analysis/scan/scanner-int.h | 2 | ||||
-rw-r--r-- | src/analysis/scan/scanner.c | 13 | ||||
-rw-r--r-- | src/analysis/scan/scanner.h | 2 | ||||
-rw-r--r-- | src/rost.c | 21 |
6 files changed, 22 insertions, 34 deletions
diff --git a/plugins/pychrysalide/analysis/scan/core.c b/plugins/pychrysalide/analysis/scan/core.c index dcf5bf8..16df9a9 100644 --- a/plugins/pychrysalide/analysis/scan/core.c +++ b/plugins/pychrysalide/analysis/scan/core.c @@ -37,18 +37,6 @@ -/* #include <malloc.h> */ - -/* #include <i18n.h> */ -/* #include <arch/processor.h> */ -/* #include <core/processors.h> */ - -/* #include "../core.h" */ - -/* #include "../arch/processor.h" */ - - - /* Inscrit un modificateur dans la liste des disponibles. */ static PyObject *py_scan_register_token_modifier(PyObject *, PyObject *); diff --git a/plugins/pychrysalide/analysis/scan/scanner.c b/plugins/pychrysalide/analysis/scan/scanner.c index e2d5a18..bc58c9a 100644 --- a/plugins/pychrysalide/analysis/scan/scanner.c +++ b/plugins/pychrysalide/analysis/scan/scanner.c @@ -76,6 +76,7 @@ static PyObject *py_content_scanner_get_filename(PyObject *, void *); static int py_content_scanner_init(PyObject *self, PyObject *args, PyObject *kwds) { const char *text; /* Contenu de règles à traiter */ + Py_ssize_t len; /* Taille de ce nom */ const char *filename; /* Fichier de définitions */ int ret; /* Bilan de lecture des args. */ GContentScanner *scanner; /* Création GLib à transmettre */ @@ -100,9 +101,10 @@ static int py_content_scanner_init(PyObject *self, PyObject *args, PyObject *kwd /* Récupération des paramètres */ text = NULL; + len = 0; filename = NULL; - ret = PyArg_ParseTupleAndKeywords(args, kwds, "|ss", kwlist, &text, &filename); + ret = PyArg_ParseTupleAndKeywords(args, kwds, "|s#s", kwlist, &text, &len, &filename); if (!ret) return -1; /* Initialisation d'un objet GLib */ @@ -116,7 +118,7 @@ static int py_content_scanner_init(PyObject *self, PyObject *args, PyObject *kwd if (text != NULL) { - if (!g_content_scanner_create_from_text(scanner, text)) + if (!g_content_scanner_create_from_text(scanner, text, len)) { PyErr_SetString(PyExc_ValueError, _("Unable to create content scanner.")); return -1; diff --git a/src/analysis/scan/scanner-int.h b/src/analysis/scan/scanner-int.h index 4fcda87..02fd6b3 100644 --- a/src/analysis/scan/scanner-int.h +++ b/src/analysis/scan/scanner-int.h @@ -55,7 +55,7 @@ struct _GContentScannerClass /* Met en place un scanner de contenus binaires. */ -bool g_content_scanner_create_from_text(GContentScanner *, const char *); +bool g_content_scanner_create_from_text(GContentScanner *, const char *, size_t); /* Met en place un scanner de contenus binaires. */ bool g_content_scanner_create_from_file(GContentScanner *, const char *); diff --git a/src/analysis/scan/scanner.c b/src/analysis/scan/scanner.c index 57fe0d9..1f90393 100644 --- a/src/analysis/scan/scanner.c +++ b/src/analysis/scan/scanner.c @@ -163,7 +163,8 @@ static void g_content_scanner_finalize(GContentScanner *scanner) /****************************************************************************** * * -* Paramètres : text = définitions textuelles de règles de recherche. * +* Paramètres : text = définitions textuelles de règles de recherche. * +* length = taille de la définition. * * * * Description : Prépare une recherche de motifs dans du contenu binaire. * * * @@ -173,13 +174,13 @@ static void g_content_scanner_finalize(GContentScanner *scanner) * * ******************************************************************************/ -GContentScanner *g_content_scanner_new_from_text(const char *text) +GContentScanner *g_content_scanner_new_from_text(const char *text, size_t length) { GContentScanner *result; /* Structure à retourner */ result = g_object_new(G_TYPE_CONTENT_SCANNER, NULL); - if (!g_content_scanner_create_from_text(result, text)) + if (!g_content_scanner_create_from_text(result, text, length)) g_clear_object(&result); return result; @@ -191,6 +192,7 @@ GContentScanner *g_content_scanner_new_from_text(const char *text) * * * Paramètres : scanner = scanner de contenus à initialiser pleinement. * * text = définitions textuelles de règles de recherche. * +* length = taille de la définition. * * * * Description : Met en place un scanner de contenus binaires. * * * @@ -200,12 +202,9 @@ GContentScanner *g_content_scanner_new_from_text(const char *text) * * ******************************************************************************/ -bool g_content_scanner_create_from_text(GContentScanner *scanner, const char *text) +bool g_content_scanner_create_from_text(GContentScanner *scanner, const char *text, size_t length) { bool result; /* Bilan à retourner */ - size_t length; /* Taille de la définition */ - - length = strlen(text); result = process_rules_definitions(scanner, text, length); diff --git a/src/analysis/scan/scanner.h b/src/analysis/scan/scanner.h index e03ecda..7926ba1 100644 --- a/src/analysis/scan/scanner.h +++ b/src/analysis/scan/scanner.h @@ -55,7 +55,7 @@ typedef struct _GContentScannerClass GContentScannerClass; GType g_content_scanner_get_type(void); /* Prépare une recherche de motifs dans du contenu binaire. */ -GContentScanner *g_content_scanner_new_from_text(const char *); +GContentScanner *g_content_scanner_new_from_text(const char *, size_t); /* Prépare une recherche de motifs dans du contenu binaire. */ GContentScanner *g_content_scanner_new_from_file(const char *); @@ -34,7 +34,6 @@ #include <i18n.h> - #include "gleak.h" #include "analysis/contents/file.h" #include "analysis/scan/options.h" @@ -56,7 +55,7 @@ static void show_rost_help(const char *); static void show_rost_version(void); /* Récupère un contenu à traiter depuis l'entrée standard. */ -static void *get_input_data_from_stdin(void); +static void *get_input_data_from_stdin(size_t *); @@ -150,7 +149,7 @@ static void show_rost_version(void) /****************************************************************************** * * -* Paramètres : - * +* Paramètres : length = taille de la définition lue. [OUT] * * * * Description : Récupère un contenu à traiter depuis l'entrée standard. * * * @@ -160,23 +159,22 @@ static void show_rost_version(void) * * ******************************************************************************/ -static void *get_input_data_from_stdin(void) +static void *get_input_data_from_stdin(size_t *length) { char *result; /* Espace mémoire à retourner */ - size_t length; /* Taille de ce contenu */ ssize_t got; /* Quantité d'octets lus */ result = NULL; - length = 0; + *length = 0; #define ALLOC_SIZE 2048 while (true) { - result = realloc(result, (length + ALLOC_SIZE) * sizeof(char)); + result = realloc(result, (*length + ALLOC_SIZE) * sizeof(char)); - got = read(STDIN_FILENO, result + length, ALLOC_SIZE); + got = read(STDIN_FILENO, result + *length, ALLOC_SIZE); if (got == -1) { @@ -184,7 +182,7 @@ static void *get_input_data_from_stdin(void) goto exit_with_error; } - length += got; + *length += got; if (got < ALLOC_SIZE) break; @@ -228,6 +226,7 @@ int main(int argc, char **argv) char *edir; /* Répertoire de base effectif */ char *rules; /* Définition de règles */ char *target; /* Cible communiquée */ + size_t rule_length; /* Taille d'un contenu */ void *rule_content; /* Contenu à traduire */ GContentScanner *scanner; /* Encadrement d'une recherche */ GBinContent *content; /* Contenu à analyser */ @@ -407,11 +406,11 @@ int main(int argc, char **argv) if (rules == NULL) { - rule_content = get_input_data_from_stdin(); + rule_content = get_input_data_from_stdin(&rule_length); if (rule_content != NULL) { - scanner = g_content_scanner_new_from_text(rule_content); + scanner = g_content_scanner_new_from_text(rule_content, rule_length); free(rule_content); } else |