Compare commits

..

2 commits

Author SHA1 Message Date
Yuri Benditovich
d902e99a2a Use lower device for queries during initialization
It is more correct to use lower device in stack for queries
during filter initialization. Lower device is in initialized
state and can process all kinds of requests, when current one is
not ready yet.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2017-07-12 16:49:32 +03:00
Dmitry Fleytman
dfd3a4a0ca ci: Integrate with AppVeyor
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
2017-06-07 14:27:19 +03:00
33 changed files with 113 additions and 863 deletions

View file

@ -3,7 +3,8 @@ image: Visual Studio 2015
version: build-{build}-{branch}
before_build:
- tools\AppVeyor\before-build.cmd
- ren "C:\Program Files (x86)\Windows Kits\10\include\00wdf" "wdf"
- ren "C:\Program Files (x86)\WiX Toolset v3.11" "WiX Toolset v3.8"
build_script: buildAll.bat

View file

@ -1,83 +0,0 @@
Short description of Device Hider feature:
The interface is described in UsbDkHelperHider.h
It includes basic and extended interfaces:
1. Basic interface:
UsbDk_AddPersistentHideRule
UsbDk_DeletePersistentHideRule
UsbDk_AddHideRule
UsbDk_ClearHideRules
Rule structure includes:
Class
BCD
Vendor ID
Product ID
Hide specifier (0 or 1), 0 is terminal, 1 continues for next rule
Class describes device class as specified in device descriptor.
Checkers for these rules do not check classes of interfaces in multifunction devices,
i.e.
class match = (device class == rule class) or (rule class == -1)
2. Extended interface
UsbDk_AddExtendedHideRule
UsbDk_AddExtendedPersistentHideRule
UsbDk_DeleteExtendedPersistentHideRule
These API calls receive the same rule structure as basic API and
an additional parameter 'Rule Type', which can be
0 (USBDK_HIDER_RULE_DEFAULT) or 1 (USBDK_HIDER_RULE_DETERMINATIVE_TYPES)
Using extended API with USBDK_HIDER_RULE_DEFAULT produces exactly the
same result as using basic API.
Using USBDK_HIDER_RULE_DETERMINATIVE_TYPES forces different processing
of hiding rules:
Rule structure includes the same fields:
Class (bitmask of device types to match)
BCD
Vendor ID
Product ID
Hide specifier (0 or 1), 0 is terminal, 1 continues for next rule
Device type for each specific device is determined from device class as specified
in device descriptor and 'class' field in all the interface descriptors of all
device's configurations.
Supported classes are:
USB_DEVICE_CLASS_AUDIO (0x1) -> USB_DEVICE_CLASS_AUDIO
USB_DEVICE_CLASS_COMMUNICATIONS(0x2)
USB_DEVICE_CLASS_CDC_DATA(0xA)
USB_DEVICE_CLASS_WIRELESS_CONTROLLER(0xE0) -> USB_DEVICE_CLASS_COMMUNICATIONS
USB_DEVICE_CLASS_PRINTER(0x7) -> USB_DEVICE_CLASS_PRINTER
USB_DEVICE_CLASS_STORAGE(0x8) -> USB_DEVICE_CLASS_STORAGE
USB_DEVICE_CLASS_VIDEO(0xE) -> USB_DEVICE_CLASS_VIDEO
USB_DEVICE_CLASS_AUDIO_VIDEO(0x10) -> USB_DEVICE_CLASS_AUDIO, USB_DEVICE_CLASS_VIDEO
USB_DEVICE_CLASS_HUMAN_INTERFACE(0x3) -> USB_DEVICE_CLASS_HUMAN_INTERFACE
All other classes -> OTHER (31)
Following classes are determinative (if the device belongs to one
of determinative types, all device types except of
determinative one are removed from device type bitmask):
The order of determinative types is:
USB_DEVICE_CLASS_PRINTER
USB_DEVICE_CLASS_COMMUNICATIONS
USB_DEVICE_CLASS_AUDIO
USB_DEVICE_CLASS_VIDEO
Checkers for these rules check resulting set of device type and
device types of interfaces in multifunction devices, i.e.
Class match = (device type bitmask) & (rule class bitmask) != 0
Example of usage:
Rule.BCD = Rule.VID = Rule.PID = -1;
Rule.Hide = 1;
Rule.Class = (1 << USB_DEVICE_CLASS_STORAGE) | (1 << USB_DEVICE_CLASS_PRINTER);
UsbDk_AddExtendedPersistentHideRule(&Rule, USBDK_HIDER_RULE_DETERMINATIVE_TYPES);
This call will Hide all the device that determined as being mass storage
devices or printer devices.

View file

@ -1,6 +1,4 @@
Maintained by Daynix Computing
Maintained by Dmitry Fleytman
------------------------------
M: Yuri Benditovich <yuri.benditovich@daynix.com>
M: Yuri Benditovich <ybendito@redhat.com>
M: Yan Vugenfirer <yan@daynix.com>
M: Yan Vugenfirer <yvugenfi@redhat.com>
M: Dmitry Fleytman <dfleytma@redhat.com>
M: Dmitry Fleytman <dmitry@daynix.com>

View file

@ -1,4 +1,4 @@
[![Build Status](https://ci.appveyor.com/api/projects/status/p3s6bdbx8mq8o0hu?svg=true)](https://ci.appveyor.com/api/projects/status/p3s6bdbx8mq8o0hu?svg=true)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/daynix/usbdk?branch=master&svg=true)](https://ci.appveyor.com/project/daynix/usbdk)
# UsbDk

View file

@ -1,5 +0,0 @@
@echo off
pushd "%~dp0"
curl -L -s https://drive.google.com/uc?id=17ZK6a1kxhTR-YOkWpAOqNJZA7UBUGkmu --output Microsoft.DriverKit.Build.Tasks.14.0.dll
copy /y Microsoft.DriverKit.Build.Tasks.14.0.dll "C:\Program Files (x86)\Windows Kits\10\build\bin"
popd

View file

@ -1,31 +0,0 @@
<!--
***********************************************************************************************
Driver.Initial.props
Should be imported just after Microsoft.Cpp.Default.props
and after target Windows versions defined for configurations
Common property definitions used by all drivers:
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="Platform">
<Target Name="IntermediateNotify" BeforeTargets="PrepareForBuild" AfterTargets="DriverBuildNotifications">
<!-- Indicate to users what they are building -->
<Message Importance="high" Text="Driver.Initial.props: TargetVersion=$(TargetVersion) _NT_TARGET_VERSION=$(_NT_TARGET_VERSION) SUBSYSTEM_NATVER=$(SUBSYSTEM_NATVER) mismatch=$(MidlTargetMismatch)" />
</Target>
<PropertyGroup Condition="'$(TargetVersion)'=='Windows10'">
<_NT_TARGET_VERSION>0x0A00</_NT_TARGET_VERSION>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetVersion)'=='WindowsV6.3'">
<_NT_TARGET_VERSION>0x0603</_NT_TARGET_VERSION>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetVersion)'=='Windows8'">
<_NT_TARGET_VERSION>0x0602</_NT_TARGET_VERSION>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetVersion)'=='Windows7'">
<_NT_TARGET_VERSION>0x0601</_NT_TARGET_VERSION>
</PropertyGroup>
</Project>

View file

@ -117,11 +117,9 @@
</Directory>
</Directory>
<Property Id="MSGBOX" Value=" " />
<CustomAction Id="InstallDriver"
Directory="UsbDk_Directory"
ExeCommand="[UsbDk_Directory]\UsbDkInstHelper.exe i[MSGBOX]"
ExeCommand="[UsbDk_Directory]\UsbDkInstHelper.exe i"
Execute="deferred"
Impersonate="no"
Return="check">

View file

