aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/Engine/Viruses.cs
blob: 5042934262fa13b61358bedac40194cbea547132 (plain) (blame)
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using ShiftUI;

/*
 * WARNING: SOME PARTS OF THIS FILE ARE NSFW
 * AS WITH REAL LIFE, VIRUSES ARE NAMED VULGAR THINGS THAT MAY BE NOT APPROPIATE FOR WORK, SCHOOL OR GRANDMOTHER'S BIRTHDAY
 * JUST DON'T USE THE WORK OR SCHOOL COMPUTERS TO EDIT THIS FILE, THANK YOU
*/

namespace ShiftOS
{
    class Viruses
    {
        public static Dictionary<string, string> Infections = new Dictionary<string, string>();

        public static void CheckForInfected()
        {
            VirusTimer.Interval = 1000;
            Infections.Clear();
            Scan(Paths.SaveRoot);
            VirusTimer.Tick += new EventHandler(VirusTimer_Tick);
            VirusTimer.Start();
        }
        
        public static void VirusTimer_Tick(object sender, EventArgs e)
        {
            ShiftoriumKiller.KillRandomUpgrade();
            if(InfectedWith("beepseverysecond"))
            {
                API.PlaySound(Properties.Resources._3beepvirus);
            }
            if(InfectedWith("imtheshifternow"))
            {
                Skinning.Utilities.Randomize();
            }
        }
        
        public static void Scan(string directory)
        {
            foreach(string file in Directory.GetFiles(directory))
            {
                CheckInfected(file);
            }
            foreach(string dir in Directory.GetDirectories(directory))
            {
                if(dir != Paths.Mod_Temp) {
                    Scan(dir);
                }
            }
        }

        public static void ScanForInfectable(string directory, ref List<string> file_list)
        {
            foreach (string file in Directory.GetFiles(directory))
            {
                var finf = new FileInfo(file);
                switch (finf.Extension) {
                    case ".skn":
                    case ".spk":
                    case ".dri":
                    case ".stp":
                    case ".pkg":
                        if (finf.Name != "HDD.dri")
                        {
                            file_list.Add(file);
                        }
                        break;
            }
            }
            foreach (string dir in Directory.GetDirectories(directory))
            {
                if (dir != Paths.Mod_Temp)
                {
                    ScanForInfectable(dir, ref file_list);
                }
            }
        }
        const string virusfilename = "00110";


        public static void CheckInfected(string filepath) {
            var finf = new FileInfo(filepath);
            switch(finf.Extension)
            {
                case ".stp":
                case ".spk":
                case ".pkg":
                case ".skn":
                    if (File.Exists(finf.FullName))
                    {
                        try {
                            string pth = Paths.SystemDir + "_virusregister";
                            API.ExtractFile(finf.FullName, pth, false);
                            string dirsep = "\\";
                            switch (OSInfo.GetPlatformID())
                            {
                                case "microsoft":
                                    dirsep = "\\";
                                    break;
                                default:
                                    dirsep = "/";
                                    break;
                            }
                            if (File.Exists(pth + dirsep + virusfilename))
                            {
                                string encrypted = File.ReadAllText(pth + dirsep + virusfilename);
                                if (encrypted != "" && encrypted != null)
                                {
                                    foreach (string line in API.Encryption.Decrypt(encrypted).Split(';'))
                                    {
                                        if (Infections.ContainsKey(line))
                                        {
                                            Infections[line] += ";" + finf.FullName;
                                        }
                                        else {
                                            Infections.Add(line, finf.FullName);
                                        }
                                    }
                                }
                            }
                            Directory.Delete(pth, true);
                        }
                        catch
                        {
                            API.LogException("Corrupted package file detected while checking for infections... skipping.", false);
                        }
                    }
                    break;
                case ".dri":
                    if (finf.Name != "HDD.dri" && !finf.Name.Contains("BN") && finf.Name != "Network.dri")
                    {
                        if (File.ReadAllText(finf.FullName) != "")
                        {
                            string encrypted = File.ReadAllText(finf.FullName);
                            try
                            {
                                foreach (string line in API.Encryption.Decrypt(encrypted).Split(';'))
                                {
                                    if (Infections.ContainsKey(line))
                                    {
                                        Infections[line] += ";" + finf.FullName;
                                    }
                                    else {
                                        Infections.Add(line, finf.FullName);
                                    }
                                }
                            }
                            catch
                            {
                                if (encrypted != "")
                                {
                                    string decrypted = API.Encryption.Decrypt(encrypted);
                                    if (Infections.ContainsKey(decrypted))
                                    {
                                        Infections[decrypted] += ";" + finf.FullName;
                                    }
                                    else {
                                        Infections.Add(decrypted, finf.FullName);
                                    }
                                }
                            }
                        }
                    }
                    break;
                
            }
        }

