当前位置: 首页 > news >正文

nt!MiAllocateWsle函数分析之设置Wsle[WorkingSetIndex]

第一部分:

1: kd> p
nt!MiAddValidPageToWorkingSet+0xa9:
80a83c13 e8da9afcff      call    nt!MiAllocateWsle (80a4d6f2)
1: kd> t
nt!MiAllocateWsle:
80a4d6f2 55              push    ebp
1: kd> dv
         WsInfo = 0x8953a1f8
     PointerPte = 0xc01df8a8
           Pfn1 = 0x81bcd810
       WsleMask = 0x118
           Wsle = 0x00000008
WorkingSetIndex = 0x8953a1f8


第二部分:

1: kd> dx -r1 ((ntkrnlmp!_MMWSL *)0xc0503000)
((ntkrnlmp!_MMWSL *)0xc0503000)                 : 0xc0503000 [Type: _MMWSL *]
    [+0x000] FirstFree        : 0xc3 [Type: unsigned long]


   WorkingSetIndex = WorkingSetList->FirstFree;
    WorkingSetList->FirstFree = (WSLE_NUMBER)(Wsle[WorkingSetIndex].u1.Long >> MM_FREE_WSLE_SHIFT);


1: kd> dd 0xc0503698+c3*4
c05039a4  00000c40 00000c50 00000c60 00000c70

WorkingSetList->FirstFree=c4

    if (WorkingSetIndex > WorkingSetList->LastEntry) {
        WorkingSetList->LastEntry = WorkingSetIndex;
    }

1: kd> dx -r1 ((ntkrnlmp!_MMWSL *)0xc0503000)
((ntkrnlmp!_MMWSL *)0xc0503000)                 : 0xc0503000 [Type: _MMWSL *]
    [+0x000] FirstFree        : 0xc4 [Type: unsigned long]
    [+0x004] FirstDynamic     : 0x4 [Type: unsigned long]
    [+0x008] LastEntry        : 0xc3 [Type: unsigned long]


第三部分:

#define MiGetVirtualAddressMappedByPte(PTE) ((PVOID)((ULONG)(PTE) << 10))

     PointerPte = 0xc01df8a8


1100 0000 0001 1101 1111 1000 1010 1000

01 11  01 11  11 10  00 10  10 10  00 00 0000 0000

77e2a000

参考后总结:得到的确实是虚拟地址,PTE左移10位 得到虚拟地址前20位!!
虚拟地址右移10位+0xC000 0000 得到PTE

1: kd> dv
StoreInstruction = 0
 FaultingAddress = 0x77e2a0c8


1: kd> !pte 0x77e2a0c8
                 VA 77e2a0c8
PDE at C030077C         PTE at C01DF8A8
contains 7B259867       contains 7DE56025
pfn 7b259 ---DA--UWEV   pfn 7de56 ----A--UREV


第四部分:

1: kd> t
nt!MiAllocateWsle+0x14d:
80a4d83f e80aaeffff      call    nt!MiUpdateWsle (80a4864e)
1: kd> t
nt!MiUpdateWsle:
80a4864e 55              push    ebp
1: kd> kc
 #
00 nt!MiUpdateWsle
01 nt!MiAllocateWsle
02 nt!MiAddValidPageToWorkingSet
03 nt!MiCompleteProtoPteFault
04 nt!MiResolveProtoPteFault
05 nt!MiDispatchFault
06 nt!MmAccessFault
07 nt!_KiTrap0E
08 nt!ObpCaptureObjectName
09 nt!ObpCaptureObjectCreateInformation
0a nt!ObOpenObjectByName
0b nt!NtOpenSection
0c nt!_KiSystemService
0d SharedUserData!SystemCallStub
0e ntdll!NtOpenSection
0f KERNEL32!OpenSection
10 KERNEL32!GetLocaleFileInfo
11 KERNEL32!NlsProcessInitialize
12 KERNEL32!NlsDllInitialize
13 KERNEL32!BaseDllInitialize
14 ntdll!LdrpCallInitRoutine
15 ntdll!LdrpRunInitializeRoutines
16 ntdll!LdrpLoadDll
17 ntdll!LdrLoadDll
18 CSRSRV!CsrLoadServerDll
19 CSRSRV!CsrParseServerCommandLine
1a CSRSRV!CsrServerInitialization
1b csrss!main
1c csrss!NtProcessStartup

1: kd> dv
   DesiredIndex = 0xf704b9f0
 VirtualAddress = 0x77e2a000
         WsInfo = 0x8953a1f8
            Pfn = 0x81bcd810
           Wsle = 0x80a4864e


第五部分:

    WsleContents.u1.VirtualAddress = PAGE_ALIGN (VirtualAddress);
    WsleContents.u1.e1.Valid = 1;


1: kd> dt mmwsle -r
nt!MMWSLE
   +0x000 u1               : __unnamed
      +0x000 VirtualAddress   : Ptr32 Void
      +0x000 Long             : Uint4B
      +0x000 e1               : _MMWSLENTRY
         +0x000 Valid            : Pos 0, 1 Bit
         +0x000 LockedInWs       : Pos 1, 1 Bit
         +0x000 LockedInMemory   : Pos 2, 1 Bit
         +0x000 Protection       : Pos 3, 5 Bits
         +0x000 SameProtectAsProto : Pos 8, 1 Bit
         +0x000 Direct           : Pos 9, 1 Bit
         +0x000 Age              : Pos 10, 2 Bits
         +0x000 VirtualPageNumber : Pos 12, 20 Bits

0x77e2a001


第六部分:

