summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Benditovich <yuri.benditovich@daynix.com>2019-02-12 12:31:41 +0200
committerYan Vugenfirer <yan@daynix.com>2019-04-15 11:19:13 +0300
commit08ad75894345ba4e5fd13ab28eb2405624ec800e (patch)
tree3fd1b9ea77339359a6ba757883688c808f82d068
parent916f797c890390ca0622668930243364e0317d39 (diff)
Use also extended rules to decide whether device should be hidden
Extended rules processing uses bitmask OR between device type determination bitmap and class/type bitmap provided in 'Class' parameter of the extended rule. Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
-rw-r--r--UsbDk/ControlDevice.cpp44
-rw-r--r--UsbDk/ControlDevice.h11
-rw-r--r--UsbDk/FilterDevice.cpp4
3 files changed, 54 insertions, 5 deletions
diff --git a/UsbDk/ControlDevice.cpp b/UsbDk/ControlDevice.cpp
index 88cad28..79dcf39 100644
--- a/UsbDk/ControlDevice.cpp
+++ b/UsbDk/ControlDevice.cpp
@@ -314,15 +314,35 @@ void CUsbDkControlDevice::UnregisterHiddenDevice(CUsbDkFilterDevice &FilterDevic
m_HiddenDevices.Remove(&FilterDevice);
}
-bool CUsbDkControlDevice::ShouldHide(const USB_DEVICE_DESCRIPTOR &DevDescriptor) const
+bool CUsbDkControlDevice::ShouldHideDevice(CUsbDkChildDevice &Device) const
{
+ const USB_DEVICE_DESCRIPTOR &DevDescriptor = Device.DeviceDescriptor();
auto Hide = false;
-
+ ULONG classes = Device.ClassesBitMask();
const auto &HideVisitor = [&DevDescriptor, &Hide](CUsbDkHideRule *Entry) -> bool
{
+ Entry->Dump(TRACE_LEVEL_VERBOSE);
+ TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FILTERDEVICE,
+ "checking old hide rules %X:%X", DevDescriptor.idVendor, DevDescriptor.idProduct);
if (Entry->Match(DevDescriptor))
{
Hide = Entry->ShouldHide();
+ TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FILTERDEVICE, "Match: hide = %d", Hide);
+ return !Entry->ForceDecision();
+ }
+
+ return true;
+ };
+
+ const auto &HideVisitorExt = [&DevDescriptor, &Hide, classes](CUsbDkHideRule *Entry) -> bool
+ {
+ Entry->Dump(TRACE_LEVEL_VERBOSE);
+ TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FILTERDEVICE,
+ "checking ext hide rules %X:%X", DevDescriptor.idVendor, DevDescriptor.idProduct);
+ if (Entry->Match(classes, DevDescriptor))
+ {
+ Hide = Entry->ShouldHide();
+ TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FILTERDEVICE, "Match: hide = %d", Hide);
return !Entry->ForceDecision();
}
@@ -332,9 +352,29 @@ bool CUsbDkControlDevice::ShouldHide(const USB_DEVICE_DESCRIPTOR &DevDescriptor)
const_cast<HideRulesSet*>(&m_HideRules)->ForEach(HideVisitor);
const_cast<HideRulesSet*>(&m_PersistentHideRules)->ForEach(HideVisitor);
+ if (!Hide)
+ {
+ const_cast<HideRulesSet*>(&m_ExtHideRules)->ForEach(HideVisitorExt);
+ const_cast<HideRulesSet*>(&m_PersistentExtHideRules)->ForEach(HideVisitorExt);
+ }
+
return Hide;
}
+bool CUsbDkControlDevice::ShouldHide(const USB_DK_DEVICE_ID &DevId)
+{
+ bool b = false;
+
+ EnumUsbDevicesByID(DevId,
+ [&b, this](CUsbDkChildDevice *Child) -> bool
+ {
+ b = ShouldHideDevice(*Child);
+ return false;
+ });
+
+ return b;
+}
+
bool CUsbDkControlDevice::EnumerateDevices(USB_DK_DEVICE_INFO *outBuff, size_t numberAllocatedDevices, size_t &numberExistingDevices)
{
numberExistingDevices = 0;
diff --git a/UsbDk/ControlDevice.h b/UsbDk/ControlDevice.h
index 4811c3d..b933c2f 100644
--- a/UsbDk/ControlDevice.h
+++ b/UsbDk/ControlDevice.h
@@ -117,6 +117,14 @@ public:
MatchCharacteristic(m_BCD, Descriptor.bcdDevice);
}
+ bool Match(ULONG UsbClassesBitmask, const USB_DEVICE_DESCRIPTOR &Descriptor) const
+ {
+ return (UsbClassesBitmask & m_Class) &&
+ MatchCharacteristic(m_VID, Descriptor.idVendor) &&
+ MatchCharacteristic(m_PID, Descriptor.idProduct) &&
+ MatchCharacteristic(m_BCD, Descriptor.bcdDevice);
+ }
+
bool ShouldHide() const
{
return m_Hide;
@@ -286,7 +294,8 @@ public:
return !DontRedirect;
}
- bool ShouldHide(const USB_DEVICE_DESCRIPTOR &DevDescriptor) const;
+ bool ShouldHideDevice(CUsbDkChildDevice &Device) const;
+ bool ShouldHide(const USB_DK_DEVICE_ID &DevId);
template <typename TDevID>
void NotifyRedirectionRemoved(const TDevID &Dev) const
diff --git a/UsbDk/FilterDevice.cpp b/UsbDk/FilterDevice.cpp
index dab8daf..ebfbbf1 100644
--- a/UsbDk/FilterDevice.cpp
+++ b/UsbDk/FilterDevice.cpp
@@ -439,7 +439,7 @@ bool CUsbDkHubFilterStrategy::FetchConfigurationDescriptors(CWdmUsbDeviceAccess
void CUsbDkHubFilterStrategy::ApplyRedirectionPolicy(CUsbDkChildDevice &Device)
{
if (m_ControlDevice->ShouldRedirect(Device) ||
- m_ControlDevice->ShouldHide(Device.DeviceDescriptor()))
+ m_ControlDevice->ShouldHideDevice(Device))
{
if (Device.AttachToDeviceStack())
{
@@ -646,7 +646,7 @@ bool CUsbDkFilterDevice::CStrategist::SelectStrategy(PDEVICE_OBJECT DevObj)
}
// Should be hidden -> hider strategy
- if (m_Strategy->GetControlDevice()->ShouldHide(DevDescr))
+ if (m_Strategy->GetControlDevice()->ShouldHide(ID))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Assigning hidden USB device strategy");
m_Strategy->Delete();