两个注册回调的函数:PsSetCreateProcessNotifyRoutine 进程回调PsSetCreateThreadNotifyRoutine 线程回调分别对应的回调函数类型:
VOID MyCreateProcessNotify
(
IN HANDLE ParentId,
IN HANDLE ProcessId,
IN BOOLEAN Create
)
{
if (Create) {
DbgPrint("[monitor_create_process_x64]进程创建! PID=%ld;PPID=%ld\n", ProcessId, ParentId);
}
else {
DbgPrint("[monitor_create_process_x64]进程退出! PID=%ld;PPID=%ld\n", ProcessId, ParentId);
}
}
VOID MyCreateThreadNotify
(
IN HANDLE ProcessId,
IN HANDLE ThreadId,
IN BOOLEAN Create
)
{
if (Create) {
DbgPrint("[monitor_create_process_x64]线程创建! PID=%ld;TID=%ld\n", ProcessId, ThreadId);
}
else {
DbgPrint("[monitor_create_process_x64]线程退出! PID=%ld;TID=%ld\n", ProcessId, ThreadId);
}
}
注册回调:
PsSetCreateProcessNotifyRoutine(MyCreateProcessNotify, FALSE);
PsSetCreateThreadNotifyRoutine(MyCreateThreadNotify);
注销回调(在DriverUnload里面调用):
PsSetCreateProcessNotifyRoutine(MyCreateProcessNotify, TRUE);
PsRemoveCreateThreadNotifyRoutine(MyCreateThreadNotify);
执行结果:
OK上面很好理解,就是进程线程创建退出的时候会对应的调这些回调,通过这个我们可以监控进程和线程的调用和退出情况。但是在学习过程中书上说了这个回调:
PsSetCreateProcessNotifyRoutineEx ,
这个的回调函数参数不同于PsSetCreateProcessNotifyRoutine,
VOID MyCreateProcessNotifyEx(__inout PEPROCESS Process,__in HANDLE ProcessId,
__in_opt PPS_CREATE_NOTIFY_INFO CreateInfo
){}
通过第三个参数CreateInfo->CreationStatus=STATUS_UNSUCCESSFUL;
但是一直卡在一个地方:
查了很多地方,是说在source文件里添加:LINKER_FLAGS=/INTEGRITYCHECK
不过我用的WDK+Vs2015开发的,我理解的source是改.rc文件但是失败了,一直在找解决方案。找到再把这个补上吧,目的是为了使用Ex的函数进行进程创建劫持。