-
Notifications
You must be signed in to change notification settings - Fork 3
/
Utilities.cs
352 lines (327 loc) · 12.9 KB
/
Utilities.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
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Caching;
using System.Windows.Forms;
using Microsoft.VisualStudio.Services.Identity;
using SharpCompress;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ALL_LEGIT
{
class Utilities
{
public static void ExtractFile2(string sourceArchive, string destination)
{
try
{
if (!File.Exists(Environment.CurrentDirectory + "\\7z.exe") || !File.Exists(Environment.CurrentDirectory + "\\7z.dll"))
{
WebClient client = new WebClient();
client.DownloadFile("https://github.com/harryeffinpotter/-Loader/raw/main/7z.exe", "7z.exe");
client.DownloadFile("https://github.com/harryeffinpotter/-Loader/raw/main/7z.dll", "7z.dll");
}
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.FileName = $"{Environment.CurrentDirectory}\\7z.exe";
pro.Arguments = string.Format("x \"{0}\" -y -o\"{1}\"", sourceArchive, destination);
Process x = Process.Start(pro);
if (!x.HasExited)
x.WaitForExit();
}
catch
{
MessageBox.Show("Unable to extract updated files. If you have WINRAR try uninstalling it then trying again! If you have not installed FFAIO since version 2.0.13 then ");
}
}
public static string FailedExtract = "";
public static void GetMissingFiles()
{
var client = new WebClient();
string _bin = $"{Environment.CurrentDirectory}\\_bin";
string config = $"{Environment.CurrentDirectory}\\All.Legit.exe.config";
if (!File.Exists($"{_bin}\\transmission-show.exe"))
{
client.DownloadFile("https://github.com/harryeffinpotter/ALL-LEGIT/raw/main/_bin.7z", "_bin.7z");
if (Directory.Exists(_bin))
{
_bin.DirectoryRecycle();
Directory.CreateDirectory(_bin);
}
ExtractFile2(Environment.CurrentDirectory + "\\_bin.7z", _bin);
string filetodelete = Environment.CurrentDirectory + "\\_bin\\_bin.7z";
filetodelete.FileRecycle();
}
}
public static string get_parent_dir_path(string path)
{
// notice that i used two separators windows style "\\" and linux "/" (for bad formed paths)
// We make sure to remove extra unneeded characters.
int index = path.Trim('/', '\\').LastIndexOfAny(new char[] { '\\', '/' });
// now if index is >= 0 that means we have at least one parent directory, otherwise the given path is the root most.
if (index >= 0)
return path.Remove(index);
else
return "";
}
public static bool IsExtracting = false;
public static bool IsArchive(string ArchiveFile)
{
System.Diagnostics.Process x = new System.Diagnostics.Process();
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.UseShellExecute = false;
pro.CreateNoWindow = true;
pro.RedirectStandardError = true;
pro.WorkingDirectory = $"{Environment.CurrentDirectory}\\_bin";
pro.RedirectStandardOutput = true;
pro.FileName = "cmd.exe";
string Output = null;
Thread isArchive = new Thread(() =>
{
pro.Arguments = $"/c Archive.bat \"{ArchiveFile}\"";
x.StartInfo = pro;
x.Start();
Output = x.StandardOutput.ReadToEnd();
});
isArchive.Start();
while (isArchive.IsAlive)
{
Task.Delay(50);
}
if (Output.ToLower().Contains("archive"))
{
return true;
}
else
{
return false;
}
}
public static async void ExtractFile(string sourceArchive, string destination)
{
if (!Directory.Exists(destination))
{
Directory.CreateDirectory(destination);
}
if (sourceArchive.EndsWith(".exe"))
{
return;
}
if (String.IsNullOrEmpty(MainWindow.MainDLDir))
{
MainWindow.MainDLDir = destination;
}
System.Diagnostics.Process x2 = new System.Diagnostics.Process();
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.UseShellExecute = false;
pro.CreateNoWindow = true;
pro.RedirectStandardError = true;
pro.RedirectStandardOutput = true;
pro.FileName = $"{Environment.CurrentDirectory}\\7z.exe";
string Error = null;
string[] PWArray = MainWindow.PWLIST.Split(';');
int fails = 0;
foreach (string PW in PWArray)
{
try
{
if (File.Exists(sourceArchive) && Directory.Exists(destination))
{
Thread unzip = new Thread(() =>
{
pro.Arguments = string.Format("x \"{0}\" -aoa -o\"{1}\"", sourceArchive, destination) + $" -p\"{PW}\"";
x2.StartInfo = pro;
IsExtracting = true;
x2.Start();
Error = x2.StandardError.ReadToEnd();
if (!x2.HasExited)
x2.WaitForExit();
});
unzip.Start();
while (unzip.IsAlive)
{
IsExtracting = true;
await Task.Delay(100);
}
IsExtracting = false;
}
else { return; }
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
if (Error.Contains("Data Error in encrypted file. Wrong password?"))
{
fails++;
}
if (fails == PWArray.Length)
{
if (Directory.GetFiles(destination, "*.*", SearchOption.AllDirectories).Length == 0)
{
destination.DirectoryRecycle();
}
FailedExtract += sourceArchive;
MessageBox.Show(new Form { TopMost = true }, "Archive is passworded and supplied passwords(if any)" +
" did not work.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
foreach (ListViewItem item in Program.form.listView1.Items)
{
if (Properties.Settings.Default.RemDL)
{
if (sourceArchive.Contains(item.SubItems[0].Text))
{
Program.form.listView1.Items.Remove(item);
}
}
}
}
}
}
public static void DecryptDLC()
{
Program.form.Invoke(() =>
{
Program.form.DownloadingText.Text = $"Decrypting Filecrypt links...";
});
bool filecryptinprog = false;
string[] files = Directory.GetFiles(Environment.CurrentDirectory, "*.dlc", SearchOption.AllDirectories);
string[] files2 = Directory.GetFiles(MainWindow.GetDownloadsPath(), "*.dlc", SearchOption.AllDirectories);
string[] joinedResult = files.Concatenate(files2);
string currentDLCfile = "";
foreach (string file in joinedResult)
{
string parentpath = System.IO.Directory.GetParent(file).FullName;
if (!parentpath.EndsWith("_bin"))
{
string JUSTNAME = Path.GetFileName(file);
File.Move(file, $"{Environment.CurrentDirectory}\\_bin\\{JUSTNAME}");
currentDLCfile = $"{Environment.CurrentDirectory}\\_bin\\{JUSTNAME}";
}
else
{
filecryptinprog= true;
currentDLCfile = file;
}
int DLCNumber = MainWindow.randomNumber;
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.FileName = $"cmd.exe";
pro.WorkingDirectory = $"{Environment.CurrentDirectory}\\_bin";
pro.Arguments = $"/c decrypt-dlc.cmd \"{currentDLCfile}\" -o \"{Environment.CurrentDirectory}\\_bin\\{DLCNumber}.txt\"";
Process x = Process.Start(pro);
x.Start();
x.WaitForExit();
try
{
File.Delete(currentDLCfile);
}
catch
{
}
}
if (filecryptinprog)
{
string[] filez = Directory.GetFiles($"{Environment.CurrentDirectory}\\_bin", "*.txt", SearchOption.TopDirectoryOnly);
string linkstoget = "";
foreach (string file in files)
{
if (file.Contains(".txt"))
{
string[] list = File.ReadAllLines(file);
foreach (string line in list)
{
if (!line.Contains("Urls stored"))
{
linkstoget += line + "\n";
DLCCount++;
}
}
file.FileRecycle();
}
}
if (!String.IsNullOrWhiteSpace(linkstoget))
{
Clipboard.SetText(linkstoget);
linkstoget = "";
filecryptinprog = false;
}
}
}
public static int DLCCount = 0;
public static void Melt()
{
Process.Start(new ProcessStartInfo()
{
Arguments = $"/C WMIC PROCESS WHERE \"Name Like '%Legit%'\" CALL Terminate & choice /C Y /N /D Y /T 4 & del \"{Application.ExecutablePath}\" & rename \"{Environment.CurrentDirectory}\\All LegitNEW.exe\" \"All.Legit.exe\" & timeout /T 3 /NOBREAK & start \"\" \"{Environment.CurrentDirectory}\\All.Legit.exe\"",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "cmd.exe"
});
Environment.Exit(0);
}
public static string RemoveEverythingAfterFirst(string s, string removeMe)
{
int index = s.IndexOf(removeMe);
if (index > 0)
s = s.Substring(0, index);
return s;
}
public static string RemoveEverythingAfterLast(string s, string removeMe)
{
int index = s.LastIndexOf(removeMe);
if (index > 0)
s = s.Substring(0, index);
return s;
}
public static string RemoveEverythingBeforeFirst(string s, string removeMe)
{
int index = s.IndexOf(removeMe);
if (index > 0)
s = s.Substring(index);
return s;
}
public static string KeepOnlyNumbers(string s)
{
string numbers = "0123456789";
string a = "";
foreach (char ch in s)
{
if (numbers.Contains(ch))
{
a += ch;
}
}
return a;
}
public static string RemoveEverythingBeforeLast(string s, string removeMe)
{
int index = s.LastIndexOf(removeMe);
if (index > 0)
s = s.Substring(index);
return s;
}
}
}
public static class Extension
{
public static T[] Concatenate<T>(this T[] first, T[] second)
{
if (first == null)
{
return second;
}
if (second == null)
{
return first;
}
return first.Concat(second).ToArray();
}
}