summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Benditovich <yuri.benditovich@daynix.com>2020-01-02 14:58:39 +0200
committerYan Vugenfirer <yan@daynix.com>2020-01-02 21:47:41 +0200
commit427b3f010640d7991f248df07ecabc515d9fadc9 (patch)
tree7da8d9be9b94f1a2bd3bbd66dc52e7accfc24da3
parentdb6c11f48afb236c422e26ce892cefcaf5c3e4eb (diff)
driver: maintain owner process id field of CUsbDkRedirection
Set owner process id when device redirection successfully established (i.e. filter device is open and respective user mode handle created for the process). Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
-rw-r--r--UsbDk/ControlDevice.cpp9
-rw-r--r--UsbDk/ControlDevice.h3
2 files changed, 12 insertions, 0 deletions
diff --git a/UsbDk/ControlDevice.cpp b/UsbDk/ControlDevice.cpp
index 49097f7..74cd2c4 100644
--- a/UsbDk/ControlDevice.cpp
+++ b/UsbDk/ControlDevice.cpp
@@ -1120,6 +1120,12 @@ void CUsbDkRedirection::Dump(LPCSTR message) const
m_DeviceID, m_InstanceID);
}
+bool CUsbDkRedirection::MatchProcess(ULONG pid)
+{
+ TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_WDFDEVICE, "%!FUNC! pid 0x%X, owner 0x%X", pid, m_OwnerPid);
+ return pid == m_OwnerPid;
+}
+
void CUsbDkRedirection::NotifyRedirectorCreated(CUsbDkFilterDevice *RedirectorDevice)
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_WDFDEVICE, "%!FUNC! Redirector created for");
@@ -1209,6 +1215,9 @@ NTSTATUS CUsbDkRedirection::CreateRedirectorHandle(HANDLE RequestorProcess, PHAN
status = m_RedirectorDevice->CreateUserModeHandle(RequestorProcess, ObjectHandle);
if (NT_SUCCESS(status))
{
+ ULONG pid = (ULONG)(ULONG_PTR)PsGetCurrentProcessId();
+ TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_WDFDEVICE, "%!FUNC! done for process 0x%X", pid);
+ m_OwnerPid = pid;
return status;
}
diff --git a/UsbDk/ControlDevice.h b/UsbDk/ControlDevice.h
index e612050..7e7cd0f 100644
--- a/UsbDk/ControlDevice.h
+++ b/UsbDk/ControlDevice.h
@@ -190,6 +190,8 @@ public:
bool IsPreparedForRemove() const
{ return m_RemovalInProgress; }
+ bool MatchProcess(ULONG pid);
+
NTSTATUS WaitForAttachment()
{ return m_RedirectionCreated.Wait(true, -SecondsTo100Nanoseconds(120)); }
@@ -216,6 +218,7 @@ private:
CWdmEvent m_RedirectionCreated;
CWdmEvent m_RedirectionRemoved;
CUsbDkFilterDevice *m_RedirectorDevice = nullptr;
+ ULONG m_OwnerPid = 0;
bool m_RemovalInProgress = false;