ELFSectionStrTab.hxx revision 00e067ef50c860668ed67003309d5ae71aa02b32
1#ifndef ELF_SECTION_STR_TAB_HXX 2#define ELF_SECTION_STR_TAB_HXX 3 4#include "utils/helper.h" 5#include "utils/raw_ostream.h" 6 7#include <llvm/ADT/OwningPtr.h> 8#include <llvm/Support/Format.h> 9#include <llvm/Support/raw_ostream.h> 10 11template <unsigned Bitwidth> 12template <typename Archiver> 13ELFSectionStrTab<Bitwidth> * 14ELFSectionStrTab<Bitwidth>::read(Archiver &AR, 15 ELFSectionHeaderTy const *sh) { 16 17 llvm::OwningPtr<ELFSectionStrTab> st(new ELFSectionStrTab()); 18 st->buf.resize(sh->getSize()); 19 20 // Save section_header 21 st->section_header = sh; 22 23 AR.seek(sh->getOffset(), true); 24 AR.prologue(sh->getSize()); 25 AR.readBytes(&*st->buf.begin(), sh->getSize()); 26 AR.epilogue(sh->getSize()); 27 28 if (!AR) { 29 // Unable to read the string table. 30 return 0; 31 } 32 33 return st.take(); 34} 35 36template <unsigned Bitwidth> 37void ELFSectionStrTab<Bitwidth>::print() const { 38 using namespace llvm; 39 40 out() << '\n' << fillformat('=', 79) << '\n'; 41 out().changeColor(raw_ostream::WHITE, true); 42 out() << "ELF String Table: " << this->section_header->getName() << '\n'; 43 out().resetColor(); 44 out() << fillformat('-', 79) << '\n'; 45 46 dump_hex((unsigned char const *)&*buf.begin(), buf.size(), 0, buf.size()); 47 48 out() << fillformat('=', 79) << '\n'; 49} 50 51#endif // ELF_SECTION_STR_TAB_HXX 52