/* 禁止写操作。 暂时只禁止一个卷。 前操作实现。 注意普通的删除操作也会被拦截。 made by correy made at 2013.08.05 email:kouleguan at hotmail dot com homepage:http://correy.webs.com */ #include <fltKernel.h> PFLT_FILTER gFilterHandle; FLT_PREOP_CALLBACK_STATUS WritePreOPeration(__inout PFLT_CALLBACK_DATA Cbd, __in PCFLT_RELATED_OBJECTS FltObjects, __out PVOID *CompletionContext) { PFLT_FILE_NAME_INFORMATION pfni; NTSTATUS status; UNICODE_STRING temp; status = FltGetFileNameInformation( Cbd, FLT_FILE_NAME_NORMALIZED | FLT_FILE_NAME_QUERY_DEFAULT, &pfni); if (!NT_SUCCESS( status )) { /* Note If the minifilter driver's preoperation callback routine returns FLT_PREOP_SUCCESS_WITH_CALLBACK but the minifilter driver has not registered a postoperation callback routine for the operation, the system asserts on a checked build. 注释:在XP上会蓝屏,在WIN 7上不会蓝屏。 */ return FLT_PREOP_SUCCESS_WITH_CALLBACK; } status = FltParseFileNameInformation(pfni); if (!NT_SUCCESS( status )) { FltReleaseFileNameInformation(pfni); return FLT_PREOP_SUCCESS_WITH_CALLBACK; } RtlInitUnicodeString(&temp,L"\\Device\\HarddiskVolume2"); if (RtlEqualUnicodeString(&temp,&pfni->Volume,TRUE)) { Cbd->IoStatus.Status = STATUS_ACCESS_DENIED; Cbd->IoStatus.Information = 0; return FLT_PREOP_COMPLETE; } FltReleaseFileNameInformation(pfni); return FLT_PREOP_SUCCESS_WITH_CALLBACK; } CONST FLT_OPERATION_REGISTRATION Callbacks[] = { { IRP_MJ_WRITE, 0, WritePreOPeration, 0}, { IRP_MJ_OPERATION_END } }; #pragma PAGEDCODE NTSTATUS PtInstanceQueryTeardown (__in PCFLT_RELATED_OBJECTS FltObjects,__in FLT_INSTANCE_QUERY_TEARDOWN_FLAGS Flags) { return STATUS_SUCCESS; } #pragma PAGEDCODE//#pragma alloc_text(PAGE, PtUnload) NTSTATUS PtUnload (__in FLT_FILTER_UNLOAD_FLAGS Flags) { FltUnregisterFilter( gFilterHandle ); return STATUS_SUCCESS; } CONST FLT_REGISTRATION FilterRegistration = { sizeof( FLT_REGISTRATION ), // Size FLT_REGISTRATION_VERSION, // Version 0, // Flags NULL, // Context Callbacks, // Operation callbacks PtUnload, // MiniFilterUnload NULL, // InstanceSetup PtInstanceQueryTeardown, // InstanceQueryTeardown NULL, // InstanceTeardownStart NULL, // InstanceTeardownComplete NULL, // GenerateFileName NULL, // GenerateDestinationFileName NULL // NormalizeNameComponent }; DRIVER_INITIALIZE DriverEntry; #pragma alloc_text(INIT, DriverEntry)//#pragma INITCODE NTSTATUS DriverEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath) { NTSTATUS status; UNREFERENCED_PARAMETER( RegistryPath ); KdBreakPoint();//DbgBreakPoint() status = FltRegisterFilter( DriverObject, &FilterRegistration, &gFilterHandle );//Register with FltMgr to tell it our callback routines if (NT_SUCCESS( status )) //FLT_ASSERT( NT_SUCCESS( status ) ); { status = FltStartFiltering( gFilterHandle ); if (!NT_SUCCESS( status )) { FltUnregisterFilter( gFilterHandle ); } } return status; }
2013年8月13日星期二
Minifilter禁止写操作
订阅:
博文评论 (Atom)
没有评论:
发表评论