17 #ifndef __STOUT_ELF_HPP__ 18 #define __STOUT_ELF_HPP__ 24 #include <elfio/elfio.hpp> 78 if (!file->elf.load(path)) {
80 return Error(
"Unknown error during elfio::load");
84 foreach (ELFIO::section* section, file->elf.sections) {
86 file->sections_by_type[section_type].push_back(section);
97 return Error(
"Unknown error");
108 return Error(
"No DYNAMIC sections found");
111 std::vector<std::string>
strings;
113 foreach (ELFIO::section* section,
115 auto accessor = ELFIO::dynamic_section_accessor(
elf, section);
117 for (ELFIO::Elf_Xword i = 0; i < accessor.get_entries_num(); ++i) {
118 ELFIO::Elf_Xword entry_tag;
119 ELFIO::Elf_Xword entry_value;
120 std::string entry_string;
122 if (!accessor.get_entry(i, entry_tag, entry_value, entry_string)) {
123 return Error(
"Failed to get entry from DYNAMIC section");
127 strings.push_back(entry_string);
147 ELFIO::section* section =
elf.sections[
".note.ABI-tag"];
149 if (section ==
nullptr) {
154 return Error(
"Section '.note.ABI-tag' is not a NOTE section");
157 auto accessor = ELFIO::note_section_accessor(
elf, section);
159 if (accessor.get_notes_num() != 1) {
160 return Error(
"Section '.note.ABI-tag' does not have exactly one entry");
163 ELFIO::Elf_Word
type;
166 ELFIO::Elf_Word descriptor_size;
168 if (!accessor.get_note(0, type, name, descriptor, descriptor_size)) {
169 return Error(
"Failed to get entry from '.note.ABI-tag' section");
175 " entry in '.note.ABI-tag' section");
180 return Error(
"Corrupt label '" + name +
"' from" 181 " entry in '.note.ABI-tag' section");
190 (uint32_t*)descriptor,
191 (uint32_t*)((
char*)descriptor + descriptor_size));
193 if (version.size() != 4 || version[0] != 0) {
195 " from entry in '.note.ABI-tag' section");
198 return Version(version[1], version[2], version[3]);
208 ELFIO::section* section =
elf.sections[
".interp"];
210 if (section ==
nullptr) {
215 return Error(
"Section '.interp' is not a PROGBITS section");
218 return std::string(section->get_data(), section->get_size());
225 std::map<SectionType, std::vector<ELFIO::section*>> sections_by_type;
230 #endif // __STOUT_ELF_HPP__
Definition: errorbase.hpp:36
Definition: format.hpp:45
URI file(const std::string &path)
Creates a file URI with the given path on the local host.
Definition: file.hpp:33
SectionType
Definition: elf.hpp:45
process::Future< Version > version()
Definition: version.hpp:32
Result< Version > get_abi_version() const
Definition: elf.hpp:145
Try< std::vector< std::string > > get_dynamic_strings(DynamicTag tag) const
Definition: elf.hpp:105
DynamicTag
Definition: elf.hpp:52
Definition: version.hpp:41
Try< uint32_t > type(const std::string &path)
Try< Class > get_class() const
Definition: elf.hpp:93
std::string stringify(int flags)
static Try< File * > load(const std::string &path)
Definition: elf.hpp:74
constexpr const char * name
Definition: shell.hpp:41
Result< std::string > get_interpreter() const
Definition: elf.hpp:206
Class
Definition: elf.hpp:38