[转载]静态分析nt!KiFastCallEntry

转载: http://bbs.pediy.com/showthread.php?t=89407

在XP系统中, 系统服务在内核的入口是KiFastCallEntry,我们从该入口开始,分析这一段代码都做了什么工作。

由于水平有限和背景知识不够,本人没有完全读懂它们,作为抛砖引玉,我先将我所看懂的和大家分享,希望大家多多指教!       
KiFastCallEntry的主要功能有:

  • 初始化系统堆栈
  • 将上下文压入系统堆栈,压栈顺序见KTrap_Frame内核堆栈框架
  • 将参数从用户模式堆栈复制到内核堆栈,以上步骤在关中断下进行的,应为要用到KUser_Shared_Data
  • 确定服务例程的入口地址,包括使用那个服务表,是Shadow SSDT还是SSDT
  • 转入服务例程入口
  • 等等,欢迎补充

背景知识:

  • 进入内核后,fs:[0]或者说ds:[ffdff000] 处是一个叫做KPCR 的结构,PCR 即 Processor Control Region ,处理器控制域。这是一个很有用的结构。系统本身就大量使用。
  • 多谢qihoocom和bozer的补充,在ds:[ffdf0000]处是一个nt!_KUser_Shared_Data结构 在Sysenter调用前,将上下文保存到这里,注意:该结构是共享的,要关闭中断才能使用
  • eax中是服务例程ID
  • edx指向用户堆栈,参数可以通过其得到
  • 在 Ring3 的代码调用了 sysenter 指令之后,CPU 会做出如下的操作:
  • 1. 将 SYSENTER_CS_MSR 的值装载到 cs 寄存器
  • 2. 将 SYSENTER_EIP_MSR 的值装载到 eip 寄存器
  • 3. 将 SYSENTER_CS_MSR 的值加 8(Ring0 的堆栈段描述符)装载到 ss 寄存器。 4. 将 SYSENTER_ESP_MSR 的值装载到 esp 寄存器
  • 5. 将特权级切换到 Ring0
  • 6. 如果 EFLAGS 寄存器的 VM 标志被置位,则清除该标志
  • 7. 开始执行指定的 Ring0 代码  在 Ring0 代码执行完毕,调用 SYSEXIT 指令退回 Ring3 时,CPU 会做出如下操作:
    • 1. 将 SYSENTER_CS_MSR 的值加 16(Ring3 的代码段描述符)装载到 cs 寄存器
    • 2. 将寄存器 edx 的值装载到 eip 寄存器
    • 3. 将 SYSENTER_CS_MSR 的值加 24(Ring3 的堆栈段描述符)装载到 ss 寄存器
    • 4. 将寄存器 ecx 的值装载到 esp 寄存器
    • 5. 将特权级切换到 Ring3
    • 6. 继续执行 Ring3 的代码

  1 nt!KiFastCallEntry:
  2
  3 // 当线程在内核模式下执行时的数据段选择子是23h
  4 // 当线程在内核模式下执行时,在FS寄存器中加载的是选择子30,
  5 // 用于寻址PCR结构体
  6 804de6f0      mov ecx,23h
  7 804de6f5      push 30h
  8 804de6f7      pop fs
  9
 10 // 23h->ds;23h->es
 11 804de6f9      mov ds,cx
 12 804de6fb      mov es,cx
 13
 14 // dword ptr fs:[40h] == dword ptr ds:[0FFDFF040h]{TSS}
 15 // dword ptr [ecx+4] 为当前线程的内核模式栈顶指针的值
 16 804de6fd      mov ecx,dword ptr ds:[0FFDFF040h]
 17 804de703      mov esp,dword ptr [ecx+4]
 18
 19 // ==========================================
 20 // 将当前(执行Sysenter前各寄存器的值)上下文压入系统堆栈,
 21
 22 // _KTRAP_FRAME.HardwareSegSs
 23 804de706      push 23h
 24
 25 // _KTRAP_FRAME.HardwareEsp
 26 804de708      push edx
 27
 28 // _KTRAP_FRAME.EFags
 29 804de709      pushfd
 30 804de70a      push 2
 31 804de70c      add edx,8
 32
 33 // EFlags = 2
 34 804de70f      popfd
 35 804de710      or byte ptr [esp+1],2
 36
 37 // _KTRAP_FRAME.SegCs
 38 804de715      push 1Bh
 39
 40 // ds:[0FFDF0304h] 是SystemCallReturn(_KUser_Shared_Data)
 41 // _KTRAP_FRAME.Eip
 42 804de717      push dword ptr ds:[0FFDF0304h]
 43
 44 //_KTRAP_FRAME.ErrorCode
 45 804de71d      push 0
 46
 47 //_KTRAP_FRAME.Ebp
 48 804de71f      push ebp
 49
 50 //_KTRAP_FRAME.Ebx
 51 804de720      push ebx
 52
 53 //_KTRAP_FRAME.Esi
 54 804de721      push esi
 55
 56 //_KTRAP_FRAME.Edi
 57 804de722      push edi
 58
 59
 60 //ebx<-_KPCR.SelfPcr
 61 804de723      mov ebx,dword ptr ds:[0FFDFF01Ch]
 62
 63 // _KTRAP_FRAME.SegFs
 64 804de729      push 3Bh
 65
 66 //esi=_KPCR.PrcbData.CurrentThread
 67 804de72b      mov esi,dword ptr [ebx+124h]
 68
 69 //_KTRAP_FRAME.ExceptionList
 70 804de731      push dword ptr [ebx]
 71 // 初始化链表
 72 804de733      mov dword ptr [ebx],0FFFFFFFFh
 73
 74 //ebp = KPCR.PrcbData.CurrentThread. InitialStack
 75 804de739      mov ebp,dword ptr [esi+18h]
 76
 77 //_KTRAP_FRAME.PreviousPreviousMode = 1
 78 804de73c      push 1
 79
 80 // esp->_KTRAP_FRAME
 81 804de73e      sub esp,48h
 82
 83 // ebp ->_KTRAP_FRAME
 84 804de741      sub ebp,29Ch
 85
 86 // CurrentThread +124 = 1
 87 804de747      mov byte ptr [esi+140h],1
 88
 89 // 比较
 90 804de74e      cmp ebp,esp
 91 // 不相等,发生了异常
 92 804de750      jne nt!KiFastCallEntry2+0x24 (804de6c8)
 93
 94 // _KTRAP_FRAME.Dr7 = 0
 95 804de756      and dword ptr [ebp+2Ch],0
 96
 97 // [esi+2Ch]是KTHREAD.DebugActive当前线程的调试标志
 98 //不等于0xFF表示调试中?
 99 804de75a      test byte ptr [esi+2Ch],0FFh
