我正在关注这个关于如何用 C 语言制作内存扫描器的简单教程。出于某种原因,我的主循环永远不会中断。
这是代码
MEMBLOCK* create_scan(unsigned int pid){
MEMBLOCK *mb_list = NULL;
MEMORY_BASIC_INFORMATION meminfo;
unsigned char *addr = 0;
HANDLE hProc = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
if(hProc){
while(1){
// print the address for debug purpose
printf("%d \r\n", addr);
// loop should break out when the address overflows (return 0)
if(VirtualQueryEx (hProc, addr, &meminfo, sizeof(meminfo)) == 0){
break;
}
#define WRITABLE (PAGE_READWRITE | PAGE_WRITECOPY |PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)
if ((meminfo.State & MEM_COMMIT) && (meminfo.Protect & WRITABLE)){
MEMBLOCK *mb = create_memblock (hProc, &meminfo);
if(mb){
mb->next = mb_list;
mb_list = mb;
}
}
addr = (unsigned char*)meminfo.BaseAddress + meminfo.RegionSize;
}
}
return mb_list;
}
由于某种原因,输出(printf)是这样的
123863040
125943808
... until ...
2147418112
... all on the sudden ...
-1207959552
...
-243924992
0
65536
loop start again
任何想法,我有点迷路了!