├── README.md ├── veh.cpp └── veh.h /README.md: -------------------------------------------------------------------------------- 1 | # veh_hooking 2 | x64/x86 Hooking through VectoredExceptionHandler (PAGE_GUARD method) 3 | 4 | Anti-cheat safe in most games with little performance loss in some situations 5 | 6 | # How To Use 7 | - Call veh::Setup() 8 | - Hook functions through veh::Hook(old, new) 9 | - Unhook functions with veh::Destroy() (you will need to call veh::Setup() again if you wanna hook functions again) 10 | 11 | To call the original function from inside the hook function use veh::CallOriginal(original, args) 12 | 13 | # Example 14 | ```cpp 15 | 16 | void hooks::Setup() 17 | { 18 | veh::Setup(); 19 | veh::Hook(Present, Present_hk); 20 | veh::Hook(CreateMove, CreateMove_hk); 21 | } 22 | 23 | void hooks::Destroy() 24 | { 25 | veh::Destroy(); 26 | 27 | if (ImGui::GetCurrentContext()) 28 | { 29 | ImGui_ImplDX11_Shutdown(); 30 | ImGui_ImplWin32_Shutdown(); 31 | } 32 | } 33 | 34 | bool hooks::CreateMove_hk(CCSGOInput* csgo_input, uint32_t slot, uint64_t a3, uint8_t a4) 35 | { 36 | bool result = veh::CallOriginal(CreateMove, csgo_input, slot, a3, a4); 37 | 38 | if (!globals::Update() || !globals::local_pawn->m_pGameSceneNode()) 39 | return result; 40 | 41 | CUserCmd* user_cmd = csgo_input->GetUserCmd(slot); 42 | globals::view_angles = user_cmd->base_user_cmd->msg_qangle->angles; 43 | globals::shoot_position = globals::local_pawn->m_pGameSceneNode()->m_vecAbsOrigin() + globals::local_pawn->m_vecViewOffset(); 44 | 45 | aim_assist::Tick(user_cmd, csgo_input, slot); 46 | triggerbot::Tick(user_cmd); 47 | misc::AutoFire(user_cmd); 48 | 49 | return result; 50 | } 51 | ``` 52 | -------------------------------------------------------------------------------- /veh.cpp: -------------------------------------------------------------------------------- 1 | #include "veh.h" 2 | 3 | void veh::Setup() 4 | { 5 | GetSystemInfo(&system_info); 6 | handle = AddVectoredExceptionHandler(1, VectoredExceptionHandler); 7 | } 8 | 9 | bool veh::Hook(void* source, void* destination) 10 | { 11 | if (!handle) 12 | return false; 13 | 14 | MEMORY_BASIC_INFORMATION source_info; 15 | if (!VirtualQuery(source, &source_info, sizeof(MEMORY_BASIC_INFORMATION))) 16 | return false; 17 | 18 | MEMORY_BASIC_INFORMATION destination_info; 19 | if (!VirtualQuery(destination, &destination_info, sizeof(MEMORY_BASIC_INFORMATION))) 20 | return false; 21 | 22 | if (source_info.AllocationBase == destination_info.AllocationBase) 23 | return false; 24 | 25 | hooks.push_back({ source, destination }); 26 | DWORD tmp; 27 | VirtualProtect(source, system_info.dwPageSize, PAGE_EXECUTE_READ | PAGE_GUARD, &tmp); 28 | return true; 29 | } 30 | 31 | void veh::Destroy() 32 | { 33 | std::vector _hooks(hooks); 34 | hooks.clear(); 35 | 36 | for (HookInfo_t& hook_info : _hooks) 37 | { 38 | DWORD tmp; 39 | VirtualProtect(hook_info.source, system_info.dwPageSize, PAGE_EXECUTE_READ, &tmp); 40 | } 41 | 42 | RemoveVectoredExceptionHandler(handle); 43 | handle = nullptr; 44 | } 45 | 46 | LONG veh::VectoredExceptionHandler(EXCEPTION_POINTERS* exception_info) 47 | { 48 | if (exception_info->ExceptionRecord->ExceptionCode == EXCEPTION_GUARD_PAGE) 49 | { 50 | for (HookInfo_t& hook_info : hooks) 51 | { 52 | if (exception_info->ExceptionRecord->ExceptionAddress == hook_info.source) 53 | { 54 | #ifdef _WIN64 55 | exception_info->ContextRecord->Rip = (DWORD64)hook_info.destination; 56 | #else 57 | exception_info->ContextRecord->Eip = (DWORD)hook_info.destination; 58 | #endif 59 | } 60 | } 61 | 62 | exception_info->ContextRecord->EFlags |= PAGE_GUARD; 63 | return EXCEPTION_CONTINUE_EXECUTION; 64 | } 65 | else if (exception_info->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) 66 | { 67 | for (HookInfo_t& hook_info : hooks) 68 | { 69 | DWORD tmp; 70 | VirtualProtect(hook_info.source, system_info.dwPageSize, PAGE_EXECUTE_READ | PAGE_GUARD, &tmp); 71 | } 72 | 73 | return EXCEPTION_CONTINUE_EXECUTION; 74 | } 75 | 76 | return EXCEPTION_CONTINUE_SEARCH; 77 | } 78 | -------------------------------------------------------------------------------- /veh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | struct HookInfo_t 6 | { 7 | void* source; 8 | void* destination; 9 | }; 10 | 11 | namespace veh 12 | { 13 | void Setup(); 14 | bool Hook(void* source, void* destination); 15 | void Destroy(); 16 | LONG VectoredExceptionHandler(EXCEPTION_POINTERS* exception_info); 17 | 18 | template 19 | ReturnType CallOriginal(Prototype source, Args... args); 20 | 21 | inline SYSTEM_INFO system_info; 22 | inline PVOID handle; 23 | inline std::vector hooks; 24 | } 25 | 26 | template 27 | ReturnType veh::CallOriginal(Prototype source, Args... args) 28 | { 29 | DWORD old_protection; 30 | 31 | if constexpr (std::is_void_v) 32 | { 33 | VirtualProtect(source, system_info.dwPageSize, PAGE_EXECUTE_READ, &old_protection); 34 | source(args...); 35 | VirtualProtect(source, system_info.dwPageSize, old_protection, &old_protection); 36 | } 37 | else 38 | { 39 | VirtualProtect(source, system_info.dwPageSize, PAGE_EXECUTE_READ, &old_protection); 40 | ReturnType result = source(args...); 41 | VirtualProtect(source, system_info.dwPageSize, old_protection, &old_protection); 42 | return result; 43 | } 44 | } 45 | --------------------------------------------------------------------------------