KiFastCallEntry简单呀简单呀分析呀分析

来源:百度文库 编辑:神马文学网 时间:2024/05/07 01:55:18

WinXP系统调用的步骤

sysenter指令:从sysenter_CS_MSR、sysenter_ESP_MSR、sysenter_EIP_MSR寄存器读取数据,填写cs、ss(cs+8)esp、eip。进入ring0特权级

步骤:
0. 进入时eax = 服务号,edx = 当前栈顶 (+0x08为用户参数) sysenter 进入ring0
1. 初始化ds、es为0x23,fs 0x30
2.PCR+0x40(0FFDFF040h)处取得TSS,TSS+0x04取得当前线程内核栈地址,赋值给esp。所以sysenter_ESP_MSR没有意义。
esp = pcr->TSS->Esp0
3. 关中断,建立ThTrapFrame
ntdll!_KTRAP_FRAME
   +0x000 DbgEbp           : Uint4B
   +0x004 DbgEip           : Uint4B
   +0x008 DbgArgMark       : Uint4B
   +0x00c DbgArgPointer    : Uint4B
   +0x010 TempSegCs        : Uint4B
   +0x014 TempEsp          : Uint4B
   +0x018 Dr0              : Uint4B
   +0x01c Dr1              : Uint4B
   +0x020 Dr2              : Uint4B
   +0x024 Dr3              : Uint4B
   +0x028 Dr6              : Uint4B ;如果KTHREAD中DebugActive被置位 则填写上面的值
   +0x02c Dr7              : Uint4B ;置0
   +0x030 SegGs            : Uint4B
   +0x034 SegEs            : Uint4B
   +0x038 SegDs            : Uint4B
   +0x03c Edx              : Uint4B
   +0x040 Ecx              : Uint4B
   +0x044 Eax              : Uint4B
   +0x048 PreviousPreviousMode : Uint4B     ;设置为USERMODE (1),并设置KTHREAD中的对应字段为USERMODE  

   +0x04c ExceptionList    : Ptr32 _EXCEPTION_REGISTRATION_RECORD;从PCR获得,并且设置更新PCR中的ExceptionList为-1
   +0x050 SegFs            : Uint4B
   +0x054 Edi              : Uint4B
   +0x058 Esi              : Uint4B
   +0x05c Ebx              : Uint4B
   +0x060 Ebp              : Uint4B
   +0x064 ErrCode          : Uint4B
   +0x068 Eip              : Uint4B   ;返回地址从USER_SHARED_DATA+UsSystemCallReturn取得,我的系统上是0x7c92eb94,只是一个ret,所以返回用户态时直接可以返回Zw.....函数
   +0x06c SegCs            : Uint4B
   +0x070 EFlags           : Uint4B
   +0x074 HardwareEsp      : Uint4B
   +0x078 HardwareSegSs    : Uint4B
   +0x07c V86Es            : Uint4B
   +0x080 V86Ds            : Uint4B
   +0x084 V86Fs            : Uint4B
   +0x088 V86Gs            : Uint4B
更新KTHREAD中的TrapFrame

4. 从KTHREAD中取出服务表ServiceTable
   将用户堆栈中的参数复制到内核堆栈中,如果service no & 0x1000 为ssdtShadow服务,否则为ssdt服务。
   如果是ssdtShadow服务则先Call _KeGdiFlushUserBatch
   call相应服务
5. 取出_KTRAP_FRAME 恢复ExceptionList 等。。。。没看下去。。。

疑问:
恢复ExceptionList 时
        mov     edx, [ebp].TsEdx        ; restore previous trap frameaddress
        mov     [ecx].ThTrapFrame, edx ;
   [ebp].TsEdx填了么??不应该是[ebp].ExceptionList??