shstr_off = shstr_shdr.get_sh_offset(); shstr_size = shstr_shdr.get_sh_size(); } if (sh_name >= shstr_size) file->error(_("bad section name offset for section %u: %u"), shndx, sh_name); typename File::View v(file->view(shstr_off, shstr_size)); const unsigned char* datau = v.data(); const char* data = reinterpret_cast<const char*>(datau); const void* p = ::memchr(data + sh_name, '\0', shstr_size - sh_name); if (p == NULL) file->error(_("missing null terminator for name of section %u"), shndx); size_t len = static_cast<const char*>(p) - (data + sh_name); return std::string(data + sh_name, len);} // Return the contents of section SHNDX. template<int size, bool big_endian, typename File>typename File::LocationElf_file<size, big_endian, File>::section_contents(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_contents: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return typename File::Location(shdr.get_sh_offset(), shdr.get_sh_size());} // Get the size of section SHNDX. template<int size, bool big_endian, typename File>typename Elf_types<size>::Elf_WXwordElf_file<size, big_endian, File>::section_size(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_size: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_size();} // Return the section flags of section SHNDX. template<int size, bool big_endian, typename File>typename Elf_types<size>::Elf_WXwordElf_file<size, big_endian, File>::section_flags(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_flags: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_flags();} // Return the address of section SHNDX. template<int size, bool big_endian, typename File>typename Elf_types<size>::Elf_AddrElf_file<size, big_endian, File>::section_addr(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_flags: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_addr();} // Return the type of section SHNDX. template<int size, bool big_endian, typename File>Elf_WordElf_file<size, big_endian, File>::section_type(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_type: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_type();} // Return the sh_link field of section SHNDX. template<int size, bool big_endian, typename File>Elf_WordElf_file<size, big_endian, File>::section_link(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_link: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_link();} // Return the sh_info field of section SHNDX. template<int size, bool big_endian, typename File>Elf_WordElf_file<size, big_endian, File>::section_info(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_info: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_info();} // Return the sh_addralign field of section SHNDX. template<int size, bool big_endian, typename File>typename Elf_types<size>::Elf_WXwordElf_file<size, big_endian, File>::section_addralign(unsigned int shndx){ File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_addralign: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_addralign();} inlineElf_strtab::Elf_strtab(const unsigned char* p, size_t size){ // Check if the section is NUL-terminated. If it isn't, we ignore // the last part to make sure we don't return non-NUL-terminated // strings. while (size > 0 && p[size - 1] != 0) size--; this->base_ = reinterpret_cast<const char*>(p); this->usable_size_ = size;} } // End namespace elfcpp. #endif // !defined(ELFCPP_FILE_H)Lines 501–688 of 688. Previous lines
shstr_off = shstr_shdr.get_sh_offset(); shstr_size = shstr_shdr.get_sh_size(); } if (sh_name >= shstr_size) file->error(_("bad section name offset for section %u: %u"), shndx, sh_name); typename File::View v(file->view(shstr_off, shstr_size)); const unsigned char* datau = v.data(); const char* data = reinterpret_cast<const char*>(datau); const void* p = ::memchr(data + sh_name, '\0', shstr_size - sh_name); if (p == NULL) file->error(_("missing null terminator for name of section %u"), shndx); size_t len = static_cast<const char*>(p) - (data + sh_name); return std::string(data + sh_name, len); } // Return the contents of section SHNDX. template<int size, bool big_endian, typename File> typename File::Location Elf_file<size, big_endian, File>::section_contents(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_contents: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return typename File::Location(shdr.get_sh_offset(), shdr.get_sh_size()); } // Get the size of section SHNDX. template<int size, bool big_endian, typename File> typename Elf_types<size>::Elf_WXword Elf_file<size, big_endian, File>::section_size(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_size: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_size(); } // Return the section flags of section SHNDX. template<int size, bool big_endian, typename File> typename Elf_types<size>::Elf_WXword Elf_file<size, big_endian, File>::section_flags(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_flags: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_flags(); } // Return the address of section SHNDX. template<int size, bool big_endian, typename File> typename Elf_types<size>::Elf_Addr Elf_file<size, big_endian, File>::section_addr(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_flags: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_addr(); } // Return the type of section SHNDX. template<int size, bool big_endian, typename File> Elf_Word Elf_file<size, big_endian, File>::section_type(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_type: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_type(); } // Return the sh_link field of section SHNDX. template<int size, bool big_endian, typename File> Elf_Word Elf_file<size, big_endian, File>::section_link(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_link: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_link(); } // Return the sh_info field of section SHNDX. template<int size, bool big_endian, typename File> Elf_Word Elf_file<size, big_endian, File>::section_info(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_info: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_info(); } // Return the sh_addralign field of section SHNDX. template<int size, bool big_endian, typename File> typename Elf_types<size>::Elf_WXword Elf_file<size, big_endian, File>::section_addralign(unsigned int shndx) { File* const file = this->file_; if (shndx >= this->shnum()) file->error(_("section_addralign: bad shndx %u >= %u"), shndx, this->shnum()); typename File::View v(file->view(this->section_header_offset(shndx), This::shdr_size)); Ef_shdr shdr(v.data()); return shdr.get_sh_addralign(); } inline Elf_strtab::Elf_strtab(const unsigned char* p, size_t size) { // Check if the section is NUL-terminated. If it isn't, we ignore // the last part to make sure we don't return non-NUL-terminated // strings. while (size > 0 && p[size - 1] != 0) size--; this->base_ = reinterpret_cast<const char*>(p); this->usable_size_ = size; } } // End namespace elfcpp. #endif // !defined(ELFCPP_FILE_H)