LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
ContentInfo.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PE_CONTENT_INFO_H
16#define LIEF_PE_CONTENT_INFO_H
17
18#include <memory>
19#include <ostream>
20#include <vector>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24
25#include "LIEF/PE/enums.hpp"
27
28
29namespace LIEF::PE {
30
31class Parser;
32class SignatureParser;
33
80class LIEF_API ContentInfo : public Object {
81 friend class Parser;
82 friend class SignatureParser;
83
84 public:
85 class LIEF_API Content : public Object {
86 public:
88 type_(std::move(oid)) {}
89
90 const oid_t& content_type() const {
91 return type_;
92 }
93
94 virtual std::unique_ptr<Content> clone() const = 0;
95 virtual void print(std::ostream& os) const = 0;
96
97 LIEF_API friend std::ostream& operator<<(std::ostream& os,
98 const Content& content) {
99 content.print(os);
100 return os;
101 }
102
103 template<class T>
104 const T* cast() const {
105 static_assert(std::is_base_of_v<Content, T>,
106 "Require ContentInfo inheritance");
107 if (T::classof(this)) {
108 return static_cast<const T*>(this);
109 }
110 return nullptr;
111 }
112
113 template<class T>
114 T* cast() {
115 return const_cast<T*>(static_cast<const Content*>(this)->cast<T>());
116 }
117
118 ~Content() override = default;
119
120 private:
121 oid_t type_;
122 };
125 ContentInfo(ContentInfo&& other) noexcept = default;
127
128 void swap(ContentInfo& other) noexcept;
129
133 return value_->content_type();
134 }
135
137 return *value_;
138 }
139
141 return *value_;
142 }
143
146 std::vector<uint8_t> digest() const;
147
150
151 void accept(Visitor& visitor) const override;
152
153 ~ContentInfo() override = default;
154
155 LIEF_API friend std::ostream& operator<<(std::ostream& os,
156 const ContentInfo& content_info);
157
158 private:
159 std::unique_ptr<Content> value_;
160};
161
162}
163
164
165#endif
Definition ContentInfo.hpp:85
~Content() override=default
const oid_t & content_type() const
Definition ContentInfo.hpp:90
Content(oid_t oid)
Definition ContentInfo.hpp:87
virtual std::unique_ptr< Content > clone() const =0
virtual void print(std::ostream &os) const =0
T * cast()
Definition ContentInfo.hpp:114
const T * cast() const
Definition ContentInfo.hpp:104
friend std::ostream & operator<<(std::ostream &os, const Content &content)
Definition ContentInfo.hpp:97
std::vector< uint8_t > digest() const
Return the digest (authentihash) if the underlying content type is SPC_INDIRECT_DATA_OBJID Otherwise,...
ALGORITHMS digest_algorithm() const
Return the digest used to hash the file.
void accept(Visitor &visitor) const override
ContentInfo(ContentInfo &&other) noexcept=default
ContentInfo(const ContentInfo &other)
const Content & value() const
Definition ContentInfo.hpp:140
oid_t content_type() const
Return the OID that describes the content wrapped by this object. It should match SPC_INDIRECT_DATA_O...
Definition ContentInfo.hpp:132
~ContentInfo() override=default
friend class SignatureParser
Definition ContentInfo.hpp:82
Content & value()
Definition ContentInfo.hpp:136
friend class Parser
Definition ContentInfo.hpp:81
void swap(ContentInfo &other) noexcept
ContentInfo & operator=(ContentInfo other)
friend std::ostream & operator<<(std::ostream &os, const ContentInfo &content_info)
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:53
Definition SignatureParser.hpp:37
Definition Visitor.hpp:211
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:28
std::string oid_t
Definition PE/signature/types.hpp:22
@ T
Definition AcceleratorCodes.hpp:96
#define LIEF_API
Definition visibility.h:44