Merge pull request #71 from h1-mod/aslr_patch
This commit is contained in:
commit
d2ec7fff4c
@ -303,7 +303,7 @@ targetname "h1-mod"
|
|||||||
pchheader "std_include.hpp"
|
pchheader "std_include.hpp"
|
||||||
pchsource "src/client/std_include.cpp"
|
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/**.*"}
|
files {"./src/client/**.rc", "./src/client/**.hpp", "./src/client/**.cpp", "./src/client/resources/**.*"}
|
||||||
|
|
||||||
|
@ -60,9 +60,9 @@ namespace game_module
|
|||||||
|
|
||||||
DWORD __stdcall get_module_file_name_a(HMODULE hmodule, const LPSTR filename, const DWORD size)
|
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<DWORD>(hmodule, filename, size);
|
return file_name_a_hook.invoke<DWORD>(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)
|
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<DWORD>(hmodule, filename, size);
|
return file_name_w_hook.invoke<DWORD>(hmodule, filename, size);
|
||||||
|
@ -40,6 +40,38 @@ launcher::mode detect_mode_from_arguments()
|
|||||||
return launcher::mode::none;
|
return launcher::mode::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool apply_aslr_patch(std::string* data)
|
||||||
|
{
|
||||||
|
if (data->size() < 0x1EE || (data->at(0x1EE) != static_cast<char>(0x60) && data->at(0x1EE) != static_cast<char>(0x20)))
|
||||||
|
{
|
||||||
|
// what the fuck is wrong with this binary data?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->at(0x1EE) = static_cast<char>(0x20);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_aslr_patched_binary(std::string* binary, std::string* data)
|
||||||
|
{
|
||||||
|
std::string patched_binary = "h1-mod\\" + *binary;
|
||||||
|
|
||||||
|
if (!apply_aslr_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)
|
FARPROC load_binary(const launcher::mode mode, uint64_t* base_address)
|
||||||
{
|
{
|
||||||
loader loader;
|
loader loader;
|
||||||
@ -87,6 +119,8 @@ FARPROC load_binary(const launcher::mode mode, uint64_t* base_address)
|
|||||||
binary.data()));
|
binary.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_aslr_patched_binary(&binary, &data);
|
||||||
|
|
||||||
#ifdef INJECT_HOST_AS_LIB
|
#ifdef INJECT_HOST_AS_LIB
|
||||||
return loader.load_library(binary, base_address);
|
return loader.load_library(binary, base_address);
|
||||||
#else
|
#else
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#pragma comment(linker, "/stack:0x1000000")
|
#pragma comment(linker, "/stack:0x1000000")
|
||||||
|
|
||||||
#ifdef INJECT_HOST_AS_LIB
|
#ifdef INJECT_HOST_AS_LIB
|
||||||
//#pragma comment(linker, "/base:0x160000000")
|
#pragma comment(linker, "/base:0x160000000")
|
||||||
#else
|
#else
|
||||||
#pragma comment(linker, "/base:0x140000000")
|
#pragma comment(linker, "/base:0x140000000")
|
||||||
#pragma comment(linker, "/merge:.data=.cld")
|
#pragma comment(linker, "/merge:.data=.cld")
|
||||||
|
Loading…
Reference in New Issue
Block a user