Trap Frame是指中断、自陷、异常进入内核后,在堆栈上形成的一种数据结构。对于Windows操作系统,是
kd> dt nt!_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
+0x02c Dr7 : Uint4B
+0x030 SegGs : Uint4B
+0x034 SegEs : Uint4B
+0x038 SegDs : Uint4B
+0x03c Edx : Uint4B
+0x040 Ecx : Uint4B
+0x044 Eax : Uint4B
+0x048 PreviousPreviousMode : Uint4B
+0x04c ExceptionList : Ptr32 _EXCEPTION_REGISTRATION_RECORD
+0x050 SegFs : Uint4B
+0x054 Edi : Uint4B
+0x058 Esi : Uint4B
+0x05c Ebx : Uint4B
+0x060 Ebp : Uint4B
+0x064 ErrCode : Uint4B
+0x068 Eip : Uint4B
+0x06c SegCs : Uint4B
+0x070 EFlags : Uint4B
+0x074 HardwareEsp : Uint4B
+0x078 HardwareSegSs : Uint4B
+0x07c V86Es : Uint4B
+0x080 V86Ds : Uint4B
+0x084 V86Fs : Uint4B
+0x088 V86Gs : Uint4B
这里做一个试验,对于nt!_KiSystemService设置断点。当断住的时候,观察堆栈。
kd> kv
ChildEBP RetAddr Args to Child
fa057c10 8082c04d badb0d00 fa057c88 fa057c88 nt!_KiSystemService+0x76 (FPO: [0,0] TrapFrame @ fa057c10) [C:\SourceCode\wrk\wrk-v1.2\base\ntos\ke\i386\trap.asm @ 1056]
fa057c80 808e32e0 80000214 8161ec44 00000000 nt!ZwClose+0x11 (FPO: [1,0,0]) [C:\SourceCode\wrk\wrk-v1.2\base\ntos\ke\i386\sysstubs.asm @ 332]
fa057cb4 f9dfbbdf 80000214 81539e98 fa057d38 nt!IoGetDeviceObjectPointer+0x7a (FPO: [Non-Fpo]) (CONV: stdcall) [c:\sourcecode\wrk\wrk-v1.2\base\ntos\io\iomgr\iosubs.c @ 7604]
fa057d3c f9e09a37 815c3630 8161ec50 f99a5df7 ptilink!PtiQueryDeviceStatus+0x49 (FPO: [Non-Fpo])
fa057d5c f9e0a084 00000000 817a7020 8089dd40 raspti!QueryPtiPorts+0x29 (FPO: [Non-Fpo])
fa057d70 f99a3013 815711a8 8161ec10 fa057dac raspti!OpenAfPassive+0x3e (FPO: [Non-Fpo])
fa057d80 80818963 815711a8 00000000 817a7020 NDIS!ndisWorkItemHandler+0xe (FPO: [Non-Fpo])
fa057dac 80930c70 815711a8 00000000 00000000 nt!ExpWorkerThread+0xe9 (FPO: [Non-Fpo]) (CONV: stdcall) [c:\sourcecode\wrk\wrk-v1.2\base\ntos\ex\worker.c @ 1183]
fa057ddc 8088732e 8081887a 00000000 00000000 nt!PspSystemThreadStartup+0x2e (FPO: [Non-Fpo]) (CONV: stdcall) [c:\sourcecode\wrk\wrk-v1.2\base\ntos\ps\create.c @ 2214]
00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x16 [C:\SourceCode\wrk\wrk-v1.2\base\ntos\ke\i386\threadbg.asm @ 78]
其中fa057c10就是Trap Frame的地址。
kd> dt nt!_KTRAP_FRAME fa057c10
+0x000 DbgEbp : 0xfa057cb4
+0x004 DbgEip : 0x8082c04d
+0x008 DbgArgMark : 0xbadb0d00
+0x00c DbgArgPointer : 0xfa057c88
+0x010 TempSegCs : 0xfa057c88
+0x014 TempEsp : 0xfa057d44
+0x018 Dr0 : 0x1b
+0x01c Dr1 : 0x1b
+0x020 Dr2 : 0xffffffff
+0x024 Dr3 : 0x30
+0x028 Dr6 : 0
+0x02c Dr7 : 0
+0x030 SegGs : 0x30
+0x034 SegEs : 0xfa057cb4
+0x038 SegDs : 0
+0x03c Edx : 0
+0x040 Ecx : 8
+0x044 Eax : 0x346
+0x048 PreviousPreviousMode : 0
+0x04c ExceptionList : 0xfa057dcc _EXCEPTION_REGISTRATION_RECORD
+0x050 SegFs : 0x30
+0x054 Edi : 0
+0x058 Esi : 0
+0x05c Ebx : 0x8161ec50
+0x060 Ebp : 0xfa057cb4
+0x064 ErrCode : 0
+0x068 Eip : 0x8082c04d
+0x06c SegCs : 8
+0x070 EFlags : 0x246
+0x074 HardwareEsp : 0x808e32e0
+0x078 HardwareSegSs : 0x80000214
+0x07c V86Es : 0x8161ec44
+0x080 V86Ds : 0
+0x084 V86Fs : 0x18
+0x088 V86Gs : 0
同时,可以采用.trap命令。
kd> .trap fa057c10
ErrCode = 00000000
eax=00000346 ebx=8161ec50 ecx=00000008 edx=00000000 esi=00000000 edi=00000000
eip=8082c04d esp=fa057c84 ebp=fa057cb4 iopl=0 nv up ei pl zr na pe nc
cs=0008 ss=0010 ds=0000 es=7cb4 fs=0030 gs=0030 efl=00000246
nt!ZwClose+0x11:
8082c04d c20400 ret 4
.trap命令除了显示Trap Frame中的各个字段外,同时让CPU返回其中的EIP。
转载于:https://www.cnblogs.com/fanzi2009/archive/2011/04/07/2008144.html