ReactOS 0.4.16-dev-106-g10b08aa
fltmc.cpp File Reference
#include <Windows.h>
#include <fltuser.h>
#include <atlstr.h>
#include <strsafe.h>
#include "resource.h"
Include dependency graph for fltmc.cpp:

Go to the source code of this file.

Functions

EXTERN_C int wmain (int argc, WCHAR *argv[])
 
void LoadAndPrintString (ULONG MessageId,...)
 
void PrintErrorText (_In_ ULONG ErrorCode)
 
DWORD SetDriverLoadPrivilege ()
 
void LoadFilter (_In_ LPWSTR FilterName)
 
void UnloadFilter (_In_ LPWSTR FilterName)
 
void PrintFilterInfo (_In_ PVOID Buffer, _In_ BOOL IsNewStyle)
 
void PrintVolumeInfo (_In_ PVOID Buffer)
 
void ListFilters ()
 
void ListVolumes ()
 

Function Documentation

◆ ListFilters()

void ListFilters ( )

Definition at line 265 of file fltmc.cpp.

266{
267 HANDLE FindHandle;
268 BYTE Buffer[1024];
270 BOOL IsNewStyle = TRUE;
271 HRESULT hr;
272
273 hr = FilterFindFirst(FilterAggregateStandardInformation,
274 Buffer,
275 sizeof(Buffer),
277 &FindHandle);
278 if (!SUCCEEDED(hr))
279 {
280 IsNewStyle = FALSE;
281 hr = FilterFindFirst(FilterFullInformation,
282 Buffer,
283 sizeof(Buffer),
285 &FindHandle);
286 }
287
288 if (!SUCCEEDED(hr))
289 {
292 return;
293 }
294
295 if (IsNewStyle)
296 {
298 wprintf(L"------------------------------ ------------- ------------ -----\n");
299 }
300 else
301 {
303 wprintf(L"------------------------------ ------------- -----\n");
304 }
305
306 PrintFilterInfo(Buffer, IsNewStyle);
307
308 do
309 {
310 hr = FilterFindNext(FindHandle,
311 IsNewStyle ? FilterAggregateStandardInformation : FilterFullInformation,
312 Buffer,
313 sizeof(Buffer),
315 if (SUCCEEDED(hr))
316 {
317 PrintFilterInfo(Buffer, IsNewStyle);
318 }
320 {
323 }
324 } while (SUCCEEDED(hr));
325
326 hr = FilterFindClose(FindHandle);
327 if (!SUCCEEDED(hr))
328 {
331 }
332}
#define IDS_DISPLAY_FILTERS2
Definition: resource.h:10
#define IDS_DISPLAY_FILTERS1
Definition: resource.h:9
#define IDS_ERROR_FILTERS
Definition: resource.h:14
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
_Must_inspect_result_ HRESULT WINAPI FilterFindNext(_In_ HANDLE hFilterFind, _In_ FILTER_INFORMATION_CLASS dwInformationClass, _Out_writes_bytes_to_(dwBufferSize, *lpBytesReturned) LPVOID lpBuffer, _In_ DWORD dwBufferSize, _Out_ LPDWORD lpBytesReturned)
Definition: stubs.c:126
_Must_inspect_result_ HRESULT WINAPI FilterFindFirst(_In_ FILTER_INFORMATION_CLASS dwInformationClass, _Out_writes_bytes_to_(dwBufferSize, *lpBytesReturned) LPVOID lpBuffer, _In_ DWORD dwBufferSize, _Out_ LPDWORD lpBytesReturned, _Out_ LPHANDLE lpFilterFind)
Definition: stubs.c:109
_Must_inspect_result_ HRESULT WINAPI FilterFindClose(_In_ HANDLE hFilterFind)
Definition: stubs.c:143
unsigned int BOOL
Definition: ntddk_ex.h:94
void PrintFilterInfo(_In_ PVOID Buffer, _In_ BOOL IsNewStyle)
Definition: fltmc.cpp:131
void PrintErrorText(_In_ ULONG ErrorCode)
Definition: fltmc.cpp:41
void LoadAndPrintString(ULONG MessageId,...)
Definition: fltmc.cpp:27
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define L(x)
Definition: ntvdm.h:50
HRESULT hr
Definition: shlfolder.c:183
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
#define wprintf(...)
Definition: whoami.c:18
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
unsigned char BYTE
Definition: xxhash.c:193

Referenced by wmain().

◆ ListVolumes()

void ListVolumes ( )

Definition at line 335 of file fltmc.cpp.

336{
337 HANDLE FindHandle;
338 BYTE Buffer[1024];
340 HRESULT hr;
341
342 hr = FilterVolumeFindFirst(FilterVolumeStandardInformation,
343 Buffer,
344 1024,
346 &FindHandle);
347 if (SUCCEEDED(hr))
348 {
350 wprintf(L"------------------------------ --------------------------------------- ---------- --------\n");
351
353
354 do
355 {
356 hr = FilterVolumeFindNext(FindHandle,
357 FilterVolumeStandardInformation,
358 Buffer,
359 1024,
361 if (SUCCEEDED(hr))
362 {
364 }
365
366 } while (SUCCEEDED(hr));
367
368 FilterVolumeFindClose(FindHandle);
369 }
370
372 {
375 }
376}
#define IDS_ERROR_VOLUMES
Definition: resource.h:17
#define IDS_DISPLAY_VOLUMES
Definition: resource.h:11
_Must_inspect_result_ HRESULT WINAPI FilterVolumeFindFirst(_In_ FILTER_VOLUME_INFORMATION_CLASS dwInformationClass, _Out_writes_bytes_to_(dwBufferSize, *lpBytesReturned) LPVOID lpBuffer, _In_ DWORD dwBufferSize, _Out_ LPDWORD lpBytesReturned, _Out_ PHANDLE lpVolumeFind)
Definition: stubs.c:152
_Must_inspect_result_ HRESULT WINAPI FilterVolumeFindNext(_In_ HANDLE hVolumeFind, _In_ FILTER_VOLUME_INFORMATION_CLASS dwInformationClass, _Out_writes_bytes_to_(dwBufferSize, *lpBytesReturned) LPVOID lpBuffer, _In_ DWORD dwBufferSize, _Out_ LPDWORD lpBytesReturned)
Definition: stubs.c:169
HRESULT WINAPI FilterVolumeFindClose(_In_ HANDLE hVolumeFind)
Definition: stubs.c:185
void PrintVolumeInfo(_In_ PVOID Buffer)
Definition: fltmc.cpp:206

Referenced by wmain().

◆ LoadAndPrintString()

void LoadAndPrintString ( ULONG  MessageId,
  ... 
)

Definition at line 27 of file fltmc.cpp.

28{
30
32 if (Message.LoadStringW(MessageId))
33 {
34 va_start(args, MessageId);
35 vwprintf(Message.GetBuffer(), args);
36 va_end(args);
37 }
38}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static const WCHAR Message[]
Definition: register.c:74
_Check_return_opt_ _CRTIMP int __cdecl vwprintf(_In_z_ _Printf_format_string_ const wchar_t *_Format, va_list _ArgList)
Definition: match.c:390

Referenced by ListFilters(), ListVolumes(), LoadFilter(), UnloadFilter(), and wmain().

◆ LoadFilter()

void LoadFilter ( _In_ LPWSTR  FilterName)

Definition at line 93 of file fltmc.cpp.

94{
95 DWORD dwError;
96 dwError = SetDriverLoadPrivilege();
97 if (dwError != ERROR_SUCCESS)
98 {
100 return;
101 }
102
103 HRESULT hr = FilterLoad(FilterName);
104 if (hr != S_OK)
105 {
108 }
109}
#define IDS_ERROR_PRIV
Definition: resource.h:13
#define IDS_ERROR_LOAD
Definition: resource.h:15
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ HRESULT WINAPI FilterLoad(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:42
DWORD SetDriverLoadPrivilege()
Definition: fltmc.cpp:57
#define S_OK
Definition: intsafe.h:52

Referenced by wmain().

◆ PrintErrorText()

void PrintErrorText ( _In_ ULONG  ErrorCode)

Definition at line 41 of file fltmc.cpp.

42{
43 WCHAR Buffer[256];
45 0,
47 0,
48 Buffer,
49 256,
50 0))
51 {
52 wprintf(L"%s\n", Buffer);
53 }
54}
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ListFilters(), ListVolumes(), LoadFilter(), and UnloadFilter().

◆ PrintFilterInfo()

void PrintFilterInfo ( _In_ PVOID  Buffer,
_In_ BOOL  IsNewStyle 
)

Definition at line 131 of file fltmc.cpp.

133{
134 WCHAR FilterName[128] = { 0 };
135 WCHAR NumOfInstances[16] = { 0 };
136 WCHAR Altitude[64] = { 0 };
137 WCHAR Frame[16] = { 0 };
138
139 if (IsNewStyle)
140 {
141 PFILTER_AGGREGATE_STANDARD_INFORMATION FilterAggInfo;
142 FilterAggInfo = (PFILTER_AGGREGATE_STANDARD_INFORMATION)Buffer;
143
144 if (FilterAggInfo->Flags & FLTFL_ASI_IS_MINIFILTER)
145 {
146 if (FilterAggInfo->Type.MiniFilter.FilterNameLength < 128)
147 {
148 CopyMemory(FilterName,
149 (PCHAR)FilterAggInfo + FilterAggInfo->Type.MiniFilter.FilterNameBufferOffset,
150 FilterAggInfo->Type.MiniFilter.FilterNameLength);
151 FilterName[FilterAggInfo->Type.MiniFilter.FilterNameLength] = UNICODE_NULL;
152 }
153
154 StringCchPrintfW(NumOfInstances, 16, L"%lu", FilterAggInfo->Type.MiniFilter.NumberOfInstances);
155
156 if (FilterAggInfo->Type.MiniFilter.FilterAltitudeLength < 64)
157 {
159 (PCHAR)FilterAggInfo + FilterAggInfo->Type.MiniFilter.FilterAltitudeBufferOffset,
160 FilterAggInfo->Type.MiniFilter.FilterAltitudeLength);
161 FilterName[FilterAggInfo->Type.MiniFilter.FilterAltitudeLength] = UNICODE_NULL;
162 }
163
164 StringCchPrintfW(Frame, 16, L"%lu", FilterAggInfo->Type.MiniFilter.FrameID);
165 }
166 else if (FilterAggInfo->Flags & FLTFL_ASI_IS_LEGACYFILTER)
167 {
168 if (FilterAggInfo->Type.LegacyFilter.FilterNameLength < 128)
169 {
170 CopyMemory(FilterName,
171 (PCHAR)FilterAggInfo + FilterAggInfo->Type.LegacyFilter.FilterNameBufferOffset,
172 FilterAggInfo->Type.LegacyFilter.FilterNameLength);
173 FilterName[FilterAggInfo->Type.LegacyFilter.FilterNameLength] = UNICODE_NULL;
174 }
175
176 StringCchCopyW(Frame, 16, L"<Legacy>"); //Fixme: is this localized?
177 }
178
179 wprintf(L"%-38s %-10s %-10s %3s\n",
180 FilterName,
181 NumOfInstances,
182 Altitude,
183 Frame);
184 }
185 else
186 {
187 PFILTER_FULL_INFORMATION FilterInfo;
188 FilterInfo = (PFILTER_FULL_INFORMATION)Buffer;
189
190 if (FilterInfo->FilterNameLength < 128)
191 {
192 CopyMemory(FilterName,
193 FilterInfo->FilterNameBuffer,
194 FilterInfo->FilterNameLength);
195 FilterName[FilterInfo->FilterNameLength] = UNICODE_NULL;
196 }
197
198 wprintf(L"%-38s %-10lu %-10lu\n",
199 FilterName,
200 FilterInfo->NumberOfInstances,
201 FilterInfo->FrameID);
202 }
203}
_Must_inspect_result_ _Inout_ PFLT_VOLUME _In_ PCUNICODE_STRING Altitude
Definition: fltkernel.h:1173
#define UNICODE_NULL
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
char * PCHAR
Definition: typedefs.h:51
#define CopyMemory
Definition: winbase.h:1710

