Skip to content

Commit

Permalink
Hider: Introduce header file with registry layout
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 23, 2015
1 parent 2516f17 commit 73ba48b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
8 changes: 4 additions & 4 deletions UsbDk/ControlDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ NTSTATUS CUsbDkControlDevice::AddHideRule(const USB_DK_HIDE_RULE &UsbDkRule)
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CONTROLDEVICE, "%!FUNC! entry");

auto MatchAllMapper = [](ULONG64 Value) -> ULONG
{ return Value == USB_DK_HIDE_RULE_MATCH_ALL ? CUsbDkHideRule::MATCH_ALL : static_cast<ULONG>(Value); };
{ return Value == USB_DK_HIDE_RULE_MATCH_ALL ? USBDK_REG_HIDE_RULE_MATCH_ALL
: static_cast<ULONG>(Value); };

CObjHolder<CUsbDkHideRule> NewRule(new CUsbDkHideRule(UsbDkRule.Hide ? true : false,
MatchAllMapper(UsbDkRule.Class),
Expand Down Expand Up @@ -792,7 +793,7 @@ class CRegHideRule final : private CRegKey

if (NT_SUCCESS(status))
{
Value = !!RawValue;
Value = HideRuleBoolFromRegistry(RawValue);
}

return status;
Expand All @@ -805,8 +806,7 @@ class CRegHideRule final : private CRegKey

if (NT_SUCCESS(status))
{
Value = (RawValue == CUsbDkHideRule::MATCH_ALL) ? USB_DK_HIDE_RULE_MATCH_ALL
: RawValue;
Value = HideRuleUlongMaskFromRegistry(RawValue);
}

return status;
Expand Down
4 changes: 2 additions & 2 deletions UsbDk/ControlDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "FilterDevice.h"
#include "HiderDevice.h"
#include "UsbDkDataHider.h"
#include "HideRulesRegPublic.h"

typedef struct tag_USB_DK_DEVICE_ID USB_DK_DEVICE_ID;
typedef struct tag_USB_DK_DEVICE_INFO USB_DK_DEVICE_INFO;
Expand Down Expand Up @@ -74,7 +75,6 @@ class CUsbDkControlDeviceQueue : public CWdfDefaultQueue, public CAllocatable<Pa
class CUsbDkHideRule : public CAllocatable < NonPagedPool, 'RHHR' >
{
public:
static const ULONG MATCH_ALL = ULONG(-1);

CUsbDkHideRule(bool Hide, ULONG Class, ULONG VID, ULONG PID, ULONG BCD)
: m_Hide(Hide)
Expand Down Expand Up @@ -118,7 +118,7 @@ class CUsbDkHideRule : public CAllocatable < NonPagedPool, 'RHHR' >
private:
bool MatchCharacteristic(ULONG CharacteristicFilter, ULONG CharacteristicValue) const
{
return (CharacteristicFilter == MATCH_ALL) ||
return (CharacteristicFilter == USBDK_REG_HIDE_RULE_MATCH_ALL) ||
(CharacteristicValue == CharacteristicFilter);
}

Expand Down
51 changes: 51 additions & 0 deletions UsbDk/HideRulesRegPublic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**********************************************************************
* Copyright (c) 2013-2014 Red Hat, Inc.
*
* Developed by Daynix Computing LTD.
*
* Authors:
* Dmitry Fleytman <[email protected]>
* Pavel Gurvich <[email protected]>
*
* 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 USBDK_PARAMS_SUBKEY_NAME TEXT("Parameters")
#define USBDK_HIDE_RULES_SUBKEY_NAME TEXT("HideRules")

#define USBDK_HIDE_RULE_SHOULD_HIDE TEXT("ShouldHide")
#define USBDK_HIDE_RULE_VID TEXT("VID")
#define USBDK_HIDE_RULE_PID TEXT("PID")
#define USBDK_HIDE_RULE_BCD TEXT("BCD")
#define USBDK_HIDE_RULE_CLASS TEXT("Class")

#define USBDK_HIDE_RULES_PATH TEXT("SYSTEM\\CurrentControlSet\\Services\\") \
USBDK_DRIVER_NAME TEXT("\\") \
USBDK_PARAMS_SUBKEY_NAME TEXT("\\") \
USBDK_HIDE_RULES_SUBKEY_NAME TEXT("\\")

#define USBDK_REG_HIDE_RULE_MATCH_ALL ULONG(-1)

static inline ULONG64 HideRuleUlongMaskFromRegistry(DWORD Value)
{
return (Value == USBDK_REG_HIDE_RULE_MATCH_ALL) ? USB_DK_HIDE_RULE_MATCH_ALL
: Value;
}

static inline ULONG64 HideRuleBoolFromRegistry(DWORD Value)
{
return !!Value;
}
1 change: 1 addition & 0 deletions UsbDk/UsbDk.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<ClInclude Include="FilterDevice.h" />
<ClInclude Include="FilterStrategy.h" />
<ClInclude Include="HiderDevice.h" />
<ClInclude Include="HideRulesRegPublic.h" />
<ClInclude Include="Irp.h" />
<ClInclude Include="MemoryBuffer.h" />
<ClInclude Include="Public.h" />
Expand Down
3 changes: 3 additions & 0 deletions UsbDk/UsbDk.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<ClInclude Include="Registry.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HideRulesRegPublic.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Driver.cpp">
Expand Down
9 changes: 0 additions & 9 deletions UsbDk/UsbDkNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,3 @@
#define USBDK_HIDER_DEVICE_NAME TEXT("\\Device\\") _USBDK_HIDER_NAME
#define USBDK_DOS_HIDER_DEVICE_NAME TEXT("\\DosDevices\\") _USBDK_HIDER_NAME
#define USBDK_USERMODE_HIDER_NAME TEXT("\\\\.\\") _USBDK_HIDER_NAME

#define USBDK_PARAMS_SUBKEY_NAME TEXT("Parameters")
#define USBDK_HIDE_RULES_SUBKEY_NAME TEXT("HideRules")

#define USBDK_HIDE_RULE_SHOULD_HIDE TEXT("ShouldHide")
#define USBDK_HIDE_RULE_VID TEXT("VID")
#define USBDK_HIDE_RULE_PID TEXT("PID")
#define USBDK_HIDE_RULE_BCD TEXT("BCD")
#define USBDK_HIDE_RULE_CLASS TEXT("Class")

0 comments on commit 73ba48b

Please sign in to comment.