静态分析nt!KiFastCallEntry

蓝屏总结(一) ——基本分析方法 目录 一、蓝屏造成原因 二、通常的排查步骤 三、Debug步骤 四、使用Driver Verifier进行排查 五、Debug示例 1、分析示例 1 2、分析示例 2 一、蓝屏造成原因 关于停止错误(蓝屏或者错误检查)没有简单的解释,包含很多因素,目前大量研究表明停止错误通常不是由微软Windows组件导致的,而是厂商的硬件驱动或者三方软件的驱动,包括声卡、无线网卡、安全程序等等。 crash的根因一般都是由三方驱动代码引起的,另外一小部分是硬件问... 阅读详情

转载: 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 的代码 
代码:
nt!KiFastCallEntry:
 
// 当线程在内核模式下执行时的数据段选择子是23h
// 当线程在内核模式下执行时,在FS寄存器中加载的是选择子30,
// 用于寻址PCR结构体
804de6f0      mov ecx,23h
804de6f5      push 30h
804de6f7      pop fs
 
// 23h->ds;23h->es
804de6f9      mov ds,cx
804de6fb      mov es,cx
 
// dword ptr fs:[40h] == dword ptr ds:[0FFDFF040h]{TSS}
// dword ptr [ecx+4] 为当前线程的内核模式栈顶指针的值
804de6fd      mov ecx,dword ptr ds:[0FFDFF040h]
804de703      mov esp,dword ptr [ecx+4]
 
// ==========================================
// 将当前(执行Sysenter前各寄存器的值)上下文压入系统堆栈,
 
// _KTRAP_FRAME.HardwareSegSs
804de706      push 23h
 
// _KTRAP_FRAME.HardwareEsp
804de708      push edx
 
// _KTRAP_FRAME.EFags
804de709      pushfd
804de70a      push 2
804de70c      add edx,8
 
// EFlags = 2
804de70f      popfd
804de710      or byte ptr [esp+1],2
 
// _KTRAP_FRAME.SegCs
804de715      push 1Bh
 
// ds:[0FFDF0304h] 是SystemCallReturn(_KUser_Shared_Data)
// _KTRAP_FRAME.Eip
804de717      push dword ptr ds:[0FFDF0304h]
 
//_KTRAP_FRAME.ErrorCode
804de71d      push 0   
 
//_KTRAP_FRAME.Ebp                                       
804de71f      push ebp     
 
//_KTRAP_FRAME.Ebx
804de720      push ebx
 
//_KTRAP_FRAME.Esi
804de721      push esi                                        
 
//_KTRAP_FRAME.Edi
804de722      push edi 
 
 
//ebx<-_KPCR.SelfPcr
804de723      mov ebx,dword ptr ds:[0FFDFF01Ch]  
 
// _KTRAP_FRAME.SegFs
804de729      push 3Bh
 
//esi=_KPCR.PrcbData.CurrentThread
804de72b      mov esi,dword ptr [ebx+124h]   
 
//_KTRAP_FRAME.ExceptionList
804de731      push dword ptr [ebx]
// 初始化链表
804de733      mov dword ptr [ebx],0FFFFFFFFh
 
//ebp = KPCR.PrcbData.CurrentThread. InitialStack
804de739      mov ebp,dword ptr [esi+18h]
 
//_KTRAP_FRAME.PreviousPreviousMode = 1
804de73c      push 1
 
// esp->_KTRAP_FRAME
804de73e      sub esp,48h   
 
// ebp ->_KTRAP_FRAME
804de741      sub ebp,29Ch
 
// CurrentThread +124 = 1
804de747      mov byte ptr [esi+140h],1
 
// 比较
804de74e      cmp ebp,esp
// 不相等,发生了异常
804de750      jne nt!KiFastCallEntry2+0x24 (804de6c8)
 
// _KTRAP_FRAME.Dr7 = 0
804de756      and dword ptr [ebp+2Ch],0
 
// [esi+2Ch]是KTHREAD.DebugActive当前线程的调试标志
//不等于0xFF表示调试中?
804de75a      test byte ptr [esi+2Ch],0FFh
804de75e      mov dword ptr [esi+134h],ebp
804de764      jne nt!Dr_FastCallDrSave (804de5b0)
 
 
// ebx = _KTRAP_FRAME.Ebp
804de76a      mov ebx,dword ptr [ebp+60h]
 
// edi = _KTRAP_FRAME.EIP
804de76d      mov edi,dword ptr [ebp+68h]
 