@ -9,9 +9,9 @@ pushd ..\..\Install_Debug\x86
del *.msi *.wixobj *.wixpdb
"%WIX%bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk_Debug.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=%DEBUG_CFG%
"C:\Program Files (x86)\WiX Toolset v3.8\bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk_Debug.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=%DEBUG_CFG%
if !ERRORLEVEL! NEQ 0 exit /B 1
"%WIX%bin\light.exe" UsbDk_Debug.wixobj -out UsbDk_Debug_%UsbDkVersion%_x86.msi -sw1076
"C:\Program Files (x86)\WiX Toolset v3.8\bin\light.exe" UsbDk_Debug.wixobj -out UsbDk_Debug_%UsbDkVersion%_x86.msi -sw1076
if !ERRORLEVEL! NEQ 0 exit /B 1
popd
@ -20,9 +20,9 @@ pushd ..\..\Install_Debug\x64
del *.msi *.wixobj *.wixpdb
"%WIX%bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk_Debug.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=%DEBUG_CFG% -dUsbDk64Bit=1
"C:\Program Files (x86)\WiX Toolset v3.8\bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk_Debug.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=%DEBUG_CFG% -dUsbDk64Bit=1
if !ERRORLEVEL! NEQ 0 exit /B 1
"%WIX%bin\light.exe" UsbDk_Debug.wixobj -out UsbDk_Debug_%UsbDkVersion%_x64.msi -sw1076
"C:\Program Files (x86)\WiX Toolset v3.8\bin\light.exe" UsbDk_Debug.wixobj -out UsbDk_Debug_%UsbDkVersion%_x64.msi -sw1076
if !ERRORLEVEL! NEQ 0 exit /B 1
popd
@ -31,9 +31,9 @@ pushd ..\..\Install\x86
del *.msi *.wixobj *.wixpdb
"%WIX%bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=Release
"C:\Program Files (x86)\WiX Toolset v3.8\bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=Release
if !ERRORLEVEL! NEQ 0 exit /B 1
"%WIX%bin\light.exe" UsbDk.wixobj -out UsbDk_%UsbDkVersion%_x86.msi -sw1076
"C:\Program Files (x86)\WiX Toolset v3.8\bin\light.exe" UsbDk.wixobj -out UsbDk_%UsbDkVersion%_x86.msi -sw1076
if !ERRORLEVEL! NEQ 0 exit /B 1
popd
@ -42,9 +42,9 @@ pushd ..\..\Install\x64
del *.msi *.wixobj *.wixpdb
"%WIX%bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=Release -dUsbDk64Bit=1
"C:\Program Files (x86)\WiX Toolset v3.8\bin\candle.exe" ..\..\Tools\Installer\UsbDkInstaller.wxs -out UsbDk.wixobj -dUsbDkVersion=%UsbDkVersion% -dConfig=Release -dUsbDk64Bit=1
if !ERRORLEVEL! NEQ 0 exit /B 1
"%WIX%bin\light.exe" UsbDk.wixobj -out UsbDk_%UsbDkVersion%_x64.msi -sw1076
"C:\Program Files (x86)\WiX Toolset v3.8\bin\light.exe" UsbDk.wixobj -out UsbDk_%UsbDkVersion%_x64.msi -sw1076
if !ERRORLEVEL! NEQ 0 exit /B 1
popd

View file

@ -381,7 +381,6 @@
<DriverType>Package</DriverType>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
<Import Project="..\Tools\Driver.Initial.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>

View file

