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

Side by Side Diff: sandbox/win/sandbox_poc/pocdll/registry.cc

Issue 543153002: More compiler whack-a-mole. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "sandbox/win/sandbox_poc/pocdll/exports.h" 5 #include "sandbox/win/sandbox_poc/pocdll/exports.h"
6 #include "sandbox/win/sandbox_poc/pocdll/utils.h" 6 #include "sandbox/win/sandbox_poc/pocdll/utils.h"
7 7
8 // This file contains the tests used to verify the security of the registry. 8 // This file contains the tests used to verify the security of the registry.
9 9
10 // Converts an HKEY to a string. This is using the lazy way and works only
11 // for the main hives.
12 // "key" is the hive to convert to string.
13 // The return value is the string corresponding to the hive or "unknown"
14 const wchar_t *HKEYToString(const HKEY key) {
15 switch (reinterpret_cast<LONG_PTR>(key)) {
16 case reinterpret_cast<LONG_PTR>(HKEY_CLASSES_ROOT):
17 return L"HKEY_CLASSES_ROOT";
18 case reinterpret_cast<LONG_PTR>(HKEY_CURRENT_CONFIG):
19 return L"HKEY_CURRENT_CONFIG";
20 case reinterpret_cast<LONG_PTR>(HKEY_CURRENT_USER):
21 return L"HKEY_CURRENT_USER";
22 case reinterpret_cast<LONG_PTR>(HKEY_LOCAL_MACHINE):
23 return L"HKEY_LOCAL_MACHINE";
24 case reinterpret_cast<LONG_PTR>(HKEY_USERS):
25 return L"HKEY_USERS";
26 }
27 return L"unknown";
28 }
29
30 // Tries to open the key hive\path and outputs the result. 10 // Tries to open the key hive\path and outputs the result.
31 // "output" is the stream used for logging. 11 // "output" is the stream used for logging.
32 void TryOpenKey(const HKEY hive, const wchar_t *path, FILE *output) { 12 void TryOpenKey(const HKEY hive,
13 const wchar_t* hive_name,
14 const wchar_t* path,
15 FILE* output) {
33 HKEY key; 16 HKEY key;
34 LONG err_code = ::RegOpenKeyEx(hive, 17 LONG err_code = ::RegOpenKeyEx(hive,
35 path, 18 path,
36 0, // Reserved, must be 0. 19 0, // Reserved, must be 0.
37 MAXIMUM_ALLOWED, 20 MAXIMUM_ALLOWED,
38 &key); 21 &key);
39 if (ERROR_SUCCESS == err_code) { 22 if (ERROR_SUCCESS == err_code) {
40 fprintf(output, "[GRANTED] Opening key \"%S\\%S\". Handle 0x%p\r\n", 23 fprintf(output,
41 HKEYToString(hive), 24 "[GRANTED] Opening key \"%S\\%S\". Handle 0x%p\r\n",
25 hive_name,
42 path, 26 path,
43 key); 27 key);
44 ::RegCloseKey(key); 28 ::RegCloseKey(key);
45 } else { 29 } else {
46 fprintf(output, "[BLOCKED] Opening key \"%S\\%S\". Error %ld\r\n", 30 fprintf(output,
47 HKEYToString(hive), 31 "[BLOCKED] Opening key \"%S\\%S\". Error %ld\r\n",
32 hive_name,
48 path, 33 path,
49 err_code); 34 err_code);
50 } 35 }
51 } 36 }
52 37
53 void POCDLL_API TestRegistry(HANDLE log) { 38 void POCDLL_API TestRegistry(HANDLE log) {
54 HandleToFile handle2file; 39 HandleToFile handle2file;
55 FILE *output = handle2file.Translate(log, "w"); 40 FILE *output = handle2file.Translate(log, "w");
56 41
57 TryOpenKey(HKEY_LOCAL_MACHINE, NULL, output); 42 TryOpenKey(HKEY_LOCAL_MACHINE, L"HKEY_LOCAL_MACHINE", NULL, output);
58 TryOpenKey(HKEY_CURRENT_USER, NULL, output); 43 TryOpenKey(HKEY_CURRENT_USER, L"HKEY_CURRENT_USER", NULL, output);
59 TryOpenKey(HKEY_USERS, NULL, output); 44 TryOpenKey(HKEY_USERS, L"HKEY_USERS", NULL, output);
60 TryOpenKey(HKEY_LOCAL_MACHINE, 45 TryOpenKey(HKEY_LOCAL_MACHINE,
46 L"HKEY_LOCAL_MACHINE",
61 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon", 47 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon",
62 output); 48 output);
63 } 49 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698