LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
FunctionStarts.hpp
Go to the documentation of this file.
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"
25
26namespace LIEF {
27namespace MachO {
28class BinaryParser;
29class LinkEdit;
30
31namespace details {
32struct linkedit_data_command;
33}
34
35class 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 uint32_t data_offset() const {
56 return data_offset_;
57 }
58 uint32_t data_size() const {
61 return data_size_;
62 }
63 const std::vector<uint64_t>& functions() const {
70 return functions_;
71 }
72
73 std::vector<uint64_t>& functions() {
74 return functions_;
75 }
76 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
LoadCommand.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
LIEF::MachO::FunctionStarts
Class which represents the LC_FUNCTION_STARTS command.
Definition FunctionStarts.hpp:39
LIEF::MachO::FunctionStarts::content
span< const uint8_t > content() const
Definition FunctionStarts.hpp:93
LIEF::MachO::FunctionStarts::functions
std::vector< uint64_t > & functions()
Definition FunctionStarts.hpp:73
LIEF::MachO::FunctionStarts::print
std::ostream & print(std::ostream &os) const override
LIEF::MachO::FunctionStarts::data_size
void data_size(uint32_t size)
Definition FunctionStarts.hpp:85
LIEF::MachO::FunctionStarts::functions
const std::vector< uint64_t > & functions() const
Addresses of every function entry point in the executable.
Definition FunctionStarts.hpp:69
LIEF::MachO::FunctionStarts::data_offset
uint32_t data_offset() const
Offset in the __LINKEDIT SegmentCommand where start functions are located.
Definition FunctionStarts.hpp:55
LIEF::MachO::FunctionStarts::operator=
FunctionStarts & operator=(const FunctionStarts &copy)=default
LIEF::MachO::FunctionStarts::clone
std::unique_ptr< LoadCommand > clone() const override
Definition FunctionStarts.hpp:50
LIEF::MachO::FunctionStarts::data_offset
void data_offset(uint32_t offset)
Definition FunctionStarts.hpp:82
LIEF::MachO::FunctionStarts::FunctionStarts
FunctionStarts(const details::linkedit_data_command &cmd)
LIEF::MachO::FunctionStarts::~FunctionStarts
~FunctionStarts() override=default
LIEF::MachO::FunctionStarts::data_size
uint32_t data_size() const
Size of the functions list in the binary.
Definition FunctionStarts.hpp:60
LIEF::MachO::FunctionStarts::add_function
void add_function(uint64_t address)
Add a new function.
Definition FunctionStarts.hpp:78
LIEF::MachO::FunctionStarts::classof
static bool classof(const LoadCommand *cmd)
Definition FunctionStarts.hpp:107
LIEF::MachO::FunctionStarts::content
span< uint8_t > content()
Definition FunctionStarts.hpp:97
LIEF::MachO::FunctionStarts::functions
void functions(std::vector< uint64_t > funcs)
Definition FunctionStarts.hpp:89
LIEF::MachO::FunctionStarts::FunctionStarts
FunctionStarts()=default
LIEF::MachO::FunctionStarts::FunctionStarts
FunctionStarts(const FunctionStarts &copy)=default
LIEF::MachO::FunctionStarts::accept
void accept(Visitor &visitor) const override
LIEF::MachO::LinkEdit
Definition LinkEdit.hpp:42
LIEF::MachO::LoadCommand
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:37
LIEF::MachO::LoadCommand::command
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:124
LIEF::MachO::details
Definition endianness_support.hpp:59
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41