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;
28
33 public:
34
36 enum class KIND {
39 };
40
41 CHPEMetadata() = default;
43 kind_(kind), version_(version)
44 {}
45
46 CHPEMetadata(const CHPEMetadata&) = default;
48
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
59 KIND kind() const {
60 return kind_;
61 }
62
64 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
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
uint32_t version() const
Version of the structure.
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:64
CHPEMetadata(KIND kind, uint32_t version)
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:42
friend std::ostream & operator<<(std::ostream &os, const CHPEMetadata &meta)
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:88
static std::unique_ptr< CHPEMetadata > parse(Parser &ctx, BinaryStream &stream)
CHPEMetadata & operator=(CHPEMetadata &&)=default
T * as()
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:73
virtual ~CHPEMetadata()=default
KIND kind() const
Determine the type of the concrete implementation.
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:59
CHPEMetadata(const CHPEMetadata &)=default
virtual std::string to_string() const
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:68
const T * as() const
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:83
KIND
Discriminator for the subclasses.
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:36
@ UNKNOWN
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:37
@ ARM64
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:38
@ X86
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:38
CHPEMetadata(CHPEMetadata &&)=default
CHPEMetadata & operator=(const CHPEMetadata &)=default
virtual std::unique_ptr< CHPEMetadata > clone() const
Definition PE/LoadConfigurations/CHPEMetadata/Metadata.hpp:52
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41