@ -314,35 +314,15 @@ void CUsbDkControlDevice::UnregisterHiddenDevice(CUsbDkFilterDevice &FilterDevic
m_HiddenDevices.Remove(&FilterDevice);
}
bool CUsbDkControlDevice::ShouldHideDevice(CUsbDkChildDevice &Device) const
bool CUsbDkControlDevice::ShouldHide(const USB_DEVICE_DESCRIPTOR &DevDescriptor) 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();
}
@ -352,29 +332,9 @@ bool CUsbDkControlDevice::ShouldHideDevice(CUsbDkChildDevice &Device) const
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;
@ -451,7 +411,7 @@ PDEVICE_OBJECT CUsbDkControlDevice::GetPDOByDeviceID(const USB_DK_DEVICE_ID &Dev
return PDO;
}
NTSTATUS CUsbDkControlDevice::ResetUsbDevice(const USB_DK_DEVICE_ID &DeviceID, bool ForceD0)
NTSTATUS CUsbDkControlDevice::ResetUsbDevice(const USB_DK_DEVICE_ID &DeviceID)
{
PDEVICE_OBJECT PDO = GetPDOByDeviceID(DeviceID);
if (PDO == nullptr)
@ -460,7 +420,7 @@ NTSTATUS CUsbDkControlDevice::ResetUsbDevice(const USB_DK_DEVICE_ID &DeviceID, b
}
CWdmUsbDeviceAccess pdoAccess(PDO);
auto status = pdoAccess.Reset(ForceD0);
auto status = pdoAccess.Reset();
ObDereferenceObject(PDO);
return status;
@ -707,7 +667,7 @@ void CUsbDkControlDevice::AddRedirectRollBack(const USB_DK_DEVICE_ID &DeviceId,
return;
}
auto resetRes = ResetUsbDevice(DeviceId, false);
auto resetRes = ResetUsbDevice(DeviceId);
if (!NT_SUCCESS(resetRes))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! Roll-back reset failed. %!STATUS!", resetRes);
@ -731,13 +691,11 @@ NTSTATUS CUsbDkControlDevice::AddRedirect(const USB_DK_DEVICE_ID &DeviceId, HAND
{
return addRes;
}
Redirection->AddRef();
CObjHolder<CUsbDkRedirection, CRefCountingDeleter> dereferencer(Redirection);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE, "%!FUNC! Success. New redirections list:");
m_Redirections.Dump();
auto resetRes = ResetUsbDevice(DeviceId, true);
auto resetRes = ResetUsbDevice(DeviceId);
if (!NT_SUCCESS(resetRes))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_CONTROLDEVICE, "%!FUNC! Reset after start redirection failed. %!STATUS!", resetRes);
@ -857,14 +815,6 @@ public:
return status;
}
DWORD32 val;
status = ReadDwordValue(USBDK_HIDE_RULE_TYPE, val);
if (!NT_SUCCESS(status))
{
return status;
}
Rule.Type = val;
status = ReadDwordMaskValue(USBDK_HIDE_RULE_VID, Rule.VID);
if (!NT_SUCCESS(status))
{
@ -961,7 +911,6 @@ private:
NTSTATUS CUsbDkControlDevice::ReloadPersistentHideRules()
{
m_PersistentHideRules.Clear();
m_PersistentExtHideRules.Clear();
CHideRulesRegKey RulesKey;
auto status = RulesKey.Open();
@ -1029,7 +978,7 @@ NTSTATUS CUsbDkControlDevice::RemoveRedirect(const USB_DK_DEVICE_ID &DeviceId)
{
if (NotifyRedirectorRemovalStarted(DeviceId))
{
auto res = ResetUsbDevice(DeviceId, false);
auto res = ResetUsbDevice(DeviceId);
if (NT_SUCCESS(res))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE,
@ -1081,8 +1030,7 @@ bool CUsbDkControlDevice::NotifyRedirectorAttached(CRegText *DeviceID, CRegText
bool CUsbDkControlDevice::NotifyRedirectorRemovalStarted(const USB_DK_DEVICE_ID &ID)
{
ULONG pid = (ULONG)(ULONG_PTR)PsGetCurrentProcessId();
return m_Redirections.ModifyOne(&ID, [](CUsbDkRedirection *R){ R->NotifyRedirectionRemovalStarted(); }, pid);
return m_Redirections.ModifyOne(&ID, [](CUsbDkRedirection *R){ R->NotifyRedirectionRemovalStarted(); });
}
bool CUsbDkControlDevice::WaitForDetachment(const USB_DK_DEVICE_ID &ID)
@ -1113,20 +1061,13 @@ NTSTATUS CUsbDkRedirection::Create(const USB_DK_DEVICE_ID &Id)
return m_InstanceID.Create(Id.InstanceID);
}
void CUsbDkRedirection::Dump(LPCSTR message) const
void CUsbDkRedirection::Dump() const
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE,
"%!FUNC! %s DevID: %wZ, InstanceID: %wZ",
message,
"%!FUNC! Redirect: DevID: %wZ, InstanceID: %wZ",
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");
@ -1207,18 +1148,9 @@ NTSTATUS CUsbDkRedirection::CreateRedirectorHandle(HANDLE RequestorProcess, PHAN
do
{
if (IsPreparedForRemove())
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_WDFDEVICE, "%!FUNC!: device already marked for removal");
status = STATUS_DEVICE_REMOVED;
break;
}
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;
}
@ -1229,10 +1161,9 @@ NTSTATUS CUsbDkRedirection::CreateRedirectorHandle(HANDLE RequestorProcess, PHAN
return status;
}
LONG CUsbDkHideRule::m_defaultDumpLevel = TRACE_LEVEL_INFORMATION;
void CUsbDkHideRule::Dump(LONG traceLevel) const
void CUsbDkHideRule::Dump() const
{
TraceEvents(traceLevel, TRACE_CONTROLDEVICE, "%!FUNC! Hide: %!bool!, C: %08X, V: %08X, P: %08X, BCD: %08X",
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);
}
@ -1267,29 +1198,3 @@ void CDriverParamsRegistryPath::Destroy()
}
CDriverParamsRegistryPath::CAllocatablePath *CDriverParamsRegistryPath::m_Path = nullptr;
NTSTATUS CUsbDkControlDevice::AddHideRule(const USB_DK_HIDE_RULE &UsbDkRule)
{
if (UsbDkRule.Type == USBDK_HIDER_RULE_DEFAULT)
{
return AddHideRuleToSet(UsbDkRule, m_HideRules);
}
else if (UsbDkRule.Type == USBDK_HIDER_RULE_DETERMINATIVE_TYPES)
{
return AddHideRuleToSet(UsbDkRule, m_ExtHideRules);
}
return STATUS_INVALID_PARAMETER;
}
NTSTATUS CUsbDkControlDevice::AddPersistentHideRule(const USB_DK_HIDE_RULE &UsbDkRule)
{
if (UsbDkRule.Type == USBDK_HIDER_RULE_DEFAULT)
{
return AddHideRuleToSet(UsbDkRule, m_PersistentHideRules);
}
else if (UsbDkRule.Type == USBDK_HIDER_RULE_DETERMINATIVE_TYPES)
{
return AddHideRuleToSet(UsbDkRule, m_PersistentExtHideRules);
}
return STATUS_INVALID_PARAMETER;
}

View file

@ -117,14 +117,6 @@ 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;
@ -146,7 +138,7 @@ public:
}
void Dump(LONG traceLevel = m_defaultDumpLevel) const;
void Dump() const;
private:
bool MatchCharacteristic(ULONG CharacteristicFilter, ULONG CharacteristicValue) const
@ -160,7 +152,7 @@ private:
ULONG m_VID;
ULONG m_PID;
ULONG m_BCD;
static LONG m_defaultDumpLevel;
DECLARE_CWDMLIST_ENTRY(CUsbDkHideRule);
};
@ -178,7 +170,7 @@ public:
bool operator==(const CUsbDkChildDevice &Dev) const;
bool operator==(const CUsbDkRedirection &Other) const;
void Dump(LPCSTR message = " ") const;
void Dump() const;
void NotifyRedirectorCreated(CUsbDkFilterDevice *RedirectorDevice);
void NotifyRedirectionRemoved();
@ -190,8 +182,6 @@ public:
bool IsPreparedForRemove() const
{ return m_RemovalInProgress; }
bool MatchProcess(ULONG pid);
NTSTATUS WaitForAttachment()
{ return m_RedirectionCreated.Wait(true, -SecondsTo100Nanoseconds(120)); }
@ -202,7 +192,6 @@ public:
private:
~CUsbDkRedirection()
{
Dump("Deleting ");
if (m_RedirectorDevice != nullptr)
{
m_RedirectorDevice->Release();
@ -218,7 +207,6 @@ private:
CWdmEvent m_RedirectionCreated;
CWdmEvent m_RedirectionRemoved;
CUsbDkFilterDevice *m_RedirectorDevice = nullptr;
ULONG m_OwnerPid = 0;
bool m_RemovalInProgress = false;
@ -266,11 +254,13 @@ public:
{ return ReloadPersistentHideRules(); }
bool EnumerateDevices(USB_DK_DEVICE_INFO *outBuff, size_t numberAllocatedDevices, size_t &numberExistingDevices);
NTSTATUS ResetUsbDevice(const USB_DK_DEVICE_ID &DeviceId, bool ForceD0);
NTSTATUS ResetUsbDevice(const USB_DK_DEVICE_ID &DeviceId);
NTSTATUS AddRedirect(const USB_DK_DEVICE_ID &DeviceId, HANDLE RequestorProcess, PHANDLE ObjectHandle);
NTSTATUS AddHideRule(const USB_DK_HIDE_RULE &UsbDkRule);
NTSTATUS AddPersistentHideRule(const USB_DK_HIDE_RULE &UsbDkRule);
NTSTATUS AddHideRule(const USB_DK_HIDE_RULE &UsbDkRule)
{ return AddHideRuleToSet(UsbDkRule, m_HideRules); }
NTSTATUS AddPersistentHideRule(const USB_DK_HIDE_RULE &UsbDkRule)
{ return AddHideRuleToSet(UsbDkRule, m_PersistentHideRules); }
void ClearHideRules();
@ -298,8 +288,7 @@ public:
return !DontRedirect;
}
bool ShouldHideDevice(CUsbDkChildDevice &Device) const;
bool ShouldHide(const USB_DK_DEVICE_ID &DevId);
bool ShouldHide(const USB_DEVICE_DESCRIPTOR &DevDescriptor) const;
template <typename TDevID>
void NotifyRedirectionRemoved(const TDevID &Dev) const
@ -331,8 +320,6 @@ private:
typedef CWdmSet<CUsbDkHideRule, CLockedAccess, CNonCountingObject> HideRulesSet;
HideRulesSet m_HideRules;
HideRulesSet m_PersistentHideRules;
HideRulesSet m_ExtHideRules;
HideRulesSet m_PersistentExtHideRules;
NTSTATUS AddHideRuleToSet(const USB_DK_HIDE_RULE &UsbDkRule, HideRulesSet &Set);

View file

@ -168,41 +168,6 @@ SIZE_T CWdmDeviceAccess::GetIdBufferLength(BUS_QUERY_ID_TYPE idType, PWCHAR idDa
}
}
bool CWdmDeviceAccess::QueryPowerData(CM_POWER_DATA& powerData)
{
powerData.PD_Size = sizeof(powerData);
#if !TARGET_OS_WIN_XP
ULONG dummy;
DEVPROPTYPE propType;
auto status = IoGetDevicePropertyData(m_DevObj, &DEVPKEY_Device_PowerData, LOCALE_NEUTRAL, 0,
sizeof(powerData), &powerData, &dummy, &propType);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_DEVACCESS, "%!FUNC! Error %!STATUS!", status);
}
return NT_SUCCESS(status);
#else
return false;
#endif
}
static void PowerRequestCompletion(
_In_ PDEVICE_OBJECT DeviceObject,
_In_ UCHAR MinorFunction,
_In_ POWER_STATE PowerState,
_In_opt_ PVOID Context,
_In_ PIO_STATUS_BLOCK IoStatus
)
{
UNREFERENCED_PARAMETER(DeviceObject);
UNREFERENCED_PARAMETER(MinorFunction);
UNREFERENCED_PARAMETER(PowerState);
UNREFERENCED_PARAMETER(IoStatus);
CWdmEvent *pev = (CWdmEvent *)Context;
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVACCESS, "%!FUNC! -> D%d", PowerState.DeviceState - 1);
pev->Set();
}
PWCHAR CWdmDeviceAccess::MakeNonPagedDuplicate(BUS_QUERY_ID_TYPE idType, PWCHAR idData)
{
auto bufferLength = GetIdBufferLength(idType, idData);
@ -250,23 +215,9 @@ NTSTATUS CWdmDeviceAccess::QueryForInterface(const GUID &guid, __out INTERFACE &
return status;
}
NTSTATUS CWdmUsbDeviceAccess::Reset(bool ForceD0)
NTSTATUS CWdmUsbDeviceAccess::Reset()
{
CIoControlIrp Irp;
CM_POWER_DATA powerData;
if (ForceD0 && QueryPowerData(powerData) && powerData.PD_MostRecentPowerState != PowerDeviceD0)
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVACCESS, "%!FUNC! device power state D%d", powerData.PD_MostRecentPowerState - 1);
POWER_STATE PowerState;
CWdmEvent Event;
PowerState.DeviceState = PowerDeviceD0;
auto status = PoRequestPowerIrp(m_DevObj, IRP_MN_SET_POWER, PowerState, PowerRequestCompletion, &Event, NULL);
if (NT_SUCCESS(status))
{
Event.Wait();
}
}
auto status = Irp.Create(m_DevObj, IOCTL_INTERNAL_USB_CYCLE_PORT);
if (!NT_SUCCESS(status))

