OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <string> | 5 #include <string> |
6 #include "sandbox/win/sandbox_poc/pocdll/exports.h" | 6 #include "sandbox/win/sandbox_poc/pocdll/exports.h" |
7 #include "sandbox/win/sandbox_poc/pocdll/utils.h" | 7 #include "sandbox/win/sandbox_poc/pocdll/utils.h" |
8 | 8 |
9 // This file contains the tests used to verify the security of the system by | 9 // This file contains the tests used to verify the security of the system by |
10 // using some spying techniques. | 10 // using some spying techniques. |
11 | 11 |
12 void POCDLL_API TestSpyKeys(HANDLE log) { | 12 void POCDLL_API TestSpyKeys(HANDLE log) { |
13 HandleToFile handle2file; | 13 HandleToFile handle2file; |
14 FILE *output = handle2file.Translate(log, "w"); | 14 FILE *output = handle2file.Translate(log, "w"); |
15 | 15 |
16 if (RegisterHotKey(NULL, 1, 0, 0x42)) { | 16 if (RegisterHotKey(NULL, 1, 0, 0x42)) { |
17 fprintf(output, "[GRANTED] successfully registered hotkey\r\n"); | 17 fprintf(output, "[GRANTED] successfully registered hotkey\r\n"); |
18 UnregisterHotKey(NULL, 1); | 18 UnregisterHotKey(NULL, 1); |
19 } else { | 19 } else { |
20 fprintf(output, "[BLOCKED] Failed to register hotkey. Error = %d\r\n", | 20 fprintf(output, "[BLOCKED] Failed to register hotkey. Error = %d\r\n", |
21 ::GetLastError()); | 21 ::GetLastError()); |
22 } | 22 } |
23 | 23 |
24 fprintf(output, "[INFO] Logging keystrokes for 15 seconds\r\n"); | 24 fprintf(output, "[INFO] Logging keystrokes for 15 seconds\r\n"); |
25 fflush(output); | 25 fflush(output); |
26 std::wstring logged; | 26 base::string16 logged; |
27 DWORD tick = ::GetTickCount() + 15000; | 27 DWORD tick = ::GetTickCount() + 15000; |
28 while (tick > ::GetTickCount()) { | 28 while (tick > ::GetTickCount()) { |
29 for (int i = 0; i < 256; ++i) { | 29 for (int i = 0; i < 256; ++i) { |
30 if (::GetAsyncKeyState(i) & 1) { | 30 if (::GetAsyncKeyState(i) & 1) { |
31 if (i >= VK_SPACE && i <= 0x5A /*VK_Z*/) { | 31 if (i >= VK_SPACE && i <= 0x5A /*VK_Z*/) { |
32 logged.append(1, static_cast<wchar_t>(i)); | 32 logged.append(1, static_cast<wchar_t>(i)); |
33 } else { | 33 } else { |
34 logged.append(1, '?'); | 34 logged.append(1, '?'); |
35 } | 35 } |
36 } | 36 } |
(...skipping 20 matching lines...) Expand all Loading... |
57 if (::GetPixel(screen_dc, x, y) != pixel_color) { | 57 if (::GetPixel(screen_dc, x, y) != pixel_color) { |
58 fprintf(output, "[GRANTED] Read pixel on screen\r\n"); | 58 fprintf(output, "[GRANTED] Read pixel on screen\r\n"); |
59 return; | 59 return; |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 fprintf(output, "[BLOCKED] Read pixel on screen. Error = %d\r\n", | 64 fprintf(output, "[BLOCKED] Read pixel on screen. Error = %d\r\n", |
65 ::GetLastError()); | 65 ::GetLastError()); |
66 } | 66 } |
OLD | NEW |