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
3 // found in the LICENSE file.
7 #include "base/strings/string16.h"
8 #include "sandbox/win/sandbox_poc/pocdll/exports.h"
9 #include "sandbox/win/sandbox_poc/pocdll/utils.h"
11 // This file contains the tests used to verify the security of the system by
12 // using some spying techniques.
14 void POCDLL_API
TestSpyKeys(HANDLE log
) {
15 HandleToFile handle2file
;
16 FILE *output
= handle2file
.Translate(log
, "w");
18 if (RegisterHotKey(NULL
, 1, 0, 0x42)) {
19 fprintf(output
, "[GRANTED] successfully registered hotkey\r\n");
20 UnregisterHotKey(NULL
, 1);
22 fprintf(output
, "[BLOCKED] Failed to register hotkey. Error = %ld\r\n",
26 fprintf(output
, "[INFO] Logging keystrokes for 15 seconds\r\n");
28 base::string16 logged
;
29 DWORD tick
= ::GetTickCount() + 15000;
30 while (tick
> ::GetTickCount()) {
31 for (int i
= 0; i
< 256; ++i
) {
32 if (::GetAsyncKeyState(i
) & 1) {
33 if (i
>= VK_SPACE
&& i
<= 0x5A /*VK_Z*/) {
34 logged
.append(1, static_cast<wchar_t>(i
));
36 logged
.append(1, '?');
43 fprintf(output
, "[GRANTED] Spyed keystrokes \"%S\"\r\n",
46 fprintf(output
, "[BLOCKED] Spyed keystrokes \"(null)\"\r\n");
50 void POCDLL_API
TestSpyScreen(HANDLE log
) {
51 HandleToFile handle2file
;
52 FILE *output
= handle2file
.Translate(log
, "w");
54 HDC screen_dc
= ::GetDC(NULL
);
55 COLORREF pixel_color
= ::GetPixel(screen_dc
, 0, 0);
57 for (int x
= 0; x
< 10; ++x
) {
58 for (int y
= 0; y
< 10; ++y
) {
59 if (::GetPixel(screen_dc
, x
, y
) != pixel_color
) {
60 fprintf(output
, "[GRANTED] Read pixel on screen\r\n");
66 fprintf(output
, "[BLOCKED] Read pixel on screen. Error = %ld\r\n",