Re: 《Nt vs. Zw - Clearing Confusion on the Native API》一文的疑惑

Windows内核调试

《Nt vs. Zw - Clearing Confusion on the Native API》一文的疑惑


merry 2009-06-01, 23:42 下午

Quote:

    " If a Kernel component calls the ZwXxx version of a native API, all is well. The previous mode is set to Kernel and the credentials of the Kernel are used."

ntoskrnl.exe的ZwOpenProcess函数如下:

nt!ZwOpenProcess:
80826dc8 b87a000000      mov     eax,7Ah
80826dcd 8d542404        lea     edx,[esp+4]
80826dd1 9c              pushfd
80826dd2 6a08            push    8
80826dd4 e898ea0300      call    nt!KiSystemService (80865871)
80826dd9 c21000          ret     10h

Q:如何从以上代码看出内核模式调用函数ZwOpenProcess 会将Previous Mode设置为Kernel Mode (0),并调用NtOpenProcess?

谢谢!

Re: 《Nt vs. Zw - Clearing Confusion on the Native API》一文的疑惑


benlong 2009-06-02, 12:57 下午
KiSystemService中
80542483 648b3524010000 mov esi,dword ptr fs:[124h]
8054248a ffb640010000 push dword ptr [esi+140h]
在陷进框架中保存了线程原来的Previous Mode
接下来
80542493 8b5c246c mov ebx,dword ptr [esp+6Ch]
80542497 83e301 and ebx,1
8054249a 889e40010000 mov byte ptr [esi+140h],bl
就是设置新的Previous Mode
完成陷进框架后会
805424d3 e9e7000000 jmp nt!KiFastCallEntry+0x8f (805425bf)
由kthread.ServiceTable获取系统服务表,在根据Eax中的系统服务号,找到NtOpenProcess的地址,根据参数的大小,复制参数到内核栈中,调用NtOpenProcess。
上述过程是启用了快速调用机制的过程。

Powered by Community Server Powered by CnForums.Net