100 804de75e      mov dword ptr [esi+134h],ebp
101 804de764      jne nt!Dr_FastCallDrSave (804de5b0)
102
103
104 // ebx = _KTRAP_FRAME.Ebp
105 804de76a      mov ebx,dword ptr [ebp+60h]
106
107 // edi = _KTRAP_FRAME.EIP
108 804de76d      mov edi,dword ptr [ebp+68h]
109
110 // _KTRAP_FRAME.DbgArgPointer
111 804de770      mov dword ptr [ebp+0Ch],edx
112
113 // _KTRAP_FRAME.DbgArgPointer = DbgArgMark
114 804de773      mov dword ptr [ebp+8],0BADB0D00h
115
116 //_KTRAP_FRAME.DbgEbp
117 804de77a      mov dword ptr [ebp],ebx
118
119 //_KTRAP_FRAME.DbgEip = _KTRAP_FRAME.EIP
120 804de77d      mov dword ptr [ebp+4],edi
121 //==================================
122
123 // 开中断
124 804de780      sti
125
126 //eax为函数序号,但是在KeServiceDescriptorTableShadow时
127 //是函数序号+1000h,所以在KeServiceDescriptorTableShadow
128 //经过下面运算ecx最终为10h,否则为0
129 804de781      mov edi,eax
130 804de783      shr edi,8
131 804de786      and edi,30h
132 804de789      mov ecx,edi
133
134 //KTHREAD.ServiceTable gdi32.dll和user32.dll调用时,
135 //ServiceTable为KeServiceDescriptorTableShadow,
136 //ntdll.dll调用时ServiceTable为KeServiceDescriptorTable
137 //在KeServiceDescriptorTableShadow时+10正好得到win32.sys调用
138 804de78b      add edi,dword ptr [esi+0E0h]
139 804de791      mov ebx,eax
140
141 //保留三个字节,得到正真的序号
142 804de793      and eax,0FFFh
143
144 //和ssdt或shadow ssdt总共项数比较,eax大则跳
145 804de798      cmp eax,dword ptr [edi+8]
146 804de79b      jae nt!KiBBTUnexpectedRange (804de4e2)
147
148 //判断是shadow ssdt还是ssdt,不跳则是shadow ssdt,跳则是ssdt
149 804de7a1      cmp ecx,10h
150 804de7a4      jne nt!KiFastCallEntry+0xcc (804de7c0)
151
152 // TIB地址送ecx
153 804de7a6      mov ecx,dword ptr ds:[0FFDFF018h]
154
155 // [ecx+0xf70] 是什么东东?
156 804de7ac      xor ebx,ebx
157 804de7ae      or ebx,dword ptr [ecx+0F70h]
158 804de7b4      je nt!KiFastCallEntry+0xcc (804de7c0)
159
160 804de7b6      push edx
161 804de7b7      push eax
162 804de7b8      call dword ptr [nt!KeGdiFlushUserBatch (8055a164)]
163 804de7be      pop eax
164 804de7bf      pop edx
165
166 // SSDT
167 // ds:[0FFDFF638h](fs:[638h]) KeSystemCalls
168 // 仅仅用来记录系统调用的次数,无太多用处
169 804de7c0      inc dword ptr ds:[0FFDFF638h]
170
171 // edx中是参数(堆栈顶的指针)
172 804de7c6      mov esi,edx
173 804de7c8      mov ebx,dword ptr [edi+0Ch]
174 804de7cb      xor ecx,ecx
175 804de7cd      mov cl,byte ptr [eax+ebx]
176
177 //edi=KeServiceDescriptorTable->ServiceTableBase
178 804de7d0      mov edi,dword ptr [edi]
179
180 //计算服务例程地址(edi为KiServiceTable,eax为函数序号)
181 804de7d2      mov ebx,dword ptr [edi+eax*4]
182 804de7d5      sub esp,ecx
183 804de7d7      shr ecx,2
184 804de7da      mov edi,esp
185
186 // 检查esi是否指向用户空间
187 804de7dc      cmp esi,dword ptr ds:[0EED02CF4h]
188 804de7e2      jae nt!KiSystemCallExit2+0x9f (804de990)
189
190 //把参数复制到内核
191 804de7e8      rep movs dword ptr es:[edi],dword ptr [esi]
192
193 //转入服务例程入口
194 804de7ea      call ebx
195
196 // 恢复堆栈
197 804de7ec      mov esp,ebp
198
199 // fs:[124h]中储存着当前线程的ETHREAD
200 // ETHREAD的偏移134h处为TrapFrame
201 804de7ee      mov ecx,dword ptr ds:[0FFDFF124h]
202 804de7f4      mov edx,dword ptr [ebp+3Ch]
203 804de7f7      mov dword ptr [ecx+134h],edx
204  。。。。
205
206 804de904      sysexit

