5 BOOL WINAPI
MessageBeepHook(__in UINT uType
)
7 printf("New Silent MessageBeep\n");
11 BOOL WINAPI
IMPL_GetTextExtentPoint32W(HDC hdc
, LPCWSTR lpString
, int cbString
, LPSIZE lpSize
)
13 printf("GetTextExtentPoint32W\n");
17 BOOL WINAPI
IMPL_GetTextExtentPoint32A(HDC hdc
, LPCSTR lpString
, int cbString
, LPSIZE lpSize
)
19 printf("GetTextExtentPoint32A\n");
23 HFONT WINAPI
IMPL_CreateFontIndirectW(CONST LOGFONTW
*lplf
)
25 printf("CreateFontIndirectW\n");
29 HFONT (WINAPI
* ORIG_CreateFontIndirectW
)(CONST LOGFONTW
*lplf
);
31 BOOL (WINAPI
* ORIG_MessageBeepHook
)(__in UINT
);
32 BOOL (WINAPI
* ORIG_GetTextExtentPoint32W
)(HDC hdc
, LPCWSTR lpString
, int cbString
, LPSIZE lpSize
);
33 BOOL (WINAPI
* ORIG_GetTextExtentPoint32A
)(HDC hdc
, LPCSTR lpString
, int cbString
, LPSIZE lpSize
);
35 #define FORCE(expr) {if(!SUCCEEDED(NtStatus = (expr))) goto ERROR_ABORT;}
37 extern "C" int main(int argc
, wchar_t* argv
[])
39 TRACED_HOOK_HANDLE hHook
= new HOOK_TRACE_INFO();
41 ULONG ACLEntries
[1] = {0};
42 UNICODE_STRING
* NameBuffer
= NULL
;
44 ORIG_CreateFontIndirectW
= CreateFontIndirectW
;
47 ORIG_CreateFontIndirectW
,
48 IMPL_CreateFontIndirectW
,
51 FORCE(LhSetInclusiveACL(ACLEntries
, 1, hHook
));
53 CreateFontIndirectW(0);
54 CreateFontW(10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L
"system");
56 CreateFontIndirectA(&lf
);
57 CreateFontA(12, 0, 0, 0, 400, 0, 0, 0, 2, 0, 0, 0, 0, "MARLETT");
60 ORIG_GetTextExtentPoint32A
= GetTextExtentPoint32A
;
62 ORIG_GetTextExtentPoint32A
,
63 IMPL_GetTextExtentPoint32A
,
66 HDC hdc
= GetDC(NULL
);
68 FORCE(LhSetInclusiveACL(ACLEntries
, 1, hHook
));
69 GetTextExtentPoint32W(hdc
, L
"abc", 3, &size
);
70 GetTextExtentPointW(hdc
, L
"abc", 3, &size
);
71 GetTextExtentPoint32A(hdc
, "abc", 3, &size
);
72 GetTextExtentPointA(hdc
, "abc", 3, &size
);
76 ORIG_MessageBeepHook
= MessageBeep
;
78 The following shows how to install and remove local hooks...
87 // won't invoke the hook handler because hooks are inactive after installation
92 FORCE(LhIsThreadIntercepted(hHook
, 0, &flags
));
93 printf("Intercepted %d\n", flags
);
94 // activate the hook for the current thread
95 FORCE(LhSetInclusiveACL(ACLEntries
, 1, hHook
));
96 FORCE(LhIsThreadIntercepted(hHook
, 0, &flags
));
97 printf("Intercepted %d\n", flags
);
100 // will be redirected into the handler...
104 FORCE(LhSetGlobalExclusiveACL(ACLEntries
, 1));
106 // will be redirected into the handler...
110 FORCE(LhSetGlobalInclusiveACL(ACLEntries
, 1));
112 // will be redirected into the handler...
117 // won't invoke the hook handler because hooks are inactive after installation
118 ORIG_MessageBeepHook(123);
121 // this will also invalidate "hHook", because it is a traced handle...
122 LhUninstallAllHooks();
123 // this will do nothing because the hook is already removed...
124 LhUninstallHook(hHook
);
127 // will be redirected into the handler...
131 // now we can safely release the traced handle
136 // even if the hook is removed, we need to wait for memory release
137 LhWaitForPendingRemovals();
146 if(NameBuffer
!= NULL
)
149 printf("\n[Error(0x%p)]: \"%S\" (code: %d {0x%p})\n", (PVOID
)NtStatus
, RtlGetLastErrorString(), RtlGetLastError(), (PVOID
)RtlGetLastError());