View file

@ -52,7 +52,7 @@ public:
ULONG GetAddress();
CRegText *GetDeviceID() { return new CRegSz(QueryBusID(BusQueryDeviceID)); }
CRegText *GetInstanceID() { return new CRegSz(QueryBusID(BusQueryInstanceID)); }
bool QueryPowerData(CM_POWER_DATA& powerData);
protected:
PDEVICE_OBJECT m_DevObj;
@ -71,7 +71,7 @@ public:
: CWdmDeviceAccess(WdmDevice)
{ }
NTSTATUS Reset(bool ForceD0);
NTSTATUS Reset();
NTSTATUS GetDeviceDescriptor(USB_DEVICE_DESCRIPTOR &Descriptor);
NTSTATUS GetConfigurationDescriptor(UCHAR Index, USB_CONFIGURATION_DESCRIPTOR &Descriptor, size_t Length);

View file

@ -83,11 +83,7 @@ NTSTATUS CUsbDkFilterDeviceInit::Configure(ULONG InstanceNumber)
SetIoInCallerContextCallback([](_In_ WDFDEVICE Device, WDFREQUEST Request)
{ return Strategy(Device)->IoInCallerContext(Device, Request); });
SetFileEventCallbacks([](_In_ WDFDEVICE Device, _In_ WDFREQUEST Request, _In_ WDFFILEOBJECT FileObject)
{
UNREFERENCED_PARAMETER(FileObject);
UsbDkFilterGetContext(Device)->UsbDkFilter->OnFileCreate(Request);
},
SetFileEventCallbacks(WDF_NO_EVENT_CALLBACK,
[](_In_ WDFFILEOBJECT FileObject)
{
WDFDEVICE Device = WdfFileObjectGetDevice(FileObject);
@ -318,33 +314,8 @@ void CUsbDkHubFilterStrategy::RegisterNewChild(PDEVICE_OBJECT PDO)
{
CWdmUsbDeviceAccess pdoAccess(PDO);
// in case when the device is composite and one of interfaces installed
// under USB class and creates child device (example is composite USB with
// more than one interface and one of them is CD) the PDO can be non-USB
// device. Sending USB requests to it may be problematic as sending URB
// is just internal device control with trivial IOCTL code.
// Before trying to initialize it as USB device we check it is really one.
CObjHolder<CRegText> DevID;
CObjHolder<CRegText> InstanceID;
if (!UsbDkGetWdmDeviceIdentity(PDO, &DevID, &InstanceID))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Cannot query device identity");
return;
}
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Registering new child (PDO: %p):", PDO);
DevID->Dump();
InstanceID->Dump();
// Not a USB device -> do not register
if (!DevID->MatchPrefix(L"USB\\"))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Not a usb device, skip child registration");
return;
}
auto Port = pdoAccess.GetAddress();
if (Port == CWdmDeviceAccess::NO_ADDRESS)
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Cannot read device port number");
@ -366,14 +337,24 @@ void CUsbDkHubFilterStrategy::RegisterNewChild(PDEVICE_OBJECT PDO)
return;
}
#if (NTDDI_VERSION == NTDDI_WIN7)
// recheck on Win7, superspeed indication as on Win8 might be not available
if (Speed == HighSpeed && DevDescriptor.bcdUSB >= 0x300)
CObjHolder<CRegText> DevID;
CObjHolder<CRegText> InstanceID;
if (!UsbDkGetWdmDeviceIdentity(PDO, &DevID, &InstanceID))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! superspeed assigned according to BCD field");
Speed = SuperSpeed;
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Cannot query device identity");
return;
}
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Registering new child (PDO: %p):", PDO);
DevID->Dump();
InstanceID->Dump();
// Not a USB device -> do not register
if (!DevID->MatchPrefix(L"USB\\"))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Not a usb device, skip child registration");
return;
}
#endif
CUsbDkChildDevice::TDescriptorsCache CfgDescriptors(DevDescriptor.bNumConfigurations);
@ -443,7 +424,7 @@ bool CUsbDkHubFilterStrategy::FetchConfigurationDescriptors(CWdmUsbDeviceAccess
void CUsbDkHubFilterStrategy::ApplyRedirectionPolicy(CUsbDkChildDevice &Device)
{
if (m_ControlDevice->ShouldRedirect(Device) ||
m_ControlDevice->ShouldHideDevice(Device))
m_ControlDevice->ShouldHide(Device.DeviceDescriptor()))
{
if (Device.AttachToDeviceStack())
{
@ -479,23 +460,6 @@ bool CUsbDkChildDevice::AttachToDeviceStack()
return true;
}
void CUsbDkFilterDevice::OnFileCreate(WDFREQUEST Request)
{
CWdfRequest r(Request);
WdfRequestFormatRequestUsingCurrentType(Request);
// in the log we'll see which process created the file
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC!");
r.SendWithCompletion(IOTarget(), [](WDFREQUEST Request, WDFIOTARGET Target, PWDF_REQUEST_COMPLETION_PARAMS Params, WDFCONTEXT Context)
{
UNREFERENCED_PARAMETER(Target);
CWdfRequest r(Request);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%s: completed", (LPCSTR)Context);
r.SetStatus(Params->IoStatus.Status);
r.SetBytesWritten(Params->IoStatus.Information);
},
__FUNCTION__);
}
NTSTATUS CUsbDkFilterDevice::AttachToStack(WDFDRIVER Driver)
{
PAGED_CODE();
@ -667,7 +631,7 @@ bool CUsbDkFilterDevice::CStrategist::SelectStrategy(PDEVICE_OBJECT DevObj)
}
// Should be hidden -> hider strategy
if (m_Strategy->GetControlDevice()->ShouldHide(ID))
if (m_Strategy->GetControlDevice()->ShouldHide(DevDescr))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "%!FUNC! Assigning hidden USB device strategy");
m_Strategy->Delete();
@ -687,115 +651,3 @@ size_t CUsbDkFilterDevice::CStrategist::GetRequestContextSize()
max(CUsbDkHubFilterStrategy::GetRequestContextSize(),
CUsbDkRedirectorStrategy::GetRequestContextSize()));
}
static ULONG InterfaceTypeMask(UCHAR bClass) {
switch (bClass) {
case USB_DEVICE_CLASS_AUDIO:
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "Class 0x%X -> audio", bClass);
return 1 << USB_DEVICE_CLASS_AUDIO;
case USB_DEVICE_CLASS_COMMUNICATIONS:
case USB_DEVICE_CLASS_CDC_DATA:
case USB_DEVICE_CLASS_WIRELESS_CONTROLLER:
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "Class 0x%X -> network", bClass);
return 1 << USB_DEVICE_CLASS_COMMUNICATIONS;
case USB_DEVICE_CLASS_PRINTER:
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "Class 0x%X -> printer", bClass);
return 1 << USB_DEVICE_CLASS_PRINTER;
case USB_DEVICE_CLASS_STORAGE:
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "Class 0x%X -> storage", bClass);
return 1 << USB_DEVICE_CLASS_STORAGE;
case USB_DEVICE_CLASS_VIDEO:
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "Class 0x%X -> video", bClass);
return 1 << USB_DEVICE_CLASS_VIDEO;
case USB_DEVICE_CLASS_AUDIO_VIDEO:
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "Class 0x%X -> audio/video", bClass);
return (1 << USB_DEVICE_CLASS_VIDEO) |
(1 << USB_DEVICE_CLASS_AUDIO);
case USB_DEVICE_CLASS_HUB:
return (1 << USB_DEVICE_CLASS_HUB);
case USB_DEVICE_CLASS_HUMAN_INTERFACE:
return (1 << USB_DEVICE_CLASS_HUMAN_INTERFACE);
default:
return 1U << 31;
}
}
static PUSB_INTERFACE_DESCRIPTOR FindNextInterface(PUSB_CONFIGURATION_DESCRIPTOR cfg, ULONG& offset)
{
PUSB_COMMON_DESCRIPTOR desc;
if (offset >= cfg->wTotalLength)
return NULL;
do {
if (offset + sizeof(*desc) > cfg->wTotalLength)
return NULL;
desc = (PUSB_COMMON_DESCRIPTOR)((PUCHAR)cfg + offset);
if (desc->bLength + offset > cfg->wTotalLength)
return NULL;
offset += desc->bLength;
if (desc->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE) {
return (PUSB_INTERFACE_DESCRIPTOR)desc;
}
} while (1);
}
void CUsbDkChildDevice::DetermineDeviceClasses()
{
if (m_DevDescriptor.bDeviceClass)
{
m_ClassMaskForExtHider |= InterfaceTypeMask(m_DevDescriptor.bDeviceClass);
}
USB_CONFIGURATION_DESCRIPTOR cfg;
for (UCHAR index = 0; index < m_CfgDescriptors.Size(); ++index)
{
if (ConfigurationDescriptor(index, cfg, sizeof(cfg)))
{
PVOID buffer = ExAllocatePoolWithTag(USBDK_NON_PAGED_POOL, cfg.wTotalLength, 'CFGD');
if (buffer)
{
USB_CONFIGURATION_DESCRIPTOR *p = (USB_CONFIGURATION_DESCRIPTOR *)buffer;
if (ConfigurationDescriptor(index, *p, cfg.wTotalLength))
{
ULONG offset = 0;
PUSB_INTERFACE_DESCRIPTOR intf_desc;
while (true)
{
intf_desc = FindNextInterface(p, offset);
if (!intf_desc)
break;
m_ClassMaskForExtHider |= InterfaceTypeMask(intf_desc->bInterfaceClass);
}
}
ExFreePool(buffer);
}
}
}
#define SINGLE_DETERMINATIVE_CLASS
#if defined(SINGLE_DETERMINATIVE_CLASS)
// only one determinative type present in final mask
if (m_ClassMaskForExtHider & (1 << USB_DEVICE_CLASS_PRINTER))
{
m_ClassMaskForExtHider = 1 << USB_DEVICE_CLASS_PRINTER;
}
else if (m_ClassMaskForExtHider & (1 << USB_DEVICE_CLASS_COMMUNICATIONS))
{
m_ClassMaskForExtHider = 1 << USB_DEVICE_CLASS_COMMUNICATIONS;
}
else if (m_ClassMaskForExtHider & ((1 << USB_DEVICE_CLASS_AUDIO) | (1 << USB_DEVICE_CLASS_VIDEO)))
{
m_ClassMaskForExtHider &= (1 << USB_DEVICE_CLASS_AUDIO) | (1 << USB_DEVICE_CLASS_VIDEO);
}
#else
// all the determinative types present in final mask
ULONG determinativeMask =
(1 << USB_DEVICE_CLASS_PRINTER) |
(1 << USB_DEVICE_CLASS_COMMUNICATIONS) |
(1 << USB_DEVICE_CLASS_AUDIO) |
(1 << USB_DEVICE_CLASS_VIDEO);
if (m_ClassMaskForExtHider & determinativeMask)
{
m_ClassMaskForExtHider &= determinativeMask;
}
#endif
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FILTERDEVICE, "Class mask %08X", m_ClassMaskForExtHider);
}

