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 - 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_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 {
27class LIEF_API Attribute : public Object {
30
31 friend class Parser;
32 friend class SignatureParser;
33
34 public:
35 enum class TYPE {
36 UNKNOWN = 0,
37 CONTENT_TYPE,
38 GENERIC_TYPE,
39 SIGNING_CERTIFICATE_V2,
40
41 SPC_SP_OPUS_INFO,
42 SPC_RELAXED_PE_MARKER_CHECK,
43
44 MS_COUNTER_SIGN,
45 MS_SPC_NESTED_SIGN,
46 MS_SPC_STATEMENT_TYPE,
47 MS_PLATFORM_MANIFEST_BINARY_ID,
48
49 PKCS9_AT_SEQUENCE_NUMBER,
50 PKCS9_COUNTER_SIGNATURE,
51 PKCS9_MESSAGE_DIGEST,
52 PKCS9_SIGNING_TIME,
53 };
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 virtual TYPE type() const {
63 return type_;
64 }
65 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
101LIEF_API const char* to_string(Attribute::TYPE e);
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
Attribute()=delete
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.
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(DataDirectory::TYPES e)
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41