Process Hacker
ntfill.h
Go to the documentation of this file.
1 #ifndef NTFILL_H
2 #define NTFILL_H
3 
4 extern ULONG KphDynNtVersion;
5 extern ULONG KphDynObDecodeShift;
6 extern ULONG KphDynObAttributesShift;
7 
8 // IO
9 
10 extern POBJECT_TYPE *IoDriverObjectType;
11 
12 // KE
13 
14 typedef enum _KAPC_ENVIRONMENT
15 {
21 
22 typedef VOID (NTAPI *PKNORMAL_ROUTINE)(
23  __in PVOID NormalContext,
24  __in PVOID SystemArgument1,
25  __in PVOID SystemArgument2
26  );
27 
29  __in PRKAPC Apc,
30  __inout PKNORMAL_ROUTINE *NormalRoutine,
31  __inout PVOID *NormalContext,
32  __inout PVOID *SystemArgument1,
33  __inout PVOID *SystemArgument2
34  );
35 
36 typedef KKERNEL_ROUTINE (NTAPI *PKKERNEL_ROUTINE);
37 
38 typedef VOID (NTAPI *PKRUNDOWN_ROUTINE)(
39  __in PRKAPC Apc
40  );
41 
42 NTKERNELAPI
43 VOID
44 NTAPI
46  __out PRKAPC Apc,
47  __in PRKTHREAD Thread,
48  __in KAPC_ENVIRONMENT Environment,
49  __in PKKERNEL_ROUTINE KernelRoutine,
50  __in_opt PKRUNDOWN_ROUTINE RundownRoutine,
51  __in_opt PKNORMAL_ROUTINE NormalRoutine,
52  __in_opt KPROCESSOR_MODE ProcessorMode,
53  __in_opt PVOID NormalContext
54  );
55 
56 NTKERNELAPI
57 BOOLEAN
58 NTAPI
60  __inout PRKAPC Apc,
61  __in_opt PVOID SystemArgument1,
62  __in_opt PVOID SystemArgument2,
63  __in KPRIORITY Increment
64  );
65 
66 // EX
67 
68 typedef struct _EX_PUSH_LOCK_WAIT_BLOCK *PEX_PUSH_LOCK_WAIT_BLOCK;
69 
71  __inout PEX_PUSH_LOCK PushLock,
72  __inout_opt PEX_PUSH_LOCK_WAIT_BLOCK WaitBlock
73  );
74 
75 typedef struct _HANDLE_TABLE_ENTRY
76 {
77  union
78  {
79  PVOID Object;
80  ULONG ObAttributes;
81  ULONG_PTR Value;
82  };
83  union
84  {
85  ACCESS_MASK GrantedAccess;
87  };
89 
90 typedef struct _HANDLE_TABLE HANDLE_TABLE, *PHANDLE_TABLE;
91 
92 typedef BOOLEAN (NTAPI *PEX_ENUM_HANDLE_CALLBACK_61)(
93  __inout PHANDLE_TABLE_ENTRY HandleTableEntry,
94  __in HANDLE Handle,
95  __in PVOID Context
96  );
97 
98 // since WIN8
99 typedef BOOLEAN (NTAPI *PEX_ENUM_HANDLE_CALLBACK)(
100  __in PHANDLE_TABLE HandleTable,
101  __inout PHANDLE_TABLE_ENTRY HandleTableEntry,
102  __in HANDLE Handle,
103  __in PVOID Context
104  );
105 
106 NTKERNELAPI
107 BOOLEAN
108 NTAPI
110  __in PHANDLE_TABLE HandleTable,
111  __in PEX_ENUM_HANDLE_CALLBACK EnumHandleProcedure,
112  __inout PVOID Context,
113  __out_opt PHANDLE Handle
114  );
115 
116 NTSYSCALLAPI
117 NTSTATUS
118 NTAPI
120  __in SYSTEM_INFORMATION_CLASS SystemInformationClass,
121  __out_bcount_opt(SystemInformationLength) PVOID SystemInformation,
122  __in ULONG SystemInformationLength,
123  __out_opt PULONG ReturnLength
124  );
125 
126 // OB
127 
128 // These definitions are no longer correct, but they produce correct results.
129 
130 #define OBJ_PROTECT_CLOSE 0x00000001
131 #define OBJ_HANDLE_ATTRIBUTES (OBJ_PROTECT_CLOSE | OBJ_INHERIT | OBJ_AUDIT_OBJECT_CLOSE)
132 
133 // This attribute is now stored in the GrantedAccess field.
134 #define ObpAccessProtectCloseBit 0x2000000
135 
136 #define ObpDecodeGrantedAccess(Access) \
137  ((Access) & ~ObpAccessProtectCloseBit)
138 
139 FORCEINLINE PVOID ObpDecodeObject(PVOID Object)
140 {
141 #ifdef _M_X64
142  if (KphDynNtVersion >= PHNT_WIN8)
143  {
144  if (KphDynObDecodeShift != -1)
145  return (PVOID)(((LONG_PTR)Object >> KphDynObDecodeShift) & ~(ULONG_PTR)0xf);
146  else
147  return NULL;
148  }
149  else
150  {
151  return (PVOID)((ULONG_PTR)Object & ~OBJ_HANDLE_ATTRIBUTES);
152  }
153 #else
154  return (PVOID)((ULONG_PTR)Object & ~OBJ_HANDLE_ATTRIBUTES);
155 #endif
156 }
157 
158 FORCEINLINE ULONG ObpGetHandleAttributes(PHANDLE_TABLE_ENTRY HandleTableEntry)
159 {
160 #ifdef _M_X64
161  if (KphDynNtVersion >= PHNT_WIN8)
162  {
163  if (KphDynObAttributesShift != -1)
164  return (ULONG)(HandleTableEntry->Value >> KphDynObAttributesShift) & 0x3;
165  else
166  return 0;
167  }
168  else
169  {
170  return (HandleTableEntry->ObAttributes & (OBJ_INHERIT | OBJ_AUDIT_OBJECT_CLOSE)) |
171  ((HandleTableEntry->GrantedAccess & ObpAccessProtectCloseBit) ? OBJ_PROTECT_CLOSE : 0);
172  }
173 #else
174  return (HandleTableEntry->ObAttributes & (OBJ_INHERIT | OBJ_AUDIT_OBJECT_CLOSE)) |
175  ((HandleTableEntry->GrantedAccess & ObpAccessProtectCloseBit) ? OBJ_PROTECT_CLOSE : 0);
176 #endif
177 }
178 
179 typedef struct _OBJECT_CREATE_INFORMATION OBJECT_CREATE_INFORMATION, *POBJECT_CREATE_INFORMATION;
180 
181 // This is incorrect as of Windows 8.1, but the size of the structure is still correct.
182 typedef struct _OBJECT_HEADER
183 {
185  union
186  {
188  PVOID NextToFree;
189  };
190  POBJECT_TYPE Type;
194  UCHAR Flags;
195  union
196  {
197  POBJECT_CREATE_INFORMATION ObjectCreateInfo;
199  };
203 
204 #define OBJECT_TO_OBJECT_HEADER(Object) CONTAINING_RECORD((Object), OBJECT_HEADER, Body)
205 
206 typedef POBJECT_TYPE (NTAPI *_ObGetObjectType)(
207  __in PVOID Object
208  );
209 
210 NTKERNELAPI
211 NTSTATUS
212 NTAPI
214  __in POBJECT_ATTRIBUTES ObjectAttributes,
215  __in POBJECT_TYPE ObjectType,
216  __in KPROCESSOR_MODE PreviousMode,
217  __in_opt PACCESS_STATE AccessState,
218  __in_opt ACCESS_MASK DesiredAccess,
219  __in PVOID ParseContext,
220  __out PHANDLE Handle
221  );
222 
223 NTKERNELAPI
224 NTSTATUS
225 NTAPI
227  __in HANDLE Handle,
228  __in POBJECT_HANDLE_FLAG_INFORMATION HandleFlags,
229  __in KPROCESSOR_MODE PreviousMode
230  );
231 
232 NTKERNELAPI
233 NTSTATUS
235  __in HANDLE Handle,
236  __in KPROCESSOR_MODE PreviousMode
237  );
238 
239 // PS
240 
241 typedef NTSTATUS (NTAPI *_PsAcquireProcessExitSynchronization)(
242  __in PEPROCESS Process
243  );
244 
245 typedef NTSTATUS (NTAPI *_PsReleaseProcessExitSynchronization)(
246  __in PEPROCESS Process
247  );
248 
249 typedef NTSTATUS (NTAPI *_PsSuspendProcess)(
250  __in PEPROCESS Process
251  );
252 
253 typedef NTSTATUS (NTAPI *_PsResumeProcess)(
254  __in PEPROCESS Process
255  );
256 
257 typedef BOOLEAN (NTAPI *_PsIsProtectedProcess)(
258  __in PEPROCESS Process
259  );
260 
261 NTSYSCALLAPI
262 NTSTATUS
263 NTAPI
265  __in HANDLE ProcessHandle,
266  __in PROCESSINFOCLASS ProcessInformationClass,
267  __out_bcount(ProcessInformationLength) PVOID ProcessInformation,
268  __in ULONG ProcessInformationLength,
269  __out_opt PULONG ReturnLength
270  );
271 
272 NTSYSCALLAPI
273 NTSTATUS
274 NTAPI
276  __in HANDLE ProcessHandle,
277  __in PROCESSINFOCLASS ProcessInformationClass,
278  __in_bcount(ProcessInformationLength) PVOID ProcessInformation,
279  __in ULONG ProcessInformationLength
280  );
281 
282 NTSYSCALLAPI
283 NTSTATUS
284 NTAPI
286  __in HANDLE ThreadHandle,
287  __in THREADINFOCLASS ThreadInformationClass,
288  __out_bcount(ThreadInformationLength) PVOID ThreadInformation,
289  __in ULONG ThreadInformationLength,
290  __out_opt PULONG ReturnLength
291  );
292 
293 NTKERNELAPI
294 NTSTATUS
295 NTAPI
297  __in PCLIENT_ID ClientId,
298  __out_opt PEPROCESS *Process,
299  __out PETHREAD *Thread
300  );
301 
302 NTKERNELAPI
303 PVOID
304 NTAPI
306  __in PETHREAD Thread
307  );
308 
309 NTKERNELAPI
310 NTSTATUS
311 NTAPI
313  __in PETHREAD Thread,
314  __inout PCONTEXT ThreadContext,
315  __in KPROCESSOR_MODE PreviousMode
316  );
317 
318 NTKERNELAPI
319 NTSTATUS
320 NTAPI
322  __in PETHREAD Thread,
323  __in PCONTEXT ThreadContext,
324  __in KPROCESSOR_MODE PreviousMode
325  );
326 
327 typedef struct _EJOB *PEJOB;
328 
329 extern POBJECT_TYPE *PsJobType;
330 
331 NTKERNELAPI
332 PEJOB
333 NTAPI
335  __in PEPROCESS Process
336  );
337 
338 // RTL
339 
340 // Sensible limit that may or may not correspond to the actual Windows value.
341 #define MAX_STACK_DEPTH 64
342 
343 #define RTL_WALK_USER_MODE_STACK 0x00000001
344 #define RTL_WALK_VALID_FLAGS 0x00000001
345 
346 NTSYSAPI
347 ULONG
348 NTAPI
350  __out PVOID *Callers,
351  __in ULONG Count,
352  __in ULONG Flags
353  );
354 
355 #endif