handle_enumerator_win.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/handle_enumerator_win.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
1258e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch#include "base/process/process.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/windows_version.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_switches.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/result_codes.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sandbox/win/src/handle_table.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)typedef std::map<const base::string16, HandleType> HandleTypeMap;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)HandleTypeMap& MakeHandleTypeMap() {
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HandleTypeMap& handle_types = *(new HandleTypeMap());
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeProcess] = ProcessHandle;
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeThread] = ThreadHandle;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeFile] = FileHandle;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeDirectory] = DirectoryHandle;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeKey] = KeyHandle;
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeWindowStation] = WindowStationHandle;
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeDesktop] = DesktopHandle;
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeService] = ServiceHandle;
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeMutex] = MutexHandle;
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeSemaphore] = SemaphoreHandle;
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeEvent] = EventHandle;
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeTimer] = TimerHandle;
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeNamedPipe] = NamedPipeHandle;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeJobObject] = JobHandle;
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeFileMap] = FileMapHandle;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  handle_types[sandbox::HandleTable::kTypeAlpcPort] = AlpcPortHandle;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return handle_types;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxHandleNameLength = 1024;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void HandleEnumerator::EnumerateHandles() {
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  sandbox::HandleTable handles;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string process_type =
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          switches::kProcessType);
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 output = ASCIIToUTF16(process_type);
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  output.append(ASCIIToUTF16(" process - Handles at shutdown:\n"));
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (sandbox::HandleTable::Iterator sys_handle
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      = handles.HandlesForProcess(::GetCurrentProcessId());
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      sys_handle != handles.end(); ++sys_handle) {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HandleType current_type = StringToHandleType(sys_handle->Type());
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!all_handles_ && (current_type != ProcessHandle &&
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          current_type != FileHandle &&
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          current_type != DirectoryHandle &&
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          current_type != KeyHandle &&
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          current_type != WindowStationHandle &&
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          current_type != DesktopHandle &&
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          current_type != ServiceHandle))
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      continue;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output += ASCIIToUTF16("[");
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output += sys_handle->Type();
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output += ASCIIToUTF16("] (");
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output += sys_handle->Name();
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output += ASCIIToUTF16(")\n");
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output += GetAccessString(current_type,
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        sys_handle->handle_entry()->GrantedAccess);
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DVLOG(0) << output;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)HandleType StringToHandleType(const base::string16& type) {
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static HandleTypeMap handle_types = MakeHandleTypeMap();
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HandleTypeMap::iterator result = handle_types.find(type);
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return result != handle_types.end() ? result->second : OtherHandle;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
87a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 GetAccessString(HandleType handle_type,
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           ACCESS_MASK access) {
89a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 output;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & GENERIC_READ)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tGENERIC_READ\n"));
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & GENERIC_WRITE)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tGENERIC_WRITE\n"));
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & GENERIC_EXECUTE)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tGENERIC_EXECUTE\n"));
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & GENERIC_ALL)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tGENERIC_ALL\n"));
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & DELETE)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tDELETE\n"));
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & READ_CONTROL)
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tREAD_CONTROL\n"));
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & WRITE_DAC)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tWRITE_DAC\n"));
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & WRITE_OWNER)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tWRITE_OWNER\n"));
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (access & SYNCHRONIZE)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    output.append(ASCIIToUTF16("\tSYNCHRONIZE\n"));
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (handle_type) {
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case ProcessHandle:
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_CREATE_PROCESS)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_CREATE_PROCESS\n"));
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_CREATE_THREAD)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_CREATE_THREAD\n"));
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_DUP_HANDLE)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_DUP_HANDLE\n"));
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_QUERY_INFORMATION)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_QUERY_INFORMATION\n"));
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_QUERY_LIMITED_INFORMATION)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_QUERY_LIMITED_INFORMATION\n"));
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_SET_INFORMATION)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_SET_INFORMATION\n"));
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_SET_QUOTA)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_SET_QUOTA\n"));
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_SUSPEND_RESUME)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_SUSPEND_RESUME\n"));
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_TERMINATE)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_TERMINATE\n"));
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_VM_OPERATION)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_VM_OPERATION\n"));
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_VM_READ)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_VM_READ\n"));
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PROCESS_VM_WRITE)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPROCESS_VM_WRITE\n"));
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case ThreadHandle:
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_DIRECT_IMPERSONATION)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_DIRECT_IMPERSONATION\n"));
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_GET_CONTEXT)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_GET_CONTEXT\n"));
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_IMPERSONATE)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_IMPERSONATE\n"));
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_QUERY_INFORMATION )
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_QUERY_INFORMATION\n"));
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_QUERY_LIMITED_INFORMATION)
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_QUERY_LIMITED_INFORMATION\n"));
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_SET_CONTEXT)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_SET_CONTEXT\n"));
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_SET_INFORMATION)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_SET_INFORMATION\n"));
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_SET_LIMITED_INFORMATION)
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_SET_LIMITED_INFORMATION\n"));
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_SET_THREAD_TOKEN)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_SET_THREAD_TOKEN\n"));
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_SUSPEND_RESUME)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_SUSPEND_RESUME\n"));
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & THREAD_TERMINATE)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTHREAD_TERMINATE\n"));
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case FileHandle:
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_APPEND_DATA)
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_APPEND_DATA\n"));
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_EXECUTE)
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_EXECUTE\n"));
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_READ_ATTRIBUTES)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_READ_ATTRIBUTES\n"));
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_READ_DATA)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_READ_DATA\n"));
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_READ_EA)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_READ_EA\n"));
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_WRITE_ATTRIBUTES)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_WRITE_ATTRIBUTES\n"));
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_WRITE_DATA)
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_WRITE_DATA\n"));
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_WRITE_EA)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_WRITE_EA\n"));
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case DirectoryHandle:
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_ADD_FILE)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_ADD_FILE\n"));
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_ADD_SUBDIRECTORY)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_ADD_SUBDIRECTORY\n"));
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_APPEND_DATA)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_APPEND_DATA\n"));
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_DELETE_CHILD)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_DELETE_CHILD\n"));
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_LIST_DIRECTORY)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_LIST_DIRECTORY\n"));
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_READ_DATA)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_READ_DATA\n"));
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_TRAVERSE)
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_TRAVERSE\n"));
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_WRITE_DATA)
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_WRITE_DATA\n"));
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case KeyHandle:
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_CREATE_LINK)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_CREATE_LINK\n"));
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_CREATE_SUB_KEY)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_CREATE_SUB_KEY\n"));
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_ENUMERATE_SUB_KEYS)
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_ENUMERATE_SUB_KEYS\n"));
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_EXECUTE)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_EXECUTE\n"));
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_NOTIFY)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_NOTIFY\n"));
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_QUERY_VALUE)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_QUERY_VALUE\n"));
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_READ)
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_READ\n"));
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_SET_VALUE)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_SET_VALUE\n"));
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_WOW64_32KEY)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_WOW64_32KEY\n"));
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & KEY_WOW64_64KEY)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tKEY_WOW64_64KEY\n"));
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case WindowStationHandle:
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_ACCESSCLIPBOARD)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_ACCESSCLIPBOARD\n"));
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_ACCESSGLOBALATOMS)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_ACCESSGLOBALATOMS\n"));
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_CREATEDESKTOP)
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_CREATEDESKTOP\n"));
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_ENUMDESKTOPS)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_ENUMDESKTOPS\n"));
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_ENUMERATE)
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_ENUMERATE\n"));
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_EXITWINDOWS)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_EXITWINDOWS\n"));
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_READATTRIBUTES)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_READATTRIBUTES\n"));
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_READSCREEN)
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_READSCREEN\n"));
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & WINSTA_WRITEATTRIBUTES)
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tWINSTA_WRITEATTRIBUTES\n"));
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case DesktopHandle:
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_CREATEMENU)
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_CREATEMENU\n"));
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_CREATEWINDOW)
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_CREATEWINDOW\n"));
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_ENUMERATE)
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_ENUMERATE\n"));
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_HOOKCONTROL)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_HOOKCONTROL\n"));
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_JOURNALPLAYBACK)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_JOURNALPLAYBACK\n"));
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_JOURNALRECORD)
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_JOURNALRECORD\n"));
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_READOBJECTS)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_READOBJECTS\n"));
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_SWITCHDESKTOP)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_SWITCHDESKTOP\n"));
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & DESKTOP_WRITEOBJECTS)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tDESKTOP_WRITEOBJECTS\n"));
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case ServiceHandle:
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & SC_MANAGER_CREATE_SERVICE)
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tSC_MANAGER_CREATE_SERVICE\n"));
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & SC_MANAGER_CONNECT)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tSC_MANAGER_CONNECT\n"));
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & SC_MANAGER_ENUMERATE_SERVICE )
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tSC_MANAGER_ENUMERATE_SERVICE\n"));
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & SC_MANAGER_LOCK)
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tSC_MANAGER_LOCK\n"));
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & SC_MANAGER_MODIFY_BOOT_CONFIG )
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tSC_MANAGER_MODIFY_BOOT_CONFIG\n"));
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & SC_MANAGER_QUERY_LOCK_STATUS )
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tSC_MANAGER_QUERY_LOCK_STATUS\n"));
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case EventHandle:
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & EVENT_MODIFY_STATE)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tEVENT_MODIFY_STATE\n"));
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case MutexHandle:
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & MUTEX_MODIFY_STATE)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tMUTEX_MODIFY_STATE\n"));
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case SemaphoreHandle:
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & SEMAPHORE_MODIFY_STATE)
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tSEMAPHORE_MODIFY_STATE\n"));
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case TimerHandle:
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & TIMER_MODIFY_STATE)
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTIMER_MODIFY_STATE\n"));
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & TIMER_QUERY_STATE)
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tTIMER_QUERY_STATE\n"));
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case NamedPipeHandle:
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PIPE_ACCESS_INBOUND)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPIPE_ACCESS_INBOUND\n"));
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & PIPE_ACCESS_OUTBOUND)
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tPIPE_ACCESS_OUTBOUND\n"));
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case JobHandle:
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & JOB_OBJECT_ASSIGN_PROCESS)
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tJOB_OBJECT_ASSIGN_PROCESS\n"));
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & JOB_OBJECT_QUERY)
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tJOB_OBJECT_QUERY\n"));
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & JOB_OBJECT_SET_ATTRIBUTES)
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tJOB_OBJECT_SET_ATTRIBUTES\n"));
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & JOB_OBJECT_SET_SECURITY_ATTRIBUTES)
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tJOB_OBJECT_SET_SECURITY_ATTRIBUTES\n"));
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & JOB_OBJECT_TERMINATE)
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tJOB_OBJECT_TERMINATE\n"));
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case FileMapHandle:
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_MAP_EXECUTE)
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_MAP_EXECUTE\n"));
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_MAP_READ)
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_MAP_READ\n"));
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (access & FILE_MAP_WRITE)
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        output.append(ASCIIToUTF16("\tFILE_MAP_WRITE\n"));
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return output;
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
321