Hider API: add ability to delete all persistent rules
The application that uses Hider API does not have an ability to query which persistent rules exist. So in order to use UsbDk_DeletePersistentHideRule the application shall guess which rule it needs to delete. Current commit adds ability to delete all existing the persistent rules. This API requires administrative privileges as all APIs related to persistent hide rules. Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
This commit is contained in:
parent
c4504cc1ad
commit
5549421d45
5 changed files with 78 additions and 2 deletions
|
|
@ -48,6 +48,7 @@ static void ShowUsage()
|
|||
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 << 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;
|
||||
|
|
@ -319,6 +320,15 @@ 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, ¬Done);
|
||||
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];
|
||||
|
|
@ -410,6 +420,10 @@ int __cdecl _tmain(int argc, TCHAR* argv[])
|
|||
}
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowUsage();
|
||||
|
|
|
|||
|
|
@ -128,3 +128,20 @@ 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ 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);
|
||||
|
|
|
|||
|
|
@ -401,3 +401,29 @@ DLL InstallResult UsbDk_DeletePersistentHideRule(PUSB_DK_HIDE_RULE_PUBLIC Public
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ extern "C" {
|
|||
*
|
||||
* @note
|
||||
* 1. Persistent rule stays until explicitly deleted by
|
||||
* UsbDk_DeletePersistentHideRule()
|
||||
* UsbDk_DeletePersistentHideRule 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.
|
||||
|
|
@ -167,7 +167,7 @@ extern "C" {
|
|||
*
|
||||
* @note
|
||||
* 1. Persistent rule stays until explicitly deleted by
|
||||
* UsbDk_DeletePersistentHideRule()
|
||||
* 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.
|
||||
|
|
@ -211,6 +211,24 @@ extern "C" {
|
|||
*/
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue