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 - 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_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 {
27class LIEF_API Function : public Symbol {
30 public: enum class FLAGS : uint32_t {
33 NONE = 0, CONSTRUCTOR = 1 << 0,
39 DESTRUCTOR = 1 << 1,
45 DEBUG_INFO = 1 << 2,
48 EXPORTED = 1 << 3,
52 IMPORTED = 1 << 4,
55 };
56
57 public:
58 Function() = default;
59 Function(const std::string& name) :
60 Symbol(name)
61 {}
62 Function(uint64_t address) :
63 Function("", address)
64 {}
65 Function(const std::string& name, uint64_t address) :
66 Symbol(name, address)
67 {}
68 Function(const std::string& name, uint64_t address, FLAGS flags) :
69 Function(name, address)
70 {
71 flags_ = flags;
72 }
73
74 Function(const Function&) = default;
75 Function& operator=(const Function&) = default;
76
77 ~Function() override = default;
78 std::vector<FLAGS> flags_list() const;
81
82 FLAGS flags() const {
83 return flags_;
84 }
85 Function& add(FLAGS f) {
88 flags_ = (FLAGS)((uint32_t)flags_ | (uint32_t)f);
89 return *this;
90 }
91 bool has(FLAGS f) const {
94 return ((uint32_t)flags_ & (uint32_t)f) != 0;
95 }
96 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
115LIEF_API const char* to_string(Function::FLAGS e);
116}
117
118ENABLE_BITMASK_OPERATORS(LIEF::Function::FLAGS)
119
120#endif
121
Symbol.hpp
LIEF::Function
Class that represents a function in the binary.
Definition Abstract/Function.hpp:29
LIEF::Function::address
void address(uint64_t address)
Definition Abstract/Function.hpp:103
LIEF::Function::~Function
~Function() override=default
LIEF::Function::has
bool has(FLAGS f) const
Check if the function has the given flag.
Definition Abstract/Function.hpp:93
LIEF::Function::Function
Function(const std::string &name, uint64_t address)
Definition Abstract/Function.hpp:65
LIEF::Function::Function
Function()=default
LIEF::Function::accept
void accept(Visitor &visitor) const override
LIEF::Function::flags_list
std::vector< FLAGS > flags_list() const
List of FLAGS.
LIEF::Function::FLAGS
FLAGS
Flags used to characterize the semantic of the function.
Definition Abstract/Function.hpp:32
LIEF::Function::Function
Function(const std::string &name)
Definition Abstract/Function.hpp:59
LIEF::Function::flags
FLAGS flags() const
Definition Abstract/Function.hpp:82
LIEF::Function::operator<<
friend std::ostream & operator<<(std::ostream &os, const Function &entry)
LIEF::Function::Function
Function(uint64_t address)
Definition Abstract/Function.hpp:62
LIEF::Function::Function
Function(const Function &)=default
LIEF::Function::operator=
Function & operator=(const Function &)=default
LIEF::Function::Function
Function(const std::string &name, uint64_t address, FLAGS flags)
Definition Abstract/Function.hpp:68
LIEF::Function::address
uint64_t address() const
Address of the current function. For functions that are set with the FLAGS::IMPORTED flag,...
Definition Abstract/Function.hpp:99
LIEF::Function::add
Function & add(FLAGS f)
Add a flag to the current function.
Definition Abstract/Function.hpp:87
LIEF::Symbol
This class represents a symbol in an executable format.
Definition Abstract/Symbol.hpp:28
enums.hpp
ENABLE_BITMASK_OPERATORS
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
LIEF::to_string
const char * to_string(Binary::VA_TYPES e)
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41