static DWORD64 __stdcall GetModBase ( HANDLE hProcess , DWORD64 dwAddr ) #endif { // Check in the symbol engine first. IMAGEHLP_MODULE stIHM ; // This is what the MFC stack trace routines forgot to do so their // code will not get the info out of the symbol engine. stIHM.SizeOfStruct = sizeof ( IMAGEHLP_MODULE ) ; if ( g_cSym.SymGetModuleInfo ( dwAddr , &stIHM ) ) { return ( stIHM.BaseOfImage ) ; } else { // Let's go fishing. MEMORY_BASIC_INFORMATION stMBI ; if ( 0 != VirtualQueryEx ( hProcess , (LPCVOID)dwAddr , &stMBI , sizeof ( stMBI ) ) ) { // Try and load it. DWORD dwNameLen = 0 ; TCHAR szFile[ MAX_PATH ] ; dwNameLen = GetModuleFileName ( (HINSTANCE) stMBI.AllocationBase , szFile , MAX_PATH ); HANDLE hFile = NULL ; if ( 0 != dwNameLen ) { hFile = CreateFile ( szFile , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , 0 , 0 ) ; } g_cSym.SymLoadModule ( hFile , ( dwNameLen ? szFile : NULL ) , NULL , (DWORD)stMBI.AllocationBase , 0 ) ; return ( (DWORD)stMBI.AllocationBase ) ; } } return ( 0 ) ; }
static DWORD __stdcall GetModBase ( HANDLE hProcess , DWORD dwAddr ) { // Check in the symbol engine first. IMAGEHLP_MODULE stIHM ; // This is what the MFC stack trace routines forgot to do so their // code will not get the info out of the symbol engine. stIHM.SizeOfStruct = sizeof ( IMAGEHLP_MODULE ) ; // Check to see if the module is already loaded. if ( g_cSym.SymGetModuleInfo ( dwAddr , &stIHM ) ) { return ( stIHM.BaseOfImage ) ; } else { // The module is not loaded, so let's go fishing. MEMORY_BASIC_INFORMATION stMBI ; // Do the VirtualQueryEx to see if I can find the start of // this module. Since the HMODULE is the start of a module // in memory, viola, this will give me the HMODULE. if ( 0 != VirtualQueryEx ( hProcess , (LPCVOID)dwAddr , &stMBI , sizeof ( stMBI ) ) ) { // Try and load it. DWORD dwNameLen = 0 ; TCHAR szFile[ MAX_PATH ] ; // Using the address base for the memory location, try // to grab the module filename. dwNameLen = GetModuleFileName ( (HINSTANCE) stMBI.AllocationBase , szFile , MAX_PATH ); HANDLE hFile = NULL ; if ( 0 != dwNameLen ) { // Very cool, I found the DLL. Now open it up for // reading. hFile = CreateFile ( szFile , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , 0 , 0 ) ; } // Go ahead and try to load the module anyway. #ifdef _DEBUG DWORD dwRet = #endif g_cSym.SymLoadModule ( hFile , ( dwNameLen ? szFile : NULL ) , NULL , (DWORD)stMBI.AllocationBase , 0 ) ; #ifdef _DEBUG if ( 0 == dwRet ) { TRACE ( "SymLoadModule failed : 0x%08X\n" , GetLastError ( ) ) ; } #endif // _DEBUG return ( (DWORD)stMBI.AllocationBase ) ; } } return ( 0 ) ; }