GetModuleInfo Function

Please any example to use this function
1
2
3
4
5
6
7
8
9
10
MODULEINFO GetModuleInfo(char * szModule)
{
MODULEINFO modinfo = {0};
HMODULE hModule = GetModuleHandle (szModule);
if(hModule == 0)

GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
return modinfo;

}


and how can print modinfo ?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <windows.h>
#include <psapi.h>

bool GetModuleInfo( const char* szModule, MODULEINFO& modinfo )
{
    const HMODULE hModule = GetModuleHandle(szModule);

    if( hModule != 0 && GetModuleInformation( GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO) ) )
            return true ;

    modinfo = {} ; // failed to get module information
    return false ;
}

void print_module_info( const char* szModule )
{
    if( szModule == nullptr ) return ;

    MODULEINFO minfo{} ;
    if( GetModuleInfo( szModule, minfo ) )
    {
        std::cout << "module '" << szModule
                  << "'\n\tbase address: " << minfo.lpBaseOfDll << '\n'
                  << "\timage size: " << minfo.SizeOfImage << " bytes\n"
                  << "\tentry point: " << minfo.EntryPoint << '\n' ;
    }
    else std::cerr << "failed to get module info for module '" << szModule << "'\n" ;
}

int main() 
{
    print_module_info( "kernel32.dll" ) ;
}
Thanks so much , but if i change "kernel32.dll" to game name got error "failed to get module info for module "

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <windows.h>
#include <psapi.h>

bool GetModuleInfo( const char* szModule, MODULEINFO& modinfo )
{
    const HMODULE hModule = GetModuleHandle(szModule);

    if( hModule != 0 && GetModuleInformation( GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO) ) )
            return true ;

    modinfo = {} ; // failed to get module information
    return false ;
}

void print_module_info( const char* szModule )
{
    if( szModule == nullptr ) return ;

    MODULEINFO minfo{} ;
    if( GetModuleInfo( szModule, minfo ) )
    {
        std::cout << "module '" << szModule
                  << "'\n\tbase address: " << minfo.lpBaseOfDll << '\n'
                  << "\timage size: " << minfo.SizeOfImage << " bytes\n"
                  << "\tentry point: " << minfo.EntryPoint << '\n' ;
    }
    else std::cerr << "failed to get module info for module '" << szModule << "'\n" ;
}

int main()
{
    print_module_info( "ac_client.exe" ) ;
}
Topic archived. No new replies allowed.