Tools: Remove patcher (will not work for bfa)

This commit is contained in:
Shauren
2018-11-22 20:11:44 +01:00
parent 1423d3e7f3
commit a069ca177c
14 changed files with 0 additions and 887 deletions

View File

@@ -8,7 +8,6 @@
# 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(extractor_common)
add_subdirectory(map_extractor)
add_subdirectory(vmap4_assembler)

View File

@@ -1,32 +0,0 @@
# Copyright (C) 2008-2018 TrinityCore <https://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.
CollectSourceFiles(${CMAKE_CURRENT_SOURCE_DIR} PRIVATE_SOURCES)
if (WIN32)
list(APPEND PRIVATE_SOURCES ${sources_windows})
endif()
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(connection_patcher ${PRIVATE_SOURCES})
target_link_libraries(connection_patcher
PRIVATE
trinity-core-interface
PUBLIC
common
)
if (UNIX)
install(TARGETS connection_patcher DESTINATION bin)
elseif (WIN32)
install(TARGETS connection_patcher DESTINATION "${CMAKE_INSTALL_PREFIX}")
endif ()

View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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_CONSTANTS_BINARYTYPES_HPP
#define CONNECTION_PATCHER_CONSTANTS_BINARYTYPES_HPP
#include <cstdint>
namespace Connection_Patcher
{
namespace Constants
{
enum class BinaryTypes : uint32_t
{
Pe32 = 0x0000014C,
Pe64 = 0x00008664,
Mach64 = 0xFEEDFACF
};
}
}
#endif

View File

@@ -1,105 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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 "Patterns/Common.hpp"
namespace Connection_Patcher
{
namespace Helper
{
// 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());
}
}
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::set<size_t> SearchOffset(std::vector<unsigned char> const& binary, std::vector<unsigned char> const& pattern)
{
std::set<size_t> offsets;
for (size_t i = 0; (i + pattern.size()) < binary.size(); i++)
{
size_t matches = 0;
for (size_t j = 0; j < pattern.size(); j++)
{
if (binary[i + j] != pattern[j])
break;
matches++;
}
if (matches == pattern.size())
{
offsets.insert(i);
i += matches;
}
}
return offsets.empty() ? throw std::runtime_error("unable to find pattern") : offsets;
}
uint32_t GetBuildNumber(std::vector<unsigned char> const& binary)
{
std::set<size_t> offsets = SearchOffset(binary, Patterns::Common::BinaryVersion());
if (!offsets.empty())
{
size_t const verOffset = (*offsets.begin());
std::string ver(&binary[verOffset + 16], &binary[verOffset + 21]);
return std::stoi(ver);
}
return 0;
}
}
}

View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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_HELPER_HPP
#define CONNECTION_PATCHER_HELPER_HPP
#include "Constants/BinaryTypes.hpp"
#include <boost/filesystem.hpp>
#include <vector>
#include <set>
namespace Connection_Patcher
{
namespace Helper
{
void CopyDir(boost::filesystem::path const & source, boost::filesystem::path const & destination);
Constants::BinaryTypes GetBinaryType(std::vector<unsigned char> const& data);
std::set<size_t> SearchOffset(std::vector<unsigned char> const& binary, std::vector<unsigned char> const& pattern);
uint32_t GetBuildNumber(std::vector<unsigned char> const& binary);
}
}
#endif

View File

@@ -1,81 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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"
namespace Connection_Patcher
{
Patcher::Patcher(boost::filesystem::path file)
: filePath(file)
{
ReadFile();
binaryType = Helper::GetBinaryType(binary);
}
void Patcher::ReadFile()
{
std::ifstream ifs(filePath.string(), std::ifstream::binary);
if (!ifs)
throw std::runtime_error("could not open " + filePath.string());
binary.clear();
ifs >> std::noskipws;
ifs.seekg(0, std::ios_base::end);
binary.reserve(ifs.tellg());
ifs.seekg(0, std::ios_base::beg);
std::copy(std::istream_iterator<unsigned char>(ifs), std::istream_iterator<unsigned char>(), std::back_inserter(binary));
}
void Patcher::WriteFile(boost::filesystem::path const& path)
{
std::ofstream ofs(path.string(), std::ofstream::binary);
if (!ofs)
throw std::runtime_error("could not open " + path.string());
ofs << std::noskipws;
std::copy(binary.begin(), binary.end(), std::ostream_iterator<unsigned char>(ofs));
}
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;
for (size_t const offset : Helper::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);
WriteFile(out);
}
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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_PATCHER_HPP
#define CONNECTION_PATCHER_PATCHER_HPP
#include "Helper.hpp"
#include <fstream>
#include <iostream>
#include <iterator>
namespace Connection_Patcher
{
class Patcher
{
public:
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);
Constants::BinaryTypes GetType() const { return binaryType; }
std::vector<unsigned char> const& GetBinary() const { return binary; }
private:
void ReadFile();
void WriteFile(boost::filesystem::path const& path);
boost::filesystem::path filePath;
std::vector<unsigned char> binary;
Constants::BinaryTypes binaryType;
};
}
#endif

