LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
AuxiliarySymbol.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_COFF_AUXILIARY_SYMBOL_H
16#define LIEF_COFF_AUXILIARY_SYMBOL_H
17
18#include <memory>
19#include <ostream>
20#include <vector>
21
23#include "LIEF/span.hpp"
24#include "LIEF/visibility.h"
25
26namespace LIEF {
27class BinaryStream;
28
29namespace COFF {
30class Symbol;
31
37 public:
38 AuxiliarySymbol() = default;
39 AuxiliarySymbol(std::vector<uint8_t> payload) :
40 payload_(std::move(payload)) {}
43
46
47 LIEF_LOCAL static std::unique_ptr<AuxiliarySymbol>
48 parse(Symbol& sym, std::vector<uint8_t> payload);
49
50 virtual std::unique_ptr<AuxiliarySymbol> clone() const {
51 return std::make_unique<AuxiliarySymbol>(*this);
52 }
53
55 enum class TYPE {
56 UNKNOWN = 0,
57 CLR_TOKEN,
59 FUNC_DEF,
60
62 BF_AND_EF,
63
65 WEAK_EXTERNAL,
66
68 FILE,
69
71 SEC_DEF,
72 };
73
75 type_(ty) {}
76
77 static TYPE get_aux_type(const Symbol& sym);
78
79 TYPE type() const {
80 return type_;
81 }
82
85 return payload_;
86 }
87
89 return payload_;
90 }
91
92 virtual std::string to_string() const;
93
94 virtual ~AuxiliarySymbol() = default;
95
97 template<class T>
98 const T* as() const {
99 static_assert(std::is_base_of_v<AuxiliarySymbol, T>,
100 "Require AuxiliarySymbol inheritance");
101 if (T::classof(this)) {
102 return static_cast<const T*>(this);
103 }
104 return nullptr;
105 }
106
107 template<class T>
108 T* as() {
109 return const_cast<T*>(static_cast<const AuxiliarySymbol*>(this)->as<T>());
110 }
111
112 LIEF_API friend std::ostream& operator<<(std::ostream& os,
113 const AuxiliarySymbol& aux) {
114 os << aux.to_string();
115 return os;
116 }
117
118 protected:
119 TYPE type_ = TYPE::UNKNOWN;
120 std::vector<uint8_t> payload_;
121};
122
123}
124}
125#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
const T * as() const
Helper to downcast an AuxiliarySymbol into a concrete implementation.
Definition AuxiliarySymbol.hpp:98
span< const uint8_t > payload() const
For unknown type only, return the raw representation of this symbol.
Definition AuxiliarySymbol.hpp:84
static std::unique_ptr< AuxiliarySymbol > parse(Symbol &sym, std::vector< uint8_t > payload)
static TYPE get_aux_type(const Symbol &sym)
T * as()
Definition AuxiliarySymbol.hpp:108
virtual std::unique_ptr< AuxiliarySymbol > clone() const
Definition AuxiliarySymbol.hpp:50
virtual ~AuxiliarySymbol()=default
AuxiliarySymbol(TYPE ty)
Definition AuxiliarySymbol.hpp:74
AuxiliarySymbol & operator=(AuxiliarySymbol &&)=default
TYPE type() const
Definition AuxiliarySymbol.hpp:79
friend std::ostream & operator<<(std::ostream &os, const AuxiliarySymbol &aux)
Definition AuxiliarySymbol.hpp:112
virtual std::string to_string() const
AuxiliarySymbol(std::vector< uint8_t > payload)
Definition AuxiliarySymbol.hpp:39
AuxiliarySymbol(AuxiliarySymbol &&)=default
TYPE
Type discriminator for the subclasses.
Definition AuxiliarySymbol.hpp:55
AuxiliarySymbol(const AuxiliarySymbol &)=default
AuxiliarySymbol & operator=(const AuxiliarySymbol &)=default
span< uint8_t > payload()
Definition AuxiliarySymbol.hpp:88
This class represents a COFF symbol.
Definition COFF/Symbol.hpp:36
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition AuxiliarySymbol.hpp:29
LIEF namespace.
Definition Abstract/Binary.hpp:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:44
#define LIEF_LOCAL
Definition visibility.h:45