参考
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 Docsrr
如果返回值是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也能达到效果,只不过代码会复杂一些。



