security/sandbox/win/src/handle_table.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef SANDBOX_SRC_HANDLE_TABLE_H_
michael@0 6 #define SANDBOX_SRC_HANDLE_TABLE_H_
michael@0 7
michael@0 8 #include <windows.h>
michael@0 9 #include <vector>
michael@0 10
michael@0 11 #include "base/basictypes.h"
michael@0 12 #include "base/strings/string16.h"
michael@0 13 #include "sandbox/win/src/nt_internals.h"
michael@0 14
michael@0 15 namespace sandbox {
michael@0 16
michael@0 17 // HandleTable retrieves the global handle table and provides helper classes
michael@0 18 // for iterating through the table and retrieving handle info.
michael@0 19 class HandleTable {
michael@0 20 public:
michael@0 21 static const char16* HandleTable::kTypeProcess;
michael@0 22 static const char16* HandleTable::kTypeThread;
michael@0 23 static const char16* HandleTable::kTypeFile;
michael@0 24 static const char16* HandleTable::kTypeDirectory;
michael@0 25 static const char16* HandleTable::kTypeKey;
michael@0 26 static const char16* HandleTable::kTypeWindowStation;
michael@0 27 static const char16* HandleTable::kTypeDesktop;
michael@0 28 static const char16* HandleTable::kTypeService;
michael@0 29 static const char16* HandleTable::kTypeMutex;
michael@0 30 static const char16* HandleTable::kTypeSemaphore;
michael@0 31 static const char16* HandleTable::kTypeEvent;
michael@0 32 static const char16* HandleTable::kTypeTimer;
michael@0 33 static const char16* HandleTable::kTypeNamedPipe;
michael@0 34 static const char16* HandleTable::kTypeJobObject;
michael@0 35 static const char16* HandleTable::kTypeFileMap;
michael@0 36 static const char16* HandleTable::kTypeAlpcPort;
michael@0 37
michael@0 38 class Iterator;
michael@0 39
michael@0 40 // Used by the iterator to provide simple caching accessors to handle data.
michael@0 41 class HandleEntry {
michael@0 42 public:
michael@0 43 bool operator==(const HandleEntry& rhs) const {
michael@0 44 return handle_entry_ == rhs.handle_entry_;
michael@0 45 }
michael@0 46
michael@0 47 bool operator!=(const HandleEntry& rhs) const {
michael@0 48 return handle_entry_ != rhs.handle_entry_;
michael@0 49 }
michael@0 50
michael@0 51 const SYSTEM_HANDLE_INFORMATION* handle_entry() const {
michael@0 52 return handle_entry_;
michael@0 53 }
michael@0 54
michael@0 55 const OBJECT_TYPE_INFORMATION* TypeInfo();
michael@0 56
michael@0 57 const string16& Name();
michael@0 58
michael@0 59 const string16& Type();
michael@0 60
michael@0 61 bool IsType(const string16& type_string);
michael@0 62
michael@0 63 private:
michael@0 64 friend class Iterator;
michael@0 65 friend class HandleTable;
michael@0 66
michael@0 67 enum UpdateType {
michael@0 68 UPDATE_INFO_ONLY,
michael@0 69 UPDATE_INFO_AND_NAME,
michael@0 70 UPDATE_INFO_AND_TYPE_NAME,
michael@0 71 };
michael@0 72
michael@0 73 explicit HandleEntry(const SYSTEM_HANDLE_INFORMATION* handle_info_entry);
michael@0 74
michael@0 75 bool needs_info_update() { return handle_entry_ != last_entry_; }
michael@0 76
michael@0 77 void UpdateInfo(UpdateType flag);
michael@0 78
michael@0 79 OBJECT_TYPE_INFORMATION* type_info_internal() {
michael@0 80 return reinterpret_cast<OBJECT_TYPE_INFORMATION*>(
michael@0 81 &(type_info_buffer_[0]));
michael@0 82 }
michael@0 83
michael@0 84 const SYSTEM_HANDLE_INFORMATION* handle_entry_;
michael@0 85 const SYSTEM_HANDLE_INFORMATION* last_entry_;
michael@0 86 std::vector<BYTE> type_info_buffer_;
michael@0 87 string16 handle_name_;
michael@0 88 string16 type_name_;
michael@0 89
michael@0 90 DISALLOW_COPY_AND_ASSIGN(HandleEntry);
michael@0 91 };
michael@0 92
michael@0 93 class Iterator {
michael@0 94 public:
michael@0 95 Iterator(const HandleTable& table, const SYSTEM_HANDLE_INFORMATION* start,
michael@0 96 const SYSTEM_HANDLE_INFORMATION* stop);
michael@0 97
michael@0 98 Iterator(const Iterator& it);
michael@0 99
michael@0 100 Iterator& operator++() {
michael@0 101 if (++(current_.handle_entry_) == end_)
michael@0 102 current_.handle_entry_ = table_.end();
michael@0 103 return *this;
michael@0 104 }
michael@0 105
michael@0 106 bool operator==(const Iterator& rhs) const {
michael@0 107 return current_ == rhs.current_;
michael@0 108 }
michael@0 109
michael@0 110 bool operator!=(const Iterator& rhs) const {
michael@0 111 return current_ != rhs.current_;
michael@0 112 }
michael@0 113
michael@0 114 HandleEntry& operator*() { return current_; }
michael@0 115
michael@0 116 operator const SYSTEM_HANDLE_INFORMATION*() {
michael@0 117 return current_.handle_entry_;
michael@0 118 }
michael@0 119
michael@0 120 HandleEntry* operator->() { return &current_; }
michael@0 121
michael@0 122 private:
michael@0 123 const HandleTable& table_;
michael@0 124 HandleEntry current_;
michael@0 125 const SYSTEM_HANDLE_INFORMATION* end_;
michael@0 126 };
michael@0 127
michael@0 128 HandleTable();
michael@0 129
michael@0 130 Iterator begin() const {
michael@0 131 return Iterator(*this, handle_info()->Information,
michael@0 132 &handle_info()->Information[handle_info()->NumberOfHandles]);
michael@0 133 }
michael@0 134
michael@0 135 const SYSTEM_HANDLE_INFORMATION_EX* handle_info() const {
michael@0 136 return reinterpret_cast<const SYSTEM_HANDLE_INFORMATION_EX*>(
michael@0 137 &(handle_info_buffer_[0]));
michael@0 138 }
michael@0 139
michael@0 140 // Returns an iterator to the handles for only the supplied process ID.
michael@0 141 Iterator HandlesForProcess(ULONG process_id) const;
michael@0 142 const SYSTEM_HANDLE_INFORMATION* end() const {
michael@0 143 return &handle_info()->Information[handle_info()->NumberOfHandles];
michael@0 144 }
michael@0 145
michael@0 146 private:
michael@0 147 SYSTEM_HANDLE_INFORMATION_EX* handle_info_internal() {
michael@0 148 return reinterpret_cast<SYSTEM_HANDLE_INFORMATION_EX*>(
michael@0 149 &(handle_info_buffer_[0]));
michael@0 150 }
michael@0 151
michael@0 152 std::vector<BYTE> handle_info_buffer_;
michael@0 153
michael@0 154 DISALLOW_COPY_AND_ASSIGN(HandleTable);
michael@0 155 };
michael@0 156
michael@0 157 } // namespace sandbox
michael@0 158
michael@0 159 #endif // SANDBOX_SRC_HANDLE_TABLE_H_

mercurial