-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
194 lines (174 loc) · 7.87 KB
/
Copy pathProgram.cs
File metadata and controls
194 lines (174 loc) · 7.87 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
using System;
using System.Diagnostics;
using Microsoft.Win32;
class Program
{
const string RegPath = @"SOFTWARE\MadeForNet\HTTPDebuggerPro";
static int Main(string[] args)
{
var nameGen = new NameGenerator();
string label = "User";
bool noLaunch = false;
bool patchFile = false;
bool dryRun = false;
bool restore = false;
try
{
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
{
case "--exe" when i + 1 < args.Length:
nameGen.InstallPath = args[++i];
break;
case "--ver" when i + 1 < args.Length:
nameGen.FileVersionOverride = args[++i];
break;
case "--label" when i + 1 < args.Length:
label = args[++i];
break;
case "--no-launch":
noLaunch = true;
break;
case "--patch-file":
patchFile = true;
break;
case "--dry-run":
dryRun = true;
break;
case "--restore":
restore = true;
break;
case "-h":
case "--help":
PrintUsage();
return 0;
default:
throw new ArgumentException("Unknown or incomplete argument: " + args[i]);
}
}
// Create() resolves the executable, reads FileVersion, computes the
// version-bound registry value name, and leaves all results available
// for the v10 patch planner. It does not write anything itself.
string snName = nameGen.Create();
string keyValue = new KeyGenerator().Create();
bool needsV10Patch = OnlineValidationPatch.NeedsV10Patch(nameGen.ParsedFileVersion);
OnlineValidationPatchPlan patchPlan = null;
if (needsV10Patch || patchFile || restore)
{
if (string.IsNullOrEmpty(nameGen.ResolvedInstallPath))
throw new InvalidOperationException(
"A real HTTPDebuggerUI.exe path is required for v10 patching; --ver alone is insufficient.");
patchPlan = OnlineValidationPatch.Analyze(nameGen.ResolvedInstallPath);
}
PrintIdentity(nameGen, snName, keyValue, label);
if (patchPlan != null)
PrintPatchPlan(patchPlan);
if (dryRun)
{
Console.WriteLine("dry-run : no registry or process changes made");
return 0;
}
if (restore)
{
EnsureUiIsClosed();
string backup = OnlineValidationPatch.RestoreFile(nameGen.ResolvedInstallPath);
Console.WriteLine("restored : " + nameGen.ResolvedInstallPath);
Console.WriteLine("from backup : " + backup);
return 0;
}
if (patchFile)
{
EnsureUiIsClosed();
string backup = OnlineValidationPatch.ApplyFilePatch(patchPlan);
Console.WriteLine("file patch : applied");
Console.WriteLine("backup : " + backup);
// Re-analyze the bytes that will be mapped by CreateProcess.
patchPlan = OnlineValidationPatch.Analyze(nameGen.ResolvedInstallPath);
}
if (needsV10Patch && !noLaunch)
EnsureUiIsClosed();
WriteRegistry(snName, keyValue, label);
Console.WriteLine($"wrote : HKCU\\{RegPath}");
if (needsV10Patch && !noLaunch)
{
int processId = RuntimePatcher.LaunchPatched(patchPlan);
Console.WriteLine($"launched : PID {processId} with response-758 checks and notification neutralized in memory");
}
else if (needsV10Patch)
{
Console.WriteLine("launch : skipped (--no-launch); an ordinary v10.3+ launch can invalidate the generated serial");
}
return 0;
}
catch (Exception ex)
{
Console.Error.WriteLine("error: " + ex.Message);
return 1;
}
}
static void WriteRegistry(string snName, string keyValue, string label)
{
using var key = Registry.CurrentUser.CreateSubKey(RegPath);
key.SetValue(snName, keyValue, RegistryValueKind.String);
key.SetValue("Label", label, RegistryValueKind.String);
}
static void EnsureUiIsClosed()
{
var processes = Process.GetProcessesByName("HTTPDebuggerUI");
try
{
if (processes.Length != 0)
throw new InvalidOperationException(
"Close every running HTTP Debugger window before applying or launching the v10 patch.");
}
finally
{
foreach (var process in processes)
process.Dispose();
}
}
static void PrintIdentity(NameGenerator nameGen, string snName, string keyValue, string label)
{
Console.WriteLine($"fileVersion : {nameGen.LastFileVersion}");
Console.WriteLine($"versionInt : {nameGen.LastVersionInt}");
Console.WriteLine($"vsn : 0x{nameGen.LastVolumeOrVersion:X8}");
Console.WriteLine($"name : {snName}");
Console.WriteLine($"key : {keyValue}");
Console.WriteLine($"label : {label}");
}
static void PrintPatchPlan(OnlineValidationPatchPlan plan)
{
Console.WriteLine($"binary : {plan.FilePath}");
Console.WriteLine($"sha256 : {plan.Sha256}");
Console.WriteLine($"patch state : {(plan.IsAlreadyPatched ? "persistent patch present" : "original response-758 checks")}");
for (int i = 0; i < plan.Sites.Count; i++)
{
var site = plan.Sites[i];
Console.WriteLine(
$"patch[{i}] : file+0x{site.ImmediateFileOffset:X}, RVA 0x{site.ImmediateRva:X}, value {site.CurrentValue}");
}
Console.WriteLine(
$"notify call : file+0x{plan.NotificationCallFileOffset:X}, RVA 0x{plan.NotificationCallRva:X}");
Console.WriteLine(
$"reject call : file+0x{plan.InvalidationCallFileOffset:X}, RVA 0x{plan.InvalidationCallRva:X}");
}
static void PrintUsage()
{
Console.WriteLine("HTTPDebuggerKeygen - v9 serial generator and v10.3+ runtime validation patch");
Console.WriteLine();
Console.WriteLine("usage: HTTPDebuggerKeygen [options]");
Console.WriteLine();
Console.WriteLine(" --exe <path> Path to HTTPDebuggerUI.exe (default: Program Files lookup)");
Console.WriteLine(" --ver <version> Override FileVersion for registry-only v9 research");
Console.WriteLine(" --label <name> Display name (default: User)");
Console.WriteLine(" --no-launch Write the registry serial but do not launch/patch v10 in memory");
Console.WriteLine(" --patch-file Persist the v10 patch in HTTPDebuggerUI.exe; creates a .bak rollback copy");
Console.WriteLine(" --restore Restore HTTPDebuggerUI.exe from the .bak rollback copy");
Console.WriteLine(" --dry-run Analyze the installed build without changing registry, files, or processes");
Console.WriteLine(" -h, --help Show this help");
Console.WriteLine();
Console.WriteLine("For v10.3+, the default mode launches HTTP Debugger, neutralizes both response-758");
Console.WriteLine("checks and their activation-state notification in memory, then continues startup.");
}
}