2023-11-09 22:42:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-13 21:30:53 +02:00
|
|
|
#include <LibELF/Types.h>
|
|
|
|
|
2023-11-09 22:42:47 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <optional>
|
|
|
|
#include <span>
|
|
|
|
#include <string_view>
|
|
|
|
#include <string>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
class ELFFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ELFFile(std::string_view path);
|
|
|
|
~ELFFile();
|
|
|
|
|
2023-11-13 21:30:53 +02:00
|
|
|
const LibELF::ElfNativeFileHeader& elf_header() const;
|
2023-11-09 22:42:47 +02:00
|
|
|
std::optional<std::span<const uint8_t>> find_section(std::string_view name) const;
|
|
|
|
|
|
|
|
bool success() const { return m_success; }
|
|
|
|
|
|
|
|
std::string_view path() const { return m_path; }
|
|
|
|
|
|
|
|
private:
|
2023-11-13 21:30:53 +02:00
|
|
|
const LibELF::ElfNativeSectionHeader& section_header(std::size_t index) const;
|
|
|
|
std::string_view section_name(const LibELF::ElfNativeSectionHeader&) const;
|
2023-11-09 22:42:47 +02:00
|
|
|
bool validate_elf_header() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string m_path;
|
|
|
|
bool m_success { false };
|
|
|
|
int m_fd { -1 };
|
|
|
|
struct stat m_stat { };
|
|
|
|
uint8_t* m_mmap { nullptr };
|
|
|
|
};
|