2017-01-19 16:23:59 -05:00
|
|
|
#include "STDInclude.hpp"
|
|
|
|
|
|
|
|
namespace Main
|
|
|
|
{
|
|
|
|
void Initialize()
|
|
|
|
{
|
2017-06-30 04:37:29 -04:00
|
|
|
Utils::SetEnvironment();
|
2017-01-19 16:23:59 -05:00
|
|
|
Utils::Cryptography::Initialize();
|
2017-01-30 15:13:30 -05:00
|
|
|
Components::Loader::Initialize();
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-01-30 15:13:30 -05:00
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2017-07-03 09:40:32 -04:00
|
|
|
if (Components::Loader::IsPerformingUnitTests())
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2017-01-30 15:13:30 -05:00
|
|
|
DWORD result = (Components::Loader::PerformUnitTests() ? 0 : -1);
|
|
|
|
Components::Loader::Uninitialize();
|
|
|
|
ExitProcess(result);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
2017-01-27 16:03:35 -05:00
|
|
|
#else
|
2017-01-30 15:13:30 -05:00
|
|
|
if (Components::Flags::HasFlag("tests"))
|
|
|
|
{
|
|
|
|
Components::Logger::Print("Unit tests are disabled outside the debug environment!\n");
|
2017-01-27 16:03:35 -05:00
|
|
|
}
|
2017-01-30 15:13:30 -05:00
|
|
|
#endif
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Uninitialize()
|
|
|
|
{
|
2017-01-30 15:13:30 -05:00
|
|
|
Components::Loader::Uninitialize();
|
2017-01-22 14:12:36 -05:00
|
|
|
Utils::Cache::Uninitialize();
|
|
|
|
google::protobuf::ShutdownProtobufLibrary();
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
2017-05-30 17:34:52 -04:00
|
|
|
|
|
|
|
__declspec(naked) void EntryPoint()
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
pushad
|
|
|
|
call Main::Initialize
|
|
|
|
popad
|
|
|
|
|
2017-06-12 13:54:11 -04:00
|
|
|
push 6BAA2Fh // Continue init routine
|
2017-05-30 17:34:52 -04:00
|
|
|
push 6CA062h // ___security_init_cookie
|
|
|
|
retn
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
|
|
|
|
{
|
|
|
|
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
|
|
|
{
|
2017-02-20 13:18:07 -05:00
|
|
|
// Not sure if it conflicts with our TLS variables
|
|
|
|
//DisableThreadLibraryCalls(hModule);
|
|
|
|
|
2017-02-16 21:27:38 -05:00
|
|
|
Steam::Proxy::RunMod();
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
// Ensure we're working with our desired binary
|
2020-12-19 18:00:07 -05:00
|
|
|
char* _module = reinterpret_cast<char*>(0x400000);
|
|
|
|
auto hash1 = Utils::Cryptography::JenkinsOneAtATime::Compute(_module + 0x1000, 0x2D531F); // .text
|
|
|
|
auto hash2 = Utils::Cryptography::JenkinsOneAtATime::Compute(_module + 0x2D75FC, 0xBDA04); // .rdata
|
2018-11-26 04:41:15 -05:00
|
|
|
if ((hash1 != 0x54684DBE
|
2018-11-04 14:10:27 -05:00
|
|
|
#ifdef DEBUG
|
2018-11-26 04:41:15 -05:00
|
|
|
&& hash1 != 0x8AADE716
|
2018-11-04 14:10:27 -05:00
|
|
|
#endif
|
2018-11-26 04:41:15 -05:00
|
|
|
) || hash2 != 0x8030ec53)
|
2018-10-19 16:58:33 -04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-06-23 04:04:43 -04:00
|
|
|
#ifndef DISABLE_ANTICHEAT
|
2017-03-04 07:51:41 -05:00
|
|
|
[]()
|
|
|
|
{
|
2017-07-12 05:33:30 -04:00
|
|
|
if (!Components::Dedicated::IsEnabled() && !Components::Loader::IsPerformingUnitTests())
|
2017-06-30 04:37:29 -04:00
|
|
|
{
|
|
|
|
Components::AntiCheat::ProtectProcess();
|
|
|
|
Components::AntiCheat::PatchThreadCreation();
|
|
|
|
}
|
2017-03-04 07:51:41 -05:00
|
|
|
}();
|
|
|
|
#endif
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
DWORD oldProtect;
|
2020-12-19 18:00:07 -05:00
|
|
|
VirtualProtect(_module + 0x1000, 0x2D6000, PAGE_EXECUTE_READ, &oldProtect); // Protect the .text segment
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-05-30 17:34:52 -04:00
|
|
|
// Install entry point hook
|
|
|
|
Utils::Hook(0x6BAC0F, Main::EntryPoint, HOOK_JUMP).install()->quick();
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
|
|
|
|
{
|
|
|
|
Main::Uninitialize();
|
|
|
|
}
|
2017-06-30 04:37:29 -04:00
|
|
|
else if (ul_reason_for_call == DLL_THREAD_ATTACH)
|
2017-06-10 14:24:42 -04:00
|
|
|
{
|
2017-06-23 04:04:43 -04:00
|
|
|
#ifndef DISABLE_ANTICHEAT
|
2017-06-10 14:24:42 -04:00
|
|
|
[]()
|
|
|
|
{
|
2017-07-12 05:33:30 -04:00
|
|
|
if (!Components::Dedicated::IsEnabled() && !Components::Loader::IsPerformingUnitTests())
|
2017-06-30 04:37:29 -04:00
|
|
|
{
|
|
|
|
Components::AntiCheat::VerifyThreadIntegrity();
|
|
|
|
}
|
2017-06-10 14:24:42 -04:00
|
|
|
}();
|
|
|
|
#endif
|
|
|
|
}
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|