View file

@ -65,10 +65,8 @@ public:
, m_CfgDescriptors(CfgDescriptors)
, m_ParentDevice(ParentDevice)
, m_PDO(PDO)
, m_ClassMaskForExtHider(0)
{
DetermineDeviceClasses();
}
{}
ULONG ParentID() const;
PCWCHAR DeviceID() const { return *m_DeviceID->begin(); }
PCWCHAR InstanceID() const { return *m_InstanceID->begin(); }
@ -79,8 +77,6 @@ public:
const USB_DEVICE_DESCRIPTOR &DeviceDescriptor() const
{ return m_DevDescriptor; }
PDEVICE_OBJECT PDO() const { return m_PDO; }
ULONG ClassesBitMask() const
{ return m_ClassMaskForExtHider; }
bool ConfigurationDescriptor(UCHAR Index, USB_CONFIGURATION_DESCRIPTOR &Buffer, size_t BufferLength)
{
@ -111,12 +107,10 @@ private:
TDescriptorsCache m_CfgDescriptors;
PDEVICE_OBJECT m_PDO;
const CUsbDkFilterDevice &m_ParentDevice;
ULONG m_ClassMaskForExtHider;
CUsbDkChildDevice(const CUsbDkChildDevice&) = delete;
CUsbDkChildDevice& operator= (const CUsbDkChildDevice&) = delete;
void DetermineDeviceClasses();
DECLARE_CWDMLIST_ENTRY(CUsbDkChildDevice);
};
@ -175,7 +169,6 @@ public:
void SetSerialNumber(ULONG Number)
{ m_SerialNumber = Number; }
void OnFileCreate(WDFREQUEST Request);
private:
~CUsbDkFilterDevice()
{

View file

@ -31,7 +31,6 @@
#define USBDK_HIDE_RULE_PID TEXT("PID")
#define USBDK_HIDE_RULE_BCD TEXT("BCD")
#define USBDK_HIDE_RULE_CLASS TEXT("Class")
#define USBDK_HIDE_RULE_TYPE TEXT("Type")
#define USBDK_HIDE_RULES_PATH TEXT("SYSTEM\\CurrentControlSet\\Services\\") \
USBDK_DRIVER_NAME TEXT("\\") \

View file

@ -630,7 +630,6 @@ void CUsbDkRedirectorStrategy::OnClose()
{
USB_DK_DEVICE_ID ID;
UsbDkFillIDStruct(&ID, *m_DeviceID->begin(), *m_InstanceID->begin());
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_REDIRECTOR, "%!FUNC!");
auto status = m_ControlDevice->RemoveRedirect(ID);
if (!NT_SUCCESS(status))

View file

@ -71,16 +71,5 @@ NTSTATUS CIsochronousUrb::Create(Direction TransferDirection, PVOID TransferBuff
m_Urb->UrbIsochronousTransfer.TransferBuffer = TransferBuffer;
m_Urb->UrbIsochronousTransfer.NumberOfPackets = static_cast<ULONG>(NumberOfPackets);
if (TransferDirection == URB_DIRECTION_OUT)
{
// initialize Length with initial packet length
// USB controller driver may override it (Win7)
for (size_t i = 0; i < NumberOfPackets; i++)
{
m_Urb->UrbIsochronousTransfer.IsoPacket[i].Length = static_cast<ULONG>(PacketSizes[i]);
}
}
return FillOffsetsArray(NumberOfPackets, PacketSizes, TransferBufferSize);
}

View file

@ -1178,7 +1178,6 @@
<KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR>
<KMDF_VERSION_MINOR>11</KMDF_VERSION_MINOR>
</PropertyGroup>
<Import Project="..\Tools\Driver.Initial.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>

View file

@ -23,26 +23,13 @@
#pragma once
#include "UsbDkDataHiderPublic.h"
#define USB_DK_HIDE_RULE_MATCH_ALL ((ULONG64)(-1))
#ifdef __cplusplus
class USB_DK_HIDE_RULE : public USB_DK_HIDE_RULE_PUBLIC
typedef struct tag_USB_DK_HIDE_RULE
{
public:
USB_DK_HIDE_RULE(PUSB_DK_HIDE_RULE_PUBLIC PublicRule = NULL, ULONG RuleType = USBDK_HIDER_RULE_DEFAULT) :
Type(RuleType)
{
if (PublicRule)
{
Hide = PublicRule->Hide;
Class = PublicRule->Class;
VID = PublicRule->VID;
PID = PublicRule->PID;
BCD = PublicRule->BCD;
}
}
ULONG64 Type;
};
typedef USB_DK_HIDE_RULE *PUSB_DK_HIDE_RULE;
#endif
ULONG64 Hide;
ULONG64 Class;
ULONG64 VID;
ULONG64 PID;
ULONG64 BCD;
} USB_DK_HIDE_RULE, *PUSB_DK_HIDE_RULE;

View file

