/*++
Copyright (C) Microsoft Corporation, 1999 - 1999
Module Name:
addfilter.c
Abstract:
This command line utility adds and removes upper filter drivers
for a given drive or volume
Author:
Benjamin Strautin (t-bensta)
Environment:
User mode only
Notes:
- the filter is not checked for validity before it is added to the driver
stack; if an invalid filter is added, the device may no longer be
accessible.
- all code works irrespective of character set (ANSI, Unicode, ...)
Revision History:
05-24-99 : created
--*/
#include <driverspecs.h>
_Analysis_mode_(_Analysis_code_type_user_code_);
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
// defines GUID
#include <initguid.h>
// the SetupDiXXX api (from the DDK)
#include <setupapi.h>
// defines guids for device classes (GUID_DEVINTERFACE_DISK, etc)
#include <devioctl.h>
#include <ntddstor.h>
// for all of the _t stuff (to allow compiling for both Unicode/Ansi)
#include <tchar.h>
#include <strsafe.h>
#if DBG
#include <assert.h>
#define ASSERT(condition) assert(condition)
#else
#define ASSERT(condition)
#endif
BOOLEAN
AddFilterDriver(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
_In_ IN LPTSTR Filter,
IN BOOLEAN UpperFilter
);
BOOLEAN
RemoveFilterDriver(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
_In_ IN LPTSTR Filter,
IN BOOLEAN UpperFilter
);
void
PrintFilters(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
IN BOOLEAN UpperFilters
);
LPTSTR
GetFilters(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
IN BOOLEAN UpperFilters
);
void PrintDeviceName(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData
);
BOOLEAN
DeviceNameMatches(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
_In_ IN LPTSTR DeviceName
);
PBYTE
GetDeviceRegistryProperty(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
IN DWORD Property,
OUT PDWORD PropertyRegDataType
);
BOOLEAN
RestartDevice(
IN HDEVINFO DeviceInfoSet,
IN OUT PSP_DEVINFO_DATA DeviceInfoData
);
BOOLEAN
PrependSzToMultiSz(
_In_ LPTSTR SzToPrepend,
_Inout_ LPTSTR *MultiSz
);
size_t
MultiSzLength(
_In_ IN LPTSTR MultiSz
);
size_t
MultiSzSearchAndDeleteCaseInsensitive(
_In_ IN LPTSTR FindThis,
_In_ IN LPTSTR FindWithin,
OUT size_t *NewStringLength
);
void
PrintUsage();
// To add/remove filter drivers:
// - use SetupDiGetClassDevs to get a list of devices of the given interface
// class
// - use SetupDiEnumDeviceInfo to enumerate the items in that list and
// obtain a SP_DEVINFO_DATA
// - use SetupDiGetDeviceRegistryProperty to get the list of filter drivers
// - add/remove items in the filter list
// - use SetupDiSetDeviceRegistryProperty to put the list back in place
// To restart the device:
// - use SetupDiCallClassInstaller with DIF_PROPERTYCHANGE and DICS_STOP to
// stop the device
// - use SetupDiCallClassInstaller with DIF_PROPERTYCHANGE and DICS_START to
// restart the device
int __cdecl _tmain(int argc, _In_reads_(argc) LPTSTR argv[])
{
// these two constants are used to help enumerate through the list of all
// disks and volumes on the system. Adding another GUID should "just work"
static const GUID * deviceGuids[] = {
&GUID_DEVINTERFACE_DISK,
&GUID_DEVINTERFACE_VOLUME,
&GUID_DEVINTERFACE_CDROM
};
static const int numdeviceGuids = sizeof(deviceGuids) / sizeof(LPGUID);
// structs needed to contain information about devices
HDEVINFO devInfo = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA devInfoData;
// indices for stepping through devices, and device interface guids
int argIndex;
int devGuidIndex;
int deviceIndex;
// variables used to deal with the command-line options of this program
BOOLEAN listDevices = FALSE;
BOOLEAN upperFilter = TRUE;
LPTSTR deviceName = NULL;
LPTSTR filterToAdd = NULL;
LPTSTR filterToRemove = NULL;
BOOLEAN keepGoing = TRUE;
BOOLEAN needReboot = FALSE;
BOOLEAN deviceMatch = FALSE;
////////////////////////////////////////////////
// parse arguments; nothing too exciting here //
////////////////////////////////////////////////
if( argc < 2 || _tcscmp(argv[1], _T("/?")) == 0 )
{
PrintUsage();
return (0);
}
for (argIndex = 1; argIndex < argc; argIndex++) {
#pragma prefast(suppress:6385, "Previously checked argIndex being less than argc. No buffer overflow.")
if( _tcscmp(argv[argIndex], _T("/listdevices")) == 0 ) {
listDevices = TRUE;
} else if( _tcscmp(argv[argIndex], _T("/lower")) == 0 ) {
upperFilter = FALSE;
printf("Using Lower Filters\n");
} else if( _tcscmp(argv[argIndex], _T("/device")) == 0 ) {
argIndex++;
if( argIndex < argc ) {
deviceName = argv[argIndex];
} else {
PrintUsage();
return (0);
}
} else if( _tcscmp(argv[argIndex], _T("/add")) == 0 ) {
argIndex++;
if( argIndex<argc ) {
filterToAdd = argv[argIndex];
} else {
PrintUsage();
return (0);
}
} else if( _tcscmp(argv[argIndex], _T("/remove")) == 0 ) {
argIndex++;
if( argIndex<argc ) {
filterToRemove = argv[argIndex];
} else {
PrintUsage();
return (0);
}
} else {
PrintUsage();
return (0);
}
}
//////////////////////////////////////////////////////
// done parsing arguments, move onto the good stuff //
//////////////////////////////////////////////////////
// This outer loop steps through the array of device guid pointers that is
// defined above main(). It was just the easiest way to deal with both
// Disks and Volumes (and it is easy to add other types of devices)
for(devGuidIndex = 0; devGuidIndex<numdeviceGuids; devGuidIndex++) {
// get a list of devices which support the given interface
devInfo = SetupDiGetClassDevs( deviceGuids[devGuidIndex],
NULL,
NULL,
DIGCF_PROFILE |
DIGCF_DEVICEINTERFACE |
DIGCF_PRESENT );
if( devInfo == INVALID_HANDLE_VALUE ) {
printf("got INVALID_HANDLE_VALUE!\n");
return (1);
}
// as per DDK docs on SetupDiEnumDeviceInfo
devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
// step through the list of devices for this handle
// get device info at index deviceIndex, the function returns FALSE
// when there is no device at the given index.
for( deviceIndex=0;
SetupDiEnumDeviceInfo( devInfo, deviceIndex, &devInfoData );
deviceIndex++ ) {
// setting this variable to FALSE will cause all of the if
// statements to fall through, cutting off processing for this
// device.
keepGoing = TRUE;
// if a device name was specified, and it doesn't match this one,
// stop. If there is a match (or no name was specified), mark that
// there was a match.
if( deviceName !=
没有合适的资源?快使用搜索试试~ 我知道了~
AddFilter-Storage-Filter-Tool.rar_tool
共16个文件
css:7个
rtf:1个
c:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 43 浏览量
2022-09-14
22:29:44
上传
评论
收藏 38KB RAR 举报
温馨提示
AddFilter Storage Filter Tool AddFilter Storage Filter Tool
资源详情
资源评论
资源推荐
收起资源包目录
AddFilter-Storage-Filter-Tool.rar (16个子文件)
AddFilter Storage Filter Tool
description
19eccd10-9a4c-4ebc-a240-2680a581332eBrand.css 6KB
dc96e5d0-205a-4f07-963c-0adecf31d9c1Combined.css 0B
Brand.css 70KB
Combined.css 0B
Layout.css 2KB
offline.js 2KB
Galleries.css 10KB
iframedescription.css 3KB
description.html 15KB
C++
src
addfilter.c 33KB
addfilter.vcxproj.Filters 841B
addfilter.rc 644B
addfiltr.htm 10KB
addfilter.vcxproj 26KB
addfilter.sln 3KB
license.rtf 5KB
共 16 条
- 1
weixin_42653672
- 粉丝: 94
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0