Created
April 30, 2020 02:58
-
-
Save Radfordhound/fec9627e6f187f93ebfb31a5c5562369 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based heavily on Skyth's Helpers.h: https://github.com/blueskythlikesclouds/DllMods/blob/master/Dependencies/Helpers.h | |
#pragma once | |
#include "detours.h" | |
#define WIN32_LEAN_AND_MEAN | |
#include <windows.h> | |
#include <cstddef> | |
inline static const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr); | |
#ifdef BASE_ADDRESS | |
#define ASLR(address) (reinterpret_cast<std::size_t>(MODULE_HANDLE) + \ | |
static_cast<std::size_t>(address) - static_cast<std::size_t>(BASE_ADDRESS)) | |
#else | |
#define ASLR(address) (reinterpret_cast<std::size_t>(MODULE_HANDLE) + \ | |
static_cast<std::size_t>(address)) | |
#endif | |
#define ININSTALL_HOOK(orig, hook) \ | |
{ \ | |
DetourTransactionBegin(); \ | |
DetourUpdateThread(GetCurrentThread()); \ | |
DetourAttach((void**)&orig, hook); \ | |
DetourTransactionCommit(); \ | |
} | |
#define INSTALL_HOOK(name) ININSTALL_HOOK(name##_original, name##_hook) | |
#define INSTALL_HOOK_MEMBER(className, name) \ | |
ININSTALL_HOOK(className::name##_original, className##_##name##_hook) | |
#define FUNC_PTR(address, callingConvention, returnType, name, ...)\ | |
typedef returnType (callingConvention*name##_ptr_t)(__VA_ARGS__);\ | |
inline static const name##_ptr_t name = reinterpret_cast<name##_ptr_t>(address);\ | |
inline static name##_ptr_t name##_original = reinterpret_cast<name##_ptr_t>(address) | |
#define MEMBER_FUNC(address, className, returnType, name, ...)\ | |
typedef returnType (__thiscall*name##_ptr_t)(className* thisPtr, __VA_ARGS__);\ | |
inline static const name##_ptr_t name##_ptr = (name##_ptr_t)(address);\ | |
inline static name##_ptr_t name##_original = reinterpret_cast<name##_ptr_t>(address) | |
#define CALL_ORIGINAL(name, ...) name##_original(__VA_ARGS__) | |
#define HOOK(callingConvention, returnType, name, ...)\ | |
returnType callingConvention name##_hook(__VA_ARGS__) | |
#if defined(x64) || defined(_AMD64_) | |
#define HOOK_MEMBER(className, returnType, name, ...)\ | |
returnType __fastcall className##_##name##_hook(className* thisPtr,\ | |
__VA_ARGS__) | |
#else | |
#define HOOK_MEMBER(className, returnType, name, ...)\ | |
returnType __fastcall className##_##name##_hook(className* thisPtr,\ | |
void* DUMMY_ARGUMENT, __VA_ARGS__) | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment