OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stdio.h> |
| 6 #include <windows.h> |
| 7 |
| 8 #define _DLL_EXPORTING |
| 9 #include "integration_tests_common.h" |
| 10 |
| 11 // This data section creates a common area that is accessible |
| 12 // to all instances of the DLL (in every process). They map to |
| 13 // the same physical memory location. |
| 14 // **Note that each instance of this DLL runs in the context of |
| 15 // the process it's injected into, so things like pointers and |
| 16 // addresses won't work. |
| 17 // **Note that any variables must be initialized to put them in |
| 18 // the specified segment, otherwise they will end up in the |
| 19 // default data segment. |
| 20 #pragma data_seg(".hook") |
| 21 HHOOK hook = NULL; |
| 22 bool hook_called = false; |
| 23 #pragma data_seg() |
| 24 #pragma comment(linker, "/SECTION:.hook,RWS") |
| 25 |
| 26 namespace { |
| 27 |
| 28 HANDLE event = NULL; |
| 29 } |
| 30 |
| 31 void SetHook(HHOOK hook_handle) { |
| 32 hook = hook_handle; |
| 33 |
| 34 return; |
| 35 } |
| 36 |
| 37 bool WasHookCalled() { |
| 38 return hook_called; |
| 39 } |
| 40 |
| 41 LRESULT HookProc(int code, WPARAM w_param, LPARAM l_param) { |
| 42 hook_called = true; |
| 43 if (event) |
| 44 ::SetEvent(event); |
| 45 |
| 46 // Recent versions of Windows do not require the HHOOK to be passed along, |
| 47 // but I'm doing it here to show the shared use of the HHOOK variable in |
| 48 // the shared data segment. It is set by the instance of the DLL in the |
| 49 // main test process. |
| 50 return CallNextHookEx(hook, code, w_param, l_param); |
| 51 } |
| 52 |
| 53 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) { |
| 54 if (reason == DLL_PROCESS_ATTACH) { |
| 55 // The testing process should have set up this named event already |
| 56 // (if the test needs this event to be signaled). |
| 57 event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, g_hook_event); |
| 58 } |
| 59 |
| 60 if (reason == DLL_PROCESS_DETACH) |
| 61 ::CloseHandle(event); |
| 62 |
| 63 return TRUE; |
| 64 } |
OLD | NEW |