// _KTRAP_FRAME.DbgArgPointer
804de770      mov dword ptr [ebp+0Ch],edx
 
// _KTRAP_FRAME.DbgArgPointer = DbgArgMark
804de773      mov dword ptr [ebp+8],0BADB0D00h
 
//_KTRAP_FRAME.DbgEbp 
804de77a      mov dword ptr [ebp],ebx
 
//_KTRAP_FRAME.DbgEip = _KTRAP_FRAME.EIP
804de77d      mov dword ptr [ebp+4],edi
//==================================
 
// 开中断
804de780      sti
 
//eax为函数序号,但是在KeServiceDescriptorTableShadow时
//是函数序号+1000h,所以在KeServiceDescriptorTableShadow
//经过下面运算ecx最终为10h,否则为0
804de781      mov edi,eax
804de783      shr edi,8
804de786      and edi,30h
804de789      mov ecx,edi
 
//KTHREAD.ServiceTable gdi32.dll和user32.dll调用时,
//ServiceTable为KeServiceDescriptorTableShadow,
//ntdll.dll调用时ServiceTable为KeServiceDescriptorTable
//在KeServiceDescriptorTableShadow时+10正好得到win32.sys调用
804de78b      add edi,dword ptr [esi+0E0h]
804de791      mov ebx,eax
 
//保留三个字节,得到正真的序号
804de793      and eax,0FFFh
 
//和ssdt或shadow ssdt总共项数比较,eax大则跳
804de798      cmp eax,dword ptr [edi+8]
804de79b      jae nt!KiBBTUnexpectedRange (804de4e2)
 
//判断是shadow ssdt还是ssdt,不跳则是shadow ssdt,跳则是ssdt
804de7a1      cmp ecx,10h
804de7a4      jne nt!KiFastCallEntry+0xcc (804de7c0)
 
// TIB地址送ecx
804de7a6      mov ecx,dword ptr ds:[0FFDFF018h]
 
// [ecx+0xf70] 是什么东东?
804de7ac      xor ebx,ebx
804de7ae      or ebx,dword ptr [ecx+0F70h]
804de7b4      je nt!KiFastCallEntry+0xcc (804de7c0)
 
804de7b6      push edx
804de7b7      push eax
804de7b8      call dword ptr [nt!KeGdiFlushUserBatch (8055a164)]
804de7be      pop eax
804de7bf      pop edx
 
// SSDT
// ds:[0FFDFF638h](fs:[638h]) KeSystemCalls 
// 仅仅用来记录系统调用的次数,无太多用处
804de7c0      inc dword ptr ds:[0FFDFF638h]
 
// edx中是参数(堆栈顶的指针)
804de7c6      mov esi,edx
804de7c8      mov ebx,dword ptr [edi+0Ch]
804de7cb      xor ecx,ecx
804de7cd      mov cl,byte ptr [eax+ebx]
 
//edi=KeServiceDescriptorTable->ServiceTableBase
804de7d0      mov edi,dword ptr [edi]
 
//计算服务例程地址(edi为KiServiceTable,eax为函数序号)
804de7d2      mov ebx,dword ptr [edi+eax*4]
804de7d5      sub esp,ecx
804de7d7      shr ecx,2
804de7da      mov edi,esp
 
// 检查esi是否指向用户空间
804de7dc      cmp esi,dword ptr ds:[0EED02CF4h]
804de7e2      jae nt!KiSystemCallExit2+0x9f (804de990)
 
//把参数复制到内核
804de7e8      rep movs dword ptr es:[edi],dword ptr [esi]
 
//转入服务例程入口
804de7ea      call ebx
 
// 恢复堆栈
804de7ec      mov esp,ebp
 
// fs:[124h]中储存着当前线程的ETHREAD
// ETHREAD的偏移134h处为TrapFrame
804de7ee      mov ecx,dword ptr ds:[0FFDFF124h]
804de7f4      mov edx,dword ptr [ebp+3Ch]
804de7f7      mov dword ptr [ecx+134h],edx
 。。。。
 
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
系统调用计算KiFastCallEntry地址的过程以及由此得到的一种获取KiFastCallEntry地址的方式 SYENTER和SYSEXIT指令首次出现于Pentium II处理器中,其目的是为了提供一个快速(低负载) 的调用操作系统或者执行体过程的机制.SYSENTER用于运行特权级别为3的用户 调用特权级0 的系统内核代码。 WinDbg中反汇编 KiFastSystemCall可以看到SYSENTER指令。 在调用SYSENTER指令前,CPU会通过下面的MSR 阅读详情

