-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
224 lines (208 loc) · 8.53 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
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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
namespace SimpleDebugger
{
internal static class Program
{
private const string TargetProcessName = "LeagueClientUx.exe";
private static void Main(string[] args)
{
if (args.Length == 0)
{
Program.Menu();
}
else
{
Program.AllocConsole();
string lpApplicationName = args[0];
string input = "\"" + ((IEnumerable<string>)args).Skip<string>(1).Aggregate<string>((Func<string, string, string>)((x, y) => x + "\" \"" + y)) + "\"";
string str = Regex.Match(input, "(\"--remoting-auth-token=)([^\"]*)(\")").Groups[2].Value;
Console.WriteLine("Using Port: " + int.Parse(Regex.Match(input, "(\"--app-port=)([^\"]*)(\")").Groups[2].Value).ToString());
Console.WriteLine("Using Auth: " + str);
Console.WriteLine("CurrentDir: " + Environment.CurrentDirectory);
Console.WriteLine(new string('-', Console.BufferWidth - 1));
Console.WriteLine("App: " + lpApplicationName);
Console.WriteLine("Args: " + input);
string lpCommandLine = input.Replace("\"--no-proxy-server\"", "");
Console.WriteLine(new string('-', Console.BufferWidth - 1));
Console.WriteLine("App: " + lpApplicationName);
Console.WriteLine("Args: " + lpCommandLine);
Program.STARTUPINFO lpStartupInfo = new Program.STARTUPINFO();
Program.PROCESS_INFORMATION lpProcessInformation;
//if (!Program.CreateProcess(lpApplicationName, lpCommandLine, IntPtr.Zero, IntPtr.Zero, false, 2U, IntPtr.Zero, (string) null, ref lpStartupInfo, out lpProcessInformation))
// throw new Win32Exception();
try
{
Program.CreateProcess(lpApplicationName, lpCommandLine, IntPtr.Zero, IntPtr.Zero, true, 1U, IntPtr.Zero, (string)null, ref lpStartupInfo, out lpProcessInformation);
Program.DebugActiveProcessStop(lpProcessInformation.dwProcessId);
Process.GetProcessById(lpProcessInformation.dwProcessId).WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("LeagueClientUx.exe quit.");
Thread.Sleep(3000);
}
}
private static void Menu()
{
Program.AllocConsole();
RegistryKey registryKey = (RegistryKey)null;
string location = Assembly.GetExecutingAssembly().Location;
try
{
registryKey = Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\LeagueClientUx.exe");
}
catch (UnauthorizedAccessException ex)
{
try
{
new Process()
{
StartInfo = {
FileName = Assembly.GetExecutingAssembly().Location,
UseShellExecute = true,
Verb = "runas"
}
}.Start();
Environment.Exit(0);
}
catch
{
Console.WriteLine("Access denied.");
Thread.Sleep(1000);
Environment.Exit(1);
}
}
int num = 0;
label_31:
Console.Clear();
Console.ResetColor();
Console.CursorVisible = false;
Console.Write("Currently hooked to: ");
string str = (registryKey?.GetValue("debugger") ?? (object)"Nothing.").ToString().Replace(location, "This program.");
if (str == "This program.")
Console.ForegroundColor = ConsoleColor.Green;
else if (str != "Nothing.")
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(str);
if (num == 0)
Console.ForegroundColor = ConsoleColor.White;
else
Console.ResetColor();
Console.WriteLine((num == 0 ? "-->" : " ") + " Register LeagueClientUx.exe debugger IEFO.");
if (num == 1)
Console.ForegroundColor = ConsoleColor.White;
else
Console.ResetColor();
Console.WriteLine((num == 1 ? "-->" : " ") + " Unregister LeagueClientUx.exe debugger IEFO.");
if (num == 2)
Console.ForegroundColor = ConsoleColor.White;
else
Console.ResetColor();
Console.WriteLine((num == 2 ? "-->" : " ") + " Exit.");
bool flag = false;
while (!flag)
{
switch (Console.ReadKey(true).Key)
{
case ConsoleKey.Enter:
flag = true;
switch (num)
{
case 0:
if (registryKey != null)
{
registryKey.SetValue("debugger", (object)location);
continue;
}
continue;
case 1:
if (registryKey != null)
{
registryKey.DeleteValue("debugger");
continue;
}
continue;
case 2:
Environment.Exit(0);
continue;
default:
continue;
}
case ConsoleKey.UpArrow:
if (num != (num = Math.Max(num - 1, 0)))
{
flag = true;
continue;
}
continue;
case ConsoleKey.DownArrow:
if (num != (num = Math.Min(num + 1, 2)))
{
flag = true;
continue;
}
continue;
default:
continue;
}
}
goto label_31;
}
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AllocConsole();
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DebugActiveProcessStop([In] int Pid);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool CreateProcess(
string lpApplicationName,
string lpCommandLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
bool bInheritHandles,
uint dwCreationFlags,
IntPtr lpEnvironment,
string lpCurrentDirectory,
[In] ref Program.STARTUPINFO lpStartupInfo,
out Program.PROCESS_INFORMATION lpProcessInformation);
private struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public int dwProcessId;
public int dwThreadId;
}
private struct STARTUPINFO
{
public uint cb;
public string lpReserved;
public string lpDesktop;
public string lpTitle;
public uint dwX;
public uint dwY;
public uint dwXSize;
public uint dwYSize;
public uint dwXCountChars;
public uint dwYCountChars;
public uint dwFillAttribute;
public uint dwFlags;
public short wShowWindow;
public short cbReserved2;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdError;
}
}
}