created code for decrypting logger

send part of this update tho
This commit is contained in:
Václav Šmejkal 2023-01-24 12:16:16 +01:00
parent 000021b9a2
commit 6620382d4e
Signed by: ENGO150
GPG Key ID: F6D6DF86242C5A59

View File

@ -23,6 +23,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <string.h>
#include <unistd.h>
#include <why2/decrypter.h>
#include <why2/flags.h>
#include <why2/misc.h>
#include <why2/logger/flags.h>
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;