Пользователь
- Статус
- Оффлайн
- Регистрация
- 12 Янв 2018
- Сообщения
- 55
- Реакции
- 116
Код:
#include <iostream>
#include <cstddef>
#include <Windows.h>
#define KAREN_READ_WRITE_EXECUTE 0x40
#define KAREN_CALL '\xe9'
#define KAREN_JUMP_SIZE 0x5
struct Example_t {
uint32_t field1;
float_t field2;
};
void __stdcall NtZwHkStruct() {
std::cout << "hooked struct" << std::endl;
//triggering break in debugger to simple proof it works when running debugger
__debugbreak();
}
int main() {
//Creating object of Example_t structure, just for example. Storing it inside struct1
auto struct1 = Example_t();
//Changing protection of struct to KAREN_READ_WRITE_EXECUTE, so we allow read, write and execute
//memory located at address of struct1
//No memory leak, new DWORD will be destroyed by Karen right after finishing program
VirtualProtect(&struct1, sizeof(Example_t), KAREN_READ_WRITE_EXECUTE, new DWORD);
//just hooking our struct object via simple bytepatching
//changing first structure byte to 0xe9 (KAREN_JUMP instruction specified inside INTEL KAREN MANUAL)
*(char*)& struct1 = KAREN_CALL;
//replacing next 4(sizeof uintptr_t in x86) bytes with offset to NtZwHkStruct
*(uintptr_t*)((uintptr_t)&struct1 + 1) = (uintptr_t)&NtZwHkStruct - (uintptr_t)&struct1 - KAREN_JUMP_SIZE;
//Calling struct1 object
((decltype(&NtZwHkStruct))&struct1)();
return 0;
}
