LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PublicSymbol.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2025 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_PDB_PUBLIC_SYMBOL_H
16#define LIEF_PDB_PUBLIC_SYMBOL_H
17#include <memory>
18#include <string>
19#include <ostream>
20
21#include "LIEF/visibility.h"
22
23namespace LIEF {
24namespace pdb {
25
26namespace details {
27class PublicSymbol;
28class PublicSymbolIt;
29}
34 public:
35 class LIEF_API Iterator {
36 public:
37 using iterator_category = std::forward_iterator_tag;
38 using value_type = std::unique_ptr<PublicSymbol>;
39 using difference_type = std::ptrdiff_t;
40 using pointer = PublicSymbol*;
41 using reference = PublicSymbol&;
42 using implementation = details::PublicSymbolIt;
43
44 class LIEF_API PointerProxy {
45 // Inspired from LLVM's iterator_facade_base
46 friend class Iterator;
47 public:
48 pointer operator->() const { return R.get(); }
49
50 private:
51 value_type R;
52
53 template <typename RefT>
54 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
55 };
56
57 Iterator(const Iterator&);
58 Iterator(Iterator&&);
59 Iterator(std::unique_ptr<details::PublicSymbolIt> impl);
61
62 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
63
64 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
65 return !(LHS == RHS);
66 }
67
68 Iterator& operator++();
69
70 Iterator operator++(int) {
71 Iterator tmp = *static_cast<Iterator*>(this);
72 ++*static_cast<Iterator *>(this);
73 return tmp;
74 }
75
76 std::unique_ptr<PublicSymbol> operator*() const;
77
78 PointerProxy operator->() const {
79 return static_cast<const Iterator*>(this)->operator*();
80 }
81
82 private:
83 std::unique_ptr<details::PublicSymbolIt> impl_;
84 };
85 PublicSymbol(std::unique_ptr<details::PublicSymbol> impl);
87
88 enum class FLAGS : uint32_t {
89 NONE = 0,
90 CODE = 1 << 0,
91 FUNCTION = 1 << 1,
92 MANAGED = 1 << 2,
93 MSIL = 1 << 3,
94 };
95 std::string name() const;
98 std::string demangled_name() const;
101 std::string section_name() const;
106 uint32_t RVA() const;
111
112 std::string to_string() const;
113
114 LIEF_API friend
115 std::ostream& operator<<(std::ostream& os, const PublicSymbol& sym)
116 {
117 os << sym.to_string();
118 return os;
119 }
120
121 private:
122 std::unique_ptr<details::PublicSymbol> impl_;
123};
124
125}
126}
127#endif
128
pointer operator->() const
Definition PublicSymbol.hpp:48
Iterator(std::unique_ptr< details::PublicSymbolIt > impl)
friend bool operator==(const Iterator &LHS, const Iterator &RHS)
std::unique_ptr< PublicSymbol > operator*() const
Iterator operator++(int)
Definition PublicSymbol.hpp:70
PointerProxy operator->() const
Definition PublicSymbol.hpp:78
friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
Definition PublicSymbol.hpp:64
This class provides general information (RVA, name) about a symbol from the PDB's public symbol strea...
Definition PublicSymbol.hpp:33
friend std::ostream & operator<<(std::ostream &os, const PublicSymbol &sym)
Definition PublicSymbol.hpp:115
PublicSymbol(std::unique_ptr< details::PublicSymbol > impl)
std::string name() const
Name of the symbol.
std::string demangled_name() const
Demangled representation of the symbol.
std::string to_string() const
std::string section_name() const
Name of the section in which this symbol is defined (e.g. .text).
uint32_t RVA() const
Relative Virtual Address of this symbol.
Definition BuildMetadata.hpp:26
Definition BuildMetadata.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41