2013-05-12 56 views
2

我想知道是否有办法监视更改的特定内存区域。我使用的是为了打开一个过程,其使用的内存区域获得集合下面的方法:C#/ WinAPI - 监视内存区域

internal static MemoryProcess OpenProcess(Process process) 
{ 
    IntPtr processHandle = OpenProcess(ProcessAccess.Desided, true, (UInt32)process.Id); 

    if (processHandle == IntPtr.Zero) 
     return null; 

    IntPtr processAddress = new IntPtr(); 
    List<MemoryRegion> memoryRegions = new List<MemoryRegion>(); 

    while (true) 
    { 
     MemoryBasicInformation info = new MemoryBasicInformation(); 

     if (VirtualQueryEx(processHandle, processAddress, out info, MemoryBasicInformation.Size) == 0) 
      break; 

     if (info.Allocation.HasFlag(MemoryAllocation.Commit) && info.Type.HasFlag(MemoryType.Private) && ((info.Protection & MemoryProtection.Readable) != 0) && ((info.Protection & MemoryProtection.Protected) == 0)) 
      memoryRegions.Add(new MemoryRegion(info.BaseAddress, info.RegionSize)); 

     processAddress = new IntPtr(info.BaseAddress.ToInt64() + info.RegionSize.ToInt64()); 
    } 

    if (memoryRegions.Count == 0) 
    { 
     CloseHandle(processHandle); 
     return null; 
    } 

    return (new MemoryProcess(processHandle, memoryRegions)); 
} 

我看到了很多这样的应用程序。作弊引擎就是其中之一。比方说,我打开谷歌浏览器选项卡的过程,我又把它的记忆中搜索,找到一个特定的值(字符串“计算器”):

enter image description here

现在,我使用该选项卡浏览另一个完全不同的,网站,我看到那些地址值发生变化:

enter image description here

最后一步:我关闭Chrome标签杀死其相应的过程:

enter image description here

所以...当然,必须有一种内存区域的监视。而且,事实上,有:

enter image description here

使用Process.Exited事件是不够的,实现了实时的内存更新解决我觉得值......所以,我该怎么办呢?

+0

我很确定你不能直接使用.NET。你可能可以通过interop来使用Win32 API,但AFAIK没有这种API的.NET API。 – jugg1es 2013-05-12 05:09:36

回答

1

如果你可以拦截称为目标应用VirtualAlloc,并结合MEM_WRITE_WATCH原来的标志,系统将跟踪该分配的内存区域,那么你可以调用GetWriteWatch函数来检索已写入页的地址因为该区域已被分配或写入跟踪状态已被重置。这看起来很多工作要做。