zoukankan      html  css  js  c++  java
  • Win64 驱动内核编程-12.回调监控进线程创建和退出

    回调监控进线程创建和退出

        两个注册回调的函数:PsSetCreateProcessNotifyRoutine   进程回调PsSetCreateThreadNotifyRoutine    线程回调分别对应的回调函数类型:

    VOID MyCreateProcessNotify
    (
    	IN HANDLE ParentId,
    	IN HANDLE ProcessId,
    	IN BOOLEAN Create
    )
    {
    	if (Create) {
    		DbgPrint("[monitor_create_process_x64]进程创建! PID=%ld;PPID=%ld
    ", ProcessId, ParentId);
    	}
    	else {
    		DbgPrint("[monitor_create_process_x64]进程退出! PID=%ld;PPID=%ld
    ", ProcessId, ParentId);
    	}
    }
    
    VOID MyCreateThreadNotify
    (
    	IN HANDLE  ProcessId,
    	IN HANDLE  ThreadId,
    	IN BOOLEAN  Create
    )
    {
    	if (Create) {
    		DbgPrint("[monitor_create_process_x64]线程创建! PID=%ld;TID=%ld
    ", ProcessId, ThreadId);
    	}
    	else {
    		DbgPrint("[monitor_create_process_x64]线程退出! PID=%ld;TID=%ld
    ", 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的函数进行进程创建劫持。



  • 相关阅读:
    【数学】【AOJ-614】座位安排
    【乱搞】【AOJ-611】消失的5,8,9
    redis 与session
    Nginx 与 tomcat 部署网站
    linux 进程在后台执行
    印象笔记
    consul 小結
    spring boot 使用拦截器,注解 实现 权限过滤
    Springcloud/Springboot项目绑定域名,使用Nginx配置Https
    spring boot 登录认证
  • 原文地址:https://www.cnblogs.com/csnd/p/12062025.html
Copyright © 2011-2022 走看看