附相关数据结构 :

lkd> dt nt!_KPCR
+0x000 NtTib : _NT_TIB
+0x01c SelfPcr : Ptr32 _KPCR
+0x020 Prcb : Ptr32 _KPRCB
+0x024 Irql : UChar
+0x028 IRR : Uint4B
+0x02c IrrActive : Uint4B
+0x030 IDR : Uint4B
+0x034 KdVersionBlock : Ptr32 Void
+0x038 IDT : Ptr32 _KIDTENTRY
+0x03c GDT : Ptr32 _KGDTENTRY
+0x040 TSS : Ptr32 _KTSS
+0x044 MajorVersion : Uint2B
+0x046 MinorVersion : Uint2B
+0x048 SetMember : Uint4B
+0x04c StallScaleFactor : Uint4B
+0x050 DebugActive : UChar
+0x051 Number : UChar
+0x052 Spare0 : UChar
+0x053 SecondLevelCacheAssociativity : UChar
+0x054 VdmAlert : Uint4B
+0x058 KernelReserved : [14] Uint4B
+0x090 SecondLevelCacheSize : Uint4B
+0x094 HalReserved : [16] Uint4B
+0x0d4 InterruptMode : Uint4B
+0x0d8 Spare1 : UChar
+0x0dc KernelReserved2 : [17] Uint4B
+0x120 PrcbData : _KPRCB

