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