LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_ELF_SEGMENT_H
17#define LIEF_ELF_SEGMENT_H
56 using sections_t = std::vector<Section*>;
57 using it_sections = ref_iterator<sections_t&>;
58 using it_const_sections = const_ref_iterator<const sections_t&>;
60 static constexpr uint64_t PT_BIT = 33;
61 static constexpr uint64_t PT_OS_BIT = 53;
62 static constexpr uint64_t PT_MASK = (uint64_t(1) << PT_BIT) - 1;
64 static constexpr uint64_t PT_ARM = uint64_t(1) << PT_BIT;
65 static constexpr uint64_t PT_AARCH64 = uint64_t(2) << PT_BIT;
66 static constexpr uint64_t PT_MIPS = uint64_t(3) << PT_BIT;
67 static constexpr uint64_t PT_RISCV = uint64_t(4) << PT_BIT;
68 static constexpr uint64_t PT_IA_64 = uint64_t(5) << PT_BIT;
70 static constexpr uint64_t PT_HPUX = uint64_t(1) << PT_OS_BIT;
72 enum class TYPE : uint64_t {
73 UNKNOWN = uint64_t(-1),
83 GNU_EH_FRAME = 0x6474e550,
85 GNU_STACK = 0x6474e551,
86 GNU_PROPERTY = 0x6474e553,
87 GNU_RELRO = 0x6474e552,
88 PAX_FLAGS = 0x65041580,
90 ARM_ARCHEXT = 0x70000000 | PT_ARM,
91 ARM_EXIDX = 0x70000001 | PT_ARM,
93 AARCH64_MEMTAG_MTE = 0x70000002 | PT_AARCH64,
95 MIPS_REGINFO = 0x70000000 | PT_MIPS,
96 MIPS_RTPROC = 0x70000001 | PT_MIPS,
97 MIPS_OPTIONS = 0x70000002 | PT_MIPS,
98 MIPS_ABIFLAGS = 0x70000003 | PT_MIPS,
100 RISCV_ATTRIBUTES = 0x70000003 | PT_RISCV,
102 IA_64_EXT = (0x70000000 + 0x0) | PT_IA_64,
103 IA_64_UNWIND = (0x70000000 + 0x1) | PT_IA_64,
105 HP_TLS = (0x60000000 + 0x0) | PT_HPUX,
106 HP_CORE_NONE = (0x60000000 + 0x1) | PT_HPUX,
107 HP_CORE_VERSION = (0x60000000 + 0x2) | PT_HPUX,
108 HP_CORE_KERNEL = (0x60000000 + 0x3) | PT_HPUX,
109 HP_CORE_COMM = (0x60000000 + 0x4) | PT_HPUX,
110 HP_CORE_PROC = (0x60000000 + 0x5) | PT_HPUX,
111 HP_CORE_LOADABLE = (0x60000000 + 0x6) | PT_HPUX,
112 HP_CORE_STACK = (0x60000000 + 0x7) | PT_HPUX,
113 HP_CORE_SHM = (0x60000000 + 0x8) | PT_HPUX,
114 HP_CORE_MMF = (0x60000000 + 0x9) | PT_HPUX,
115 HP_PARALLEL = (0x60000000 + 0x10) | PT_HPUX,
116 HP_FASTBIND = (0x60000000 + 0x11) | PT_HPUX,
117 HP_OPT_ANNOT = (0x60000000 + 0x12) | PT_HPUX,
118 HP_HSL_ANNOT = (0x60000000 + 0x13) | PT_HPUX,
119 HP_STACK = (0x60000000 + 0x14) | PT_HPUX,
120 HP_CORE_UTSNAME = (0x60000000 + 0x15) | PT_HPUX,
130 static TYPE
type_from(uint64_t value, ARCH arch, Header::OS_ABI os);
132 return static_cast<uint64_t
>(type) & PT_MASK;
135 static result<Segment>
from_raw(
const uint8_t* ptr,
size_t size);
136 static result<Segment>
from_raw(
const std::vector<uint8_t>& raw) {
137 return from_raw(raw.data(), raw.size());
153 return type() == TYPE::LOAD;
157 return type() == TYPE::INTERP;
161 return type() == TYPE::PHDR;
168 FLAGS
flags()
const {
171 return FLAGS(flags_);
181 return virtual_address_;
190 return physical_address_;
202 return virtual_size_;
209 span<const uint8_t>
content()
const;
212 bool has(FLAGS flag)
const {
215 return (flags_ &
static_cast<uint64_t
>(flag)) != 0;
217 bool has(
const Section& section)
const;
220 bool has(
const std::string& section_name)
const;
223 void add(FLAGS flag);
235 flags_ =
static_cast<uint32_t
>(flags);
249 virtual_address_ = virtual_address;
253 physical_address_ = physical_address;
259 virtual_size_ = virtual_size;
263 alignment_ = alignment;
281 std::unique_ptr<SpanStream>
stream()
const;
283 void accept(Visitor& visitor)
const override;
299 LIEF_LOCAL Segment(
const T& header, ARCH arch = ARCH::NONE,
300 Header::OS_ABI os = Header::OS_ABI::SYSTEMV);
305 TYPE type_ = TYPE::PT_NULL_;
306 ARCH arch_ = ARCH::NONE;
308 uint64_t file_offset_ = 0;
309 uint64_t virtual_address_ = 0;
310 uint64_t physical_address_ = 0;
312 uint64_t virtual_size_ = 0;
313 uint64_t alignment_ = 0;
314 uint64_t handler_size_ = 0;
315 sections_t sections_;
316 DataHandler::Handler* datahandler_ =
nullptr;
317 std::vector<uint8_t> content_c_;
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
Class which takes an ELF::Binary object and reconstructs a valid binary.
Definition ELF/Builder.hpp:48
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
Class wich represents an ELF Section.
Definition ELF/Section.hpp:48
Class which represents the ELF segments.
Definition Segment.hpp:48
uint64_t physical_address() const
The physical address of the segment. This value is not really relevant on systems like Linux or Andro...
Definition Segment.hpp:189
void physical_address(uint64_t physical_address)
Definition Segment.hpp:252
void add(FLAGS flag)
Append the given ELF_SEGMENT_FLAGS.
static result< Segment > from_raw(const std::vector< uint8_t > &raw)
Definition Segment.hpp:136
size_t get_content_size() const
T get_content_value(size_t offset) const
bool is_interpreter() const
Definition Segment.hpp:156
void flags(FLAGS flags)
Definition Segment.hpp:234
~Segment() override=default
bool is_phdr() const
Definition Segment.hpp:160
uint64_t physical_size() const
The file size of the data associated with this segment.
Definition Segment.hpp:194
void clear_flags()
Definition Segment.hpp:242
Segment & operator-=(FLAGS flag)
Definition Segment.hpp:290
bool has(const std::string §ion_name) const
Check if the current segment wraps the given section's name.
void flags(uint32_t flags)
Definition Segment.hpp:238
Segment & operator+=(FLAGS flag)
Definition Segment.hpp:285
void set_content_value(size_t offset, T value)
void file_offset(uint64_t file_offset)
Segment & operator=(Segment other)
void remove(FLAGS flag)
Remove the given ELF_SEGMENT_FLAGS.
Segment & operator=(Segment &&)=default
void type(TYPE type)
Definition Segment.hpp:230
uint64_t virtual_address() const
The virtual address of the segment.
Definition Segment.hpp:180
span< const uint8_t > content() const
The raw data associated with this segment.
bool has(FLAGS flag) const
Check if the current segment has the given flag.
Definition Segment.hpp:214
void swap(Segment &other)
FLAGS
Definition Segment.hpp:123
it_sections sections()
Iterator over the sections wrapped by this segment.
Definition Segment.hpp:273
void virtual_size(uint64_t virtual_size)
Definition Segment.hpp:258
static TYPE type_from(uint64_t value, ARCH arch, Header::OS_ABI os)
TYPE type() const
The segment's type (LOAD, DYNAMIC, ...)
Definition Segment.hpp:165
void content(std::vector< uint8_t > content)
void physical_size(uint64_t physical_size)
bool has(const Section §ion) const
Check if the current segment wraps the given ELF::Section.
uint64_t file_offset() const
The file offset of the data associated with this segment.
Definition Segment.hpp:175
bool is_load() const
Definition Segment.hpp:152
it_const_sections sections() const
Definition Segment.hpp:277
TYPE
Definition Segment.hpp:72
Segment(const Segment &other)
uint64_t alignment() const
The offset alignment of the segment.
Definition Segment.hpp:206
static uint64_t to_value(TYPE type)
Definition Segment.hpp:131
FLAGS flags() const
The flag permissions associated with this segment.
Definition Segment.hpp:170
void virtual_address(uint64_t virtual_address)
Definition Segment.hpp:248
std::unique_ptr< SpanStream > stream() const
Segment(Segment &&)=default
static result< Segment > from_raw(const uint8_t *ptr, size_t size)
uint64_t virtual_size() const
The in-memory size of this segment. Usually, if the .bss segment is wrapped by this segment then,...
Definition Segment.hpp:201
void alignment(uint64_t alignment)
Definition Segment.hpp:262
void accept(Visitor &visitor) const override
friend std::ostream & operator<<(std::ostream &os, const Segment &segment)
Definition SpanStream.hpp:32
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
Definition ELF/Binary.hpp:38
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
const char * to_string(DynamicEntry::TAG e)
ARCH
Definition ELF/enums.hpp:30
@ NONE
Definition ELF/enums.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42