LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PE/signature/Attribute.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_ATTRIBUTES_H
17#define LIEF_PE_ATTRIBUTES_H
18#include <memory>
19#include <string>
20#include <ostream>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
26namespace PE {
27
29class LIEF_API Attribute : public Object {
30
31 friend class Parser;
32 friend class SignatureParser;
33
34 public:
54
55 Attribute() = delete;
56 Attribute(const Attribute&) = default;
57 Attribute& operator=(const Attribute&) = default;
58
59 virtual std::unique_ptr<Attribute> clone() const = 0;
60
62 virtual TYPE type() const {
63 return type_;
64 }
65
67 virtual std::string print() const = 0;
68
69 void accept(Visitor& visitor) const override;
70
71 ~Attribute() override = default;
72
73 LIEF_API friend
74 std::ostream& operator<<(std::ostream& os, const Attribute& attribute) {
75 os << attribute.print();
76 return os;
77 }
78
79 template<class T>
80 const T* cast() const {
81 static_assert(std::is_base_of<Attribute, T>::value,
82 "Require Attribute inheritance");
83 if (T::classof(this)) {
84 return static_cast<const T*>(this);
85 }
86 return nullptr;
87 }
88
89 template<class T>
90 T* cast() {
91 return const_cast<T*>(static_cast<const Attribute*>(this)->cast<T>());
92 }
93
94 protected:
95 Attribute(TYPE type) :
96 type_(type)
97 {}
98 TYPE type_ = TYPE::UNKNOWN;
99};
100
102
103}
104}
105
106#endif
Interface over PKCS #7 attribute.
Definition PE/signature/Attribute.hpp:29
~Attribute() override=default
friend std::ostream & operator<<(std::ostream &os, const Attribute &attribute)
Definition PE/signature/Attribute.hpp:74
virtual std::unique_ptr< Attribute > clone() const =0
Attribute(const Attribute &)=default
T * cast()
Definition PE/signature/Attribute.hpp:90
TYPE
Definition PE/signature/Attribute.hpp:35
@ PKCS9_COUNTER_SIGNATURE
Definition PE/signature/Attribute.hpp:50
@ MS_SPC_STATEMENT_TYPE
Definition PE/signature/Attribute.hpp:46
@ MS_COUNTER_SIGN
Definition PE/signature/Attribute.hpp:44
@ GENERIC_TYPE
Definition PE/signature/Attribute.hpp:38
@ SPC_RELAXED_PE_MARKER_CHECK
Definition PE/signature/Attribute.hpp:42
@ SIGNING_CERTIFICATE_V2
Definition PE/signature/Attribute.hpp:39
@ UNKNOWN
Definition PE/signature/Attribute.hpp:36
@ CONTENT_TYPE
Definition PE/signature/Attribute.hpp:37
@ PKCS9_AT_SEQUENCE_NUMBER
Definition PE/signature/Attribute.hpp:49
@ MS_PLATFORM_MANIFEST_BINARY_ID
Definition PE/signature/Attribute.hpp:47
@ PKCS9_SIGNING_TIME
Definition PE/signature/Attribute.hpp:52
@ PKCS9_MESSAGE_DIGEST
Definition PE/signature/Attribute.hpp:51
@ SPC_SP_OPUS_INFO
Definition PE/signature/Attribute.hpp:41
@ MS_SPC_NESTED_SIGN
Definition PE/signature/Attribute.hpp:45
friend class SignatureParser
Definition PE/signature/Attribute.hpp:32
friend class Parser
Definition PE/signature/Attribute.hpp:31
const T * cast() const
Definition PE/signature/Attribute.hpp:80
virtual TYPE type() const
Concrete type of the attribute.
Definition PE/signature/Attribute.hpp:62
Attribute & operator=(const Attribute &)=default
void accept(Visitor &visitor) const override
virtual std::string print() const =0
Print information about the underlying attribute.
Definition Visitor.hpp:210
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(CODE_PAGES e)
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41