lkd> dt nt!_NT_TIB
+0x000 ExceptionList : Ptr32 _EXCEPTION_REGISTRATION_RECORD
+0x004 StackBase : Ptr32 Void
+0x008 StackLimit : Ptr32 Void
+0x00c SubSystemTib : Ptr32 Void
+0x010 FiberData : Ptr32 Void
+0x010 Version : Uint4B
+0x014 ArbitraryUserPointer : Ptr32 Void
+0x018 Self : Ptr32 _NT_TIB

lkd> dt nt!_KPRCB
+0x000 MinorVersion : Uint2B
+0x002 MajorVersion : Uint2B
+0x004 CurrentThread : Ptr32 _KTHREAD
+0x008 NextThread : Ptr32 _KTHREAD
+0x00c IdleThread : Ptr32 _KTHREAD
+0x010 Number : Char
+0x011 Reserved : Char
+0x012 BuildType : Uint2B
+0x014 SetMember : Uint4B
+0x018 CpuType : Char
+0x019 CpuID : Char
+0x01a CpuStep : Uint2B
+0x01c ProcessorState : _KPROCESSOR_STATE
+0x33c KernelReserved : [16] Uint4B
+0x37c HalReserved : [16] Uint4B
+0x3bc PrcbPad0 : [92] UChar
+0x418 LockQueue : [16] _KSPIN_LOCK_QUEUE
+0x498 PrcbPad1 : [8] UChar
+0x4a0 NpxThread : Ptr32 _KTHREAD
+0x4a4 InterruptCount : Uint4B
+0x4a8 KernelTime : Uint4B
+0x4ac UserTime : Uint4B
+0x4b0 DpcTime : Uint4B
+0x4b4 DebugDpcTime : Uint4B
+0x4b8 InterruptTime : Uint4B
+0x4bc AdjustDpcThreshold : Uint4B
+0x4c0 PageColor : Uint4B
+0x4c4 SkipTick : Uint4B
+0x4c8 MultiThreadSetBusy : UChar
+0x4c9 Spare2 : [3] UChar
+0x4cc ParentNode : Ptr32 _KNODE
+0x4d0 MultiThreadProcessorSet : Uint4B
+0x4d4 MultiThreadSetMaster : Ptr32 _KPRCB
+0x4d8 ThreadStartCount : [2] Uint4B
+0x4e0 CcFastReadNoWait : Uint4B
+0x4e4 CcFastReadWait : Uint4B
+0x4e8 CcFastReadNotPossible : Uint4B
+0x4ec CcCopyReadNoWait : Uint4B
+0x4f0 CcCopyReadWait : Uint4B
+0x4f4 CcCopyReadNoWaitMiss : Uint4B
+0x4f8 KeAlignmentFixupCount : Uint4B
+0x4fc KeContextSwitches : Uint4B
+0x500 KeDcacheFlushCount : Uint4B
+0x504 KeExceptionDispatchCount : Uint4B
+0x508 KeFirstLevelTbFills : Uint4B
+0x50c KeFloatingEmulationCount : Uint4B
+0x510 KeIcacheFlushCount : Uint4B
+0x514 KeSecondLevelTbFills : Uint4B
+0x518 KeSystemCalls : Uint4B
+0x51c SpareCounter0 : [1] Uint4B
+0x520 PPLookasideList : [16] _PP_LOOKASIDE_LIST
+0x5a0 PPNPagedLookasideList : [32] _PP_LOOKASIDE_LIST
+0x6a0 PPPagedLookasideList : [32] _PP_LOOKASIDE_LIST
+0x7a0 PacketBarrier : Uint4B
+0x7a4 ReverseStall : Uint4B
+0x7a8 IpiFrame : Ptr32 Void
+0x7ac PrcbPad2 : [52] UChar
+0x7e0 CurrentPacket : [3] Ptr32 Void
+0x7ec TargetSet : Uint4B
+0x7f0 WorkerRoutine : Ptr32 void
+0x7f4 IpiFrozen : Uint4B
+0x7f8 PrcbPad3 : [40] UChar
+0x820 RequestSummary : Uint4B
+0x824 SignalDone : Ptr32 _KPRCB
+0x828 PrcbPad4 : [56] UChar
+0x860 DpcListHead : _LIST_ENTRY
+0x868 DpcStack : Ptr32 Void
+0x86c DpcCount : Uint4B
+0x870 DpcQueueDepth : Uint4B
+0x874 DpcRoutineActive : Uint4B
+0x878 DpcInterruptRequested : Uint4B
+0x87c DpcLastCount : Uint4B
+0x880 DpcRequestRate : Uint4B
+0x884 MaximumDpcQueueDepth : Uint4B
+0x888 MinimumDpcRate : Uint4B
+0x88c QuantumEnd : Uint4B
+0x890 PrcbPad5 : [16] UChar
+0x8a0 DpcLock : Uint4B
+0x8a4 PrcbPad6 : [28] UChar
+0x8c0 CallDpc : _KDPC
+0x8e0 ChainedInterruptList : Ptr32 Void
+0x8e4 LookasideIrpFloat : Int4B
+0x8e8 SpareFields0 : [6] Uint4B
+0x900 VendorString : [13] UChar
+0x90d InitialApicId : UChar
+0x90e LogicalProcessorsPerPhysicalProcessor : UChar
+0x910 MHz : Uint4B
+0x914 FeatureBits : Uint4B
+0x918 UpdateSignature : _LARGE_INTEGER
+0x920 NpxSaveArea : _FX_SAVE_AREA
+0xb30 PowerState : _PROCESSOR_POWER_STATE

