LIEF: Library to Instrument Executable Formats Version
Loading...
Searching...
No Matches
DyldExportsTrie.hpp
1/* Copyright 2017 - 2023 R. Thomas
2 * Copyright 2017 - 2023 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"
22#include "LIEF/MachO/LoadCommand.hpp"
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
40class LIEF_API DyldExportsTrie : public LoadCommand {
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 DyldExportsTrie* clone() const override;
59
60 void swap(DyldExportsTrie& other);
61
62 ~DyldExportsTrie() override;
63
66 uint32_t data_offset() const;
67
69 uint32_t data_size() const;
70
71 void data_offset(uint32_t offset);
72 void data_size(uint32_t size);
73
74 span<const uint8_t> content() const {
75 return content_;
76 }
77
80 it_const_export_info exports() const;
81
83 std::string show_export_trie() const;
84
87 void add(std::unique_ptr<ExportInfo> info);
88
89
90 void accept(Visitor& visitor) const override;
91
92 std::ostream& print(std::ostream& os) const override;
93
94 static bool classof(const LoadCommand* cmd);
95
96 private:
97 DyldExportsTrie& operator=(DyldExportsTrie other);
98 DyldExportsTrie(const DyldExportsTrie& other);
99
100 uint32_t data_offset_ = 0;
101 uint32_t data_size_ = 0;
102
103 // Raw payload of the DyldChainedFixups.
104 // This payload is located in the __LINKEDIT segment
105 span<uint8_t> content_;
106
107 export_info_t export_info_;
108};
109
110}
111}
112#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:73
Class which represents a MachO binary.
Definition MachO/Binary.hpp:74
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:58
Class that represents the LC_DYLD_EXPORTS_TRIE command.
Definition DyldExportsTrie.hpp:40
std::vector< std::unique_ptr< ExportInfo > > export_info_t
Internal container for storing ExportInfo.
Definition DyldExportsTrie.hpp:48
it_export_info exports()
Iterator over the ExportInfo entries.
void add(std::unique_ptr< ExportInfo > info)
Add an entrie in the current trie. See also: LIEF::MachO::Binary::add_exported_function.
std::string show_export_trie() const
Print the exports trie in a humman-readable way.
uint32_t data_size() const
Size of the LC_DYLD_EXPORTS_TRIE payload.
uint32_t data_offset() const
Offset of the LC_DYLD_EXPORTS_TRIE. This offset should point in the __LINKEDIT segment.
Definition LinkEdit.hpp:48
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:39
Definition Visitor.hpp:219
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32