5 #define PHNT_MODE PHNT_MODE_KERNEL
13 #define dprintf(Format, ...) DbgPrint("KProcessHacker: " Format, __VA_ARGS__)
30 __out PULONG Features,
31 __in KPROCESSOR_MODE AccessMode
47 NTSTATUS KphDispatchDeviceControl(
48 __in PDEVICE_OBJECT DeviceObject,
67 __in PWSTR SystemRoutineName
77 __in PEPROCESS Process
81 __in PEPROCESS Process
90 __in HANDLE ProcessHandle,
91 __out_bcount(BufferLength) PVOID Buffer,
92 __in_opt ULONG BufferLength,
93 __out_opt PULONG ReturnLength,
94 __in KPROCESSOR_MODE AccessMode
99 __out_bcount(BufferLength) POBJECT_NAME_INFORMATION Buffer,
100 __in ULONG BufferLength,
101 __out PULONG ReturnLength
105 __in PFILE_OBJECT FileObject,
106 __out_bcount(BufferLength) POBJECT_NAME_INFORMATION Buffer,
107 __in ULONG BufferLength,
108 __out PULONG ReturnLength
112 __in HANDLE ProcessHandle,
115 __out_bcount(ObjectInformationLength) PVOID ObjectInformation,
116 __in ULONG ObjectInformationLength,
117 __out_opt PULONG ReturnLength,
118 __in KPROCESSOR_MODE AccessMode
122 __in HANDLE ProcessHandle,
125 __in_bcount(ObjectInformationLength) PVOID ObjectInformation,
126 __in ULONG ObjectInformationLength,
127 __in KPROCESSOR_MODE AccessMode
131 __in PEPROCESS SourceProcess,
132 __in_opt PEPROCESS TargetProcess,
133 __in HANDLE SourceHandle,
134 __out_opt PHANDLE TargetHandle,
135 __in ACCESS_MASK DesiredAccess,
136 __in ULONG HandleAttributes,
138 __in KPROCESSOR_MODE AccessMode
142 __in HANDLE SourceProcessHandle,
143 __in HANDLE SourceHandle,
144 __in_opt HANDLE TargetProcessHandle,
145 __out_opt PHANDLE TargetHandle,
146 __in ACCESS_MASK DesiredAccess,
147 __in ULONG HandleAttributes,
149 __in KPROCESSOR_MODE AccessMode
153 __out PHANDLE ObjectHandle,
154 __in ACCESS_MASK DesiredAccess,
156 __in POBJECT_TYPE ObjectType,
157 __in KPROCESSOR_MODE AccessMode
163 __out PHANDLE ProcessHandle,
164 __in ACCESS_MASK DesiredAccess,
166 __in KPROCESSOR_MODE AccessMode
170 __in HANDLE ProcessHandle,
171 __in ACCESS_MASK DesiredAccess,
172 __out PHANDLE TokenHandle,
173 __in KPROCESSOR_MODE AccessMode
177 __in HANDLE ProcessHandle,
178 __in ACCESS_MASK DesiredAccess,
179 __out PHANDLE JobHandle,
180 __in KPROCESSOR_MODE AccessMode
184 __in HANDLE ProcessHandle,
185 __in KPROCESSOR_MODE AccessMode
189 __in HANDLE ProcessHandle,
190 __in KPROCESSOR_MODE AccessMode
194 __in PEPROCESS Process,
195 __in NTSTATUS ExitStatus
199 __in HANDLE ProcessHandle,
200 __in NTSTATUS ExitStatus,
201 __in KPROCESSOR_MODE AccessMode
205 __in HANDLE ProcessHandle,
207 __out_bcount(ProcessInformationLength) PVOID ProcessInformation,
208 __in ULONG ProcessInformationLength,
209 __out_opt PULONG ReturnLength,
210 __in KPROCESSOR_MODE AccessMode
214 __in HANDLE ProcessHandle,
216 __in_bcount(ProcessInformationLength) PVOID ProcessInformation,
217 __in ULONG ProcessInformationLength,
218 __in KPROCESSOR_MODE AccessMode
222 __in PEPROCESS Process
226 __in PEPROCESS Process
232 __out PHANDLE DriverHandle,
234 __in KPROCESSOR_MODE AccessMode
238 __in HANDLE DriverHandle,
240 __out_bcount(DriverInformationLength) PVOID DriverInformation,
241 __in ULONG DriverInformationLength,
242 __out_opt PULONG ReturnLength,
243 __in KPROCESSOR_MODE AccessMode
249 __out PHANDLE ThreadHandle,
250 __in ACCESS_MASK DesiredAccess,
252 __in KPROCESSOR_MODE AccessMode
256 __in HANDLE ThreadHandle,
257 __in ACCESS_MASK DesiredAccess,
258 __out PHANDLE ProcessHandle,
259 __in KPROCESSOR_MODE AccessMode
263 __in PETHREAD Thread,
264 __in NTSTATUS ExitStatus
268 __in HANDLE ThreadHandle,
269 __in NTSTATUS ExitStatus,
270 __in KPROCESSOR_MODE AccessMode
274 __in HANDLE ThreadHandle,
275 __in NTSTATUS ExitStatus,
276 __in KPROCESSOR_MODE AccessMode
280 __in HANDLE ThreadHandle,
281 __inout PCONTEXT ThreadContext,
282 __in KPROCESSOR_MODE AccessMode
286 __in HANDLE ThreadHandle,
287 __in PCONTEXT ThreadContext,
288 __in KPROCESSOR_MODE AccessMode
292 __in ULONG FramesToSkip,
293 __in ULONG FramesToCapture,
294 __in_opt ULONG Flags,
295 __out_ecount(FramesToCapture) PVOID *BackTrace,
296 __out_opt PULONG BackTraceHash
300 __in PETHREAD Thread,
301 __in ULONG FramesToSkip,
302 __in ULONG FramesToCapture,
303 __out_ecount(FramesToCapture) PVOID *BackTrace,
304 __out_opt PULONG CapturedFrames,
305 __out_opt PULONG BackTraceHash,
306 __in KPROCESSOR_MODE AccessMode
310 __in HANDLE ThreadHandle,
311 __in ULONG FramesToSkip,
312 __in ULONG FramesToCapture,
313 __out_ecount(FramesToCapture) PVOID *BackTrace,
314 __out_opt PULONG CapturedFrames,
315 __out_opt PULONG BackTraceHash,
316 __in KPROCESSOR_MODE AccessMode
320 __in HANDLE ThreadHandle,
322 __out_bcount(ProcessInformationLength) PVOID ThreadInformation,
323 __in ULONG ThreadInformationLength,
324 __out_opt PULONG ReturnLength,
325 __in KPROCESSOR_MODE AccessMode
329 __in HANDLE ThreadHandle,
331 __in_bcount(ThreadInformationLength) PVOID ThreadInformation,
332 __in ULONG ThreadInformationLength,
333 __in KPROCESSOR_MODE AccessMode
339 __in PEPROCESS FromProcess,
340 __in PVOID FromAddress,
341 __in PEPROCESS ToProcess,
342 __in PVOID ToAddress,
343 __in SIZE_T BufferLength,
344 __in KPROCESSOR_MODE AccessMode,
345 __out PSIZE_T ReturnLength
349 __in HANDLE ProcessHandle,
350 __in PVOID BaseAddress,
351 __out_bcount(BufferSize) PVOID Buffer,
352 __in SIZE_T BufferSize,
353 __out_opt PSIZE_T NumberOfBytesRead,
354 __in KPROCESSOR_MODE AccessMode
358 __in HANDLE ProcessHandle,
359 __in_opt PVOID BaseAddress,
360 __in_bcount(BufferSize) PVOID Buffer,
361 __in SIZE_T BufferSize,
362 __out_opt PSIZE_T NumberOfBytesWritten,
363 __in KPROCESSOR_MODE AccessMode
367 __in_opt HANDLE ProcessHandle,
368 __in PVOID BaseAddress,
369 __out_bcount(BufferSize) PVOID Buffer,
370 __in SIZE_T BufferSize,
371 __out_opt PSIZE_T NumberOfBytesRead,
372 __in KPROCESSOR_MODE AccessMode
381 if (CapturedUnicodeString->Buffer)
382 ExFreePoolWithTag(CapturedUnicodeString->Buffer,
'UhpK');
395 ProbeForRead(UnicodeString,
sizeof(
UNICODE_STRING),
sizeof(ULONG));
396 unicodeString.
Length = UnicodeString->Length;
398 unicodeString.Buffer = NULL;
400 userBuffer = UnicodeString->Buffer;
401 ProbeForRead(userBuffer, unicodeString.
Length,
sizeof(WCHAR));
403 __except (EXCEPTION_EXECUTE_HANDLER)
405 return GetExceptionCode();
408 if (unicodeString.
Length & 1)
410 return STATUS_INVALID_PARAMETER;
413 if (unicodeString.
Length != 0)
415 unicodeString.Buffer = ExAllocatePoolWithTag(
421 if (!unicodeString.Buffer)
422 return STATUS_INSUFFICIENT_RESOURCES;
427 unicodeString.Buffer,
432 __except (EXCEPTION_EXECUTE_HANDLER)
435 return GetExceptionCode();
439 *CapturedUnicodeString = unicodeString;
441 return STATUS_SUCCESS;