LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
EnclaveConfiguration.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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_ENCLAVE_CONFIG_H
17#define LIEF_PE_LOAD_CONFIGURATION_ENCLAVE_CONFIG_H
18#include <memory>
19#include <string>
20#include <array>
21
22#include "LIEF/iterators.hpp"
23#include "LIEF/visibility.h"
25
26namespace LIEF {
27class BinaryStream;
28namespace PE {
29class Parser;
30
33 public:
34 static constexpr auto MIN_SIZE = 0x4C; // sizeof(IMAGE_ENCLAVE_CONFIG32)
35
36 static constexpr auto POLICY_DEBUGGABLE = 0x00000001;
37
38 using id_array_t = std::array<uint8_t, 16>;
39
40 using imports_t = std::vector<EnclaveImport>;
43
47
50
51 std::unique_ptr<EnclaveConfiguration> clone() const {
52 return std::unique_ptr<EnclaveConfiguration>(new EnclaveConfiguration(*this));
53 }
54
57 uint32_t size() const {
58 return size_;
59 }
60
75 uint32_t min_required_config_size() const {
76 return min_req_size_;
77 }
78
80 uint32_t policy_flags() const {
81 return policy_flags_;
82 }
83
85 bool is_debuggable() const {
86 return (policy_flags_ & POLICY_DEBUGGABLE) != 0;
87 }
88
91 uint32_t import_list_rva() const {
92 return imports_list_rva_;
93 }
94
97 uint32_t import_entry_size() const {
98 return import_entry_size_;
99 }
100
103 size_t nb_imports() const {
104 return imports_.size();
105 }
106
109 return imports_;
110 }
111
113 return imports_;
114 }
115
118 const id_array_t& family_id() const {
119 return family_id_;
120 }
121
123 const id_array_t& image_id() const {
124 return image_id_;
125 }
126
128 uint32_t image_version() const {
129 return image_version_;
130 }
131
134 uint32_t security_version() const {
135 return security_version_;
136 }
137
140 uint64_t enclave_size() const {
141 return enclave_size_;
142 }
143
145 uint32_t nb_threads() const {
146 return nb_threads_;
147 }
148
151 uint32_t enclave_flags() const {
152 return enclave_flags_;
153 }
154
155 EnclaveConfiguration& size(uint32_t value) {
156 size_ = value;
157 return *this;
158 }
159
161 min_req_size_ = value;
162 return *this;
163 }
164
166 policy_flags_ = value;
167 return *this;
168 }
169
171 imports_list_rva_ = value;
172 return *this;
173 }
174
176 import_entry_size_ = value;
177 return *this;
178 }
179
181 family_id_ = value;
182 return *this;
183 }
184
186 image_id_ = value;
187 return *this;
188 }
189
191 image_version_ = value;
192 return *this;
193 }
194
196 security_version_ = value;
197 return *this;
198 }
199
201 enclave_size_ = value;
202 return *this;
203 }
204
206 nb_threads_ = value;
207 return *this;
208 }
209
211 enclave_flags_ = value;
212 return *this;
213 }
214
215 std::string to_string() const;
216
217 LIEF_API friend
218 std::ostream& operator<<(std::ostream& os, const EnclaveConfiguration& meta)
219 {
220 os << meta.to_string();
221 return os;
222 }
223
225 template<class PE_T>
226 LIEF_LOCAL static std::unique_ptr<EnclaveConfiguration>
227 parse(Parser& ctx, BinaryStream& stream);
228
229 private:
230 uint32_t size_ = 0;
231 uint32_t min_req_size_ = 0;
232 uint32_t policy_flags_ = 0;
233 uint32_t imports_list_rva_ = 0;
234 uint32_t import_entry_size_ = 0;
235 id_array_t family_id_ = {0};
236 id_array_t image_id_ = {0};
237 uint32_t image_version_ = 0;
238 uint32_t security_version_ = 0;
239 uint64_t enclave_size_ = 0;
240 uint32_t nb_threads_ = 0;
241 uint32_t enclave_flags_ = 0;
242
243 imports_t imports_;
244};
245}
246}
247
248#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
friend std::ostream & operator<<(std::ostream &os, const EnclaveConfiguration &meta)
Definition EnclaveConfiguration.hpp:218
std::unique_ptr< EnclaveConfiguration > clone() const
Definition EnclaveConfiguration.hpp:51
uint32_t size() const
The size of the IMAGE_ENCLAVE_CONFIG64/IMAGE_ENCLAVE_CONFIG32 structure, in bytes.
Definition EnclaveConfiguration.hpp:57
size_t nb_imports() const
The number of images in the array of images that the import_list_rva() member points to.
Definition EnclaveConfiguration.hpp:103
ref_iterator< imports_t & > it_imports
Definition EnclaveConfiguration.hpp:41
EnclaveConfiguration & enclave_flags(uint32_t value)
Definition EnclaveConfiguration.hpp:210
uint64_t enclave_size() const
The expected virtual size of the private address range for the enclave, in bytes.
Definition EnclaveConfiguration.hpp:140
EnclaveConfiguration & operator=(EnclaveConfiguration &&)=default
EnclaveConfiguration & min_required_config_size(uint32_t value)
Definition EnclaveConfiguration.hpp:160
static constexpr auto MIN_SIZE
Definition EnclaveConfiguration.hpp:34
const_ref_iterator< const imports_t & > it_const_imports
Definition EnclaveConfiguration.hpp:42
uint32_t import_list_rva() const
The RVA of the array of images that the enclave image may import, with identity information for each ...
Definition EnclaveConfiguration.hpp:91
EnclaveConfiguration & image_version(uint32_t value)
Definition EnclaveConfiguration.hpp:190
EnclaveConfiguration & enclave_size(uint64_t value)
Definition EnclaveConfiguration.hpp:200
uint32_t import_entry_size() const
The size of each image in the array of images that the import_list_rva() member points to.
Definition EnclaveConfiguration.hpp:97
EnclaveConfiguration(const EnclaveConfiguration &)=default
it_const_imports imports() const
Definition EnclaveConfiguration.hpp:112
std::array< uint8_t, 16 > id_array_t
Definition EnclaveConfiguration.hpp:38
EnclaveConfiguration & policy_flags(uint32_t value)
Definition EnclaveConfiguration.hpp:165
uint32_t image_version() const
The version number that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:128
EnclaveConfiguration & image_id(const id_array_t &value)
Definition EnclaveConfiguration.hpp:185
uint32_t nb_threads() const
The maximum number of threads that can be created within the enclave.
Definition EnclaveConfiguration.hpp:145
uint32_t min_required_config_size() const
The minimum size of the IMAGE_ENCLAVE_CONFIG(32,64) structure that the image loader must be able to p...
Definition EnclaveConfiguration.hpp:75
std::vector< EnclaveImport > imports_t
Definition EnclaveConfiguration.hpp:40
EnclaveConfiguration & size(uint32_t value)
Definition EnclaveConfiguration.hpp:155
uint32_t policy_flags() const
A flag that indicates whether the enclave permits debugging.
Definition EnclaveConfiguration.hpp:80
EnclaveConfiguration & import_entry_size(uint32_t value)
Definition EnclaveConfiguration.hpp:175
uint32_t enclave_flags() const
A flag that indicates whether the image is suitable for use as the primary image in the enclave.
Definition EnclaveConfiguration.hpp:151
uint32_t security_version() const
The security version number that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:134
static constexpr auto POLICY_DEBUGGABLE
Definition EnclaveConfiguration.hpp:36
const id_array_t & image_id() const
The image identifier that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:123
std::string to_string() const
EnclaveConfiguration & security_version(uint32_t value)
Definition EnclaveConfiguration.hpp:195
bool is_debuggable() const
Whether this enclave can be debugged.
Definition EnclaveConfiguration.hpp:85
it_imports imports()
Return an iterator over the enclave's imports.
Definition EnclaveConfiguration.hpp:108
EnclaveConfiguration(EnclaveConfiguration &&)=default
EnclaveConfiguration & nb_threads(uint32_t value)
Definition EnclaveConfiguration.hpp:205
const id_array_t & family_id() const
The family identifier that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:118
EnclaveConfiguration & family_id(const id_array_t &value)
Definition EnclaveConfiguration.hpp:180
EnclaveConfiguration & operator=(const EnclaveConfiguration &)=default
EnclaveConfiguration & import_list_rva(uint32_t value)
Definition EnclaveConfiguration.hpp:170
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
Iterator which returns reference on container's values.
Definition iterators.hpp:46
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:40
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:257
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42