Windows Filesystem filter driver
参考:http://www.codeproject.com/Articles/43586/File-System-Filter-Driver-Tutorial
关键点:
To perform attaching, we create a new device object with the device extension (call
IoCreateDevice) and the propagate device object flags from the device object we are trying to attach to (DO_BUFFERED_IO,DO_DIRECT_IO,FILE_DEVICE_SECURE_OPEN). Then, we callIoAttachDeviceToDeviceStackSafein a loop with a delay in the case of failure. It is possible for this attachment request to fail because the device object has not finished initialization. This situation can occur if we try to mount the filter that was loaded as the volume only. When attaching is finished, we save the “attached to” device object to the device extension and clear theDO_DEVICE_INITIALIZINGflag. The device extension is shown below:
首先创建一个hookDevice,指定我们正在操作的driver为它服务;
然后使用IoAttachDeviceByPointer或者IoAttachDeviceToDeviceStack,将hookDevice放到targetDevice所在Dev Stack的顶部,这样,当有IRP过来时,会先经过hookDevice,即先调用我们的Driver进行处理,再传给下一层driver进行处理。
The IoAttachDeviceToDeviceStack routine attaches the caller's device object to the highest device object in the chain and returns a pointer to the previously highest device object.
下面以例子说明
kd> !drvobj atapi
Driver object (867ce610) is for:
\Driver\atapi
Driver Extension List: (id , addr)
(f744e8d8 867d2430)
Device Object list:
86758b00 8675ab00 86790b00 86786030
86787030
kd> dt _DRIVER_OBJECT 0x867ce610
ntdll!_DRIVER_OBJECT
+0x000 Type : 0n4
+0x002 Size : 0n168
+0x004 DeviceObject : 0x86758b00 _DEVICE_OBJECT
+0x008 Flags : 0x12
+0x00c DriverStart : 0xf743a000 Void
+0x010 DriverSize : 0x17480
+0x014 DriverSection : 0x867ebbc0 Void
+0x018 DriverExtension : 0x867ce6b8 _DRIVER_EXTENSION
+0x01c DriverName : _UNICODE_STRING "\Driver\atapi"
+0x024 HardwareDatabase : 0x80670260 _UNICODE_STRING "\REGISTRY\MACHINE\HARDWARE\DESCRIPTION\SYSTEM"
+0x028 FastIoDispatch : (null)
+0x02c DriverInit : 0xf744f5f7 long atapi!GsDriverEntry+0
+0x030 DriverStartIo : 0xf74417c6 void atapi!IdePortStartIo+0
+0x034 DriverUnload : 0xf744b204 void atapi!IdePortUnload+0
+0x038 MajorFunction : [28] 0xf7444572 long atapi!IdePortAlwaysStatusSuccessIrp+0
表明,驱动名称为apapi,它一共为5个device提供服务,我们来看一下其中第一个device object
kd> dt _DEVICE_OBJECT 0x86758b00
ntdll!_DEVICE_OBJECT
+0x000 Type : 0n3
+0x002 Size : 0x234
+0x004 ReferenceCount : 0n0
+0x008 DriverObject : 0x867ce610 _DRIVER_OBJECT
+0x00c NextDevice : 0x8675ab00 _DEVICE_OBJECT
+0x010 AttachedDevice : 0x8678f030 _DEVICE_OBJECT
+0x014 CurrentIrp : (null)
+0x018 Timer : (null)
+0x01c Flags : 0x5050
+0x020 Characteristics : 0x101
+0x024 Vpb : (null)
+0x028 DeviceExtension : 0x86758bb8 Void
+0x02c DeviceType : 2
+0x030 StackSize : 1 ''
+0x034 Queue : __unnamed
+0x05c AlignmentRequirement : 1
+0x060 DeviceQueue : _KDEVICE_QUEUE
+0x074 Dpc : _KDPC
+0x094 ActiveThreadCount : 0
+0x098 SecurityDescriptor : 0xe100cf70 Void
+0x09c DeviceLock : _KEVENT
+0x0ac SectorSize : 0
+0x0ae Spare1 : 1
+0x0b0 DeviceObjectExtension : 0x86758d38 _DEVOBJ_EXTENSION
+0x0b4 Reserved : (null)
+0x008 DriverObject : 0x867ce610 _DRIVER_OBJECT 【指向为其服务的driver,即atapi】
+0x00c NextDevice : 0x8675ab00 _DEVICE_OBJECT 【指向atapi中的device list中的下一项,在!drvobj atapi的结果中得到了验证】
+0x010 AttachedDevice : 0x8678f030 _DEVICE_OBJECT 【指向该device object所在的device stack中的下一项,或者说更加靠近顶层的一项】
我们沿着device stack一直向下遍历:
kd> dt _DEVICE_OBJECT 0x8678f030
ntdll!_DEVICE_OBJECT
+0x000 Type : 0n3
+0x002 Size : 0x47c
+0x004 ReferenceCount : 0n0
+0x008 DriverObject : 0x867d0970 _DRIVER_OBJECT
+0x00c NextDevice : (null)
+0x010 AttachedDevice : (null)
+0x014 CurrentIrp : (null)
+0x018 Timer : 0x8679a548 _IO_TIMER
+0x01c Flags : 0x2050
+0x020 Characteristics : 0x101
+0x024 Vpb : 0x867bebe0 _VPB
+0x028 DeviceExtension : 0x8678f0e8 Void
+0x02c DeviceType : 2
+0x030 StackSize : 3 ''
+0x034 Queue : __unnamed
+0x05c AlignmentRequirement : 1
+0x060 DeviceQueue : _KDEVICE_QUEUE
+0x074 Dpc : _KDPC
+0x094 ActiveThreadCount : 0
+0x098 SecurityDescriptor : 0xe100cf70 Void
+0x09c DeviceLock : _KEVENT
+0x0ac SectorSize : 0
+0x0ae Spare1 : 0
+0x0b0 DeviceObjectExtension : 0x8678f4b0 _DEVOBJ_EXTENSION
+0x0b4 Reserved : (null)
kd> !devstack 0x8678f030
!DevObj !DrvObj !DevExt ObjectName
> 8678f030 \Driver\Cdrom 8678f0e8 CdRom0
86758b00 \Driver\atapi 86758bb8 IdeDeviceP1T0L0-17
!DevNode 8678f9b8 :
DeviceInst is "IDE\CdRomVBOX_CD-ROM_____________________________1.0_____\42562d3231303037333036372020202020202020"
ServiceName is "cdrom"
可见,device stack其实就是通过_DEVICE_OBJECT中的AttachedDevice指针串联起来的一个单链表,当调用IoAttachDeviceToDeviceStack时,会在该device stack的最顶端添加我们自己的device object。
然后,当一个IRP过来时,不论它是以这个device object中的哪一个device object作为参数,它都会传递到栈的最顶端的device所对应的driver中去处理。
因此,这就是为什么IoAttachDeviceToDeviceStack能够创建file system filter driver的原因。
Device Stack决定了Driver被执行的顺序,或者说driver是没有层次结构的,只有device有层次结构。
Windows Filesystem filter driver的更多相关文章
- busdog is a filter driver for MS Windows (XP and above) to sniff USB traffic.
https://code.google.com/p/busdog/ busdog is a filter driver for MS Windows (XP and above) to sniff U ...
- Windows Self Signed Driver
In particular, Microsoft® instituted a device driver certification process for its Windows® desktop ...
- 显示器驱动程序 NVIDIA Windows Kernel Mode Driver Version 已停止响应 并且己成功恢复 解决方法
原文:http://news.160.com/?p=1890 在玩游戏中 经常 出现显示器驱动程序 NVIDIA Windows Kernel Mode Driver Version 已停止响应 并且 ...
- mini filter driver sql server
https://blogs.msdn.microsoft.com/sql_pfe_blog/2013/04/23/identifying-the-cause-of-sql-server-io-bott ...
- [Windows驱动]驱动包(Driver Packages)
在windows下安装一个驱动,我们你需要把所有需要的软件打包-称为驱动包.驱动包里包括系统提供的给所有设备类使用的一般安装工具,还包括了设备商提供的设备特定的组件.下面我们就来看看驱动包里具体需要哪 ...
- Windows平台内核级文件访问
1.背景 在windows平台下,应用程序通常使用API函数来进行文件访问,创建,打开,读写文件.从kernel32的CreateFile/ReadFile/WriteFile函数,到本地系统 ...
- Windows 8 应用商店无法连接到网络的终极完美解决方案
当你看到以下几个步骤的时候,你可能会不以为然,因为你已经试过了,还是没成功,依然提示"你的电脑没有连接到Internet或者现在无法使用Windows应用商店,要使用Windows应用商店, ...
- WIFI WPA1/2 Crack for Windows
0x00 前言 目前WIFI WPA破解主要 以“aircrack-ng”为代表,运行于Linux系统( 如Kali Linux ),Windows系统比较少见,主要是Windows系统下WIFI网卡 ...
- Windows Kernel Security Training Courses
http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers Thi ...
随机推荐
- JAVA模拟Spring实现IoC过程(附源码)
前言:本人大四学生,第一次写博客,如果有写得不好的地方,请大家多多指正 一.IoC(Inversion of Control)反转控制 传统开发都是需要对象就new,但这样做有几个问题: 效率低下,创 ...
- Codeforces 1110C (思维+数论)
题面 传送门 分析 这种数据范围比较大的题最好的方法是先暴力打表找规律 通过打表,可以发现规律如下: 定义\(x=2^{log_2a+1}\) (注意,cf官方题解这里写错了,官方题解中定义\(x=2 ...
- python自定义迭代器对象以及可迭代对象
# coding=utf8 from collections import Iterator from collections import Iterable #迭代器对象 class OwnIter ...
- C# Base64编码解码 ,Md5、Rsa加密解密
using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Clas ...
- JSTL获取list的大小
转自:https://blog.csdn.net/buster2014/article/details/45789647 JSTL获取list的大小,jstl获取list 的长度,EL表达式获取lis ...
- presentingViewController、presentedViewController区别
解释两个属性:presentingViewController 和 presentedViewController A----(present)-----B----(present)-----C 1. ...
- zabbix入门之添加主机
添加主机的方法有两种:手动添加.自动发现 前提是:在被监控主机中安装zabbix-agent.zabbix-sender组件,并配置好启动服务. 手动添加: 自动发现: 这里等待1分钟左右即可发现主机 ...
- BZOJ-2337 XOR和路径(HNOI2011)概率DP+概率的线性叠加
题意:给出n个点和m条边,每条边有权值wi,从1出发,每次等概率选一条出边走,直到终点n停止,得到的值是路径所有边的异或和.问异或和期望. 解法:这道题非常有意思!首先比较直观的想法就是dp[x]代表 ...
- [Luogu2365]任务安排(斜率优化)
[Luogu2365]任务安排 题目描述 N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务.从时刻0开始,这些任务被分批加工,第i个任务单独完成 ...
- rabbitmq消息的路由
https://blog.csdn.net/lby0307/article/details/80875666 三种模式