Skip to content

Commit fb43a0c

Browse files
committed
almost complete rewrite
1 parent 46d20dc commit fb43a0c

17 files changed

Lines changed: 1411 additions & 774 deletions

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# CS1591: Missing XML comment for publicly visible type or member
4+
dotnet_diagnostic.CS1591.severity = silent
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Bluscream;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
7+
namespace OverwolfPatcher.Classes
8+
{
9+
public class Overwolf
10+
{
11+
private const string ProcessName = "overwolf";
12+
13+
public DirectoryInfo ProgramFolder { get; set; }
14+
public DirectoryInfo DataFolder { get; set; }
15+
16+
public DirectoryInfo ExtensionsFolder => DataFolder.Combine("Extensions");
17+
public List<DirectoryInfo> ProgramVersionFolders => ProgramFolder.GetDirectories(searchPattern: "*.*.*.*").ToList(); // C:\Program Files (x86)\Overwolf\0.258.1.7\
18+
public List<Process> Processes => Process.GetProcessesByName(ProcessName).ToList();
19+
}
20+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Bluscream;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Text.RegularExpressions;
6+
7+
namespace OverwolfPatcher.Classes
8+
{
9+
public interface IPatch
10+
{
11+
public string Name { get; }
12+
public string Description { get; }
13+
public string RelativePath { get; }
14+
15+
public bool TryPatch(Overwolf overwolfDir, out Exception error);
16+
public bool TryUnpatch(Overwolf overwolfDir, out Exception error);
17+
}
18+
public static class PatchExtension // : IPatch
19+
{
20+
public static void PrintHeader(this IPatch patch)
21+
{
22+
Console.WriteLine();
23+
Console.WriteLine();
24+
var padding = Utils.GetPadding("");
25+
var box = new string('=', padding[2]);
26+
Console.WriteLine(box);
27+
Console.WriteLine(Utils.Pad(patch.Name));
28+
Console.WriteLine(Utils.Pad(patch.Description));
29+
Console.WriteLine(box);
30+
}
31+
32+
}
33+
}

OverwolfInsiderPatcher/InjectMethods.cs

Lines changed: 13 additions & 208 deletions
Large diffs are not rendered by default.

OverwolfInsiderPatcher/OverwolfInsiderPatcher.csproj renamed to OverwolfInsiderPatcher/OverwolfPatcher.csproj

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<LangVersion>Latest</LangVersion>
58
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
69
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
710
<ProjectGuid>{53370A50-3DC8-45C9-A300-D396D8731DE8}</ProjectGuid>
811
<OutputType>Exe</OutputType>
9-
<RootNamespace>OverwolfInsiderPatcher</RootNamespace>
10-
<AssemblyName>OverwolfInsiderPatcher</AssemblyName>
12+
<RootNamespace>OverwolfPatcher</RootNamespace>
13+
<AssemblyName>OverwolfPatcher</AssemblyName>
1114
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
15+
<!--TargetFramework>net5.0</TargetFramework-->
1216
<FileAlignment>512</FileAlignment>
1317
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1418
<Deterministic>true</Deterministic>
1519
<TargetFrameworkProfile />
1620
<NuGetPackageImportStamp>
1721
</NuGetPackageImportStamp>
22+
<IsWebBootstrapper>false</IsWebBootstrapper>
1823
<PublishUrl>publish\</PublishUrl>
1924
<Install>true</Install>
2025
<InstallFrom>Disk</InstallFrom>
@@ -27,19 +32,20 @@
2732
<MapFileExtensions>true</MapFileExtensions>
2833
<ApplicationRevision>0</ApplicationRevision>
2934
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
30-
<IsWebBootstrapper>false</IsWebBootstrapper>
3135
<UseApplicationTrust>false</UseApplicationTrust>
3236
<BootstrapperEnabled>true</BootstrapperEnabled>
3337
</PropertyGroup>
3438
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3539
<PlatformTarget>AnyCPU</PlatformTarget>
3640
<DebugSymbols>true</DebugSymbols>
3741
<DebugType>full</DebugType>
38-
<Optimize>false</Optimize>
42+
<Optimize>true</Optimize>
3943
<OutputPath>bin\Debug\</OutputPath>
4044
<DefineConstants>DEBUG;TRACE</DefineConstants>
4145
<ErrorReport>prompt</ErrorReport>
4246
<WarningLevel>4</WarningLevel>
47+
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
48+
<DocumentationFile>bin\Debug\OverwolfPatcher.xml</DocumentationFile>
4349
</PropertyGroup>
4450
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4551
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -52,7 +58,7 @@
5258
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
5359
</PropertyGroup>
5460
<PropertyGroup>
55-
<ApplicationIcon>IconFileOverwolf_32Bit_16_32_48_256.ico</ApplicationIcon>
61+
<ApplicationIcon>icon.ico</ApplicationIcon>
5662
</PropertyGroup>
5763
<PropertyGroup>
5864
<StartupObject>OverwolfInsiderPatcher.Program</StartupObject>
@@ -80,17 +86,27 @@
8086
<Reference Include="System.Xml" />
8187
</ItemGroup>
8288
<ItemGroup>
89+
<Compile Include="Classes\Overwolf.cs" />
90+
<Compile Include="Classes\Patch.cs" />
91+
<Compile Include="Patches\Extensions.cs" />
92+
<Compile Include="Patches\ClientCommonUtils.cs" />
93+
<Compile Include="Patches\Subscriptions.cs" />
94+
<Compile Include="Patches\ClientBL.cs" />
95+
<Compile Include="Utils\AssemblyInfo.cs" />
96+
<Compile Include="Utils\Extensions.cs" />
8397
<Compile Include="InjectMethods.cs" />
98+
<Compile Include="Patches\ClientCore.cs" />
8499
<Compile Include="Program.cs" />
85100
<Compile Include="Properties\AssemblyInfo.cs" />
101+
<Compile Include="Utils\Utils.cs" />
86102
</ItemGroup>
87103
<ItemGroup>
88104
<None Include="App.config" />
89105
<None Include="ILMerge.props" />
90106
<None Include="packages.config" />
91107
</ItemGroup>
92108
<ItemGroup>
93-
<Content Include="IconFileOverwolf_32Bit_16_32_48_256.ico" />
109+
<Content Include="icon.ico" />
94110
</ItemGroup>
95111
<ItemGroup>
96112
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using OverwolfPatcher.Classes;
3+
using Mono.Cecil;
4+
using System.Linq;
5+
using Bluscream;
6+
7+
namespace OverwolfPatcher.Patches;
8+
9+
internal class ClientBL: IPatch
10+
{
11+
12+
public string Name => "Client BL";
13+
public string Description => "Patching the overwolf client bl dll";
14+
public string RelativePath => "OverWolf.Client.BL.dll";
15+
16+
public bool TryPatch(Overwolf ow, out Exception error)
17+
{
18+
error = null;
19+
foreach (var versionFolder in ow.ProgramVersionFolders)
20+
{
21+
try
22+
{
23+
var fullPath = versionFolder.CombineFile(RelativePath);
24+
var fileString = $"\"{versionFolder.Name}\\{RelativePath}\"";
25+
if (!fullPath.Exists)
26+
{
27+
Console.WriteLine($"{fileString} does not exist, skipping...");
28+
}
29+
this.PrintHeader();
30+
var resolver = new DefaultAssemblyResolver();
31+
resolver.AddSearchDirectory(versionFolder.FullName);
32+
var reader = new ReaderParameters { AssemblyResolver = resolver, ReadWrite = true, ReadingMode = ReadingMode.Immediate, InMemory = true };
33+
34+
AssemblyDefinition overwolfBD = AssemblyDefinition.ReadAssembly(fullPath.FullName, reader);
35+
TypeDefinition overwolfExtensionDataManager = overwolfBD.MainModule.GetType("OverWolf.Client.BL.ODKv2.Managers.DataManager.ExtensionDataManager");
36+
37+
if (overwolfBD != null)
38+
{
39+
MethodDefinition validateExtensionMethod = overwolfExtensionDataManager.Methods.SingleOrDefault(x => x.Name == "ValidateExtension");
40+
if (validateExtensionMethod != null)
41+
{
42+
validateExtensionMethod.PatchReturnBool(true);
43+
} else
44+
Console.WriteLine("ValidateExtension not found!");
45+
46+
MethodDefinition blockUnauthorizedExtensionMethod = overwolfExtensionDataManager.Methods.SingleOrDefault(x => x.Name == "BlockUnauthorizedExtension");
47+
if (blockUnauthorizedExtensionMethod != null)
48+
{
49+
blockUnauthorizedExtensionMethod.PatchReturnBool(false);
50+
} else
51+
Console.WriteLine("BlockUnauthorizedExtension not found!");
52+
53+
MethodDefinition isWhiteListForValidationMethod = overwolfExtensionDataManager.Methods.SingleOrDefault(x => x.Name == "IsWhiteListForValidation");
54+
if (isWhiteListForValidationMethod != null)
55+
{
56+
isWhiteListForValidationMethod.PatchReturnBool(true);
57+
} else
58+
Console.WriteLine("IsWhiteListForValidation not found!");
59+
}
60+
61+
try
62+
{
63+
fullPath.Backup(true);
64+
overwolfBD.Write(fullPath.FullName);
65+
Console.WriteLine(Utils.Pad("Patched successfully"));
66+
} catch (UnauthorizedAccessException) { Console.WriteLine($"Permission denied for file {fileString}"); } catch (Exception e)
67+
{
68+
fullPath.Restore();
69+
Console.WriteLine(e);
70+
}
71+
resolver.Dispose();
72+
Console.WriteLine("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
73+
} catch (Exception ex)
74+
{
75+
error = ex;
76+
return false;
77+
}
78+
}
79+
return true;
80+
}
81+
82+
public bool TryUnpatch(Overwolf ow, out Exception error)
83+
{
84+
error = new NotImplementedException($"Unpatching is not implemented for {Name}");
85+
return false;
86+
}
87+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System.IO;
2+
using System;
3+
using OverwolfPatcher.Classes;
4+
using Mono.Cecil.Cil;
5+
using Mono.Cecil;
6+
using System.Linq;
7+
using Bluscream;
8+
using Mono.Cecil.Rocks;
9+
using System.Collections.Generic;
10+
11+
namespace OverwolfPatcher.Patches;
12+
13+
internal class ClientCommonUtils : IPatch
14+
{
15+
16+
public string Name => "Client Common Utils";
17+
public string Description => "Patching the overwolf client common utils dll";
18+
public string RelativePath => "OverWolf.Client.CommonUtils.dll";
19+
20+
public bool TryPatch(Overwolf ow, out Exception error)
21+
{
22+
error = null;
23+
foreach (var versionFolder in ow.ProgramVersionFolders)
24+
{
25+
try
26+
{
27+
var fullPath = versionFolder.CombineFile(RelativePath);
28+
var fileString = $"\"{versionFolder.Name}\\{RelativePath}\"";
29+
if (!fullPath.Exists)
30+
{
31+
Console.WriteLine($"{fileString} does not exist, skipping...");
32+
}
33+
this.PrintHeader();
34+
var resolver = new DefaultAssemblyResolver();
35+
resolver.AddSearchDirectory(versionFolder.FullName);
36+
var reader = new ReaderParameters { AssemblyResolver = resolver, ReadWrite = true, ReadingMode = ReadingMode.Immediate, InMemory = true };
37+
38+
AssemblyDefinition overwolfCore = AssemblyDefinition.ReadAssembly(fullPath.FullName, reader);
39+
TypeDefinition overwolfCoreCUFeatures = overwolfCore.MainModule.GetType("OverWolf.Client.CommonUtils.Features.CommonFeatures");
40+
if (overwolfCoreCUFeatures != null)
41+
{
42+
Console.WriteLine(Utils.Pad("OverWolf.Client.CommonUtils.Features.CommonFeatures type found!"));
43+
MethodDefinition enableDevToolsForQA = overwolfCoreCUFeatures.Methods.SingleOrDefault(x => x.Name == "EnableDevToolsForQA");
44+
if (enableDevToolsForQA != null)
45+
{
46+
enableDevToolsForQA.PatchReturnBool(true);
47+
} else
48+
{
49+
Console.WriteLine(Utils.Pad("EnableDevToolsForQA not found!"));
50+
Console.WriteLine("");
51+
}
52+
53+
} else
54+
{
55+
Console.WriteLine(Utils.Pad("OverWolf.Client.CommonUtils.Features.CommonFeatures type not found!"));
56+
}
57+
58+
try
59+
{
60+
fullPath.Backup(true);
61+
overwolfCore.Write(fullPath.FullName);
62+
Console.WriteLine(Utils.Pad("Patched successfully"));
63+
} catch (UnauthorizedAccessException) { Console.WriteLine($"Permission denied for file {fileString}"); } catch (Exception e)
64+
{
65+
fullPath.Restore();
66+
Console.WriteLine(e);
67+
}
68+
resolver.Dispose();
69+
Console.WriteLine("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
70+
} catch (Exception ex)
71+
{
72+
error = ex;
73+
return false;
74+
}
75+
}
76+
return true;
77+
}
78+
79+
public bool TryUnpatch(Overwolf ow, out Exception error)
80+
{
81+
error = new NotImplementedException($"Unpatching is not implemented for {Name}");
82+
return false;
83+
}
84+
85+
}

0 commit comments

Comments
 (0)