aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--cmake/macros/ConfigureBoost.cmake6
-rw-r--r--contrib/Connection Patcher/App.config6
-rw-r--r--contrib/Connection Patcher/Connection Patcher.csproj68
-rw-r--r--contrib/Connection Patcher/Connection Patcher.sln22
-rw-r--r--contrib/Connection Patcher/Helper.cs76
-rw-r--r--contrib/Connection Patcher/Patcher.cs130
-rw-r--r--contrib/Connection Patcher/Patches/Windows.cs40
-rw-r--r--contrib/Connection Patcher/Patterns/Windows.cs40
-rw-r--r--contrib/Connection Patcher/Program.cs189
-rw-r--r--contrib/Connection Patcher/Properties/AssemblyInfo.cs36
-rw-r--r--src/tools/CMakeLists.txt1
-rw-r--r--src/tools/connection_patcher/CMakeLists.txt48
-rw-r--r--src/tools/connection_patcher/Constants/BinaryTypes.hpp (renamed from contrib/Connection Patcher/Constants/BinaryTypes.cs)24
-rw-r--r--src/tools/connection_patcher/Helper.cpp58
-rw-r--r--src/tools/connection_patcher/Helper.hpp (renamed from contrib/Connection Patcher/Patches/Mac.cs)23
-rw-r--r--src/tools/connection_patcher/Patcher.cpp114
-rw-r--r--src/tools/connection_patcher/Patcher.hpp (renamed from contrib/Connection Patcher/Patterns/Mac.cs)32
-rw-r--r--src/tools/connection_patcher/Patches/Mac.hpp42
-rw-r--r--src/tools/connection_patcher/Patches/Windows.hpp51
-rw-r--r--src/tools/connection_patcher/Patterns/Mac.hpp42
-rw-r--r--src/tools/connection_patcher/Patterns/Windows.hpp51
-rw-r--r--src/tools/connection_patcher/Program.cpp197
23 files changed, 662 insertions, 636 deletions
diff --git a/.travis.yml b/.travis.yml
index 622666746a7..cb3d09c671c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,7 +12,7 @@ before_install:
- sudo apt-get -qq update
- sudo apt-get -qq install build-essential libtool gcc-4.8 g++-4.8 make cmake openssl
- sudo apt-get -qq install libssl-dev libmysqlclient15-dev libmysql++-dev libreadline6-dev zlib1g-dev libbz2-dev libzmq3-dev
- - sudo apt-get -qq install libboost1.55-dev libboost-thread1.55-dev libboost-system1.55-dev libboost-program-options1.55-dev
+ - sudo apt-get -qq install libboost1.55-dev libboost-thread1.55-dev libboost-filesystem1.55-dev libboost-system1.55-dev libboost-program-options1.55-dev
install:
- mysql -uroot -e 'create database test_mysql;'
diff --git a/cmake/macros/ConfigureBoost.cmake b/cmake/macros/ConfigureBoost.cmake
index 3d3791b8a93..81b4dd9abb2 100644
--- a/cmake/macros/ConfigureBoost.cmake
+++ b/cmake/macros/ConfigureBoost.cmake
@@ -25,11 +25,15 @@ if(WIN32)
add_definitions(-D_WIN32_WINNT=${ver})
endif()
-find_package(Boost 1.49 REQUIRED system thread program_options)
+find_package(Boost 1.49 REQUIRED system filesystem thread program_options)
add_definitions(-DBOOST_DATE_TIME_NO_LIB)
add_definitions(-DBOOST_REGEX_NO_LIB)
add_definitions(-DBOOST_CHRONO_NO_LIB)
+if(!WIN32) # https://svn.boost.org/trac/boost/ticket/6779
+ add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)
+endif()
+
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
diff --git a/contrib/Connection Patcher/App.config b/contrib/Connection Patcher/App.config
deleted file mode 100644
index 87b8cafdd3d..00000000000
--- a/contrib/Connection Patcher/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
- </startup>
-</configuration>
diff --git a/contrib/Connection Patcher/Connection Patcher.csproj b/contrib/Connection Patcher/Connection Patcher.csproj
deleted file mode 100644
index 7ee4bf6f972..00000000000
--- a/contrib/Connection Patcher/Connection Patcher.csproj
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProjectGuid>{137B1355-6A81-4A3A-A01E-93ABAA4FFFDB}</ProjectGuid>
- <OutputType>Exe</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Connection_Patcher</RootNamespace>
- <AssemblyName>Connection Patcher</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <PlatformTarget>AnyCPU</PlatformTarget>
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>TRACE;DEBUG</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- <RunCodeAnalysis>false</RunCodeAnalysis>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <PlatformTarget>AnyCPU</PlatformTarget>
- <DebugType>none</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>
- </DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
- <UseVSHostingProcess>false</UseVSHostingProcess>
- </PropertyGroup>
- <PropertyGroup>
- <NoWin32Manifest>true</NoWin32Manifest>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Constants\BinaryTypes.cs" />
- <Compile Include="Helper.cs" />
- <Compile Include="Patcher.cs" />
- <Compile Include="Patches\Mac.cs" />
- <Compile Include="Patches\Windows.cs" />
- <Compile Include="Patterns\Mac.cs" />
- <Compile Include="Patterns\Windows.cs" />
- <Compile Include="Program.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="App.config" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project> \ No newline at end of file
diff --git a/contrib/Connection Patcher/Connection Patcher.sln b/contrib/Connection Patcher/Connection Patcher.sln
deleted file mode 100644
index 7ba4e8c6137..00000000000
--- a/contrib/Connection Patcher/Connection Patcher.sln
+++ /dev/null
@@ -1,22 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30110.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connection Patcher", "Connection Patcher.csproj", "{137B1355-6A81-4A3A-A01E-93ABAA4FFFDB}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {137B1355-6A81-4A3A-A01E-93ABAA4FFFDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {137B1355-6A81-4A3A-A01E-93ABAA4FFFDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {137B1355-6A81-4A3A-A01E-93ABAA4FFFDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {137B1355-6A81-4A3A-A01E-93ABAA4FFFDB}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/contrib/Connection Patcher/Helper.cs b/contrib/Connection Patcher/Helper.cs
deleted file mode 100644
index d0e8f6655e7..00000000000
--- a/contrib/Connection Patcher/Helper.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using Connection_Patcher.Constants;
-using System;
-using System.IO;
-using System.Security.Cryptography;
-
-namespace Connection_Patcher
-{
- class Helper
- {
- public static BinaryTypes GetBinaryType(byte[] data)
- {
- BinaryTypes type = 0u;
-
- using (var reader = new BinaryReader(new MemoryStream(data)))
- {
- var magic = (uint)reader.ReadUInt16();
-
- // Check MS-DOS magic
- if (magic == 0x5A4D)
- {
- reader.BaseStream.Seek(0x3C, SeekOrigin.Begin);
-
- // Read PE start offset
- var peOffset = reader.ReadUInt32();
-
- reader.BaseStream.Seek(peOffset, SeekOrigin.Begin);
-
- var peMagic = reader.ReadUInt32();
-
- // Check PE magic
- if (peMagic != 0x4550)
- throw new NotSupportedException("Not a PE file!");
-
- type = (BinaryTypes)reader.ReadUInt16();
- }
- else
- {
- reader.BaseStream.Seek(0, SeekOrigin.Begin);
-
- type = (BinaryTypes)reader.ReadUInt32();
- }
- }
-
- return type;
- }
-
- public static string GetFileChecksum(byte[] data)
- {
- using (var stream = new BufferedStream(new MemoryStream(data), 1200000))
- {
- var sha256 = new SHA256Managed();
- var checksum = sha256.ComputeHash(stream);
-
- return BitConverter.ToString(checksum).Replace("-", "").ToLower();
- }
- }
- }
-}
diff --git a/contrib/Connection Patcher/Patcher.cs b/contrib/Connection Patcher/Patcher.cs
deleted file mode 100644
index 8e73997365c..00000000000
--- a/contrib/Connection Patcher/Patcher.cs
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using Connection_Patcher.Constants;
-using System;
-using System.IO;
-
-namespace Connection_Patcher
-{
- class Patcher : IDisposable
- {
- public string Binary { get; set; }
- public bool Initialized { get; private set; }
- public BinaryTypes Type { get; private set; }
-
- public byte[] binary;
- bool success;
-
- public Patcher(string file)
- {
- Initialized = false;
- success = false;
-
- using (var stream = new MemoryStream(File.ReadAllBytes(file)))
- {
- Binary = file;
- binary = stream.ToArray();
-
- if (binary != null)
- {
- Type = Helper.GetBinaryType(binary);
-
- Initialized = true;
- }
- }
- }
-
- public void Patch(byte[] bytes, byte[] pattern, long address = 0)
- {
- if (Initialized && (address != 0 || binary.Length >= pattern.Length))
- {
- var offset = pattern == null ? address : SearchOffset(pattern);
- Console.WriteLine("Found offset {0}", offset);
-
- if (offset != 0 && binary.Length >= bytes.Length)
- {
- try
- {
- for (int i = 0; i < bytes.Length; i++)
- binary[offset + i] = bytes[i];
- }
- catch (Exception ex)
- {
- throw new NotSupportedException(ex.Message);
- }
- }
- }
- }
-
- long SearchOffset(byte[] pattern)
- {
- var matches = 0;
-
- for (long i = 0; i < binary.Length; i++)
- {
- matches = 0;
-
- for (int j = 0; j < pattern.Length; j++)
- {
- if (pattern.Length > (binary.Length - i))
- return 0;
-
- if (pattern[j] == 0)
- {
- matches++;
- continue;
- }
-
- if (binary[i + j] != pattern[j])
- break;
-
- matches++;
- }
-
- if (matches == pattern.Length)
- return i;
- }
-
- return 0;
- }
-
- public void Finish()
- {
- success = true;
- }
-
- public void Dispose()
- {
- try
- {
- if (File.Exists(Binary))
- File.Delete(Binary);
-
- if (success)
- File.WriteAllBytes(Binary, binary);
- }
- catch (UnauthorizedAccessException)
- {
-
- }
-
- binary = null;
- }
- }
-}
diff --git a/contrib/Connection Patcher/Patches/Windows.cs b/contrib/Connection Patcher/Patches/Windows.cs
deleted file mode 100644
index c76f71312fb..00000000000
--- a/contrib/Connection Patcher/Patches/Windows.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace Connection_Patcher.Patches
-{
- class Windows
- {
- public static class x86
- {
- public static byte[] BNet = { 0xC7, 0x40, 0x0C, 0xD5, 0xF8, 0x7F, 0x82 };
- public static byte[] Connect = { 0xEB };
- public static byte[] Password = { 0x75 };
- public static byte[] Signature = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xEB };
- }
-
- public static class x64
- {
- public static byte[] BNet = { 0xB8, 0xD5, 0xF8, 0x7F, 0x82, 0x89, 0x41, 0x0C, 0x48, 0x8B, 0xC1, 0xC3 };
- public static byte[] Portal = new byte[18];
- public static byte[] Connect = { 0xEB };
- public static byte[] Password = { 0x75 };
- public static byte[] Signature = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xE9 };
- }
- }
-}
diff --git a/contrib/Connection Patcher/Patterns/Windows.cs b/contrib/Connection Patcher/Patterns/Windows.cs
deleted file mode 100644
index fef0c47d465..00000000000
--- a/contrib/Connection Patcher/Patterns/Windows.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace Connection_Patcher.Patterns
-{
- class Windows
- {
- public static class x86
- {
- public static byte[] BNet = { 0x8B, 0x75, 0x08, 0x8D, 0x78, 0x0C };
- public static byte[] Connect = { 0x74, 0x33, 0x6A, 0x04, 0xFF, 0x75, 0xF8 };
- public static byte[] Password = { 0x74, 0x89, 0x8B, 0x16, 0x8B, 0x42, 0x04 };
- public static byte[] Signature = { 0xE8, 0x00, 0x00, 0x00, 0x00, 0x84, 0xC0, 0x75, 0x5F, 0x33, 0xC0 };
- }
-
- public static class x64
- {
- public static byte[] BNet = { 0x8B, 0x02, 0x89, 0x41, 0x0C, 0x48, 0x8B, 0xC1, 0xC3 };
- public static byte[] Portal = { 0x2E, 0x6C, 0x6F, 0x67, 0x6F, 0x6E, 0x2E, 0x62, 0x61, 0x74, 0x74, 0x6C, 0x65, 0x2E, 0x6E, 0x65, 0x74, 0x00 };
- public static byte[] Connect = { 0x74, 0x2C, 0x48, 0x8D, 0x4C, 0x24, 0x78 };
- public static byte[] Password = { 0x74, 0x84, 0x48, 0x8B, 0x03 };
- public static byte[] Signature = { 0xE8, 0x00, 0x00, 0x00, 0x00, 0x84, 0xC0, 0x0F, 0x85, 0x88, 0x00, 0x00, 0x00, 0x45, 0x33, 0xC0 };
- }
- }
-}
diff --git a/contrib/Connection Patcher/Program.cs b/contrib/Connection Patcher/Program.cs
deleted file mode 100644
index 579f47a09f8..00000000000
--- a/contrib/Connection Patcher/Program.cs
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using Connection_Patcher.Constants;
-using System;
-using System.IO;
-using System.Net;
-using System.Text;
-using System.Threading;
-
-namespace Connection_Patcher
-{
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length >= 1)
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
-
- Console.WriteLine("Client Connection Patcher");
- Console.WriteLine("Press Enter to patch...");
-
- Console.ReadKey(true);
-
- var commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
- var modulePath = "";
- var moduleFile = "";
-
- // Let's use Win64 as default module
- var modulePatch = Patches.Windows.x64.Password;
- var modulePattern = Patterns.Windows.x64.Password;
- var patchBNet = Patches.Windows.x64.BNet;
- var patternBNet = Patterns.Windows.x64.BNet;
- var patchPortal = Patches.Windows.x64.Portal;
- var patternPortal = Patterns.Windows.x64.Portal;
- var patchConnect = Patches.Windows.x64.Connect;
- var patternConnect = Patterns.Windows.x64.Connect;
- var patchSignature = Patches.Windows.x64.Signature;
- var patternSignature = Patterns.Windows.x64.Signature;
- var fileName = "";
-
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("Creating patched binaries for ");
-
- using (var patcher = new Patcher(args[0]))
- {
- switch (patcher.Type)
- {
- case BinaryTypes.Pe32:
- Console.WriteLine("Win32 client...");
- patchBNet = Patches.Windows.x86.BNet;
- patternBNet = Patterns.Windows.x86.BNet;
- patchConnect = Patches.Windows.x86.Connect;
- patternConnect = Patterns.Windows.x86.Connect;
- patchSignature = Patches.Windows.x86.Signature;
- patternSignature = Patterns.Windows.x86.Signature;
- fileName = patcher.Binary.Replace(".exe", "") + "_Patched.exe";
-
- modulePath = commonAppData + "/Blizzard Entertainment/Battle.net/Cache/";
- moduleFile = "8f52906a2c85b416a595702251570f96d3522f39237603115f2f1ab24962043c.auth";
- modulePatch = Patches.Windows.x86.Password;
- modulePattern = Patterns.Windows.x86.Password;
- break;
- case BinaryTypes.Pe64:
- Console.WriteLine("Win64 client...");
- fileName = patcher.Binary.Replace(".exe", "") + "_Patched.exe";
-
- modulePath = commonAppData + "/Blizzard Entertainment/Battle.net/Cache/";
- moduleFile = "0a3afee2cade3a0e8b458c4b4660104cac7fc50e2ca9bef0d708942e77f15c1d.auth";
- break;
- case BinaryTypes.Mach32:
- throw new NotSupportedException("Type: " + patcher.Type + " not supported!");
- case BinaryTypes.Mach64:
- Console.WriteLine("Mac client...");
- patchBNet = Patches.Mac.x64.BNet;
- patternBNet = Patterns.Mac.x64.BNet;
- patchConnect = Patterns.Windows.x64.Connect;
- patternConnect = Patterns.Windows.x64.Connect;
- patchSignature = Patches.Mac.x64.Signature;
- patternSignature = Patterns.Mac.x64.Signature;
- fileName = patcher.Binary + " Patched";
-
- modulePath = "/Users/Shared/Blizzard/Battle.net/Cache/";
- moduleFile = "97eeb2e28e9e56ed6a22d09f44e2ff43c93315e006bbad43bafc0defaa6f50ae.auth";
- modulePatch = Patches.Mac.x64.Password;
- modulePattern = Patterns.Mac.x64.Password;
- break;
- default:
- throw new NotSupportedException("Type: " + patcher.Type + " not supported!");
- }
-
- patcher.Patch(patchBNet, patternBNet);
- patcher.Patch(patchPortal, patternPortal);
- patcher.Patch(patchConnect, patternConnect);
- patcher.Patch(patchSignature, patternSignature);
-
- patcher.Binary = fileName;
-
- patcher.Finish();
-
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Patching done.");
-
- CreateModule(moduleFile, modulePath, modulePatch, modulePattern);
-
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Successfully created your patched binaries.");
- }
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Wrong number of arguments: Missing client file.");
- }
-
- Console.ForegroundColor = ConsoleColor.Gray;
- Thread.Sleep(5000);
-
- Environment.Exit(0);
- }
-
- static void CreateModule(string moduleName, string path, byte[] patches, byte[] patterns)
- {
- var modulePath = path + moduleName[0] + moduleName[1] + "/" + moduleName[2] + moduleName[3];
- var module = modulePath + "/" + moduleName;
-
- if (!File.Exists(module))
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Base module doesn't exist, downloading it...");
-
- if (!Directory.Exists(modulePath))
- Directory.CreateDirectory(modulePath);
-
- var webClient = new WebClient();
-
- webClient.DownloadFileCompleted += (o, e) => PatchModule(module, path, patches, patterns);
- webClient.DownloadFileAsync(new Uri("http://xx.depot.battle.net:1119/" + moduleName), module);
-
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Done.");
- }
- else
- PatchModule(module, path, patches, patterns);
- }
-
- static void PatchModule(string file, string path, byte[] patches, byte[] pattern)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Patching module...");
-
- using (var patcher2 = new Patcher(file))
- {
- patcher2.Patch(patches, pattern);
-
- var moduleName = Helper.GetFileChecksum(patcher2.binary) + ".auth";
- var modulePath = path + moduleName[0] + moduleName[1] + "/" + moduleName[2] + moduleName[3];
-
- if (!Directory.Exists(modulePath))
- Directory.CreateDirectory(modulePath);
-
- patcher2.Binary = modulePath + "/" + moduleName;
-
- patcher2.Finish();
- }
-
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Patching module finished.");
-
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- }
-}
diff --git a/contrib/Connection Patcher/Properties/AssemblyInfo.cs b/contrib/Connection Patcher/Properties/AssemblyInfo.cs
deleted file mode 100644
index b1d174575c5..00000000000
--- a/contrib/Connection Patcher/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Connection Patcher")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Connection Patcher")]
-[assembly: AssemblyCopyright("Copyright © 2014")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("07c6905b-5b42-4804-81fe-73d0f74ebfb1")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index c2ea8a85926..29dba016e87 100644
--- a/src/tools/CMakeLists.txt
+++ b/src/tools/CMakeLists.txt
@@ -8,6 +8,7 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+add_subdirectory(connection_patcher)
add_subdirectory(map_extractor)
add_subdirectory(vmap4_assembler)
add_subdirectory(vmap4_extractor)
diff --git a/src/tools/connection_patcher/CMakeLists.txt b/src/tools/connection_patcher/CMakeLists.txt
new file mode 100644
index 00000000000..8867ec5170b
--- /dev/null
+++ b/src/tools/connection_patcher/CMakeLists.txt
@@ -0,0 +1,48 @@
+# Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/src/server/shared
+ ${CMAKE_SOURCE_DIR}/src/server/shared/Cryptography
+ ${CMAKE_SOURCE_DIR}/src/server/shared/Debugging
+ ${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
+ ${OPENSSL_INCLUDE_DIR}
+)
+
+set(HEADER_FILES
+ Helper.hpp
+ Patcher.hpp
+ Constants/BinaryTypes.hpp
+ Patches/Mac.hpp
+ Patches/Windows.hpp
+ Patterns/Mac.hpp
+ Patterns/Windows.hpp
+)
+
+set(SRC_FILES
+ Helper.cpp
+ Patcher.cpp
+ Program.cpp
+)
+
+add_executable(connection_patcher ${HEADER_FILES} ${SRC_FILES})
+
+target_link_libraries(connection_patcher
+ shared
+ ${OPENSSL_LIBRARIES}
+ ${Boost_LIBRARIES}
+)
+
+if (UNIX)
+ install(TARGETS connection_patcher DESTINATION bin)
+elseif (WIN32)
+ install(TARGETS connection_patcher DESTINATION "${CMAKE_INSTALL_PREFIX}")
+endif ()
diff --git a/contrib/Connection Patcher/Constants/BinaryTypes.cs b/src/tools/connection_patcher/Constants/BinaryTypes.hpp
index b98a7ea73c0..fc7b34339fa 100644
--- a/contrib/Connection Patcher/Constants/BinaryTypes.cs
+++ b/src/tools/connection_patcher/Constants/BinaryTypes.hpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
*
@@ -16,14 +16,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace Connection_Patcher.Constants
+#ifndef CONNECTION_PATCHER_CONSTANTS_BINARYTYPES_HPP
+#define CONNECTION_PATCHER_CONSTANTS_BINARYTYPES_HPP
+
+#include <cstdint>
+
+namespace Connection_Patcher
{
- enum BinaryTypes : uint
+ namespace Constants
{
- None = 0000000000,
- Pe32 = 0x0000014C,
- Pe64 = 0x00008664,
- Mach32 = 0xFEEDFACE,
- Mach64 = 0xFEEDFACF
+ enum class BinaryTypes : uint32_t
+ {
+ Pe32 = 0x0000014C,
+ Pe64 = 0x00008664,
+ Mach64 = 0xFEEDFACF
+ };
}
}
+
+#endif
diff --git a/src/tools/connection_patcher/Helper.cpp b/src/tools/connection_patcher/Helper.cpp
new file mode 100644
index 00000000000..75de2452d26
--- /dev/null
+++ b/src/tools/connection_patcher/Helper.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Helper.hpp"
+
+#include <SHA256.h>
+#include <Util.h>
+
+#include <stdexcept>
+
+namespace Connection_Patcher
+{
+ namespace Helper
+ {
+ Constants::BinaryTypes GetBinaryType(std::vector<unsigned char> const& data)
+ {
+ // Check MS-DOS magic
+ if (*reinterpret_cast<uint16_t const*>(data.data()) == 0x5A4D)
+ {
+ uint32_t const peOffset(*reinterpret_cast<uint32_t const*>(data.data() + 0x3C));
+
+ // Check PE magic
+ if (*reinterpret_cast<uint32_t const*>(data.data() + peOffset) != 0x4550)
+ throw std::invalid_argument("Not a PE file!");
+
+ return Constants::BinaryTypes(*reinterpret_cast<uint16_t const*>(data.data() + peOffset + 4));
+ }
+ else
+ {
+ return Constants::BinaryTypes(*reinterpret_cast<uint32_t const*>(data.data()));
+ }
+ }
+
+ std::string GetFileChecksum(std::vector<unsigned char> const& data)
+ {
+ SHA256Hash h;
+ h.UpdateData(data.data(), data.size());
+ h.Finalize();
+
+ return ByteArrayToHexStr(h.GetDigest(), h.GetLength());
+ }
+ }
+}
diff --git a/contrib/Connection Patcher/Patches/Mac.cs b/src/tools/connection_patcher/Helper.hpp
index aab9e57c240..ed6f91363e6 100644
--- a/contrib/Connection Patcher/Patches/Mac.cs
+++ b/src/tools/connection_patcher/Helper.hpp
@@ -16,16 +16,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace Connection_Patcher.Patches
+#ifndef CONNECTION_PATCHER_HELPER_HPP
+#define CONNECTION_PATCHER_HELPER_HPP
+
+#include "Constants/BinaryTypes.hpp"
+
+#include <vector>
+#include <string>
+
+namespace Connection_Patcher
{
- class Mac
+ namespace Helper
{
- public static class x64
- {
- public static byte[] BNet = { 0xB8, 0xD5, 0xF8, 0x7F, 0x82, 0x89, 0x47, 0x0C, 0x5D, 0xC3, 0x90, 0x90, 0x90 };
- public static byte[] Connect = { };
- public static byte[] Password = { 0x0F, 0x85 };
- public static byte[] Signature = { 0x45, 0x31, 0xED, 0x4D, 0x89, 0xFC, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xEB };
- }
+ Constants::BinaryTypes GetBinaryType(std::vector<unsigned char> const& data);
+ std::string GetFileChecksum(std::vector<unsigned char> const& data);
}
}
+
+#endif
diff --git a/src/tools/connection_patcher/Patcher.cpp b/src/tools/connection_patcher/Patcher.cpp
new file mode 100644
index 00000000000..65cf1704472
--- /dev/null
+++ b/src/tools/connection_patcher/Patcher.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * asize_t with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Patcher.hpp"
+#include "Helper.hpp"
+
+#include <boost/filesystem.hpp>
+
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <stdexcept>
+
+namespace
+{
+ std::vector<unsigned char> read_file(boost::filesystem::path const& path)
+ {
+ std::ifstream ifs(path.string(), std::ifstream::binary);
+ if (!ifs)
+ throw std::runtime_error("could not open " + path.string());
+
+ ifs >> std::noskipws;
+
+ return {std::istream_iterator<unsigned char>(ifs), std::istream_iterator<unsigned char>()};
+ }
+
+ void write_file(boost::filesystem::path const& path, std::vector<unsigned char> const& data)
+ {
+ std::ofstream ofs(path.string(), std::ofstream::binary);
+ if (!ofs)
+ throw std::runtime_error("could not open " + path.string());
+
+ ofs << std::noskipws;
+
+ std::copy(data.begin(), data.end(), std::ostream_iterator<unsigned char>(ofs));
+ }
+
+ size_t SearchOffset (std::vector<unsigned char> const& binary, std::vector<unsigned char> const& pattern)
+ {
+ for (size_t i = 0; i < binary.size(); i++)
+ {
+ size_t matches = 0;
+
+ for (size_t j = 0; j < pattern.size(); j++)
+ {
+ if (pattern.size() > (binary.size() - i))
+ throw std::runtime_error("unable to find pattern");
+
+ if (pattern[j] == 0)
+ {
+ matches++;
+ continue;
+ }
+
+ if (binary[i + j] != pattern[j])
+ break;
+
+ matches++;
+ }
+
+ if (matches == pattern.size())
+ return i;
+ }
+
+ throw std::runtime_error("unable to find pattern");
+ }
+}
+
+namespace Connection_Patcher
+{
+ Patcher::Patcher(boost::filesystem::path file)
+ : binary(read_file(file))
+ , Type(Helper::GetBinaryType(binary))
+ {}
+
+ void Patcher::Patch(std::vector<unsigned char> const& bytes, std::vector<unsigned char> const& pattern)
+ {
+ if (binary.size() < pattern.size())
+ throw std::logic_error("pattern larger than binary");
+
+ if (pattern.empty())
+ return;
+
+ size_t const offset(SearchOffset(binary, pattern));
+ std::cout << "Found offset " << offset << std::endl;
+
+ if (offset != 0 && binary.size() >= bytes.size())
+ for (size_t i = 0; i < bytes.size(); i++)
+ binary[offset + i] = bytes[i];
+ }
+
+ void Patcher::Finish(boost::filesystem::path out)
+ {
+ if (boost::filesystem::exists(out))
+ boost::filesystem::remove(out);
+
+ write_file(out, binary);
+ }
+}
diff --git a/contrib/Connection Patcher/Patterns/Mac.cs b/src/tools/connection_patcher/Patcher.hpp
index fa89a667105..ecdf21815d1 100644
--- a/contrib/Connection Patcher/Patterns/Mac.cs
+++ b/src/tools/connection_patcher/Patcher.hpp
@@ -16,16 +16,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-namespace Connection_Patcher.Patterns
+#ifndef CONNECTION_PATCHER_PATCHER_HPP
+#define CONNECTION_PATCHER_PATCHER_HPP
+
+#include "Constants/BinaryTypes.hpp"
+
+#include <boost/filesystem.hpp>
+
+#include <vector>
+#include <string>
+
+namespace Connection_Patcher
{
- class Mac
+ struct Patcher
{
- public static class x64
- {
- public static byte[] BNet = { 0x8B, 0x06, 0x89, 0x47, 0x0C, 0x5D, 0xC3 };
- public static byte[] Connect = { };
- public static byte[] Password = { 0x0F, 0x84, 0x00, 0xFF, 0xFF, 0xFF, 0x49, 0x8B, 0x45, 0x00, 0xB9, 0x40 };
- public static byte[] Signature = { 0xE8, 0x00, 0x00, 0x00, 0x00, 0x45, 0x31, 0xED, 0x4D, 0x89, 0xFC, 0x84, 0xC0, 0x75 };
- }
- }
+ std::vector<unsigned char> binary;
+ Constants::BinaryTypes Type;
+
+ Patcher (boost::filesystem::path file);
+
+ void Patch(std::vector<unsigned char> const& bytes, std::vector<unsigned char> const& pattern);
+ void Finish (boost::filesystem::path out);
+ };
}
+
+#endif
diff --git a/src/tools/connection_patcher/Patches/Mac.hpp b/src/tools/connection_patcher/Patches/Mac.hpp
new file mode 100644
index 00000000000..02279730668
--- /dev/null
+++ b/src/tools/connection_patcher/Patches/Mac.hpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CONNECTION_PATCHER_PATCHES_MAC_HPP
+#define CONNECTION_PATCHER_PATCHES_MAC_HPP
+
+#include <vector>
+
+namespace Connection_Patcher
+{
+ namespace Patches
+ {
+ namespace Mac
+ {
+ struct x64
+ {
+ static const std::vector<unsigned char> BNet () { return { 0xB8, 0xD5, 0xF8, 0x7F, 0x82, 0x89, 0x47, 0x0C, 0x5D, 0xC3, 0x90, 0x90, 0x90 }; }
+ static const std::vector<unsigned char> Portal () { return { }; }
+ static const std::vector<unsigned char> Connect () { return { }; }
+ static const std::vector<unsigned char> Password () { return { 0x0F, 0x85 }; }
+ static const std::vector<unsigned char> Signature() { return { 0x45, 0x31, 0xED, 0x4D, 0x89, 0xFC, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xEB }; }
+ };
+ };
+ }
+}
+
+#endif
diff --git a/src/tools/connection_patcher/Patches/Windows.hpp b/src/tools/connection_patcher/Patches/Windows.hpp
new file mode 100644
index 00000000000..2114f2edae1
--- /dev/null
+++ b/src/tools/connection_patcher/Patches/Windows.hpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CONNECTION_PATCHER_PATCHES_WINDOWS_HPP
+#define CONNECTION_PATCHER_PATCHES_WINDOWS_HPP
+
+#include <vector>
+
+namespace Connection_Patcher
+{
+ namespace Patches
+ {
+ namespace Windows
+ {
+ struct x86
+ {
+ static const std::vector<unsigned char> BNet () { return { 0xC7, 0x40, 0x0C, 0xD5, 0xF8, 0x7F, 0x82 }; }
+ static const std::vector<unsigned char> Portal () { return { }; }
+ static const std::vector<unsigned char> Connect () { return { 0xEB }; }
+ static const std::vector<unsigned char> Password () { return { 0x75 }; }
+ static const std::vector<unsigned char> Signature() { return { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xEB }; }
+ };
+
+ struct x64
+ {
+ static const std::vector<unsigned char> BNet () { return { 0xB8, 0xD5, 0xF8, 0x7F, 0x82, 0x89, 0x41, 0x0C, 0x48, 0x8B, 0xC1, 0xC3 }; }
+ static const std::vector<unsigned char> Portal () { return { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; }
+ static const std::vector<unsigned char> Connect () { return { 0xEB }; }
+ static const std::vector<unsigned char> Password () { return { 0x75 }; }
+ static const std::vector<unsigned char> Signature() { return { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xE9 }; }
+ };
+ };
+ }
+}
+
+#endif
diff --git a/src/tools/connection_patcher/Patterns/Mac.hpp b/src/tools/connection_patcher/Patterns/Mac.hpp
new file mode 100644
index 00000000000..78fa0c61b1c
--- /dev/null
+++ b/src/tools/connection_patcher/Patterns/Mac.hpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CONNECTION_PATCHER_PATTERNS_MAC_HPP
+#define CONNECTION_PATCHER_PATTERNS_MAC_HPP
+
+#include <vector>
+
+namespace Connection_Patcher
+{
+ namespace Patterns
+ {
+ namespace Mac
+ {
+ struct x64
+ {
+ static const std::vector<unsigned char> BNet () { return { 0x8B, 0x06, 0x89, 0x47, 0x0C, 0x5D, 0xC3 }; }
+ static const std::vector<unsigned char> Portal () { return { }; }
+ static const std::vector<unsigned char> Connect () { return { }; }
+ static const std::vector<unsigned char> Password () { return { 0x0F, 0x84, 0x00, 0xFF, 0xFF, 0xFF, 0x49, 0x8B, 0x45, 0x00, 0xB9, 0x40 }; }
+ static const std::vector<unsigned char> Signature() { return { 0xE8, 0x00, 0x00, 0x00, 0x00, 0x45, 0x31, 0xED, 0x4D, 0x89, 0xFC, 0x84, 0xC0, 0x75 }; }
+ };
+ };
+ }
+}
+
+#endif
diff --git a/src/tools/connection_patcher/Patterns/Windows.hpp b/src/tools/connection_patcher/Patterns/Windows.hpp
new file mode 100644
index 00000000000..0f51c471a85
--- /dev/null
+++ b/src/tools/connection_patcher/Patterns/Windows.hpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CONNECTION_PATCHER_PATTERNS_WINDOWS_HPP
+#define CONNECTION_PATCHER_PATTERNS_WINDOWS_HPP
+
+#include <vector>
+
+namespace Connection_Patcher
+{
+ namespace Patterns
+ {
+ namespace Windows
+ {
+ struct x86
+ {
+ static const std::vector<unsigned char> BNet () { return { 0x8B, 0x75, 0x08, 0x8D, 0x78, 0x0C }; }
+ static const std::vector<unsigned char> Portal () { return { }; }
+ static const std::vector<unsigned char> Connect () { return { 0x74, 0x33, 0x6A, 0x04, 0xFF, 0x75, 0xF8 }; }
+ static const std::vector<unsigned char> Password () { return { 0x74, 0x89, 0x8B, 0x16, 0x8B, 0x42, 0x04 }; }
+ static const std::vector<unsigned char> Signature() { return { 0xE8, 0x00, 0x00, 0x00, 0x00, 0x84, 0xC0, 0x75, 0x5F, 0x33, 0xC0 }; }
+ };
+
+ struct x64
+ {
+ static const std::vector<unsigned char> BNet () { return { 0x8B, 0x02, 0x89, 0x41, 0x0C, 0x48, 0x8B, 0xC1, 0xC3 }; }
+ static const std::vector<unsigned char> Portal () { return { 0x2E, 0x6C, 0x6F, 0x67, 0x6F, 0x6E, 0x2E, 0x62, 0x61, 0x74, 0x74, 0x6C, 0x65, 0x2E, 0x6E, 0x65, 0x74, 0x00 }; }
+ static const std::vector<unsigned char> Connect () { return { 0x74, 0x2C, 0x48, 0x8D, 0x4C, 0x24, 0x78 }; }
+ static const std::vector<unsigned char> Password () { return { 0x74, 0x84, 0x48, 0x8B, 0x03 }; }
+ static const std::vector<unsigned char> Signature() { return { 0xE8, 0x00, 0x00, 0x00, 0x00, 0x84, 0xC0, 0x0F, 0x85, 0x88, 0x00, 0x00, 0x00, 0x45, 0x33, 0xC0 }; }
+ };
+ };
+ }
+}
+
+#endif
diff --git a/src/tools/connection_patcher/Program.cpp b/src/tools/connection_patcher/Program.cpp
new file mode 100644
index 00000000000..539c6093d53
--- /dev/null
+++ b/src/tools/connection_patcher/Program.cpp
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Helper.hpp"
+#include "Patcher.hpp"
+#include "Patches/Mac.hpp"
+#include "Patches/Windows.hpp"
+#include "Patterns/Mac.hpp"
+#include "Patterns/Windows.hpp"
+
+#include <CompilerDefs.h>
+
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/filesystem.hpp>
+
+#include <iostream>
+
+#if PLATFORM == PLATFORM_WINDOWS
+#include <Shlobj.h>
+#endif
+
+namespace Connection_Patcher
+{
+ namespace
+ {
+ template<typename PATCH, typename PATTERN>
+ void PatchModule(boost::filesystem::path file, boost::filesystem::path path)
+ {
+ std::cout << "Patching module...\n";
+
+ Patcher patcher(file);
+ std::cout << "patching Password\n";
+ patcher.Patch(PATCH::Password(), PATTERN::Password());
+
+ std::string const moduleName(Helper::GetFileChecksum(patcher.binary) + ".auth");
+ boost::filesystem::path const modulePath
+ (path / std::string(&moduleName[0], 2) / std::string(&moduleName[2], 2));
+
+ if (!boost::filesystem::exists(modulePath))
+ boost::filesystem::create_directories(modulePath);
+
+ patcher.Finish(modulePath / moduleName);
+
+ std::cout << "Patching module finished.\n";
+ }
+
+ template<typename PATCH, typename PATTERN>
+ void do_module(std::string moduleName, boost::filesystem::path path)
+ {
+ boost::filesystem::path const modulePath
+ (path / std::string(&moduleName[0], 2) / std::string(&moduleName[2], 2));
+ boost::filesystem::path const module(modulePath / moduleName);
+
+ if (!boost::filesystem::exists (module))
+ throw std::runtime_error("base module does not exist. run client once.");
+
+ PatchModule<PATCH, PATTERN>(module, path);
+ }
+
+ template<typename PATCH, typename PATTERN>
+ void do_patches(Patcher* patcher, boost::filesystem::path output)
+ {
+ std::cout << "patching BNet\n";
+ patcher->Patch(PATCH::BNet(), PATTERN::BNet());
+ std::cout << "patching Portal\n";
+ patcher->Patch(PATCH::Portal(), PATTERN::Portal());
+ std::cout << "patching Connect\n";
+ patcher->Patch(PATCH::Connect(), PATTERN::Connect());
+ std::cout << "patching Signature\n";
+ patcher->Patch(PATCH::Signature(), PATTERN::Signature());
+ patcher->Finish(output);
+
+ std::cout << "Patching done.\n";
+
+ }
+ }
+
+ // adapted from http://stackoverflow.com/questions/8593608/how-can-i-copy-a-directory-using-boost-filesystem
+ void copyDir(boost::filesystem::path const & source, boost::filesystem::path const & destination)
+ {
+ namespace fs = boost::filesystem;
+ if (!fs::exists(source) || !fs::is_directory(source))
+ throw std::invalid_argument("Source directory " + source.string() + " does not exist or is not a directory.");
+
+ if (fs::exists(destination))
+ throw std::invalid_argument("Destination directory " + destination.string() + " already exists.");
+
+ if (!fs::create_directory(destination))
+ throw std::runtime_error("Unable to create destination directory" + destination.string());
+
+ for (fs::directory_iterator file(source); file != fs::directory_iterator(); ++file)
+ {
+ fs::path current(file->path());
+ if (fs::is_directory(current))
+ copyDir(current, destination / current.filename());
+ else
+ fs::copy_file(current, destination / current.filename());
+ }
+ }
+}
+
+int main(int argc, char** argv)
+{
+ using namespace Connection_Patcher;
+
+ try
+ {
+ if (argc != 2)
+ throw std::invalid_argument("Wrong number of arguments: Missing client file.");
+
+ std::string const binary_path(argv[1]);
+
+ std::string renamed_binary_path(binary_path);
+
+ wchar_t* commonAppData (nullptr);
+#if PLATFORM == PLATFORM_WINDOWS
+ SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &commonAppData);
+#endif
+
+ std::cout << "Creating patched binaries for ";
+
+ Patcher patcher(binary_path);
+
+ switch (patcher.Type)
+ {
+ case Constants::BinaryTypes::Pe32:
+ std::cout << "Win32 client...\n";
+
+ boost::algorithm::replace_all(renamed_binary_path, ".exe", "_Patched.exe");
+ do_patches<Patches::Windows::x86, Patterns::Windows::x86>
+ (&patcher, renamed_binary_path);
+
+ do_module<Patches::Windows::x86, Patterns::Windows::x86>
+ ( "8f52906a2c85b416a595702251570f96d3522f39237603115f2f1ab24962043c.auth"
+ , std::wstring(commonAppData) + std::wstring(L"/Blizzard Entertainment/Battle.net/Cache/")
+ );
+
+ break;
+ case Constants::BinaryTypes::Pe64:
+ std::cout << "Win64 client...\n";
+
+ boost::algorithm::replace_all(renamed_binary_path, ".exe", "_Patched.exe");
+ do_patches<Patches::Windows::x64, Patterns::Windows::x64>
+ (&patcher, renamed_binary_path);
+
+ do_module<Patches::Windows::x64, Patterns::Windows::x64>
+ ( "0a3afee2cade3a0e8b458c4b4660104cac7fc50e2ca9bef0d708942e77f15c1d.auth"
+ , std::wstring(commonAppData) + std::wstring(L"/Blizzard Entertainment/Battle.net/Cache/")
+ );
+
+ break;
+ case Constants::BinaryTypes::Mach64:
+ std::cout << "Mac client...\n";
+
+ boost::algorithm::replace_all (renamed_binary_path, ".app", " Patched.app");
+ copyDir ( boost::filesystem::path(binary_path).parent_path()/*MacOS*/.parent_path()/*Contents*/.parent_path()
+ , boost::filesystem::path(renamed_binary_path).parent_path()/*MacOS*/.parent_path()/*Contents*/.parent_path()
+ );
+
+ do_patches<Patches::Mac::x64, Patterns::Mac::x64>
+ (&patcher, renamed_binary_path);
+
+ do_module<Patches::Windows::x64, Patterns::Windows::x64>
+ ( "97eeb2e28e9e56ed6a22d09f44e2ff43c93315e006bbad43bafc0defaa6f50ae.auth"
+ , "/Users/Shared/Blizzard/Battle.net/Cache/"
+ );
+
+ break;
+ default:
+ throw std::runtime_error("Type: " + std::to_string(static_cast<uint32_t>(patcher.Type)) + " not supported!");
+ }
+
+ std::cout << "Successfully created your patched binaries.\n";
+
+ return 0;
+ }
+ catch (std::exception const& ex)
+ {
+ std::cerr << "EX: " << ex.what() << std::endl;
+ return 1;
+ }
+}