Referenced by ListFilters().

◆ PrintVolumeInfo()

void PrintVolumeInfo ( _In_ PVOID  Buffer)

Definition at line 206 of file fltmc.cpp.

207{
208 PFILTER_VOLUME_STANDARD_INFORMATION FilterVolInfo;
209 WCHAR DosName[16] = { 0 };
210 WCHAR VolName[128] = { 0 };
211 WCHAR FileSystem[32] = { 0 };
212
213 FilterVolInfo = (PFILTER_VOLUME_STANDARD_INFORMATION)Buffer;
214
215 if (FilterVolInfo->FilterVolumeNameLength < 128)
216 {
217 CopyMemory(VolName,
218 (PCHAR)FilterVolInfo->FilterVolumeName,
219 FilterVolInfo->FilterVolumeNameLength);
220 VolName[FilterVolInfo->FilterVolumeNameLength] = UNICODE_NULL;
221 }
222
224 DosName[0] = L'\0';
225
226 switch (FilterVolInfo->FileSystemType)
227 {
228 case FLT_FSTYPE_MUP:
229 StringCchCopyW(FileSystem, 32, L"Remote");
230 break;
231
232 case FLT_FSTYPE_NTFS:
233 StringCchCopyW(FileSystem, 32, L"NTFS");
234 break;
235
236 case FLT_FSTYPE_FAT:
237 StringCchCopyW(FileSystem, 32, L"FAT");
238 break;
239
240 case FLT_FSTYPE_EXFAT:
241 StringCchCopyW(FileSystem, 32, L"exFAT");
242 break;
243
244 case FLT_FSTYPE_NPFS:
245 StringCchCopyW(FileSystem, 32, L"NamedPipe");
246 break;
247
248 case FLT_FSTYPE_MSFS:
249 StringCchCopyW(FileSystem, 32, L"Mailslot");
250 break;
251
252 case FLT_FSTYPE_UNKNOWN:
253 default:
254 StringCchCopyW(FileSystem, 32, L"<Unknown>");
255 break;
256 }
257
258 wprintf(L"%-31s %-40s %-10s\n",
259 DosName,
260 VolName,
261 FileSystem);
262}
PWCHAR FileSystem
Definition: format.c:72
_Must_inspect_result_ HRESULT WINAPI FilterGetDosName(_In_ LPCWSTR lpVolumeName, _Out_writes_(dwDosNameBufferSize) LPWSTR lpDosName, _In_ DWORD dwDosNameBufferSize)
Definition: stubs.c:318
#define _countof(array)
Definition: sndvol32.h:70
_Out_ PUNICODE_STRING DosName
Definition: rtlfuncs.h:1283

