Skip to content

Instantly share code, notes, and snippets.

@Artem-B
Created February 5, 2021 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Artem-B/b7bc53d6f74a673d11570a9df6ba9b45 to your computer and use it in GitHub Desktop.
Save Artem-B/b7bc53d6f74a673d11570a9df6ba9b45 to your computer and use it in GitHub Desktop.
/* Search in terms of symbol name and section name */
bool Elf::get_symbol(const std::string& name, const std::string& section_name,
Elf64_Addr& value, Elf_Xword& size, unsigned char& bind,
unsigned char& type, Elf_Half& section_index,
unsigned char& other) const {
bool ret = false;
symbol_section_accessor symbol_reader(_elfio, _elfio.sections[_symtab_ndx]);
// Opportunistic lookup, in case the name is unique.
if (symbol_reader.get_symbol(name, value, size, bind, type, section_index,
other)) {
if (section_name == _elfio.sections[section_index]->get_name())
return true;
}
for (Elf_Xword i = 0; i < symbol_reader.get_symbols_num() && !ret; i++) {
std::string symbol_name;
if (symbol_reader.get_symbol(i, symbol_name, value, size, bind, type,
section_index, other)) {
if (symbol_name == name &&
section_name == _elfio.sections[section_index]->get_name()) {
return true;
}
}
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment