LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_PE_SECTION_H
17#define LIEF_PE_SECTION_H
51 static constexpr size_t MAX_SECTION_NAME = 8;
53 enum class CHARACTERISTICS: uint64_t {
54 TYPE_NO_PAD = 0x00000008,
55 CNT_CODE = 0x00000020,
56 CNT_INITIALIZED_DATA = 0x00000040,
57 CNT_UNINITIALIZED_DATA = 0x00000080,
58 LNK_OTHER = 0x00000100,
59 LNK_INFO = 0x00000200,
60 LNK_REMOVE = 0x00000800,
61 LNK_COMDAT = 0x00001000,
63 MEM_PURGEABLE = 0x00010000,
64 MEM_16BIT = 0x00020000,
65 MEM_LOCKED = 0x00040000,
66 MEM_PRELOAD = 0x00080000,
67 ALIGN_1BYTES = 0x00100000,
68 ALIGN_2BYTES = 0x00200000,
69 ALIGN_4BYTES = 0x00300000,
70 ALIGN_8BYTES = 0x00400000,
71 ALIGN_16BYTES = 0x00500000,
72 ALIGN_32BYTES = 0x00600000,
73 ALIGN_64BYTES = 0x00700000,
74 ALIGN_128BYTES = 0x00800000,
75 ALIGN_256BYTES = 0x00900000,
76 ALIGN_512BYTES = 0x00A00000,
77 ALIGN_1024BYTES = 0x00B00000,
78 ALIGN_2048BYTES = 0x00C00000,
79 ALIGN_4096BYTES = 0x00D00000,
80 ALIGN_8192BYTES = 0x00E00000,
81 LNK_NRELOC_OVFL = 0x01000000,
82 MEM_DISCARDABLE = 0x02000000,
83 MEM_NOT_CACHED = 0x04000000,
84 MEM_NOT_PAGED = 0x08000000,
85 MEM_SHARED = 0x10000000,
86 MEM_EXECUTE = 0x20000000,
87 MEM_READ = 0x40000000,
88 MEM_WRITE = 0x80000000
91 Section(
const details::pe_section& header);
96 name_ = std::move(name);
99 Section(std::string name, std::vector<uint8_t> content) :
100 Section(std::move(name))
102 content_ = std::move(content);
103 size_ = content_.size();
117 return virtual_size_;
119 span<const uint8_t>
content()
const override {
124 span<const uint8_t>
padding()
const {
139 return pointer_to_relocations_;
146 return pointer_to_linenumbers_;
151 return number_of_relocations_;
156 return number_of_linenumbers_;
163 return characteristics_;
168 return (characteristics() & (uint32_t)c) > 0;
178 return has_characteristic(CHARACTERISTICS::MEM_DISCARDABLE);
180 void clear(uint8_t c);
183 void content(
const std::vector<uint8_t>& data)
override;
185 void name(std::string name)
override;
188 virtual_size_ = virtual_sz;
196 pointer_to_relocations_ = ptr;
200 pointer_to_linenumbers_ = ptr;
204 number_of_relocations_ = nb;
208 number_of_linenumbers_ = nb;
216 characteristics_ = characteristics;
232 characteristics_ &= ~static_cast<size_t>(characteristic);
237 characteristics_ |=
static_cast<size_t>(characteristic);
241 std::unique_ptr<SpanStream>
stream()
const;
242 LIEF_LOCAL Section& reserve(
size_t size, uint8_t value = 0) {
245 content_.resize(size, value);
251 return vector_iostream(content_);
258 void accept(Visitor& visitor)
const override;
263 std::vector<uint8_t> content_;
264 std::vector<uint8_t> padding_;
265 uint32_t virtual_size_ = 0;
266 uint32_t pointer_to_relocations_ = 0;
267 uint32_t pointer_to_linenumbers_ = 0;
268 uint16_t number_of_relocations_ = 0;
269 uint16_t number_of_linenumbers_ = 0;
270 uint32_t characteristics_ = 0;
272 COFFString* coff_string_ =
nullptr;
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:56
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
This class represents a string located in the COFF string table.
Definition COFFString.hpp:33
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
Class which represents a PE section.
Definition PE/Section.hpp:43
COFFString * coff_string()
Return the COFF string associated with the section's name (or a nullptr)
Definition PE/Section.hpp:223
Section(const Section &)=default
uint32_t pointerto_line_numbers() const
The file pointer to the beginning of line-number entries for the section. This is set to zero if ther...
Definition PE/Section.hpp:145
void sizeof_raw_data(uint32_t size)
Definition PE/Section.hpp:211
Section(std::string name)
Definition PE/Section.hpp:93
uint32_t pointerto_relocation() const
The file pointer to the beginning of the COFF relocation entries for the section. This is set to zero...
Definition PE/Section.hpp:138
Section & remove_characteristic(CHARACTERISTICS characteristic)
Definition PE/Section.hpp:231
friend std::ostream & operator<<(std::ostream &os, const Section §ion)
const COFFString * coff_string() const
Definition PE/Section.hpp:227
Section & operator=(const Section &)=default
bool has_characteristic(CHARACTERISTICS c) const
Check if the section has the given CHARACTERISTICS.
Definition PE/Section.hpp:167
uint16_t numberof_line_numbers() const
No longer used in recent PE binaries produced by Visual Studio.
Definition PE/Section.hpp:155
bool is_discardable() const
True if the section can be discarded as needed.
Definition PE/Section.hpp:177
~Section() override=default
CHARACTERISTICS
Definition PE/Section.hpp:53
span< const uint8_t > content() const override
The actual content of the section.
Definition PE/Section.hpp:121
void clear(uint8_t c)
Fill the content of the section with the given char
void pointerto_raw_data(uint32_t ptr)
Definition PE/Section.hpp:191
std::vector< CHARACTERISTICS > characteristics_list() const
List of the section characteristics.
uint32_t characteristics() const
Characteristics of the section: it provides information about the permissions of the section when map...
Definition PE/Section.hpp:162
void name(std::string name) override
Change the section's name.
void pointerto_relocation(uint32_t ptr)
Definition PE/Section.hpp:195
uint32_t sizeof_raw_data() const
Return the size of the data in the section.
span< const uint8_t > padding() const
Content of the section's padding area.
Definition PE/Section.hpp:126
void pointerto_line_numbers(uint32_t ptr)
Definition PE/Section.hpp:199
std::unique_ptr< SpanStream > stream() const
span< uint8_t > writable_content()
Definition PE/Section.hpp:254
void characteristics(uint32_t characteristics)
Definition PE/Section.hpp:215
void virtual_size(uint32_t virtual_sz)
Definition PE/Section.hpp:187
void content(const std::vector< uint8_t > &data) override
Change section content.
uint32_t pointerto_raw_data() const
The offset of the section data in the PE file.
void numberof_line_numbers(uint16_t nb)
Definition PE/Section.hpp:207
Section(const details::pe_section &header)
uint16_t numberof_relocations() const
No longer used in recent PE binaries produced by Visual Studio.
Definition PE/Section.hpp:150
void accept(Visitor &visitor) const override
Section(std::string name, std::vector< uint8_t > content)
Definition PE/Section.hpp:99
uint32_t virtual_size() const
Return the size of the data when mapped in memory.
Definition PE/Section.hpp:116
Section & add_characteristic(CHARACTERISTICS characteristic)
Definition PE/Section.hpp:236
void numberof_relocations(uint16_t nb)
Definition PE/Section.hpp:203
virtual std::string name() const
section's name
Definition Abstract/Section.hpp:44
Definition SpanStream.hpp:32
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(AuxiliaryWeakExternal::CHARACTERISTICS e)
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42