LIEF: Library to Instrument Executable Formats Version 0.16.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_ELF_SECTION_H
17#define LIEF_ELF_SECTION_H
44class ObjectFileLayout;
52 friend class ExeLayout;
53 friend class ObjectFileLayout;
56 using segments_t = std::vector<Segment*>;
57 using it_segments = ref_iterator<segments_t&>;
58 using it_const_segments = const_ref_iterator<const segments_t&>;
60 static constexpr uint32_t MAX_SECTION_SIZE = 2_GB;
62 enum class TYPE : uint64_t {
82 ANDROID_REL = 0x60000001,
83 ANDROID_RELA = 0x60000002,
84 LLVM_ADDRSIG = 0x6fff4c03,
85 ANDROID_RELR = 0x6fffff00,
86 GNU_ATTRIBUTES = 0x6ffffff5,
87 GNU_HASH = 0x6ffffff6,
88 GNU_VERDEF = 0x6ffffffd,
89 GNU_VERNEED = 0x6ffffffe,
90 GNU_VERSYM = 0x6fffffff,
93 _ARM_ID_ = 1LLU, _HEX_ID_ = 2LLU, _X86_64_ID_ = 2LLU,
94 _MIPS_ID_ = 3LLU, _RISCV_ID_ = 4LLU,
96 ARM_EXIDX = 0x70000001U + (_ARM_ID_ << _ID_SHIFT_),
97 ARM_PREEMPTMAP = 0x70000002U + (_ARM_ID_ << _ID_SHIFT_),
98 ARM_ATTRIBUTES = 0x70000003U + (_ARM_ID_ << _ID_SHIFT_),
99 ARM_DEBUGOVERLAY = 0x70000004U + (_ARM_ID_ << _ID_SHIFT_),
100 ARM_OVERLAYSECTION = 0x70000005U + (_ARM_ID_ << _ID_SHIFT_),
102 HEX_ORDERED = 0x70000000 + (_HEX_ID_ << _ID_SHIFT_),
105 X86_64_UNWIND = 0x70000001 + (_X86_64_ID_ << _ID_SHIFT_),
107 MIPS_REGINFO = 0x70000006 + (_MIPS_ID_ << _ID_SHIFT_),
108 MIPS_OPTIONS = 0x7000000d + (_MIPS_ID_ << _ID_SHIFT_),
109 MIPS_ABIFLAGS = 0x7000002a + (_MIPS_ID_ << _ID_SHIFT_),
111 RISCV_ATTRIBUTES = 0x70000003 + (_RISCV_ID_ << _ID_SHIFT_),
114 enum class FLAGS : uint64_t {
118 EXECINSTR = 0x000000004,
120 STRINGS = 0x000000020,
121 INFO_LINK = 0x000000040,
122 LINK_ORDER = 0x000000080,
123 OS_NONCONFORMING = 0x000000100,
126 COMPRESSED = 0x000000800,
127 GNU_RETAIN = 0x000200000,
128 EXCLUDE = 0x080000000,
131 _XCORE_ID_ = 1LLU, _HEX_ID_ = 3LLU, _X86_64_ID_ = 2LLU,
132 _MIPS_ID_ = 4LLU, _ARM_ID_ = 5LLU,
134 XCORE_SHF_DP_SECTION = 0x010000000 + (_XCORE_ID_ << _ID_SHIFT_),
135 XCORE_SHF_CP_SECTION = 0x020000000 + (_XCORE_ID_ << _ID_SHIFT_),
137 X86_64_LARGE = 0x010000000 + (_X86_64_ID_ << _ID_SHIFT_),
139 HEX_GPREL = 0x010000000 + (_HEX_ID_ << _ID_SHIFT_),
141 MIPS_NODUPES = 0x001000000 + (_MIPS_ID_ << _ID_SHIFT_),
142 MIPS_NAMES = 0x002000000 + (_MIPS_ID_ << _ID_SHIFT_),
143 MIPS_LOCAL = 0x004000000 + (_MIPS_ID_ << _ID_SHIFT_),
144 MIPS_NOSTRIP = 0x008000000 + (_MIPS_ID_ << _ID_SHIFT_),
145 MIPS_GPREL = 0x010000000 + (_MIPS_ID_ << _ID_SHIFT_),
146 MIPS_MERGE = 0x020000000 + (_MIPS_ID_ << _ID_SHIFT_),
147 MIPS_ADDR = 0x040000000 + (_MIPS_ID_ << _ID_SHIFT_),
148 MIPS_STRING = 0x080000000 + (_MIPS_ID_ << _ID_SHIFT_),
150 ARM_PURECODE = 0x020000000 + (_ARM_ID_ << _ID_SHIFT_),
153 static constexpr uint64_t FLAG_MASK = (uint64_t(1) << uint8_t(FLAGS::_ID_SHIFT_)) - 1;
154 static constexpr uint64_t TYPE_MASK = (uint64_t(1) << uint8_t(TYPE::_ID_SHIFT_)) - 1;
158 return static_cast<uint64_t
>(type) & TYPE_MASK;
161 Section(
const std::string& name, TYPE type = TYPE::PROGBITS) :
174 void swap(Section& other)
noexcept;
179 span<const uint8_t>
content()
const override;
182 void content(
const std::vector<uint8_t>& data)
override;
187 uint64_t
flags()
const {
192 bool has(FLAGS flag)
const;
195 bool has(
const Segment& segment)
const;
202 uint64_t
size()
const override {
206 void size(uint64_t size)
override;
216 return this->offset();
224 return original_size_;
229 return address_align_;
247 uint32_t
link()
const {
252 Section&
clear(uint8_t value = 0);
255 void add(FLAGS flag);
275 this->offset(offset);
287 address_align_ = alignment;
291 entry_size_ = entry_size;
311 void accept(Visitor& visitor)
const override;
322 std::unique_ptr<SpanStream>
stream()
const;
330 LIEF_LOCAL Section(
const T& header, ARCH arch);
333 ARCH arch_ = ARCH::NONE;
334 TYPE type_ = TYPE::SHT_NULL_;
336 uint64_t original_size_ = 0;
339 uint64_t address_align_ = 0;
340 uint64_t entry_size_ = 0;
341 segments_t segments_;
342 bool is_frame_ =
false;
343 DataHandler::Handler* datahandler_ =
nullptr;
344 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
void size(uint64_t size) override
Change the section size.
static TYPE type_from(uint32_t value, ARCH arch)
span< const uint8_t > content() const override
Section's content.
it_segments segments()
Definition ELF/Section.hpp:294
uint64_t original_size() const
Original size of the section's data.
Definition ELF/Section.hpp:223
Section & operator+=(FLAGS c)
Definition ELF/Section.hpp:313
void clear_flags()
Definition ELF/Section.hpp:270
uint64_t flags() const
Section flags.
Definition ELF/Section.hpp:189
Section & as_frame()
Definition ELF/Section.hpp:302
void offset(uint64_t offset) override
friend std::ostream & operator<<(std::ostream &os, const Section §ion)
void remove(FLAGS flag)
Remove the given ELF_SECTION_FLAGS.
std::vector< FLAGS > flags_list() const
Return section flags as a std::set
bool is_frame() const
Definition ELF/Section.hpp:307
uint64_t file_offset() const
Definition ELF/Section.hpp:215
~Section() override=default
void alignment(uint64_t alignment)
Definition ELF/Section.hpp:286
void information(uint32_t info)
Definition ELF/Section.hpp:282
static uint32_t to_value(TYPE type)
Definition ELF/Section.hpp:157
std::unique_ptr< SpanStream > stream() const
Return a stream over the content of this section.
Section(const Section &other)
TYPE type() const
Definition ELF/Section.hpp:176
TYPE
Definition ELF/Section.hpp:62
Section & operator-=(FLAGS c)
Definition ELF/Section.hpp:318
void content(std::vector< uint8_t > &&data)
uint32_t link() const
Index to another section.
Definition ELF/Section.hpp:249
uint64_t size() const override
section's size (size in the binary, not the virtual size)
Definition ELF/Section.hpp:202
void content(const std::vector< uint8_t > &data) override
Set section content.
Section & clear(uint8_t value=0)
Clear the content of the section with the given value
void accept(Visitor &visitor) const override
void swap(Section &other) noexcept
bool has(const Segment &segment) const
True if the section is wrapped by the given Segment
void entry_size(uint64_t entry_size)
Definition ELF/Section.hpp:290
Section(const std::string &name, TYPE type=TYPE::PROGBITS)
Definition ELF/Section.hpp:161
FLAGS
Definition ELF/Section.hpp:114
void type(TYPE type)
Definition ELF/Section.hpp:262
uint64_t information() const
Section information. The meaning of this value depends on the section's type.
Definition ELF/Section.hpp:234
uint64_t offset() const override
Offset in the binary.
Definition ELF/Section.hpp:210
void link(uint32_t link)
Definition ELF/Section.hpp:278
void add(FLAGS flag)
Add the given ELF_SECTION_FLAGS.
Section & operator=(Section other)
Definition ELF/Section.hpp:169
uint64_t alignment() const
Section file alignment.
Definition ELF/Section.hpp:228
it_const_segments segments() const
Definition ELF/Section.hpp:298
bool has(FLAGS flag) const
True if the section has the given flag
uint64_t entry_size() const
This function returns the size of an element in the case of a section that contains an array.
Definition ELF/Section.hpp:244
void file_offset(uint64_t offset)
Definition ELF/Section.hpp:274
void flags(uint64_t flags)
Definition ELF/Section.hpp:266
Class which represents the ELF segments.
Definition Segment.hpp:46
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