- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
在学习Minifilter和sfilter后明白了一点,这两个文件过滤都是attach到设备上
那么我们废掉的方法就很明显了,将文件系统上attach的所有设备清零
怎么得到attach的所有设备呢?
我们通过ObReferenceObjectByName或得到文件驱动对象地址
得到的对象中有一个成员DeviceObject就得到了文件设备对象
这里还有一个链表,保存着下一个对象的地址
在得到的文件设备对象下有一个成员AttachedDevice就是我们需要清0的attach设备地址了
我们循环这个表,执行同样的操作,就可以干掉过滤驱动了
当然我们还要保存原来的attach的设备对象
在恢复或者卸载的时候给会写出去
代码:- SIZE_T NtfsOriFsFlt[64]= {0};
- SIZE_T FastfatOriFsFlt[64]= {0};
- SIZE_T RawOriFsFlt[64]= {0};
- VOID DisableAllFilters(PWSTR lpwName, SIZE_T *OriFsFlt, ULONG MaxCount, ULONG Action)
- {
- ULONG i=0;
- UNICODE_STRING TName;
- PDRIVER_OBJECT TDrvObj;
- PDEVICE_OBJECT CurrentDevice;
- NTSTATUS status;
- BOOL bInit = FALSE;
- RtlInitUnicodeString(&TName, lpwName);
- status = ObReferenceObjectByName(&TName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- 0,
- *IoDriverObjectType,
- KernelMode,
- NULL,
- &TDrvObj);
- if (!NT_SUCCESS(status)) return ;
- if(!TDrvObj) return ;
- CurrentDevice = TDrvObj->DeviceObject;
- while(CurrentDevice != NULL )
- {
- if(!Action)
- {
- OriFsFlt[i] = (SIZE_T)InterlockedExchangePointer((PVOID*)&CurrentDevice->AttachedDevice, NULL);
- }
- else
- {
- OriFsFlt[i] = (SIZE_T)InterlockedExchangePointer((PVOID*)&CurrentDevice->AttachedDevice, (PDEVICE_OBJECT)(OriFsFlt[i]));
- }
- CurrentDevice = CurrentDevice->NextDevice;
- i++;
- if(i>=MaxCount)
- break;
- }
- ObDereferenceObject(TDrvObj);
- return;
- }
- //0=禁用所有文件系统过滤驱动 1=恢复所有文件系统过滤驱动
- void DisableFsFlt(ULONG Restore)
- {
- DisableAllFilters(L"\\FileSystem\\Ntfs",NtfsOriFsFlt,64,Restore);
- DisableAllFilters(L"\\FileSystem\\fastfat",FastfatOriFsFlt,64,Restore);
- DisableAllFilters(L"\\FileSystem\\RAW",RawOriFsFlt,64,Restore);
- }
复制代码 |
|