Skip to content

Commit

Permalink
UsbDkHelper: Add persistent hide rules interface
Browse files Browse the repository at this point in the history
Signed-off-by: Kirill Moizik <[email protected]>
Signed-off-by: Dmitry Fleytman <[email protected]>
  • Loading branch information
Dmitry Fleytman committed Mar 25, 2015
1 parent 408a787 commit eb8c876
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
28 changes: 28 additions & 0 deletions UsbDkHelper/UsbDkHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Installer.h"
#include "DriverAccess.h"
#include "RedirectorAccess.h"
#include "RuleManager.h"

//-------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -315,3 +316,30 @@ void UsbDk_CloseHiderHandle(HANDLE HiderHandle)
{
delete reinterpret_cast<UsbDkHiderAccess *>(HiderHandle);
}

static inline
BOOL ModifyPersistentHideRules(const USB_DK_HIDE_RULE &Rule,
void(CRulesManager::*Modifier)(const USB_DK_HIDE_RULE&))
{
try
{
CRulesManager Manager;
(Manager.*Modifier)(Rule);
return TRUE;
}
catch (const exception &e)
{
printExceptionString(e.what());
return FALSE;
}
}

DLL BOOL UsbDk_AddPersistentHideRule(PUSB_DK_HIDE_RULE Rule)
{
return ModifyPersistentHideRules(*Rule, &CRulesManager::AddRule);
}

DLL BOOL UsbDk_DeletePersistentHideRule(PUSB_DK_HIDE_RULE Rule)
{
return ModifyPersistentHideRules(*Rule, &CRulesManager::DeleteRule);
}
41 changes: 41 additions & 0 deletions UsbDkHelper/UsbDkHelperHider.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,47 @@ extern "C" {
*
*/
DLL void UsbDk_CloseHiderHandle(HANDLE HiderHandle);

/* Add rule for detaching USB devices from OS stack persistently.
* The rule consists of:
*
* class, vendor, product, version, allow
*
* Use -1 for @class/@vendor/@product/@version to accept any value.
*
* @params
* IN - Rule - pointer to hide rule
* OUT - None
*
* @return
* TRUE if function succeeds
*
* @note
* 1. Persistent rule stays until explicitly deleted by
* 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 BOOL UsbDk_AddPersistentHideRule(PUSB_DK_HIDE_RULE Rule);

/* Delete specific persistent hide rule
*
* @params
* IN - Rule - pointer to hide rule
* OUT - None
*
* @return
* TRUE if function succeeds
*
* @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 BOOL UsbDk_DeletePersistentHideRule(PUSB_DK_HIDE_RULE Rule);
#ifdef __cplusplus
}
#endif

0 comments on commit eb8c876

Please sign in to comment.