diff options
author | Oxore <oxore@protonmail.com> | 2024-02-05 01:20:51 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2024-02-05 01:21:59 +0300 |
commit | 21a9aa92a7cf8767a0fcb33858546dea744c4071 (patch) | |
tree | a5313fdaff5c0ed2d3db416d027e6df21d3cd7ff /elf_image.h | |
parent | 9fd2eba95beb6c9ce6fb26e1442aa2f68aac9b1f (diff) |
Organize source code and tests
Diffstat (limited to 'elf_image.h')
-rw-r--r-- | elf_image.h | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/elf_image.h b/elf_image.h deleted file mode 100644 index b7c7123..0000000 --- a/elf_image.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -/* SPDX-License-Identifier: Unlicense - */ - -#include "elf_format.h" -#include "data_buffer.h" - -#include <cstdlib> - -namespace ELF { - -struct ProgramHeader32Table { - const ProgramHeader32 *headers{}; - size_t size{}; - static ProgramHeader32Table FromBytes(const DataView &, DataEncoding); -}; - -struct Segment { - Segment *next{}; - const DataView view{}; -}; - -class Image { - const DataBuffer _data; - char *const _error; - const Header32 _h; - const ProgramHeader32Table _pht; -public: - explicit Image(DataBuffer&&); - ~Image(); - constexpr bool IsValid() const { return _error == nullptr; } - constexpr const DataBuffer &Data() const { return _data; }; - constexpr const DataView ProgramView() const - { - if (!IsValid()) { - return DataView{}; - } - for (size_t i = 0; i < _pht.size; i++) { - const auto ph = _pht.headers[i]; - const bool is_code = (ph.flags & (kPHFlagX | kPHFlagW | kPHFlagR)) == - (kPHFlagX | kPHFlagR); - const bool is_load = ParsePHType(ph.type) == PHType::kLoad; - const bool contains_entry = _h.entry >= ph.vaddr && _h.entry < ph.vaddr + ph.memsz; - if (is_load && is_code && ph.vaddr == 0 && contains_entry) - { - return _data.View(ph.offset, ph.filesz); - } - } - return DataView{}; - }; - constexpr const char *Error() const { return _error; } -}; - -} |