48 static constexpr size_t MAX_SECTION_NAME = 8;
50 enum class CHARACTERISTICS: uint64_t {
51 TYPE_NO_PAD = 0x00000008,
52 CNT_CODE = 0x00000020,
53 CNT_INITIALIZED_DATA = 0x00000040,
54 CNT_UNINITIALIZED_DATA = 0x00000080,
55 LNK_OTHER = 0x00000100,
56 LNK_INFO = 0x00000200,
57 LNK_REMOVE = 0x00000800,
58 LNK_COMDAT = 0x00001000,
60 MEM_PURGEABLE = 0x00010000,
61 MEM_16BIT = 0x00020000,
62 MEM_LOCKED = 0x00040000,
63 MEM_PRELOAD = 0x00080000,
64 ALIGN_1BYTES = 0x00100000,
65 ALIGN_2BYTES = 0x00200000,
66 ALIGN_4BYTES = 0x00300000,
67 ALIGN_8BYTES = 0x00400000,
68 ALIGN_16BYTES = 0x00500000,
69 ALIGN_32BYTES = 0x00600000,
70 ALIGN_64BYTES = 0x00700000,
71 ALIGN_128BYTES = 0x00800000,
72 ALIGN_256BYTES = 0x00900000,
73 ALIGN_512BYTES = 0x00A00000,
74 ALIGN_1024BYTES = 0x00B00000,
75 ALIGN_2048BYTES = 0x00C00000,
76 ALIGN_4096BYTES = 0x00D00000,
77 ALIGN_8192BYTES = 0x00E00000,
78 LNK_NRELOC_OVFL = 0x01000000,
79 MEM_DISCARDABLE = 0x02000000,
80 MEM_NOT_CACHED = 0x04000000,
81 MEM_NOT_PAGED = 0x08000000,
82 MEM_SHARED = 0x10000000,
83 MEM_EXECUTE = 0x20000000,
84 MEM_READ = 0x40000000,
85 MEM_WRITE = 0x80000000
88 Section(
const details::pe_section& header);
90 Section(
const std::vector<uint8_t>& data,
91 const std::string& name =
"", uint32_t characteristics = 0);
92 Section(
const std::string& name);
105 return virtual_size_;
109 span<const uint8_t>
content()
const override {
127 return pointer_to_relocations_;
134 return pointer_to_linenumbers_;
139 return number_of_relocations_;
144 return number_of_linenumbers_;
151 return characteristics_;
158 const std::set<PE_SECTION_TYPES>&
types()
const;
162 return (characteristics() &
static_cast<size_t>(c)) > 0;
170 void content(
const std::vector<uint8_t>& data)
override;
172 void name(std::string name)
override;
174 void virtual_size(uint32_t virtual_sz) {
175 virtual_size_ = virtual_sz;
178 void pointerto_raw_data(uint32_t ptr);
180 void pointerto_relocation(uint32_t ptr) {
181 pointer_to_relocations_ = ptr;
184 void pointerto_line_numbers(uint32_t ptr) {
185 pointer_to_linenumbers_ = ptr;
188 void numberof_relocations(uint16_t nb) {
189 number_of_relocations_ = nb;
192 void numberof_line_numbers(uint16_t nb) {
193 number_of_linenumbers_ = nb;
196 void sizeof_raw_data(uint32_t sizeOfRawData);
198 void characteristics(uint32_t characteristics) {
199 characteristics_ = characteristics;
202 void type(PE_SECTION_TYPES type);
203 void add_type(PE_SECTION_TYPES type);
204 void remove_type(PE_SECTION_TYPES type);
206 Section& remove_characteristic(CHARACTERISTICS characteristic) {
207 characteristics_ &= ~static_cast<size_t>(characteristic);
211 Section& add_characteristic(CHARACTERISTICS characteristic) {
212 characteristics_ |=
static_cast<size_t>(characteristic);
216 void accept(Visitor& visitor)
const override;
218 LIEF_API
friend std::ostream& operator<<(std::ostream& os,
const Section& section);
221 span<uint8_t> writable_content() {
225 std::vector<uint8_t> content_;
226 std::vector<uint8_t> padding_;
227 uint32_t virtual_size_ = 0;
228 uint32_t pointer_to_relocations_ = 0;
229 uint32_t pointer_to_linenumbers_ = 0;
230 uint16_t number_of_relocations_ = 0;
231 uint16_t number_of_linenumbers_ = 0;
232 uint32_t characteristics_ = 0;
233 std::set<PE_SECTION_TYPES> types_ = {PE_SECTION_TYPES::UNKNOWN};