LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
FunctionStarts.hpp
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_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"
24#include "LIEF/MachO/LoadCommand.hpp"
25
26namespace LIEF {
27namespace MachO {
28class BinaryParser;
29class LinkEdit;
30
31namespace details {
32struct linkedit_data_command;
33}
34
35
39class LIEF_API FunctionStarts : public LoadCommand {
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
55 uint32_t data_offset() const {
56 return data_offset_;
57 }
58
60 uint32_t data_size() const {
61 return data_size_;
62 }
63
69 const std::vector<uint64_t>& functions() const {
70 return functions_;
71 }
72
73 std::vector<uint64_t>& functions() {
74 return functions_;
75 }
76
78 void add_function(uint64_t address) {
79 functions_.emplace_back(address);
80 }
81
82 void data_offset(uint32_t offset) {
83 data_offset_ = offset;
84 }
85 void data_size(uint32_t size) {
86 data_size_ = size;
87 }
88
89 void functions(std::vector<uint64_t> funcs) {
90 functions_ = std::move(funcs);
91 }
92
93 span<const uint8_t> content() const {
94 return content_;
95 }
96
97 span<uint8_t> content() {
98 return content_;
99 }
100
101 ~FunctionStarts() override = default;
102
103 void accept(Visitor& visitor) const override;
104
105 std::ostream& print(std::ostream& os) const override;
106
107 static bool classof(const LoadCommand* cmd) {
108 return cmd->command() == LoadCommand::TYPE::FUNCTION_STARTS;
109 }
110 private:
111 uint32_t data_offset_ = 0;
112 uint32_t data_size_ = 0;
113 span<uint8_t> content_;
114 std::vector<uint64_t> functions_;
115};
116
117}
118}
119#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:73
Class which represents the LC_FUNCTION_STARTS command.
Definition FunctionStarts.hpp:39
const std::vector< uint64_t > & functions() const
Addresses of every function entry point in the executable.
Definition FunctionStarts.hpp:69
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where start functions are located.
Definition FunctionStarts.hpp:55
uint32_t data_size() const
Size of the functions list in the binary.
Definition FunctionStarts.hpp:60
void add_function(uint64_t address)
Add a new function.
Definition FunctionStarts.hpp:78
Definition LinkEdit.hpp:42
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:32