Lists information about modules loaded by this program.

Source: Internet
Author: User
List one of Windows core programming languagesProgramLoaded module information
Author: Jimmy
ArticleNature: original
Released on: 2004-02 2
MessageBox (getactivewindow (), "list DLL files loaded by this program", "", mb_ OK );

Memory_basic_information MBI;
Pbyte PTR = NULL;
DWORD dwbytesreturn = sizeof (memory_basic_information );

Char szbuffer [256*100] = "";
Char szmodufile [240] = "";
Char sztmpbuffer [256] = "";

While (dwbytesreturn = sizeof (memory_basic_information ))
{
Dwbytesreturn = virtualquery (PTR, & MBI, sizeof (memory_basic_information ));

If (MBI. type = mem_free)
{
MBI. allocationbase = MBI. baseaddress;
}

Getmodulefilename (hinstance) MBI. allocationbase, szmodufile, 240 );

Sprintf (sztmpbuffer, "[module: % x-% s]/R/N", MBI. allocationbase, szmodufile );

If (MBI. allocationbase = MBI. baseaddress &&
MBI. allocationbase! = NULL &&
MBI. allocationbase! = Getmodulehandle (null) strcat (szbuffer, sztmpbuffer );
PTR + = MBI. regionsize;
}
// Add yourCode, Put the generated information into an editing box for viewing, or store the file

Technical introduction to the program

Virtualquery is easy to get memory information

Typedef struct _ memory_basic_information {// MBI
Pvoid baseaddress; // base address of Region
Pvoid allocationbase; // allocation base address
DWORD allocationprotect; // initial access protection
DWORD regionsize; // size, in bytes, of Region
DWORD state; // committed, reserved, free
DWORD protect; // current access protection
DWORD type; // type of pages
} Memory_basic_information;
Typedef memory_basic_information * pmemory_basic_information;

This structure, in our program, is most concerned with allocationbase, baseaddress can be seen from the code

Allocationbase is equivalent to hmodule.

Regionsize indicates the size of the memory.
PTR + = MBI. regionsize;
Let's get the information of the next memory block.

Through getmodulefilename, we get the detailed information of the module.

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.