LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
FunctionStarts.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_MACHO_FUNCTION_STARTS_COMMAND_H
17#define LIEF_MACHO_FUNCTION_STARTS_COMMAND_H
18#include <memory>
19#include <ostream>
20#include <vector>
21
23#include "LIEF/visibility.h"
24
26#include "LIEF/span.hpp"
27
28
29namespace LIEF::MachO {
30class BinaryParser;
31class LinkEdit;
32
33namespace details {
34struct linkedit_data_command;
35}
36
37
42 friend class BinaryParser;
43 friend class LinkEdit;
44
45 public:
46 FunctionStarts() = default;
47 FunctionStarts(const details::linkedit_data_command& cmd);
48
49 FunctionStarts& operator=(const FunctionStarts& copy) = default;
50 FunctionStarts(const FunctionStarts& copy) = default;
51
52 std::unique_ptr<LoadCommand> clone() const override {
53 return std::make_unique<FunctionStarts>(*this);
54 }
55
58 uint32_t data_offset() const {
59 return data_offset_;
60 }
61
63 uint32_t data_size() const {
64 return data_size_;
65 }
66
73 const std::vector<uint64_t>& functions() const LIEF_LIFETIMEBOUND {
74 return functions_;
75 }
76
77 std::vector<uint64_t>& functions() LIEF_LIFETIMEBOUND {
78 return functions_;
79 }
80
82 void add_function(uint64_t address) {
83 functions_.emplace_back(address);
84 }
85
86 void data_offset(uint32_t offset) {
87 data_offset_ = offset;
88 }
89 void data_size(uint32_t size) {
90 data_size_ = size;
91 }
92
93 void functions(std::vector<uint64_t> funcs) {
94 functions_ = std::move(funcs);
95 }
96
98 return content_;
99 }
100
102 return content_;
103 }
104
105 ~FunctionStarts() override = default;
106
107 void accept(Visitor& visitor) const override;
108
109 std::ostream& print(std::ostream& os) const override;
110
111 static bool classof(const LoadCommand* cmd) {
113 }
114
115 private:
116 uint32_t data_offset_ = 0;
117 uint32_t data_size_ = 0;
118 span<uint8_t> content_;
119 std::vector<uint64_t> functions_;
120};
121
122}
123
124#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:79
span< const uint8_t > content() const
Definition FunctionStarts.hpp:97
std::vector< uint64_t > & functions()
Definition FunctionStarts.hpp:77
std::ostream & print(std::ostream &os) const override
void data_size(uint32_t size)
Definition FunctionStarts.hpp:89
const std::vector< uint64_t > & functions() const
Addresses of every function entry point in the executable.
Definition FunctionStarts.hpp:73
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where start functions are located.
Definition FunctionStarts.hpp:58
friend class BinaryParser
Definition FunctionStarts.hpp:42
FunctionStarts & operator=(const FunctionStarts &copy)=default
std::unique_ptr< LoadCommand > clone() const override
Definition FunctionStarts.hpp:52
void data_offset(uint32_t offset)
Definition FunctionStarts.hpp:86
FunctionStarts(const details::linkedit_data_command &cmd)
~FunctionStarts() override=default
uint32_t data_size() const
Size of the functions list in the binary.
Definition FunctionStarts.hpp:63
void add_function(uint64_t address)
Add a new function.
Definition FunctionStarts.hpp:82
friend class LinkEdit
Definition FunctionStarts.hpp:43
static bool classof(const LoadCommand *cmd)
Definition FunctionStarts.hpp:111
span< uint8_t > content()
Definition FunctionStarts.hpp:101
void functions(std::vector< uint64_t > funcs)
Definition FunctionStarts.hpp:93
FunctionStarts(const FunctionStarts &copy)=default
void accept(Visitor &visitor) const override
Definition LinkEdit.hpp:47
uint32_t size() const
Size of the command (should be greater than sizeof(load_command)).
Definition LoadCommand.hpp:137
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:132
@ FUNCTION_STARTS
Definition LoadCommand.hpp:87
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45