void RelocationTable::setRelocationSection(){ ASSERT(elfFile); ASSERT(elfFile->getSectionHeader(getSectionIndex())); SectionHeader* sh = elfFile->getSectionHeader(getSectionIndex()); ASSERT(elfFile->getRawSection(sh->GET(sh_info))); RawSection* rs = elfFile->getRawSection(sh->GET(sh_info)); relocationSection = rs; }
void RelocationTable::setSymbolTable(){ ASSERT(elfFile); ASSERT(elfFile->getSectionHeader(getSectionIndex())); SectionHeader* sh = elfFile->getSectionHeader(getSectionIndex()); ASSERT(elfFile->getRawSection(sh->GET(sh_link))); RawSection* sy = elfFile->getRawSection(sh->GET(sh_link)); ASSERT(sy->getType() == PebilClassType_SymbolTable); symbolTable = (SymbolTable*)sy; }
void SymbolTable::setStringTable(){ ASSERT(elfFile); ASSERT(elfFile->getSectionHeader(getSectionIndex())); SectionHeader* sh = elfFile->getSectionHeader(getSectionIndex()); ASSERT(elfFile->getRawSection(sh->GET(sh_link))); RawSection* st = elfFile->getRawSection(sh->GET(sh_link)); ASSERT(st->getType() == PebilClassType_StringTable); stringTable = (StringTable*)st; ASSERT(stringTable); }
void SymbolTable::print(){ char tmpstr[__MAX_STRING_SIZE]; PRINT_INFOR("SymbolTable : %d aka sect %d with %d symbols",index,getSectionIndex(),symbols.size()); PRINT_INFOR("\tdyn? : %s", isDynamic() ? "yes" : "no"); for (uint32_t i = 0; i < symbols.size(); i++){ symbols[i]->print(); } }
void RelocationTable::print(){ PRINT_INFOR("RelocTable : %d aka sect %d with %d relocations",index,getSectionIndex(),relocations.size()); PRINT_INFOR("\tadd? : %s", type == ElfRelType_rela ? "yes" : "no"); PRINT_INFOR("\tsect : %d", elfFile->getSectionHeader(getSectionIndex())->GET(sh_info)); PRINT_INFOR("\tstbs : %d", elfFile->getSectionHeader(getSectionIndex())->GET(sh_link)); ASSERT(elfFile->getSectionHeader(getSectionIndex()) && "Section header doesn't exist"); for (uint32_t i = 0; i < relocations.size(); i++){ char* namestr = NULL; Symbol* foundsymbols[3]; for (uint32_t j = 0; j < 3; j++){ foundsymbols[j] = NULL; } symbolTable->findSymbol4Addr(relocations[i]->GET(r_offset),foundsymbols,3,&namestr); relocations[i]->print(namestr); for (uint32_t j = 0; j < 3; j++){ if (foundsymbols[j]){ foundsymbols[j]->print(); } } delete[] namestr; } }
int SP_NKIniFile :: getSection( const char * section, SP_NKStringList * list ) const { int index = getSectionIndex( section ); if( index < 0 ) return -1; for( int i = index + 1; i < mFile->getCount(); i++ ) { const char * line = mFile->getItem(i); if( '[' == line[0] ) break; list->append( line ); } return 0; }
const char * SP_NKIniFile :: getRawValue( const char * section, const char * key, char * value, size_t size ) const { *value = '\0'; int index = getSectionIndex( section ); if( index < 0 ) return NULL; const char * ret = NULL; size_t keyLen = strlen( key ); for( int i = index + 1; i < mFile->getCount(); i++ ) { const char * line = mFile->getItem(i); if( ';' == line[0] || '#' == line[0] || isspace( line[0] ) ) continue; if( '[' == line[0] ) break; if( 0 == strncmp( line, key, keyLen ) ) { char * pos = (char*)line + keyLen; if( isspace( *pos ) || '=' == *pos ) { pos = strchr( pos, '=' ); if( NULL == pos ) { *value = '\0'; } else { // remove leading space for( pos++; isspace( *pos ); ) pos++; SP_NKStr::strlcpy( value, pos, size ); pos = strchr( value, '\0' ); // remove tailing space for( ; pos > value && isspace( *( pos - 1 ) ); ) pos--; *pos = '\0'; } ret = value; } } } return ret; }
int SP_NKIniFile :: getKeyNameList( const char * section, SP_NKStringList * list ) const { int index = getSectionIndex( section ); if( index < 0 ) return -1; for( int i = index + 1; i < mFile->getCount(); i++ ) { const char * line = mFile->getItem(i); if( ';' == line[0] || '#' == line[0] || isspace( line[0] ) ) continue; if( '[' == line[0] ) break; const char * end = strchr( line, '=' ); if( NULL == end ) end = strchr( line, '\0' ); // remove tailing space for( ; end > line && isspace( *( end - 1 ) ); ) end--; if( end > line ) list->append( line, end - line ); } return 0; }
SectionHeader* RawSection::getSectionHeader(){ return elfFile->getSectionHeader(getSectionIndex()); }