Browse Source

read section name string table

assembler
Zack Marvel 1 year ago
parent
commit
9ee5de8d7a
  1. 30
      src/elf_reader.cpp

30
src/elf_reader.cpp

@ -79,6 +79,36 @@ ELFReader::read(std::istream& is)
<< "entsize: " << it->sh_entsize << std::endl << std::endl;
}
auto &strhdr = shtab[header.e_shstrndx];
if (!is.seekg(strhdr.sh_offset, std::ios_base::beg)) {
return tl::make_unexpected("Unable to seek to section name string table");
}
std::vector<std::string> section_names{};
{
{
char buf;
if (!is.read(&buf, sizeof(buf)) || buf != '\0') {
return tl::make_unexpected("Invalid section name string table");
}
}
std::string curr{};
for (size_t i = 0; i < strhdr.sh_size; i++) {
char buf;
if (!is.read(&buf, sizeof(buf))) {
return tl::make_unexpected(
"Failed to read char from section name string table");
}
curr.push_back(buf);
if (buf == '\0') {
std::cout << curr << std::endl;
section_names.push_back(curr);
curr.clear();
}
}
}
auto reader = std::make_unique<ELFReader>();
reader->elf_ = std::move(*pelf);
return std::move(reader);

Loading…
Cancel
Save