View File

@@ -1,107 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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_COMMON_HPP
#define CONNECTION_PATCHER_PATCHES_COMMON_HPP
#include <vector>
namespace Connection_Patcher
{
namespace Patches
{
struct Common
{
static 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 std::vector<unsigned char> Modulus()
{
return
{
0x5F, 0xD6, 0x80, 0x0B, 0xA7, 0xFF, 0x01, 0x40, 0xC7, 0xBC, 0x8E, 0xF5, 0x6B, 0x27, 0xB0, 0xBF,
0xF0, 0x1D, 0x1B, 0xFE, 0xDD, 0x0B, 0x1F, 0x3D, 0xB6, 0x6F, 0x1A, 0x48, 0x0D, 0xFB, 0x51, 0x08,
0x65, 0x58, 0x4F, 0xDB, 0x5C, 0x6E, 0xCF, 0x64, 0xCB, 0xC1, 0x6B, 0x2E, 0xB8, 0x0F, 0x5D, 0x08,
0x5D, 0x89, 0x06, 0xA9, 0x77, 0x8B, 0x9E, 0xAA, 0x04, 0xB0, 0x83, 0x10, 0xE2, 0x15, 0x4D, 0x08,
0x77, 0xD4, 0x7A, 0x0E, 0x5A, 0xB0, 0xBB, 0x00, 0x61, 0xD7, 0xA6, 0x75, 0xDF, 0x06, 0x64, 0x88,
0xBB, 0xB9, 0xCA, 0xB0, 0x18, 0x8B, 0x54, 0x13, 0xE2, 0xCB, 0x33, 0xDF, 0x17, 0xD8, 0xDA, 0xA9,
0xA5, 0x60, 0xA3, 0x1F, 0x4E, 0x27, 0x05, 0x98, 0x6F, 0xAA, 0xEE, 0x14, 0x3B, 0xF3, 0x97, 0xA8,
0x12, 0x02, 0x94, 0x0D, 0x84, 0xDC, 0x0E, 0xF1, 0x76, 0x23, 0x95, 0x36, 0x13, 0xF9, 0xA9, 0xC5,
0x48, 0xDB, 0xDA, 0x86, 0xBE, 0x29, 0x22, 0x54, 0x44, 0x9D, 0x9F, 0x80, 0x7B, 0x07, 0x80, 0x30,
0xEA, 0xD2, 0x83, 0xCC, 0xCE, 0x37, 0xD1, 0xD1, 0xCF, 0x85, 0xBE, 0x91, 0x25, 0xCE, 0xC0, 0xCC,
0x55, 0xC8, 0xC0, 0xFB, 0x38, 0xC5, 0x49, 0x03, 0x6A, 0x02, 0xA9, 0x9F, 0x9F, 0x86, 0xFB, 0xC7,
0xCB, 0xC6, 0xA5, 0x82, 0xA2, 0x30, 0xC2, 0xAC, 0xE6, 0x98, 0xDA, 0x83, 0x64, 0x43, 0x7F, 0x0D,
0x13, 0x18, 0xEB, 0x90, 0x53, 0x5B, 0x37, 0x6B, 0xE6, 0x0D, 0x80, 0x1E, 0xEF, 0xED, 0xC7, 0xB8,
0x68, 0x9B, 0x4C, 0x09, 0x7B, 0x60, 0xB2, 0x57, 0xD8, 0x59, 0x8D, 0x7F, 0xEA, 0xCD, 0xEB, 0xC4,
0x60, 0x9F, 0x45, 0x7A, 0xA9, 0x26, 0x8A, 0x2F, 0x85, 0x0C, 0xF2, 0x19, 0xC6, 0x53, 0x92, 0xF7,
0xF0, 0xB8, 0x32, 0xCB, 0x5B, 0x66, 0xCE, 0x51, 0x54, 0xB4, 0xC3, 0xD3, 0xD4, 0xDC, 0xB3, 0xEE
};
}
static std::string VersionsFile() { return "trinity6.github.io/%s/%s/build/versi"; };
static std::vector<unsigned char> CertBundleUrl() { return { 'h', 't', 't', 'p', 's', ':', '/', '/', 't', 'r', 'i', 'n', 'i', 't', 'y', '6', '.', 'g', 'i', 't', 'h', 'u', 'b', '.', 'i', 'o', '/', 'B', 'n', 'e', 't', '/', 'z', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '/', 'c', 'l', 'i', 'e', 'n', 't', '/', 'b', 'g', 's', '-', 'k', 'e', 'y', '-', 'f', 'i', 'n', 'g', 'e', 'r', 'p', 'r', 'i', 'n', 't' }; }
static std::string CertificateBundle()
{
return
R"({
"Created": 1455065214,
"Certificates": [
{ "Uri": "*.*", "ShaHashPublicKeyInfo": "B1241D831999D4A67B0C6F9A687331C87FBA9B2CDC4CAC3694ADAD622F01952B" }
],
"PublicKeys": [
{ "Uri": "*.*", "ShaHashPublicKeyInfo": "B1241D831999D4A67B0C6F9A687331C87FBA9B2CDC4CAC3694ADAD622F01952B" }
],
"SigningCertificates": [
{ "RawData": "-----BEGIN CERTIFICATE-----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-----END CERTIFICATE-----" }
]
})";
}
static std::string CertificatePrivateKey()
{
return
R"(-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAwN3EYmKhDGawGrh62wAgjh3wr4CcV6lp61Ev39jzTkgetXDB
F2SWC9s/pzS/h10HQwL9P0cYlqbZHj/darOphcqplK05WsJC876lUASSeVWVPiHs
mfpSzjx65qV2PfmcNE1SUEizOOfpaoxvLfVqh5y4MkuSxXxOXCXS9CnQBwQo8f/4
uV6czHZgigi7CSID75VK3VhqvlTaLYFoEiOpjWNAQ7x/18sv+VoSVuX+alYez2PD
wU+hl0CpzEIqtaavntce9sQ3uEd3eXYGAJp6X+bOVItRmUhb3WXoIXmHMaLe5oSc
cINa17ZL7H2ISOqr/1Pfq84Ck/VStbzEfJdTZwIDAQABAoIBAHcu1DQERQd30a3B
gNIi4vtPzzN1I6gcXgL3+cC3vasLcEapdflxxDNxeoVmWFFbEKi9iSf4VF6MnrFN
wBM3ETRHh8IDxeSrFVqw3lFzcdyfIYnyxtZkVZVy1HQBne8wd/HuMkbAllg9IAYi
4HWjKgDBvSX/g6Sca4QQL6uIxy/9s3Z4K2vU8KbvUpwo+ON4HMt61fgrIrbEUVCl
TMCVEf8UphwHctmQJb/Pr0+BCTdiv04ga1dkt+ZyR2o0VN6T/zKDqk4m1sSl0GZz
8sn63GbuTlwHcm9GgkaxoeeZJK1/sdOSIZN8W3PpnyHrAZJlNOY7G684F1mBaWV1
PGCcVtkCgYEA8jCDTGub7ZyMk48x+8L3Devja3TQz7YNIGkVEbQBpNw4gDV8j1m6
EgqFdzowkY+gbA76ylNfm6Aa66RDR/LbTbXlsNd8YkXcbU3xDQ96F6cS51VBkled
hq+iAuGJB9VYN5yP1P/Oswg/AFMjOnsfBL/1zFo26364z9x8zazw0wsCgYEAy907
mpkk59AQ4YIDSR9wK2YpXv6HoBPFld6m7PAnBWFO0uNtQ0YppbYbrhmDqrxUoFud
ZiEHIa0gLlp9lHr+UdUAMPDlJ6gbMnJW3U5qiVuuZA13tiZFlv11qUeU1tQUzTUv
ZoIISN15Im0PQzUFbTxSFbS+vTYjsedv1C9UOpUCgYEAkTaTUzvmV3cZNtSSFLFW
ros0Zda56QDwJ/G5x06V+cJtQjpPwCf9kBms4ssKGgzzFDd7GdsZpVc/LPDlwnsU
ESkyWnEpzEa1HvivwrP38bykcf5Ffbh45CvkyTNvlTnPVjDScNUcm24jUE+I/OSb
uZ5bg7bH3TWzHDbIwg2iq/cCgYB+DPqvqoVhOAtYBBWX/vJSQ0bNT7/4QIFpG1RH
KG5YK0SbrLeAYz+ZELKowWniBbSluj/mSAGq1usQ/i6rwijB3FvT5v8puA2o8X24
NKY27BM2FgWxAJUCuREpa/Mhqdx6zanTTg9lTlt558kKGxyR4Dw445sUTwdfFuTU
Y7dGyQKBgAG0vyOdfku9TlPX2a3LasM5jkbxljeTlCJUlahW7LSoQEmLoEhOM4Ja
6CA5PADhA16pOUweKjOtSkNEcVEorFNjlH34PpnsysF+NsDBP5HEy0eYyHSYwg1Y
7BGwQxUOoBaUKMu7jVQcffrKiWOGEXzBDSEZ3A30t7+JIS7qy1d1
-----END RSA PRIVATE KEY-----
)";
}
};
}
}
#endif

