示例#1
0
bool ElfReader::LoadSymbols()
{
  bool hasSymbols = false;
  SectionID sec = GetSectionByName(".symtab");
  if (sec != -1)
  {
    int stringSection = sections[sec].sh_link;
    const char* stringBase = (const char*)GetSectionDataPtr(stringSection);

    // We have a symbol table!
    Elf32_Sym* symtab = (Elf32_Sym*)(GetSectionDataPtr(sec));
    int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
    for (int sym = 0; sym < numSymbols; sym++)
    {
      int size = Common::swap32(symtab[sym].st_size);
      if (size == 0)
        continue;

      // int bind = symtab[sym].st_info >> 4;
      int type = symtab[sym].st_info & 0xF;
      int sectionIndex = Common::swap16(symtab[sym].st_shndx);
      int value = Common::swap32(symtab[sym].st_value);
      const char* name = stringBase + Common::swap32(symtab[sym].st_name);
      if (bRelocate)
        value += sectionAddrs[sectionIndex];

      int symtype = Symbol::SYMBOL_DATA;
      switch (type)
      {
      case STT_OBJECT:
        symtype = Symbol::SYMBOL_DATA;
        break;
      case STT_FUNC:
        symtype = Symbol::SYMBOL_FUNCTION;
        break;
      default:
        continue;
      }
      g_symbolDB.AddKnownSymbol(value, size, name, symtype);
      hasSymbols = true;
    }
  }
  g_symbolDB.Index();
  return hasSymbols;
}
示例#2
0
const char *ElfReader::GetSectionName(int section) const
{
	if (sections[section].sh_type == SHT_NULL)
		return NULL;

	int nameOffset = sections[section].sh_name;
	char *ptr = (char*)GetSectionDataPtr(header->e_shstrndx);

	if (ptr)
		return ptr + nameOffset;
	else
		return NULL;
}