Chromium Code Reviews| 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 void SetHook(HHOOK handle) { | |
| 27 hook = handle; | |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 bool WasHookCalled() { | |
| 32 return hook_called; | |
| 33 } | |
| 34 | |
| 35 LRESULT HookProc(int code, WPARAM wParam, LPARAM lParam) { | |
| 36 hook_called = true; | |
| 37 // Recent versions of Windows do not require the HHOOK to be passed along, | |
| 38 // but I'm doing it here to show the shared use of the HHOOK variable in | |
| 39 // the shared data segment. It is set by the instance of the DLL in the | |
| 40 // test process. | |
| 41 return CallNextHookEx(hook, code, wParam, lParam); | |
| 42 } | |
| 43 | |
| 44 BOOL WINAPI DllMain(__in HINSTANCE hinstDLL, | |
| 45 __in DWORD reason, | |
| 46 __in LPVOID lpvReserved) { | |
|
robertshield
2016/04/14 03:57:29
nit: don't need the __in annotations, naming conve
penny
2016/04/24 18:50:49
Done.
| |
| 47 return TRUE; | |
| 48 } | |
| OLD | NEW |