Call WINAPI Query Memory information

Source: Internet
Author: User
Tags include memory usage printf

pnig0s1992:

Lists current system information, current system memory status.

Enumerate processes that list the page types, page properties, and protection properties of all memory blocks in each process

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 (&AMP;SI); 
    printf ("\ n current memory page size%UKB", si.dwpagesize/1024); 
    printf ("\ n is less than 0x%x for system retention.", si.lpminimumapplicationaddress); 
    printf ("\ n is greater than 0x%x is the system kernel area.", si.lpmaximumapplicationaddress); 
    printf ("\ncpu Quantity:%u", si.dwnumberofprocessors); 
    GlobalMemoryStatus (&AMP;MS); 
    printf ("\ n current system memory usage:%u%%:", ms.dwmemoryload); 
    printf ("\ n current system Total Physical memory:%uM", ms.dwtotalphys/1024/1024); 
    printf ("\ n current system available physical memory:%uM", ms.dwavailphys/1024/1024); 
    printf ("\ n current system total virtual memory:%uM", ms.dwtotalvirtual/1024/1024); 
    printf ("\ n current system available virtual memory:%uM", ms.dwavailvirtual/1024/1024); 
    printf ("\ n current system total page file:%uM", ms.dwtotalpagefile/1024/1024); 
    printf ("\ n current system available page files:%uM", ms.dwavailpagefile/1024/1024); PROCESSENTRY32 Pe32; 
    pe32.dwsize = sizeof (PE32); 
    HANDLE Hprocesssnap; 
    Hprocesssnap = CreateToolhelp32Snapshot (th32cs_snapprocess,0); 
        if (Hprocesssnap = = Invalid_handle_value) {printf ("Get process snapshot Failed"); 
    return-1; 
        }else {Process32First (HPROCESSSNAP,&AMP;PE32); 
            do {printf (\ n Current process name:%s pid:%u, PE32.SZEXEFILE,PE32.TH32PROCESSID); if (Pe32.th32processid!= getcurrentprocessid ()) {HANDLE hprocess = openprocess (process_quer y_information| 
                PROCESS_VM_READ,FALSE,PE32.TH32PROCESSID); 
            Getmemoryinfo (si,hprocess); 
    } while (Process32Next (HPROCESSSNAP,&AMP;PE32)); 
    System ("pause"); 
return 0; 
    } VOID getmemoryinfo (system_info si,handle hprocess) {printf ("\ n memory Address Protection property page type"); DWORD Dwcurpos = (DWORD) si.lpminimumapplicationaddress;//First query location is an accessible minimum memory address while (Dwcurpos < (DWORD) si.lpmaximumapplicationaddress)//End condition isMax memory address {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;//current block base address plus block size}}

This article is from the "About:blank h4cking" blog, please be sure to keep this source http://pnig0s1992.blog.51cto.com/393390/807029

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.