• 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的函数进行进程创建劫持。



  • 相关阅读:
    Leetcode-784 Letter Case Permutation(字母大小写全排列)
    Leetcode-450 Delete Node in a BST(删除二叉搜索树中的节点)
    Leetcode-423 Reconstruct Original Digits from English(从英文中重建数字)
    Leetcode-692 Top K Frequent Words(前K个高频单词)
    Leetcode-355 Design Twitter(设计推特)
    Leetcode-229 Majority Element II(求众数 II)
    Leetcode-557 Reverse Words in a String III(反转字符串中的单词 III)
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/csnd/p/12062025.html
Copyright © 2020-2023  润新知