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