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
21#include "LIEF/visibility.h"
22
23#include "LIEF/span.hpp"
25
26namespace LIEF {
27namespace MachO {
28class BinaryParser;
29class LinkEdit;
30
31namespace details {
32struct linkedit_data_command;
33}
34
35
40 friend class BinaryParser;
41 friend class LinkEdit;
42
43 public:
44 FunctionStarts() = default;
45 FunctionStarts(const details::linkedit_data_command& cmd);
46
47 FunctionStarts& operator=(const FunctionStarts& copy) = default;
48 FunctionStarts(const FunctionStarts& copy) = default;
49
50 std::unique_ptr<LoadCommand> clone() const override {
51 return std::unique_ptr<FunctionStarts>(new FunctionStarts(*this));
52 }
53
56 uint32_t data_offset() const {
57 return data_offset_;
58 }
59
61 uint32_t data_size() const {
62 return data_size_;
63 }
64
71 const std::vector<uint64_t>& functions() const {
72 return functions_;
73 }
74
75 std::vector<uint64_t>& functions() {
76 return functions_;
77 }
78
80 void add_function(uint64_t address) {
81 functions_.emplace_back(address);
82 }
83
84 void data_offset(uint32_t offset) {
85 data_offset_ = offset;
86 }
87 void data_size(uint32_t size) {
88 data_size_ = size;
89 }
90
91 void functions(std::vector<uint64_t> funcs) {
92 functions_ = std::move(funcs);
93 }
94
96 return content_;
97 }
98
100 return content_;
101 }
102
103 ~FunctionStarts() override = default;
104
105 void accept(Visitor& visitor) const override;
106
107 std::ostream& print(std::ostream& os) const override;
108
109 static bool classof(const LoadCommand* cmd) {
111 }
112
113 private:
114 uint32_t data_offset_ = 0;
115 uint32_t data_size_ = 0;
116 span<uint8_t> content_;
117 std::vector<uint64_t> functions_;
118};
119
120}
121}
122#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:78
span< const uint8_t > content() const
Definition FunctionStarts.hpp:95
std::vector< uint64_t > & functions()
Definition FunctionStarts.hpp:75
std::ostream & print(std::ostream &os) const override
void data_size(uint32_t size)
Definition FunctionStarts.hpp:87
const std::vector< uint64_t > & functions() const
Addresses of every function entry point in the executable.
Definition FunctionStarts.hpp:71
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where start functions are located.
Definition FunctionStarts.hpp:56
friend class BinaryParser
Definition FunctionStarts.hpp:40
FunctionStarts & operator=(const FunctionStarts &copy)=default
std::unique_ptr< LoadCommand > clone() const override
Definition FunctionStarts.hpp:50
void data_offset(uint32_t offset)
Definition FunctionStarts.hpp:84
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:61
void add_function(uint64_t address)
Add a new function.
Definition FunctionStarts.hpp:80
friend class LinkEdit
Definition FunctionStarts.hpp:41
static bool classof(const LoadCommand *cmd)
Definition FunctionStarts.hpp:109
span< uint8_t > content()
Definition FunctionStarts.hpp:99
void functions(std::vector< uint64_t > funcs)
Definition FunctionStarts.hpp:91
FunctionStarts(const FunctionStarts &copy)=default
void accept(Visitor &visitor) const override
Definition LinkEdit.hpp:45
uint32_t size() const
Size of the command (should be greather than sizeof(load_command)).
Definition LoadCommand.hpp:133
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:128
@ FUNCTION_STARTS
Definition LoadCommand.hpp:85
Definition Visitor.hpp:212
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:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:43