@@ -56,32 +56,37 @@ const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr);
56
56
57
57
#define WRITE_MEMORY (location , type , ...) \
58
58
do { \
59
- const type data[] = { __VA_ARGS__ }; \
60
- DWORD oldProtect; \
61
- VirtualProtect((void*)(location), sizeof(data), PAGE_EXECUTE_READWRITE, &oldProtect); \
62
- memcpy((void*)(location), data, sizeof(data)); \
63
- VirtualProtect((void*)(location), sizeof(data), oldProtect, &oldProtect); \
59
+ void* writeMemLoc = (void*)(location); \
60
+ const type writeMemData[] = { __VA_ARGS__ }; \
61
+ DWORD writeMemOldProtect; \
62
+ VirtualProtect(writeMemLoc, sizeof(writeMemData), PAGE_EXECUTE_READWRITE, &writeMemOldProtect); \
63
+ memcpy(writeMemLoc, writeMemData, sizeof(writeMemData)); \
64
+ VirtualProtect(writeMemLoc, sizeof(writeMemData), writeMemOldProtect, &writeMemOldProtect); \
64
65
} while(0)
65
66
66
67
#define WRITE_JUMP (location , function ) \
67
68
do { \
68
- WRITE_MEMORY((size_t)(location), uint8_t, 0x48, 0xB8); \
69
- WRITE_MEMORY((size_t)(location) + 2, uint64_t, (uint64_t)(function)); \
70
- WRITE_MEMORY((size_t)(location) + 10, uint8_t, 0xFF, 0xE0); \
69
+ size_t writeJmpLoc = (size_t)(location); \
70
+ WRITE_MEMORY(writeJmpLoc, uint8_t, 0x48, 0xB8); \
71
+ WRITE_MEMORY(writeJmpLoc + 2, uint64_t, (uint64_t)(function)); \
72
+ WRITE_MEMORY(writeJmpLoc + 10, uint8_t, 0xFF, 0xE0); \
71
73
} while(0)
72
74
73
75
#define WRITE_CALL (location , function ) \
74
76
do { \
75
- WRITE_MEMORY((size_t)(location), uint8_t, 0x48, 0xB8); \
76
- WRITE_MEMORY((size_t)(location) + 2, uint64_t, (uint64_t)(function)); \
77
- WRITE_MEMORY((size_t)(location) + 10, uint8_t, 0xFF, 0xD0); \
77
+ size_t writeCallLoc = (size_t)(location); \
78
+ WRITE_MEMORY(writeCallLoc, uint8_t, 0x48, 0xB8); \
79
+ WRITE_MEMORY(writeCallLoc + 2, uint64_t, (uint64_t)(function)); \
80
+ WRITE_MEMORY(writeCallLoc + 10, uint8_t, 0xFF, 0xD0); \
78
81
} while(0)
79
82
80
83
#define WRITE_NOP (location , count ) \
81
84
do { \
82
- DWORD oldProtect; \
83
- VirtualProtect((void*)(location), (size_t)(count), PAGE_EXECUTE_READWRITE, &oldProtect); \
84
- for (size_t i = 0; i < (size_t)(count); i++) \
85
- *((uint8_t*)(location) + i) = 0x90; \
86
- VirtualProtect((void*)(location), (size_t)(count), oldProtect, &oldProtect); \
85
+ void* writeNopLoc = (void*)(location); \
86
+ size_t writeNopCount = (size_t)(count); \
87
+ DWORD writeNopOldProtect; \
88
+ VirtualProtect(writeNopLoc, writeNopCount, PAGE_EXECUTE_READWRITE, &writeNopOldProtect); \
89
+ for (size_t i = 0; i < writeNopCount; i++) \
90
+ *((uint8_t*)writeNopLoc + i) = 0x90; \
91
+ VirtualProtect(writeNopLoc, writeNopCount, writeNopOldProtect, &writeNopOldProtect); \
87
92
} while(0)
0 commit comments