diff --git a/UsbDk/ControlDevice.cpp b/UsbDk/ControlDevice.cpp index b822f94..d4ae0d4 100644 --- a/UsbDk/ControlDevice.cpp +++ b/UsbDk/ControlDevice.cpp @@ -865,3 +865,35 @@ void CUsbDkHideRule::Dump() const TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE, "%!FUNC! Hide: %!bool!, C: %08X, V: %08X, P: %08X, BCD: %08X", m_Hide, m_Class, m_VID, m_PID, m_BCD); } + +void CDriverParamsRegistryPath::CreateFrom(PCUNICODE_STRING DriverRegPath) +{ + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE, + "%!FUNC! Driver registry path: %wZ", DriverRegPath); + + m_Path = new CAllocatablePath; + if (m_Path == nullptr) + { + TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, + "%!FUNC! Failed to allocate storage for parameters registry path"); + return; + } + + CStringHolder ParamsSubkey; + auto status = ParamsSubkey.Attach(USBDK_PARAMS_SUBKEY_NAME); + ASSERT(NT_SUCCESS(status)); + + status = m_Path->Create(DriverRegPath, ParamsSubkey); + if (!NT_SUCCESS(status)) + { + TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, + "%!FUNC! Failed to duplicate parameters registry path"); + } +} + +void CDriverParamsRegistryPath::Destroy() +{ + delete m_Path; +} + +CDriverParamsRegistryPath::CAllocatablePath *CDriverParamsRegistryPath::m_Path = nullptr; diff --git a/UsbDk/ControlDevice.h b/UsbDk/ControlDevice.h index 9b9687b..661f3f9 100644 --- a/UsbDk/ControlDevice.h +++ b/UsbDk/ControlDevice.h @@ -182,6 +182,26 @@ private: DECLARE_CWDMLIST_ENTRY(CUsbDkRedirection); }; +class CDriverParamsRegistryPath final +{ +public: + static PCUNICODE_STRING Get() + { return *m_Path; }; + +private: + static void CreateFrom(PCUNICODE_STRING DriverRegPath); + static void Destroy(); + + class CAllocatablePath : public CString, + public CAllocatable < PagedPool, 'PRHR' > + {}; + + static CAllocatablePath *m_Path; + + friend NTSTATUS DriverEntry(PDRIVER_OBJECT, PUNICODE_STRING); + friend VOID DriverUnload(IN WDFDRIVER Driver); +}; + class CUsbDkControlDevice : private CWdfControlDevice, public CAllocatable { public: diff --git a/UsbDk/Driver.cpp b/UsbDk/Driver.cpp index a5ce8a3..d3e5799 100644 --- a/UsbDk/Driver.cpp +++ b/UsbDk/Driver.cpp @@ -60,6 +60,8 @@ DriverEntry( config.EvtDriverUnload = DriverUnload; + CDriverParamsRegistryPath::CreateFrom(RegistryPath); + WDFDRIVER Driver; status = WdfDriverCreate(DriverObject, RegistryPath, @@ -94,6 +96,8 @@ DriverUnload(IN WDFDRIVER Driver) CUsbDkControlDevice::Deallocate(); + CDriverParamsRegistryPath::Destroy(); + return; } diff --git a/UsbDk/UsbDkNames.h b/UsbDk/UsbDkNames.h index 8584e52..0351bc4 100644 --- a/UsbDk/UsbDkNames.h +++ b/UsbDk/UsbDkNames.h @@ -34,3 +34,5 @@ #define USBDK_HIDER_DEVICE_NAME TEXT("\\Device\\") _USBDK_HIDER_NAME #define USBDK_DOS_HIDER_DEVICE_NAME TEXT("\\DosDevices\\") _USBDK_HIDER_NAME #define USBDK_USERMODE_HIDER_NAME TEXT("\\\\.\\") _USBDK_HIDER_NAME + +#define USBDK_PARAMS_SUBKEY_NAME TEXT("\\Parameters")