16#ifndef LIEF_PE_SECTION_H
17#define LIEF_PE_SECTION_H
94 Section(
const details::pe_section& header);
99 name_ = std::move(
name);
106 size_ = content_.size();
120 return virtual_size_;
142 return pointer_to_relocations_;
149 return pointer_to_linenumbers_;
154 return number_of_relocations_;
159 return number_of_linenumbers_;
166 return characteristics_;
188 void content(
const std::vector<uint8_t>& data)
override;
193 virtual_size_ = virtual_sz;
201 pointer_to_relocations_ = ptr;
205 pointer_to_linenumbers_ = ptr;
209 number_of_relocations_ = nb;
213 number_of_linenumbers_ = nb;
237 characteristics_ &= ~static_cast<size_t>(characteristic);
242 characteristics_ |=
static_cast<size_t>(characteristic);
246 std::unique_ptr<SpanStream>
stream()
const;
250 content_.resize(
size, value);
270 std::vector<uint8_t> content_;
271 std::vector<uint8_t> padding_;
272 uint32_t virtual_size_ = 0;
273 uint32_t pointer_to_relocations_ = 0;
274 uint32_t pointer_to_linenumbers_ = 0;
275 uint16_t number_of_relocations_ = 0;
276 uint16_t number_of_linenumbers_ = 0;
277 uint32_t characteristics_ = 0;
This class represents a string located in the COFF string table.
Definition String.hpp:33
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:57
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
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:148
void sizeof_raw_data(uint32_t size)
Definition PE/Section.hpp:216
Section(std::string name)
Definition PE/Section.hpp:96
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:141
Section & remove_characteristic(CHARACTERISTICS characteristic)
Definition PE/Section.hpp:236
static std::vector< CHARACTERISTICS > characteristics_to_list(uint32_t value)
friend std::ostream & operator<<(std::ostream &os, const Section §ion)
Section & operator=(const Section &)=default
bool has_characteristic(CHARACTERISTICS c) const
Check if the section has the given CHARACTERISTICS.
Definition PE/Section.hpp:170
uint16_t numberof_line_numbers() const
No longer used in recent PE binaries produced by Visual Studio.
Definition PE/Section.hpp:158
bool is_discardable() const
True if the section can be discarded as needed.
Definition PE/Section.hpp:182
~Section() override=default
CHARACTERISTICS
Definition PE/Section.hpp:56
@ MEM_PRELOAD
Definition PE/Section.hpp:69
@ MEM_SHARED
Definition PE/Section.hpp:88
@ ALIGN_128BYTES
Definition PE/Section.hpp:77
@ ALIGN_512BYTES
Definition PE/Section.hpp:79
@ ALIGN_2BYTES
Definition PE/Section.hpp:71
@ CNT_CODE
Definition PE/Section.hpp:58
@ GPREL
Definition PE/Section.hpp:65
@ ALIGN_64BYTES
Definition PE/Section.hpp:76
@ ALIGN_4BYTES
Definition PE/Section.hpp:72
@ MEM_NOT_CACHED
Definition PE/Section.hpp:86
@ ALIGN_16BYTES
Definition PE/Section.hpp:74
@ LNK_REMOVE
Definition PE/Section.hpp:63
@ ALIGN_2048BYTES
Definition PE/Section.hpp:81
@ ALIGN_8192BYTES
Definition PE/Section.hpp:83
@ MEM_DISCARDABLE
Definition PE/Section.hpp:85
@ ALIGN_256BYTES
Definition PE/Section.hpp:78
@ LNK_INFO
Definition PE/Section.hpp:62
@ ALIGN_4096BYTES
Definition PE/Section.hpp:82
@ MEM_NOT_PAGED
Definition PE/Section.hpp:87
@ MEM_WRITE
Definition PE/Section.hpp:91
@ CNT_UNINITIALIZED_DATA
Definition PE/Section.hpp:60
@ MEM_EXECUTE
Definition PE/Section.hpp:89
@ MEM_LOCKED
Definition PE/Section.hpp:68
@ ALIGN_32BYTES
Definition PE/Section.hpp:75
@ MEM_READ
Definition PE/Section.hpp:90
@ LNK_COMDAT
Definition PE/Section.hpp:64
@ MEM_PURGEABLE
Definition PE/Section.hpp:66
@ TYPE_NO_PAD
Definition PE/Section.hpp:57
@ ALIGN_8BYTES
Definition PE/Section.hpp:73
@ LNK_OTHER
Definition PE/Section.hpp:61
@ MEM_16BIT
Definition PE/Section.hpp:67
@ CNT_INITIALIZED_DATA
Definition PE/Section.hpp:59
@ LNK_NRELOC_OVFL
Definition PE/Section.hpp:84
@ ALIGN_1024BYTES
Definition PE/Section.hpp:80
@ ALIGN_1BYTES
Definition PE/Section.hpp:70
const COFF::String * coff_string() const
Definition PE/Section.hpp:232
friend class Builder
Definition PE/Section.hpp:49
span< const uint8_t > content() const override
The actual content of the section.
Definition PE/Section.hpp:124
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:196
std::vector< CHARACTERISTICS > characteristics_list() const
List of the section characteristics.
Definition PE/Section.hpp:175
uint32_t characteristics() const
Characteristics of the section: it provides information about the permissions of the section when map...
Definition PE/Section.hpp:165
void name(std::string name) override
Change the section's name.
static constexpr size_t MAX_SECTION_NAME
Definition PE/Section.hpp:54
friend class Binary
Definition PE/Section.hpp:50
void pointerto_relocation(uint32_t ptr)
Definition PE/Section.hpp:200
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:129
void pointerto_line_numbers(uint32_t ptr)
Definition PE/Section.hpp:204
std::unique_ptr< SpanStream > stream() const
span< uint8_t > writable_content()
Definition PE/Section.hpp:259
friend class Parser
Definition PE/Section.hpp:48
void characteristics(uint32_t characteristics)
Definition PE/Section.hpp:220
void virtual_size(uint32_t virtual_sz)
Definition PE/Section.hpp:192
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:212
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:153
COFF::String * coff_string()
Return the COFF string associated with the section's name (or a nullptr).
Definition PE/Section.hpp:228
void accept(Visitor &visitor) const override
Section(std::string name, std::vector< uint8_t > content)
Definition PE/Section.hpp:102
uint32_t virtual_size() const
Return the size of the data when mapped in memory.
Definition PE/Section.hpp:119
Section & add_characteristic(CHARACTERISTICS characteristic)
Definition PE/Section.hpp:241
void numberof_relocations(uint16_t nb)
Definition PE/Section.hpp:208
Class which represents an abstracted section.
Definition Abstract/Section.hpp:29
virtual void size(uint64_t size)
Change the section size.
Definition Abstract/Section.hpp:60
virtual std::string name() const
section's name
Definition Abstract/Section.hpp:44
virtual uint64_t offset() const
Offset in the binary.
Definition Abstract/Section.hpp:70
Definition SpanStream.hpp:32
Definition Visitor.hpp:210
Definition iostream.hpp:31
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
Definition AuxiliarySymbol.hpp:29
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(CODE_PAGES e)
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42