相关推荐

Utrust4701F与Utrust2700R读写器在银河麒麟系统的安装及测试步骤说明

Utrust4701F与Utrust2700R读写器支持银河麒麟系统,广泛应用会员管理、支付管理等领域。本文将重点介绍Utrust4701F与Utrust2700R读写器在银河麒麟系统的安装及测试步骤说明。以上方法适用于主流国产操作系统,如 优麒麟(UbuntuKylin)/ 中标麒麟(NeoKylin) / UOS(统信操作系统)/ 中兴新支点 / 红旗 linux(redflag linux)/ 普华 Linux(I-soft OS) / 威科乐恩 Linux(WiOS)等

华翔天诚科技 1842

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

为什么要写这篇文章 1.      因为最近在学习《软件调试》这本书,看到书中的某个调试历程中讲了Windows的系统调用的实现机制,其中讲到了从Ring3跳转到Ring0之后直接进入了KiFastCallEntry这个函数。 2.      碰巧前天又在网上看到了一篇老文章介绍xxx安全卫士对Windows系统调用的Hook,主要就是Hook到这个函数 3.      刚刚做完毕业设计,对

Less Is More 2万+

【codex教程】Codex 注册和使用教程(2026最新版)

Codex 是 OpenAI 推出的 AI 编程助手,可以帮助开发者阅读代码、修改代码、运行命令、生成测试、排查 bug、做代码审查,也可以在终端、IDE、Codex App 或网页端使用。根据 OpenAI 帮助中心,截至 2026 年 6 月,Codex 已包含在 Free、Go、Plus、Pro、Business、Edu 和 Enterprise 等 ChatGPT 方案中,但不同套餐的使用额度会有所不同。适合开发者在终端中使用。如果你想在命令行里使用 Codex,可以安装 Codex CLI。

与时俱进,开放共享 2万+

SYSENTER系统服务调用过程

SYSENTER系统服务调用过程 以NtReadFile调用为例。一.NtDll.Dll中,NtReadFile过程如下:ntdll!NtReadFile:7c92d9b0 b8b7000000      mov     eax,0B7h7c92d9b5 ba0003fe7f      mov     edx,offset SharedUserData!SystemCa

misterliwei的专栏 5672

YOLOv8 改进有效涨点专栏目录 | 含卷积、主干、注意力机制、Neck、检测头、损失函数、二次创新C2PSA/C3k2等各种网络结构改进

YOLOv8在目标检测领域的地位与优势模型改进的意义与价值本专栏的特色与创新点读者学习路径建议关键改进点回顾不同场景的模型选型建议开源社区资源汇总持续学习路径指南YOLOv8在目标检测领域的地位与优势模型改进的意义与价值本专栏的特色与创新点读者学习路径建议关键改进点回顾不同场景的模型选型建议开源社区资源汇总持续学习路径指南。

weixin_39818775的博客 1075

HDMI接口及其在编程中的应用

在编程中,我们可以使用HDMI接口来控制和管理连接到计算机的HDMI设备。本文将介绍HDMI接口的基本原理以及如何在编程中使用HDMI接口。在编程中,我们可以使用HDMI接口来控制和管理连接到计算机的HDMI设备。本文介绍了HDMI接口的基本原理,并提供了使用Python编程语言和相关库实现HDMI接口应用的示例代码。我们可以使用编程语言提供的音频库来生成和播放音频,并将其通过HDMI接口输出到连接的设备上。我们可以使用编程语言提供的音频库来生成和播放音频,并将其通过HDMI接口输出到连接的设备上。

CodeByte的博客 807

KiFastCallEntry() 机制分析

本文转自:http://www.mouseos.com/windows/kernel/KiFastCallEntry.html 1. 概述 从 windows xp 和 windows 2003 开始使用了快速切入内核的方式提供系统服务例程的调用。 KiFastCallEntry() 的实现是直接使用汇编语言,C 语言不能直接表达某些操作。我从 windows 2003

无本之木 1386

YOLOv8 改进:使用 MobileNetV3 轻量化架构改进特征提取网络

通过使用 MobileNetV3 作为 YOLOv8 的特征提取器,能够显著降低模型复杂度和运行时资源消耗,同时在一定程度上保持检测精度。这种方法特别适合需要高效计算的边缘设备和嵌入式系统。

走向CTO的路上... 1281

对XP上的KiFastSystemCall进行浅析