lkd> dt nt!_KTHREAD
+0x000 Header : _DISPATCHER_HEADER
+0x010 MutantListHead : _LIST_ENTRY
+0x018 InitialStack : Ptr32 Void
+0x01c StackLimit : Ptr32 Void
+0x020 Teb : Ptr32 Void
+0x024 TlsArray : Ptr32 Void
+0x028 KernelStack : Ptr32 Void
+0x02c DebugActive : UChar
+0x02d State : UChar
+0x02e Alerted : [2] UChar
+0x030 Iopl : UChar
+0x031 NpxState : UChar
+0x032 Saturation : Char
+0x033 Priority : Char
+0x034 ApcState : _KAPC_STATE
+0x04c ContextSwitches : Uint4B
+0x050 IdleSwapBlock : UChar
+0x051 Spare0 : [3] UChar
+0x054 WaitStatus : Int4B
+0x058 WaitIrql : UChar
+0x059 WaitMode : Char
+0x05a WaitNext : UChar
+0x05b WaitReason : UChar
+0x05c WaitBlockList : Ptr32 _KWAIT_BLOCK
+0x060 WaitListEntry : _LIST_ENTRY
+0x060 SwapListEntry : _SINGLE_LIST_ENTRY
+0x068 WaitTime : Uint4B
+0x06c BasePriority : Char
+0x06d DecrementCount : UChar
+0x06e PriorityDecrement : Char
+0x06f Quantum : Char
+0x070 WaitBlock : [4] _KWAIT_BLOCK
+0x0d0 LegoData : Ptr32 Void
+0x0d4 KernelApcDisable : Uint4B
+0x0d8 UserAffinity : Uint4B
+0x0dc SystemAffinityActive : UChar
+0x0dd PowerState : UChar
+0x0de NpxIrql : UChar
+0x0df InitialNode : UChar
+0x0e0 ServiceTable : Ptr32 Void
+0x0e4 Queue : Ptr32 _KQUEUE
+0x0e8 ApcQueueLock : Uint4B
+0x0f0 Timer : _KTIMER
+0x118 QueueListEntry : _LIST_ENTRY
+0x120 SoftAffinity : Uint4B
+0x124 Affinity : Uint4B
+0x128 Preempted : UChar
+0x129 ProcessReadyQueue : UChar
+0x12a KernelStackResident : UChar
+0x12b NextProcessor : UChar
+0x12c CallbackStack : Ptr32 Void
+0x130 Win32Thread : Ptr32 Void
+0x134 TrapFrame : Ptr32 _KTRAP_FRAME
+0x138 ApcStatePointer : [2] Ptr32 _KAPC_STATE
+0x140 PreviousMode : Char
+0x141 EnableStackSwap : UChar
+0x142 LargeStack : UChar
+0x143 ResourceIndex : UChar
+0x144 KernelTime : Uint4B
+0x148 UserTime : Uint4B
+0x14c SavedApcState : _KAPC_STATE
+0x164 Alertable : UChar
+0x165 ApcStateIndex : UChar
+0x166 ApcQueueable : UChar
+0x167 AutoAlignment : UChar
+0x168 StackBase : Ptr32 Void
+0x16c SuspendApc : _KAPC
+0x19c SuspendSemaphore : _KSEMAPHORE
+0x1b0 ThreadListEntry : _LIST_ENTRY
+0x1b8 FreezeCount : Char
+0x1b9 SuspendCount : Char
+0x1ba IdealProcessor : UChar
+0x1bb DisableBoost : UChar