Referenced by ListVolumes().

◆ SetDriverLoadPrivilege()

DWORD SetDriverLoadPrivilege ( )

Definition at line 57 of file fltmc.cpp.

58{
60 HANDLE hToken;
61 LUID luid;
63 DWORD dwError = ERROR_SUCCESS;
64
67 &hToken);
68 if (bSuccess == FALSE)
69 return GetLastError();
70
72 return GetLastError();
73
74 TokenPrivileges.PrivilegeCount = 1;
75 TokenPrivileges.Privileges[0].Luid = luid;
76 TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
77
79 FALSE,
81 sizeof(TOKEN_PRIVILEGES),
82 NULL,
83 NULL);
84 if (bSuccess == FALSE)
85 dwError = GetLastError();
86
87 CloseHandle(hToken);
88
89 return dwError;
90}
#define NULL
Definition: types.h:112
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define CloseHandle
Definition: compat.h:739
#define GetCurrentProcess()
Definition: compat.h:759
static BOOLEAN bSuccess
Definition: drive.cpp:477
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SE_LOAD_DRIVER_NAME
Definition: winnt_old.h:375
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
@ TokenPrivileges
Definition: setypes.h:968
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63

Referenced by LoadFilter(), and UnloadFilter().

◆ UnloadFilter()

