-
Notifications
You must be signed in to change notification settings - Fork 24
/
Sample.IATHooking.h
42 lines (31 loc) · 1.59 KB
/
Sample.IATHooking.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include "Sample.h"
typedef int (WINAPI* PfnMessageBoxA)(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);
typedef int (WINAPI* PfnMessageBoxW)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
PfnMessageBoxA pfnMessageBoxA = nullptr;
PfnMessageBoxW pfnMessageBoxW = nullptr;
int WINAPI HfnMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
lpText = "MessageBoxA -> Hooked";
return pfnMessageBoxA(hWnd, lpText, lpCaption, uType);
}
int WINAPI HfnMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
lpText = L"MessageBoxW -> Hooked";
return pfnMessageBoxW(hWnd, lpText, lpCaption, uType);
}
DEF_SAMPLE(IATHooking)
{
vu::Process process;
process.attach(GetCurrentProcess());
auto process_name = process.name();
vu::IATHooking::instance().install(process_name, ts("user32.dll"), ts("MessageBoxA"), HfnMessageBoxA, (void**)&pfnMessageBoxA);
vu::IATHooking::instance().install(process_name, ts("user32.dll"), ts("MessageBoxW"), HfnMessageBoxW, (void**)&pfnMessageBoxW);
MessageBoxA(vu::get_console_window(), "The first message.", "A", MB_OK);
MessageBoxW(vu::get_console_window(), L"The first message.", L"W", MB_OK);
vu::IATHooking::instance().uninstall(process_name, ts("user32.dll"), ts("MessageBoxA"), (void**)&pfnMessageBoxA);
vu::IATHooking::instance().uninstall(process_name, ts("user32.dll"), ts("MessageBoxW"), (void**)&pfnMessageBoxW);
MessageBoxA(vu::get_console_window(), "The second message.", "A", MB_OK);
MessageBoxW(vu::get_console_window(), L"The second message.", L"W", MB_OK);
return vu::VU_OK;
}