lkd> dt nt!_KUSER_SHARED_DATA
+0x000 TickCountLow     : Uint4B
+0x004 TickCountMultiplier : Uint4B
+0x008 InterruptTime    : _KSYSTEM_TIME
+0x014 SystemTime       : _KSYSTEM_TIME
+0x020 TimeZoneBias     : _KSYSTEM_TIME
+0x02c ImageNumberLow   : Uint2B
+0x02e ImageNumberHigh  : Uint2B
+0x030 NtSystemRoot     : [260] Uint2B
+0x238 MaxStackTraceDepth : Uint4B
+0x23c CryptoExponent   : Uint4B
+0x240 TimeZoneId       : Uint4B
+0x244 Reserved2        : [8] Uint4B
+0x264 NtProductType    : _NT_PRODUCT_TYPE
+0x268 ProductTypeIsValid : UChar
+0x26c NtMajorVersion   : Uint4B
+0x270 NtMinorVersion   : Uint4B
+0x274 ProcessorFeatures : [64] UChar
+0x2b4 Reserved1        : Uint4B
+0x2b8 Reserved3        : Uint4B
+0x2bc TimeSlip         : Uint4B
+0x2c0 AlternativeArchitecture : _ALTERNATIVE_ARCHITECTURE_TYPE
+0x2c8 SystemExpirationDate : _LARGE_INTEGER
+0x2d0 SuiteMask        : Uint4B
+0x2d4 KdDebuggerEnabled : UChar
+0x2d5 NXSupportPolicy  : UChar
+0x2d8 ActiveConsoleId  : Uint4B
+0x2dc DismountCount    : Uint4B
+0x2e0 ComPlusPackage   : Uint4B
+0x2e4 LastSystemRITEventTickCount : Uint4B
+0x2e8 NumberOfPhysicalPages : Uint4B
+0x2ec SafeBootMode     : UChar
+0x2f0 TraceLogging     : Uint4B
+0x2f8 TestRetInstruction : Uint8B
+0x300 SystemCall       : Uint4B
+0x304 SystemCallReturn : Uint4B
+0x308 SystemCallPad    : [3] Uint8B
+0x320 TickCount        : _KSYSTEM_TIME
+0x320 TickCountQuad    : Uint8B
+0x330 Cookie           : Uint4B

lkd> dt _KTRAP_FRAME
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

时间: 2024-08-02 11:05:07

[转载]静态分析nt!KiFastCallEntry的相关文章

[转载]Windows系统调用架构分析—也谈KiFastCallEntry函数地址的获取

原文地址:点击打开链接 为什么要写这篇文章 1.      因为最近在学习<软件调试>这本书,看到书中的某个调试历程中讲了Windows的系统调用的实现机制,其中讲到了从Ring3跳转到Ring0之后直接进入了KiFastCallEntry这个函数. 2.      碰巧前天又在网上看到了一篇老文章介绍xxx安全卫士对Windows系统调用的Hook,主要就是Hook到这个函数 3.      刚刚做完毕业设计,对使用中断来实现系统调用的方式记忆犹新. 以上原因导致我最近眼前总是出现系统调用这

内核函数KiFastCallEntry

KiFastCallEntry() 机制分析 概述 Win32 子系统 API 调用 ntdll!ZwWriteFile() 函数 ntdll!KiFastSystemCall() 函数 _KUSER_SHARED_DATA 结构 切入 KiFastCallEntry() 函数 读取 TSS 信息 KTRAP_FRAME 结构 系统服务例程号与 ServiceTable ServiceTable ServiceTable entry 读取目标例程地址和参数size KiFastCallEntry

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

