From 543a17a1b99d2a75909a4df0ca34fbea3ad19c32 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 10 May 2014 13:30:48 +0200 Subject: Contrib: Added client patcher, original author @Fabi --- contrib/Connection Patcher/Program.cs | 244 ++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 contrib/Connection Patcher/Program.cs (limited to 'contrib/Connection Patcher/Program.cs') diff --git a/contrib/Connection Patcher/Program.cs b/contrib/Connection Patcher/Program.cs new file mode 100644 index 00000000000..5ba7b3e0a87 --- /dev/null +++ b/contrib/Connection Patcher/Program.cs @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2012-2014 Arctium Emulation + * Copyright (C) 2008-2014 TrinityCore + * + * 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 . + */ + +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 system32 = Environment.GetFolderPath(Environment.SpecialFolder.System); + var hostsPath = Path.Combine(system32, "drivers/etc/hosts"); + var modulePath = ""; + var moduleFile = ""; + + // Let's use Win32 as default module + var patchSend = Patches.Windows.x86.Send; + var offsetSend = Offsets.Windows.x86.Send; + var patchRecv = Patches.Windows.x86.Recv; + var offsetRecv = Offsets.Windows.x86.Recv; + var patchBNet = Patches.Windows.x86.BNet; + var offsetBNet = Offsets.Windows.x86.BNet; + var patchSignature = Patches.Windows.x86.Signature; + var offsetSignature = Offsets.Windows.x86.Signature; + var fileName = ""; + var battleNetFileName = args[0].Replace("Wow.exe", "Battle.net.dll"); + var modulePatch = Patches.Windows.x86.Password; + var modulePattern = Patterns.Windows.x86.Password; + + 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..."); + modulePath = commonAppData + "/Blizzard Entertainment/Battle.net/Cache/"; + moduleFile = "8f52906a2c85b416a595702251570f96d3522f39237603115f2f1ab24962043c.auth"; + 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: + // break; + //case BinaryTypes.Mach64: + // Console.WriteLine("Mc64 client..."); + // patchBNet = Patches.Mac.x64.BNet; + // patternBNet = Patterns.Mac.x64.BNet; + // patchSend = Patches.Mac.x64.Send; + // patternSend = Patterns.Mac.x64.Send; + // 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; + // hostsPath = "/private/etc/hosts"; + // break; + default: + throw new NotSupportedException("Type: " + patcher.Type + " not supported!"); + } + + if (!File.Exists(battleNetFileName + "_backup")) + { + File.Copy(battleNetFileName, battleNetFileName + "_backup"); + File.SetAttributes(battleNetFileName + "_backup", File.GetAttributes(battleNetFileName + "_backup") | FileAttributes.ReadOnly); + } + + using (var bnpatcher = new Patcher(battleNetFileName)) + { + bnpatcher.Patch(patchBNet, null, offsetBNet); + bnpatcher.Patch(patchSignature, null, offsetSignature); + bnpatcher.Finish(); + } + + patcher.Patch(patchSend, null, offsetSend); + patcher.Patch(patchRecv, null, offsetRecv); + + 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."); + } + + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine("Adding host rewrite..."); + + var host = args.Length == 2 ? args[1] : "127.0.0.1"; + var hostName = args.Length == 3 ? (" " + args[2] + ".logon.battle.net") : " tc.logon.battle.net"; + var exists = false; + + using (var sr = new StreamReader(hostsPath)) + { + while (!sr.EndOfStream) + { + var line = sr.ReadLine(); + + if (line.Contains(hostName)) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("Host rewrite not needed."); + + exists = true; + break; + } + } + } + + if (!exists) + { + try + { + using (var stream = new StreamWriter(hostsPath, true, Encoding.UTF8)) + { + stream.WriteLine(""); + stream.WriteLine("{0}{1}", host, hostName); + } + + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Host rewrite successfully added."); + } + catch (Exception e) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(string.Format("Can't write host file! Exception type: {0}", e.GetType())); + Console.WriteLine("You must add the following line:"); + + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine("{0}{1}", host, hostName); + + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("to your host file before using Arctium WoD Sandbox!"); + } + } + } + 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; + } + } +} -- cgit v1.2.3 From a078c1555c7de6bf2d770f1091fbce46deaae427 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 18 May 2014 22:29:26 +0200 Subject: Contrib/Patcher: Make the client use realmListBn config instead of having to deal with portal and hosts rewrites --- contrib/Connection Patcher/Offsets/Windows.cs | 2 + contrib/Connection Patcher/Patches/Windows.cs | 4 +- contrib/Connection Patcher/Patterns/Windows.cs | 1 + contrib/Connection Patcher/Program.cs | 62 +++----------------------- 4 files changed, 13 insertions(+), 56 deletions(-) (limited to 'contrib/Connection Patcher/Program.cs') diff --git a/contrib/Connection Patcher/Offsets/Windows.cs b/contrib/Connection Patcher/Offsets/Windows.cs index c4e01eeb4c2..4f2f32708cc 100644 --- a/contrib/Connection Patcher/Offsets/Windows.cs +++ b/contrib/Connection Patcher/Offsets/Windows.cs @@ -25,6 +25,7 @@ namespace Connection_Patcher.Offsets public static readonly long Send = 0x889CA; public static readonly long Recv = 0x86EEE; public static readonly long Signature = 0x20B79; + public static readonly long RealmList = 0x228D6C; } public static class x64 @@ -33,6 +34,7 @@ namespace Connection_Patcher.Offsets public static readonly long Send = 0xAAB6B; public static readonly long Recv = 0xA9FA3; public static readonly long Signature = 0; + public static readonly long RealmList = 0x2BB33C; } } } diff --git a/contrib/Connection Patcher/Patches/Windows.cs b/contrib/Connection Patcher/Patches/Windows.cs index 75c1067d4df..feb10507084 100644 --- a/contrib/Connection Patcher/Patches/Windows.cs +++ b/contrib/Connection Patcher/Patches/Windows.cs @@ -22,12 +22,13 @@ namespace Connection_Patcher.Patches { public static class x86 { - //public static byte[] BNet = { 0xC7, 0x40, 0x0C, 0xD5, 0xF8, 0x7F, 0x82 }; public static byte[] BNet = { 0x89, 0x48, 0x08, 0xC7, 0x40, 0x0C, 0xD5, 0xF8, 0x7F, 0x82, 0x90 }; public static byte[] Send = { 0xBA, 0x00, 0x00, 0x00, 0x00, 0x90, 0xEB }; public static byte[] Recv = { 0xB8, 0x00, 0x00, 0x00, 0x00 }; public static byte[] Password = { 0x75 }; public static byte[] Signature = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xE9 }; + public static byte[] RealmList = { 0x08 }; + public static byte[] RealmListBn = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; } public static class x64 @@ -37,6 +38,7 @@ namespace Connection_Patcher.Patches public static byte[] Send = { 0x45, 0x33, 0xED, 0x90, 0x90, 0x90 }; public static byte[] Recv = { 0xB8, 0x00, 0x00, 0x00, 0x00, 0x90 }; public static byte[] Password = { 0x75 }; + public static byte[] RealmList = { 0x4C, 0x8B, 0xEA }; //public static byte[] Signature = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0xE9 }; public static byte[] Signature = { }; } diff --git a/contrib/Connection Patcher/Patterns/Windows.cs b/contrib/Connection Patcher/Patterns/Windows.cs index 84d63f031fb..f8bde67dddb 100644 --- a/contrib/Connection Patcher/Patterns/Windows.cs +++ b/contrib/Connection Patcher/Patterns/Windows.cs @@ -23,6 +23,7 @@ namespace Connection_Patcher.Patterns public static class x86 { public static byte[] Password = { 0x74, 0x89, 0x8B, 0x16, 0x8B, 0x42, 0x04 }; + public static byte[] RealmListBn = { 0x2E, 0x6C, 0x6F, 0x67, 0x6F, 0x6E, 0x2E, 0x62, 0x61, 0x74, 0x74, 0x6C, 0x65, 0x2E, 0x6E, 0x65, 0x74 }; } public static class x64 diff --git a/contrib/Connection Patcher/Program.cs b/contrib/Connection Patcher/Program.cs index 5ba7b3e0a87..956741b625b 100644 --- a/contrib/Connection Patcher/Program.cs +++ b/contrib/Connection Patcher/Program.cs @@ -39,8 +39,6 @@ namespace Connection_Patcher Console.ReadKey(true); var commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); - var system32 = Environment.GetFolderPath(Environment.SpecialFolder.System); - var hostsPath = Path.Combine(system32, "drivers/etc/hosts"); var modulePath = ""; var moduleFile = ""; @@ -53,10 +51,14 @@ namespace Connection_Patcher var offsetBNet = Offsets.Windows.x86.BNet; var patchSignature = Patches.Windows.x86.Signature; var offsetSignature = Offsets.Windows.x86.Signature; - var fileName = ""; + var fileName = args[0].Replace(".exe", "_Patched.exe"); var battleNetFileName = args[0].Replace("Wow.exe", "Battle.net.dll"); var modulePatch = Patches.Windows.x86.Password; var modulePattern = Patterns.Windows.x86.Password; + var realmListPatch = Patches.Windows.x86.RealmList; + var realmListoffset = Offsets.Windows.x86.RealmList; + var realmListBnPatch = Patches.Windows.x86.RealmListBn; + var realmListBnPattern = Patterns.Windows.x86.RealmListBn; Console.ForegroundColor = ConsoleColor.White; Console.Write("Creating patched binaries for "); @@ -93,7 +95,6 @@ namespace Connection_Patcher // moduleFile = "97eeb2e28e9e56ed6a22d09f44e2ff43c93315e006bbad43bafc0defaa6f50ae.auth"; // modulePatch = Patches.Mac.x64.Password; // modulePattern = Patterns.Mac.x64.Password; - // hostsPath = "/private/etc/hosts"; // break; default: throw new NotSupportedException("Type: " + patcher.Type + " not supported!"); @@ -109,11 +110,13 @@ namespace Connection_Patcher { bnpatcher.Patch(patchBNet, null, offsetBNet); bnpatcher.Patch(patchSignature, null, offsetSignature); + bnpatcher.Patch(realmListBnPatch, realmListBnPattern); bnpatcher.Finish(); } patcher.Patch(patchSend, null, offsetSend); patcher.Patch(patchRecv, null, offsetRecv); + patcher.Patch(realmListPatch, null, realmListoffset); patcher.Binary = fileName; @@ -127,57 +130,6 @@ namespace Connection_Patcher Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Successfully created your patched binaries."); } - - Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("Adding host rewrite..."); - - var host = args.Length == 2 ? args[1] : "127.0.0.1"; - var hostName = args.Length == 3 ? (" " + args[2] + ".logon.battle.net") : " tc.logon.battle.net"; - var exists = false; - - using (var sr = new StreamReader(hostsPath)) - { - while (!sr.EndOfStream) - { - var line = sr.ReadLine(); - - if (line.Contains(hostName)) - { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("Host rewrite not needed."); - - exists = true; - break; - } - } - } - - if (!exists) - { - try - { - using (var stream = new StreamWriter(hostsPath, true, Encoding.UTF8)) - { - stream.WriteLine(""); - stream.WriteLine("{0}{1}", host, hostName); - } - - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("Host rewrite successfully added."); - } - catch (Exception e) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(string.Format("Can't write host file! Exception type: {0}", e.GetType())); - Console.WriteLine("You must add the following line:"); - - Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("{0}{1}", host, hostName); - - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("to your host file before using Arctium WoD Sandbox!"); - } - } } else { -- cgit v1.2.3