diff options
Diffstat (limited to 'src/analysis/scan/matches')
-rw-r--r-- | src/analysis/scan/matches/bytes.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/analysis/scan/matches/bytes.c b/src/analysis/scan/matches/bytes.c index 043170e..ccd73a1 100644 --- a/src/analysis/scan/matches/bytes.c +++ b/src/analysis/scan/matches/bytes.c @@ -449,7 +449,7 @@ static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *match, cons write(fd, ",\n", 2); - /* Affichage du contenu */ + /* Affichage du contenu brut */ for (i = 0; i < level; i++) write(fd, padding->data, padding->len); @@ -462,12 +462,61 @@ static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *match, cons for (k = 0; k < match->len; k++) { - if (isprint(data[k])) + if (data[k] == '\\') + write(fd, "\\\\", 2); + + else if (isprint(data[k])) write(fd, &data[k], 1); else { - write(fd, "\\x", 2); + 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; i++) + write(fd, padding->data, padding->len); + + write(fd, "\"content_str\": \"", 16); + + init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL); + + data = g_binary_content_get_raw_access(match->content, &pos, match->len); + + for (k = 0; k < match->len; k++) + { + if (data[k] == '\\') + write(fd, "\\\\", 2); + + else if (isprint(data[k])) + write(fd, &data[k], 1); + + else + { + write(fd, "\\\\x", 3); ret = snprintf(value, ULLONG_MAXLEN, "%02hhx", data[k]); |