Home > C++, VC++, Windows API > Enumerating symbols in a module!

Enumerating symbols in a module!

We can enumerate symbols in a module use dbghelp API’s provided by Microsoft. Make sure you link with dbghelp.lib.

Here is a demo… 🙂

// Open a process for enumeration
HANDLE hProcessHandle = ::OpenProcess( PROCESS_ALL_ACCESS, 
				  dwProcId );   

// Initialize process for enumerating debug symbols
if( !hProcessHandle || !SymInitialize( hProcessHandle, 0, TRUE ))

// Note that you need to enumerate each module in
// the process and pass it's dll base to this function
VERIFY( SymEnumerateSymbols( hProcessHandle,
                             lpSomeCustomParam )); 

// Don't forget to call SymCleanup
VERIFY( SymCleanup( hProcessHandle ));
CloseHandle( hProcessHandle );

// Now after above function call this function will
// be invoked, passing in the name and other info
// of a single symbol in a module
BOOL EnumSymbolsCB( LPSTR lpszSymbolName_i,
                    ULONG /*ulSymbolAddress_i*/,
                    ULONG /*ulSymbolSize_i*/,
                    LPVOID /*lpvdUserContext_i*/ )
    // Trace out symbol name      

    CString csSymbolName = lpszSymbolName_i;
    AfxTrace( csSymbolName );
    AfxTrace( _T( "n" ));  

    // We want more callbacks
    return TRUE;
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: