make detour faster

This commit is contained in:
quaK 2025-05-02 20:38:18 +03:00
parent 157ed4db6e
commit 98775cfa7f
5 changed files with 38 additions and 16 deletions

View File

@ -9,14 +9,20 @@
#include <utils/hook.hpp>
#include <utils/string.hpp>
#include "integrity.hpp"
#include "breakpoints.hpp"
#include "illegal_instructions.hpp"
#define PRECOMPUTED_INTEGRITY_CHECKS
#define PRECOMPUTED_BREAKPOINTS
#define PRECOMPUTED_ILLEGAL_INSTRUCTIONS
#ifdef PRECOMPUTED_INTEGRITY_CHECKS
#include "integrity.hpp"
#endif
#ifdef PRECOMPUTED_BREAKPOINTS
#include "breakpoints.hpp"
#endif
#ifdef PRECOMPUTED_ILLEGAL_INSTRUCTIONS
#include "illegal_instructions.hpp"
#endif
#define ProcessDebugPort 7
#define ProcessDebugObjectHandle 30
#define ProcessDebugFlags 31
@ -674,6 +680,7 @@ namespace arxan
const auto nt_query_information_process = ntdll.get_proc<void*>("NtQueryInformationProcess");
nt_query_information_process_hook.create(nt_query_information_process, nt_query_information_process_stub);
nt_query_information_process_hook.enable();
nt_query_information_process_hook.move();
AddVectoredExceptionHandler(1, exception_filter);

View File

@ -113,6 +113,8 @@ namespace fastfiles
HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename)
{
auto result = sys_createfile_hook.invoke<HANDLE>(folder, base_filename);
const auto create_file_a = [](const std::string& filepath)
{
return CreateFileA(filepath.data(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
@ -138,12 +140,9 @@ namespace fastfiles
return INVALID_HANDLE_VALUE;
}
if (auto result = sys_createfile_hook.invoke<HANDLE>(folder, base_filename))
if (result != INVALID_HANDLE_VALUE)
{
if (result != INVALID_HANDLE_VALUE)
{
return result;
}
return result;
}
std::string real_path{};

View File

@ -17,6 +17,8 @@ DECLSPEC_NORETURN void WINAPI exit_hook(const int code)
DWORD_PTR WINAPI set_thread_affinity_mask(HANDLE hThread, DWORD_PTR dwThreadAffinityMask)
{
component_loader::post_unpack();
MH_ApplyQueued();
return SetThreadAffinityMask(hThread, dwThreadAffinityMask);
}
@ -154,6 +156,7 @@ int main()
game::base_address = base_address;
if (!component_loader::post_load()) return EXIT_FAILURE;
MH_ApplyQueued();
premature_shutdown = false;
}

View File

@ -1,4 +1,4 @@
#include "hook.hpp"
#include "hook.hpp"
#include <map>
#include <MinHook.h>
@ -291,6 +291,16 @@ namespace utils::hook
this->clear();
}
void detour::queue_enable()
{
MH_QueueEnableHook(this->place_);
}
void detour::queue_disable()
{
MH_QueueDisableHook(this->place_);
}
void detour::enable()
{
MH_EnableHook(this->place_);
@ -317,7 +327,7 @@ namespace utils::hook
throw std::runtime_error(string::va("Unable to create hook at location: %p", this->place_));
}
this->enable();
this->queue_enable();
}
void detour::create(const size_t place, void* target)
@ -540,15 +550,15 @@ namespace utils::hook
asm_function(a);
void* result = nullptr;
auto err_result = runtime.add(&result, &code);
void* dst = nullptr;
auto result = runtime.add(&dst, &code);
if (err_result != asmjit::ErrorCode::kErrorOk)
if (result != asmjit::ErrorCode::kErrorOk)
{
printf("ASMJIT ERROR: %s\n", asmjit::DebugUtils::errorAsString(err_result));
throw std::runtime_error(string::va("ASMJIT ERROR: %s\n", asmjit::DebugUtils::errorAsString(result)));
}
return result;
return dst;
}
void inject(size_t pointer, size_t data)

View File

@ -122,6 +122,9 @@ namespace utils::hook
void enable();
void disable();
void queue_enable();
void queue_disable();
void create(void* place, void* target);
void create(size_t place, void* target);
void clear();