WinDbg 中的页目录指针表

逆向工程 记忆 风袋
2021-06-25 10:25:57

WinDbg 中的 !pte 命令提供了有关虚拟地址(PDE 和 PTE 位置和内容)的所有信息,但即使在具有 PAE 的系统上,它也没有说明页面目录指针表。我知道我可以通过查看 CR3 来获得 PDPT 的物理基础,然后使用 VA 的最高 2 位作为该表中的索引来获得 PDPT 条目,但我只是好奇是否有当涉及到 PAE 时,命令的工作方式类似于 !pte,因为它将是一个很好的工具,可以逐步验证我的地址转换。

另外,有没有办法确定MAXPHYADDR?我知道它最多是 52。

2个回答

对于va to phys address translation 有一个 windbg bang 命令
!vtop 0 < VirtualAddress >

下面该命令的示例输出

kd> !vtop 0 403000
X86VtoP: Virt 00403000, pagedir 11800480
X86VtoP: PAE PDPE 11800480 - 00000000387a9001
X86VtoP: PAE PDE 387a9010 - 000000001b6b7067
X86VtoP: PAE PTE 1b6b7018 - 800000001bb2e225
X86VtoP: PAE Mapped phys 1bb2e000
Virtual address 403000 translates to physical address 1bb2e000.

下面是我编写的一个windbg 脚本,(can be buggy havent tested this in a 64 bit machine )
这个脚本需要一个进程名称和一个虚拟地址,该进程将它拆分为pd pde pte 和偏移量,并检索物理地址并打印内容。

脚本内容

r $t0 = ${$arg1}
r $t1 = ${$arg2}
r $t2 = (( @$t1 & 0xc0000000 ) >> 0n29 )
r $t3 = (( @$t1 & 0x3fe00000 ) >> 0n21 )
r $t4 = (( @$t1 & 0x001ff000 ) >> 0n12 )
r $t5 = (( @$t1 & 0x00000fff ) >> 0n00 )
.printf "Page Directory Index      \t%x\n" , @$t2
.printf "Page Directory Entry Index\t%x\n" , @$t3
.printf "Page Table Entry Index    \t%x\n" , @$t4
.printf "Offset                    \t%x\n" , @$t5
.foreach /pS 1 /ps 100 ( place { !process 0 0 ${$arg1} } ) { r $t6 = place }
.process /p /r @$t6
db @$t1
r $t7 = @@c++( *(ULONG *)@$proc->Pcb.DirectoryTableBase )
.printf "printing PDINDEX[%08x]\n",@$t2
!dd @$t7 + @$t2 * @@c++(sizeof(INT64)) l1
.printf "printing PDEINDEX[%08x]\n",@$t3
.foreach /pS 1 /ps 100 (place {!dd @$t7 + @$t2 * @@c++(sizeof(INT64)) l1 } ) {r $t8 = ( place & 0xfffff000 ) ; !dd ( place & 0xfffff000) l1 }
.printf "printing PTEINDEX[%08x]\n",@$t4
.foreach /pS 1 /ps 100 (place {!dd @$t8 + @$t3 * @@c++(sizeof(INT64)) l1 } ) {r $t9 = ( place & 0xfffff000 ) ; !dd ( place & 0xfffff000) l1 }
.printf "printing Offset[%08x]\n",@$t5
.foreach /pS 1 /ps 100 (place {!dd @$t9 + @$t4 * @@c++(sizeof(INT64)) l1 } ) {r $t10 = ( place & 0xfffff000 ) ; !db ( place & 0xfffff000) }

样本运行的输出

lkd> $$>a< .\scripts\splitva.txt msgbox.exe 403000
Page Directory Index        0
Page Directory Entry Index  2
Page Table Entry Index      3
Offset                      0
Implicit process is now 86389020
Loading User Symbols
..........
00403000  49 63 7a 65 6c 69 6f 6e-27 73 20 74 75 74 6f 72  Iczelion's tutor
00403010  69 61 6c 20 6e 6f 2e 32-00 57 69 6e 33 32 20 41  ial no.2.Win32 A
00403020  73 73 65 6d 62 6c 79 20-69 73 20 47 72 65 61 74  ssembly is Great
00403030  21 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  !...............
00403040  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
00403050  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
00403060  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
00403070  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
printing PDINDEX[00000000]
#11800480 387a9001
printing PDEINDEX[00000002]
#387a9000 297b9067
printing PTEINDEX[00000003]
#1b6b7000 3dcb8025
printing Offset[00000000]
#1bb2e000 49 63 7a 65 6c 69 6f 6e-27 73 20 74 75 74 6f 72 Iczelion's tutor
#1bb2e010 69 61 6c 20 6e 6f 2e 32-00 57 69 6e 33 32 20 41 ial no.2.Win32 A
#1bb2e020 73 73 65 6d 62 6c 79 20-69 73 20 47 72 65 61 74 ssembly is Great
#1bb2e030 21 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 !...............
#1bb2e040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
#1bb2e050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
#1bb2e060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
#1bb2e070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

要回答您的另一个问题,可以通过 cpuid 叶找到 maxphyaddr 和 AMD 对应物,但重要的是要注意 MCH 的总线接口(这些天通常集成在 cpu 上)可能只使用这些线路中的 33-36地址总线。