diff --git a/src/client/component/arxan/arxan.cpp b/src/client/component/arxan/arxan.cpp index c185dd9a..58034cdc 100644 --- a/src/client/component/arxan/arxan.cpp +++ b/src/client/component/arxan/arxan.cpp @@ -9,14 +9,20 @@ #include #include -#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("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); diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index b2441b99..88414480 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -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(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(folder, base_filename)) + if (result != INVALID_HANDLE_VALUE) { - if (result != INVALID_HANDLE_VALUE) - { - return result; - } + return result; } std::string real_path{}; diff --git a/src/client/main.cpp b/src/client/main.cpp index 808973ff..849b8333 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -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; } diff --git a/src/common/utils/hook.cpp b/src/common/utils/hook.cpp index b58b34d3..614919e4 100644 --- a/src/common/utils/hook.cpp +++ b/src/common/utils/hook.cpp @@ -1,4 +1,4 @@ -#include "hook.hpp" +#include "hook.hpp" #include #include @@ -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) diff --git a/src/common/utils/hook.hpp b/src/common/utils/hook.hpp index 6c8ba52b..707eb1c0 100644 --- a/src/common/utils/hook.hpp +++ b/src/common/utils/hook.hpp @@ -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();