/*++
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_The Given
版权申诉
166 浏览量
2022-09-21
19:13:35
上传
评论
收藏 39KB RAR 举报
寒泊
- 粉丝: 75
- 资源: 1万+
最新资源
- 基于图像的三维模型重建C++源代码+文档说明(高分课程设计)
- 基于聚焦法的工件立体测量方案,根据数据进行三维重建 使用HALCON处理图像,MATLAB拟合数据+源代码+数据集+效果图
- 锄战三国村 修改:货币使用不减 v1.10(2) 原创 (中文).apk
- 基于python实现的单目双目视觉三维重建+源代码+图像图片(高分课程设计)
- 基于C+++OPENCV的全景图像拼接源码(课程设计)
- 基于Python+OpenCV对多张图片进行全景图像拼接,消除鬼影,消除裂缝+源代码+文档说明+界面截图(高分课程设计)
- 基于C++实现的全景图像拼接源码(课程设计)
- 基于SIFT特征点提取和RASIC算法实现全景图像拼接python源码+文档说明+界面截图+详细注释(95分以上课程大作业)
- 基于matlab实现眼部判别的疲劳检测系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的异常姿势识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