55#include " HookDll.h"
66
77
8- void DoHook ()
8+ TRACED_HOOK_HANDLE hHookZwSetInformationFile = new HOOK_TRACE_INFO();
9+ ULONG HookZwSetInformationFile_ACLEntries[1 ] = { 0 };
10+ ptrZwSetInformationFile realZwSetInformationFile = NULL ;
11+
12+
13+ void Prepare ()
914{
15+ hWriteMailslot = CreateFile (TEXT (" \\\\ *\\ mailslot\\ APIHOOK\\ Monitor\\ Log" ),
16+ GENERIC_WRITE,
17+ FILE_SHARE_READ,
18+ NULL ,
19+ OPEN_EXISTING,
20+ FILE_ATTRIBUTE_NORMAL,
21+ NULL );
22+ if (INVALID_HANDLE_VALUE == hWriteMailslot)
23+ {
24+ OutputDebugString (TEXT (" Create Mailslot ERROR\n " ));
25+ return ;
26+ }
27+
28+ realZwSetInformationFile = (ptrZwSetInformationFile)GetRealApiEntry (L" ntdll.dll" , " ZwSetInformationFile" );
29+ }
1030
31+
32+ void DoHook ()
33+ {
34+ NTSTATUS status = 0 ;
35+ // hook MyZwSetInformationFile
36+ status = LhInstallHook (
37+ realZwSetInformationFile,
38+ MyZwSetInformationFile,
39+ NULL ,
40+ hHookZwSetInformationFile);
41+ if (!SUCCEEDED (status))
42+ {
43+ OutputDebugString (L" LhInstallHook ERROR\n " );
44+ }
45+ status = LhSetExclusiveACL (
46+ HookZwSetInformationFile_ACLEntries,
47+ 1 ,
48+ hHookZwSetInformationFile);
49+ if (!SUCCEEDED (status))
50+ {
51+ OutputDebugString (L" LhSetExclusiveACL ERROR\n " );
52+ }
1153}
1254
1355
1456void DoUnHook ()
1557{
58+ // LhUninstallAllHooks();
59+ // OutputDebugString(L"LhUninstallAllHooks\n");
60+
61+ NTSTATUS status = 0 ;
62+ status = LhUninstallHook (hHookZwSetInformationFile);
63+ if (!SUCCEEDED (status))
64+ {
65+ OutputDebugString (L" LhUninstallHook ERROR\n " );
66+ }
67+ delete hHookZwSetInformationFile;
68+ hHookZwSetInformationFile = NULL ;
69+ status = LhWaitForPendingRemovals ();
70+ if (!SUCCEEDED (status))
71+ {
72+ OutputDebugString (L" LhWaitForPendingRemovals ERROR\n " );
73+ }
74+ }
1675
17- }
76+
77+ void Finish ()
78+ {
79+ CloseHandle (hWriteMailslot);
80+ hWriteMailslot = NULL ;
81+
82+ }
83+
84+
85+ FARPROC GetRealApiEntry (LPCWSTR lpModuleName, LPCSTR lpProcName)
86+ {
87+ HMODULE hModule = NULL ;
88+ FARPROC realProc = NULL ;
89+ OutputDebugString (L" PrepareRealApiEntry()\n " );
90+
91+ hModule = GetModuleHandleW (lpModuleName);
92+ if (NULL == hModule)
93+ {
94+ OutputDebugString (L" GetModuleHandleW ERROR\n " );
95+ }
96+ realProc = GetProcAddress (hModule, lpProcName);
97+ if (NULL == realProc)
98+ {
99+ OutputDebugString (L" GetProcAddress ERROR\n " );
100+ }
101+ return realProc;
102+ // CloseHandle(hModule);
103+ }
0 commit comments