LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
LoadConfiguration.hpp
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_PE_LOAD_CONFIGURATION_H
17#define LIEF_PE_LOAD_CONFIGURATION_H
18#include <ostream>
19#include <cstdint>
20
21#include "LIEF/Object.hpp"
22#include "LIEF/visibility.h"
23
24namespace LIEF {
25namespace PE {
26
27namespace details {
28template<class T>
30}
31
35class LIEF_API LoadConfiguration : public Object {
36 public:
37 enum class VERSION {
38 UNKNOWN = 0,
39 SEH,
40 WIN_8_1,
41 WIN_10_0_9879,
42 WIN_10_0_14286,
43 WIN_10_0_14383,
44 WIN_10_0_14901,
45 WIN_10_0_15002,
46 WIN_10_0_16237,
47 WIN_10_0_18362,
48 WIN_10_0_19534,
49 WIN_10_0_MSVC_2019,
50 WIN_10_0_MSVC_2019_16,
51 };
52
53 static constexpr VERSION WIN_VERSION = VERSION::UNKNOWN;
54
55 LoadConfiguration() = default;
56
57 template<class T>
58 LIEF_LOCAL LoadConfiguration(const details::load_configuration<T>& header);
59
60 LoadConfiguration& operator=(const LoadConfiguration&) = default;
61 LoadConfiguration(const LoadConfiguration&) = default;
62
64 virtual VERSION version() const {
65 return WIN_VERSION;
66 }
67
72 uint32_t characteristics() const {
73 return characteristics_;
74 }
75
77 uint32_t size() const {
78 return characteristics_;
79 }
80
82 uint32_t timedatestamp() const {
83 return timedatestamp_;
84 }
85
87 uint16_t major_version() const {
88 return major_version_;
89 }
90
92 uint16_t minor_version() const {
93 return minor_version_;
94 }
95
98 uint32_t global_flags_clear() const {
99 return global_flags_clear_;
100 }
101
104 uint32_t global_flags_set() const {
105 return global_flags_set_;
106 }
107
111 return critical_section_default_timeout_;
112 }
113
117 return decommit_free_block_threshold_;
118 }
119
123 return decommit_total_free_threshold_;
124 }
125
132 uint64_t lock_prefix_table() const {
133 return lock_prefix_table_;
134 }
135
137 uint64_t maximum_allocation_size() const {
138 return maximum_allocation_size_;
139 }
140
142 uint64_t virtual_memory_threshold() const {
143 return virtual_memory_threshold_;
144 }
145
148 uint64_t process_affinity_mask() const {
149 return process_affinity_mask_;
150 }
151
155 uint32_t process_heap_flags() const {
156 return process_heap_flags_;
157 }
158
160 uint16_t csd_version() const {
161 return csd_version_;
162 }
163
165 uint16_t reserved1() const {
166 return reserved1_;
167 }
168
172 uint16_t dependent_load_flags() const {
173 return reserved1_;
174 }
175
177 uint32_t editlist() const {
178 return editlist_;
179 }
180
183 uint32_t security_cookie() const {
184 return security_cookie_;
185 }
186
187
188 void characteristics(uint32_t characteristics) {
189 characteristics_ = characteristics;
190 }
191
192 void timedatestamp(uint32_t timedatestamp) {
193 timedatestamp_ = timedatestamp;
194 }
195
196 void major_version(uint16_t major_version) {
197 major_version_ = major_version;
198 }
199
200 void minor_version(uint16_t minor_version) {
201 minor_version_ = minor_version;
202 }
203
204 void global_flags_clear(uint32_t global_flags_clear) {
205 global_flags_clear_ = global_flags_clear;
206 }
207
208 void global_flags_set(uint32_t global_flags_set) {
209 global_flags_set_ = global_flags_set;
210 }
211
212 void critical_section_default_timeout(uint32_t critical_section_default_timeout) {
213 critical_section_default_timeout_ = critical_section_default_timeout;
214 }
215
216 void decommit_free_block_threshold(uint64_t decommit_free_block_threshold) {
217 decommit_free_block_threshold_ = decommit_free_block_threshold;
218 }
219
220 void decommit_total_free_threshold(uint64_t decommit_total_free_threshold) {
221 decommit_total_free_threshold_ = decommit_total_free_threshold;
222 }
223
224 void lock_prefix_table(uint64_t lock_prefix_table) {
225 lock_prefix_table_ = lock_prefix_table;
226 }
227
228 void maximum_allocation_size(uint64_t maximum_allocation_size) {
229 maximum_allocation_size_ = maximum_allocation_size;
230 }
231
232 void virtual_memory_threshold(uint64_t virtual_memory_threshold) {
233 virtual_memory_threshold_ = virtual_memory_threshold;
234 }
235
236 void process_affinity_mask(uint64_t process_affinity_mask) {
237 process_affinity_mask_ = process_affinity_mask;
238 }
239
240 void process_heap_flags(uint32_t process_heap_flagsid) {
241 process_heap_flags_ = process_heap_flagsid;
242 }
243
244 void csd_version(uint16_t csd_version) {
245 csd_version_ = csd_version;
246 }
247
248 void reserved1(uint16_t reserved1) {
249 reserved1_ = reserved1;
250 }
251
252 void dependent_load_flags(uint16_t flags) {
253 reserved1(flags);
254 }
255
256 void editlist(uint32_t editlist) {
257 editlist_ = editlist;
258 }
259
260 void security_cookie(uint32_t security_cookie) {
261 security_cookie_ = security_cookie;
262 }
263
264 ~LoadConfiguration() override = default;
265
266 static bool classof(const LoadConfiguration* /*config*/) {
267 // This is the base class, thus all the other
268 // classes can be safely casted into this one.
269 return true;
270 }
271
272 void accept(Visitor& visitor) const override;
273
274 virtual std::ostream& print(std::ostream& os) const;
275
276 LIEF_API friend std::ostream& operator<<(std::ostream& os, const LoadConfiguration& config);
277
278 protected:
279 uint32_t characteristics_ = 0; // also named size
280 uint32_t timedatestamp_ = 0;
281
282 uint16_t major_version_ = 0;
283 uint16_t minor_version_ = 0;
284
285 uint32_t global_flags_clear_ = 0;
286 uint32_t global_flags_set_ = 0;
287
288 uint32_t critical_section_default_timeout_ = 0;
289
290 uint64_t decommit_free_block_threshold_ = 0;
291 uint64_t decommit_total_free_threshold_ = 0;
292
293 uint64_t lock_prefix_table_ = 0;
294 uint64_t maximum_allocation_size_ = 0;
295 uint64_t virtual_memory_threshold_ = 0;
296 uint64_t process_affinity_mask_ = 0;
297 uint32_t process_heap_flags_ = 0;
298 uint16_t csd_version_ = 0;
299 uint16_t reserved1_ = 0; // named DependentLoadFlags in recent headers
300 uint64_t editlist_ = 0;
301 uint64_t security_cookie_ = 0;
302};
303
304LIEF_API const char* to_string(LoadConfiguration::VERSION e);
305
306}
307}
308
309#endif
Definition Object.hpp:25
Class that represents the default PE's LoadConfiguration
Definition LoadConfiguration.hpp:35
uint32_t editlist() const
Reserved for use by the system.
Definition LoadConfiguration.hpp:177
uint32_t characteristics() const
Characteristics of the structure It usually holds its size.
Definition LoadConfiguration.hpp:72
uint32_t critical_section_default_timeout() const
The default timeout value to use for this process’s critical sections that are abandoned.
Definition LoadConfiguration.hpp:110
uint32_t security_cookie() const
A pointer to a cookie that is used by Visual C++ or GS implementation.
Definition LoadConfiguration.hpp:183
uint64_t decommit_free_block_threshold() const
Memory that must be freed before it is returned to the system, in bytes.
Definition LoadConfiguration.hpp:116
uint64_t process_affinity_mask() const
Setting this field to a non-zero value is equivalent to calling SetProcessAffinityMask with this valu...
Definition LoadConfiguration.hpp:148
uint64_t maximum_allocation_size() const
Maximum allocation size, in bytes.
Definition LoadConfiguration.hpp:137
virtual VERSION version() const
(SDK) Version of the structure
Definition LoadConfiguration.hpp:64
uint16_t minor_version() const
Minor version.
Definition LoadConfiguration.hpp:92
uint32_t timedatestamp() const
Date and time stamp value.
Definition LoadConfiguration.hpp:82
uint32_t size() const
Size of the current structure which is an alias for characteristics.
Definition LoadConfiguration.hpp:77
uint16_t csd_version() const
The service pack version identifier.
Definition LoadConfiguration.hpp:160
uint32_t global_flags_set() const
The global loader flags to set for this process as the loader starts the process.
Definition LoadConfiguration.hpp:104
uint64_t virtual_memory_threshold() const
Maximum virtual memory size, in bytes.
Definition LoadConfiguration.hpp:142
uint64_t decommit_total_free_threshold() const
Total amount of free memory, in bytes.
Definition LoadConfiguration.hpp:122
uint64_t lock_prefix_table() const
The VA of a list of addresses where the LOCK prefix is used so that they can be replaced with NOP on ...
Definition LoadConfiguration.hpp:132
uint32_t global_flags_clear() const
The global loader flags to clear for this process as the loader start the process.
Definition LoadConfiguration.hpp:98
uint16_t major_version() const
Major Version.
Definition LoadConfiguration.hpp:87
uint32_t process_heap_flags() const
Process heap flags that correspond to the first argument of the HeapCreate function....
Definition LoadConfiguration.hpp:155
uint16_t dependent_load_flags() const
Alias for reserved1.
Definition LoadConfiguration.hpp:172
uint16_t reserved1() const
Must be zero.
Definition LoadConfiguration.hpp:165
LIEF namespace.
Definition Abstract/Binary.hpp:32
Definition LoadConfiguration.hpp:29