LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
LoadConfiguration.hpp
Go to the documentation of this file.
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}
31class 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 virtual VERSION version() const {
65 return WIN_VERSION;
66 }
67 uint32_t characteristics() const {
73 return characteristics_;
74 }
75 uint32_t size() const {
78 return characteristics_;
79 }
80 uint32_t timedatestamp() const {
83 return timedatestamp_;
84 }
85 uint16_t major_version() const {
88 return major_version_;
89 }
90 uint16_t minor_version() const {
93 return minor_version_;
94 }
95 uint32_t global_flags_clear() const {
99 return global_flags_clear_;
100 }
101 uint32_t global_flags_set() const {
105 return global_flags_set_;
106 }
107 uint32_t critical_section_default_timeout() const {
111 return critical_section_default_timeout_;
112 }
113 uint64_t decommit_free_block_threshold() const {
117 return decommit_free_block_threshold_;
118 }
119 uint64_t decommit_total_free_threshold() const {
123 return decommit_total_free_threshold_;
124 }
125 uint64_t lock_prefix_table() const {
133 return lock_prefix_table_;
134 }
135 uint64_t maximum_allocation_size() const {
138 return maximum_allocation_size_;
139 }
140 uint64_t virtual_memory_threshold() const {
143 return virtual_memory_threshold_;
144 }
145 uint64_t process_affinity_mask() const {
149 return process_affinity_mask_;
150 }
151 uint32_t process_heap_flags() const {
156 return process_heap_flags_;
157 }
158 uint16_t csd_version() const {
161 return csd_version_;
162 }
163 uint16_t reserved1() const {
166 return reserved1_;
167 }
168 uint16_t dependent_load_flags() const {
173 return reserved1_;
174 }
175 uint32_t editlist() const {
178 return editlist_;
179 }
180 uint64_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(uint64_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 template<class T>
273 static const T* cast(const LoadConfiguration* config) {
274 if (config->version() >= T::WIN_VERSION) {
275 return static_cast<const T*>(config);
276 }
277 return nullptr;
278 }
279
280 void accept(Visitor& visitor) const override;
281
282 virtual std::ostream& print(std::ostream& os) const;
283
284 LIEF_API friend std::ostream& operator<<(std::ostream& os, const LoadConfiguration& config);
285
286 protected:
287 uint32_t characteristics_ = 0; // also named size
288 uint32_t timedatestamp_ = 0;
289
290 uint16_t major_version_ = 0;
291 uint16_t minor_version_ = 0;
292
293 uint32_t global_flags_clear_ = 0;
294 uint32_t global_flags_set_ = 0;
295
296 uint32_t critical_section_default_timeout_ = 0;
297
298 uint64_t decommit_free_block_threshold_ = 0;
299 uint64_t decommit_total_free_threshold_ = 0;
300
301 uint64_t lock_prefix_table_ = 0;
302 uint64_t maximum_allocation_size_ = 0;
303 uint64_t virtual_memory_threshold_ = 0;
304 uint64_t process_affinity_mask_ = 0;
305 uint32_t process_heap_flags_ = 0;
306 uint16_t csd_version_ = 0;
307 uint16_t reserved1_ = 0; // named DependentLoadFlags in recent headers
308 uint64_t editlist_ = 0;
309 uint64_t security_cookie_ = 0;
310};
311
312LIEF_API const char* to_string(LoadConfiguration::VERSION e);
313
314}
315}
316
317#endif
Object.hpp
LIEF::PE::LoadConfiguration
Class that represents the default PE's LoadConfiguration
Definition LoadConfiguration.hpp:35
LIEF::PE::LoadConfiguration::editlist
uint32_t editlist() const
Reserved for use by the system.
Definition LoadConfiguration.hpp:177
LIEF::PE::LoadConfiguration::virtual_memory_threshold
void virtual_memory_threshold(uint64_t virtual_memory_threshold)
Definition LoadConfiguration.hpp:232
LIEF::PE::LoadConfiguration::lock_prefix_table
void lock_prefix_table(uint64_t lock_prefix_table)
Definition LoadConfiguration.hpp:224
LIEF::PE::LoadConfiguration::editlist
void editlist(uint32_t editlist)
Definition LoadConfiguration.hpp:256
LIEF::PE::LoadConfiguration::LoadConfiguration
LoadConfiguration()=default
LIEF::PE::LoadConfiguration::characteristics
void characteristics(uint32_t characteristics)
Definition LoadConfiguration.hpp:188
LIEF::PE::LoadConfiguration::characteristics
uint32_t characteristics() const
Characteristics of the structure It usually holds its size.
Definition LoadConfiguration.hpp:72
LIEF::PE::LoadConfiguration::critical_section_default_timeout
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
LIEF::PE::LoadConfiguration::classof
static bool classof(const LoadConfiguration *)
Definition LoadConfiguration.hpp:266
LIEF::PE::LoadConfiguration::security_cookie
uint64_t security_cookie() const
A pointer to a cookie that is used by Visual C++ or GS implementation.
Definition LoadConfiguration.hpp:183
LIEF::PE::LoadConfiguration::decommit_free_block_threshold
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
LIEF::PE::LoadConfiguration::dependent_load_flags
void dependent_load_flags(uint16_t flags)
Definition LoadConfiguration.hpp:252
LIEF::PE::LoadConfiguration::LoadConfiguration
LoadConfiguration(const details::load_configuration< T > &header)
LIEF::PE::LoadConfiguration::reserved1
void reserved1(uint16_t reserved1)
Definition LoadConfiguration.hpp:248
LIEF::PE::LoadConfiguration::process_affinity_mask
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
LIEF::PE::LoadConfiguration::global_flags_set
void global_flags_set(uint32_t global_flags_set)
Definition LoadConfiguration.hpp:208
LIEF::PE::LoadConfiguration::maximum_allocation_size
uint64_t maximum_allocation_size() const
Maximum allocation size, in bytes.
Definition LoadConfiguration.hpp:137
LIEF::PE::LoadConfiguration::operator=
LoadConfiguration & operator=(const LoadConfiguration &)=default
LIEF::PE::LoadConfiguration::version
virtual VERSION version() const
(SDK) Version of the structure
Definition LoadConfiguration.hpp:64
LIEF::PE::LoadConfiguration::print
virtual std::ostream & print(std::ostream &os) const
LIEF::PE::LoadConfiguration::minor_version
uint16_t minor_version() const
Minor version.
Definition LoadConfiguration.hpp:92
LIEF::PE::LoadConfiguration::LoadConfiguration
LoadConfiguration(const LoadConfiguration &)=default
LIEF::PE::LoadConfiguration::timedatestamp
uint32_t timedatestamp() const
Date and time stamp value.
Definition LoadConfiguration.hpp:82
LIEF::PE::LoadConfiguration::size
uint32_t size() const
Size of the current structure which is an alias for characteristics.
Definition LoadConfiguration.hpp:77
LIEF::PE::LoadConfiguration::csd_version
uint16_t csd_version() const
The service pack version identifier.
Definition LoadConfiguration.hpp:160
LIEF::PE::LoadConfiguration::global_flags_set
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
LIEF::PE::LoadConfiguration::virtual_memory_threshold
uint64_t virtual_memory_threshold() const
Maximum virtual memory size, in bytes.
Definition LoadConfiguration.hpp:142
LIEF::PE::LoadConfiguration::accept
void accept(Visitor &visitor) const override
LIEF::PE::LoadConfiguration::critical_section_default_timeout
void critical_section_default_timeout(uint32_t critical_section_default_timeout)
Definition LoadConfiguration.hpp:212
LIEF::PE::LoadConfiguration::decommit_free_block_threshold
void decommit_free_block_threshold(uint64_t decommit_free_block_threshold)
Definition LoadConfiguration.hpp:216
LIEF::PE::LoadConfiguration::maximum_allocation_size
void maximum_allocation_size(uint64_t maximum_allocation_size)
Definition LoadConfiguration.hpp:228
LIEF::PE::LoadConfiguration::decommit_total_free_threshold
uint64_t decommit_total_free_threshold() const
Total amount of free memory, in bytes.
Definition LoadConfiguration.hpp:122
LIEF::PE::LoadConfiguration::lock_prefix_table
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
LIEF::PE::LoadConfiguration::process_heap_flags
void process_heap_flags(uint32_t process_heap_flagsid)
Definition LoadConfiguration.hpp:240
LIEF::PE::LoadConfiguration::cast
static const T * cast(const LoadConfiguration *config)
Definition LoadConfiguration.hpp:273
LIEF::PE::LoadConfiguration::global_flags_clear
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
LIEF::PE::LoadConfiguration::security_cookie
void security_cookie(uint64_t security_cookie)
Definition LoadConfiguration.hpp:260
LIEF::PE::LoadConfiguration::major_version
uint16_t major_version() const
Major Version.
Definition LoadConfiguration.hpp:87
LIEF::PE::LoadConfiguration::major_version
void major_version(uint16_t major_version)
Definition LoadConfiguration.hpp:196
LIEF::PE::LoadConfiguration::process_heap_flags
uint32_t process_heap_flags() const
Process heap flags that correspond to the first argument of the HeapCreate function....
Definition LoadConfiguration.hpp:155
LIEF::PE::LoadConfiguration::dependent_load_flags
uint16_t dependent_load_flags() const
Alias for reserved1.
Definition LoadConfiguration.hpp:172
LIEF::PE::LoadConfiguration::operator<<
friend std::ostream & operator<<(std::ostream &os, const LoadConfiguration &config)
LIEF::PE::LoadConfiguration::minor_version
void minor_version(uint16_t minor_version)
Definition LoadConfiguration.hpp:200
LIEF::PE::LoadConfiguration::VERSION
VERSION
Definition LoadConfiguration.hpp:37
LIEF::PE::LoadConfiguration::~LoadConfiguration
~LoadConfiguration() override=default
LIEF::PE::LoadConfiguration::reserved1
uint16_t reserved1() const
Must be zero.
Definition LoadConfiguration.hpp:165
LIEF::PE::LoadConfiguration::decommit_total_free_threshold
void decommit_total_free_threshold(uint64_t decommit_total_free_threshold)
Definition LoadConfiguration.hpp:220
LIEF::PE::LoadConfiguration::global_flags_clear
void global_flags_clear(uint32_t global_flags_clear)
Definition LoadConfiguration.hpp:204
LIEF::PE::LoadConfiguration::csd_version
void csd_version(uint16_t csd_version)
Definition LoadConfiguration.hpp:244
LIEF::PE::LoadConfiguration::timedatestamp
void timedatestamp(uint32_t timedatestamp)
Definition LoadConfiguration.hpp:192
LIEF::PE::LoadConfiguration::process_affinity_mask
void process_affinity_mask(uint64_t process_affinity_mask)
Definition LoadConfiguration.hpp:236
LIEF::PE::details
Definition CodeIntegrity.hpp:26
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::to_string
const char * to_string(DataDirectory::TYPES e)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
LIEF::PE::details::load_configuration
Definition LoadConfiguration.hpp:29
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42