49 static constexpr size_t MAX_SECTION_NAME = 8;
51 enum class CHARACTERISTICS:
size_t {
52 TYPE_NO_PAD = 0x00000008,
53 CNT_CODE = 0x00000020,
54 CNT_INITIALIZED_DATA = 0x00000040,
55 CNT_UNINITIALIZED_DATA = 0x00000080,
56 LNK_OTHER = 0x00000100,
57 LNK_INFO = 0x00000200,
58 LNK_REMOVE = 0x00000800,
59 LNK_COMDAT = 0x00001000,
61 MEM_PURGEABLE = 0x00010000,
62 MEM_16BIT = 0x00020000,
63 MEM_LOCKED = 0x00040000,
64 MEM_PRELOAD = 0x00080000,
65 ALIGN_1BYTES = 0x00100000,
66 ALIGN_2BYTES = 0x00200000,
67 ALIGN_4BYTES = 0x00300000,
68 ALIGN_8BYTES = 0x00400000,
69 ALIGN_16BYTES = 0x00500000,
70 ALIGN_32BYTES = 0x00600000,
71 ALIGN_64BYTES = 0x00700000,
72 ALIGN_128BYTES = 0x00800000,
73 ALIGN_256BYTES = 0x00900000,
74 ALIGN_512BYTES = 0x00A00000,
75 ALIGN_1024BYTES = 0x00B00000,
76 ALIGN_2048BYTES = 0x00C00000,
77 ALIGN_4096BYTES = 0x00D00000,
78 ALIGN_8192BYTES = 0x00E00000,
79 LNK_NRELOC_OVFL = 0x01000000,
80 MEM_DISCARDABLE = 0x02000000,
81 MEM_NOT_CACHED = 0x04000000,
82 MEM_NOT_PAGED = 0x08000000,
83 MEM_SHARED = 0x10000000,
84 MEM_EXECUTE = 0x20000000,
85 MEM_READ = 0x40000000,
86 MEM_WRITE = 0x80000000
89 Section(
const details::pe_section& header);
91 Section(
const std::vector<uint8_t>& data,
92 const std::string& name =
"", uint32_t characteristics = 0);
93 Section(
const std::string& name);
106 return virtual_size_;
110 span<const uint8_t>
content()
const override {
128 return pointer_to_relocations_;
135 return pointer_to_linenumbers_;
140 return number_of_relocations_;
145 return number_of_linenumbers_;
152 return characteristics_;
159 const std::set<PE_SECTION_TYPES>&
types()
const;
163 return (characteristics() &
static_cast<size_t>(c)) > 0;
171 void content(
const std::vector<uint8_t>& data)
override;
173 void name(
const std::string& name)
override;
175 void virtual_size(uint32_t virtual_sz) {
176 virtual_size_ = virtual_sz;
179 void pointerto_raw_data(uint32_t ptr);
181 void pointerto_relocation(uint32_t ptr) {
182 pointer_to_relocations_ = ptr;
185 void pointerto_line_numbers(uint32_t ptr) {
186 pointer_to_linenumbers_ = ptr;
189 void numberof_relocations(uint16_t nb) {
190 number_of_relocations_ = nb;
193 void numberof_line_numbers(uint16_t nb) {
194 number_of_linenumbers_ = nb;
197 void sizeof_raw_data(uint32_t sizeOfRawData);
199 void characteristics(uint32_t characteristics) {
200 characteristics_ = characteristics;
203 void type(PE_SECTION_TYPES type);
204 void add_type(PE_SECTION_TYPES type);
205 void remove_type(PE_SECTION_TYPES type);
207 void remove_characteristic(Section::CHARACTERISTICS characteristic) {
208 characteristics_ &= ~static_cast<size_t>(characteristic);
211 void add_characteristic(Section::CHARACTERISTICS characteristic) {
212 characteristics_ |=
static_cast<size_t>(characteristic);
215 void accept(Visitor& visitor)
const override;
217 LIEF_API
friend std::ostream& operator<<(std::ostream& os,
const Section& section);
220 span<uint8_t> writable_content() {
224 std::vector<uint8_t> content_;
225 std::vector<uint8_t> padding_;
226 uint32_t virtual_size_ = 0;
227 uint32_t pointer_to_relocations_ = 0;
228 uint32_t pointer_to_linenumbers_ = 0;
229 uint16_t number_of_relocations_ = 0;
230 uint16_t number_of_linenumbers_ = 0;
231 uint32_t characteristics_ = 0;
232 std::set<PE_SECTION_TYPES> types_ = {PE_SECTION_TYPES::UNKNOWN};