        public enum VirusID
        {
            ShiftoriumKiller,
            WindowsEverywhere,
            WindowMicrofier,
            Bye,
            WindowSpazzer,
            KeyboardFucker,
            ImTheShifterNow,
            ThanksfortheInfo,
            SkinInterceptor,
            HolyFuckMyEars,
            BeepsEverySecond,
            MouseTrap,
            Seized,
            FileFucker,
        }

        public class FileFucker
        {
            public static void GetSomeFiles(string directory, ref List<string> file_list)
            {
                foreach (string file in Directory.GetFiles(directory))
                {
                    var finf = new FileInfo(file);
                    switch (finf.Extension)
                    {
                        case ".npk":
                        case ".docx":
                        case ".doc":
                        case ".owd":
                        case ".txt":
                            if (finf.Name != "names.npk" && finf.Name != "_Log.txt")
                            {
                                file_list.Add(file);
                            }
                            break;
                    }
                }
                foreach (string dir in Directory.GetDirectories(directory))
                {
                    if (dir != Paths.Mod_Temp)
                    {
                        GetSomeFiles(dir, ref file_list);
                    }
                }
            }

            public static void Infect()
            {
                List<string> files = new List<string>();
                GetSomeFiles(Paths.SaveRoot, ref files);
                var rnd = new Random();
                string fname = files[rnd.Next(0, files.Count - 1)];
                string fcontents = File.ReadAllText(fname);
                string encrypted = API.Encryption.Encrypt(fcontents);
                File.WriteAllText(fname, encrypted);
            }
        }

