From c39cb207eb53bbb6196f398287c32d5d72fb9fa7 Mon Sep 17 00:00:00 2001 From: Adonais Romero González Date: Wed, 27 Sep 2023 10:37:01 -0700 Subject: [storage/filters] Remove deprecated sample --- storage/filters/addfilter/README.md | 34 - storage/filters/addfilter/addfilter.sln | 28 - storage/filters/addfilter/src/addfilter.c | 1129 -------------------- storage/filters/addfilter/src/addfilter.rc | 21 - storage/filters/addfilter/src/addfilter.vcxproj | 191 ---- .../addfilter/src/addfilter.vcxproj.Filters | 27 - 6 files changed, 1430 deletions(-) delete mode 100644 storage/filters/addfilter/README.md delete mode 100644 storage/filters/addfilter/addfilter.sln delete mode 100644 storage/filters/addfilter/src/addfilter.c delete mode 100644 storage/filters/addfilter/src/addfilter.rc delete mode 100644 storage/filters/addfilter/src/addfilter.vcxproj delete mode 100644 storage/filters/addfilter/src/addfilter.vcxproj.Filters diff --git a/storage/filters/addfilter/README.md b/storage/filters/addfilter/README.md deleted file mode 100644 index 149922df..00000000 --- a/storage/filters/addfilter/README.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -page_type: sample -description: "A command-line application that adds and removes filter drivers for a given drive or volume." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# AddFilter Storage Filter Tool - -Addfilter is a command-line application that adds and removes filter drivers for a given drive or volume. This application demonstrates how to insert a filter driver into the driver stack of a device. The sample illustrates how to insert such a filter driver by using the SetupDi API. - -## Installation and Operation - -This initial sample does not check the filter for validity before it is added to the driver stack. If an invalid filter is added, the specified device might no longer be accessible. - -The minifilter identifies implicit locks when it sees a non-shared write open request on a volume object. In this scenario, the minifilter closes its metadata file and sets a trigger that corresponds to the volume in its instance object. Later, each close operation is examined to identify if the implicit lock on the volume is being released and, if so, a re-open of the minifilter's metadata file is triggered. - -> [!IMPORTANT] -> If you attempt to add a non-existing filter to a boot device and then restart, the system might show the INACCESSIBLE\_BOOT\_DEVICE error message. If this message appears, you will be unable to start the computer. To fix this problem, when the startup menu is displayed when the computer starts up, go to the Advanced Options screen and select **Use Last Known Good Profile**. - -The sample is intended for use with upper filter drivers only. - -When you add a filter to a device, that device needs to be restarted. Depending on the device, you might also need to restart your computer. The RestartDevice function (in *Addfilter.c*) stops the specified device and then restarts it. If the device has been stopped but not restarted, and the computer is restarted, the restart will not necessarily restart the device. You will need to call the RestartDevice function to restart your device. - -Because the sample currently enumerates only disk devices, the sample can operate only on devices of this class. To extend this sample code, you can add another command-line argument that handles other device types. - -The following is the command line usage for addfilter: - -`addfilter [/listdevices] [/device device_name] [/add filter] [/remove filter]` - -If the device name is not supplied, settings will apply to all devices. If there is no /add or /remove argument, a list of currently installed drivers will be printed. diff --git a/storage/filters/addfilter/addfilter.sln b/storage/filters/addfilter/addfilter.sln deleted file mode 100644 index f2c404f5..00000000 --- a/storage/filters/addfilter/addfilter.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0 -MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "addfilter", "src\addfilter.vcxproj", "{95C071C0-CBCC-4943-BB7D-90E2EDD17043}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Debug|Win32.ActiveCfg = Debug|Win32 - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Debug|Win32.Build.0 = Debug|Win32 - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Release|Win32.ActiveCfg = Release|Win32 - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Release|Win32.Build.0 = Release|Win32 - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Debug|x64.ActiveCfg = Debug|x64 - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Debug|x64.Build.0 = Debug|x64 - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Release|x64.ActiveCfg = Release|x64 - {95C071C0-CBCC-4943-BB7D-90E2EDD17043}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/storage/filters/addfilter/src/addfilter.c b/storage/filters/addfilter/src/addfilter.c deleted file mode 100644 index 5c319bf7..00000000 --- a/storage/filters/addfilter/src/addfilter.c +++ /dev/null @@ -1,1129 +0,0 @@ -/*++ - -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 -_Analysis_mode_(_Analysis_code_type_user_code_); - -#include -#include -#include - -// defines GUID -#include - -// the SetupDiXXX api (from the DDK) -#include - -// defines guids for device classes (GUID_DEVINTERFACE_DISK, etc) -#include -#include - -// for all of the _t stuff (to allow compiling for both Unicode/Ansi) -#include - -#include - -#if DBG -#include -#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 0 ); - - if( length == 1 ) - { - // if the length of the list is 1, the return value from - // MultiSzLength() was just accounting for the trailing '\0', so we can - // delete the registry key, by setting it to NULL. - success = SetupDiSetDeviceRegistryProperty( DeviceInfoSet, - DeviceInfoData, - (UpperFilter ? SPDRP_UPPERFILTERS : SPDRP_LOWERFILTERS), - NULL, - 0 ); - } - else - { - // set the new list of drivers into the registry - size = length*sizeof(_TCHAR); - success = SetupDiSetDeviceRegistryProperty( DeviceInfoSet, - DeviceInfoData, - (UpperFilter ? SPDRP_UPPERFILTERS : SPDRP_LOWERFILTERS), - (PBYTE)buffer, - (DWORD)size ); - } - - // no need for buffer anymore - free( buffer ); - - if( !success ) - { - printf("in RemoveUpperFilterDriver(): " - "couldn't set registry value! error: %u\n", GetLastError()); - return (FALSE); - } - - return (TRUE); -} - -/* - * print the list of upper filters for the given device - * - * parameters: - * DeviceInfoSet - The device information set which contains DeviceInfoData - * DeviceInfoData - Information needed to deal with the given device - */ -void -PrintFilters( - IN HDEVINFO DeviceInfoSet, - IN PSP_DEVINFO_DATA DeviceInfoData, - IN BOOLEAN UpperFilters - ) -{ - // get the list of filters - LPTSTR buffer = GetFilters( DeviceInfoSet, DeviceInfoData, UpperFilters ); - LPTSTR filterName; - DWORD filterPosition; - - if( buffer == NULL ) - { - // if there is no such value in the registry, then there are no upper - // filter drivers loaded - printf("There are no upper filter drivers loaded for this device.\n"); - } - else - { - // go through the multisz and print out each driver - filterPosition=0; - filterName = buffer; - while( *filterName != _T('\0') ) - { - _tprintf(_T("%u: %s\n"), filterPosition, filterName); - filterName += _tcslen(filterName)+1; - filterPosition++; - } - - // no need for buffer anymore - free( buffer ); - } - - return; -} - -/* - * print the device name - * - * parameters: - * DeviceInfoSet - The device information set which contains DeviceInfoData - * DeviceInfoData - Information needed to deal with the given device - */ -void PrintDeviceName( - IN HDEVINFO DeviceInfoSet, - IN PSP_DEVINFO_DATA DeviceInfoData - ) -{ - DWORD regDataType; - LPTSTR deviceName = - (LPTSTR) GetDeviceRegistryProperty( DeviceInfoSet, - DeviceInfoData, - SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, - ®DataType ); - - if( deviceName != NULL ) - { - // just to make sure we are getting the expected type of buffer - if( regDataType != REG_SZ ) - { - printf("in PrintDeviceName(): registry key is not an SZ!\n"); - } - else - { - // if the device name starts with \Device, cut that off (all - // devices will start with it, so it is redundant) - - if( _tcsncmp(deviceName, _T("\\Device"), 7) == 0 ) - { - memmove(deviceName, - deviceName+7, - (_tcslen(deviceName)-6)*sizeof(_TCHAR) ); - } - - _tprintf(_T("%s\n"), deviceName); - } - free( deviceName ); - } - else - { - printf("in PrintDeviceName(): registry key is NULL! error: %u\n", - GetLastError()); - } - - return; -} - -/* - * Returns a buffer containing the list of upper filters for the device. (NULL - * is returned if there is no buffer, or an error occurs) - * The buffer must be freed by the caller. - * - * parameters: - * DeviceInfoSet - The device information set which contains DeviceInfoData - * DeviceInfoData - Information needed to deal with the given device - */ -LPTSTR -GetFilters( - IN HDEVINFO DeviceInfoSet, - IN PSP_DEVINFO_DATA DeviceInfoData, - IN BOOLEAN UpperFilters - ) -{ - DWORD regDataType; - LPTSTR buffer = (LPTSTR) GetDeviceRegistryProperty( DeviceInfoSet, - DeviceInfoData, - (UpperFilters ? SPDRP_UPPERFILTERS : SPDRP_LOWERFILTERS), - ®DataType ); - - // just to make sure we are getting the expected type of buffer - if( buffer != NULL && regDataType != REG_MULTI_SZ ) - { - printf("in GetUpperFilters(): " - "registry key is not a MULTI_SZ!\n"); - free( buffer ); - return (NULL); - } - - return (buffer); -} - -/* - * return true if DeviceName matches the name of the device specified by - * DeviceInfoData - * - * parameters: - * DeviceInfoSet - The device information set which contains DeviceInfoData - * DeviceInfoData - Information needed to deal with the given device - * DeviceName - the name to try to match - */ -BOOLEAN -DeviceNameMatches( - IN HDEVINFO DeviceInfoSet, - IN PSP_DEVINFO_DATA DeviceInfoData, - _In_ IN LPTSTR DeviceName - ) -{ - BOOLEAN matching = FALSE; - DWORD regDataType; - - // get the device name - LPTSTR deviceName = - (LPTSTR) GetDeviceRegistryProperty( DeviceInfoSet, - DeviceInfoData, - SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, - ®DataType ); - - if( deviceName != NULL ) - { - // just to make sure we are getting the expected type of buffer - if( regDataType != REG_SZ ) - { - printf("in DeviceNameMatches(): registry key is not an SZ!\n"); - matching = FALSE; - } - else - { - // if the device name starts with \Device, cut that off (all - // devices will start with it, so it is redundant) - - if( _tcsncmp(deviceName, _T("\\Device"), 7) == 0 ) - { - memmove(deviceName, - deviceName+7, - (_tcslen(deviceName)-6)*sizeof(_TCHAR) ); - } - - // do the strings match? - matching = (_tcscmp(deviceName, DeviceName) == 0) ? TRUE : FALSE; - } - free( deviceName ); - } - else - { - printf("in DeviceNameMatches(): registry key is NULL!\n"); - matching = FALSE; - } - - return (matching); -} - -/* - * A wrapper around SetupDiGetDeviceRegistryProperty, so that I don't have to - * deal with memory allocation anywhere else - * - * parameters: - * DeviceInfoSet - The device information set which contains DeviceInfoData - * DeviceInfoData - Information needed to deal with the given device - * Property - which property to get (SPDRP_XXX) - * PropertyRegDataType - the type of registry property - */ -PBYTE -GetDeviceRegistryProperty( - IN HDEVINFO DeviceInfoSet, - IN PSP_DEVINFO_DATA DeviceInfoData, - IN DWORD Property, - OUT PDWORD PropertyRegDataType - ) -{ - DWORD length = 0; - PBYTE buffer = NULL; - - // get the required length of the buffer - if( SetupDiGetDeviceRegistryProperty( DeviceInfoSet, - DeviceInfoData, - Property, - NULL, // registry data type - NULL, // buffer - 0, // buffer size - &length // required size - ) ) - { - // we should not be successful at this point, so this call succeeding - // is an error condition - printf("in GetDeviceRegistryProperty(): " - "call SetupDiGetDeviceRegistryProperty did not fail? (%x)\n", - GetLastError()); - return (NULL); - } - - if( GetLastError() != ERROR_INSUFFICIENT_BUFFER ) - { - // this means there are no upper filter drivers loaded, so we can just - // return. - return (NULL); - } - - // since we don't have a buffer yet, it is "insufficient"; we allocate - // one and try again. - buffer = malloc( length ); - if( buffer == NULL ) - { - printf("in GetDeviceRegistryProperty(): " - "unable to allocate memory!\n"); - return (NULL); - } - if( !SetupDiGetDeviceRegistryProperty( DeviceInfoSet, - DeviceInfoData, - Property, - PropertyRegDataType, - buffer, - length, - NULL // required size - ) ) - { - printf("in GetDeviceRegistryProperty(): " - "couldn't get registry property! error: %u\n", - GetLastError()); - free( buffer ); - return (NULL); - } - - // ok, we are finally done, and can return the buffer - return (buffer); -} - - -/* - * restarts the given device - * - * call CM_Query_And_Remove_Subtree (to unload the driver) - * call CM_Reenumerate_DevNode on the _parent_ (to reload the driver) - * - * parameters: - * DeviceInfoSet - The device information set which contains DeviceInfoData - * DeviceInfoData - Information needed to deal with the given device - */ -BOOLEAN -RestartDevice( - IN HDEVINFO DeviceInfoSet, - IN OUT PSP_DEVINFO_DATA DeviceInfoData - ) -{ - SP_PROPCHANGE_PARAMS params; - SP_DEVINSTALL_PARAMS installParams; - - // for future compatibility; this will zero out the entire struct, rather - // than just the fields which exist now - memset(¶ms, 0, sizeof(SP_PROPCHANGE_PARAMS)); - - // initialize the SP_CLASSINSTALL_HEADER struct at the beginning of the - // SP_PROPCHANGE_PARAMS struct, so that SetupDiSetClassInstallParams will - // work - params.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); - params.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; - - // initialize SP_PROPCHANGE_PARAMS such that the device will be stopped. - params.StateChange = DICS_STOP; - params.Scope = DICS_FLAG_CONFIGSPECIFIC; - params.HwProfile = 0; // current profile - - // prepare for the call to SetupDiCallClassInstaller (to stop the device) - if( !SetupDiSetClassInstallParams( DeviceInfoSet, - DeviceInfoData, - (PSP_CLASSINSTALL_HEADER) ¶ms, - sizeof(SP_PROPCHANGE_PARAMS) - ) ) - { - printf("in RestartDevice(): couldn't set the install parameters!"); - printf(" error: %u\n", GetLastError()); - return (FALSE); - } - - // stop the device - if( !SetupDiCallClassInstaller( DIF_PROPERTYCHANGE, - DeviceInfoSet, - DeviceInfoData ) - ) - { - printf("in RestartDevice(): call to class installer (STOP) failed!"); - printf(" error: %u\n", GetLastError() ); - return (FALSE); - } - - // restarting the device - params.StateChange = DICS_START; - - // prepare for the call to SetupDiCallClassInstaller (to stop the device) - if( !SetupDiSetClassInstallParams( DeviceInfoSet, - DeviceInfoData, - (PSP_CLASSINSTALL_HEADER) ¶ms, - sizeof(SP_PROPCHANGE_PARAMS) - ) ) - { - printf("in RestartDevice(): couldn't set the install parameters!"); - printf(" error: %u\n", GetLastError()); - return (FALSE); - } - - // restart the device - if( !SetupDiCallClassInstaller( DIF_PROPERTYCHANGE, - DeviceInfoSet, - DeviceInfoData ) - ) - { - printf("in RestartDevice(): call to class installer (START) failed!"); - printf(" error: %u\n", GetLastError()); - return (FALSE); - } - - installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS); - - // same as above, the call will succeed, but we still need to check status - if( !SetupDiGetDeviceInstallParams( DeviceInfoSet, - DeviceInfoData, - &installParams ) - ) - { - printf("in RestartDevice(): couldn't get the device install params!"); - printf(" error: %u\n", GetLastError() ); - return (FALSE); - } - - // to see if the machine needs to be rebooted - if( installParams.Flags & DI_NEEDREBOOT ) - { - return (FALSE); - } - - // if we get this far, then the device has been stopped and restarted - return (TRUE); -} - - -/* - * prepend the given string to a MultiSz - * - * returns true if successful, false if not (will only fail in memory - * allocation) - * - * note: This WILL allocate and free memory, so don't keep pointers to the - * MultiSz passed in. - * - * parameters: - * SzToPrepend - string to prepend - * MultiSz - pointer to a MultiSz which will be prepended-to - */ -BOOLEAN -PrependSzToMultiSz( - _In_ LPTSTR SzToPrepend, - _Inout_ LPTSTR *MultiSz - ) -{ - size_t szLen; - size_t multiSzLen; - LPTSTR newMultiSz = NULL; - - ASSERT(SzToPrepend != NULL); - ASSERT(MultiSz != NULL); - - if (SzToPrepend == NULL || MultiSz == NULL) { - return (FALSE); - } - - // get the size, in bytes, of the two buffers - szLen = (_tcslen(SzToPrepend)+1)*sizeof(_TCHAR); - multiSzLen = MultiSzLength(*MultiSz)*sizeof(_TCHAR); - newMultiSz = (LPTSTR)malloc( szLen+multiSzLen ); - - if( newMultiSz == NULL ) - { - return (FALSE); - } - - // recopy the old MultiSz into proper position into the new buffer. - // the (char*) cast is necessary, because newMultiSz may be a wchar*, and - // szLen is in bytes. - - memcpy( ((char*)newMultiSz) + szLen, *MultiSz, multiSzLen ); - - // copy in the new string - StringCbCopy( newMultiSz, szLen, SzToPrepend ); - - free( *MultiSz ); - *MultiSz = newMultiSz; - - return (TRUE); -} - - -/* - * returns the length (in characters) of the buffer required to hold this - * MultiSz, INCLUDING the trailing null. - * - * example: MultiSzLength("foo\0bar\0") returns 9 - * - * note: since MultiSz cannot be null, a number >= 1 will always be returned - * - * parameters: - * MultiSz - the MultiSz to get the length of - */ -size_t -MultiSzLength( - _In_ IN LPTSTR MultiSz - ) -{ - size_t len = 0; - size_t totalLen = 0; - - ASSERT( MultiSz != NULL ); - - // search for trailing null character - while( *MultiSz != _T('\0') ) - { - len = _tcslen(MultiSz)+1; - MultiSz += len; - totalLen += len; - } - - // add one for the trailing null character - return (totalLen+1); -} - - -/* - * Deletes all instances of a string from within a multi-sz. - * - * parameters: - * FindThis - the string to find and remove - * FindWithin - the string having the instances removed - * NewStringLength - the new string length - */ -size_t -MultiSzSearchAndDeleteCaseInsensitive( - _In_ IN LPTSTR FindThis, - _In_ IN LPTSTR FindWithin, - OUT size_t *NewLength - ) -{ - LPTSTR search; - size_t currentOffset; - DWORD instancesDeleted; - size_t searchLen; - - ASSERT(FindThis != NULL); - ASSERT(FindWithin != NULL); - ASSERT(NewLength != NULL); - - currentOffset = 0; - instancesDeleted = 0; - search = FindWithin; - - *NewLength = MultiSzLength(FindWithin); - - // loop while the multisz null terminator is not found - while ( *search != _T('\0') ) - { - // length of string + null char; used in more than a couple places - searchLen = _tcslen(search) + 1; - - // if this string matches the current one in the multisz... - if( _tcsicmp(search, FindThis) == 0 ) - { - // they match, shift the contents of the multisz, to overwrite the - // string (and terminating null), and update the length - instancesDeleted++; - *NewLength -= searchLen; - memmove( search, - search + searchLen, - (*NewLength - currentOffset) * sizeof(TCHAR) ); - } - else - { - // they don't mactch, so move pointers, increment counters - currentOffset += searchLen; - search += searchLen; - } - } - - return (instancesDeleted); -} - - -/* - * print usage - */ -void PrintUsage() -{ - printf("usage:\n\n" - "addfilter" - " [/listdevices]" - " [/device device_name]" - " [/add filter]" - " [/remove filter]" - " [/lower]" - "\n\n"); - printf("If device_name is not supplied, settings will apply " - "to all devices.\n"); - printf("If there is no /add or /remove argument, a list of currently" - " installed drivers\n" - "will be printed.\n"); - printf("The default is to process upper filters. Use the /lower switch" - " to process lower filters instead.\n"); - return; -} diff --git a/storage/filters/addfilter/src/addfilter.rc b/storage/filters/addfilter/src/addfilter.rc deleted file mode 100644 index 2568f031..00000000 --- a/storage/filters/addfilter/src/addfilter.rc +++ /dev/null @@ -1,21 +0,0 @@ -//+------------------------------------------------------------------------- -// -// Microsoft Windows -// -// Copyright (C) Microsoft Corporation, 1999 - 1999 -// -// File: addfilter.rc -// -//-------------------------------------------------------------------------- - -#include -#include - -#define VER_FILETYPE VFT_APP -#define VER_FILESUBTYPE VFT2_UNKNOWN -#define VER_FILEDESCRIPTION_STR "Microsoft add/remove filter drivers sample utility" - -#define VER_INTERNALNAME_STR "addfilter.exe" -#define VER_ORIGINALFILENAME_STR "addfilter.exe" - -#include diff --git a/storage/filters/addfilter/src/addfilter.vcxproj b/storage/filters/addfilter/src/addfilter.vcxproj deleted file mode 100644 index 7216a90a..00000000 --- a/storage/filters/addfilter/src/addfilter.vcxproj +++ /dev/null @@ -1,191 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {95C071C0-CBCC-4943-BB7D-90E2EDD17043} - $(MSBuildProjectName) - Debug - Win32 - {E441786B-1740-49DB-ACB6-E800A4DB2D15} - - - - Windows10 - False - Windows Driver - - WindowsApplicationForDrivers10.0 - Application - - - Windows10 - True - Windows Driver - - WindowsApplicationForDrivers10.0 - Application - - - Windows10 - False - Windows Driver - - WindowsApplicationForDrivers10.0 - Application - - - Windows10 - True - Windows Driver - - WindowsApplicationForDrivers10.0 - Application - - - - $(IntDir) - - - - - - - - - - - - - - - - addfilter - - - addfilter - - - addfilter - - - addfilter - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalIncludeDirectories) - true - Level4 - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalDependencies);setupapi.lib - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalIncludeDirectories) - true - Level4 - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalDependencies);setupapi.lib - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalIncludeDirectories) - true - Level4 - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalDependencies);setupapi.lib - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalIncludeDirectories) - true - Level4 - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions);_UNICODE;UNICODE - - - %(AdditionalDependencies);setupapi.lib - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/storage/filters/addfilter/src/addfilter.vcxproj.Filters b/storage/filters/addfilter/src/addfilter.vcxproj.Filters deleted file mode 100644 index 9b5df5cf..00000000 --- a/storage/filters/addfilter/src/addfilter.vcxproj.Filters +++ /dev/null @@ -1,27 +0,0 @@ - - - - - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;* - {BFD7B380-2B08-4124-81F2-BD9E9E1E59BB} - - - h;hpp;hxx;hm;inl;inc;xsd - {84770C65-A89D-40AC-BFB6-2D42A6ECD7C4} - - - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml - {E60018BB-F626-48CB-90FA-2817FC2C2C06} - - - - - Source Files - - - - - Resource Files - - - \ No newline at end of file -- cgit v1.3.1