找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 6683|回复: 5

[悬赏]如何在64位系统下检验内核地址有效性?【已解决】

[复制链接]

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
发表于 2012-8-29 19:23:27 | 显示全部楼层 |阅读模式
MmIsAddressValid有时不管用,是人人皆知的事情。
不少高手都说:基本没有绝对有效的方法。
那么,大家有没有比较有效的办法呢?

需求:
一个校验地址有效性的函数,能像WINDBG一样,访问任何地址都不会蓝屏。

奖励:
终身核心会员 + 10000水晶币。

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
 楼主| 发表于 2012-8-31 01:06:52 | 显示全部楼层
已经自己解决了:
  1. BOOLEAN IsAddressSafe(UINT_PTR StartAddress)
  2. {
  3. #ifdef AMD64
  4.         //cannonical check. Bits 48 to 63 must match bit 47
  5.         UINT_PTR toppart=(StartAddress >> 47);
  6.         if (toppart & 1)
  7.         {
  8.                 //toppart must be 0x1ffff
  9.                 if (toppart != 0x1ffff)
  10.                         return FALSE;
  11.         }
  12.         else
  13.         {
  14.                 //toppart must be 0
  15.                 if (toppart != 0)
  16.                         return FALSE;

  17.         }
  18. #endif
  19.         {
  20. #ifdef AMD64
  21.                 UINT_PTR kernelbase=0x7fffffffffffffffULL;
  22.                 if (StartAddress<kernelbase)
  23.                         return TRUE;
  24.                 else
  25.                 {
  26.                         PHYSICAL_ADDRESS physical;
  27.                         physical.QuadPart=0;
  28.                         physical=MmGetPhysicalAddress((PVOID)StartAddress);
  29.                         return (physical.QuadPart!=0);
  30.                 }
  31.                 return TRUE; //for now untill I ave figure out the win 4 paging scheme
  32. #else
  33.                 /*        MDL x;


  34.                         MmProbeAndLockPages(&x,KernelMode,IoModifyAccess);


  35.                         MmUnlockPages(&x);
  36.                         */
  37.                 ULONG kernelbase=0x7ffe0000;
  38.                 if ((!HiddenDriver) && (StartAddress<kernelbase))
  39.                         return TRUE;
  40.                 {
  41.                         UINT_PTR PTE,PDE;
  42.                         struct PTEStruct *x;
  43.                         /*
  44.                         PHYSICAL_ADDRESS physical;
  45.                         physical=MmGetPhysicalAddress((PVOID)StartAddress);
  46.                         return (physical.QuadPart!=0);*/
  47.                         PTE=(UINT_PTR)StartAddress;
  48.                         PTE=PTE/0x1000*PTESize+0xc0000000;
  49.                         //now check if the address in PTE is valid by checking the page table directory at 0xc0300000 (same location as CR3 btw)
  50.                         PDE=PTE/0x1000*PTESize+0xc0000000; //same formula
  51.                         x=(PVOID)PDE;
  52.                         if ((x->P==0) && (x->A2==0))
  53.                         {
  54.                                 //Not present or paged, and since paging in this area isn't such a smart thing to do just skip it
  55.                                 //perhaps this is only for the 4 mb pages, but those should never be paged out, so it should be 1
  56.                                 //bah, I've got no idea what this is used for
  57.                                 return FALSE;
  58.                         }
  59.                         if (x->PS==1)
  60.                         {
  61.                                 //This is a 4 MB page (no pte list)
  62.                                 //so, (startaddress/0x400000*0x400000) till ((startaddress/0x400000*0x400000)+(0x400000-1) ) ) is specified by this page
  63.                         }
  64.                         else //if it's not a 4 MB page then check the PTE
  65.                         {
  66.                                 //still here so the page table directory agreed that it is a usable page table entry
  67.                                 x=(PVOID)PTE;
  68.                                 if ((x->P==0) && (x->A2==0))
  69.                                         return FALSE; //see for explenation the part of the PDE
  70.                         }
  71.                         return TRUE;
  72.                 }
  73. #endif
  74.         }
  75. }
复制代码
代码来自CheatEngine。
利用此函数和MmIsAddressValid进行两次判断,在正常模式下暂时未发现误判断。
最后,感谢ithurricane大牛提供线索。

1

主题

19

回帖

0

精华

铜牌会员

积分
47
发表于 2012-9-9 12:56:54 | 显示全部楼层
win64下这么麻烦?

0

主题

11

回帖

0

精华

铜牌会员

积分
45
发表于 2012-9-27 18:46:42 | 显示全部楼层
可惜了来晚了,不然就可以是终身会员了。。。

7

主题

414

回帖

1

精华

铂金会员

积分
2173
发表于 2013-4-7 22:00:33 | 显示全部楼层
支持!!

0

主题

6

回帖

0

精华

初来乍到

积分
22
发表于 2017-12-9 13:54:00 | 显示全部楼层
好东西
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表