Pnig0s1992:
列出当前系统信息,当前系统内存状况。
枚举进程,列出每个进程所有内存块的页面类型,页面属性,保护属性等信息
- //Code by Pnig0s1992
- //Date:2012,3,15
- #include <stdio.h>
- #include <Windows.h>
- #include <TlHelp32.h>
- VOID getMemoryInfo(SYSTEM_INFO si,HANDLE hProcess);
- int main(void)
- {
- SYSTEM_INFO si;
- MEMORYSTATUS ms;
- ms.dwLength = sizeof(ms);
- GetSystemInfo(&si);
- printf("\n当前内存页大小%uKB",si.dwPageSize/1024);
- printf("\n小于0x%x为系统保留区.",si.lpMinimumApplicationAddress);
- printf("\n大于0x%x为系统内核区.",si.lpMaximumApplicationAddress);
- printf("\nCPU数量:%u",si.dwNumberOfProcessors);
- GlobalMemoryStatus(&ms);
- printf("\n当前系统内存使用率:%u%%:",ms.dwMemoryLoad);
- printf("\n当前系统总物理内存:%uM",ms.dwTotalPhys/1024/1024);
- printf("\n当前系统可用物理内存:%uM",ms.dwAvailPhys/1024/1024);
- printf("\n当前系统总虚拟内存:%uM",ms.dwTotalVirtual/1024/1024);
- printf("\n当前系统可用虚拟内存:%uM",ms.dwAvailVirtual/1024/1024);
- printf("\n当前系统总页文件:%uM",ms.dwTotalPageFile/1024/1024);
- printf("\n当前系统可用页文件:%uM",ms.dwAvailPageFile/1024/1024);
- PROCESSENTRY32 pe32;
- pe32.dwSize = sizeof(pe32);
- HANDLE hProcessSnap;
- hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- if(hProcessSnap == INVALID_HANDLE_VALUE)
- {
- printf("\n获取进程快照失败");
- return -1;
- }else
- {
- Process32First(hProcessSnap,&pe32);
- do
- {
- printf("\n当前进程名:%S PID:%u",pe32.szExeFile,pe32.th32ProcessID);
- if(pe32.th32ProcessID != GetCurrentProcessId())
- {
- HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pe32.th32ProcessID);
- getMemoryInfo(si,hProcess);
- }
- } while (Process32Next(hProcessSnap,&pe32));
- }
- system("pause");
- return 0;
- }
- VOID getMemoryInfo(SYSTEM_INFO si,HANDLE hProcess)
- {
- printf("\n内存地址 保护属性 页面类型");
- DWORD dwCurPos = (DWORD)si.lpMinimumApplicationAddress;//第一次查询位置为可访问的最小内存地址
- while(dwCurPos <(DWORD)si.lpMaximumApplicationAddress) //结束条件为最大内存地址
- {
- MEMORY_BASIC_INFORMATION mbi;
- DWORD dwRc = VirtualQueryEx(hProcess,(LPVOID)dwCurPos,&mbi,sizeof(mbi));
- printf("\n0x%x %u %u",mbi.BaseAddress,mbi.AllocationProtect,mbi.Type);
- dwCurPos = (DWORD)mbi.BaseAddress+mbi.RegionSize;//当前块儿基址加块儿大小
- }
- }
本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/807029,如需转载请自行联系原作者