BOOL GetOffsetFromSym( LPSTR pString, PULONG pOffset ) { CHAR SuffixedString[256+64]; CHAR Suffix[4]; // // Nobody should be referencing a 1 character symbol! It causes the // rest of us to pay a huge penalty whenever we make a typo. Please // change to 2 character instead of removing this hack! // if ( strlen(pString) == 1 || strlen(pString) == 0 ) { return FALSE; } #ifdef _PPC_ if (CreateDotDotName( SuffixedString, pString, 0 )) { if (SymGetSymFromName( CurrProcess, SuffixedString, sym )) { *pOffset = sym->Address; return TRUE; } } #endif if (SymGetSymFromName( CurrProcess, pString, sym )) { *pOffset = sym->Address; return TRUE; } return FALSE; }
const IMAGEHLP_SYMBOL * KImageModule::ImageGetSymbol(const char * name) { char localname[MAX_PATH]; memset(m_is, 0, sizeof(m_is)); m_is[0].SizeOfStruct = sizeof(IMAGEHLP_SYMBOL); m_is[0].MaxNameLength = sizeof(m_is) - sizeof(m_is[0]); // The silly implementation in imagehlp.dll will try to change the '!' in name // to 0, which generates an access violation, because name would came from read-only // constant data. Make a local copy to solve the problem strcpy(localname, name); if ( SymGetSymFromName(m_hProcess, localname, m_is) ) { // On Win2K RC1, m_is[0].Address is a valid address, m_pidi->ReservedMappedBase=NULL if ( m_symbolbase ) m_is[0].Address += m_imagebase_default - m_symbolbase; return & m_is[0]; } else { DWORD err = GetLastError(); return NULL; } }