LIEF: Library to Instrument Executable Formats Version 1.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 <vector>
19#include <ostream>
20
22#include "LIEF/visibility.h"
23
24#include "LIEF/span.hpp"
26
27namespace LIEF {
28namespace MachO {
29class BinaryParser;
30class LinkEdit;
31
32namespace details {
33struct linkedit_data_command;
34}
35
36
41 friend class BinaryParser;
42 friend class LinkEdit;
43
44 public:
45 FunctionStarts() = default;
46 FunctionStarts(const details::linkedit_data_command& cmd);
47
48 FunctionStarts& operator=(const FunctionStarts& copy) = default;
49 FunctionStarts(const FunctionStarts& copy) = default;
50
51 std::unique_ptr<LoadCommand> clone() const override {
52 return std::unique_ptr<FunctionStarts>(new FunctionStarts(*this));
53 }
54
57 uint32_t data_offset() const {
58 return data_offset_;
59 }
60
62 uint32_t data_size() const {
63 return data_size_;
64 }
65
72 const std::vector<uint64_t>& functions() const LIEF_LIFETIMEBOUND {
73 return functions_;
74 }
75
76 std::vector<uint64_t>& functions() LIEF_LIFETIMEBOUND {
77 return functions_;
78 }
79
81 void add_function(uint64_t address) {
82 functions_.emplace_back(address);
83 }
84
85 void data_offset(uint32_t offset) {
86 data_offset_ = offset;
87 }
88 void data_size(uint32_t size) {
89 data_size_ = size;
90 }
91
92 void functions(std::vector<uint64_t> funcs) {
93 functions_ = std::move(funcs);
94 }
95
97 return content_;
98 }
99
101 return content_;
102 }
103
104 ~FunctionStarts() override = default;
105
106 void accept(Visitor& visitor) const override;
107
108 std::ostream& print(std::ostream& os) const override;
109
110 static bool classof(const LoadCommand* cmd) {
112 }
113
114 private:
115 uint32_t data_offset_ = 0;
116 uint32_t data_size_ = 0;
117 span<uint8_t> content_;
118 std::vector<uint64_t> functions_;
119};
120
121}
122}
123#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:96
std::vector< uint64_t > & functions()
Definition FunctionStarts.hpp:76
std::ostream & print(std::ostream &os) const override
void data_size(uint32_t size)
Definition FunctionStarts.hpp:88
const std::vector< uint64_t > & functions() const
Addresses of every function entry point in the executable.
Definition FunctionStarts.hpp:72
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where start functions are located.
Definition FunctionStarts.hpp:57
friend class BinaryParser
Definition FunctionStarts.hpp:41
FunctionStarts & operator=(const FunctionStarts &copy)=default
std::unique_ptr< LoadCommand > clone() const override
Definition FunctionStarts.hpp:51
void data_offset(uint32_t offset)
Definition FunctionStarts.hpp:85
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:62
void add_function(uint64_t address)
Add a new function.
Definition FunctionStarts.hpp:81
friend class LinkEdit
Definition FunctionStarts.hpp:42
static bool classof(const LoadCommand *cmd)
Definition FunctionStarts.hpp:110
span< uint8_t > content()
Definition FunctionStarts.hpp:100
void functions(std::vector< uint64_t > funcs)
Definition FunctionStarts.hpp:92
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:60
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45