WindowsAPI的系统调用过程通过KiFastSystemCall或int2e进入内核,本文仅对XP上的KiFastSystemCall进行浅析。   以ntdll!ZwCreateProcessEx为例:   Eax中保存系统调用号,此处ZwCreateProcessEx的为30h;Edx是SharedUserData!SystemCallStub的地址,里面保存着KiF...

weixin_34200628的博客 312

SPSS 多重共线性问题:编程解决方案

多重共线性会导致回归模型的不稳定性,使得估计的回归系数失去解释力,降低模型的准确性和可靠性。通过执行这些代码,你将能够计算和查看VIF和CI的结果,并确定是否存在多重共线性问题。上述代码执行了一个回归分析,其中A是我们感兴趣的因变量,B、C、D和E是我们要检查的自变量。接下来,我们将执行多重共线性的检测。通过执行上述代码,你将能够看到每个自变量的VIF和CI值,以及预先设置的阈值。上述代码将计算VIF和CI的值,并将结果写入指定路径的结果文件中。接下来,我们可以使用以下代码来计算和显示VIF和CI的值。

CyberGenius的博客 1431

番外篇第3集:多模态运维!让 AI 看懂 Grafana 图表并自动生成巡检报告

文章摘要 《多模态运维:让AI看懂Grafana图表并自动生成巡检报告》介绍了如何利用Qwen2.5-VL多模态模型解决传统运维巡检的痛点。文章指出人工查看Grafana监控图表存在效率低、易漏判、报告编写耗时等问题,提出通过Grafana Render API和多模态AI技术实现自动化巡检方案。 主要内容包括: 环境准备:配置Qwen2.5-VL多模态模型和Grafana访问权限 测试验证:展示模型准确识别图表类型、指标数值和异常趋势的能力 技术实现:封装Grafana截图API客户端,支持面板截图和数据

qq_2937655951的博客 116

[转载]静态分析nt!KiFastCallEntry

转载: http://bbs.pediy.com/showthread.php?t=89407 在XP系统中,系统服务在内核的入口是KiFastCallEntry,我们从该入口开始,分析这一段代码都做了什么工作。 由于水平有限和背景知识不够,本人没有完全读懂它们,作为抛砖引玉,我先将我所看懂的和大家分享,希望大家多多指教! KiFastCallEntry的主要...

angbagangzhe065140的博客 420

使用亚组分析进行子组分析并可视化森林图 - R语言

通过亚组分析和森林图的结合,我们可以更好地理解不同子组之间的差异和效果大小。当然,在实际应用中,还需要考虑多种因素,如样本量、异质性等,以得到更准确的结果和结论。每个森林图中的水平线代表了每个子组的效应估计,线的长度表示了该效应估计的置信区间。假设我们有一个包含研究对象的数据框(data frame),其中包括了治疗组和对照组的结果数据,以及一些可能的影响因素作为调整变量。在本例中,我们将比较两种不同的治疗方法(A和B)对结果变量的影响,并调整了一个额外的变量。是结果变量和对照组变量的列名。

2301_79326857的博客 1238

Windows Research Kernel (WRK) 调试技巧:如何使用WinDbg分析NT内核源代码的完整指南

Windows Research Kernel (WRK) 是微软官方发布的Windows NT内核源代码研究项目,为操作系统研究人员和内核开发者提供了深入了解Windows内核架构的绝佳机会。本文将为您详细介绍如何利用WinDbg调试工具来分析和调试WRK内核源代码,帮助您快速掌握Windows内核调试的核心技巧。💡 ## 为什么选择Windows Research Kernel进行内核研究

gitblog_00009的博客 551

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Windows保护模式(五)任务段&任务门

call 加载 TSS 的指令格式为call 16位TSS段选择子:无效EIP,因此可以在 GDT 中构造一个段选择子然后指向自己构造的 TSS 然后 call 过去。利用 call 指令进行 TSS 加载时会将 EFLAGS 寄存器中的 NT 位置 1 ,表示中断嵌套,根据 NT 位是否为 1,iretd 返回时会选择根据 Previous Task Link 选择 TSS 还是根据堆栈返回。如果在切换任务函数中使用了int 3断点会将 NT 位置 0 导致返回时根据堆栈返回触发蓝屏。

sky123博客 2178

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

[转](54)线程结构体 ETHREAD,线程断链

