summaryrefslogtreecommitdiff
path: root/src/analysis/scan/matches
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2023-09-12 21:49:01 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2023-09-12 21:49:01 (GMT)
commit6f160d1b1e1bfdd06414d5b6c49a0c9d9fc8a830 (patch)
tree2b2cfc9d1641a6fcf4c2be5578d35fda2585fb1a /src/analysis/scan/matches
parentfef46dc1537e3302ac7bab653d24495c570e1d5c (diff)
Complete the output of scan results (text or JSON).
Diffstat (limited to 'src/analysis/scan/matches')
-rw-r--r--src/analysis/scan/matches/bytes.c55
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]);