Windows驱动(2)-Driver安装调试报错security_init_cookie&蓝屏

来源:互联网 发布:风险评估矩阵中 编辑:程序博客网 时间:2024/06/06 17:12

在完成测试驱动的编写后,F7生成,然后拿到虚拟机进行调试,发现每次载入WinDbg就会给出一段很莫名的报错

RtlpBreakWithStatusInstruction
security_init_cookie

以下是编写&测试环境

编写环境:vs community 2015 + SDK 10.0.15063.137 + WDK 10.0.15063.0
测试环境:Windows7 x86-64 Pro
Driver Loader:OsrLoader

最开始发现cookie错误,因为之前做缓冲区溢出的时候,知道vs会默认开启了/GS选项来进行溢出检查,但是禁用了GS选项后,依然继续报错security_init_cookie,这就很奇怪了。
一路Google,在stackoverflow上找到了一个和我遇见类似问题的人发出的提问__security_init_cookie in Windows driver causes bugcheck KERNEL_SECURITY_CHECK_FAILURE,在第二个答案找到原因,竟然是没有设定Driver平台……一脸懵逼
立刻回去在项目属性-Driver Setting-Gernel中修改平台,再次编译,加载Driver,通过~

但是还是有件事不清楚,为什么指定平台后就没有了security_init_cookie 的报错,是Windows在Win7之后新加入了什么特性吗?第一个答案指出了一点

If your driver targets Windows 8 (and newer) it expects that OS will initialize the cookie. Therefore it raises BSOD if cookie wasn’t changed.
On the other hand if your driver targets older OS (Windows 7), compiler has to generate code that initializes cookie if it wasn’t already initialized by OS. This way the driver is compatible with all Windows versions.

具体的还得调试看看才行

顺带一提,DbgPrint和KdPrint直接使用时在Windbg是没有输出显示的,其中涉及到Windows的一项设置,具体可以参考这里Getting DbgPrint Output To Appear In Vista and Later 。修改注册表时,要新建一个 “DEFAULT”,而不是修改那个 默认"default" 最后重启再次调试就没问题啦~

Ps:
DeviceIoControl是阻塞调用的吗……我怎么就在这里卡住了,虚拟机还在运行可就是没有下一步动作了,
(′д` )…彡…彡


PPs:
2017.05.09 09:40AM
丢人啊,原来在IRP处理的时候while最后没有break出去,一直死循环了,以后写代码要提前写好break才能继续写后面啊,不然好容易就忘了

2 0