View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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
{
struct Mac
{
static std::vector<unsigned char> LauncherLoginParametersLocation()
{
char const path[] = "org.trnity"; // not a typo, length must match original
return std::vector<unsigned char>(std::begin(path), std::end(path));
}
};
}
}
#endif

View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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
{
struct Windows
{
static std::vector<unsigned char> LauncherLoginParametersLocation()
{
char const path[] = R"(Software\TrinityCore Developers\Battle.net\Launch Options\)";
return std::vector<unsigned char>(std::begin(path), std::end(path));
}
};
}
}
#endif

View File

@@ -1,40 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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_COMMON_HPP
#define CONNECTION_PATCHER_PATTERNS_COMMON_HPP
#include <vector>
namespace Connection_Patcher
{
namespace Patterns
{
struct Common
{
static std::vector<unsigned char> Portal() { return { '.', 'a', 'c', 't', 'u', 'a' , 'l', '.', 'b', 'a', 't', 't', 'l', 'e', '.', 'n', 'e', 't', 0x00 }; }
static std::vector<unsigned char> Modulus() { return { 0x91, 0xD5, 0x9B, 0xB7, 0xD4, 0xE1, 0x83, 0xA5 }; }
static std::vector<unsigned char> BinaryVersion() { return { 0x3C, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3E }; }
static std::vector<unsigned char> VersionsFile() { return { '%', 's', '.', 'p', 'a', 't', 'c', 'h', '.', 'b', 'a', 't', 't', 'l', 'e', '.', 'n', 'e', 't', ':', '1', '1', '1', '9', '/', '%', 's', '/', 'v', 'e', 'r', 's', 'i', 'o', 'n', 's' }; }
static std::vector<unsigned char> CertBundleUrl() { return { 'h', 't', 't', 'p', ':', '/', '/', 'n', 'y', 'd', 'u', 's', '-', 'q', 'a', '.', 'w', 'e', 'b', '.', 'b', 'l', 'i', 'z', 'z', 'a', 'r', 'd', '.', 'n', 'e', 't', '/', 'B', 'n', 'e', 't', '/', 'z', 'x', 'x', '/', 'c', 'l', 'i', 'e', 'n', 't', '/', 'b', 'g', 's', '-', 'k', 'e', 'y', '-', 'f', 'i', 'n', 'g', 'e', 'r', 'p', 'r', 'i', 'n', 't' }; }
static std::vector<unsigned char> CertSignatureModulus() { return { 0x85, 0xF3, 0x7B, 0x14, 0x5A, 0x9C, 0x48, 0xF6 }; }
};
}
}
#endif

