diff options
author | Yuri Benditovich <yuri.benditovich@daynix.com> | 2020-01-02 12:53:22 +0200 |
---|---|---|
committer | Yan Vugenfirer <yan@daynix.com> | 2020-01-02 21:47:41 +0200 |
commit | 26a361966662d830b8454f68c81ee5a8a9eb56a3 (patch) | |
tree | 13f48a960b45182b09d00b4f9ce6a164270d0c4b | |
parent | 65f7251d2c02e4f9bd51a92b9de1e298969c981c (diff) |
driver: add file open callback for tracing
Add callback when filter device receives file open request.
Propagate open operation down the stack and log it.
ETW log will contain process id of open request.
It is possible that more than one process opens the device.
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
-rw-r--r-- | UsbDk/FilterDevice.cpp | 15 | ||||
-rw-r--r-- | UsbDk/FilterDevice.h | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/UsbDk/FilterDevice.cpp b/UsbDk/FilterDevice.cpp index ebfbbf1..8fe016e 100644 --- a/UsbDk/FilterDevice.cpp +++ b/UsbDk/FilterDevice.cpp @@ -83,7 +83,11 @@ NTSTATUS CUsbDkFilterDeviceInit::Configure(ULONG InstanceNumber) SetIoInCallerContextCallback([](_In_ WDFDEVICE Device, WDFREQUEST Request) { return Strategy(Device)->IoInCallerContext(Device, Request); }); - SetFileEventCallbacks(WDF_NO_EVENT_CALLBACK, + SetFileEventCallbacks([](_In_ WDFDEVICE Device, _In_ WDFREQUEST Request, _In_ WDFFILEOBJECT FileObject) + { + UNREFERENCED_PARAMETER(FileObject); + UsbDkFilterGetContext(Device)->UsbDkFilter->OnFileCreate(Request); + }, [](_In_ WDFFILEOBJECT FileObject) { WDFDEVICE Device = WdfFileObjectGetDevice(FileObject); @@ -475,6 +479,15 @@ bool CUsbDkChildDevice::AttachToDeviceStack() return true; } +void CUsbDkFilterDevice::OnFileCreate(WDFREQUEST Request) +{ + WDF_REQUEST_SEND_OPTIONS options; + WDF_REQUEST_SEND_OPTIONS_INIT(&options, WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET); + // in the log we'll see which process created the file + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC!"); + WdfRequestSend(Request, IOTarget(), &options); +} + NTSTATUS CUsbDkFilterDevice::AttachToStack(WDFDRIVER Driver) { PAGED_CODE(); diff --git a/UsbDk/FilterDevice.h b/UsbDk/FilterDevice.h index 3d79ca4..76b38ca 100644 --- a/UsbDk/FilterDevice.h +++ b/UsbDk/FilterDevice.h @@ -175,6 +175,7 @@ public: void SetSerialNumber(ULONG Number) { m_SerialNumber = Number; } + void OnFileCreate(WDFREQUEST Request); private: ~CUsbDkFilterDevice() { |