-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
76 lines (57 loc) · 2.69 KB
/
main.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// main.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <vu>
using namespace vu;
#ifndef VU_HAS_CPP_HOOKING
#include "cpp-hooking/hooking.h"
#endif
// Inline Hooking
int WINAPI hkMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
lpText = "INL Hooked";
return INLHookingManager::instance().invoke<int>(MessageBoxA, hWnd, lpText, lpCaption, uType);
}
int WINAPI hkMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
lpText = L"INL Hooked";
return INLHookingManager::instance().invoke<int>(MessageBoxW, hWnd, lpText, lpCaption, uType);
}
// IAT Hooking
#include <string>
using namespace std::literals::string_literals;
#define Entry_MessageBoxA { "cpp-hooking.exe"s, "user32.dll"s, "MessageBoxA"s }
#define Entry_MessageBoxW { "cpp-hooking.exe"s, "user32.dll"s, "MessageBoxW"s }
int WINAPI iat_hkMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType)
{
lpText = "IAT Hooked";
return IATHookingManager::instance().invoke<int>(Entry_MessageBoxA, hWnd, lpText, lpCaption, uType);
}
int WINAPI iat_hkMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
lpText = L"IAT Hooked";
return IATHookingManager::instance().invoke<int>(Entry_MessageBoxW, hWnd, lpText, lpCaption, uType);
}
#include <vu> // for `vu::get_console_window()`
int main()
{
auto hwnd = vu::get_console_window();
// Inline Hooking
INLHookingManager::instance().hook(MessageBoxA, hkMessageBoxA);
INLHookingManager::instance().hook(MessageBoxW, hkMessageBoxW);
MessageBoxA(hwnd, "The first message.", "MessageBoxA", MB_OK); // text is replaced by "INL Hooked"
MessageBoxW(hwnd, L"The first message.", L"MessageBoxW", MB_OK); // text is replaced by "INL Hooked"
INLHookingManager::instance().unhook(MessageBoxA);
INLHookingManager::instance().unhook(MessageBoxW);
MessageBoxA(hwnd, "The second message.", "MessageBoxA", MB_OK);
MessageBoxW(hwnd, L"The second message.", L"MessageBoxW", MB_OK);
// IAT Hooking
IATHookingManager::instance().hook(Entry_MessageBoxA, iat_hkMessageBoxA);
IATHookingManager::instance().hook(Entry_MessageBoxW, iat_hkMessageBoxW);
MessageBoxA(hwnd, "The first message.", "MessageBoxA", MB_OK); // text is replaced by "IAT Hooked"
MessageBoxW(hwnd, L"The first message.", L"MessageBoxW", MB_OK); // text is replaced by "IAT Hooked"
IATHookingManager::instance().unhook(Entry_MessageBoxA);
IATHookingManager::instance().unhook(Entry_MessageBoxW);
MessageBoxA(hwnd, "The second message.", "MessageBoxA", MB_OK);
MessageBoxW(hwnd, L"The second message.", L"MessageBoxW", MB_OK);
return 0;
}