View File

@@ -1,35 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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
{
struct Mac
{
static std::vector<unsigned char> LauncherLoginParametersLocation() { return { 'n','e','t','.','b','a','t','t','l','e',0 }; }
};
}
}
#endif

View File

@@ -1,39 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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
{
struct Windows
{
static std::vector<unsigned char> LauncherLoginParametersLocation()
{
char const path[] = R"(Software\Blizzard Entertainment\Battle.net\Launch Options\)";
return std::vector<unsigned char>(std::begin(path), std::end(path));
}
};
}
}
#endif

View File

@@ -1,241 +0,0 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
* Copyright (C) 2008-2018 TrinityCore <https://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/Common.hpp"
#include "Patches/Mac.hpp"
#include "Patches/Windows.hpp"
#include "Patterns/Common.hpp"
#include "Patterns/Mac.hpp"
#include "Patterns/Windows.hpp"
#include "Banner.h"
#include "BigNumber.h"
#include "RSA.h"
#include "SHA256.h"
#include <boost/algorithm/string/replace.hpp>
#include <boost/program_options.hpp>
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
#include <Shlobj.h>
#elif TRINITY_PLATFORM == TRINITY_PLATFORM_UNIX
#include <pwd.h>
#endif
namespace po = boost::program_options;
namespace Connection_Patcher
{
po::variables_map GetConsoleArguments(int argc, char** argv);
namespace
{
template<typename PATCH, typename PATTERN>
void do_patches(Patcher* patcher, boost::filesystem::path output, uint32_t buildNumber)
{
std::cout << "patching Portal\n";
// '.actual.battle.net' -> '' to allow for set portal 'host'
patcher->Patch(Patches::Common::Portal(), Patterns::Common::Portal());
std::cout << "patching redirect RSA Modulus\n";
// public component of connection signing key to use known key pair
patcher->Patch(Patches::Common::Modulus(), Patterns::Common::Modulus());
std::cout << "patching BNet certificate file location\n";
// replace certificate bundle url
patcher->Patch(Patches::Common::CertBundleUrl(), Patterns::Common::CertBundleUrl());
std::cout << "patching BNet certificate file signature\n";
Trinity::Crypto::RSA rsa;
rsa.LoadFromString(Patches::Common::CertificatePrivateKey(), Trinity::Crypto::RSA::PrivateKey{});
std::unique_ptr<uint8[]> modulusArray = rsa.GetModulus().AsByteArray(256);
patcher->Patch(std::vector<uint8>(modulusArray.get(), modulusArray.get() + 256), Patterns::Common::CertSignatureModulus());
std::cout << "patching Versions\n";
// sever the connection to blizzard's versions file to stop it from updating and replace with custom version
// this is good practice with or without the retail version, just to stop the exe from auto-patching randomly
// hardcode %s.patch.battle.net:1119/%s/versions to trinity6.github.io/%s/%s/build/versi
std::string verPatch(Patches::Common::VersionsFile());
std::string buildPattern = "build";
boost::algorithm::replace_all(verPatch, buildPattern, std::to_string(buildNumber));
std::vector<unsigned char> verVec(verPatch.begin(), verPatch.end());
patcher->Patch(verVec, Patterns::Common::VersionsFile());
std::cout << "patching launcher login parameters location\n";
// change registry/CFPreferences path
patcher->Patch(PATCH::LauncherLoginParametersLocation(), PATTERN::LauncherLoginParametersLocation());
patcher->Finish(output);
std::cout << "Patching done.\n";
}
void WriteCertificateBundle(boost::filesystem::path const& dest)
{
if (!boost::filesystem::exists(dest.parent_path()) &&
!boost::filesystem::create_directories(dest.parent_path()))
throw std::runtime_error("could not create " + dest.parent_path().string());
std::ofstream ofs(dest.string(), std::ofstream::binary);
if (!ofs)
throw std::runtime_error("could not open " + dest.string());
ofs << std::noskipws << Patches::Common::CertificateBundle() << "NGIS";
SHA256Hash signatureHash;
signatureHash.UpdateData(Patches::Common::CertificateBundle());
signatureHash.UpdateData("Blizzard Certificate Bundle");
signatureHash.Finalize();
std::array<uint8, 256> signature;
Trinity::Crypto::RSA rsa;
rsa.LoadFromString(Patches::Common::CertificatePrivateKey(), Trinity::Crypto::RSA::PrivateKey{});
rsa.Sign(signatureHash.GetDigest(), signatureHash.GetLength(), signature.data(), Trinity::Crypto::RSA::SHA256{});
ofs.write(reinterpret_cast<char const*>(signature.data()), signature.size());
}
}
po::variables_map GetConsoleArguments(int argc, char** argv)
{
po::options_description all("Allowed options");
all.add_options()
("help,h", "print usage message")
("path", po::value<std::string>()->required(), "Path to the Wow.exe")
;
po::positional_options_description pos;
pos.add("path", 1);
po::variables_map vm;
try
{
po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm);
po::notify(vm);
}
catch (std::exception& e)
{
std::cerr << e.what() << "\n";
}
if (vm.count("help"))
std::cout << all << "\n";
if (!vm.count("path"))
throw std::invalid_argument("Wrong number of arguments: Missing client file.");
return vm;
}
}
int main(int argc, char** argv)
{
using namespace Connection_Patcher;
try
{
Trinity::Banner::Show("connection_patcher", [](char const* text) { std::cout << text << std::endl; }, nullptr);
auto vm = GetConsoleArguments(argc, argv);
// exit if help is enabled
if (vm.count("help"))
{
std::cin.get();
return 0;
}
std::string const binary_path(std::move(vm["path"].as<std::string>()));
std::string renamed_binary_path(binary_path);
std::wstring appDataPath;
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
wchar_t* tempPath(nullptr);
SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &tempPath);
appDataPath = std::wstring(tempPath);
CoTaskMemFree(tempPath);
#elif TRINITY_PLATFORM == TRINITY_PLATFORM_UNIX
char* tempPath(nullptr);
if ((tempPath = getenv("HOME")) == nullptr)
tempPath = getpwuid(getuid())->pw_dir;
std::string tempPathStr(tempPath);
appDataPath.assign(tempPathStr.begin(), tempPathStr.end());
appDataPath += std::wstring(L"/.wine/drive_c/users/Public/Application Data");
#elif TRINITY_PLATFORM == TRINITY_PLATFORM_APPLE
appDataPath = L"/Users/Shared";
#endif
std::cout << "Creating patched binary..." << std::endl;
Patcher patcher(binary_path);
// always set wowBuild to current build of the .exe files
int wowBuild = Helper::GetBuildNumber(patcher.GetBinary());
// define logical limits in case the exe was tinkered with and the build number was changed
if (wowBuild == 0 || wowBuild < 10000 || wowBuild > 65535) // Build number has to be exactly 5 characters long
throw std::runtime_error("Build number was out of range. Build: " + std::to_string(wowBuild));
std::cout << "Determined build number: " << std::to_string(wowBuild) << std::endl;
switch (patcher.GetType())
{
case Constants::BinaryTypes::Pe32:
case Constants::BinaryTypes::Pe64:
std::cout << (patcher.GetType() == Constants::BinaryTypes::Pe64 ? "Win64" : "Win32") << " client...\n";
boost::algorithm::replace_all(renamed_binary_path, ".exe", "_Patched.exe");
do_patches<Patches::Windows, Patterns::Windows>
(&patcher, renamed_binary_path, wowBuild);
WriteCertificateBundle(boost::filesystem::path(appDataPath) / L"Blizzard Entertainment/Battle.net/Cache/web_cert_bundle");
break;
case Constants::BinaryTypes::Mach64:
std::cout << "Mac client...\n";
boost::algorithm::replace_all(renamed_binary_path, ".app", " Patched.app");
Helper::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, Patterns::Mac>
(&patcher, renamed_binary_path, wowBuild);
{
namespace fs = boost::filesystem;
fs::permissions(renamed_binary_path, fs::add_perms | fs::others_exe | fs::group_exe | fs::owner_exe);
}
WriteCertificateBundle(boost::filesystem::path(appDataPath) / "Blizzard/Battle.net/Cache/web_cert_bundle");
break;
default:
throw std::runtime_error("Type: " + std::to_string(static_cast<uint32_t>(patcher.GetType())) + " not supported!");
}
std::cout << "Successfully created your patched binaries.\n";
return 0;
}
catch (std::exception const& ex)
{
std::cerr << "EX: " << ex.what() << std::endl;
std::cerr << "An error occurred. Press ENTER to continue...";
std::cin.get();
return 1;
}
}