#include "stdafx.h"
#include <WINDOWS.H>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
printf("处理器个数: %d\n",systemInfo.dwNumberOfProcessors);
printf("处理器分页大小: %d\n",systemInfo.dwPageSize);
printf("最小寻址单元: %.8X\n",systemInfo.lpMinimumApplicationAddress);
printf("最大寻址单元: %.8X\n",systemInfo.lpMaximumApplicationAddress);
DWORD dwPid = 1992;//进程id
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,0,dwPid);
MEMORY_BASIC_INFORMATION stuMemoryInfo;
LPCVOID addr = systemInfo.lpMinimumApplicationAddress;
vector<MEMORY_BASIC_INFORMATION> list;
while(addr < systemInfo.lpMaximumApplicationAddress)
{
VirtualQueryEx(hProcess,addr,&stuMemoryInfo,sizeof(stuMemoryInfo));
list.push_back(stuMemoryInfo);
addr = (LPCVOID) ((DWORD)addr+stuMemoryInfo.RegionSize);
}
//TODO循环填充到list控件中
for (int i=0;i<list.size();i++)
{
char stateBuff[20] = {0};
if(list[i].State == MEM_COMMIT)
{
wsprintf(stateBuff,"COMMIT");
}
else if(list[i].State == MEM_FREE)
{
wsprintf(stateBuff,"MEM_FREE");
}
else if(list[i].State == MEM_RESERVE)
{
wsprintf(stateBuff,"MEM_RESERVE");
}
else
{
wsprintf(stateBuff,"------");
}
printf("%.8X\t%.8X\t%s \n",list[i].BaseAddress,list[i].AllocationBase,stateBuff);
}
getchar();
CloseHandle(hProcess);
return 0;
}
/*
MEMORY_BASIC_INFORMATION结构体属性
PVOID BaseAddress; 块基地址 粒度4KB
PVOID AllocationBase; 区域基地址 粒度64KB
DWORD AllocationProtect; 区域被初次保留时赋予的保护属性 读 写 执行
SIZE_T RegionSize; 从BaseAddress开始,具有相同属性的页面的大小 按照4KB对齐
DWORD State; 块属性 MEM_FREE MEM_RESERVE MEM_COMMIT
DWORD Protect; 页面的属性,其可能的取值与AllocationProtect相同
DWORD Type; 内存区域类型 私有MEM_PRIVATE 映像MEM_IMAGE已映射MEM_MAPPED
*/
初识内存,打印进程内存分布
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...