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 <string>
20#include "LIEF/span.hpp"
21#include "LIEF/iterators.hpp"
22#include "LIEF/visibility.h"
24
25namespace LIEF {
26namespace MachO {
27
28class BinaryParser;
29class Builder;
30class LinkEdit;
31class ExportInfo;
32class Binary;
33
34namespace details {
35struct linkedit_data_command;
36}
37
43 friend class BinaryParser;
44 friend class Builder;
45 friend class LinkEdit;
46 friend class Binary;
47
48 public:
50 using export_info_t = std::vector<std::unique_ptr<ExportInfo>>;
51
54
58
60 DyldExportsTrie(const details::linkedit_data_command& cmd);
61 std::unique_ptr<LoadCommand> clone() const override {
62 return std::unique_ptr<DyldExportsTrie>(new DyldExportsTrie(*this));
63 }
64
65 void swap(DyldExportsTrie& other) noexcept;
66
67 ~DyldExportsTrie() override;
68
71 uint32_t data_offset() const {
72 return data_offset_;
73 }
74
76 uint32_t data_size() const {
77 return data_size_;
78 }
79
80 void data_offset(uint32_t offset) {
81 data_offset_ = offset;
82 }
83 void data_size(uint32_t size) {
84 data_size_ = size;
85 }
86
88 return content_;
89 }
90
93 return export_info_;
94 }
95
97 return export_info_;
98 }
99
101 std::string show_export_trie() const;
102
105 ExportInfo* add(std::unique_ptr<ExportInfo> info) LIEF_LIFETIMEBOUND;
106
107 void accept(Visitor& visitor) const override;
108
109 std::ostream& print(std::ostream& os) const override;
110
111 static bool classof(const LoadCommand* cmd) {
113 }
114
115 private:
118
119 uint32_t data_offset_ = 0;
120 uint32_t data_size_ = 0;
121
122 // Raw payload of the DyldExportsTrie.
123 // This payload is located in the __LINKEDIT segment
124 span<uint8_t> content_;
125
126 export_info_t export_info_;
127};
128
129}
130}
131#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:89
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:42
std::unique_ptr< LoadCommand > clone() const override
Definition DyldExportsTrie.hpp:61
void accept(Visitor &visitor) const override
ref_iterator< export_info_t &, ExportInfo * > it_export_info
Iterator which outputs const ExportInfo&.
Definition DyldExportsTrie.hpp:53
span< const uint8_t > content() const
Definition DyldExportsTrie.hpp:87
DyldExportsTrie(const details::linkedit_data_command &cmd)
it_const_export_info exports() const
Definition DyldExportsTrie.hpp:96
friend class BinaryParser
Definition DyldExportsTrie.hpp:43
it_export_info exports()
Iterator over the ExportInfo entries.
Definition DyldExportsTrie.hpp:92
void data_size(uint32_t size)
Definition DyldExportsTrie.hpp:83
std::vector< std::unique_ptr< ExportInfo > > export_info_t
Internal container for storing ExportInfo.
Definition DyldExportsTrie.hpp:50
std::string show_export_trie() const
Print the exports trie in a human-readable way.
void data_offset(uint32_t offset)
Definition DyldExportsTrie.hpp:80
friend class Builder
Definition DyldExportsTrie.hpp:44
std::ostream & print(std::ostream &os) const override
friend class Binary
Definition DyldExportsTrie.hpp:46
const_ref_iterator< const export_info_t &, ExportInfo * > it_const_export_info
Iterator which outputs const ExportInfo&.
Definition DyldExportsTrie.hpp:56
friend class LinkEdit
Definition DyldExportsTrie.hpp:45
ExportInfo * add(std::unique_ptr< ExportInfo > info)
Add an entry in the current trie. See also: LIEF::MachO::Binary::add_exported_function.
uint32_t data_size() const
Size of the LC_DYLD_EXPORTS_TRIE payload.
Definition DyldExportsTrie.hpp:76
void swap(DyldExportsTrie &other) noexcept
static bool classof(const LoadCommand *cmd)
Definition DyldExportsTrie.hpp:111
uint32_t data_offset() const
Offset of the LC_DYLD_EXPORTS_TRIE. This offset should point in the __LINKEDIT segment.
Definition DyldExportsTrie.hpp:71
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 greater 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:47
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
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 returns a const ref on container's values.
Definition iterators.hpp:320
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46