简体   繁体   English

Memory 扫描仪总是返回相同的结果

[英]Memory scanner always returning the same results

With this code I guess the scan was faster, but the scan always return the SAME address.使用此代码我猜扫描速度更快,但扫描总是返回相同的地址。

EG:例如:

00123456
00124567
00135478
00145893
00123456 //start repeat 
00124567
00135478
00145893
00123456 //start repeat 
00124567
00135478
00145893

This is my procedure:这是我的程序:

procedure SCANBYTE(value: integer);
var
 lpflOldProtect: dword;
 s: size_t;
 mbi: MEMORY_BASIC_INFORMATION;
 SI: SYSTEM_INFO;
 lpStartAddress, lpStopAddress: dword;
 addr: dword;
 i: dword;
begin
 GetSystemInfo(si);
 lpStartAddress := dword(SI.lpMinimumApplicationAddress);
 lpStopAddress := dword(SI.lpMaximumApplicationAddress);
 for addr := lpStartAddress to lpStopAddress do begin
  S:= VirtualQuery(Pointer(addr), MBI, SizeOf(MEMORY_BASIC_INFORMATION));
  if (S=SizeOf(MEMORY_BASIC_INFORMATION)) and (MBI.State = MEM_COMMIT) and (MBI.Type_9 = MEM_PRIVATE) and (MBI.RegionSize>0) and (MBI.Protect = PAGE_READWRITE) then begin
   for i := dword(MBI.BaseAddress) to (dword(MBI.BaseAddress) + dword(MBI.RegionSize)) - 4096 do begin
     if value = PBYTE(i)^ then ListBox1.Items.Add(IntToHex(i,8));
   end;
  end;
 end;
end;

I guess the problem is at the last FOR loop:我想问题出在最后一个 FOR 循环中:

(...)
for i := dword(MBI.BaseAddress) to (dword(MBI.BaseAddress) + dword(MBI.RegionSize)) - 4096 do begin
(...)

But I really don't know.. How can I solve this?但我真的不知道..我该如何解决这个问题?

You run your code in a loop from the start address to the end address.您在从起始地址到结束地址的循环中运行代码。 The address addr increases by 1 each time around the loop.地址addr每循环一次就加1 VirtualQuery gives you information about entire pages. VirtualQuery为您提供有关整个页面的信息。 All the addresses in a page have the same base address.页中的所有地址都具有相同的基地址。 The documentation tells you, "This value is rounded down to the next page boundary." 文档告诉您,“此值向下舍入到下一页边界。”

Look more closely, and you should see that mbi.BaseAddress remains the same for 4096 iterations of your outer loop (assuming 4096 is the page size).仔细观察,您应该看到mbi.BaseAddress在外循环的 4096 次迭代中保持不变(假设页面大小为 4096)。 Thus, you're re-scanning the same block of memory over and over again.因此,您将一遍又一遍地重新扫描 memory 的同一块。 (That might also explain why your code is slow .) (这也可以解释为什么你的代码很慢。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM