1 // Copyright (c) 2006-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 SANDBOX_TOOLS_FINDER_NTUNDOC_H__
6 #define SANDBOX_TOOLS_FINDER_NTUNDOC_H__
7 
8 #define NTSTATUS ULONG
9 #define STATUS_SUCCESS 0x00000000
10 #define STATUS_INFO_LENGTH_MISMATCH 0xC0000004
11 #define STATUS_ACCESS_DENIED 0xC0000022
12 #define STATUS_BUFFER_OVERFLOW 0x80000005
13 
14 typedef struct _LSA_UNICODE_STRING {
15   USHORT Length;
16   USHORT MaximumLength;
17   PWSTR Buffer;
18 } UNICODE_STRING;
19 
20 typedef struct _OBJDIR_INFORMATION {
21   UNICODE_STRING ObjectName;
22   UNICODE_STRING ObjectTypeName;
23   BYTE Data[1];
24 } OBJDIR_INFORMATION;
25 
26 typedef struct _OBJECT_ATTRIBUTES {
27   ULONG Length;
28   HANDLE RootDirectory;
29   UNICODE_STRING *ObjectName;
30   ULONG Attributes;
31   PVOID SecurityDescriptor;
32   PVOID SecurityQualityOfService;
33 } OBJECT_ATTRIBUTES;
34 
35 typedef struct _PUBLIC_OBJECT_BASIC_INFORMATION {
36   ULONG Attributes;
37   ACCESS_MASK GrantedAccess;
38   ULONG HandleCount;
39   ULONG PointerCount;
40   ULONG Reserved[10];    // reserved for internal use
41  } PUBLIC_OBJECT_BASIC_INFORMATION, *PPUBLIC_OBJECT_BASIC_INFORMATION;
42 
43 typedef struct __PUBLIC_OBJECT_TYPE_INFORMATION {
44   UNICODE_STRING TypeName;
45   ULONG Reserved [22];    // reserved for internal use
46 } PUBLIC_OBJECT_TYPE_INFORMATION, *PPUBLIC_OBJECT_TYPE_INFORMATION;
47 
48 typedef enum _POOL_TYPE {
49   NonPagedPool,
50   PagedPool,
51   NonPagedPoolMustSucceed,
52   ReservedType,
53   NonPagedPoolCacheAligned,
54   PagedPoolCacheAligned,
55   NonPagedPoolCacheAlignedMustS
56 } POOL_TYPE;
57 
58 typedef struct _OBJECT_TYPE_INFORMATION {
59   UNICODE_STRING Name;
60   ULONG TotalNumberOfObjects;
61   ULONG TotalNumberOfHandles;
62   ULONG TotalPagedPoolUsage;
63   ULONG TotalNonPagedPoolUsage;
64   ULONG TotalNamePoolUsage;
65   ULONG TotalHandleTableUsage;
66   ULONG HighWaterNumberOfObjects;
67   ULONG HighWaterNumberOfHandles;
68   ULONG HighWaterPagedPoolUsage;
69   ULONG HighWaterNonPagedPoolUsage;
70   ULONG HighWaterNamePoolUsage;
71   ULONG HighWaterHandleTableUsage;
72   ULONG InvalidAttributes;
73   GENERIC_MAPPING GenericMapping;
74   ULONG ValidAccess;
75   BOOLEAN SecurityRequired;
76   BOOLEAN MaintainHandleCount;
77   USHORT MaintainTypeList;
78   POOL_TYPE PoolType;
79   ULONG PagedPoolUsage;
80   ULONG NonPagedPoolUsage;
81 } OBJECT_TYPE_INFORMATION, *POBJECT_TYPE_INFORMATION;
82 
83 typedef struct _OBJECT_NAME_INFORMATION {
84   UNICODE_STRING          ObjectName;
85 } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
86 
87 typedef enum _OBJECT_INFORMATION_CLASS {
88   ObjectBasicInformation,
89   ObjectNameInformation,
90   ObjectTypeInformation,
91   ObjectAllInformation,
92   ObjectDataInformation
93 } OBJECT_INFORMATION_CLASS, *POBJECT_INFORMATION_CLASS;
94 
95 typedef struct _FILE_NAME_INFORMATION {
96  ULONG FileNameLength;
97  WCHAR FileName[1];
98 } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
99 
100 typedef enum _FILE_INFORMATION_CLASS {
101  // end_wdm
102   FileDirectoryInformation       = 1,
103   FileFullDirectoryInformation, // 2
104   FileBothDirectoryInformation, // 3
105   FileBasicInformation,         // 4  wdm
106   FileStandardInformation,      // 5  wdm
107   FileInternalInformation,      // 6
108   FileEaInformation,            // 7
109   FileAccessInformation,        // 8
110   FileNameInformation,          // 9
111   FileRenameInformation,        // 10
112   FileLinkInformation,          // 11
113   FileNamesInformation,         // 12
114   FileDispositionInformation,   // 13
115   FilePositionInformation,      // 14 wdm
116   FileFullEaInformation,        // 15
117   FileModeInformation,          // 16
118   FileAlignmentInformation,     // 17
119   FileAllInformation,           // 18
120   FileAllocationInformation,    // 19
121   FileEndOfFileInformation,     // 20 wdm
122   FileAlternateNameInformation, // 21
123   FileStreamInformation,        // 22
124   FilePipeInformation,          // 23
125   FilePipeLocalInformation,     // 24
126   FilePipeRemoteInformation,    // 25
127   FileMailslotQueryInformation, // 26
128   FileMailslotSetInformation,   // 27
129   FileCompressionInformation,   // 28
130   FileObjectIdInformation,      // 29
131   FileCompletionInformation,    // 30
132   FileMoveClusterInformation,   // 31
133   FileQuotaInformation,         // 32
134   FileReparsePointInformation,  // 33
135   FileNetworkOpenInformation,   // 34
136   FileAttributeTagInformation,  // 35
137   FileTrackingInformation,      // 36
138   FileMaximumInformation
139   // begin_wdm
140 } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
141 
142 typedef enum _SYSTEM_INFORMATION_CLASS {
143   SystemHandleInformation = 16
144 } SYSTEM_INFORMATION_CLASS;
145 
146 typedef struct _IO_STATUS_BLOCK {
147     union {
148         NTSTATUS Status;
149         PVOID Pointer;
150     };
151     ULONG_PTR Information;
152 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
153 
154 #define InitializeObjectAttributes( p, n, a, r, s ) { \
155     (p)->Length = sizeof( OBJECT_ATTRIBUTES ); \
156     (p)->RootDirectory = r; \
157     (p)->Attributes = a; \
158     (p)->ObjectName = n; \
159     (p)->SecurityDescriptor = s; \
160     (p)->SecurityQualityOfService = NULL; \
161 }
162 
163 typedef struct _SYSTEM_HANDLE_INFORMATION {
164   USHORT ProcessId;
165   USHORT CreatorBackTraceIndex;
166   UCHAR ObjectTypeNumber;
167   UCHAR Flags;
168   USHORT Handle;
169   PVOID Object;
170   ACCESS_MASK GrantedAccess;
171 } SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION;
172 
173 typedef struct _SYSTEM_HANDLE_INFORMATION_EX {
174   ULONG NumberOfHandles;
175   SYSTEM_HANDLE_INFORMATION Information[1];
176 } SYSTEM_HANDLE_INFORMATION_EX, *PSYSTEM_HANDLE_INFORMATION_EX;
177 
178 #define POBJECT_ATTRIBUTES OBJECT_ATTRIBUTES*
179 
180 typedef NTSTATUS (WINAPI* NTQUERYDIRECTORYOBJECT)(
181   HANDLE,
182   OBJDIR_INFORMATION*,
183   DWORD,
184   DWORD,
185   DWORD,
186   DWORD*,
187   DWORD*);
188 
189 typedef NTSTATUS (WINAPI* NTOPENDIRECTORYOBJECT)(
190   HANDLE *,
191   DWORD,
192   OBJECT_ATTRIBUTES* );
193 
194 typedef NTSTATUS (WINAPI* NTGENERICOPEN) (
195   OUT PHANDLE EventHandle,
196   IN ACCESS_MASK DesiredAccess,
197   IN POBJECT_ATTRIBUTES ObjectAttributes);
198 
199 typedef NTSTATUS (WINAPI* NTOPENEVENT)(
200   OUT PHANDLE EventHandle,
201   IN ACCESS_MASK DesiredAccess,
202   IN POBJECT_ATTRIBUTES ObjectAttributes);
203 
204 typedef NTSTATUS (WINAPI* NTOPENJOBOBJECT)(
205   OUT PHANDLE JobHandle,
206   IN ACCESS_MASK DesiredAccess,
207   IN POBJECT_ATTRIBUTES ObjectAttributes);
208 
209 typedef NTSTATUS (WINAPI* NTOPENKEYEDEVENT)(
210   OUT PHANDLE KeyedEventHandle,
211   IN ACCESS_MASK DesiredAccess,
212   IN POBJECT_ATTRIBUTES ObjectAttributes);
213 
214 typedef NTSTATUS (WINAPI* NTOPENMUTANT)(
215   OUT PHANDLE MutantHandle,
216   IN ACCESS_MASK DesiredAccess,
217   IN POBJECT_ATTRIBUTES ObjectAttributes);
218 
219 typedef NTSTATUS (WINAPI* NTOPENSECTION)(
220   OUT PHANDLE SectionHandle,
221   IN ACCESS_MASK DesiredAccess,
222   IN POBJECT_ATTRIBUTES ObjectAttributes);
223 
224 typedef NTSTATUS (WINAPI* NTOPENSEMAPHORE)(
225   OUT PHANDLE SemaphoreHandle,
226   IN ACCESS_MASK DesiredAccess,
227   IN POBJECT_ATTRIBUTES ObjectAttributes);
228 
229 typedef NTSTATUS (WINAPI* NTOPENSYMBOLICLINKOBJECT)(
230   OUT PHANDLE SymbolicLinkHandle,
231   IN ACCESS_MASK DesiredAccess,
232   IN POBJECT_ATTRIBUTES ObjectAttributes);
233 
234 typedef NTSTATUS (WINAPI* NTOPENTIMER)(
235   OUT PHANDLE TimerHandle,
236   IN ACCESS_MASK DesiredAccess,
237   IN POBJECT_ATTRIBUTES ObjectAttributes);
238 
239 typedef NTSTATUS (WINAPI* NTOPENFILE)(
240   HANDLE *,
241   DWORD,
242   OBJECT_ATTRIBUTES *,
243   IO_STATUS_BLOCK *,
244   DWORD,
245   DWORD);
246 
247 typedef NTSTATUS (WINAPI* NTQUERYINFORMATIONFILE)(
248   HANDLE,
249   PIO_STATUS_BLOCK,
250   PVOID,
251   ULONG,
252   FILE_INFORMATION_CLASS);
253 
254 typedef NTSTATUS (WINAPI* NTQUERYSYSTEMINFORMATION)(
255   SYSTEM_INFORMATION_CLASS SystemInformationClass,
256   PVOID SystemInformation,
257   ULONG SystemInformationLength,
258   PULONG ReturnLength);
259 
260 typedef NTSTATUS (WINAPI* NTQUERYOBJECT)(
261   HANDLE Handle,
262   OBJECT_INFORMATION_CLASS ObjectInformationClass,
263   PVOID ObjectInformation,
264   ULONG ObjectInformationLength,
265   PULONG ReturnLength);
266 
267 typedef NTSTATUS (WINAPI* NTCLOSE) (HANDLE);
268 
269 #define DIRECTORY_QUERY 0x0001
270 #define DIRECTORY_TRAVERSE 0x0002
271 #define DIRECTORY_CREATE_OBJECT 0x0004
272 #define DIRECTORY_CREATE_SUBDIRECTORY 0x0008
273 #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
274 
275 #endif  // SANDBOX_TOOLS_FINDER_NTUNDOC_H__
276