@ -1,38 +0,0 @@
/**********************************************************************
* Copyright (c) 2013-2014 Red Hat, Inc.
*
* Developed by Daynix Computing LTD.
*
* Authors:
* Dmitry Fleytman <dmitry@daynix.com>
* Kirill Moizik <kirill@daynix.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************/
#pragma once
#define USB_DK_HIDE_RULE_MATCH_ALL ((ULONG64)(-1))
typedef struct tag_USB_DK_HIDE_RULE_PUBLIC
{
ULONG64 Hide;
ULONG64 Class;
ULONG64 VID;
ULONG64 PID;
ULONG64 BCD;
} USB_DK_HIDE_RULE_PUBLIC, *PUSB_DK_HIDE_RULE_PUBLIC;
#define USBDK_HIDER_RULE_DEFAULT 0
#define USBDK_HIDER_RULE_DETERMINATIVE_TYPES 1

View file

@ -411,18 +411,10 @@ public:
}
template <typename TEntryId, typename TModifier>
bool ModifyOne(TEntryId *Id, TModifier ModifierFunc, ULONG process = 0)
bool ModifyOne(TEntryId *Id, TModifier ModifierFunc)
{
CLockedContext<TAccessStrategy> LockedContext(*this);
return !m_Objects.ForEachIf([Id,process](TEntryType *ExistingEntry)
{
bool match = *ExistingEntry == *Id;
if (process && match)
{
match = ExistingEntry->MatchProcess(process);
}
return match;
},
return !m_Objects.ForEachIf([Id](TEntryType *ExistingEntry) { return *ExistingEntry == *Id; },
[&ModifierFunc](TEntryType *Entry) { ModifierFunc(Entry); return false; });
}

View file

@ -16,20 +16,7 @@ extern "C"
#include <usb.h>
#if !TARGET_OS_WIN_XP
#include <initguid.h>
#include <UsbSpec.h>
#include <devpkey.h>
#else
#define USB_DEVICE_CLASS_AUDIO 0x01
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
#define USB_DEVICE_CLASS_PRINTER 0x07
#define USB_DEVICE_CLASS_STORAGE 0x08
#define USB_DEVICE_CLASS_HUB 0x09
#define USB_DEVICE_CLASS_CDC_DATA 0x0A
#define USB_DEVICE_CLASS_VIDEO 0x0E
#define USB_DEVICE_CLASS_AUDIO_VIDEO 0x10
#define USB_DEVICE_CLASS_WIRELESS_CONTROLLER 0xE0
#endif
#include <wdfusb.h>

View file

@ -45,15 +45,12 @@ static void ShowUsage()
tcout << endl;
tcout << TEXT(" Hider API:") << endl;
tcout << endl;
tcout << TEXT(" UsbDkController -H TYPE VID PID BCD Class Hide - add dynamic hide rule") << endl;
tcout << TEXT(" UsbDkController -P TYPE VID PID BCD Class Hide - add persistent hide rule") << endl;
tcout << TEXT(" UsbDkController -D TYPE VID PID BCD Class Hide - delete persistent hide rule") << endl;
tcout << TEXT(" UsbDkController -Z - delete all persistent hide rules") << endl;
tcout << TEXT(" UsbDkController -H VID PID BCD Class Hide - add dynamic hide rule") << endl;
tcout << TEXT(" UsbDkController -P VID PID BCD Class Hide - add persistent hide rule") << endl;
tcout << TEXT(" UsbDkController -D VID PID BCD Class Hide - delete persistent hide rule") << endl;
tcout << endl;
tcout << TEXT(" <VID PID BCD Class> May be specific value or -1 to match all") << endl;
tcout << TEXT(" <Hide> Should be 0 or 1, if 0, the rule is terminal") << endl;
tcout << TEXT(" <TYPE> Should be 0 for backward-compatible hide") << endl;
tcout << TEXT(" 1 for hide by determinative type") << endl;
tcout << endl;
}
@ -232,53 +229,48 @@ static bool Controller_ParseBoolRuleField(const TCHAR *Name, const TCHAR * Str,
return true;
}
static bool Controller_ParseRule(TCHAR *Type, TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide, USB_DK_HIDE_RULE &Rule)
static bool Controller_ParseRule(TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide, USB_DK_HIDE_RULE &Rule)
{
return Controller_ParseIntRuleField(TEXT("VID"), VID, Rule.VID) &&
Controller_ParseIntRuleField(TEXT("PID"), PID, Rule.PID) &&
Controller_ParseIntRuleField(TEXT("BCD"), BCD, Rule.BCD) &&
Controller_ParseIntRuleField(TEXT("Class"), UsbClass, Rule.Class) &&
Controller_ParseBoolRuleField(TEXT("Hide"), Hide, Rule.Hide) &&
Controller_ParseIntRuleField(TEXT("Type"), Type, Rule.Type);
Controller_ParseBoolRuleField(TEXT("Hide"), Hide, Rule.Hide);
}
static int Controller_AddPersistentHideRule(TCHAR *Type, TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide)
static int Controller_AddPersistentHideRule(TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide)
{
USB_DK_HIDE_RULE Rule;
if (!Controller_ParseRule(Type, VID, PID, BCD, UsbClass, Hide, Rule))
if (!Controller_ParseRule(VID, PID, BCD, UsbClass, Hide, Rule))
{
tcout << TEXT("Persistent hide rule parsing failed") << endl;
return false;
}
auto res = Type == USBDK_HIDER_RULE_DEFAULT ?
UsbDk_AddPersistentHideRule(&Rule) :
UsbDk_AddExtendedPersistentHideRule(&Rule, (ULONG)Rule.Type);
auto res = UsbDk_AddPersistentHideRule(&Rule);
return Controller_AnalyzeInstallResult(res, TEXT("Persistent hide rule creation"));
}
static int Controller_DeletePersistentHideRule(TCHAR *Type, TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide)
static int Controller_DeletePersistentHideRule(TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide)
{
USB_DK_HIDE_RULE Rule;
if (!Controller_ParseRule(Type, VID, PID, BCD, UsbClass, Hide, Rule))
if (!Controller_ParseRule(VID, PID, BCD, UsbClass, Hide, Rule))
{
tcout << TEXT("Persistent hide rule parsing failed") << endl;
return false;
}
auto res = Type == USBDK_HIDER_RULE_DEFAULT ?
UsbDk_DeletePersistentHideRule(&Rule) :
UsbDk_DeleteExtendedPersistentHideRule(&Rule, (ULONG)Rule.Type);
auto res = UsbDk_DeletePersistentHideRule(&Rule);
return Controller_AnalyzeInstallResult(res, TEXT("Persistent hide rule removal"));
}
static void Controller_HideDevice(TCHAR *Type, TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide)
static void Controller_HideDevice(TCHAR *VID, TCHAR *PID, TCHAR *BCD, TCHAR *UsbClass, TCHAR *Hide)
{
USB_DK_HIDE_RULE Rule;
if (!Controller_ParseRule(Type, VID, PID, BCD, UsbClass, Hide, Rule))
if (!Controller_ParseRule(VID, PID, BCD, UsbClass, Hide, Rule))
{
tcout << TEXT("Hide rule parsing failed") << endl;
return;
@ -291,11 +283,7 @@ static void Controller_HideDevice(TCHAR *Type, TCHAR *VID, TCHAR *PID, TCHAR *BC
return;
}
BOOL bResult = Rule.Type == USBDK_HIDER_RULE_DEFAULT ?
UsbDk_AddHideRule(hiderHandle, &Rule) :
UsbDk_AddExtendedHideRule(hiderHandle, &Rule, (ULONG)Rule.Type);
if (bResult)
if (UsbDk_AddHideRule(hiderHandle, &Rule))
{
tcout << endl
<< TEXT("Hide rule loaded succesfully. ")
@ -320,15 +308,6 @@ static void Controller_HideDevice(TCHAR *Type, TCHAR *VID, TCHAR *PID, TCHAR *BC
UsbDk_CloseHiderHandle(hiderHandle);
}
static int Controller_DeleteAllPersistentHideRules()
{
ULONG done = 0, notDone = 0;
auto res = UsbDk_DeleteAllPersistentRules(&done, &notDone);
tcout << TEXT("Cleaning persistent rules: done ") << dec << done
<< TEXT(", not done ") << notDone << endl;
return Controller_AnalyzeInstallResult(res, TEXT("Clean persistent hide rules"));
}
static bool Controller_ChdirToPackageFolder()
{
TCHAR PackagePath[MAX_PATH];
@ -395,34 +374,30 @@ int __cdecl _tmain(int argc, TCHAR* argv[])
}
else if (_tcscmp(L"-H", argv[1]) == 0)
{
if (argc < 8)
if (argc < 7)
{
ShowUsage();
return -3;
}
Controller_HideDevice(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
Controller_HideDevice(argv[2], argv[3], argv[4], argv[5], argv[6]);
}
else if (_tcscmp(L"-P", argv[1]) == 0)
{
if (argc < 8)
if (argc < 7)
{
ShowUsage();
return -4;
}
return Controller_AddPersistentHideRule(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
return Controller_AddPersistentHideRule(argv[2], argv[3], argv[4], argv[5], argv[6]);
}
else if (_tcscmp(L"-D", argv[1]) == 0)
{
if (argc < 8)
if (argc < 7)
{
ShowUsage();
return -5;
}
return Controller_DeletePersistentHideRule(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
}
else if (_tcscmp(L"-Z", argv[1]) == 0)
{
return Controller_DeleteAllPersistentHideRules();
return Controller_DeletePersistentHideRule(argv[2], argv[3], argv[4], argv[5], argv[6]);
}
else
{

View file

@ -127,7 +127,6 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>UsbDkController</RootNamespace>
<WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
<TargetVersion>Windows7</TargetVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'" Label="Configuration">
@ -323,7 +322,6 @@
<CharacterSet>Unicode</CharacterSet>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<Import Project="..\Tools\Driver.Initial.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>

View file

@ -16,8 +16,7 @@ static bool operator == (const USB_DK_HIDE_RULE& r1, const USB_DK_HIDE_RULE& r2)
(r1.PID == r2.PID) &&
(r1.BCD == r2.BCD) &&
(r1.Class == r2.Class) &&
(r1.Hide == r2.Hide) &&
(r1.Type == r2.Type);
(r1.Hide == r2.Hide);
}
DWORD CRulesManager::ReadDword(LPCTSTR RuleName, LPCTSTR ValueName) const
@ -54,7 +53,6 @@ ULONG64 CRulesManager::ReadBool(LPCTSTR RuleName, LPCTSTR ValueName) const
void CRulesManager::ReadRule(LPCTSTR RuleName, USB_DK_HIDE_RULE &Rule) const
{
Rule.Type = ReadDword(RuleName, USBDK_HIDE_RULE_TYPE);
Rule.Hide = ReadBool(RuleName, USBDK_HIDE_RULE_SHOULD_HIDE);
Rule.VID = ReadDwordMask(RuleName, USBDK_HIDE_RULE_VID);
Rule.PID = ReadDwordMask(RuleName, USBDK_HIDE_RULE_PID);
@ -108,7 +106,6 @@ void CRulesManager::AddRule(const USB_DK_HIDE_RULE &Rule)
throw UsbDkRuleManagerException(TEXT("Failed to create rule key"), ERROR_FUNCTION_FAILED);
}
WriteDword(RuleName, USBDK_HIDE_RULE_TYPE, static_cast<ULONG>(Rule.Type));
WriteDword(RuleName, USBDK_HIDE_RULE_SHOULD_HIDE, static_cast<ULONG>(Rule.Hide));
WriteDword(RuleName, USBDK_HIDE_RULE_VID, static_cast<ULONG>(Rule.VID));
WriteDword(RuleName, USBDK_HIDE_RULE_PID, static_cast<ULONG>(Rule.PID));
@ -128,20 +125,3 @@ void CRulesManager::DeleteRule(const USB_DK_HIDE_RULE &Rule)
}
}
}
ULONG CRulesManager::DeleteAllRules(ULONG& notDeleted)
{
ULONG deleted = 0;
notDeleted = 0;
vector<wstring> subkeys;
for (const auto &SubKey : m_RegAccess)
subkeys.push_back(SubKey);
while (subkeys.size())
{
m_RegAccess.DeleteKey(subkeys.front().c_str()) ? deleted++ : notDeleted++;
subkeys.erase(subkeys.begin());
}
return deleted;
}

View file

@ -18,7 +18,6 @@ public:
void AddRule(const USB_DK_HIDE_RULE &Rule);
void DeleteRule(const USB_DK_HIDE_RULE &Rule);
ULONG DeleteAllRules(ULONG& notDeleted);
private:
template <typename TFunctor>
bool FindRule(const USB_DK_HIDE_RULE &Rule, TFunctor Functor);

View file

@ -173,11 +173,7 @@ BOOL UsbDk_StopRedirect(HANDLE DeviceHandle)
{
try
{
// if the driver is unaccessible the constructor raises exception
// there is a question whether this check is required and whether this is correct thing to do
// for now we leave it as is with TODO to investigate it in corner case flow
// (for example UsbDk uninstall when there is active redirection)
UsbDkDriverAccess checkDriverAccess;
UsbDkDriverAccess driverAccess;
unique_ptr<REDIRECTED_DEVICE_HANDLE> deviceHandle(unpackHandle<REDIRECTED_DEVICE_HANDLE>(DeviceHandle));
deviceHandle->RedirectorAccess.reset();
return TRUE;
@ -305,13 +301,12 @@ HANDLE UsbDk_CreateHiderHandle()
}
}
DLL BOOL UsbDk_AddExtendedHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE_PUBLIC PublicRule, ULONG Type)
BOOL UsbDk_AddHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE Rule)
{
USB_DK_HIDE_RULE Rule(PublicRule, Type);
try
{
auto HiderAccess = unpackHandle<UsbDkHiderAccess>(HiderHandle);
HiderAccess->AddHideRule(Rule);
HiderAccess->AddHideRule(*Rule);
return TRUE;
}
catch (const exception &e)
@ -321,11 +316,6 @@ DLL BOOL UsbDk_AddExtendedHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE_PUBLIC
}
}
BOOL UsbDk_AddHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE_PUBLIC PublicRule)
{
return UsbDk_AddExtendedHideRule(HiderHandle, PublicRule, USBDK_HIDER_RULE_DEFAULT);
}
BOOL UsbDk_ClearHideRules(HANDLE HiderHandle)
{
try
@ -380,50 +370,12 @@ InstallResult ModifyPersistentHideRules(const USB_DK_HIDE_RULE &Rule,
}
}
DLL InstallResult UsbDk_AddExtendedPersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC PublicRule, ULONG Type)
DLL InstallResult UsbDk_AddPersistentHideRule(PUSB_DK_HIDE_RULE Rule)
{
USB_DK_HIDE_RULE Rule(PublicRule, Type);
return ModifyPersistentHideRules(Rule, &CRulesManager::AddRule);
return ModifyPersistentHideRules(*Rule, &CRulesManager::AddRule);
}
DLL InstallResult UsbDk_AddPersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC PublicRule)
DLL InstallResult UsbDk_DeletePersistentHideRule(PUSB_DK_HIDE_RULE Rule)
{
return UsbDk_AddExtendedPersistentHideRule(PublicRule, USBDK_HIDER_RULE_DEFAULT);
}
DLL InstallResult UsbDk_DeleteExtendedPersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC PublicRule, ULONG Type)
{
USB_DK_HIDE_RULE Rule(PublicRule, Type);
return ModifyPersistentHideRules(Rule, &CRulesManager::DeleteRule);
}
DLL InstallResult UsbDk_DeletePersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC PublicRule)
{
return UsbDk_DeleteExtendedPersistentHideRule(PublicRule, USBDK_HIDER_RULE_DEFAULT);
}
DLL InstallResult UsbDk_DeleteAllPersistentRules(OUT PULONG pDeleted, OUT PULONG pNotDeleted)
{
try
{
CRulesManager Manager;
*pDeleted = *pNotDeleted = 0;
*pDeleted = Manager.DeleteAllRules(*pNotDeleted);
UsbDkDriverAccess driver;
driver.UpdateRegistryParameters();
return *pNotDeleted ? InstallFailure : InstallSuccess;
}
catch (const UsbDkDriverFileException &e)
{
printExceptionString(e.what());
return InstallSuccessNeedReboot;
}
catch (const exception &e)
{
printExceptionString(e.what());
return InstallFailure;
}
return ModifyPersistentHideRules(*Rule, &CRulesManager::DeleteRule);
}

