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 <cstdint>
18#include <memory>
19#include <string>
20#include <ostream>
21
22#include "LIEF/visibility.h"
23
24namespace LIEF {
25namespace pdb {
26
27namespace details {
28class PublicSymbol;
29class PublicSymbolIt;
30}
35 public:
36 class LIEF_API Iterator {
37 public:
38 using iterator_category = std::forward_iterator_tag;
39 using value_type = std::unique_ptr<PublicSymbol>;
40 using difference_type = std::ptrdiff_t;
41 using pointer = PublicSymbol*;
42 using reference = PublicSymbol&;
43 using implementation = details::PublicSymbolIt;
44
45 class LIEF_API PointerProxy {
46 // Inspired from LLVM's iterator_facade_base
47 friend class Iterator;
48 public:
49 pointer operator->() const { return R.get(); }
50
51 private:
52 value_type R;
53
54 template <typename RefT>
55 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
56 };
57
58 Iterator(const Iterator&);
59 Iterator(Iterator&&);
60 Iterator(std::unique_ptr<details::PublicSymbolIt> impl);
62
63 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
64
65 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
66 return !(LHS == RHS);
67 }
68
69 Iterator& operator++();
70
71 Iterator operator++(int) {
72 Iterator tmp = *static_cast<Iterator*>(this);
73 ++*static_cast<Iterator *>(this);
74 return tmp;
75 }
76
77 std::unique_ptr<PublicSymbol> operator*() const;
78
79 PointerProxy operator->() const {
80 return static_cast<const Iterator*>(this)->operator*();
81 }
82
83 private:
84 std::unique_ptr<details::PublicSymbolIt> impl_;
85 };
86 PublicSymbol(std::unique_ptr<details::PublicSymbol> impl);
88
89 enum class FLAGS : uint32_t {
90 NONE = 0,
91 CODE = 1 << 0,
92 FUNCTION = 1 << 1,
93 MANAGED = 1 << 2,
94 MSIL = 1 << 3,
95 };
96 std::string name() const;
99 std::string demangled_name() const;
102 std::string section_name() const;
107 uint32_t RVA() const;
112
113 std::string to_string() const;
114
115 LIEF_API friend
116 std::ostream& operator<<(std::ostream& os, const PublicSymbol& sym)
117 {
118 os << sym.to_string();
119 return os;
120 }
121
122 private:
123 std::unique_ptr<details::PublicSymbol> impl_;
124};
125
126}
127}
128#endif
129
pointer operator->() const
Definition PublicSymbol.hpp:49
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:71
PointerProxy operator->() const
Definition PublicSymbol.hpp:79
friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
Definition PublicSymbol.hpp:65
This class provides general information (RVA, name) about a symbol from the PDB's public symbol strea...
Definition PublicSymbol.hpp:34
friend std::ostream & operator<<(std::ostream &os, const PublicSymbol &sym)
Definition PublicSymbol.hpp:116
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