2022-12-18 01:00:04 +01:00
|
|
|
#include "hooking.hpp"
|
|
|
|
#include "pointers.hpp"
|
|
|
|
|
2023-06-14 21:29:25 +00:00
|
|
|
#include <Psapi.h>
|
|
|
|
|
2022-12-18 01:00:04 +01:00
|
|
|
namespace big
|
|
|
|
{
|
2023-06-14 21:29:25 +00:00
|
|
|
bool inline is_address_in_game_region(uint64_t address)
|
|
|
|
{
|
|
|
|
static uint64_t moduleBase = NULL;
|
|
|
|
static uint64_t moduleSize = NULL;
|
|
|
|
if ((!moduleBase) || (!moduleSize))
|
|
|
|
{
|
|
|
|
MODULEINFO info;
|
|
|
|
if (!GetModuleInformation(GetCurrentProcess(), GetModuleHandle(0), &info, sizeof(info)))
|
|
|
|
{
|
|
|
|
LOG(FATAL) << "GetModuleInformation failed!";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moduleBase = (uint64_t)GetModuleHandle(0);
|
|
|
|
moduleSize = (uint64_t)info.SizeOfImage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return address > moduleBase && address < (moduleBase + moduleSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_jump(__int64 fptr)
|
|
|
|
{
|
|
|
|
if (!is_address_in_game_region(fptr))
|
|
|
|
return false;
|
|
|
|
|
2023-07-20 22:46:32 +02:00
|
|
|
auto value = *(uint8_t*)(fptr);
|
2023-06-14 21:29:25 +00:00
|
|
|
return value == 0xE9;
|
|
|
|
}
|
|
|
|
|
2023-09-12 20:19:24 +02:00
|
|
|
bool is_unwanted_dependency(__int64 cb, uint64_t caller_addr_offset)
|
2023-06-14 21:29:25 +00:00
|
|
|
{
|
|
|
|
auto f1 = *(__int64*)(cb + 0x60);
|
|
|
|
auto f2 = *(__int64*)(cb + 0x100);
|
|
|
|
|
2023-09-16 11:44:03 +00:00
|
|
|
if (!is_address_in_game_region(f1) || (f2 && !is_address_in_game_region(f2)))
|
2023-06-14 21:29:25 +00:00
|
|
|
return false;
|
|
|
|
|
2023-09-16 11:44:03 +00:00
|
|
|
return is_jump(f1) || is_jump(f2);
|
2023-06-14 21:29:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
void hooks::queue_dependency(void* dependency)
|
|
|
|
{
|
2023-09-12 20:19:24 +02:00
|
|
|
uint64_t caller_addr_offset = (uint64_t)_ReturnAddress();
|
|
|
|
|
|
|
|
static auto module_base = (uint64_t)GetModuleHandle(0);
|
|
|
|
|
|
|
|
caller_addr_offset -= module_base;
|
|
|
|
|
|
|
|
if (is_unwanted_dependency((__int64)dependency, caller_addr_offset))
|
2023-03-01 21:27:15 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-12-18 01:00:04 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
return g_hooking->get_original<hooks::queue_dependency>()(dependency);
|
|
|
|
}
|
2022-12-18 01:00:04 +01:00
|
|
|
}
|