栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

Windows驱动调用PsSetCreateProcessNotifyRoutineEx失败

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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.https://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也能达到效果,只不过代码会复杂一些。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/985130.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号