LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
EnclaveImport.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_IMPORT_H
17#define LIEF_PE_LOAD_CONFIGURATION_ENCLAVE_IMPORT_H
18#include <string_view>
19#include <array>
20#include <string>
21
22#include "LIEF/errors.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
26class BinaryStream;
27namespace PE {
28class Parser;
30
33 public:
34 using short_id_t = std::array<uint8_t, 16>;
35 using long_id_t = std::array<uint8_t, 32>;
36
37 enum class TYPE : uint32_t {
40 NONE = 0x00000000,
41
44 UNIQUE_ID = 0x00000001,
45
50 AUTHOR_ID = 0x00000002,
51
54 FAMILY_ID = 0x00000003,
55
58 IMAGE_ID = 0x00000004,
59 };
60
61 EnclaveImport() = default;
62 EnclaveImport(const EnclaveImport&) = default;
64
67
70 TYPE type() const {
71 return type_;
72 }
73
79 uint32_t min_security_version() const {
80 return min_security_version_;
81 }
82
87 return id_;
88 }
89
92 return family_id_;
93 }
94
97 return image_id_;
98 }
99
102 uint32_t import_name_rva() const {
103 return import_name_rva_;
104 }
105
107 std::string_view import_name() const LIEF_LIFETIMEBOUND {
108 return import_name_;
109 }
110
112 uint32_t reserved() const {
113 return reserved_;
114 }
115
117 type_ = ty;
118 return *this;
119 }
120
122 min_security_version_ = value;
123 return *this;
124 }
125
127 id_ = value;
128 return *this;
129 }
130
132 family_id_ = value;
133 return *this;
134 }
135
137 image_id_ = value;
138 return *this;
139 }
140
142 import_name_rva_ = value;
143 return *this;
144 }
145
147 reserved_ = value;
148 return *this;
149 }
150
152 import_name_ = std::move(name);
153 return *this;
154 }
155
156 std::string to_string() const;
157
158 LIEF_API friend std::ostream& operator<<(std::ostream& os,
159 const EnclaveImport& meta) {
160 os << meta.to_string();
161 return os;
162 }
163
165 LIEF_LOCAL static result<EnclaveImport> parse(Parser& ctx, BinaryStream& stream);
166
167 private:
168 TYPE type_ = TYPE::NONE;
169 uint32_t min_security_version_ = 0;
170 long_id_t id_ = {0};
171 short_id_t family_id_ = {0};
172 short_id_t image_id_ = {0};
173 uint32_t import_name_rva_ = 0;
174 uint32_t reserved_ = 0;
175
176 std::string import_name_;
177};
178
180
181}
182}
183
184#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:35
This class represents the enclave configuration.
Definition EnclaveConfiguration.hpp:32
EnclaveImport & operator=(const EnclaveImport &)=default
std::array< uint8_t, 32 > long_id_t
Definition EnclaveImport.hpp:35
std::string_view import_name() const
Resolved import name.
Definition EnclaveImport.hpp:107
TYPE type() const
The type of identifier of the image that must match the value in the import record.
Definition EnclaveImport.hpp:70
uint32_t import_name_rva() const
The relative virtual address of a NULL-terminated string that contains the same value found in the im...
Definition EnclaveImport.hpp:102
EnclaveImport & type(TYPE ty)
Definition EnclaveImport.hpp:116
EnclaveImport & import_name(std::string name)
Definition EnclaveImport.hpp:151
const long_id_t & id() const
The unique identifier of the primary module for the enclave, if the type() is TYPE::UNIQUE_ID....
Definition EnclaveImport.hpp:86
EnclaveImport & operator=(EnclaveImport &&)=default
uint32_t min_security_version() const
The minimum enclave security version that each image must have for the image to be imported successfu...
Definition EnclaveImport.hpp:79
const short_id_t & image_id() const
The image identifier of the primary module for the enclave.
Definition EnclaveImport.hpp:96
const short_id_t & family_id() const
The family identifier of the primary module for the enclave.
Definition EnclaveImport.hpp:91
std::array< uint8_t, 16 > short_id_t
Definition EnclaveImport.hpp:34
uint32_t reserved() const
Reserved. Should be 0.
Definition EnclaveImport.hpp:112
EnclaveImport(const EnclaveImport &)=default
friend std::ostream & operator<<(std::ostream &os, const EnclaveImport &meta)
Definition EnclaveImport.hpp:158
EnclaveImport & family_id(const short_id_t &value)
Definition EnclaveImport.hpp:131
EnclaveImport & min_security_version(uint32_t value)
Definition EnclaveImport.hpp:121
std::string to_string() const
EnclaveImport & import_name_rva(uint32_t value)
Definition EnclaveImport.hpp:141
EnclaveImport(EnclaveImport &&)=default
TYPE
Definition EnclaveImport.hpp:37
EnclaveImport & image_id(const short_id_t &value)
Definition EnclaveImport.hpp:136
EnclaveImport & id(const long_id_t &value)
Definition EnclaveImport.hpp:126
EnclaveImport & reserved(uint32_t value)
Definition EnclaveImport.hpp:146
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:53
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(CODE_PAGES e)
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46