From 742f04433437e438e24df6dde5a3307fdb18540b Mon Sep 17 00:00:00 2001 From: Dmitry Fleytman Date: Mon, 16 Nov 2015 14:52:19 +0200 Subject: [PATCH] Utils: Introduce helper for opening current process handle Signed-off-by: Dmitry Fleytman --- UsbDk/UsbDkUtil.cpp | 21 +++++++++++++++++++++ UsbDk/UsbDkUtil.h | 3 +++ UsbDk/stdafx.h | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/UsbDk/UsbDkUtil.cpp b/UsbDk/UsbDkUtil.cpp index 4c641b7..6f67cbd 100644 --- a/UsbDk/UsbDkUtil.cpp +++ b/UsbDk/UsbDkUtil.cpp @@ -159,3 +159,24 @@ PVOID DuplicateStaticBuffer(const void *Buffer, SIZE_T Length, POOL_TYPE PoolTyp } return Duplicate; } + +NTSTATUS +UsbDkCreateCurrentProcessHandle(HANDLE &Handle) +{ + PAGED_CODE(); + + auto status = ZwDuplicateObject(ZwCurrentProcess(), + ZwCurrentProcess(), + ZwCurrentProcess(), + &Handle, + PROCESS_DUP_HANDLE, + OBJ_KERNEL_HANDLE, + 0); + + if (!NT_SUCCESS(status)) + { + TraceEvents(TRACE_LEVEL_ERROR, TRACE_UTILS, "%!FUNC! failed, error: %!STATUS!", status); + } + + return status; +} diff --git a/UsbDk/UsbDkUtil.h b/UsbDk/UsbDkUtil.h index 42961c1..3e39f75 100644 --- a/UsbDk/UsbDkUtil.h +++ b/UsbDk/UsbDkUtil.h @@ -497,3 +497,6 @@ LONGLONG MillisecondsTo100Nanoseconds(LONGLONG Milliseconds) { return Milliseconds * 10 * 1000; } + +NTSTATUS +UsbDkCreateCurrentProcessHandle(HANDLE &Handle); diff --git a/UsbDk/stdafx.h b/UsbDk/stdafx.h index 4e64c43..7ed69e0 100644 --- a/UsbDk/stdafx.h +++ b/UsbDk/stdafx.h @@ -11,7 +11,7 @@ extern "C" { -#include +#include #include #include