-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathProgram.cs
More file actions
304 lines (267 loc) · 12.6 KB
/
Copy pathProgram.cs
File metadata and controls
304 lines (267 loc) · 12.6 KB
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
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace KeyAuth
{
class Program
{
/*
*
* WATCH THIS VIDEO TO SETUP APPLICATION: https://youtube.com/watch?v=RfDTdiBq4_o
*
* READ HERE TO LEARN ABOUT KEYAUTH FUNCTIONS https://github.com/KeyAuth/KeyAuth-CSHARP-Example#keyauthapp-instance-definition
*
*/
public static api KeyAuthApp = new api(
name: "", // Application Name
ownerid: "", // Account ID
version: "" // Application version. Used for automatic downloads see video here https://www.youtube.com/watch?v=kW195PLCBKs
//path: @"Your_Path_Here" // (OPTIONAL) see tutorial here https://www.youtube.com/watch?v=I9rxt821gMk&t=1s
);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool TerminateProcess(IntPtr hProcess, uint uExitCode);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern ushort GlobalFindAtom(string lpString);
static void Main(string[] args)
{
securityChecks();
Console.Title = "Loader";
Console.WriteLine("\n\n Connecting..");
KeyAuthApp.init();
autoUpdate();
if (!KeyAuthApp.response.success)
{
Console.WriteLine("\n Status: " + KeyAuthApp.response.message);
Thread.Sleep(1500);
TerminateProcess(GetCurrentProcess(), 1);
}
Console.Write("\n [1] Login\n [2] Register\n [3] Upgrade\n [4] License key only\n [5] Forgot password\n\n Choose option: ");
string username, password, key, email, code;
int option = int.Parse(Console.ReadLine());
switch (option)
{
case 1:
Console.Write("\n\n Enter username: ");
username = Console.ReadLine();
Console.Write("\n\n Enter password: ");
password = Console.ReadLine();
Console.Write("\n\n Enter 2fa code: (not using 2fa? Just press enter) ");
code = Console.ReadLine();
KeyAuthApp.login(username, password, code);
break;
case 2:
Console.Write("\n\n Enter username: ");
username = Console.ReadLine();
Console.Write("\n\n Enter password: ");
password = Console.ReadLine();
Console.Write("\n\n Enter license: ");
key = Console.ReadLine();
Console.Write("\n\n Enter email (just press enter if none): ");
email = Console.ReadLine();
KeyAuthApp.register(username, password, key, email);
break;
case 3:
Console.Write("\n\n Enter username: ");
username = Console.ReadLine();
Console.Write("\n\n Enter license: ");
key = Console.ReadLine();
KeyAuthApp.upgrade(username, key);
// don't proceed to app, user hasn't authenticated yet.
Console.WriteLine("\n Status: " + KeyAuthApp.response.message);
Thread.Sleep(2500);
TerminateProcess(GetCurrentProcess(), 1);
break;
case 4:
Console.Write("\n\n Enter license: ");
key = Console.ReadLine();
Console.Write("\n\n Enter 2fa code: (not using 2fa? Just press enter");
code = Console.ReadLine();
KeyAuthApp.license(key, code);
break;
case 5:
Console.Write("\n\n Enter username: ");
username = Console.ReadLine();
Console.Write("\n\n Enter email: ");
email = Console.ReadLine();
KeyAuthApp.forgot(username, email);
// don't proceed to app, user hasn't authenticated yet.
Console.WriteLine("\n Status: " + KeyAuthApp.response.message);
Thread.Sleep(2500);
TerminateProcess(GetCurrentProcess(), 1);
break;
default:
Console.WriteLine("\n\n Invalid Selection");
Thread.Sleep(2500);
TerminateProcess(GetCurrentProcess(), 1);
break; // no point in this other than to not get error from IDE
}
if (!KeyAuthApp.response.success)
{
Console.WriteLine("\n Status: " + KeyAuthApp.response.message);
Thread.Sleep(2500);
TerminateProcess(GetCurrentProcess(), 1);
}
Console.WriteLine("\n Logged In!"); // at this point, the client has been authenticated. Put the code you want to run after here
if(string.IsNullOrEmpty(KeyAuthApp.response.message)) TerminateProcess(GetCurrentProcess(), 1);
// user data
Console.WriteLine("\n User data:");
Console.WriteLine(" Username: " + KeyAuthApp.user_data.username);
Console.WriteLine(" License: " + KeyAuthApp.user_data.subscriptions[0].key); // this can be used if the user used a license, username, and password for register. It'll display the license assigned to the user
Console.WriteLine(" IP address: " + KeyAuthApp.user_data.ip);
Console.WriteLine(" Hardware-Id: " + KeyAuthApp.user_data.hwid);
Console.WriteLine(" Created at: " + UnixTimeToDateTime(long.Parse(KeyAuthApp.user_data.createdate)));
if (!string.IsNullOrEmpty(KeyAuthApp.user_data.lastlogin)) // don't show last login on register since there is no last login at that point
Console.WriteLine(" Last login at: " + UnixTimeToDateTime(long.Parse(KeyAuthApp.user_data.lastlogin)));
Console.WriteLine(" Your subscription(s):");
for (var i = 0; i < KeyAuthApp.user_data.subscriptions.Count; i++)
{
Console.WriteLine(" Subscription name: " + KeyAuthApp.user_data.subscriptions[i].subscription + " - Expires at: " + UnixTimeToDateTime(long.Parse(KeyAuthApp.user_data.subscriptions[i].expiry)) + " - Time left in seconds: " + KeyAuthApp.user_data.subscriptions[i].timeleft);
}
Console.Write("\n [1] Enable 2FA\n [2] Disable 2FA\n Choose option: ");
int tfaOptions = int.Parse(Console.ReadLine());
switch (tfaOptions)
{
case 1:
KeyAuthApp.enable2fa();
break;
case 2:
Console.Write("Enter your 6 digit authorization code: ");
code = Console.ReadLine();
KeyAuthApp.disable2fa(code);
break;
default:
Console.WriteLine("\n\n Invalid Selection");
Thread.Sleep(2500);
TerminateProcess(GetCurrentProcess(), 1);
break; // no point in this other than to not get error from IDE
}
Console.WriteLine("\n Closing in five seconds...");
Thread.Sleep(-1);
Environment.Exit(0);
}
public static bool SubExist(string name)
{
if(KeyAuthApp.user_data.subscriptions.Exists(x => x.subscription == name))
return true;
return false;
}
public static DateTime UnixTimeToDateTime(long unixtime)
{
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Local);
try
{
dtDateTime = dtDateTime.AddSeconds(unixtime).ToLocalTime();
}
catch
{
dtDateTime = DateTime.MaxValue;
}
return dtDateTime;
}
static void checkAtom()
{
Thread atomCheckThread = new Thread(() =>
{
while (true)
{
Thread.Sleep(60000); // give people 1 minute to login
ushort foundAtom = GlobalFindAtom(KeyAuthApp.ownerid);
if (foundAtom == 0)
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
});
atomCheckThread.IsBackground = true; // Ensure the thread does not block program exit
atomCheckThread.Start();
}
static void securityChecks()
{
// check if the Loader was executed by a different program
var frames = new StackTrace().GetFrames();
foreach (var frame in frames)
{
MethodBase method = frame.GetMethod();
if (method != null && method.DeclaringType?.Assembly != Assembly.GetExecutingAssembly())
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
// check if HarmonyLib is attempting to poison our program
var harmonyAssembly = AppDomain.CurrentDomain
.GetAssemblies()
.FirstOrDefault(a => a.GetName().Name == "0Harmony");
if (harmonyAssembly != null)
{
TerminateProcess(GetCurrentProcess(), 1);
}
checkAtom();
}
static void autoUpdate()
{
if (KeyAuthApp.response.message == "invalidver")
{
if (!string.IsNullOrEmpty(KeyAuthApp.app_data.downloadLink))
{
Console.WriteLine("\n Auto update avaliable!");
Console.WriteLine(" Choose how you'd like to auto update:");
Console.WriteLine(" [1] Open file in browser");
Console.WriteLine(" [2] Download file directly");
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
Process.Start(KeyAuthApp.app_data.downloadLink);
Environment.Exit(0);
break;
case 2:
Console.WriteLine(" Downloading file directly..");
Console.WriteLine(" New file will be opened shortly..");
WebClient webClient = new WebClient();
string destFile = Application.ExecutablePath;
string rand = random_string();
destFile = destFile.Replace(".exe", $"-{rand}.exe");
webClient.DownloadFile(KeyAuthApp.app_data.downloadLink, destFile);
Process.Start(destFile);
Process.Start(new ProcessStartInfo()
{
Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "cmd.exe"
});
Environment.Exit(0);
break;
default:
Console.WriteLine(" Invalid selection, terminating program..");
Thread.Sleep(1500);
Environment.Exit(0);
break;
}
}
Console.WriteLine("\n Status: Version of this program does not match the one online. Furthermore, the download link online isn't set. You will need to manually obtain the download link from the developer.");
Thread.Sleep(2500);
Environment.Exit(0);
}
}
static string random_string()
{
string str = null;
Random random = new Random();
for (int i = 0; i < 5; i++)
{
str += Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))).ToString();
}
return str;
}
}
}