LIEF: Library to Instrument Executable Formats Version 0.17.0
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}
41 friend class BinaryParser;
42 friend class Builder;
43 friend class LinkEdit;
44 friend class Binary;
45
46 public: using export_info_t = std::vector<std::unique_ptr<ExportInfo>>;
49 using it_export_info = ref_iterator<export_info_t&, ExportInfo*>;
52 using it_const_export_info = const_ref_iterator<const export_info_t&, ExportInfo*>;
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 uint32_t data_offset() const {
69 return data_offset_;
70 }
71 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
84 span<const uint8_t> content() const {
85 return content_;
86 }
87 it_export_info exports() {
90 return export_info_;
91 }
92
93 it_const_export_info exports() const {
94 return export_info_;
95 }
96 std::string show_export_trie() const;
99 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 LIEF_LOCAL DyldExportsTrie& operator=(DyldExportsTrie other);
114 LIEF_LOCAL 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
LoadCommand.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:75
LIEF::MachO::Binary
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
LIEF::MachO::Builder
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:58
LIEF::MachO::DyldExportsTrie
Class that represents the LC_DYLD_EXPORTS_TRIE command.
Definition DyldExportsTrie.hpp:40
LIEF::MachO::DyldExportsTrie::clone
std::unique_ptr< LoadCommand > clone() const override
Definition DyldExportsTrie.hpp:58
LIEF::MachO::DyldExportsTrie::accept
void accept(Visitor &visitor) const override
LIEF::MachO::DyldExportsTrie::content
span< const uint8_t > content() const
Definition DyldExportsTrie.hpp:84
LIEF::MachO::DyldExportsTrie::DyldExportsTrie
DyldExportsTrie(const details::linkedit_data_command &cmd)
LIEF::MachO::DyldExportsTrie::exports
it_const_export_info exports() const
Definition DyldExportsTrie.hpp:93
LIEF::MachO::DyldExportsTrie::exports
it_export_info exports()
Iterator over the ExportInfo entries.
Definition DyldExportsTrie.hpp:89
LIEF::MachO::DyldExportsTrie::data_size
void data_size(uint32_t size)
Definition DyldExportsTrie.hpp:80
LIEF::MachO::DyldExportsTrie::add
void add(std::unique_ptr< ExportInfo > info)
Add an entrie in the current trie. See also: LIEF::MachO::Binary::add_exported_function.
LIEF::MachO::DyldExportsTrie::show_export_trie
std::string show_export_trie() const
Print the exports trie in a humman-readable way.
LIEF::MachO::DyldExportsTrie::~DyldExportsTrie
~DyldExportsTrie() override
LIEF::MachO::DyldExportsTrie::data_offset
void data_offset(uint32_t offset)
Definition DyldExportsTrie.hpp:77
LIEF::MachO::DyldExportsTrie::print
std::ostream & print(std::ostream &os) const override
LIEF::MachO::DyldExportsTrie::DyldExportsTrie
DyldExportsTrie()
LIEF::MachO::DyldExportsTrie::data_size
uint32_t data_size() const
Size of the LC_DYLD_EXPORTS_TRIE payload.
Definition DyldExportsTrie.hpp:73
LIEF::MachO::DyldExportsTrie::swap
void swap(DyldExportsTrie &other) noexcept
LIEF::MachO::DyldExportsTrie::classof
static bool classof(const LoadCommand *cmd)
Definition DyldExportsTrie.hpp:108
LIEF::MachO::DyldExportsTrie::data_offset
uint32_t data_offset() const
Offset of the LC_DYLD_EXPORTS_TRIE. This offset should point in the __LINKEDIT segment.
Definition DyldExportsTrie.hpp:68
LIEF::MachO::ExportInfo
Class that provides an interface over the Dyld export info.
Definition ExportInfo.hpp:38
LIEF::MachO::LinkEdit
Definition LinkEdit.hpp:43
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:125
iterators.hpp
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
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42