LIEF: Library to Instrument Executable Formats Version 1.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 <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
55 IMPORTED = 1 << 4,
56 };
57
58 public:
59 Function() = default;
60 Function(const std::string& name) :
61 Symbol(name) {}
62 Function(uint64_t address) :
63 Function("", address) {}
64 Function(const std::string& name, uint64_t address) :
66 Function(const std::string& name, uint64_t address, FLAGS flags) :
68 flags_ = flags;
69 }
70
71 Function(const Function&) = default;
72 Function& operator=(const Function&) = default;
73
74 ~Function() override = default;
75
77 std::vector<FLAGS> flags_list() const;
78
79 FLAGS flags() const {
80 return flags_;
81 }
82
85 flags_ = (FLAGS)((uint32_t)flags_ | (uint32_t)f);
86 return *this;
87 }
88
90 bool has(FLAGS f) const {
91 return ((uint32_t)flags_ & (uint32_t)f) != 0;
92 }
93
96 uint64_t address() const {
97 return value_;
98 }
99
100 void address(uint64_t address) {
101 value_ = address;
102 }
103
104 void accept(Visitor& visitor) const override;
105
106 LIEF_API friend std::ostream& operator<<(std::ostream& os,
107 const Function& entry);
108
109 protected:
110 FLAGS flags_ = FLAGS::NONE;
111};
112
114}
115
117
118#endif
void address(uint64_t address)
Definition Abstract/Function.hpp:100
~Function() override=default
bool has(FLAGS f) const
Check if the function has the given flag.
Definition Abstract/Function.hpp:90
Function(const std::string &name, uint64_t address)
Definition Abstract/Function.hpp:64
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
@ NONE
Definition Abstract/Function.hpp:33
Function(const std::string &name)
Definition Abstract/Function.hpp:60
FLAGS flags() const
Definition Abstract/Function.hpp:79
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:66
uint64_t address() const
Address of the current function. For functions that are set with the FLAGS::IMPORTED flag,...
Definition Abstract/Function.hpp:96
Function & add(FLAGS f)
Add a flag to the current function.
Definition Abstract/Function.hpp:84
Symbol()=default
virtual const std::string & name() const
Return the symbol's name.
Definition Abstract/Symbol.hpp:54
Definition Visitor.hpp:212
#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:43