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 static constexpr auto POLICY_STRICT_MEMORY = 0x00000002;
38
39 using id_array_t = std::array<uint8_t, 16>;
40
41 using imports_t = std::vector<EnclaveImport>;
44
48
51
52 std::unique_ptr<EnclaveConfiguration> clone() const {
53 return std::unique_ptr<EnclaveConfiguration>(new EnclaveConfiguration(*this));
54 }
55
58 uint32_t size() const {
59 return size_;
60 }
61
76 uint32_t min_required_config_size() const {
77 return min_req_size_;
78 }
79
81 uint32_t policy_flags() const {
82 return policy_flags_;
83 }
84
86 bool is_debuggable() const {
87 return (policy_flags_ & POLICY_DEBUGGABLE) != 0;
88 }
89
92 uint32_t import_list_rva() const {
93 return imports_list_rva_;
94 }
95
98 uint32_t import_entry_size() const {
99 return import_entry_size_;
100 }
101
104 size_t nb_imports() const {
105 return imports_.size();
106 }
107
110 return imports_;
111 }
112
114 return imports_;
115 }
116
119 const id_array_t& family_id() const {
120 return family_id_;
121 }
122
124 const id_array_t& image_id() const {
125 return image_id_;
126 }
127
129 uint32_t image_version() const {
130 return image_version_;
131 }
132
135 uint32_t security_version() const {
136 return security_version_;
137 }
138
141 uint64_t enclave_size() const {
142 return enclave_size_;
143 }
144
146 uint32_t nb_threads() const {
147 return nb_threads_;
148 }
149
152 uint32_t enclave_flags() const {
153 return enclave_flags_;
154 }
155
156 EnclaveConfiguration& size(uint32_t value) {
157 size_ = value;
158 return *this;
159 }
160
162 min_req_size_ = value;
163 return *this;
164 }
165
167 policy_flags_ = value;
168 return *this;
169 }
170
172 imports_list_rva_ = value;
173 return *this;
174 }
175
177 import_entry_size_ = value;
178 return *this;
179 }
180
182 family_id_ = value;
183 return *this;
184 }
185
187 image_id_ = value;
188 return *this;
189 }
190
192 image_version_ = value;
193 return *this;
194 }
195
197 security_version_ = value;
198 return *this;
199 }
200
202 enclave_size_ = value;
203 return *this;
204 }
205
207 nb_threads_ = value;
208 return *this;
209 }
210
212 enclave_flags_ = value;
213 return *this;
214 }
215
216 std::string to_string() const;
217
218 LIEF_API friend
219 std::ostream& operator<<(std::ostream& os, const EnclaveConfiguration& meta)
220 {
221 os << meta.to_string();
222 return os;
223 }
224
226 template<class PE_T>
227 LIEF_LOCAL static std::unique_ptr<EnclaveConfiguration>
228 parse(Parser& ctx, BinaryStream& stream);
229
230 private:
231 uint32_t size_ = 0;
232 uint32_t min_req_size_ = 0;
233 uint32_t policy_flags_ = 0;
234 uint32_t imports_list_rva_ = 0;
235 uint32_t import_entry_size_ = 0;
236 id_array_t family_id_ = {0};
237 id_array_t image_id_ = {0};
238 uint32_t image_version_ = 0;
239 uint32_t security_version_ = 0;
240 uint64_t enclave_size_ = 0;
241 uint32_t nb_threads_ = 0;
242 uint32_t enclave_flags_ = 0;
243
244 imports_t imports_;
245};
246}
247}
248
249#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:219
std::unique_ptr< EnclaveConfiguration > clone() const
Definition EnclaveConfiguration.hpp:52
uint32_t size() const
The size of the IMAGE_ENCLAVE_CONFIG64/IMAGE_ENCLAVE_CONFIG32 structure, in bytes.
Definition EnclaveConfiguration.hpp:58
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:104
ref_iterator< imports_t & > it_imports
Definition EnclaveConfiguration.hpp:42
EnclaveConfiguration & enclave_flags(uint32_t value)
Definition EnclaveConfiguration.hpp:211
uint64_t enclave_size() const
The expected virtual size of the private address range for the enclave, in bytes.
Definition EnclaveConfiguration.hpp:141
EnclaveConfiguration & operator=(EnclaveConfiguration &&)=default
EnclaveConfiguration & min_required_config_size(uint32_t value)
Definition EnclaveConfiguration.hpp:161
static constexpr auto MIN_SIZE
Definition EnclaveConfiguration.hpp:34
const_ref_iterator< const imports_t & > it_const_imports
Definition EnclaveConfiguration.hpp:43
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:92
EnclaveConfiguration & image_version(uint32_t value)
Definition EnclaveConfiguration.hpp:191
EnclaveConfiguration & enclave_size(uint64_t value)
Definition EnclaveConfiguration.hpp:201
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:98
EnclaveConfiguration(const EnclaveConfiguration &)=default
it_const_imports imports() const
Definition EnclaveConfiguration.hpp:113
std::array< uint8_t, 16 > id_array_t
Definition EnclaveConfiguration.hpp:39
EnclaveConfiguration & policy_flags(uint32_t value)
Definition EnclaveConfiguration.hpp:166
uint32_t image_version() const
The version number that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:129
EnclaveConfiguration & image_id(const id_array_t &value)
Definition EnclaveConfiguration.hpp:186
uint32_t nb_threads() const
The maximum number of threads that can be created within the enclave.
Definition EnclaveConfiguration.hpp:146
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:76
std::vector< EnclaveImport > imports_t
Definition EnclaveConfiguration.hpp:41
EnclaveConfiguration & size(uint32_t value)
Definition EnclaveConfiguration.hpp:156
uint32_t policy_flags() const
A flag that indicates whether the enclave permits debugging.
Definition EnclaveConfiguration.hpp:81
EnclaveConfiguration & import_entry_size(uint32_t value)
Definition EnclaveConfiguration.hpp:176
static constexpr auto POLICY_STRICT_MEMORY
Definition EnclaveConfiguration.hpp:37
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:152
uint32_t security_version() const
The security version number that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:135
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:124
std::string to_string() const
EnclaveConfiguration & security_version(uint32_t value)
Definition EnclaveConfiguration.hpp:196
bool is_debuggable() const
Whether this enclave can be debugged.
Definition EnclaveConfiguration.hpp:86
it_imports imports()
Return an iterator over the enclave's imports.
Definition EnclaveConfiguration.hpp:109
EnclaveConfiguration(EnclaveConfiguration &&)=default
EnclaveConfiguration & nb_threads(uint32_t value)
Definition EnclaveConfiguration.hpp:206
const id_array_t & family_id() const
The family identifier that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:119
EnclaveConfiguration & family_id(const id_array_t &value)
Definition EnclaveConfiguration.hpp:181
EnclaveConfiguration & operator=(const EnclaveConfiguration &)=default
EnclaveConfiguration & import_list_rva(uint32_t value)
Definition EnclaveConfiguration.hpp:171
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