TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Program.cpp File Reference
#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 <CompilerDefs.h>
#include <boost/algorithm/string/replace.hpp>
#include <boost/program_options.hpp>
#include <Shlobj.h>
+ Include dependency graph for Program.cpp:

Namespaces

 Connection_Patcher
 

Functions

po::variables_map Connection_Patcher::GetConsoleArguments (int argc, char **argv)
 
int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)
129 {
130  using namespace Connection_Patcher;
131 
132  try
133  {
134  auto vm = GetConsoleArguments(argc, argv);
135 
136  // exit if help is enabled
137  if (vm.count("help"))
138  {
139  std::cin.get();
140  return 0;
141  }
142 
143  std::string const binary_path(std::move(vm["path"].as<std::string>()));
144  std::string renamed_binary_path(binary_path);
145 
146  std::cout << "Creating patched binary..." << std::endl;
147 
148  Patcher patcher(binary_path);
149 
150  // always set wowBuild to current build of the .exe files
151  int wowBuild = Helper::GetBuildNumber(patcher.GetBinary());
152 
153  // define logical limits in case the exe was tinkered with and the build number was changed
154  if (wowBuild == 0 || wowBuild < 10000 || wowBuild > 65535) // Build number has to be exactly 5 characters long
155  throw std::runtime_error("Build number was out of range. Build: " + std::to_string(wowBuild));
156 
157  std::cout << "Determined build number: " << std::to_string(wowBuild) << std::endl;
158 
159  switch (patcher.GetType())
160  {
161  case Constants::BinaryTypes::Pe32:
162  std::cout << "Win32 client...\n";
163 
164  boost::algorithm::replace_all(renamed_binary_path, ".exe", "_Patched.exe");
165  do_patches<Patches::Windows::x86, Patterns::Windows::x86>
166  (&patcher, renamed_binary_path, wowBuild);
167  WriteCertificateBundle(boost::filesystem::path(binary_path).remove_filename() / "tc_bundle.txt");
168  break;
169  case Constants::BinaryTypes::Pe64:
170  std::cout << "Win64 client...\n";
171 
172  boost::algorithm::replace_all(renamed_binary_path, ".exe", "_Patched.exe");
173  do_patches<Patches::Windows::x64, Patterns::Windows::x64>
174  (&patcher, renamed_binary_path, wowBuild);
175  WriteCertificateBundle(boost::filesystem::path(binary_path).remove_filename() / "tc_bundle.txt");
176  break;
177  case Constants::BinaryTypes::Mach64:
178  std::cout << "Mac client...\n";
179 
180  boost::algorithm::replace_all(renamed_binary_path, ".app", " Patched.app");
181  Helper::CopyDir(boost::filesystem::path(binary_path).parent_path()/*MacOS*/.parent_path()/*Contents*/.parent_path()
182  , boost::filesystem::path(renamed_binary_path).parent_path()/*MacOS*/.parent_path()/*Contents*/.parent_path()
183  );
184 
185  do_patches<Patches::Mac::x64, Patterns::Mac::x64>
186  (&patcher, renamed_binary_path, wowBuild);
187 
188  {
189  namespace fs = boost::filesystem;
190  fs::permissions(renamed_binary_path, fs::add_perms | fs::others_exe | fs::group_exe | fs::owner_exe);
191  }
192  WriteCertificateBundle(boost::filesystem::path(binary_path).parent_path()/*MacOS*/.parent_path()/*Contents*/.parent_path()/*World of Warcraft.app*/.parent_path() / "tc_bundle.txt");
193  break;
194  default:
195  throw std::runtime_error("Type: " + std::to_string(static_cast<uint32_t>(patcher.GetType())) + " not supported!");
196  }
197 
198  std::cout << "Successfully created your patched binaries.\n";
199 
200  return 0;
201  }
202  catch (std::exception const& ex)
203  {
204  std::cerr << "EX: " << ex.what() << std::endl;
205  std::cerr << "An error occurred. Press ENTER to continue...";
206  std::cin.get();
207  return 1;
208  }
209 }
void CopyDir(boost::filesystem::path const &source, boost::filesystem::path const &destination)
Definition: Helper.cpp:26
po::variables_map GetConsoleArguments(int argc, char **argv)
Definition: Program.cpp:96
Definition: Helper.cpp:21
uint32_t GetBuildNumber(std::vector< unsigned char > const &binary)
Definition: Helper.cpp:169

+ Here is the call graph for this function: