From 6620382d4e7b5aa59a2e0ddfb35aac730de0d686 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Tue, 24 Jan 2023 12:16:16 +0100 Subject: [PATCH] created code for decrypting logger send part of this update tho --- src/logger/lib/utils.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/logger/lib/utils.c b/src/logger/lib/utils.c index b4c280f..26afb6f 100644 --- a/src/logger/lib/utils.c +++ b/src/logger/lib/utils.c @@ -23,6 +23,10 @@ along with this program. If not, see . #include #include +#include +#include +#include + #include void deallocateLogger(logFile logger) @@ -47,8 +51,10 @@ void decryptLogger(logFile logger) //TODO: Fix valgrind issues { FILE *file = fdopen(logger.file, "r"); //OPEN logFile AS FILE POINTER + outputFlags outputBuffer; char *rawContent; char **linesContent; + char **linesContentDecrypted; int rawContentLength; int lines = 0; int buffer = 0; @@ -73,7 +79,9 @@ void decryptLogger(logFile logger) //TODO: Fix valgrind issues if (rawContent[i] == '\n') lines++; } + //ALLOCATE SPLIT & SPLIT DECRYPTED BUFFERS linesContent = malloc(lines + 1); + linesContentDecrypted = malloc(lines + 1); for (int i = 0; i < rawContentLength; i++) //LOAD/SPIT rawContent INTO linesContent { @@ -108,13 +116,29 @@ void decryptLogger(logFile logger) //TODO: Fix valgrind issues } //TODO: Decrypt + for (int i = 0; i < buffer3; i++) + { + outputBuffer = decryptText(linesContent[i], getLogFlags().key); + linesContentDecrypted[i] = strdup(outputBuffer.outputText); + + deallocateOutput(outputBuffer); + } for (int i = 0; i < buffer3; i++) { - free(linesContent[i]); + printf("%s\n", linesContentDecrypted[i]); } + + //DEALLOCATE EACH linesContent & linesContentDecrypted INDEX + for (int i = 0; i < buffer3; i++) + { + free(linesContent[i]); + free(linesContentDecrypted[i]); //TODO: Remove + } + free(linesContent); + free(linesContentDecrypted); //TODO: Remove free(rawContent); return;