diff options
author | Dmitry Fleytman <dfleytma@redhat.com> | 2015-01-26 14:54:25 +0200 |
---|---|---|
committer | Dmitry Fleytman <dfleytma@redhat.com> | 2015-02-17 09:13:05 +0200 |
commit | e389fb7924c51822e83b2abadf5c22ec7cb46692 (patch) | |
tree | 08b7d7d225cd235fa92666ab5fac98e020acf667 /UsbDkHelper | |
parent | 18c990c39c88b2e53346eaf10a6284452976af9d (diff) |
UsbDkHelper: Introduce hider API
Signed-off-by: Kirill Moizik <kirill@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Diffstat (limited to 'UsbDkHelper')
-rw-r--r-- | UsbDkHelper/DriverAccess.cpp | 11 | ||||
-rw-r--r-- | UsbDkHelper/DriverAccess.h | 12 | ||||
-rw-r--r-- | UsbDkHelper/UsbDkHelper.cpp | 53 | ||||
-rw-r--r-- | UsbDkHelper/UsbDkHelper.vcxproj | 1 | ||||
-rw-r--r-- | UsbDkHelper/UsbDkHelper.vcxproj.filters | 3 | ||||
-rw-r--r-- | UsbDkHelper/UsbDkHelperHider.h | 105 |
6 files changed, 184 insertions, 1 deletions
diff --git a/UsbDkHelper/DriverAccess.cpp b/UsbDkHelper/DriverAccess.cpp index f0f8b7d..c1f99b9 100644 --- a/UsbDkHelper/DriverAccess.cpp +++ b/UsbDkHelper/DriverAccess.cpp @@ -92,7 +92,16 @@ HANDLE UsbDkDriverAccess::AddRedirect(USB_DK_DEVICE_ID &DeviceID) { ULONG64 RedirectorHandle; SendIoctlWithDeviceId(IOCTL_USBDK_ADD_REDIRECT, DeviceID, &RedirectorHandle); - return reinterpret_cast<HANDLE>(RedirectorHandle); } //------------------------------------------------------------------------------------------------ + +void UsbDkHiderAccess::AddHideRule(const USB_DK_HIDE_RULE &Rule) +{ + Ioctl(IOCTL_USBDK_ADD_HIDE_RULE, false, const_cast<PUSB_DK_HIDE_RULE>(&Rule), sizeof(Rule)); +} + +void UsbDkHiderAccess::ClearHideRules() +{ + Ioctl(IOCTL_USBDK_CLEAR_HIDE_RULES); +} diff --git a/UsbDkHelper/DriverAccess.h b/UsbDkHelper/DriverAccess.h index f7a7ca5..7771929 100644 --- a/UsbDkHelper/DriverAccess.h +++ b/UsbDkHelper/DriverAccess.h @@ -24,6 +24,7 @@ #pragma once #include "UsbDkData.h" +#include "UsbDkDataHider.h" #include "DriverFile.h" #include "UsbDkNames.h" @@ -63,3 +64,14 @@ private: } }; //----------------------------------------------------------------------------------- + +class UsbDkHiderAccess : public UsbDkDriverFile +{ +public: + UsbDkHiderAccess() + : UsbDkDriverFile(USBDK_USERMODE_HIDER_NAME) + {} + + void AddHideRule(const USB_DK_HIDE_RULE &Rule); + void ClearHideRules(); +}; diff --git a/UsbDkHelper/UsbDkHelper.cpp b/UsbDkHelper/UsbDkHelper.cpp index c81720a..06fd941 100644 --- a/UsbDkHelper/UsbDkHelper.cpp +++ b/UsbDkHelper/UsbDkHelper.cpp @@ -25,6 +25,8 @@ #include "stdafx.h" #include "UsbDkHelper.h" +#include "UsbDkHelperHider.h" +#include "UsbDkDataHider.h" #include "Installer.h" #include "DriverAccess.h" #include "RedirectorAccess.h" @@ -262,3 +264,54 @@ HANDLE UsbDk_GetRedirectorSystemHandle(HANDLE DeviceHandle) return deviceHandle->RedirectorAccess->GetSystemHandle(); } //------------------------------------------------------------------------------------------- + +HANDLE UsbDk_CreateHiderHandle() +{ + try + { + unique_ptr<UsbDkHiderAccess> hiderAccess(new UsbDkHiderAccess); + return reinterpret_cast<HANDLE>(hiderAccess.release()); + } + catch (const exception &e) + { + printExceptionString(e.what()); + return INVALID_HANDLE_VALUE; + } +} + +BOOL UsbDk_AddHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE Rule) +{ + auto HiderAccess = reinterpret_cast<UsbDkHiderAccess *>(HiderHandle); + + try + { + HiderAccess->AddHideRule(*Rule); + return TRUE; + } + catch (const exception &e) + { + printExceptionString(e.what()); + return FALSE; + } +} + +BOOL UsbDk_ClearHideRules(HANDLE HiderHandle) +{ + auto HiderAccess = reinterpret_cast<UsbDkHiderAccess *>(HiderHandle); + + try + { + HiderAccess->ClearHideRules(); + return TRUE; + } + catch (const exception &e) + { + printExceptionString(e.what()); + return FALSE; + } +} + +void UsbDk_CloseHiderHandle(HANDLE HiderHandle) +{ + delete reinterpret_cast<UsbDkHiderAccess *>(HiderHandle); +} diff --git a/UsbDkHelper/UsbDkHelper.vcxproj b/UsbDkHelper/UsbDkHelper.vcxproj index 8e45476..08779a8 100644 --- a/UsbDkHelper/UsbDkHelper.vcxproj +++ b/UsbDkHelper/UsbDkHelper.vcxproj @@ -974,6 +974,7 @@ </ClCompile> </ItemGroup> <ItemGroup> + <ClInclude Include="..\UsbDk\UsbDkHelperHider.h" /> <ClInclude Include="DriverAccess.h" /> <ClInclude Include="DriverFile.h" /> <ClInclude Include="Exception.h" /> diff --git a/UsbDkHelper/UsbDkHelper.vcxproj.filters b/UsbDkHelper/UsbDkHelper.vcxproj.filters index b9bea0d..356e346 100644 --- a/UsbDkHelper/UsbDkHelper.vcxproj.filters +++ b/UsbDkHelper/UsbDkHelper.vcxproj.filters @@ -104,6 +104,9 @@ <ClInclude Include="UsbDkCompat.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\UsbDk\UsbDkHelperHider.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="Resource.rc"> diff --git a/UsbDkHelper/UsbDkHelperHider.h b/UsbDkHelper/UsbDkHelperHider.h new file mode 100644 index 0000000..309943f --- /dev/null +++ b/UsbDkHelper/UsbDkHelperHider.h @@ -0,0 +1,105 @@ +/********************************************************************** +* 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 + +// UsbDkHelper C-interface + +#ifdef BUILD_DLL +#define DLL __declspec(dllexport) +#else +#ifdef _MSC_VER +#define DLL __declspec(dllimport) +#else +#define DLL +#endif +#endif + +#include "UsbDkDataHider.h" +#ifdef __cplusplus +extern "C" { +#endif + +// UsbDk hider API provides hide device feature that allows to detach USB device from the hosting system. +// It can be useful in various scenarios, for example when there is no drivers for USB device on hosting machine +// and user would like to avoid dealing with "New Hardware" wizard. + + /* Create handle to hider interface of UsbDk driver + * + * @params + * IN - None + * OUT - None + * + * @return + * Handle to hider interface of UsbDk driver + * + * @note + * When this handle closes UsbDk clears all rules set by UsbDk_AddHideRule() + * + */ + DLL HANDLE UsbDk_CreateHiderHandle(void); + + /* Add a rule to determine which USB devices + * to be hidden when plugged in, a rule contains: + * + * class, vendor, product, version, allow + * + * Use -1 for @class/@vendor/@product/@version to accept any value. + * + * @params + * IN - HiderHandle Handle to UsbDk driver + - rule - pointer to hiding rule + * OUT - None + * + * @return + * TRUE if function succeeds + * + */ + DLL BOOL UsbDk_AddHideRule(HANDLE HiderHandle, PUSB_DK_HIDE_RULE Rule); + + /* Clear all hider rules + * + * @params + * IN - HiderHandle Handle to UsbDk driver + * OUT - None + * + * @return + * TRUE if function succeeds + * + */ + DLL BOOL UsbDk_ClearHideRules(HANDLE HiderHandle); + + /* Close Handle to UsbDk hider interface + * + * @params + * IN - HiderHandle Handle to UsbDk driver + * OUT - None + * + * @return + * None + * + */ + DLL void UsbDk_CloseHiderHandle(HANDLE HiderHandle); +#ifdef __cplusplus +} +#endif |