LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
ContentInfo.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_CONTENT_INFO_H
17#define LIEF_PE_CONTENT_INFO_H
18
19#include <vector>
20#include <ostream>
21#include <memory>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25
27#include "LIEF/PE/enums.hpp"
28
29namespace LIEF {
30namespace PE {
31
32class Parser;
33class SignatureParser;
34
81class LIEF_API ContentInfo : public Object {
82 friend class Parser;
83 friend class SignatureParser;
84
85 public:
86 class Content : public Object {
87 public:
89 type_(std::move(oid)) {}
90
91 const oid_t& content_type() const {
92 return type_;
93 }
94
95 virtual std::unique_ptr<Content> clone() const = 0;
96 virtual void print(std::ostream& os) const = 0;
97
98 LIEF_API friend std::ostream& operator<<(std::ostream& os,
99 const Content& content) {
100 content.print(os);
101 return os;
102 }
103
104 template<class T>
105 const T* cast() const {
106 static_assert(std::is_base_of<Content, T>::value,
107 "Require ContentInfo inheritance");
108 if (T::classof(this)) {
109 return static_cast<const T*>(this);
110 }
111 return nullptr;
112 }
113
114 template<class T>
115 T* cast() {
116 return const_cast<T*>(static_cast<const Content*>(this)->cast<T>());
117 }
118
119 ~Content() override = default;
120
121 private:
122 oid_t type_;
123 };
126 ContentInfo(ContentInfo&& other) noexcept = default;
128
129 void swap(ContentInfo& other) noexcept;
130
134 return value_->content_type();
135 }
136
138 return *value_;
139 }
140
141 const Content& value() const {
142 return *value_;
143 }
144
147 std::vector<uint8_t> digest() const;
148
151
152 void accept(Visitor& visitor) const override;
153
154 ~ContentInfo() override = default;
155
156 LIEF_API friend std::ostream& operator<<(std::ostream& os,
157 const ContentInfo& content_info);
158
159 private:
160 std::unique_ptr<Content> value_;
161};
162
163}
164}
165
166#endif
Definition ContentInfo.hpp:86
~Content() override=default
const oid_t & content_type() const
Definition ContentInfo.hpp:91
Content(oid_t oid)
Definition ContentInfo.hpp:88
virtual std::unique_ptr< Content > clone() const =0
virtual void print(std::ostream &os) const =0
T * cast()
Definition ContentInfo.hpp:115
const T * cast() const
Definition ContentInfo.hpp:105
friend std::ostream & operator<<(std::ostream &os, const Content &content)
Definition ContentInfo.hpp:98
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:141
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:133
~ContentInfo() override=default
friend class SignatureParser
Definition ContentInfo.hpp:83
Content & value()
Definition ContentInfo.hpp:137
friend class Parser
Definition ContentInfo.hpp:82
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:52
Definition SignatureParser.hpp:37
Definition Visitor.hpp:212
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:28
std::string oid_t
Definition PE/signature/types.hpp:23
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:40
Definition string.h:155
#define LIEF_API
Definition visibility.h:43