        public static bool InfectedWith(string id)
        {
            if(Infections.ContainsKey("virus:" + id))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static void InfectFile(string FileName, VirusID id)
        {
            bool cont = false;
            string infectionString = "virus:";
            switch (id)
            {
                case VirusID.WindowSpazzer:
                    infectionString = "virus:windowspazzer";
                    break;
                case VirusID.WindowMicrofier:
                    infectionString = "virus:windowmicrofier";
                    break;
                case VirusID.Bye:
                    infectionString = "virus:bye";
                    break;
                case VirusID.ShiftoriumKiller:
                    infectionString = "virus:shiftoriumkiller";
                    break;
                case VirusID.WindowsEverywhere:
                    infectionString = "virus:windowseverywhere";
                    break;
                case VirusID.KeyboardFucker:
                    infectionString = "virus:keyboardfucker";
                    break;
                case VirusID.ImTheShifterNow:
                    infectionString = "virus:imtheshifternow";
                    break;
                case VirusID.ThanksfortheInfo:
                    infectionString = "virus:thanksfortheinfo";
                    break;
                case VirusID.SkinInterceptor:
                    infectionString = "virus:skininterceptor";
                    break;
                case VirusID.HolyFuckMyEars:
                    infectionString = "virus:holyfuckmyears";
                    break;
                case VirusID.BeepsEverySecond:
                    infectionString = "virus:beepseverysecond";
                    break;
                case VirusID.Seized:
                    infectionString = "virus:seized";
                    break;
                case VirusID.FileFucker:
                    infectionString = "virus:filefucker";
                    break;
            }
            FileInfo finf = new FileInfo(FileName);
            switch(finf.Extension)
            {
                case ".skn":
                case ".spk":
                case ".stp":
                case ".pkg":
                    if(!Directory.Exists(Paths.Mod_Temp))
                    {
                        Directory.CreateDirectory(Paths.Mod_Temp);
                    }
                    string pth = Paths.SystemDir + "_virusinfect1";
                    API.ExtractFile(finf.FullName, pth, false);
                    string dirsep = "\\";
                    switch (OSInfo.GetPlatformID())
                    {
                        case "microsoft":
                            dirsep = "\\";
                            break;
                        default:
                            dirsep = "/";
                            break;
                    }
                    InfectFile(pth + dirsep + virusfilename, id);
                    File.Delete(finf.FullName);
                    ZipFile.CreateFromDirectory(pth, FileName);
                    Directory.Delete(pth, true);
                    break;
                case ".dri":
                    if(finf.Name == "HDD.dri" || finf.Name.Contains("BN") || finf.Name == "Network.dri")
                    {
                        throw new NotHappeningException("You're not going to attempt to infect that file, are you?");
                    }
                    else
                    {
                        try {
                            string encryptedfile = File.ReadAllText(finf.FullName);
                            string unencryptedfile = API.Encryption.Decrypt(encryptedfile);
                            unencryptedfile += ";" + infectionString;
                            File.WriteAllText(finf.FullName, API.Encryption.Encrypt(unencryptedfile));
                        }
                        catch
                        {
                            File.WriteAllText(finf.FullName, API.Encryption.Encrypt(infectionString));
                        }
                    }
                    break;
                default:
                    cont = true;
                    break;
                    
            }
            if (cont == true)
            {
                if (finf.Name == virusfilename)
                {
                    try
                    {
                        string encryptedfile = File.ReadAllText(finf.FullName);
                        string unencryptedfile = API.Encryption.Decrypt(encryptedfile);
                        unencryptedfile += ";" + infectionString;
                        File.WriteAllText(finf.FullName, API.Encryption.Encrypt(unencryptedfile));
                    }
                    catch
                    {
                        File.WriteAllText(finf.FullName, API.Encryption.Encrypt(infectionString));
                    }
                }
            }
            CheckForInfected();
        }

        public static void DisInfect(string FileName)
        {
            FileInfo finf = new FileInfo(FileName);
            switch (finf.Extension)
            {
                case ".skn":
                case ".spk":
                case ".stp":
                case ".pkg":
                    string pth = Paths.SystemDir + "_viruscheck";
                    API.ExtractFile(finf.FullName, pth, false);
                    string dirsep = "\\";
                    switch (OSInfo.GetPlatformID())
                    {
                        case "microsoft":
                            dirsep = "\\";
                            break;
                        default:
                            dirsep = "/";
                            break;
                    }
                    if (File.Exists(pth + dirsep + virusfilename))
                    {
                        File.Delete(pth + dirsep + virusfilename);
                    }
                    File.Delete(finf.FullName);
                    ZipFile.CreateFromDirectory(pth, finf.FullName);
                    Directory.Delete(pth, true);
                    break;
                case ".dri":
                    if (finf.Name == "HDD.dri" || finf.Name.Contains("BN") || finf.Name == "Network.dri")
                    {
                        throw new NotHappeningException("You're not going to attempt to infect that file, are you?");
                    }
                    else
                    {
                        try
                        {
                            string encryptedfile = File.ReadAllText(finf.FullName);
                            string unencryptedfile = API.Encryption.Decrypt(encryptedfile);
                            unencryptedfile = "";
                            File.WriteAllText(finf.FullName, API.Encryption.Encrypt(unencryptedfile));
                        }
                        catch 
                        {
                            File.WriteAllText(finf.FullName, "");
                        }
                    }
                    break;


            }
            CheckForInfected();
        }

        public static void InfectFile(string FileName, string id)
        {
            bool cont = false;
            string infectionString = "virus:" + id;
            FileInfo finf = new FileInfo(FileName);
            switch (finf.Extension)
            {
                case ".skn":
                case ".spk":
                case ".stp":
                case ".pkg":
                    string pth = Paths.SystemDir + "_virusinfect2";
                    API.ExtractFile(finf.FullName, pth, false);
                    string dirsep = "\\";
                    switch (OSInfo.GetPlatformID())
                    {
                        case "microsoft":
                            dirsep = "\\";
                            break;
                        default:
                            dirsep = "/";
                            break;
                    }
                    InfectFile(pth + dirsep + virusfilename, id);
                    File.Delete(finf.FullName);
                    ZipFile.CreateFromDirectory(pth, finf.FullName);
                    Directory.Delete(pth, true);
                    break;
                case ".dri":
                    if (finf.Name == "HDD.dri" || finf.Name.Contains("BN") || finf.Name == "Network.dri")
                    {
                        throw new NotHappeningException("You're not going to attempt to infect that file, are you?");
                    }
                    else
                    {
                        try
                        {
                            string encryptedfile = File.ReadAllText(finf.FullName);
                            string unencryptedfile = API.Encryption.Decrypt(encryptedfile);
                            unencryptedfile += ";" + infectionString;
                            File.WriteAllText(finf.FullName, API.Encryption.Encrypt(unencryptedfile));
                        }
                        catch 
                        {
                            File.WriteAllText(finf.FullName, API.Encryption.Encrypt(infectionString));
                        }
                    }
                    break;
                default:
                    cont = true;
                    break;

            }
            if (cont == true)
            {
                if (finf.Name == virusfilename)
                {
                    try
                    {
                        string encryptedfile = File.ReadAllText(finf.FullName);
                        string unencryptedfile = API.Encryption.Decrypt(encryptedfile);
                        unencryptedfile += ";" + infectionString;
                        File.WriteAllText(finf.FullName, API.Encryption.Encrypt(unencryptedfile));
                    }
                    catch 
                    {
                        File.WriteAllText(finf.FullName, API.Encryption.Encrypt(infectionString));
                    }
                }
            }
            CheckForInfected();
        }


        public static void InfectRandom()
        {
            var rnd = new Random();
            var files = new List<string>();
            ScanForInfectable(Paths.SaveRoot, ref files);
            string filetoinfect = files[rnd.Next(0, files.Count - 1)];
            VirusID v = VirusID.ShiftoriumKiller;
            int vid = rnd.Next(0, 11);
            switch(vid)
            {
                case 0:
                    v = VirusID.ShiftoriumKiller;
                    break;
                case 1:
                    v = VirusID.WindowsEverywhere;
                    break;
                case 2:
                    v = VirusID.ImTheShifterNow;
                    break;
                case 3:
                    v = VirusID.BeepsEverySecond;
                    break;
                case 4:
                    v = VirusID.FileFucker;
                    break;
                case 5:
                    v = VirusID.MouseTrap;
                    break;
                case 6:
                    v = VirusID.Seized;
                    break;
                case 7:
                    v = VirusID.SkinInterceptor;
                    break;
                case 8:
                    v = VirusID.ThanksfortheInfo;
                    break;
                case 9:
                    v = VirusID.KeyboardFucker;
                    break;
                case 10:
                    v = VirusID.WindowMicrofier;
                    break;
                case 11:
                    v = VirusID.Bye;
                    break;
                case 12:
                    v = VirusID.WindowSpazzer;
                    break;
            }
            InfectFile(filetoinfect, v);
        }

        public static void DropDevXPayload()
        {
            //Viruses...
            var files = new List<string>();
            ScanForInfectable(Paths.SaveRoot, ref files);
            try {
                var rnd = new Random();
                string file = files[rnd.Next(0, files.Count - 1)];
                InfectFile(file, VirusID.ImTheShifterNow);
                InfectFile(file, VirusID.MouseTrap);
            }
            catch
            {
                DropDevXPayload();
            }
            
        }

        private static Timer VirusTimer = new Timer();

        public class ShiftoriumKiller
        { 
            public static void KillRandomUpgrade()
            {
                if(Viruses.InfectedWith("shiftoriumkiller"))
                {
                    int id = new Random().Next(0, SaveSystem.ShiftoriumRegistry.DefaultUpgrades.Count - 1);
                    Shiftorium.Upgrade upg = SaveSystem.ShiftoriumRegistry.DefaultUpgrades[id];
                    int chance = new Random().Next(0, 100);
                    if(chance == 50)
                    {
                        Shiftorium.Utilities.Unbuy(upg.id);
                    }
                }
            }
        }

        public class KeyboardInceptor
        {
            public static string[] Chars =
            {
                "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "~", "!", "@", "#", "$", "%", "^", "&", "(", ")", "-", "_", "=", "+",
                "/", "?", "\\", "|", "[", "]", "{", "}", "'", "\"", ";", ":", ".", ">", ",", "<",
            };

            public static string Intercept()
            {
                Random rnd = new Random();
                int shouldbeupper = rnd.Next(0, 10);
                switch(shouldbeupper)
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 9:
                        return Chars[rnd.Next(0, Chars.Length - 1)].ToUpper();
                    default:
                        return Chars[rnd.Next(0, Chars.Length - 1)].ToLower();
                }
            }
        }
    }

    public class NotHappeningException : Exception
    {
        public NotHappeningException() : base("You tried to do something that ain't gonna happen.")
        {

        }

        public NotHappeningException(string message) : base(message)
        {

        }
    }

}