From f23fa6a969f7867fc4e4efea6304e57db16a96dd Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Sat, 28 May 2022 13:12:29 +0300 Subject: [PATCH 1/4] Use ASLR patched binaries --- src/client/component/game_module.cpp | 8 +++---- src/client/main.cpp | 34 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/client/component/game_module.cpp b/src/client/component/game_module.cpp index 0ec79d45..ad4eb9ce 100644 --- a/src/client/component/game_module.cpp +++ b/src/client/component/game_module.cpp @@ -60,9 +60,9 @@ namespace game_module DWORD __stdcall get_module_file_name_a(HMODULE hmodule, const LPSTR filename, const DWORD size) { - if (!hmodule) + if (!hmodule || utils::nt::library(hmodule) == get_game_module()) { - hmodule = get_game_module(); + hmodule = get_host_module(); } return file_name_a_hook.invoke(hmodule, filename, size); @@ -70,9 +70,9 @@ namespace game_module DWORD __stdcall get_module_file_name_w(HMODULE hmodule, const LPWSTR filename, const DWORD size) { - if (!hmodule) + if (!hmodule || utils::nt::library(hmodule) == get_game_module()) { - hmodule = get_game_module(); + hmodule = get_host_module(); } return file_name_w_hook.invoke(hmodule, filename, size); diff --git a/src/client/main.cpp b/src/client/main.cpp index 5f26e699..1f013c6d 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -40,6 +40,38 @@ launcher::mode detect_mode_from_arguments() return launcher::mode::none; } +bool apply_dslr_patch(std::string* data) +{ + if (data->size() < 0x1EE || (data->at(0x1EE) != static_cast(0x60) && data->at(0x1EE) != static_cast(0x20))) + { + // what the fuck is wrong with this binary data? + return false; + } + + data->at(0x1EE) = static_cast(0x20); + return true; +} + +void get_aslr_patched_binary(std::string* binary, std::string* data) +{ + std::string patched_binary = "h1-mod\\" + *binary; + + if (!apply_dslr_patch(data)) + { + throw std::runtime_error(utils::string::va( + "Could not create aslr patched binary!\n(%s)", + *binary->data() + )); + } + + if (!utils::io::file_exists(patched_binary)) + { + utils::io::write_file(patched_binary, *data, false); + } + + *binary = patched_binary; +} + FARPROC load_binary(const launcher::mode mode, uint64_t* base_address) { loader loader; @@ -86,6 +118,8 @@ FARPROC load_binary(const launcher::mode mode, uint64_t* base_address) "Failed to read game binary (%s)!\nPlease copy the h1-mod.exe into your Call of Duty: Modern Warfare Remastered installation folder and run it from there.", binary.data())); } + + get_aslr_patched_binary(&binary, &data); #ifdef INJECT_HOST_AS_LIB return loader.load_library(binary, base_address); From f3ee51bc6592b89039624f3b9ed09536c1355141 Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Sat, 28 May 2022 13:15:17 +0300 Subject: [PATCH 2/4] Fix typo --- src/client/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/main.cpp b/src/client/main.cpp index 1f013c6d..1d11aea6 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -40,7 +40,7 @@ launcher::mode detect_mode_from_arguments() return launcher::mode::none; } -bool apply_dslr_patch(std::string* data) +bool apply_aslr_patch(std::string* data) { if (data->size() < 0x1EE || (data->at(0x1EE) != static_cast(0x60) && data->at(0x1EE) != static_cast(0x20))) { @@ -56,7 +56,7 @@ void get_aslr_patched_binary(std::string* binary, std::string* data) { std::string patched_binary = "h1-mod\\" + *binary; - if (!apply_dslr_patch(data)) + if (!apply_aslr_patch(data)) { throw std::runtime_error(utils::string::va( "Could not create aslr patched binary!\n(%s)", From 7023a3b21e611f6525e122f534ee5a91ad1d969d Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Sat, 28 May 2022 13:26:19 +0300 Subject: [PATCH 3/4] Fix oopsie --- src/client/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/main.cpp b/src/client/main.cpp index 1d11aea6..d3f89265 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -60,7 +60,7 @@ void get_aslr_patched_binary(std::string* binary, std::string* data) { throw std::runtime_error(utils::string::va( "Could not create aslr patched binary!\n(%s)", - *binary->data() + binary->data() )); } From 21b7dc68de4fe065a808d83147a1e7e6fd4c958f Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Sat, 28 May 2022 13:47:18 +0300 Subject: [PATCH 4/4] Forgot about this --- premake5.lua | 2 +- src/client/std_include.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/premake5.lua b/premake5.lua index 82b0ad32..7bb114b7 100644 --- a/premake5.lua +++ b/premake5.lua @@ -303,7 +303,7 @@ targetname "h1-mod" pchheader "std_include.hpp" pchsource "src/client/std_include.cpp" -linkoptions {"/IGNORE:4254", "/SAFESEH:NO", "/LARGEADDRESSAWARE", "/PDBCompress"} +linkoptions {"/IGNORE:4254", "/DYNAMICBASE:NO", "/SAFESEH:NO", "/LARGEADDRESSAWARE", "/PDBCompress"} files {"./src/client/**.rc", "./src/client/**.hpp", "./src/client/**.cpp", "./src/client/resources/**.*"} diff --git a/src/client/std_include.cpp b/src/client/std_include.cpp index 20f99122..2e932681 100644 --- a/src/client/std_include.cpp +++ b/src/client/std_include.cpp @@ -3,7 +3,7 @@ #pragma comment(linker, "/stack:0x1000000") #ifdef INJECT_HOST_AS_LIB -//#pragma comment(linker, "/base:0x160000000") +#pragma comment(linker, "/base:0x160000000") #else #pragma comment(linker, "/base:0x140000000") #pragma comment(linker, "/merge:.data=.cld")