Something went wrong. Try again.
Reactos
Something went wrong. Try again.
12 kB · 436 lines
C++
at listview
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437/** PROJECT: ReactOS fltmc utility* LICENSE: GPL - See COPYING in the top level directory* FILE: base/applications/fltmc/fltmc.c* PURPOSE: Control utility for file system filter drivers* PROGRAMMERS: Copyright 2016 Ged Murphy (gedmurphy@gmail.com)*/
// Please leave this temporary hack in place// it's used to keep VS2015 happy for development.#ifdef __REACTOS__#include <stdarg.h>#include <windef.h>#include <winbase.h>#include <wchar.h>#else#include <Windows.h>#endif#include <fltuser.h>#include <atlstr.h>#include <strsafe.h>#include "resource.h"
EXTERN_C int wmain(int argc, WCHAR *argv[]);
voidLoadAndPrintString(ULONG MessageId, ...){ va_list args;
CAtlStringW Message; if (Message.LoadStringW(MessageId)) { va_start(args, MessageId); vwprintf(Message.GetBuffer(), args); va_end(args); }}
voidPrintErrorText(_In_ ULONG ErrorCode){ WCHAR Buffer[256]; if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrorCode, 0, Buffer, 256, 0)) { wprintf(L"%s\n", Buffer); }}
DWORDSetDriverLoadPrivilege(){ TOKEN_PRIVILEGES TokenPrivileges; HANDLE hToken; LUID luid; BOOL bSuccess; DWORD dwError = ERROR_SUCCESS;
bSuccess = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken); if (bSuccess == FALSE) return GetLastError();
if (!LookupPrivilegeValueW(NULL, SE_LOAD_DRIVER_NAME, &luid)) return GetLastError();
TokenPrivileges.PrivilegeCount = 1; TokenPrivileges.Privileges[0].Luid = luid; TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bSuccess = AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), NULL, NULL); if (bSuccess == FALSE) dwError = GetLastError();
CloseHandle(hToken);
return dwError;}
voidLoadFilter(_In_ LPWSTR FilterName){ DWORD dwError; dwError = SetDriverLoadPrivilege(); if (dwError != ERROR_SUCCESS) { LoadAndPrintString(IDS_ERROR_PRIV, HRESULT_FROM_WIN32(dwError)); return; }
HRESULT hr = FilterLoad(FilterName); if (hr != S_OK) { LoadAndPrintString(IDS_ERROR_LOAD, hr); PrintErrorText(hr); }}
voidUnloadFilter(_In_ LPWSTR FilterName){ DWORD dwError; dwError = SetDriverLoadPrivilege(); if (dwError != ERROR_SUCCESS) { LoadAndPrintString(IDS_ERROR_PRIV, HRESULT_FROM_WIN32(dwError)); return; }
HRESULT hr = FilterUnload(FilterName); if (hr != S_OK) { LoadAndPrintString(IDS_ERROR_UNLOAD, hr); PrintErrorText(hr); }}
voidPrintFilterInfo(_In_ PVOID Buffer, _In_ BOOL IsNewStyle){ WCHAR FilterName[128] = { 0 }; WCHAR NumOfInstances[16] = { 0 }; WCHAR Altitude[64] = { 0 }; WCHAR Frame[16] = { 0 };
if (IsNewStyle) { PFILTER_AGGREGATE_STANDARD_INFORMATION FilterAggInfo; FilterAggInfo = (PFILTER_AGGREGATE_STANDARD_INFORMATION)Buffer;
if (FilterAggInfo->Flags & FLTFL_ASI_IS_MINIFILTER) { if (FilterAggInfo->Type.MiniFilter.FilterNameLength < 128) { CopyMemory(FilterName, (PCHAR)FilterAggInfo + FilterAggInfo->Type.MiniFilter.FilterNameBufferOffset, FilterAggInfo->Type.MiniFilter.FilterNameLength); FilterName[FilterAggInfo->Type.MiniFilter.FilterNameLength] = UNICODE_NULL; }
StringCchPrintfW(NumOfInstances, 16, L"%lu", FilterAggInfo->Type.MiniFilter.NumberOfInstances);
if (FilterAggInfo->Type.MiniFilter.FilterAltitudeLength < 64) { CopyMemory(Altitude, (PCHAR)FilterAggInfo + FilterAggInfo->Type.MiniFilter.FilterAltitudeBufferOffset, FilterAggInfo->Type.MiniFilter.FilterAltitudeLength); FilterName[FilterAggInfo->Type.MiniFilter.FilterAltitudeLength] = UNICODE_NULL; }
StringCchPrintfW(Frame, 16, L"%lu", FilterAggInfo->Type.MiniFilter.FrameID); } else if (FilterAggInfo->Flags & FLTFL_ASI_IS_LEGACYFILTER) { if (FilterAggInfo->Type.LegacyFilter.FilterNameLength < 128) { CopyMemory(FilterName, (PCHAR)FilterAggInfo + FilterAggInfo->Type.LegacyFilter.FilterNameBufferOffset, FilterAggInfo->Type.LegacyFilter.FilterNameLength); FilterName[FilterAggInfo->Type.LegacyFilter.FilterNameLength] = UNICODE_NULL; }
StringCchCopyW(Frame, 16, L"<Legacy>"); //Fixme: is this localized? }
wprintf(L"%-38s %-10s %-10s %3s\n", FilterName, NumOfInstances, Altitude, Frame); } else { PFILTER_FULL_INFORMATION FilterInfo; FilterInfo = (PFILTER_FULL_INFORMATION)Buffer;
if (FilterInfo->FilterNameLength < 128) { CopyMemory(FilterName, FilterInfo->FilterNameBuffer, FilterInfo->FilterNameLength); FilterName[FilterInfo->FilterNameLength] = UNICODE_NULL; }
wprintf(L"%-38s %-10lu %-10lu\n", FilterName, FilterInfo->NumberOfInstances, FilterInfo->FrameID); }}
voidPrintVolumeInfo(_In_ PVOID Buffer){ PFILTER_VOLUME_STANDARD_INFORMATION FilterVolInfo; WCHAR DosName[16] = { 0 }; WCHAR VolName[128] = { 0 }; WCHAR FileSystem[32] = { 0 };
FilterVolInfo = (PFILTER_VOLUME_STANDARD_INFORMATION)Buffer;
if (FilterVolInfo->FilterVolumeNameLength < 128) { CopyMemory(VolName, (PCHAR)FilterVolInfo->FilterVolumeName, FilterVolInfo->FilterVolumeNameLength); VolName[FilterVolInfo->FilterVolumeNameLength] = UNICODE_NULL; }
if (!SUCCEEDED(FilterGetDosName(VolName, DosName, _countof(DosName)))) DosName[0] = L'\0';
switch (FilterVolInfo->FileSystemType) { case FLT_FSTYPE_MUP: StringCchCopyW(FileSystem, 32, L"Remote"); break;
case FLT_FSTYPE_NTFS: StringCchCopyW(FileSystem, 32, L"NTFS"); break;
case FLT_FSTYPE_FAT: StringCchCopyW(FileSystem, 32, L"FAT"); break;
case FLT_FSTYPE_EXFAT: StringCchCopyW(FileSystem, 32, L"exFAT"); break;
case FLT_FSTYPE_NPFS: StringCchCopyW(FileSystem, 32, L"NamedPipe"); break;
case FLT_FSTYPE_MSFS: StringCchCopyW(FileSystem, 32, L"Mailslot"); break;
case FLT_FSTYPE_UNKNOWN: default: StringCchCopyW(FileSystem, 32, L"<Unknown>"); break; }
wprintf(L"%-31s %-40s %-10s\n", DosName, VolName, FileSystem);}
voidListFilters(){ HANDLE FindHandle; BYTE Buffer[1024]; ULONG BytesReturned; BOOL IsNewStyle = TRUE; HRESULT hr;
hr = FilterFindFirst(FilterAggregateStandardInformation, Buffer, sizeof(Buffer), &BytesReturned, &FindHandle); if (!SUCCEEDED(hr)) { IsNewStyle = FALSE; hr = FilterFindFirst(FilterFullInformation, Buffer, sizeof(Buffer), &BytesReturned, &FindHandle); }
if (!SUCCEEDED(hr)) { LoadAndPrintString(IDS_ERROR_FILTERS, hr); PrintErrorText(hr); return; }
if (IsNewStyle) { LoadAndPrintString(IDS_DISPLAY_FILTERS1); wprintf(L"------------------------------ ------------- ------------ -----\n"); } else { LoadAndPrintString(IDS_DISPLAY_FILTERS2); wprintf(L"------------------------------ ------------- -----\n"); }
PrintFilterInfo(Buffer, IsNewStyle);
do { hr = FilterFindNext(FindHandle, IsNewStyle ? FilterAggregateStandardInformation : FilterFullInformation, Buffer, sizeof(Buffer), &BytesReturned); if (SUCCEEDED(hr)) { PrintFilterInfo(Buffer, IsNewStyle); } else if (hr != HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS)) { LoadAndPrintString(IDS_ERROR_FILTERS, hr); PrintErrorText(hr); } } while (SUCCEEDED(hr));
hr = FilterFindClose(FindHandle); if (!SUCCEEDED(hr)) { LoadAndPrintString(IDS_ERROR_FILTERS, hr); PrintErrorText(hr); }}
voidListVolumes(){ HANDLE FindHandle; BYTE Buffer[1024]; ULONG BytesReturned; HRESULT hr;
hr = FilterVolumeFindFirst(FilterVolumeStandardInformation, Buffer, 1024, &BytesReturned, &FindHandle); if (SUCCEEDED(hr)) { LoadAndPrintString(IDS_DISPLAY_VOLUMES); wprintf(L"------------------------------ --------------------------------------- ---------- --------\n");
PrintVolumeInfo(Buffer);
do { hr = FilterVolumeFindNext(FindHandle, FilterVolumeStandardInformation, Buffer, 1024, &BytesReturned); if (SUCCEEDED(hr)) { PrintVolumeInfo(Buffer); }
} while (SUCCEEDED(hr));
FilterVolumeFindClose(FindHandle); }
if (!SUCCEEDED(hr) && hr != HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS)) { LoadAndPrintString(IDS_ERROR_VOLUMES, hr); PrintErrorText(hr); }}
int wmain(int argc, WCHAR *argv[]){ wprintf(L"\n");
if ((argc < 2) || (!_wcsicmp(argv[1], L"filters"))) { if (argc < 3) { ListFilters(); } else { LoadAndPrintString(IDS_USAGE_FILTERS); wprintf(L"fltmc.exe filters\n\n"); } } else if (!_wcsicmp(argv[1], L"help")) { LoadAndPrintString(IDS_USAGE); } else if (!_wcsicmp(argv[1], L"load")) { if (argc == 3) { LoadFilter(argv[2]); } else { LoadAndPrintString(IDS_USAGE_LOAD); wprintf(L"fltmc.exe load [name]\n\n"); } } else if (!_wcsicmp(argv[1], L"unload")) { if (argc == 3) { UnloadFilter(argv[2]); } else { LoadAndPrintString(IDS_USAGE_UNLOAD); wprintf(L"fltmc.exe unload [name]\n\n"); } } else if (!_wcsicmp(argv[1], L"volumes")) { if (argc == 2) { ListVolumes(); } else { LoadAndPrintString(IDS_USAGE_VOLUMES); wprintf(L"fltmc.exe volumes\n\n"); } }
return 0;}