LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
DyldExportsTrie.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_DYLD_EXPORTS_TRIE_H
17#define LIEF_MACHO_DYLD_EXPORTS_TRIE_H
18#include <memory>
19#include "LIEF/span.hpp"
20#include "LIEF/iterators.hpp"
21#include "LIEF/visibility.h"
23
24namespace LIEF {
25namespace MachO {
26
27class BinaryParser;
28class Builder;
29class LinkEdit;
30class ExportInfo;
31class Binary;
32
33namespace details {
34struct linkedit_data_command;
35}
36
41 friend class BinaryParser;
42 friend class Builder;
43 friend class LinkEdit;
44 friend class Binary;
45
46 public:
48 using export_info_t = std::vector<std::unique_ptr<ExportInfo>>;
49
52
56
58 DyldExportsTrie(const details::linkedit_data_command& cmd);
59 std::unique_ptr<LoadCommand> clone() const override {
60 return std::unique_ptr<DyldExportsTrie>(new DyldExportsTrie(*this));
61 }
62
63 void swap(DyldExportsTrie& other) noexcept;
64
65 ~DyldExportsTrie() override;
66
69 uint32_t data_offset() const {
70 return data_offset_;
71 }
72
74 uint32_t data_size() const {
75 return data_size_;
76 }
77
78 void data_offset(uint32_t offset) {
79 data_offset_ = offset;
80 }
81 void data_size(uint32_t size) {
82 data_size_ = size;
83 }
84
86 return content_;
87 }
88
91 return export_info_;
92 }
93
95 return export_info_;
96 }
97
99 std::string show_export_trie() const;
100
103 void add(std::unique_ptr<ExportInfo> info);
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:
116
117 uint32_t data_offset_ = 0;
118 uint32_t data_size_ = 0;
119
120 // Raw payload of the DyldChainedFixups.
121 // This payload is located in the __LINKEDIT segment
122 span<uint8_t> content_;
123
124 export_info_t export_info_;
125};
126
127}
128}
129#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:78
Class which represents a MachO binary.
Definition MachO/Binary.hpp:88
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:63
Class that represents the LC_DYLD_EXPORTS_TRIE command.
Definition DyldExportsTrie.hpp:40
std::unique_ptr< LoadCommand > clone() const override
Definition DyldExportsTrie.hpp:59
void accept(Visitor &visitor) const override
ref_iterator< export_info_t &, ExportInfo * > it_export_info
Iterator which outputs const ExportInfo&.
Definition DyldExportsTrie.hpp:51
span< const uint8_t > content() const
Definition DyldExportsTrie.hpp:85
DyldExportsTrie(const details::linkedit_data_command &cmd)
it_const_export_info exports() const
Definition DyldExportsTrie.hpp:94
friend class BinaryParser
Definition DyldExportsTrie.hpp:41
it_export_info exports()
Iterator over the ExportInfo entries.
Definition DyldExportsTrie.hpp:90
void data_size(uint32_t size)
Definition DyldExportsTrie.hpp:81
void add(std::unique_ptr< ExportInfo > info)
Add an entrie in the current trie. See also: LIEF::MachO::Binary::add_exported_function.
std::vector< std::unique_ptr< ExportInfo > > export_info_t
Internal container for storing ExportInfo.
Definition DyldExportsTrie.hpp:48
std::string show_export_trie() const
Print the exports trie in a humman-readable way.
void data_offset(uint32_t offset)
Definition DyldExportsTrie.hpp:78
friend class Builder
Definition DyldExportsTrie.hpp:42
std::ostream & print(std::ostream &os) const override
friend class Binary
Definition DyldExportsTrie.hpp:44
const_ref_iterator< const export_info_t &, ExportInfo * > it_const_export_info
Iterator which outputs const ExportInfo&.
Definition DyldExportsTrie.hpp:54
friend class LinkEdit
Definition DyldExportsTrie.hpp:43
uint32_t data_size() const
Size of the LC_DYLD_EXPORTS_TRIE payload.
Definition DyldExportsTrie.hpp:74
void swap(DyldExportsTrie &other) noexcept
static bool classof(const LoadCommand *cmd)
Definition DyldExportsTrie.hpp:109
uint32_t data_offset() const
Offset of the LC_DYLD_EXPORTS_TRIE. This offset should point in the __LINKEDIT segment.
Definition DyldExportsTrie.hpp:69
Class that provides an interface over the Dyld export info.
Definition ExportInfo.hpp:38
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
@ DYLD_EXPORTS_TRIE
Definition LoadCommand.hpp:98
Definition Visitor.hpp:212
Iterator which returns reference on container's values.
Definition iterators.hpp:45
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
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:286
#define LIEF_API
Definition visibility.h:43
#define LIEF_LOCAL
Definition visibility.h:44