LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
EnclaveConfiguration.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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
77 uint32_t min_required_config_size() const {
78 return min_req_size_;
79 }
80
82 uint32_t policy_flags() const {
83 return policy_flags_;
84 }
85
87 bool is_debuggable() const {
88 return (policy_flags_ & POLICY_DEBUGGABLE) != 0;
89 }
90
93 uint32_t import_list_rva() const {
94 return imports_list_rva_;
95 }
96
99 uint32_t import_entry_size() const {
100 return import_entry_size_;
101 }
102
105 size_t nb_imports() const {
106 return imports_.size();
107 }
108
111 return imports_;
112 }
113
115 return imports_;
116 }
117
120 const id_array_t& family_id() const {
121 return family_id_;
122 }
123
125 const id_array_t& image_id() const {
126 return image_id_;
127 }
128
130 uint32_t image_version() const {
131 return image_version_;
132 }
133
136 uint32_t security_version() const {
137 return security_version_;
138 }
139
142 uint64_t enclave_size() const {
143 return enclave_size_;
144 }
145
147 uint32_t nb_threads() const {
148 return nb_threads_;
149 }
150
153 uint32_t enclave_flags() const {
154 return enclave_flags_;
155 }
156
157 EnclaveConfiguration& size(uint32_t value) {
158 size_ = value;
159 return *this;
160 }
161
163 min_req_size_ = value;
164 return *this;
165 }
166
168 policy_flags_ = value;
169 return *this;
170 }
171
173 imports_list_rva_ = value;
174 return *this;
175 }
176
178 import_entry_size_ = value;
179 return *this;
180 }
181
183 family_id_ = value;
184 return *this;
185 }
186
188 image_id_ = value;
189 return *this;
190 }
191
193 image_version_ = value;
194 return *this;
195 }
196
198 security_version_ = value;
199 return *this;
200 }
201
203 enclave_size_ = value;
204 return *this;
205 }
206
208 nb_threads_ = value;
209 return *this;
210 }
211
213 enclave_flags_ = value;
214 return *this;
215 }
216
217 std::string to_string() const;
218
219 LIEF_API friend std::ostream& operator<<(std::ostream& os,
220 const EnclaveConfiguration& meta) {
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:105
ref_iterator< imports_t & > it_imports
Definition EnclaveConfiguration.hpp:42
EnclaveConfiguration & enclave_flags(uint32_t value)
Definition EnclaveConfiguration.hpp:212
uint64_t enclave_size() const
The expected virtual size of the private address range for the enclave, in bytes.
Definition EnclaveConfiguration.hpp:142
EnclaveConfiguration & operator=(EnclaveConfiguration &&)=default
EnclaveConfiguration & min_required_config_size(uint32_t value)
Definition EnclaveConfiguration.hpp:162
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:93
EnclaveConfiguration & image_version(uint32_t value)
Definition EnclaveConfiguration.hpp:192
EnclaveConfiguration & enclave_size(uint64_t value)
Definition EnclaveConfiguration.hpp:202
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:99
EnclaveConfiguration(const EnclaveConfiguration &)=default
it_const_imports imports() const
Definition EnclaveConfiguration.hpp:114
std::array< uint8_t, 16 > id_array_t
Definition EnclaveConfiguration.hpp:39
EnclaveConfiguration & policy_flags(uint32_t value)
Definition EnclaveConfiguration.hpp:167
uint32_t image_version() const
The version number that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:130
EnclaveConfiguration & image_id(const id_array_t &value)
Definition EnclaveConfiguration.hpp:187
uint32_t nb_threads() const
The maximum number of threads that can be created within the enclave.
Definition EnclaveConfiguration.hpp:147
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:77
std::vector< EnclaveImport > imports_t
Definition EnclaveConfiguration.hpp:41
EnclaveConfiguration & size(uint32_t value)
Definition EnclaveConfiguration.hpp:157
uint32_t policy_flags() const
A flag that indicates whether the enclave permits debugging.
Definition EnclaveConfiguration.hpp:82
EnclaveConfiguration & import_entry_size(uint32_t value)
Definition EnclaveConfiguration.hpp:177
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:153
uint32_t security_version() const
The security version number that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:136
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:125
std::string to_string() const
EnclaveConfiguration & security_version(uint32_t value)
Definition EnclaveConfiguration.hpp:197
bool is_debuggable() const
Whether this enclave can be debugged.
Definition EnclaveConfiguration.hpp:87
it_imports imports()
Return an iterator over the enclave's imports.
Definition EnclaveConfiguration.hpp:110
EnclaveConfiguration(EnclaveConfiguration &&)=default
EnclaveConfiguration & nb_threads(uint32_t value)
Definition EnclaveConfiguration.hpp:207
const id_array_t & family_id() const
The family identifier that the author of the enclave assigned to the enclave.
Definition EnclaveConfiguration.hpp:120
EnclaveConfiguration & family_id(const id_array_t &value)
Definition EnclaveConfiguration.hpp:182
EnclaveConfiguration & operator=(const EnclaveConfiguration &)=default
EnclaveConfiguration & import_list_rva(uint32_t value)
Definition EnclaveConfiguration.hpp:172
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:52
Iterator which returns reference on container's values.
Definition iterators.hpp:45
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:286
#define LIEF_API
Definition visibility.h:43
#define LIEF_LOCAL
Definition visibility.h:44