LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PE/LoadConfigurations/CHPEMetadata/Metadata.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_CHPE_METADATA_H
17#define LIEF_PE_LOAD_CONFIGURATION_CHPE_METADATA_H
18#include <memory>
19#include <string>
20#include <cstdint>
21
22#include "LIEF/visibility.h"
23
24namespace LIEF {
25class BinaryStream;
26namespace PE {
27class Parser;
33 public:
34 enum class KIND {
37 UNKNOWN = 0,
38 ARM64, X86,
39 };
40
41 CHPEMetadata() = default;
42 CHPEMetadata(KIND kind, uint32_t version) :
43 kind_(kind), version_(version)
44 {}
45
46 CHPEMetadata(const CHPEMetadata&) = default;
47 CHPEMetadata& operator=(const CHPEMetadata&) = default;
48
49 CHPEMetadata(CHPEMetadata&&) = default;
50 CHPEMetadata& operator=(CHPEMetadata&&) = default;
51
52 virtual std::unique_ptr<CHPEMetadata> clone() const {
53 return std::unique_ptr<CHPEMetadata>(new CHPEMetadata(*this));
54 }
55
56 static std::unique_ptr<CHPEMetadata> parse(Parser& ctx, BinaryStream& stream);
57 KIND kind() const {
60 return kind_;
61 }
62 uint32_t version() const {
65 return version_;
66 }
67
68 virtual std::string to_string() const {
69 return std::string("CHPEMetadata{ version= ") + std::to_string(version_) + "}";
70 }
71
72 template<class T>
73 T* as() {
74 static_assert(std::is_base_of<CHPEMetadata, T>::value,
75 "Require CHPEMetadata inheritance");
76 if (T::classof(this)) {
77 return static_cast<T*>(this);
78 }
79 return nullptr;
80 }
81
82 template<class T>
83 const T* as() const {
84 return const_cast<CHPEMetadata*>(this)->as<T>();
85 }
86
87 LIEF_API friend
88 std::ostream& operator<<(std::ostream& os, const CHPEMetadata& meta)
89 {
90 os << meta.to_string();
91 return os;
92 }
93
94 virtual ~CHPEMetadata() = default;
95
96 protected:
97 KIND kind_ = KIND::UNKNOWN;
98 uint32_t version_ = 0;
99};
100}
101}
102
103#endif
LIEF::BinaryStream
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
LIEF::PE::CHPEMetadata
Base class for any Compiled Hybrid Portable Executable (CHPE) metadata.
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:32
LIEF::PE::CHPEMetadata::version
uint32_t version() const
Version of the structure.
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:64
LIEF::PE::CHPEMetadata::CHPEMetadata
CHPEMetadata(KIND kind, uint32_t version)
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:42
LIEF::PE::CHPEMetadata::operator<<
friend std::ostream & operator<<(std::ostream &os, const CHPEMetadata &meta)
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:88
LIEF::PE::CHPEMetadata::parse
static std::unique_ptr< CHPEMetadata > parse(Parser &ctx, BinaryStream &stream)
LIEF::PE::CHPEMetadata::operator=
CHPEMetadata & operator=(CHPEMetadata &&)=default
LIEF::PE::CHPEMetadata::as
T * as()
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:73
LIEF::PE::CHPEMetadata::~CHPEMetadata
virtual ~CHPEMetadata()=default
LIEF::PE::CHPEMetadata::kind
KIND kind() const
Determine the type of the concrete implementation.
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:59
LIEF::PE::CHPEMetadata::CHPEMetadata
CHPEMetadata(const CHPEMetadata &)=default
LIEF::PE::CHPEMetadata::to_string
virtual std::string to_string() const
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:68
LIEF::PE::CHPEMetadata::as
const T * as() const
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:83
LIEF::PE::CHPEMetadata::CHPEMetadata
CHPEMetadata(CHPEMetadata &&)=default
LIEF::PE::CHPEMetadata::operator=
CHPEMetadata & operator=(const CHPEMetadata &)=default
LIEF::PE::CHPEMetadata::clone
virtual std::unique_ptr< CHPEMetadata > clone() const
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:52
LIEF::PE::CHPEMetadata::CHPEMetadata
CHPEMetadata()=default
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::ACCELERATOR_CODES::T
@ T
Definition AcceleratorCodes.hpp:97
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41