OpenProcess-->ntdll!NtOpenProcess-->ntdll!zwOpenProcess-->ntdll!KiFastSystemCall() ↓mov edx, esp ↓sysenter 用户层------------------------------------------------------------------------------------------------------ ↓ 内核层 nt!KiFastCallEntry()      

TsFltMgr.sys系统蓝屏的原因就在于QQ电脑管家!

同事一WindowsXP系统,正常执行,关闭后,第二天无法启动,详细症状为: (1)安全模式以及带网络功能的安全模式都能够进入: (2)正常模式,还没出现WindowXP滚动栏就開始重新启动: (3)进安全模式,禁用自己主动重新启动后,再正常启动,出现蓝屏,报TsFltMgr.sys内存错误! 经过互联网查询,和不断摸索,最后发现居然是可恶的QQ软件管家惹的祸,进安全模式果断卸载QQ软件管家后,再重新启动,系统全然正常了. 以下转载了一篇分析QQ电脑管家的文章,请參考: QQ电脑管家中的TsFl

WindowsXP SP3 AFD.sys 本地拒绝服务漏洞的挖掘过程

标 题: WindowsXP SP3 AFD.sys 本地拒绝服务漏洞的挖掘过程 时 间: 2013-03-17,15:22:33 这是本人第一次做漏洞挖掘,2月的时候开始研究漏洞挖掘技术,2月24号那天在进行Fuzz测试的时候偶然的发现了一个afd.sys未处理的异常,然后就对这个异常如获至宝的分析起来了,因为在上班,所以都是利用周末时间来进行,前前后后到加起来差不多5天时间.现在这个漏洞的原因以及低层次的利用已经全部完成,所以拿出来跟大家分享一下,虽然挖到现在只挖出了本地拒绝服务的用处,在如

TsFltMgr.sys其原因是,该系统蓝屏QQ计算机管理器!

同事一WindowsXP系统,正常执行,关闭后,第二天无法启动.详细症状为: (1)安全模式以及带网络功能的安全模式都能够进入. (2)正常模式.还没出现WindowXP滚动栏就開始重新启动: (3)进安全模式,禁用自己主动重新启动后,再正常启动,出现蓝屏.报TsFltMgr.sys内存错误! 经过互联网查询,和不断摸索.最后发现居然是可恶的QQ软件管家惹的祸,进安全模式果断卸载QQ软件管家后,再重新启动,系统全然正常了. 以下转载了一篇分析QQ电脑管家的文章,请參考: QQ电脑管家中的TsFl

文件删除的windows下面的三种路径(轻量级)

文件常规删除的三种方法都比较熟悉. #define FILE_DELETE_ON_CLOSE 0x00001000 @1 Nt/ZwCreateFile Nt/ZwOpenFile 填充OpenPacket结构,标记FILE_DELETE_ON_CLOSE (WRK) @2 Nt/ZwDeleteFile 填充OpenPacket结构,标记FILE_DELETE_ON_CLOSE (WRK) @3 Nt/ZwSetInformationFile 使用FileDispositionInformat

Windows内核学习笔记之浅析系统调用

在潘老师<Windows内核原理与实现>一书,解析了Windows应用程序发出的系统调用.图示如下. 从图可看出,系统调用所提供的服务(函数)是运行在内核中的,也就是说,在"系统空间"中. 用户空间与系统空间所在的内存区间不一样,同样,对于这两种区间,CPU的运行状态也不一样. 在用户空间中,CPU处于"用户态":在系统空间中,CPU处于"系统态". CPU从系统态进入用户态是容易的,因为可以执行一些系统态特有的特权指令,从而进入用户

系统调用学习笔记

开始学内核的时候,一定会讲从ring3到ring0的调用,但是网上很多的文章讲的模棱两可,这次记录下我对系统调用的研究........ 一个线程由用户态进入内核态的途径有3种典型的方式: 1.  主动通过int 2e(软中断自陷方式)或sysenter指令(快速系统调用方式)调用系统服务函数,主动进入内核 2.  发生异常,被迫进入内核 3.  发生硬件中断,被迫进入内核 现在的cpu调用api进入内核都是通过sysenter指令(AMD的处理器是syscall)进入到ring0,系统在启动的时