1ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao/* 2ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * Copyright 2011, The Android Open Source Project 3ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * 4ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * Licensed under the Apache License, Version 2.0 (the "License"); 5ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * you may not use this file except in compliance with the License. 6ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * You may obtain a copy of the License at 7ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * 8ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * http://www.apache.org/licenses/LICENSE-2.0 9ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * 10ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * Unless required by applicable law or agreed to in writing, software 11ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * distributed under the License is distributed on an "AS IS" BASIS, 12ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * See the License for the specific language governing permissions and 14ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao * limitations under the License. 15ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao */ 16ee6cdb95525abc8c7766798148302306a100b774Shih-wei Liao 178e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#ifndef ELF_SECTION_STR_TAB_HXX 188e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#define ELF_SECTION_STR_TAB_HXX 198e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 208e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#include "utils/helper.h" 218e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#include "utils/raw_ostream.h" 228e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 238e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#include <llvm/ADT/OwningPtr.h> 248e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#include <llvm/Support/Format.h> 258e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#include <llvm/Support/raw_ostream.h> 268e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 278e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chientemplate <unsigned Bitwidth> 288e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chientemplate <typename Archiver> 298e233aace27dd4c658db39ddd223bdc21121a4f2Logan ChienELFSectionStrTab<Bitwidth> * 308e233aace27dd4c658db39ddd223bdc21121a4f2Logan ChienELFSectionStrTab<Bitwidth>::read(Archiver &AR, 3158611fc8193e7386698178f167a2e0cbdd6a4f6fLogan Chien ELFSectionHeaderTy const *sh) { 328e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 338e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien llvm::OwningPtr<ELFSectionStrTab> st(new ELFSectionStrTab()); 348e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien st->buf.resize(sh->getSize()); 358e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 368e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien // Save section_header 378e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien st->section_header = sh; 388e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 398e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien AR.seek(sh->getOffset(), true); 408e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien AR.prologue(sh->getSize()); 4100e067ef50c860668ed67003309d5ae71aa02b32Logan Chien AR.readBytes(&*st->buf.begin(), sh->getSize()); 428e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien AR.epilogue(sh->getSize()); 438e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 448e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien if (!AR) { 458e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien // Unable to read the string table. 468e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien return 0; 478e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien } 488e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 498e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien return st.take(); 508e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien} 518e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 528e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chientemplate <unsigned Bitwidth> 538e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chienvoid ELFSectionStrTab<Bitwidth>::print() const { 548e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien using namespace llvm; 558e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 568e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien out() << '\n' << fillformat('=', 79) << '\n'; 578e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien out().changeColor(raw_ostream::WHITE, true); 588e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien out() << "ELF String Table: " << this->section_header->getName() << '\n'; 598e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien out().resetColor(); 608e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien out() << fillformat('-', 79) << '\n'; 618e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 628e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien dump_hex((unsigned char const *)&*buf.begin(), buf.size(), 0, buf.size()); 638e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 648e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien out() << fillformat('=', 79) << '\n'; 658e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien} 668e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien 678e233aace27dd4c658db39ddd223bdc21121a4f2Logan Chien#endif // ELF_SECTION_STR_TAB_HXX 68