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

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

Issue 2944493002: [Windows Sandbox Tests] Process Mitigations. (Closed)
Patch Set: Created 3 years, 6 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 <windows.h>
6
5 #include "integration_tests_common.h" 7 #include "integration_tests_common.h"
6 8
7 #include <windows.h>
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 // The parent process should have set up this named event already. 36 // The parent process should have set up this named event already.
37 HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, g_winproc_event); 37 HANDLE event =
38 ::OpenEventW(EVENT_MODIFY_STATE, FALSE, sandbox::g_winproc_event);
38 if (event == NULL || event == INVALID_HANDLE_VALUE) 39 if (event == NULL || event == INVALID_HANDLE_VALUE)
39 return 1; 40 return 1;
40 41
41 // Step 1: Registering the Window Class. 42 // Step 1: Registering the Window Class.
42 WNDCLASSEX window_class; 43 WNDCLASSEX window_class;
43 window_class.cbSize = sizeof(WNDCLASSEX); 44 window_class.cbSize = sizeof(WNDCLASSEX);
44 window_class.style = 0; 45 window_class.style = 0;
45 window_class.lpfnWndProc = WndProc; 46 window_class.lpfnWndProc = WndProc;
46 window_class.cbClsExtra = 0; 47 window_class.cbClsExtra = 0;
47 window_class.cbWndExtra = 0; 48 window_class.cbWndExtra = 0;
48 window_class.hInstance = instance; 49 window_class.hInstance = instance;
49 window_class.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); 50 window_class.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
50 window_class.hCursor = ::LoadCursor(NULL, IDC_ARROW); 51 window_class.hCursor = ::LoadCursor(NULL, IDC_ARROW);
51 window_class.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOWFRAME); 52 window_class.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOWFRAME);
52 window_class.lpszMenuName = NULL; 53 window_class.lpszMenuName = NULL;
53 window_class.lpszClassName = g_winproc_class_name; 54 window_class.lpszClassName = sandbox::g_winproc_class_name;
54 window_class.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION); 55 window_class.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION);
55 56
56 if (!::RegisterClassEx(&window_class)) 57 if (!::RegisterClassEx(&window_class))
57 return 1; 58 return 1;
58 59
59 // Step 2: Create the Window. 60 // Step 2: Create the Window.
60 HWND window = ::CreateWindowExW(WS_EX_CLIENTEDGE, g_winproc_class_name, 61 HWND window = ::CreateWindowExW(
61 g_winproc_window_name, WS_OVERLAPPEDWINDOW, 62 WS_EX_CLIENTEDGE, sandbox::g_winproc_class_name,
62 CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, 63 sandbox::g_winproc_window_name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
63 NULL, instance, NULL); 64 CW_USEDEFAULT, 240, 120, NULL, NULL, instance, NULL);
64 65
65 if (window == NULL) 66 if (window == NULL)
66 return 1; 67 return 1;
67 68
68 ::ShowWindow(window, cmd_show); 69 ::ShowWindow(window, cmd_show);
69 ::UpdateWindow(window); 70 ::UpdateWindow(window);
70 71
71 // Step 3: Signal that WinProc is up and running. 72 // Step 3: Signal that WinProc is up and running.
72 ::SetEvent(event); 73 ::SetEvent(event);
73 74
74 // Step 4: The Message Loop 75 // Step 4: The Message Loop
75 // WM_QUIT results in a 0 value from GetMessageW, 76 // WM_QUIT results in a 0 value from GetMessageW,
76 // breaking the loop. 77 // breaking the loop.
77 MSG message; 78 MSG message;
78 while (::GetMessageW(&message, NULL, 0, 0) > 0) { 79 while (::GetMessageW(&message, NULL, 0, 0) > 0) {
79 ::TranslateMessage(&message); 80 ::TranslateMessage(&message);
80 ::DispatchMessageW(&message); 81 ::DispatchMessageW(&message);
81 } 82 }
82 83
83 ::SetEvent(event); 84 ::SetEvent(event);
84 ::CloseHandle(event); 85 ::CloseHandle(event);
85 86
86 return message.wParam; 87 return message.wParam;
87 } 88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698