LIEF: Library to Instrument Executable Formats Version
Loading...
Searching...
No Matches
FunctionStarts.hpp
1/* Copyright 2017 - 2023 R. Thomas
2 * Copyright 2017 - 2023 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 <string>
19#include <vector>
20#include <ostream>
21#include <array>
22
23#include "LIEF/visibility.h"
24#include "LIEF/types.hpp"
25
26#include "LIEF/span.hpp"
27#include "LIEF/MachO/LoadCommand.hpp"
28
29namespace LIEF {
30namespace MachO {
31class BinaryParser;
32class LinkEdit;
33
34namespace details {
35struct linkedit_data_command;
36}
37
38
42class LIEF_API FunctionStarts : public LoadCommand {
43 friend class BinaryParser;
44 friend class LinkEdit;
45
46 public:
48 FunctionStarts(const details::linkedit_data_command& cmd);
49
50 FunctionStarts& operator=(const FunctionStarts& copy);
51 FunctionStarts(const FunctionStarts& copy);
52
53 FunctionStarts* clone() const override;
54
56 uint32_t data_offset() const;
57
59 uint32_t data_size() const;
60
66 const std::vector<uint64_t>& functions() const;
67
68 std::vector<uint64_t>& functions();
69
71 void add_function(uint64_t address);
72
73 void data_offset(uint32_t offset);
74 void data_size(uint32_t size);
75 void functions(const std::vector<uint64_t>& funcs);
76
77 span<const uint8_t> content() const {
78 return content_;
79 }
80
81 span<uint8_t> content() {
82 return content_;
83 }
84
85 ~FunctionStarts() override;
86
87
88 void accept(Visitor& visitor) const override;
89
90 std::ostream& print(std::ostream& os) const override;
91
92 static bool classof(const LoadCommand* cmd);
93
94
95 private:
96 uint32_t data_offset_ = 0;
97 uint32_t data_size_ = 0;
98 span<uint8_t> content_;
99 std::vector<uint64_t> functions_;
100};
101
102}
103}
104#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:42
const std::vector< uint64_t > & functions() const
Addresses of every function entry point in the executable.
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where start functions are located.
uint32_t data_size() const
Size of the functions list in the binary.
void add_function(uint64_t address)
Add a new function.
Definition LinkEdit.hpp:48
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:39
Definition Visitor.hpp:219
LIEF namespace.
Definition Abstract/Binary.hpp:32