OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common/handle_enumerator_win.h" | 5 #include "content/common/handle_enumerator_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/process/process.h" | 12 #include "base/process/process.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "content/public/common/result_codes.h" | 16 #include "content/public/common/result_codes.h" |
17 #include "sandbox/win/src/handle_table.h" | 17 #include "sandbox/win/src/handle_table.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 namespace { | 20 namespace { |
21 | 21 |
22 typedef std::map<const string16, HandleType> HandleTypeMap; | 22 typedef std::map<const base::string16, HandleType> HandleTypeMap; |
23 | 23 |
24 HandleTypeMap& MakeHandleTypeMap() { | 24 HandleTypeMap& MakeHandleTypeMap() { |
25 HandleTypeMap& handle_types = *(new HandleTypeMap()); | 25 HandleTypeMap& handle_types = *(new HandleTypeMap()); |
26 handle_types[sandbox::HandleTable::kTypeProcess] = ProcessHandle; | 26 handle_types[sandbox::HandleTable::kTypeProcess] = ProcessHandle; |
27 handle_types[sandbox::HandleTable::kTypeThread] = ThreadHandle; | 27 handle_types[sandbox::HandleTable::kTypeThread] = ThreadHandle; |
28 handle_types[sandbox::HandleTable::kTypeFile] = FileHandle; | 28 handle_types[sandbox::HandleTable::kTypeFile] = FileHandle; |
29 handle_types[sandbox::HandleTable::kTypeDirectory] = DirectoryHandle; | 29 handle_types[sandbox::HandleTable::kTypeDirectory] = DirectoryHandle; |
30 handle_types[sandbox::HandleTable::kTypeKey] = KeyHandle; | 30 handle_types[sandbox::HandleTable::kTypeKey] = KeyHandle; |
31 handle_types[sandbox::HandleTable::kTypeWindowStation] = WindowStationHandle; | 31 handle_types[sandbox::HandleTable::kTypeWindowStation] = WindowStationHandle; |
32 handle_types[sandbox::HandleTable::kTypeDesktop] = DesktopHandle; | 32 handle_types[sandbox::HandleTable::kTypeDesktop] = DesktopHandle; |
(...skipping 12 matching lines...) Expand all Loading... |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 const size_t kMaxHandleNameLength = 1024; | 48 const size_t kMaxHandleNameLength = 1024; |
49 | 49 |
50 void HandleEnumerator::EnumerateHandles() { | 50 void HandleEnumerator::EnumerateHandles() { |
51 sandbox::HandleTable handles; | 51 sandbox::HandleTable handles; |
52 std::string process_type = | 52 std::string process_type = |
53 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 53 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
54 switches::kProcessType); | 54 switches::kProcessType); |
55 string16 output = ASCIIToUTF16(process_type); | 55 base::string16 output = ASCIIToUTF16(process_type); |
56 output.append(ASCIIToUTF16(" process - Handles at shutdown:\n")); | 56 output.append(ASCIIToUTF16(" process - Handles at shutdown:\n")); |
57 for (sandbox::HandleTable::Iterator sys_handle | 57 for (sandbox::HandleTable::Iterator sys_handle |
58 = handles.HandlesForProcess(::GetCurrentProcessId()); | 58 = handles.HandlesForProcess(::GetCurrentProcessId()); |
59 sys_handle != handles.end(); ++sys_handle) { | 59 sys_handle != handles.end(); ++sys_handle) { |
60 HandleType current_type = StringToHandleType(sys_handle->Type()); | 60 HandleType current_type = StringToHandleType(sys_handle->Type()); |
61 if (!all_handles_ && (current_type != ProcessHandle && | 61 if (!all_handles_ && (current_type != ProcessHandle && |
62 current_type != FileHandle && | 62 current_type != FileHandle && |
63 current_type != DirectoryHandle && | 63 current_type != DirectoryHandle && |
64 current_type != KeyHandle && | 64 current_type != KeyHandle && |
65 current_type != WindowStationHandle && | 65 current_type != WindowStationHandle && |
66 current_type != DesktopHandle && | 66 current_type != DesktopHandle && |
67 current_type != ServiceHandle)) | 67 current_type != ServiceHandle)) |
68 continue; | 68 continue; |
69 | 69 |
70 output += ASCIIToUTF16("["); | 70 output += ASCIIToUTF16("["); |
71 output += sys_handle->Type(); | 71 output += sys_handle->Type(); |
72 output += ASCIIToUTF16("] ("); | 72 output += ASCIIToUTF16("] ("); |
73 output += sys_handle->Name(); | 73 output += sys_handle->Name(); |
74 output += ASCIIToUTF16(")\n"); | 74 output += ASCIIToUTF16(")\n"); |
75 output += GetAccessString(current_type, | 75 output += GetAccessString(current_type, |
76 sys_handle->handle_entry()->GrantedAccess); | 76 sys_handle->handle_entry()->GrantedAccess); |
77 } | 77 } |
78 DVLOG(0) << output; | 78 DVLOG(0) << output; |
79 } | 79 } |
80 | 80 |
81 HandleType StringToHandleType(const string16& type) { | 81 HandleType StringToHandleType(const base::string16& type) { |
82 static HandleTypeMap handle_types = MakeHandleTypeMap(); | 82 static HandleTypeMap handle_types = MakeHandleTypeMap(); |
83 HandleTypeMap::iterator result = handle_types.find(type); | 83 HandleTypeMap::iterator result = handle_types.find(type); |
84 return result != handle_types.end() ? result->second : OtherHandle; | 84 return result != handle_types.end() ? result->second : OtherHandle; |
85 } | 85 } |
86 | 86 |
87 string16 GetAccessString(HandleType handle_type, | 87 base::string16 GetAccessString(HandleType handle_type, |
88 ACCESS_MASK access) { | 88 ACCESS_MASK access) { |
89 string16 output; | 89 base::string16 output; |
90 if (access & GENERIC_READ) | 90 if (access & GENERIC_READ) |
91 output.append(ASCIIToUTF16("\tGENERIC_READ\n")); | 91 output.append(ASCIIToUTF16("\tGENERIC_READ\n")); |
92 if (access & GENERIC_WRITE) | 92 if (access & GENERIC_WRITE) |
93 output.append(ASCIIToUTF16("\tGENERIC_WRITE\n")); | 93 output.append(ASCIIToUTF16("\tGENERIC_WRITE\n")); |
94 if (access & GENERIC_EXECUTE) | 94 if (access & GENERIC_EXECUTE) |
95 output.append(ASCIIToUTF16("\tGENERIC_EXECUTE\n")); | 95 output.append(ASCIIToUTF16("\tGENERIC_EXECUTE\n")); |
96 if (access & GENERIC_ALL) | 96 if (access & GENERIC_ALL) |
97 output.append(ASCIIToUTF16("\tGENERIC_ALL\n")); | 97 output.append(ASCIIToUTF16("\tGENERIC_ALL\n")); |
98 if (access & DELETE) | 98 if (access & DELETE) |
99 output.append(ASCIIToUTF16("\tDELETE\n")); | 99 output.append(ASCIIToUTF16("\tDELETE\n")); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 if (access & FILE_MAP_READ) | 311 if (access & FILE_MAP_READ) |
312 output.append(ASCIIToUTF16("\tFILE_MAP_READ\n")); | 312 output.append(ASCIIToUTF16("\tFILE_MAP_READ\n")); |
313 if (access & FILE_MAP_WRITE) | 313 if (access & FILE_MAP_WRITE) |
314 output.append(ASCIIToUTF16("\tFILE_MAP_WRITE\n")); | 314 output.append(ASCIIToUTF16("\tFILE_MAP_WRITE\n")); |
315 break; | 315 break; |
316 } | 316 } |
317 return output; | 317 return output; |
318 } | 318 } |
319 | 319 |
320 } // namespace content | 320 } // namespace content |
OLD | NEW |