void UnloadFilter ( _In_ LPWSTR  FilterName)

Definition at line 112 of file fltmc.cpp.

113{
114 DWORD dwError;
115 dwError = SetDriverLoadPrivilege();
116 if (dwError != ERROR_SUCCESS)
117 {
119 return;
120 }
121
122 HRESULT hr = FilterUnload(FilterName);
123 if (hr != S_OK)
124 {
127 }
128}
#define IDS_ERROR_UNLOAD
Definition: resource.h:16
_Must_inspect_result_ HRESULT WINAPI FilterUnload(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:50

Referenced by wmain().

◆ wmain()

EXTERN_C int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 378 of file fltmc.cpp.

379{
380 wprintf(L"\n");
381
382 if ((argc < 2) || (!_wcsicmp(argv[1], L"filters")))
383 {
384 if (argc < 3)
385 {
386 ListFilters();
387 }
388 else
389 {
391 wprintf(L"fltmc.exe filters\n\n");
392 }
393 }
394 else if (!_wcsicmp(argv[1], L"help"))
395 {
397 }
398 else if (!_wcsicmp(argv[1], L"load"))
399 {
400 if (argc == 3)
401 {
402 LoadFilter(argv[2]);
403 }
404 else
405 {
407 wprintf(L"fltmc.exe load [name]\n\n");
408 }
409 }
410 else if (!_wcsicmp(argv[1], L"unload"))
411 {
412 if (argc == 3)
413 {
414 UnloadFilter(argv[2]);
415 }
416 else
417 {
419 wprintf(L"fltmc.exe unload [name]\n\n");
420 }
421 }
422 else if (!_wcsicmp(argv[1], L"volumes"))
423 {
424 if (argc == 2)
425 {
426 ListVolumes();
427 }
428 else
429 {
431 wprintf(L"fltmc.exe volumes\n\n");
432 }
433 }
434
435 return 0;
436}
static int argc
Definition: ServiceArgs.c:12
#define IDS_USAGE
Definition: resource.h:3
#define IDS_USAGE_LOAD
Definition: resource.h:4
#define IDS_USAGE_VOLUMES
Definition: resource.h:7
#define IDS_USAGE_UNLOAD
Definition: resource.h:5
#define IDS_USAGE_FILTERS
Definition: resource.h:6
void ListVolumes()
Definition: fltmc.cpp:335
void LoadFilter(_In_ LPWSTR FilterName)
Definition: fltmc.cpp:93
void UnloadFilter(_In_ LPWSTR FilterName)
Definition: fltmc.cpp:112
void ListFilters()
Definition: fltmc.cpp:265
#define argv
Definition: mplay32.c:18
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)