LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ContentInfo.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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
78class LIEF_API ContentInfo : public Object {
79 friend class Parser;
80 friend class SignatureParser;
81
82 public:
83 class Content : public Object {
84 public:
85 Content(oid_t oid) :
86 type_(std::move(oid))
87 {}
88
89 const oid_t& content_type() const {
90 return type_;
91 }
92
93 virtual std::unique_ptr<Content> clone() const = 0;
94 virtual void print(std::ostream& os) const = 0;
95
96 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Content& content) {
97 content.print(os);
98 return os;
99 }
100
101 template<class T>
102 const T* cast() const {
103 static_assert(std::is_base_of<Content, T>::value,
104 "Require ContentInfo inheritance");
105 if (T::classof(this)) {
106 return static_cast<const T*>(this);
107 }
108 return nullptr;
109 }
110
111 template<class T>
112 T* cast() {
113 return const_cast<T*>(static_cast<const Content*>(this)->cast<T>());
114 }
115
116 ~Content() override = default;
117 private:
118 oid_t type_;
119 };
121 ContentInfo(const ContentInfo& other);
122 ContentInfo(ContentInfo&& other) noexcept = default;
123 ContentInfo& operator=(ContentInfo other);
124
125 void swap(ContentInfo& other) noexcept;
126 oid_t content_type() const {
130 return value_->content_type();
131 }
132
133 Content& value() {
134 return *value_;
135 }
136
137 const Content& value() const {
138 return *value_;
139 }
140 std::vector<uint8_t> digest() const;
147
148 void accept(Visitor& visitor) const override;
149
150 ~ContentInfo() override = default;
151
152 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ContentInfo& content_info);
153
154 private:
155 std::unique_ptr<Content> value_;
156};
157
158}
159}
160
161#endif
~Content() override=default
const oid_t & content_type() const
Definition ContentInfo.hpp:89
Content(oid_t oid)
Definition ContentInfo.hpp:85
virtual std::unique_ptr< Content > clone() const =0
virtual void print(std::ostream &os) const =0
T * cast()
Definition ContentInfo.hpp:112
const T * cast() const
Definition ContentInfo.hpp:102
friend std::ostream & operator<<(std::ostream &os, const Content &content)
Definition ContentInfo.hpp:96
Definition ContentInfo.hpp:78
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:137
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:129
~ContentInfo() override=default
Content & value()
Definition ContentInfo.hpp:133
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 functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
Definition SignatureParser.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:686
std::string oid_t
Definition PE/signature/types.hpp:23
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41