From f2f0fc476e032ada5460f251aace7878e1cd3934 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Thu, 14 Sep 2023 08:15:12 +0200
Subject: Include lengths in ROST JSON reports.

---
 src/analysis/scan/matches/bytes.c | 48 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/analysis/scan/matches/bytes.c b/src/analysis/scan/matches/bytes.c
index ccd73a1..de101c4 100644
--- a/src/analysis/scan/matches/bytes.c
+++ b/src/analysis/scan/matches/bytes.c
@@ -459,6 +459,7 @@ static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *match, cons
     init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
 
     data = g_binary_content_get_raw_access(match->content, &pos, match->len);
+    assert(data != NULL);
 
     for (k = 0; k < match->len; k++)
     {
@@ -505,6 +506,7 @@ static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *match, cons
     init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
 
     data = g_binary_content_get_raw_access(match->content, &pos, match->len);
+    assert(data != NULL);
 
     for (k = 0; k < match->len; k++)
     {
@@ -536,6 +538,50 @@ static void g_scan_bytes_match_output_to_json(const GScanBytesMatch *match, cons
 
     }
 
-    write(fd, "\"\n", 2);
+    write(fd, "\",\n", 3);
+
+    /* Affichage du contenu brut */
+
+    for (i = 0; i < level; i++)
+        write(fd, padding->data, padding->len);
+
+    write(fd, "\"length\": ", 10);
+
+    init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
+
+    ret = snprintf(value, ULLONG_MAXLEN, "%llu", (unsigned long long)match->len);
+
+    if (ret > 0)
+        write(fd, value, ret);
+
+    else
+    {
+        log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
+        write(fd, "-1", 2);
+    }
+
+    write(fd, ",\n", 2);
+
+    /* Affichage du contenu brut (hexadécimal) */
+
+    for (i = 0; i < level; i++)
+        write(fd, padding->data, padding->len);
+
+    write(fd, "\"length_hex\": ", 14);
+
+    init_vmpa(&pos, match->start, VMPA_NO_VIRTUAL);
+
+    ret = snprintf(value, ULLONG_MAXLEN, "\"0x%llx\"", (unsigned long long)match->len);
+
+    if (ret > 0)
+        write(fd, value, ret);
+
+    else
+    {
+        log_simple_message(LMT_EXT_ERROR, "Error while converting data!");
+        write(fd, "\"0xffffffffffffffff\"", 20);
+    }
+
+    write(fd, "\n", 1);
 
 }
-- 
cgit v0.11.2-87-g4458