#include <Windows.h>
|
#include <cstdio>
|
|
VOID PrintHex(PBYTE Data, ULONG dwBytes) {
|
for (ULONG i = 0; i < dwBytes; i += 16) {
|
printf("%.8x: ", i);
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes) {
|
printf("%.2x ", Data[i + j]);
|
}
|
else {
|
printf("?? ");
|
}
|
}
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes && Data[i + j] >= 0x20 && Data[i + j] <= 0x7e) {
|
printf("%c", Data[i + j]);
|
}
|
else {
|
printf(".");
|
}
|
}
|
|
printf("\n");
|
}
|
}
|
|
PVOID *GetUser32DispatchTable() {
|
__asm{
|
mov eax, fs:30h
|
mov eax, [eax+0x2c]
|
}
|
}
|
|
BOOL HookUser32DispatchFunction(UINT Index, PVOID lpNewHandler) {
|
PVOID *DispatchTable = GetUser32DispatchTable();
|
DWORD OldProtect;
|
|
if (!VirtualProtect(DispatchTable, 0x1000, PAGE_READWRITE, &OldProtect)) {
|
printf("VirtualProtect#1 failed, %d\n", GetLastError());
|
return FALSE;
|
}
|
|
DispatchTable[Index] = lpNewHandler;
|
|
if (!VirtualProtect(DispatchTable, 0x1000, OldProtect, &OldProtect)) {
|
printf("VirtualProtect#2 failed, %d\n", GetLastError());
|
return FALSE;
|
}
|
|
return TRUE;
|
}
|
|
VOID ClientLpkDrawTextExHook(LPVOID Data) {
|
printf("----------\n");
|
PrintHex((PBYTE)Data, 0x98);
|
}
|
|
int main() {
|
if (!HookUser32DispatchFunction(69, ClientLpkDrawTextExHook)) {
|
return 1;
|
}
|
|
HWND hwnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, 0, 0);
|
DestroyWindow(hwnd);
|
|
return 0;
|
}
|