LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
Abstract/Function.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_ABSTRACT_FUNCTION_H
17#define LIEF_ABSTRACT_FUNCTION_H
18
19#include <string_view>
20#include <string>
21#include <vector>
22
24#include "LIEF/enums.hpp"
25#include "LIEF/visibility.h"
26
27namespace LIEF {
28
30class LIEF_API Function : public Symbol {
31 public:
33 enum class FLAGS : uint32_t {
34 NONE = 0,
39 CONSTRUCTOR = 1 << 0,
40
45 DESTRUCTOR = 1 << 1,
46
48 DEBUG_INFO = 1 << 2,
49
52 EXPORTED = 1 << 3,
53
56 IMPORTED = 1 << 4,
57 };
58
59 public:
60 Function() = default;
61 Function(std::string_view name) :
62 Symbol(std::string(name)) {}
63 Function(uint64_t address) :
64 Function("", address) {}
65 Function(std::string_view name, uint64_t address) :
66 Symbol(std::string(name), address) {}
67 Function(std::string_view name, uint64_t address, FLAGS flags) :
69 flags_ = flags;
70 }
71
72 Function(const Function&) = default;
73 Function& operator=(const Function&) = default;
74
75 ~Function() override = default;
76
78 std::vector<FLAGS> flags_list() const;
79
80 FLAGS flags() const {
81 return flags_;
82 }
83
86 flags_ = (FLAGS)((uint32_t)flags_ | (uint32_t)f);
87 return *this;
88 }
89
91 bool has(FLAGS f) const {
92 return ((uint32_t)flags_ & (uint32_t)f) != 0;
93 }
94
97 uint64_t address() const {
98 return value_;
99 }
100
101 void address(uint64_t address) {
102 value_ = address;
103 }
104
105 void accept(Visitor& visitor) const override;
106
107 LIEF_API friend std::ostream& operator<<(std::ostream& os,
108 const Function& entry);
109
110 protected:
111 FLAGS flags_ = FLAGS::NONE;
112};
113
115}
116
118
119#endif
void address(uint64_t address)
Definition Abstract/Function.hpp:101
~Function() override=default
bool has(FLAGS f) const
Check if the function has the given flag.
Definition Abstract/Function.hpp:91
Function()=default
Function(std::string_view name, uint64_t address, FLAGS flags)
Definition Abstract/Function.hpp:67
void accept(Visitor &visitor) const override
std::vector< FLAGS > flags_list() const
List of FLAGS.
Function(std::string_view name, uint64_t address)
Definition Abstract/Function.hpp:65
FLAGS
Flags used to characterize the semantics of the function.
Definition Abstract/Function.hpp:33
@ NONE
Definition Abstract/Function.hpp:34
FLAGS flags() const
Definition Abstract/Function.hpp:80
friend std::ostream & operator<<(std::ostream &os, const Function &entry)
Function(std::string_view name)
Definition Abstract/Function.hpp:61
Function(uint64_t address)
Definition Abstract/Function.hpp:63
Function(const Function &)=default
Function & operator=(const Function &)=default
uint64_t address() const
Address of the current function. For functions that are set with the FLAGS::IMPORTED flag,...
Definition Abstract/Function.hpp:97
Function & add(FLAGS f)
Add a flag to the current function.
Definition Abstract/Function.hpp:85
Symbol()=default
virtual std::string_view name() const
Return the symbol's name.
Definition Abstract/Symbol.hpp:56
Definition Visitor.hpp:212
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:42
const char * to_string(Binary::VA_TYPES e)
#define LIEF_API
Definition visibility.h:45