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

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

Issue 2944493002: [Windows Sandbox Tests] Process Mitigations. (Closed)
Patch Set: Code review fixes, part 2. Created 3 years, 5 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "integration_tests_common.h" 5 #include <windows.h>
6 6
7 #include <windows.h> 7 #include "hooking_win_proc.h"
8 8
9 LRESULT CALLBACK WndProc(HWND window, 9 LRESULT CALLBACK WndProc(HWND window,
10 UINT message, 10 UINT message,
11 WPARAM w_param, 11 WPARAM w_param,
12 LPARAM l_param) { 12 LPARAM l_param) {
13 // Injected keystroke via PostThreadMessage won't be dispatched to here. 13 // Injected keystroke via PostThreadMessage won't be dispatched to here.
14 // Have to use SendMessage or SendInput to trigger the keyboard hook. 14 // Have to use SendMessage or SendInput to trigger the keyboard hook.
15 switch (message) { 15 switch (message) {
16 case WM_KEYDOWN: 16 case WM_KEYDOWN:
17 break; 17 break;
18 case WM_KEYUP: 18 case WM_KEYUP:
19 break; 19 break;
20 case WM_CLOSE: 20 case WM_CLOSE:
21 ::DestroyWindow(window); 21 ::DestroyWindow(window);
22 break; 22 break;
23 case WM_DESTROY: 23 case WM_DESTROY:
24 ::PostQuitMessage(0); 24 ::PostQuitMessage(0);
25 break; 25 break;
26 default: 26 default:
27 return ::DefWindowProc(window, message, w_param, l_param); 27 return ::DefWindowProc(window, message, w_param, l_param);
28 } 28 }
29 return 0; 29 return 0;
30 } 30 }
31 31
32 int WINAPI WinMain(HINSTANCE instance, 32 int WINAPI WinMain(HINSTANCE instance,
33 HINSTANCE prev_instance, 33 HINSTANCE prev_instance,
34 LPSTR cmd_line, 34 LPSTR cmd_line,
35 int cmd_show) { 35 int cmd_show) {
36 constexpr wchar_t winproc_class_name[] = L"myWindowClass";
37 constexpr wchar_t winproc_window_name[] = L"ChromeMitigationTests";
38
36 // The parent process should have set up this named event already. 39 // The parent process should have set up this named event already.
37 HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, g_winproc_event); 40 HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE,
41 hooking_win_proc::g_winproc_event);
38 if (event == NULL || event == INVALID_HANDLE_VALUE) 42 if (event == NULL || event == INVALID_HANDLE_VALUE)
39 return 1; 43 return 1;
40 44
41 // Step 1: Registering the Window Class. 45 // Step 1: Registering the Window Class.
42 WNDCLASSEX window_class; 46 WNDCLASSEX window_class;
43 window_class.cbSize = sizeof(WNDCLASSEX); 47 window_class.cbSize = sizeof(WNDCLASSEX);
44 window_class.style = 0; 48 window_class.style = 0;
45 window_class.lpfnWndProc = WndProc; 49 window_class.lpfnWndProc = WndProc;
46 window_class.cbClsExtra = 0; 50 window_class.cbClsExtra = 0;
47 window_class.cbWndExtra = 0; 51 window_class.cbWndExtra = 0;
48 window_class.hInstance = instance; 52 window_class.hInstance = instance;
49 window_class.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); 53 window_class.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
50 window_class.hCursor = ::LoadCursor(NULL, IDC_ARROW); 54 window_class.hCursor = ::LoadCursor(NULL, IDC_ARROW);
51 window_class.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOWFRAME); 55 window_class.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOWFRAME);
52 window_class.lpszMenuName = NULL; 56 window_class.lpszMenuName = NULL;
53 window_class.lpszClassName = g_winproc_class_name; 57 window_class.lpszClassName = winproc_class_name;
54 window_class.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION); 58 window_class.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION);
55 59
56 if (!::RegisterClassEx(&window_class)) 60 if (!::RegisterClassEx(&window_class))
57 return 1; 61 return 1;
58 62
59 // Step 2: Create the Window. 63 // Step 2: Create the Window.
60 HWND window = ::CreateWindowExW(WS_EX_CLIENTEDGE, g_winproc_class_name, 64 HWND window =
61 g_winproc_window_name, WS_OVERLAPPEDWINDOW, 65 ::CreateWindowExW(WS_EX_CLIENTEDGE, winproc_class_name,
62 CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, 66 winproc_window_name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
63 NULL, instance, NULL); 67 CW_USEDEFAULT, 240, 120, NULL, NULL, instance, NULL);
64 68
65 if (window == NULL) 69 if (window == NULL)
66 return 1; 70 return 1;
67 71
68 ::ShowWindow(window, cmd_show); 72 ::ShowWindow(window, cmd_show);
69 ::UpdateWindow(window); 73 ::UpdateWindow(window);
70 74
71 // Step 3: Signal that WinProc is up and running. 75 // Step 3: Signal that WinProc is up and running.
72 ::SetEvent(event); 76 ::SetEvent(event);
73 77
74 // Step 4: The Message Loop 78 // Step 4: The Message Loop
75 // WM_QUIT results in a 0 value from GetMessageW, 79 // WM_QUIT results in a 0 value from GetMessageW,
76 // breaking the loop. 80 // breaking the loop.
77 MSG message; 81 MSG message;
78 while (::GetMessageW(&message, NULL, 0, 0) > 0) { 82 while (::GetMessageW(&message, NULL, 0, 0) > 0) {
79 ::TranslateMessage(&message); 83 ::TranslateMessage(&message);
80 ::DispatchMessageW(&message); 84 ::DispatchMessageW(&message);
81 } 85 }
82 86
83 ::SetEvent(event); 87 ::SetEvent(event);
84 ::CloseHandle(event); 88 ::CloseHandle(event);
85 89
86 return message.wParam; 90 return message.wParam;
87 } 91 }
OLDNEW
« no previous file with comments | « sandbox/win/tests/integration_tests/hooking_win_proc.h ('k') | sandbox/win/tests/integration_tests/integration_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698