• 分析ntdll.dll和ntoskrnl.exe中的 NT*和ZW*函数区别


    OpenProcess-->ntdll!NtOpenProcess-->ntdll!zwOpenProcess-->ntdll!KiFastSystemCall()
                                      ↓mov edx, esp
                                      ↓sysenter 用户层
    ------------------------------------------------------------------------------------------------------
                                      ↓ 内核层
                                      nt!KiFastCallEntry()
                                      ↙                  ↘
                                nt!zwopenprocess()           nt!ntopenprocess()
                                                                                               ↙                                 ↘
                                                                     nt!KiSystemService()                                nt!PsOpenProcess()

    1. ntdll!NtOpenProcess() 会定向到 ntdll!zwOpenProcess() 里,它们是完全一样的,只是名字不同而已!
    2. nt!ntopenprocess是实现函数具体过程, nt!zwopenprocess是在ring 0下通过SSDT服务表,KiSystemService调用ntoskrnl.exe中的中断处理程序Nt*函数。
    3. 在用户层的 stub 函数会使用 sysenter 指令切入到内核层的 KiFastCallEntry() 函数,再由 KiFastCallEntry() 函数分发到相应的系统服务例程执行。


    ntdll.dll和ntoskrnl.exe中的NT*和ZW*函数调用流程分析
    NtOpenProcess和ZwOpenProcess为例,结合Windbg的调试来说明
    1.ntdll.dll中的Nt*和Zw*区别?

    0:000> u ntdll!zwopenprocess l4
    ntdll!NtOpenProcess:
    774d5e70 b8be000000 mov eax,0BEh
    774d5e75 ba0003fe7f mov edx,offset SharedUserData!SystemCallStub (7ffe0300)
    774d5e7a ff12 call dword ptr [edx]
    774d5e7c c21000 ret 10h
    0:000> u ntdll!ntopenprocess l4
    ntdll!NtOpenProcess:
    774d5e70 b8be000000 mov eax,0BEh
    774d5e75 ba0003fe7f mov edx,offset SharedUserData!SystemCallStub (7ffe0300)
    774d5e7a ff12 call dword ptr [edx]
    774d5e7c c21000 ret 10h


    A:从汇编代码来看,两者别无区别,都是通过系统服务调度程序KiSystemService调用ntoskrnl.exe中的中断处理程序Nt*函数。

    lkd> u nt!zwopenprocess l6
    nt!ZwOpenProcess:
    8403ce58 b8be000000 mov eax,0BEh
    8403ce5d 8d542404 lea edx,[esp+4]
    8403ce61 9c pushfd
    8403ce62 6a08 push 8
    8403ce64 e8b5190000 call nt!KiSystemService (8403e81e)
    8403ce69 c21000 ret 10h
    
    lkd> u nt!ntopenprocess l20
    nt!NtOpenProcess:
    84217205 8bff mov edi,edi
    84217207 55 push ebp
    84217208 8bec mov ebp,esp
    8421720a 51 push ecx
    8421720b 51 push ecx
    8421720c 64a124010000 mov eax,dword ptr fs:[00000124h]
    84217212 8a803a010000 mov al,byte ptr [eax+13Ah]
    84217218 8b4d14 mov ecx,dword ptr [ebp+14h]
    8421721b 8b5510 mov edx,dword ptr [ebp+10h]
    8421721e 8845fc mov byte ptr [ebp-4],al
    84217221 ff75fc push dword ptr [ebp-4]
    84217224 ff75fc push dword ptr [ebp-4]
    84217227 ff750c push dword ptr [ebp+0Ch]
    8421722a ff7508 push dword ptr [ebp+8]
    8421722d e889510600 call nt!PsOpenProcess (8427c3bb)
    84217232 c9 leave
    84217233 c21000 ret 10h

    从汇编代码可知 NT*是实现函数具体过程, 而ZW*函数是在ring 0下通过SSDT服务表,KiSystemService调用ntoskrnl.exe中的中断处理程序Nt*函数。

  • 相关阅读:
    第一章 线性模型
    Kaggle比赛:从何着手?
    Kaggle初学者五步入门指南,七大诀窍助你享受竞赛
    3.深度学习的实用层面
    软件工程面试题
    PyQT5速成教程-4 Qt Designer实战[上]
    PyQT5速成教程-3 布局管理
    PyQT5速成教程-1 简介与环境搭建
    Anaconda 使用指南
    webpack的loader的原理和实现
  • 原文地址:https://www.cnblogs.com/mayingkun/p/5408634.html
Copyright © 2020-2023  润新知