WorkingSetIndex = 0xc3

1: kd> dd 0x81bcd810
81bcd810  00000000 e13a9c10 00000001 00011608
81bcd820  f926946a 000007ec


   +0x00c u3               : __unnamed
      +0x000 e1               : _MMPFNENTRY
         +0x000 Modified         : Pos 0, 1 Bit
         +0x000 ReadInProgress   : Pos 1, 1 Bit
         +0x000 WriteInProgress  : Pos 2, 1 Bit
         +0x000 PrototypePte     : Pos 3, 1 Bit    1

        if (Pfn->u3.e1.PrototypePte == 0) {

        }
        else {

            OldValue = InterlockedCompareExchange ((PLONG)&Pfn->u1.Event,
                                                   WorkingSetIndex,
                                                   0);


1: kd> dd 0x81bcd810
81bcd810  000000c3 e13a9c10 00000001 00011608        //000000c3
81bcd820  f926946a 000007ec

第七部分:

        if (OldValue == 0) {

            WsleContents.u1.e1.Direct = 1;        -->0x77e2a201

            MI_LOG_WSLE_CHANGE (WorkingSetList, WorkingSetIndex, WsleContents);

            Wsle[WorkingSetIndex] = WsleContents;

            return;


1: kd> dt mmwsle -r
nt!MMWSLE
   +0x000 u1               : __unnamed
      +0x000 VirtualAddress   : Ptr32 Void
      +0x000 Long             : Uint4B
      +0x000 e1               : _MMWSLENTRY
         +0x000 Valid            : Pos 0, 1 Bit
         +0x000 LockedInWs       : Pos 1, 1 Bit
         +0x000 LockedInMemory   : Pos 2, 1 Bit
         +0x000 Protection       : Pos 3, 5 Bits
         +0x000 SameProtectAsProto : Pos 8, 1 Bit
         +0x000 Direct           : Pos 9, 1 Bit

0x77e2a001
0000 0000 0001
0010 0000 0001
0x77e2a201


1: kd> p
nt!MiUpdateWsle+0x178:
80a487c6 890c90          mov     dword ptr [eax+edx*4],ecx
1: kd> r
eax=c0503698 ebx=77e2a001 ecx=77e2a201 edx=000000c3 esi=c0503000 edi=81bcd810

1: kd> dd c0503698+c3*4
c05039a4  00000c40 00000c50 00000c60 00000c70

Wsle[WorkingSetIndex] = WsleContents;


1: kd> dd c0503698+c3*4
c05039a4  77e2a201 00000c50 00000c60 00000c70

第八部分:返回到nt!MiAllocateWsle

1: kd> p
nt!MiAllocateWsle+0x15c:
80a4d84e 8b45fc          mov     eax,dword ptr [ebp-4]


    if (WsleMask != 0) {
        Wsle[WorkingSetIndex].u1.Long |= WsleMask;        //添加上掩码。
    }


       WsleMask = 0x118

1: kd> dd c0503698+c3*4
c05039a4  77e2a201

0x77e2a201+0x118=0x77e2a319


1: kd> p
nt!MiAllocateWsle+0x15f:
80a4d851 8d04b8          lea     eax,[eax+edi*4]
1: kd> p
nt!MiAllocateWsle+0x162:
80a4d854 0908            or      dword ptr [eax],ecx
1: kd> r
eax=c05039a4 ebx=0fffffff ecx=00000118


        Wsle[WorkingSetIndex].u1.Long |= WsleMask;之后

1: kd> dd c0503698+c3*4
c05039a4  77e2a319

http://www.dtcms.com/a/191935.html

相关文章:

  • Golang
  • 基于策略的强化学习方法之近端策略优化(PPO)深度解析
  • 2025.05.14华为机考笔试题-第一题-100分
  • xp_cmdshell bcp 导出文件
  • 测试--BUG(软件测试⽣命周期 bug的⽣命周期 与开发产⽣争执怎么办)
  • 牛客网NC22157:牛牛学数列2
  • 编程题 03-树3 Tree Traversals Again【PAT】
  • AI实时对话的通信基础,WebRTC技术综合指南
  • GPU与NPU异构计算任务划分算法研究:基于强化学习的Transformer负载均衡实践
  • Go 语言中接口类型转换为具体类型
  • Automatic Recovery of the Atmospheric Light in Hazy Images论文阅读
  • RabbitMQ 消息模式实战:从简单队列到复杂路由(一)
  • 用FileCodeBox打造私有文件传输:Ubuntu环境保姆级部署教程!
  • python算法-最大连续1的个数删除有序数组中的重复项--Day020
  • go依赖查询工具之godepgraph(分析main.go的依赖树)
  • 2025.05.14华为机考笔试题-第二题-200分
  • 鸿蒙OSUniApp制作多选框与单选框组件#三方框架 #Uniapp
  • ET EntityRef EntityWeakRef 类分析
  • C#语法基础
  • 分布式调度的--多模型协同工作实践方案
  • 语音识别——声纹识别
  • EasyExcel详解
  • 2025年,多模态特征融合只会更火
  • 争对机器学习和深度学习里Python项目开发管理项目依赖的工具中方便第三方库和包的安装
  • 【MyBatis插件】PageHelper 分页
  • 飞牛NAS本地部署开源TTS文本转语音工具EasyVoice与远程使用流程
  • 前端流行框架Vue3教程:17. _组件数据传递
  • 深入解析HTTP协议演进:从1.0到3.0的全面对比
  • 2025认证杯数学建模第二阶段A题小行星轨迹预测思路+模型+代码
  • 机器学习中采样哪些事