diff options
Diffstat (limited to 'src/analysis/scan/matches/bytes.c')
| -rw-r--r-- | src/analysis/scan/matches/bytes.c | 577 |
1 files changed, 351 insertions, 226 deletions
diff --git a/src/analysis/scan/matches/bytes.c b/src/analysis/scan/matches/bytes.c index de101c4..a23188b 100644 --- a/src/analysis/scan/matches/bytes.c +++ b/src/analysis/scan/matches/bytes.c @@ -30,53 +30,57 @@ #include "bytes-int.h" +#include "../patterns/token.h" #include "../../../common/cpp.h" #include "../../../core/logs.h" -/* --------------------- CORRESPONDANCE AVEC UNE SUITE D'OCTETS --------------------- */ +/* -------------------- CONSERVATION DE CORRESPONDANCES ETABLIES -------------------- */ -/* Initialise la classe des correspondances de chaînes. */ -static void g_scan_bytes_match_class_init(GScanBytesMatchClass *); +/* Initialise la classe des séries de correspondances d'octets. */ +static void g_scan_bytes_matches_class_init(GScanBytesMatchesClass *); -/* Initialise une instance de correspondance de chaîne trouvée. */ -static void g_scan_bytes_match_init(GScanBytesMatch *); +/* Initialise une instance de série de correspondances trouvées. */ +static void g_scan_bytes_matches_init(GScanBytesMatches *); /* Supprime toutes les références externes. */ -static void g_scan_bytes_match_dispose(GScanBytesMatch *); +static void g_scan_bytes_matches_dispose(GScanBytesMatches *); /* Procède à la libération totale de la mémoire. */ -static void g_scan_bytes_match_finalize(GScanBytesMatch *); +static void g_scan_bytes_matches_finalize(GScanBytesMatches *); /* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ +/* Dénombre les correspondances enregistrées pour un motif. */ +static size_t g_scan_bytes_matches_count(const GScanBytesMatches *); + /* Affiche une correspondance au format texte. */ -static void g_scan_bytes_match_output_to_text(const GScanBytesMatch *, int); +static void g_scan_bytes_matches_output_to_text(const GScanBytesMatches *, int); /* Affiche une correspondance au format JSON. */ -static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *, const sized_string_t *, unsigned int, int); +static void g_scan_bytes_matches_output_to_json(const GScanBytesMatches *, const sized_string_t *, unsigned int, int); /* ---------------------------------------------------------------------------------- */ -/* CORRESPONDANCE AVEC UNE SUITE D'OCTETS */ +/* CONSERVATION DE CORRESPONDANCES ETABLIES */ /* ---------------------------------------------------------------------------------- */ -/* Indique le type défini pour un correspondance de chaîne identifiée. */ -G_DEFINE_TYPE(GScanBytesMatch, g_scan_bytes_match, G_TYPE_SCAN_MATCH); +/* Indique le type défini pour une série de correspondances d'octets identifiées. */ +G_DEFINE_TYPE(GScanBytesMatches, g_scan_bytes_matches, G_TYPE_SCAN_MATCHES); /****************************************************************************** * * * Paramètres : klass = classe à initialiser. * * * -* Description : Initialise la classe des correspondances de chaînes. * +* Description : Initialise la classe des séries de correspondances d'octets. * * * * Retour : - * * * @@ -84,29 +88,31 @@ G_DEFINE_TYPE(GScanBytesMatch, g_scan_bytes_match, G_TYPE_SCAN_MATCH); * * ******************************************************************************/ -static void g_scan_bytes_match_class_init(GScanBytesMatchClass *klass) +static void g_scan_bytes_matches_class_init(GScanBytesMatchesClass *klass) { GObjectClass *object; /* Autre version de la classe */ - GScanMatchClass *match; /* Version parente de la classe*/ + GScanMatchesClass *matches; /* Version parente de la classe*/ object = G_OBJECT_CLASS(klass); - object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_bytes_match_dispose; - object->finalize = (GObjectFinalizeFunc)g_scan_bytes_match_finalize; + object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_bytes_matches_dispose; + object->finalize = (GObjectFinalizeFunc)g_scan_bytes_matches_finalize; + + matches = G_SCAN_MATCHES_CLASS(klass); - match = G_SCAN_MATCH_CLASS(klass); + matches->count = (count_scan_matches_fc)g_scan_bytes_matches_count; - match->to_text = (output_scan_match_to_text_fc)g_scan_bytes_match_output_to_text; - match->to_json = (output_scan_match_to_json_fc)g_scan_bytes_match_output_to_json; + matches->to_text = (output_scan_matches_to_text_fc)g_scan_bytes_matches_output_to_text; + matches->to_json = (output_scan_matches_to_json_fc)g_scan_bytes_matches_output_to_json; } /****************************************************************************** * * -* Paramètres : match = instance à initialiser. * +* Paramètres : matches = instance à initialiser. * * * -* Description : Initialise une instance de correspondance de chaîne trouvée. * +* Description : Initialise une instance de série de correspondances trouvées.* * * * Retour : - * * * @@ -114,19 +120,17 @@ static void g_scan_bytes_match_class_init(GScanBytesMatchClass *klass) * * ******************************************************************************/ -static void g_scan_bytes_match_init(GScanBytesMatch *match) +static void g_scan_bytes_matches_init(GScanBytesMatches *matches) { - match->content = NULL; - - match->start = VMPA_NO_PHYSICAL; - match->len = VMPA_NO_PHYSICAL; + matches->areas = NULL; + matches->count = 0; } /****************************************************************************** * * -* Paramètres : match = instance d'objet GLib à traiter. * +* Paramètres : matches = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * @@ -136,18 +140,16 @@ static void g_scan_bytes_match_init(GScanBytesMatch *match) * * ******************************************************************************/ -static void g_scan_bytes_match_dispose(GScanBytesMatch *match) +static void g_scan_bytes_matches_dispose(GScanBytesMatches *matches) { - g_clear_object(&match->content); - - G_OBJECT_CLASS(g_scan_bytes_match_parent_class)->dispose(G_OBJECT(match)); + G_OBJECT_CLASS(g_scan_bytes_matches_parent_class)->dispose(G_OBJECT(matches)); } /****************************************************************************** * * -* Paramètres : match = instance d'objet GLib à traiter. * +* Paramètres : matches = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * @@ -157,21 +159,18 @@ static void g_scan_bytes_match_dispose(GScanBytesMatch *match) * * ******************************************************************************/ -static void g_scan_bytes_match_finalize(GScanBytesMatch *match) +static void g_scan_bytes_matches_finalize(GScanBytesMatches *matches) { - G_OBJECT_CLASS(g_scan_bytes_match_parent_class)->finalize(G_OBJECT(match)); + G_OBJECT_CLASS(g_scan_bytes_matches_parent_class)->finalize(G_OBJECT(matches)); } /****************************************************************************** * * -* Paramètres : source = lien vers le motif recherché d'origine. * -* content = contenu binaire présentant un motif reconnu. * -* start = position de départ d'un motif détecté. * -* len = taille du motif repéré. * +* Paramètres : - * * * -* Description : Prend note d'une correspondance trouvée avec un motif. * +* Description : Crée un suivi pour série de correspondances avec des octets. * * * * Retour : Correspondance mise en place. * * * @@ -179,14 +178,11 @@ static void g_scan_bytes_match_finalize(GScanBytesMatch *match) * * ******************************************************************************/ -GScanMatch *g_scan_bytes_match_new(GSearchPattern *source, GBinContent *content, phys_t start, phys_t len) +GScanMatches *g_scan_bytes_matches_new(void) { - GScanMatch *result; /* Structure à retourner */ - - result = g_object_new(G_TYPE_SCAN_BYTES_MATCH, NULL); + GScanMatches *result; /* Structure à retourner */ - if (!g_scan_bytes_match_create(G_SCAN_BYTES_MATCH(result), source, content, start, len)) - g_clear_object(&result); + result = g_object_new(G_TYPE_SCAN_BYTES_MATCHES, NULL); return result; @@ -195,62 +191,51 @@ GScanMatch *g_scan_bytes_match_new(GSearchPattern *source, GBinContent *content, /****************************************************************************** * * -* Paramètres : match = instance à initialiser pleinement. * -* source = lien vers le motif recherché d'origine. * -* content = contenu binaire présentant un motif reconnu. * -* start = position de départ d'un motif détecté. * -* len = taille du motif repéré. * +* Paramètres : matches = suivi de correspondances à manipuler. * +* list = correspondances établies à mémoriser. * +* count = taille de cette liste. * * * -* Description : Met en place une correspondance trouvée avec un motif. * +* Description : Intègre une liste de correspondances vérifiées. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -bool g_scan_bytes_match_create(GScanBytesMatch *match, GSearchPattern *source, GBinContent *content, phys_t start, phys_t len) +void g_scan_bytes_matches_set_list(GScanBytesMatches *matches, match_area_t *list, size_t count) { - bool result; /* Bilan à retourner */ - GScanMatch *base; /* Lien vers les infos de base */ - - result = true; - - base = G_SCAN_MATCH(match); - - base->source = source; - g_object_ref(G_OBJECT(source)); - - match->content = content; - g_object_ref(G_OBJECT(content)); + matches->areas = list; - match->start = start; - match->len = len; - - return result; + matches->count = count; } /****************************************************************************** * * -* Paramètres : match = informations de correspondance à consulter. * +* Paramètres : matches = suivi de correspondances à consulter. * +* index = indice de la correspondance recherchée. * * * -* Description : Fournit une référence au contenu lié à la correspondance. * +* Description : Fournit les informations relatives à une correspondance. * * * -* Retour : Content binaire associé au context. * +* Retour : Propritétés de la correspondance visée ou NULL pour un échec.* * * * Remarques : - * * * ******************************************************************************/ -GBinContent *g_scan_bytes_match_get_content(const GScanBytesMatch *match) +const match_area_t *g_scan_bytes_matches_get(const GScanBytesMatches *matches, size_t index) { - GBinContent *result; /* Instance à retourner */ + const match_area_t *result; /* Pointeur à retourner */ - result = match->content; + for_each_match_area(result, matches->areas) + { + if (index == 0) + break; + } - g_object_ref(G_OBJECT(result)); + assert(index == 0); return result; @@ -259,9 +244,10 @@ GBinContent *g_scan_bytes_match_get_content(const GScanBytesMatch *match) /****************************************************************************** * * -* Paramètres : match = informations de correspondance à consulter. * -* start = position de départ d'un motif détecté. [OUT] * -* end = position d'arrivée d'un motif détecté. [OUT] * +* Paramètres : matches = informations de correspondance à consulter. * +* index = indice de la correspondance visée. * +* start = position de départ d'un motif détecté. [OUT] * +* end = position d'arrivée d'un motif détecté. [OUT] * * * * Description : Indique la localisation d'une correspondance établie. * * * @@ -271,20 +257,61 @@ GBinContent *g_scan_bytes_match_get_content(const GScanBytesMatch *match) * * ******************************************************************************/ -phys_t g_scan_bytes_match_get_location(const GScanBytesMatch *match, phys_t *start, phys_t *end) +phys_t g_scan_bytes_matches_get_location(const GScanBytesMatches *matches, size_t index, phys_t *start, phys_t *end) { phys_t result; /* Taille à retourner */ + result = 0; + + /* result = match->len; *start = match->start; *end = match->start + result; + */ return result; } +/****************************************************************************** +* * +* Paramètres : matches = informations de correspondance à consulter. * +* * +* Description : Retrouve l'origine d'une correspondance à partir d'un indice.* +* * +* Retour : Version humainement lisible de la combinaison gagnante. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char *g_scan_bytes_matches_get_modifier_path(const GScanBytesMatches *matches) +{ + char *result; /* Combinaison à retourner */ + GBytesToken *pattern; /* Autre version du motif */ + + result = NULL; + + /* + + if (match->has_mod_path) + { + pattern = G_BYTES_TOKEN(G_SCAN_MATCH(match)->source); + result = g_bytes_token_get_modifier_path(pattern, match->mod_path_index); + } + + else + result = NULL; + */ + + return result; + +} + + + /* ---------------------------------------------------------------------------------- */ /* IMPLEMENTATION DES FONCTIONS DE CLASSE */ /* ---------------------------------------------------------------------------------- */ @@ -292,8 +319,31 @@ phys_t g_scan_bytes_match_get_location(const GScanBytesMatch *match, phys_t *sta /****************************************************************************** * * -* Paramètres : match = définition de correspondance à manipuler. * -* fd = canal d'écriture. * +* Paramètres : matches = suivi de correspondances à consulter. * +* * +* Description : Dénombre les correspondances enregistrées pour un motif. * +* * +* Retour : Quantité de correspondances établies. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static size_t g_scan_bytes_matches_count(const GScanBytesMatches *matches) +{ + size_t result; /* Quantité à retourner */ + + result = matches->count; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : matches = définition de correspondance à manipuler. * +* fd = canal d'écriture. * * * * Description : Affiche une correspondance au format texte. * * * @@ -303,91 +353,105 @@ phys_t g_scan_bytes_match_get_location(const GScanBytesMatch *match, phys_t *sta * * ******************************************************************************/ -static void g_scan_bytes_match_output_to_text(const GScanBytesMatch *match, int fd) +static void g_scan_bytes_matches_output_to_text(const GScanBytesMatches *matches, int fd) { + 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 */ int ret; /* Bilan d'une conversion */ - GScanMatch *base; /* Lien vers les infos de base */ - const char *name; /* Désignation du motif ciblé */ vmpa2t pos; /* Tête de lecture */ + phys_t len; /* Taille d'une correspondance */ const bin_t *data; /* Accès aux données brutes */ phys_t k; /* Boucle de parcours #2 */ - /* Position dans le binaire (hexadécimal) */ + base = G_SCAN_MATCHES(matches); - ret = snprintf(value, ULLONG_MAXLEN, "0x%llx", (unsigned long long)match->start); + content = g_scan_context_get_content(base->context); - if (ret > 0) - write(fd, value, ret); + name = g_search_pattern_get_name(base->source); - else + for_each_match_area(iter, matches->areas) { - log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!"); - write(fd, "\"<error>\"", 9); - } + /* Position dans le binaire (hexadécimal) */ - write(fd, ":", 1); + ret = snprintf(value, ULLONG_MAXLEN, "0x%llx", (unsigned long long)iter->start); - /* Affichage de la désignation */ + if (ret > 0) + write(fd, value, ret); - write(fd, "$", 1); + else + { + log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!"); + write(fd, "\"<error>\"", 9); + } - base = G_SCAN_MATCH(match); + write(fd, ":", 1); - name = g_search_pattern_get_name(base->source); + /* Affichage de la désignation */ - /** - * Les fonctionnalités Yara d'origine autorisent les variables anonymes '$'. - * - * Cette absence de nom est supportée ici. - */ + write(fd, "$", 1); - if (name != NULL) - write(fd, name, strlen(name)); + /** + * Les fonctionnalités Yara d'origine autorisent les variables anonymes '$'. + * + * Cette absence de nom est supportée ici. + */ - write(fd, ": ", 2); + if (name != NULL) + write(fd, name, strlen(name)); - /* Affichage du contenu */ + write(fd, ": ", 2); - init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL); + /* Affichage du contenu */ - data = g_binary_content_get_raw_access(match->content, &pos, match->len); + init_vmpa(&pos, iter->start, VMPA_NO_VIRTUAL); - for (k = 0; k < match->len; k++) - { - if (isprint(data[k])) - write(fd, &data[k], 1); + len = iter->end - iter->start; - else - { - write(fd, "\\x", 2); - - ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]); + data = g_binary_content_get_raw_access(content, &pos, len); + assert(data != NULL); - if (ret > 0) - { - assert(ret == 2); - write(fd, value, ret); - } + for (k = 0; k < len; k++) + { + if (isprint(data[k])) + write(fd, &data[k], 1); else { - log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); - write(fd, "??", 2); + write(fd, "\\x", 2); + + ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]); + + if (ret > 0) + { + assert(ret == 2); + write(fd, value, ret); + } + + else + { + log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); + write(fd, "??", 2); + } + } } + write(fd, "\n", 1); + } - write(fd, "\n", 1); + g_object_unref(G_OBJECT(content)); } /****************************************************************************** * * -* Paramètres : match = définition de correspondance à manipuler. * +* Paramètres : matches = définition de correspondance à manipuler. * * padding = éventuel bourrage initial à placer ou NULL. * * level = profondeur actuelle. * * fd = canal d'écriture. * @@ -400,188 +464,249 @@ static void g_scan_bytes_match_output_to_text(const GScanBytesMatch *match, int * * ******************************************************************************/ -static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *match, const sized_string_t *padding, unsigned int level, int fd) +static void g_scan_bytes_matches_output_to_json(const GScanBytesMatches *matches, const sized_string_t *padding, unsigned int level, int fd) { unsigned int i; /* Boucle de parcours #1 */ - vmpa2t pos; /* Tête de lecture */ 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 */ + phys_t len; /* Taille d'une correspondance */ const bin_t *data; /* Accès aux données brutes */ phys_t k; /* Boucle de parcours #2 */ - /* Position dans le binaire (décimal) */ + /* Nombre de correspondances */ for (i = 0; i < level; i++) write(fd, padding->data, padding->len); - write(fd, "\"offset\": ", 10); + write(fd, "\"match_count\": ", 15); - ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)match->start); + ret = snprintf(value, ULLONG_MAXLEN, "%zu", matches->count); if (ret > 0) write(fd, value, ret); else { - log_simple_message(LMT_EXT_ERROR, "Error while converting offset!"); + log_simple_message(LMT_EXT_ERROR, "Error while converting value!"); write(fd, "null", 4); } write(fd, ",\n", 2); - /* Position dans le binaire (hexadécimal) */ + /* Détail des correspondances */ for (i = 0; i < level; i++) write(fd, padding->data, padding->len); - write(fd, "\"offset_hex\": ", 14); + write(fd, "\"matches\": [\n", 13); - ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)match->start); + base = G_SCAN_MATCHES(matches); - if (ret > 0) - write(fd, value, ret); + content = g_scan_context_get_content(base->context); - else + for_each_match_area(iter, matches->areas) { - log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!"); - write(fd, "null", 4); - } - - write(fd, ",\n", 2); + /* Marqueur de début */ - /* Affichage du contenu brut */ + for (i = 0; i < (level + 1); i++) + write(fd, padding->data, padding->len); - for (i = 0; i < level; i++) - write(fd, padding->data, padding->len); + write(fd, "{\n", 2); - write(fd, "\"content\": \"", 12); + /* Position dans le binaire (décimal) */ - init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL); + for (i = 0; i < (level + 2); i++) + write(fd, padding->data, padding->len); - data = g_binary_content_get_raw_access(match->content, &pos, match->len); - assert(data != NULL); + write(fd, "\"offset\": ", 10); - for (k = 0; k < match->len; k++) - { - if (data[k] == '\\') - write(fd, "\\\\", 2); + ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)iter->start); - else if (isprint(data[k])) - write(fd, &data[k], 1); + if (ret > 0) + write(fd, value, ret); else { - write(fd, "\\u", 2); + log_simple_message(LMT_EXT_ERROR, "Error while converting offset!"); + write(fd, "null", 4); + } - /** - * Cf. https://datatracker.ietf.org/doc/html/rfc8259#section-7 - */ - ret = snprintf(value, ULLONG_MAXLEN, "%04hhx", data[k]); + write(fd, ",\n", 2); - if (ret > 0) - { - assert(ret == 4); - write(fd, value, ret); - } + /* Position dans le binaire (hexadécimal) */ - else - { - log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); - write(fd, "??", 2); - } + for (i = 0; i < (level + 2); i++) + write(fd, padding->data, padding->len); - } + write(fd, "\"offset_hex\": ", 14); - } + ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)iter->start); + + if (ret > 0) + write(fd, value, ret); - write(fd, "\",\n", 3); + else + { + log_simple_message(LMT_EXT_ERROR, "Error while converting offset to hex!"); + write(fd, "null", 4); + } - /* Affichage du contenu en version humainement lisible */ + write(fd, ",\n", 2); - for (i = 0; i < level; i++) - write(fd, padding->data, padding->len); + /* Affichage du contenu brut */ - write(fd, "\"content_str\": \"", 16); + for (i = 0; i < (level + 2); i++) + write(fd, padding->data, padding->len); - init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL); + write(fd, "\"content\": \"", 12); - data = g_binary_content_get_raw_access(match->content, &pos, match->len); - assert(data != NULL); + init_vmpa(&pos, iter->start, VMPA_NO_VIRTUAL); - for (k = 0; k < match->len; k++) - { - if (data[k] == '\\') - write(fd, "\\\\", 2); + len = iter->end - iter->start; - else if (isprint(data[k])) - write(fd, &data[k], 1); + data = g_binary_content_get_raw_access(content, &pos, len); + assert(data != NULL); - else + for (k = 0; k < len; k++) { - write(fd, "\\\\x", 3); + if (data[k] == '\\') + write(fd, "\\\\", 2); - ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]); + else if (isprint(data[k])) + write(fd, &data[k], 1); - if (ret > 0) + else { - assert(ret == 2); - write(fd, value, ret); + write(fd, "\\u", 2); + + /** + * Cf. https://datatracker.ietf.org/doc/html/rfc8259#section-7 + */ + ret = snprintf(value, ULLONG_MAXLEN, "%04hhx", data[k]); + + if (ret > 0) + { + assert(ret == 4); + write(fd, value, ret); + } + + else + { + log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); + write(fd, "??", 2); + } + } + } + + write(fd, "\",\n", 3); + + /* Affichage du contenu en version humainement lisible */ + + for (i = 0; i < (level + 2); i++) + write(fd, padding->data, padding->len); + + write(fd, "\"content_str\": \"", 16); + + init_vmpa(&pos, iter->start, VMPA_NO_VIRTUAL); + + data = g_binary_content_get_raw_access(content, &pos, len); + assert(data != NULL); + + for (k = 0; k < len; k++) + { + if (data[k] == '\\') + write(fd, "\\\\", 2); + + else if (isprint(data[k])) + write(fd, &data[k], 1); + else { - log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); - write(fd, "??", 2); + write(fd, "\\\\x", 3); + + ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]); + + if (ret > 0) + { + assert(ret == 2); + write(fd, value, ret); + } + + else + { + log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); + write(fd, "??", 2); + } + } } - } + write(fd, "\",\n", 3); - write(fd, "\",\n", 3); + /* Affichage du contenu brut */ - /* Affichage du contenu brut */ + for (i = 0; i < (level + 2); i++) + write(fd, padding->data, padding->len); - for (i = 0; i < level; i++) - write(fd, padding->data, padding->len); + write(fd, "\"length\": ", 10); - write(fd, "\"length\": ", 10); + ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)len); - init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL); + if (ret > 0) + write(fd, value, ret); - ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)match->len); + else + { + log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); + write(fd, "-1", 2); + } - if (ret > 0) - write(fd, value, ret); + write(fd, ",\n", 2); - else - { - log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); - write(fd, "-1", 2); - } + /* Affichage du contenu brut (hexadécimal) */ - write(fd, ",\n", 2); + for (i = 0; i < (level + 2); i++) + write(fd, padding->data, padding->len); - /* Affichage du contenu brut (hexadécimal) */ + write(fd, "\"length_hex\": ", 14); - for (i = 0; i < level; i++) - write(fd, padding->data, padding->len); + ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)len); - write(fd, "\"length_hex\": ", 14); + if (ret > 0) + write(fd, value, ret); - init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL); + else + { + log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); + write(fd, "\"0xffffffffffffffff\"", 20); + } - ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)match->len); + write(fd, "\n", 1); - if (ret > 0) - write(fd, value, ret); + /* Marqueur de fin */ + + for (i = 0; i < (level + 1); i++) + write(fd, padding->data, padding->len); + + if (is_last_match_area(iter, matches->areas)) + write(fd, "}\n", 2); + else + write(fd, "},\n", 3); - else - { - log_simple_message(LMT_EXT_ERROR, "Error while converting data!"); - write(fd, "\"0xffffffffffffffff\"", 20); } - write(fd, "\n", 1); + g_object_unref(G_OBJECT(content)); + + for (i = 0; i < level; i++) + write(fd, padding->data, padding->len); + + write(fd, "]\n", 2); } |
