OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_HANDLE_ENUMERATION_WIN_H_ | |
6 #define BASE_HANDLE_ENUMERATION_WIN_H_ | |
7 | |
8 #include <windows.h> | |
9 | |
10 #include "base/base_api.h" | |
11 #include "base/basictypes.h" | |
12 #include "base/process.h" | |
13 #include "base/utf_string_conversions.h" | |
14 #include "build/build_config.h" | |
15 #include "content/browser/renderer_host/render_process_host.h" | |
16 #include "content/common/child_process_info.h" | |
17 | |
cpu_(ooo_6.6-7.5)
2011/06/07 21:18:00
we should use either src/sandbox/tools/finder/ntun
Cris Neckar
2011/06/07 22:10:10
Done.
| |
18 const wchar_t kNtdllDllName[] = L"ntdll.dll"; | |
19 const size_t kMaxHandleNameLength = 1024; | |
20 | |
21 #define STATUS_INFO_LENGTH_MISMATCH 0xc0000004 | |
22 | |
23 #define SystemHandleInformation 16 | |
24 #define ObjectNameInformation 1 | |
25 #define ObjectTypeInformation 2 | |
26 | |
27 typedef LONG (WINAPI* NtQuerySystemInformationFunction)( | |
28 ULONG SystemInformationClass, | |
29 PVOID SystemInformation, | |
30 ULONG SystemInformationLength, | |
31 PULONG ReturnLength); | |
32 | |
33 typedef LONG (WINAPI* NtDuplicateObjectFunction)( | |
34 HANDLE SourceProcessHandle, | |
35 HANDLE SourceHandle, | |
36 HANDLE TargetProcessHandle, | |
37 PHANDLE TargetHandle, | |
38 ACCESS_MASK DesiredAccess, | |
39 ULONG Attributes, | |
40 ULONG Options); | |
41 | |
42 typedef LONG (WINAPI* NtQueryObjectFunction)( | |
43 HANDLE ObjectHandle, | |
44 ULONG ObjectInformationClass, | |
45 PVOID ObjectInformation, | |
46 ULONG ObjectInformationLength, | |
47 PULONG ReturnLength); | |
48 | |
49 typedef struct _SYSTEM_HANDLE { | |
50 ULONG ProcessId; | |
51 BYTE ObjectTypeNumber; | |
52 BYTE Flags; | |
53 USHORT Handle; | |
54 PVOID Object; | |
55 ACCESS_MASK GrantedAccess; | |
56 } SYSTEM_HANDLE; | |
57 | |
58 typedef struct _SYSTEM_HANDLE_INFORMATION { | |
59 ULONG HandleCount; | |
60 SYSTEM_HANDLE Handles[1]; | |
61 } SYSTEM_HANDLE_INFORMATION; | |
62 | |
63 typedef enum _POOL_TYPE { | |
64 NonPagedPool, | |
65 PagedPool, | |
66 NonPagedPoolMustSucceed, | |
67 ReservedType, | |
68 NonPagedPoolCacheAligned, | |
69 PagedPoolCacheAligned, | |
70 NonPagedPoolCacheAlignedMustS | |
71 } POOL_TYPE; | |
72 | |
73 typedef struct _UNICODE_STRING { | |
74 USHORT Length; | |
75 USHORT MaximumLength; | |
76 PWSTR Buffer; | |
77 } UNICODE_STRING; | |
78 | |
79 typedef struct _OBJECT_TYPE_INFORMATION { | |
80 UNICODE_STRING Name; | |
81 ULONG TotalNumberOfObjects; | |
82 ULONG TotalNumberOfHandles; | |
83 ULONG TotalPagedPoolUsage; | |
84 ULONG TotalNonPagedPoolUsage; | |
85 ULONG TotalNamePoolUsage; | |
86 ULONG TotalHandleTableUsage; | |
87 ULONG HighWaterNumberOfObjects; | |
88 ULONG HighWaterNumberOfHandles; | |
89 ULONG HighWaterPagedPoolUsage; | |
90 ULONG HighWaterNonPagedPoolUsage; | |
91 ULONG HighWaterNamePoolUsage; | |
92 ULONG HighWaterHandleTableUsage; | |
93 ULONG InvalidAttributes; | |
94 GENERIC_MAPPING GenericMapping; | |
95 ULONG ValidAccess; | |
96 BOOLEAN SecurityRequired; | |
97 BOOLEAN MaintainHandleCount; | |
98 USHORT MaintainTypeList; | |
99 POOL_TYPE PoolType; | |
100 ULONG PagedPoolUsage; | |
101 ULONG NonPagedPoolUsage; | |
102 } OBJECT_TYPE_INFORMATION; | |
103 | |
104 typedef enum _HANDLE_TYPE { | |
105 ProcessHandle, | |
106 ThreadHandle, | |
107 FileHandle, | |
108 DirectoryHandle, | |
109 KeyHandle, | |
110 WindowStationHandle, | |
111 DesktopHandle, | |
112 ServiceHandle, | |
113 EventHandle, | |
114 MutexHandle, | |
115 SemaphoreHandle, | |
116 TimerHandle, | |
117 NamedPipeHandle, | |
118 JobHandle, | |
119 FileMapHandle, | |
120 OtherHandle | |
121 } HandleType; | |
122 | |
123 class HandleEnumerator : public base::RefCountedThreadSafe<HandleEnumerator> { | |
124 public: | |
125 enum HandleEnumStatus { | |
126 Starting, | |
127 InProgress, | |
128 Finished | |
129 }; | |
130 | |
131 HandleEnumerator(base::ProcessHandle handle): | |
132 handle_(handle), | |
133 type_(ChildProcessInfo::UNKNOWN_PROCESS), | |
134 status_(Starting) { } | |
135 | |
136 ChildProcessInfo::ProcessType type() { return type_; } | |
137 | |
138 HandleEnumStatus status() { return status_; } | |
139 | |
140 void RunHandleEnumeration(); | |
141 | |
142 void EnumerateHandles(); | |
143 | |
144 static HandleType StringToHandleType(string16 type); | |
145 | |
146 static string16 ProcessTypeString(ChildProcessInfo::ProcessType process_type); | |
147 | |
148 static string16 GetAccessString(HandleType handle_type, | |
149 ACCESS_MASK access); | |
150 | |
151 private: | |
152 void FindProcessOnIOThread(); | |
153 | |
154 void FindProcessOnUIThread(); | |
155 | |
156 void EnumerateHandlesAndTerminateProcess(); | |
157 | |
158 base::ProcessHandle handle_; | |
159 ChildProcessInfo::ProcessType type_; | |
160 HandleEnumStatus status_; | |
161 }; | |
162 | |
163 #endif // BASE_HANDLE_ENUMERATION_WIN_H_ | |
OLD | NEW |