Skip to content

Commit 46d20dc

Browse files
committed
Added OverWolf.Client.BL patches
Patched ValidateExtension, BlockUnauthorizedExtension and IsWhiteListForValidation
1 parent 14a13cd commit 46d20dc

File tree

2 files changed

+83
-21
lines changed

2 files changed

+83
-21
lines changed

OverwolfInsiderPatcher/InjectMethods.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ namespace OverwolfInsiderPatcher
1212
{
1313
internal class InjectMethods
1414
{
15+
public static void PatchReturn(ref MethodDefinition method, bool retVal)
16+
{
17+
method.Body.ExceptionHandlers.Clear();
18+
method.Body.Variables.Clear();
19+
method.Body.Instructions.Clear();
20+
21+
method.Body.Instructions.Add(Instruction.Create(retVal ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0));
22+
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
23+
}
24+
1525
public static MethodDefinition OverwolfCoreGetExtensionSubscriptions(ref AssemblyDefinition overwolfCore, MethodDefinition overwolfCoreGES)
1626
{
1727
overwolfCoreGES.Body.ExceptionHandlers.Clear();
1828
overwolfCoreGES.Body.Variables.Clear();
1929
overwolfCoreGES.Body.Instructions.Clear();
2030
GenericInstanceType list = new GenericInstanceType(overwolfCore.MainModule.ImportReference(typeof(List<>))); //overwolfCore.MainModule.Import();
2131
TypeReference DetailedActivePlan;
22-
32+
2333
if (overwolfCore.MainModule.TryGetTypeReference("ODKv2API.DetailedActivePlan", out DetailedActivePlan)) // Get already imported class instead of import Overwolf.ODK.Common
2434
{
2535
TypeDefinition DetailedActivePlanDef = DetailedActivePlan.Resolve();
@@ -28,12 +38,12 @@ public static MethodDefinition OverwolfCoreGetExtensionSubscriptions(ref Assembl
2838
VariableDefinition iV = new VariableDefinition(overwolfCore.MainModule.ImportReference(typeof(int)));
2939
overwolfCoreGES.Body.Variables.Add(dapV);
3040
overwolfCoreGES.Body.Variables.Add(iV);
31-
41+
3242
{
3343

3444
TypeReference List = overwolfCore.MainModule.ImportReference(overwolfCore.MainModule.ImportReference(Type.GetType("System.Collections.Generic.List`1")).MakeGenericInstanceType(new TypeReference[] { DetailedActivePlan }));
35-
36-
45+
46+
3747
MethodDefinition listCtor = List.Resolve().Methods.First(x => x.Name == ".ctor");
3848
var listCtorRef = overwolfCore.MainModule.ImportReference(listCtor, List);
3949
listCtorRef.DeclaringType = List;
@@ -56,7 +66,7 @@ public static MethodDefinition OverwolfCoreGetExtensionSubscriptions(ref Assembl
5666
overwolfCoreGES.Body.Instructions[1] = (Instruction.Create(OpCodes.Stloc_0));
5767
overwolfCoreGES.Body.Instructions[2] = (Instruction.Create(OpCodes.Ldc_I4_0));
5868
overwolfCoreGES.Body.Instructions[3] = (Instruction.Create(OpCodes.Stloc_1));
59-
overwolfCoreGES.Body.Instructions[5] = (Instruction.Create(OpCodes.Ldloc_0));
69+
overwolfCoreGES.Body.Instructions[5] = (Instruction.Create(OpCodes.Ldloc_0));
6070
overwolfCoreGES.Body.Instructions[6] = (Instruction.Create(OpCodes.Newobj, overwolfCore.MainModule.ImportReference(DetailedActivePlanDef.Methods.First(x => x.Name == ".ctor")))); // DetailedActivePlanR constructor
6171
overwolfCoreGES.Body.Instructions[7] = (Instruction.Create(OpCodes.Dup));
6272
overwolfCoreGES.Body.Instructions[8] = (Instruction.Create(OpCodes.Ldc_R4, 1.0f));
@@ -134,7 +144,7 @@ public static MethodDefinition OverwolfSubscriptionsGetExtensionSubscriptions(re
134144
overwolfCoreGES.Body.Instructions[2] = Instruction.Create(OpCodes.Stind_Ref);
135145
overwolfCoreGES.Body.Instructions[3] = Instruction.Create(OpCodes.Ldarg_0);
136146
overwolfCoreGES.Body.Instructions[4] = Instruction.Create(OpCodes.Call, overwolfSubscriptions.MainModule.GetType("Overwolf.Subscriptions.Settings.SubscriptionRepository").Methods.First(x => x.Name == "IsRequiredServiceUnavailable"));
137-
//
147+
//
138148
overwolfCoreGES.Body.Instructions[6] = Instruction.Create(OpCodes.Ldc_I4_0);
139149
overwolfCoreGES.Body.Instructions[7] = Instruction.Create(OpCodes.Ret);
140150
overwolfCoreGES.Body.Instructions[8] = Instruction.Create(OpCodes.Ldarg_1);

OverwolfInsiderPatcher/Program.cs

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void Main()
136136
{
137137
overwolfSubscriptionsPath = dir + "\\Overwolf.Subscriptions.dll";
138138
Console.WriteLine("Overwolf.Subscriptions.dll found!");
139-
}
139+
}
140140
if (File.Exists(dir + "\\OverWolf.Client.BL.dll"))
141141
{
142142
overwolfBDDllPath = dir + "\\OverWolf.Client.BL.dll";
@@ -179,7 +179,7 @@ static void Main()
179179
Console.WriteLine("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
180180
Console.WriteLine("|| OverWolf.Client.Core.dll ||");
181181
Console.WriteLine("|| ||");
182-
var resolver = new DefaultAssemblyResolver();
182+
var resolver = new DefaultAssemblyResolver();
183183
resolver.AddSearchDirectory(Path.GetDirectoryName(overwolfCorePath));
184184
ReaderParameters reader = new ReaderParameters { AssemblyResolver = resolver, ReadWrite = true, InMemory = true };
185185
AssemblyDefinition overwolfCore = AssemblyDefinition.ReadAssembly(overwolfCorePath, reader);
@@ -228,14 +228,15 @@ static void Main()
228228
try
229229
{
230230
overwolfCoreGES = InjectMethods.OverwolfCoreGetExtensionSubscriptions(ref overwolfCore, overwolfCoreGES);
231-
} catch(Exception e)
231+
}
232+
catch (Exception e)
232233
{
233234
successful = false;
234235
Console.WriteLine("Error, Overwolf.Core will not be patched: ");
235236
Console.WriteLine(e);
236237
}
237238
}
238-
239+
239240
//
240241
}
241242

@@ -257,7 +258,8 @@ static void Main()
257258
{
258259
overwolfCoreExtensionWebAppStratContentValidation.Body.Instructions.Clear();
259260
overwolfCoreExtensionWebAppStratContentValidation.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
260-
} catch (Exception e)
261+
}
262+
catch (Exception e)
261263
{
262264
successful = false;
263265
Console.WriteLine("Error, Overwolf.Core will not be patched: ");
@@ -279,8 +281,8 @@ static void Main()
279281
if (File.Exists(backupFilePath))
280282
File.Delete(backupFilePath);
281283
File.Copy(overwolfCorePath, backupFilePath);
282-
if(successful)
283-
overwolfCore.Write(overwolfCorePath);
284+
if (successful)
285+
overwolfCore.Write(overwolfCorePath);
284286
Console.WriteLine("|| ------ Patched successfully ||");
285287
}
286288
catch (System.UnauthorizedAccessException)
@@ -300,25 +302,75 @@ static void Main()
300302

301303
if (File.Exists(overwolfBDDllPath))
302304
{
305+
Console.WriteLine();
306+
Console.WriteLine();
307+
Console.WriteLine("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
308+
Console.WriteLine("|| OverWolf.Client.BL.dll ||");
309+
Console.WriteLine("|| ||");
310+
Console.WriteLine("|| OverWolf.Client.BL.ODKv2.Managers.DataManager.ExtensionDataManager type found! ||");
303311
var resolver = new DefaultAssemblyResolver();
304312
resolver.AddSearchDirectory(Path.GetDirectoryName(overwolfBDDllPath));
305313
ReaderParameters reader = new ReaderParameters { AssemblyResolver = resolver, ReadWrite = true, ReadingMode = ReadingMode.Immediate, InMemory = true };
306-
AssemblyDefinition overwolfSubscriptions = AssemblyDefinition.ReadAssembly(overwolfBDDllPath, reader);
307-
TypeDefinition overwolfSubscriptionsModel = overwolfSubscriptions.MainModule.GetType("OverWolf.Client.BL.ODKv2.Managers.DataManager.ExtensionDataManager");
314+
AssemblyDefinition overwolfBD = AssemblyDefinition.ReadAssembly(overwolfBDDllPath, reader);
315+
TypeDefinition overwolfExtensionDataManager = overwolfBD.MainModule.GetType("OverWolf.Client.BL.ODKv2.Managers.DataManager.ExtensionDataManager");
308316

309-
foreach (var m in overwolfSubscriptionsModel.Methods)
317+
if (overwolfBD != null)
310318
{
311-
if (m.Name == "BlockUnauthorizedExtension" || m.Name == "ValidateExtension" || m.Name == "IsWhiteListForValidation")
319+
MethodDefinition validateExtensionMethod = overwolfExtensionDataManager.Methods.SingleOrDefault(x => x.Name == "ValidateExtension");
320+
MethodDefinition blockUnauthorizedExtensionMethod = overwolfExtensionDataManager.Methods.SingleOrDefault(x => x.Name == "BlockUnauthorizedExtension");
321+
MethodDefinition isWhiteListForValidationMethod = overwolfExtensionDataManager.Methods.SingleOrDefault(x => x.Name == "IsWhiteListForValidation");
322+
323+
if (validateExtensionMethod != null)
312324
{
313-
m.Body.Instructions.Clear();
325+
Console.WriteLine("|| -- ValidateExtension method found! ||");
326+
InjectMethods.PatchReturn(ref validateExtensionMethod, true);
327+
Console.WriteLine("|| ---- ValidateExtension method patched! ||");
328+
}
329+
else
330+
Console.WriteLine("ValidateExtension not found!");
314331

315-
m.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4_0));
316-
m.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
332+
if (blockUnauthorizedExtensionMethod != null)
333+
{
334+
Console.WriteLine("|| -- BlockUnauthorizedExtension method found! ||");
335+
InjectMethods.PatchReturn(ref blockUnauthorizedExtensionMethod, false);
336+
Console.WriteLine("|| ---- BlockUnauthorizedExtension method patched! ||");
337+
}
338+
else
339+
Console.WriteLine("BlockUnauthorizedExtension not found!");
317340

341+
if (isWhiteListForValidationMethod != null)
342+
{
343+
Console.WriteLine("|| -- IsWhiteListForValidation method found! ||");
344+
InjectMethods.PatchReturn(ref isWhiteListForValidationMethod, true);
345+
Console.WriteLine("|| ---- IsWhiteListForValidation method patched! ||");
318346
}
347+
else
348+
Console.WriteLine("IsWhiteListForValidation not found!");
319349
}
320350

321-
overwolfSubscriptions.Write(overwolfBDDllPath);
351+
string backupFilePath = Path.GetDirectoryName(overwolfBDDllPath) + "\\" + Path.GetFileNameWithoutExtension(overwolfBDDllPath) + "_bak.dll";
352+
353+
try
354+
{
355+
if (File.Exists(backupFilePath))
356+
File.Delete(backupFilePath);
357+
File.Copy(overwolfBDDllPath, backupFilePath);
358+
overwolfBD.Write(overwolfBDDllPath);
359+
Console.WriteLine("|| ------ Patched successfully ||");
360+
}
361+
catch (System.UnauthorizedAccessException)
362+
{
363+
Console.WriteLine("Permission denied");
364+
}
365+
catch (Exception e)
366+
{
367+
File.Delete(overwolfBDDllPath);
368+
if (File.Exists(backupFilePath))
369+
File.Copy(backupFilePath, overwolfBDDllPath);
370+
Console.WriteLine(e);
371+
}
372+
resolver.Dispose();
373+
Console.WriteLine("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
322374
}
323375

324376
if (File.Exists(overwolfSubscriptionsPath))

0 commit comments

Comments
 (0)