Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: sandbox/win/tests/integration_tests/hooking_dll.cc

Issue 1835003003: [Windows Sandbox] MITIGATION_EXTENSION_POINT_DISABLE support for children. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review fixes, part 3 (robertshield). Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 ::SetEvent(event);
44
45 // Recent versions of Windows do not require the HHOOK to be passed along,
46 // but I'm doing it here to show the shared use of the HHOOK variable in
47 // the shared data segment. It is set by the instance of the DLL in the
48 // main test process.
49 return CallNextHookEx(hook, code, w_param, l_param);
50 }
51
52 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
53 if (reason == DLL_PROCESS_ATTACH) {
54 // The testing process should have set up this named event already.
55 event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, g_hook_event);
56 if (event == NULL || event == INVALID_HANDLE_VALUE)
57 return false;
58 }
59
60 if (reason == DLL_PROCESS_DETACH)
61 ::CloseHandle(event);
62
63 return TRUE;
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698