LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
Abstract/Function.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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 <vector>
20#include <string>
21
23#include "LIEF/visibility.h"
24#include "LIEF/enums.hpp"
25
26namespace LIEF {
27
29class LIEF_API Function : public Symbol {
30 public:
32 enum class FLAGS : uint32_t {
33 NONE = 0,
38 CONSTRUCTOR = 1 << 0,
39
44 DESTRUCTOR = 1 << 1,
45
47 DEBUG_INFO = 1 << 2,
48
51 EXPORTED = 1 << 3,
52
54 IMPORTED = 1 << 4,
55 };
56
57 public:
58 Function() = default;
59 Function(const std::string& name) :
61 {}
62 Function(uint64_t address) :
63 Function("", address)
64 {}
65 Function(const std::string& name, uint64_t address) :
67 {}
68 Function(const std::string& name, uint64_t address, FLAGS flags) :
70 {
71 flags_ = flags;
72 }
73
74 Function(const Function&) = default;
75 Function& operator=(const Function&) = default;
76
77 ~Function() override = default;
78
80 std::vector<FLAGS> flags_list() const;
81
82 FLAGS flags() const {
83 return flags_;
84 }
85
88 flags_ = (FLAGS)((uint32_t)flags_ | (uint32_t)f);
89 return *this;
90 }
91
93 bool has(FLAGS f) const {
94 return ((uint32_t)flags_ & (uint32_t)f) != 0;
95 }
96
99 uint64_t address() const {
100 return value_;
101 }
102
103 void address(uint64_t address) {
104 value_ = address;
105 }
106
107 void accept(Visitor& visitor) const override;
108
109 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Function& entry);
110
111 protected:
112 FLAGS flags_ = FLAGS::NONE;
113};
114
116}
117
119
120#endif
121
void address(uint64_t address)
Definition Abstract/Function.hpp:103
~Function() override=default
bool has(FLAGS f) const
Check if the function has the given flag.
Definition Abstract/Function.hpp:93
Function(const std::string &name, uint64_t address)
Definition Abstract/Function.hpp:65
Function()=default
void accept(Visitor &visitor) const override
std::vector< FLAGS > flags_list() const
List of FLAGS.
FLAGS
Flags used to characterize the semantics of the function.
Definition Abstract/Function.hpp:32
@ DESTRUCTOR
The function acts as a destructor.
Definition Abstract/Function.hpp:44
@ CONSTRUCTOR
The function acts as a constructor.
Definition Abstract/Function.hpp:38
@ NONE
Definition Abstract/Function.hpp:33
@ IMPORTED
The function is imported by the binary and the address() should return 0.
Definition Abstract/Function.hpp:54
@ EXPORTED
The function is exported by the binary and the address() method returns its virtual address in the bi...
Definition Abstract/Function.hpp:51
@ DEBUG_INFO
The function is associated with Debug information.
Definition Abstract/Function.hpp:47
Function(const std::string &name)
Definition Abstract/Function.hpp:59
FLAGS flags() const
Definition Abstract/Function.hpp:82
friend std::ostream & operator<<(std::ostream &os, const Function &entry)
Function(uint64_t address)
Definition Abstract/Function.hpp:62
Function(const Function &)=default
Function & operator=(const Function &)=default
Function(const std::string &name, uint64_t address, FLAGS flags)
Definition Abstract/Function.hpp:68
uint64_t address() const
Address of the current function. For functions that are set with the FLAGS::IMPORTED flag,...
Definition Abstract/Function.hpp:99
Function & add(FLAGS f)
Add a flag to the current function.
Definition Abstract/Function.hpp:87
Symbol()=default
virtual const std::string & name() const
Return the symbol's name.
Definition Abstract/Symbol.hpp:54
Definition Visitor.hpp:210
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:40
const char * to_string(Binary::VA_TYPES e)
#define LIEF_API
Definition visibility.h:41