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