一、回顾 上次课我们学习了进程,我们知道了进程是空间概念,最主要的功能是提供CR3,而线程才是CPU调度的最小单位; 更早的时候做SSDT HOOK FindWindow 时我们还了解到了,当3环程序向驱动发起通信时,驱动所属进程就是3环的程序; 学习了EPROCESS里的部分成员,其中 ActiveProcessLinks 是进程链表,我们可以通过对其断链实现进程隐藏,DebugPort 是调试端口,抹除它的值可以使三环调试器调试崩溃。 本次课我们来学习线程结构体 E...

weixin_41875267的博客 963

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

WINDOWS系统调用 和 SYSENTER系统服务调用过程

Windows 2K通过2Eh中断来实现系统调用的,但是在XP后使用SysEnter来实现系统调用了,同时2Eh中断还是保存着的。不管是2EH中断还是SYSENTER,Windows对所有的系统调用都会生成下面的KTRAP_FRAME堆栈框架。 KTRAP_FRAME框架结构图 用户态下使用2EH中断时,CPU会自动产生0x78和0x74 以保存用户态下...

weixin_34186128的博客 369

KeBugCheck2的第6个参数

大家知道,DDK公开了两个内核API用于产生BSOD,分别是KeBugCheck()和KeBugCheckEx()。其原型分别如下:VOID   KeBugCheck(IN ULONG  BugCheckCode    );VOID   KeBugCheckEx(IN ULONG BugCheckCode,    IN ULONG_PTR  BugCheckParameter1,    I

7599

ffdff000 处的结构 KPCR

ffdff000 处的结构 KPCR作者: JIURL                 主页: http://jiurl.yeah.net     日期: 2003-11-13     ffdff000 处是一个叫做 KPCR 的结构,PCR 即 Processor Control

jiurl的专栏 6126

sysenter后如何找到内核里的对应函数的

比如,我们调用ntdll!NtReadFile后,如何进入内核的?很多书、文章都描述了,那么在调用到sysenter以后,内核是如何找到对应的函数的? 还是需要通过SSDT,但是nt!KiFastCallEntry却没有了nt!KiSystemService的踪迹。 跟踪前,先找到SSDT的地址 接下里,我们看下SSDT表的地址 kd> dd KeServiceDescriptorTa

无本之木 863

语义分割之ENet

论文:ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation 代码:https://github.com/TimoSaemann/ENet 论文提出了新的语义分割模型ENet (efficient neural network),相比SegNet,速度提升18倍,计算量减少75倍,参数...

年轻即出发, 1万+

360安全卫士hookport.sys简单逆向

360安全卫士hookport.sys简单逆向——MyHookMgr数据结构 2009年10月23日 星期五 17:12 MyHookMgr数据结构 MyHookMgr是一个大小为0x5DDC的巨大结构,是360挂钩中的一个重要数据,它记录了挂钩函数的原地址、代理函数地址及相应函数是否挂钩的标志位。 它的数据结构是这样的: struct MyHookMgr{

lionzl的专栏 3151

系统调用002 KiSystemService函数逆向分析

文章目录前言保存现场_KTRAP_FRAMEKRPCExceptionList_KTHREAD结构体先前模式抬高堆栈判断当前权限更新_KTRAP_FRAME保存三环的寄存器环境判断调试状态 前言 之前我们详细了解了API从三环进到零环的过程,API会通过两种方式进入到零环,如果通过中断门的方式进入零环,最终会进入到KiSystemService这个函数。接下来就来分析KiSystemService...

鬼手的博客 2456

用IDA看ntdll的时候写的

今天看到了NtQuerySystemInformation()这个函数,就用IDA反了下ntdll.dll,发现了一个很有意思的事。我以前就知道XP下已经用sysenter指令代替了int 2eh来进入Ring0,但是没有想到的是,在NTDLL中,sysenter被封装到了KiFastSystemCall中,我看了几个需要进入Ring0的API,最后都调用KiFastSystemCall来执行sy

HerbBlend的专栏 3843

sysenter内核入口点代码分析

参考:http://www.mouseos.com/windows/kernel/KiFastCallEntry.html http://www.mouseos.com/windows/kernel/%E4%B8%80%E4%BA%9B%E9%80%86%E5%90%91%E5%87%BA%E6%9D%A5%E7%9A%84%E5%87%BD%E6%95%B0%E5%AE%9E%E7%8E%B0...

weixin_34015860的博客 667
上一篇: AVL树(一)之 图文解析 和 C语言的实现
下一篇: 页表项(PTE)地址计算公式的解释
ProgrammingRing
博客等级 码龄17年 76粉丝 31原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址