Windows驱动调用PsSetCreateProcessNotifyRoutineEx失败

参考

driver - Process monitoring CreateProcessNotifyRoutineEx - Stack Overflow

PE format

PE Format - Win32 apps | Microsoft Docs​​​​​​

DLL Characteristics字段介绍

PE Format - Win32 apps | Microsoft DocsThis specification describes the structure of executable (image) files and object files under the Windows family of operating systems. These files are referred to as Portable Executable (PE) and Common Object File Format (COFF) files, respectively.icon-default.png?t=M3K6https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#dll-characteristics

根据windows官方文档说明

PsSetCreateProcessNotifyRoutineEx function (ntddk.h) - Windows drivers | Microsoft Docsr​​​​​​​r

如果返回值是STATUS_ACCESS_DENIED,也就是0xC0000022

则错误原因是

The image that contains the callback routine pointer did not have IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY set in its image header.

百度后得知,PE文件中的这个标志可以通过编译程序的时候指定/integritycheck linker flag,

也就是Visual Studio的属性页->配置属性->链接器->命令行->附加选项中添加/integritycheck,可是编译驱动的时候,不是使用的Visual Studio的编译工具,而是使用wdk的编译工具。配置属性中的修改对驱动的编译不会产生丝毫影响,而且工程属性中根本就没有这个选项。

参考stack overflow中的答案,只需要驱动项目的sources文件中添加LINKER_FLAGS即可,如下:

LINKER_FLAGS=/integritycheck

sources中添加flag之后,用CFF explorer查看属性

 从pe结构中查看该字段,

IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY

0x0080

说明该配置已生效

其实一开始不知道这个配置的时候,使用PsSetCreateProcessNotifyRoutine也能达到效果,只不过代码会复杂一些。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值