LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
Abstract/Symbol.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_ABSTRACT_SYMBOLS_H
17#define LIEF_ABSTRACT_SYMBOLS_H
18
19#include <cstdint>
20#include <string>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
26
28class LIEF_API Symbol : public Object {
29 public:
30 Symbol() = default;
31 Symbol(std::string name) :
32 name_(std::move(name))
33 {}
34 Symbol(std::string name, uint64_t value) :
35 name_(std::move(name)),
36 value_(value)
37 {}
38 Symbol(std::string name, uint64_t value, uint64_t size) :
39 name_(std::move(name)),
40 value_(value),
41 size_(size)
42 {}
43
44 Symbol(const Symbol&) = default;
45 Symbol& operator=(const Symbol&) = default;
46 ~Symbol() override = default;
47
48 void swap(Symbol& other) noexcept;
49
51 virtual const std::string& name() const {
52 return name_;
53 }
54 virtual std::string& name() {
55 return name_;
56 }
57
59 virtual void name(std::string name) {
60 name_ = std::move(name);
61 }
62
63 // Symbol's value which is usually the **address** of the symbol
64 virtual uint64_t value() const {
65 return value_;
66 }
67 virtual void value(uint64_t value) {
68 value_ = value;
69 }
70
72 virtual uint64_t size() const {
73 return size_;
74 }
75
76 virtual void size(uint64_t value) {
77 size_ = value;
78 }
79
81 void accept(Visitor& visitor) const override;
82
83 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Symbol& entry);
84
85 protected:
86 std::string name_;
87 uint64_t value_ = 0;
88 uint64_t size_ = 0;
89};
90}
91
92#endif
93
Definition Object.hpp:25
This class represents a symbol in an executable format.
Definition Abstract/Symbol.hpp:28
Symbol()=default
virtual uint64_t value() const
Definition Abstract/Symbol.hpp:64
virtual uint64_t size() const
This size of the symbol (when applicable)
Definition Abstract/Symbol.hpp:72
Symbol(const Symbol &)=default
virtual void size(uint64_t value)
Definition Abstract/Symbol.hpp:76
Symbol(std::string name)
Definition Abstract/Symbol.hpp:31
Symbol(std::string name, uint64_t value, uint64_t size)
Definition Abstract/Symbol.hpp:38
~Symbol() override=default
virtual void value(uint64_t value)
Definition Abstract/Symbol.hpp:67
Symbol & operator=(const Symbol &)=default
virtual void name(std::string name)
Set symbol name.
Definition Abstract/Symbol.hpp:59
Symbol(std::string name, uint64_t value)
Definition Abstract/Symbol.hpp:34
void accept(Visitor &visitor) const override
Method so that the visitor can visit us.
virtual std::string & name()
Definition Abstract/Symbol.hpp:54
void swap(Symbol &other) noexcept
virtual const std::string & name() const
Return the symbol's name.
Definition Abstract/Symbol.hpp:51
friend std::ostream & operator<<(std::ostream &os, const Symbol &entry)
Definition Visitor.hpp:224
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41