#include "ElfReader.hpp" #include "elfinfo/elfinfo.h" #include "sal/SALConfig.hpp" #include #include #include "Demangler.hpp" namespace fail { const std::string ElfReader::NOTFOUND = "[ELFReader] Function not found."; void ElfReader::setup(const char* path) { // Try to open the ELF file FILE * fp = fopen(path, "r"); if (!fp) { m_log << "Error: Could not open " << path << std::endl; return; } // Evaluate headers Elf32_Ehdr ehdr; Elf32_Shdr sec_hdr; int num_hdrs,i; fseek(fp,(off_t)0,SEEK_SET); read_ELF_file_header(fp, &ehdr); num_hdrs=ehdr.e_shnum; m_log << "Evaluating ELF File: " << path << std::endl; // Parse symbol table and generate internal map for(i=0;isecond; } } #endif #ifndef __puma std::string ElfReader::getName(const bimap_t& map, guest_address_t address){ // .right switches key/value typedef bimap_t::right_map::const_iterator const_iterator_t; const_iterator_t iterator = map.right.find(address); if(iterator != map.right.end()){ return iterator->second; } return NOTFOUND; } std::string ElfReader::getNameByAddress(guest_address_t address) { std::string res = getName(m_bimap_demangled, address); if(res == NOTFOUND){ return getName(m_bimap_mangled, address); } return res; } std::string ElfReader::getMangledNameByAddress(guest_address_t address) { return getName(m_bimap_mangled, address); } std::string ElfReader::getDemangledNameByAddress(guest_address_t address) { return getName(m_bimap_demangled, address); } void ElfReader::printDemangled(){ print_map(m_bimap_demangled.right); // print Address as first element } void ElfReader::printMangled(){ print_map(m_bimap_mangled.right); // print Address as first element } #endif } // end-of-namespace fail