@@ -30,57 +30,56 @@ const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr);
30
30
returnType callingConvention implOf##functionName(__VA_ARGS__)
31
31
32
32
#define INSTALL_HOOK (functionName ) \
33
- { \
33
+ do { \
34
34
DetourTransactionBegin(); \
35
35
DetourUpdateThread(GetCurrentThread()); \
36
36
DetourAttach((void**)&original##functionName, implOf##functionName); \
37
37
DetourTransactionCommit(); \
38
- }
38
+ } while(0)
39
39
40
40
#define VTABLE_HOOK (returnType , callingConvention , className , functionName , ...) \
41
41
typedef returnType callingConvention className##functionName(className* This, __VA_ARGS__); \
42
42
className##functionName* original##className##functionName; \
43
43
returnType callingConvention implOf##className##functionName(className* This, __VA_ARGS__)
44
44
45
45
#define INSTALL_VTABLE_HOOK (className , object , functionName , functionIndex ) \
46
- { \
47
- void** addr = &(*(void***)object)[functionIndex]; \
48
- if (*addr != implOf##className##functionName) \
46
+ do { \
47
+ if (original##className##functionName == nullptr) \
49
48
{ \
50
- original##className##functionName = (className##functionName*)*addr ; \
51
- DWORD oldProtect ; \
52
- VirtualProtect(addr, sizeof(void*), PAGE_EXECUTE_READWRITE, &oldProtect ); \
53
- *addr = implOf##className##functionName; \
54
- VirtualProtect(addr, sizeof(void*), oldProtect, &oldProtect ); \
49
+ original##className##functionName = (*( className##functionName***)object)[functionIndex] ; \
50
+ DetourTransactionBegin() ; \
51
+ DetourUpdateThread(GetCurrentThread() ); \
52
+ DetourAttach((void**)&original##className##functionName, implOf##className##functionName) ; \
53
+ DetourTransactionCommit( ); \
55
54
} \
56
- }
55
+ } while(0)
57
56
58
57
#define WRITE_MEMORY (location , type , ...) \
59
- { \
58
+ do { \
60
59
const type data[] = { __VA_ARGS__ }; \
61
60
DWORD oldProtect; \
62
61
VirtualProtect((void*)(location), sizeof(data), PAGE_EXECUTE_READWRITE, &oldProtect); \
63
62
memcpy((void*)(location), data, sizeof(data)); \
64
63
VirtualProtect((void*)(location), sizeof(data), oldProtect, &oldProtect); \
65
- }
64
+ } while(0)
66
65
67
66
#define WRITE_JUMP (location , function ) \
68
- { \
67
+ do { \
69
68
WRITE_MEMORY(location, uint8_t, 0xE9); \
70
- WRITE_MEMORY(location + 1, uint32_t, (uint32_t)(function) - (size_t)(location) - 5); \
71
- }
69
+ WRITE_MEMORY(location + 1, uint32_t, (uint32_t)((size_t)( function) - (size_t)(location) - 5) ); \
70
+ } while(0)
72
71
73
72
#define WRITE_CALL (location , function ) \
74
- { \
73
+ do { \
75
74
WRITE_MEMORY(location, uint8_t, 0xE8); \
76
- WRITE_MEMORY(location + 1, uint32_t, (uint32_t)(function) - (size_t)(location) - 5); \
77
- }
75
+ WRITE_MEMORY(location + 1, uint32_t, (uint32_t)((size_t)( function) - (size_t)(location) - 5) ); \
76
+ } while(0)
78
77
79
78
#define WRITE_NOP (location , count ) \
80
- { \
79
+ do { \
81
80
DWORD oldProtect; \
82
81
VirtualProtect((void*)(location), (size_t)(count), PAGE_EXECUTE_READWRITE, &oldProtect); \
83
82
for (size_t i = 0; i < (size_t)(count); i++) \
84
83
*((uint8_t*)(location) + i) = 0x90; \
85
84
VirtualProtect((void*)(location), (size_t)(count), oldProtect, &oldProtect); \
86
- }
85
+ } while(0)
0 commit comments