View file

@ -127,7 +127,6 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>UsbDkHelper</RootNamespace>
<WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
<TargetVersion>Windows7</TargetVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'" Label="Configuration">
@ -323,7 +322,6 @@
<CharacterSet>Unicode</CharacterSet>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<Import Project="..\Tools\Driver.Initial.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>

View file

@ -35,7 +35,7 @@
#endif
#endif
#include "UsbDkDataHiderPublic.h"
#include "UsbDkDataHider.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -79,29 +79,7 @@ extern "C" {
* UsbDk_ClearHideRules() called
*
*/
DLL BOOL UsbDk_AddHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE_PUBLIC Rule);
/* Add extended rule for detaching USB devices from OS stack.
* The rule definition is the same as for UsbDk_AddHideRule
*
* Processing of the rule depend on exact Type parameter
* For existing extended rules see Documentation/Hider.txt
*
* @params
* IN - HiderHandle Handle to UsbDk driver
* - Rule - pointer to hide rule
* - Type - type of the rule
* OUT - None
*
* @return
* TRUE if function succeeds
*
* @note
* Hide rule stays until HiderHandle is closed, client process exits or
* UsbDk_ClearHideRules() called
*
*/
DLL BOOL UsbDk_AddExtendedHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE_PUBLIC Rule, ULONG Type);
DLL BOOL UsbDk_AddHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE Rule);
/* Clear all hider rules
*
@ -143,61 +121,18 @@ extern "C" {
*
* @note
* 1. Persistent rule stays until explicitly deleted by
* UsbDk_DeletePersistentHideRule or UsbDk_DeleteAllPersistentRules
* UsbDk_DeletePersistentHideRule()
* 2. This API requires administrative privileges
* 3. For already attached devices the rule will be applied after
* device re-plug or system reboot.
*
*/
DLL InstallResult UsbDk_AddPersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC Rule);
/* Add extended rule for detaching USB devices from OS stack persistently.
* The rule definition is the same as for UsbDk_AddPersistentHideRule
*
* Processing of the rule depend on exact Type parameter
* For existing extended rules see Documentation/Hider.txt
*
* @params
* IN - Rule - pointer to hide rule
* - Type - type of the rule
* OUT - None
*
* @return
* Rule installation status
*
* @note
* 1. Persistent rule stays until explicitly deleted by
* UsbDk_DeleteExtendedPersistentHideRule() or UsbDk_DeleteAllPersistentRules
* 2. This API requires administrative privileges
* 3. For already attached devices the rule will be applied after
* device re-plug or system reboot.
*
*/
DLL InstallResult UsbDk_AddExtendedPersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC Rule, ULONG Type);
/* Delete specific persistent hide rule (rule type is default)
*
* @params
* IN - Rule - pointer to hide rule
* - Type - type of the rule
* OUT - None
*
* @return
* Rule removal status
*
* @note
* 1. This API requires administrative privileges
* 2. For already attached devices the rule will be applied after
* device re-plug or system reboot.
*
*/
DLL InstallResult UsbDk_DeletePersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC Rule);
DLL InstallResult UsbDk_AddPersistentHideRule(PUSB_DK_HIDE_RULE Rule);
/* Delete specific persistent hide rule
*
* @params
* IN - Rule - pointer to hide rule
* - Type - type of the rule
* OUT - None
*
* @return
@ -209,26 +144,7 @@ extern "C" {
* device re-plug or system reboot.
*
*/
DLL InstallResult UsbDk_DeleteExtendedPersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC Rule, ULONG Type);
/* Delete all persistent hide rules
*
* @params
* IN - None
* OUT - PULONG pDeleted - number of deleted rules
* PULONG pNotDeleted - number of not deleted rules
*
* @return
* Rule removal status
*
* @note
* 1. This API requires administrative privileges
* 2. For already attached devices the rules become inactive after
* device re-plug or system reboot.
*
*/
DLL InstallResult UsbDk_DeleteAllPersistentRules(OUT PULONG pDeleted, OUT PULONG pNotDeleted);
DLL InstallResult UsbDk_DeletePersistentHideRule(PUSB_DK_HIDE_RULE Rule);
#ifdef __cplusplus
}
#endif

