LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
DyldExportsTrie.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_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
55
57 DyldExportsTrie(const details::linkedit_data_command& cmd);
58 std::unique_ptr<LoadCommand> clone() const override {
59 return std::unique_ptr<DyldExportsTrie>(new DyldExportsTrie(*this));
60 }
61
62 void swap(DyldExportsTrie& other) noexcept;
63
64 ~DyldExportsTrie() override;
65
68 uint32_t data_offset() const {
69 return data_offset_;
70 }
71
73 uint32_t data_size() const {
74 return data_size_;
75 }
76
77 void data_offset(uint32_t offset) {
78 data_offset_ = offset;
79 }
80 void data_size(uint32_t size) {
81 data_size_ = size;
82 }
83
85 return content_;
86 }
87
90 return export_info_;
91 }
92
94 return export_info_;
95 }
96
98 std::string show_export_trie() const;
99
102 void add(std::unique_ptr<ExportInfo> info);
103
104 void accept(Visitor& visitor) const override;
105
106 std::ostream& print(std::ostream& os) const override;
107
108 static bool classof(const LoadCommand* cmd) {
109 return cmd->command() == LoadCommand::TYPE::DYLD_EXPORTS_TRIE;
110 }
111
112 private:
113 DyldExportsTrie& operator=(DyldExportsTrie other);
114 DyldExportsTrie(const DyldExportsTrie& other);
115
116 uint32_t data_offset_ = 0;
117 uint32_t data_size_ = 0;
118
119 // Raw payload of the DyldChainedFixups.
120 // This payload is located in the __LINKEDIT segment
121 span<uint8_t> content_;
122
123 export_info_t export_info_;
124};
125
126}
127}
128#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
Class which represents a MachO binary.
Definition MachO/Binary.hpp:77
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:55
Class that represents the LC_DYLD_EXPORTS_TRIE command.
Definition DyldExportsTrie.hpp:40
std::unique_ptr< LoadCommand > clone() const override
Definition DyldExportsTrie.hpp:58
void accept(Visitor &visitor) const override
span< const uint8_t > content() const
Definition DyldExportsTrie.hpp:84
DyldExportsTrie(const details::linkedit_data_command &cmd)
it_const_export_info exports() const
Definition DyldExportsTrie.hpp:93
it_export_info exports()
Iterator over the ExportInfo entries.
Definition DyldExportsTrie.hpp:89
void data_size(uint32_t size)
Definition DyldExportsTrie.hpp:80
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:77
std::ostream & print(std::ostream &os) const override
uint32_t data_size() const
Size of the LC_DYLD_EXPORTS_TRIE payload.
Definition DyldExportsTrie.hpp:73
void swap(DyldExportsTrie &other) noexcept
static bool classof(const LoadCommand *cmd)
Definition DyldExportsTrie.hpp:108
uint32_t data_offset() const
Offset of the LC_DYLD_EXPORTS_TRIE. This offset should point in the __LINKEDIT segment.
Definition DyldExportsTrie.hpp:68
Definition LinkEdit.hpp:42
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:36
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:122
Definition Visitor.hpp:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41