View file

@ -27,8 +27,6 @@
using namespace std;
static BOOL suppressInstallMessageBox = FALSE;
static int Controller_InstallDriver()
{
//Clean up any previous versions before reinstalling
@ -42,28 +40,14 @@ static int Controller_InstallDriver()
case InstallFailure:
return 1;
case InstallAborted:
if (!suppressInstallMessageBox)
{
MessageBox(NULL,
TEXT("Failed to start the driver on the system, installation aborted!\nPlease make sure you are installing a signed version of UsbDk or else try to disable \"driver signature enforcement\" on the system"),
TEXT("UsbDk Runtime Libraries Installer"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL);
}
else
{
OutputDebugString(TEXT("UsbDkInstHelper: Installation aborted"));
}
MessageBox(NULL,
TEXT("Failed to start the driver on the system, installation aborted!\nPlease make sure you are installing a signed version of UsbDk or else try to disable \"driver signature enforcement\" on the system"),
TEXT("UsbDk Runtime Libraries Installer"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL);
return 4;
case InstallSuccessNeedReboot:
if (!suppressInstallMessageBox)
{
MessageBox(NULL,
TEXT("Please restart your computer to complete the installation"),
TEXT("UsbDk Runtime Libraries Installer"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL);
}
else
{
OutputDebugString(TEXT("UsbDkInstHelper: reboot required to complete the installation"));
}
MessageBox(NULL,
TEXT("Please restart your computer to complete the installation"),
TEXT("UsbDk Runtime Libraries Installer"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_SYSTEMMODAL);
return 0;
default:
assert(0);
@ -117,10 +101,6 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if (lpCmdLine[0] == 'i')
{
if (lpCmdLine[1] == 'n' || lpCmdLine[1] == 'N')
{
suppressInstallMessageBox = TRUE;
}
OutputDebugString(TEXT("UsbDkInstHelper: Install"));
return Controller_InstallDriver();
}

View file

@ -127,7 +127,6 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>UsbDkController</RootNamespace>
<WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
<TargetVersion>Windows7</TargetVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'" Label="Configuration">
@ -323,7 +322,6 @@
<CharacterSet>Unicode</CharacterSet>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<Import Project="..\Tools\Driver.Initial.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>

View file

@ -2,7 +2,6 @@
SETLOCAL EnableExtensions EnableDelayedExpansion
set _f=UsbDk
if [%1] EQU [MSIONLY] goto BUILD_MSI
if [%2] EQU [NOSIGN] (SET DEBUG_CFG=Debug_NoSign) ELSE (SET DEBUG_CFG=Debug)
@ -18,40 +17,16 @@ for %%x in (Win7, Win8, Win8.1, Win10, XP) do (
)
pushd Install
call :maketmf Release
"C:\Program Files (x86)\Windows Kits\10\bin\x86\tracepdb.exe" -s -o .\UsbDk.tmf
if !ERRORLEVEL! NEQ 0 exit /B 1
popd
pushd Install_Debug
call :maketmf %DEBUG_CFG%
"C:\Program Files (x86)\Windows Kits\10\bin\x86\tracepdb.exe" -s -o .\UsbDk.tmf
if !ERRORLEVEL! NEQ 0 exit /B 1
popd
if [%1] EQU [NOMSI] goto NOMSI
goto BUILD_MSI
:maketmf
del *.tmf *.mof
call :make1tmf x64\Win10%1
call :make1tmf x86\Win10%1
call :make1tmf x64\Win8.1%1
call :make1tmf x86\Win8.1%1
call :make1tmf x64\Win8%1
call :make1tmf x86\Win8%1
call :make1tmf x64\Win7%1
call :make1tmf x86\Win7%1
call :make1tmf x64\XP%1
call :make1tmf x86\XP%1
goto :eof
:make1tmf
pushd %1
echo Making TMF in %1
"C:\Program Files (x86)\Windows Kits\10\bin\x86\tracepdb.exe" -s -o .\%_f%.tmf
popd
type %1\%_f%.tmf >> %_f%.tmf
del %1\%_f%.??f
goto :eof
:BUILD_MSI