LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DynamicSymbolCommand.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_DYNAMIC_SYMBOL_COMMAND_H
17#define LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H
18#include <memory>
19#include <ostream>
20
21#include "LIEF/iterators.hpp"
22#include "LIEF/visibility.h"
23
25
26
27namespace LIEF::MachO {
28class Symbol;
29class BinaryParser;
30class Builder;
31class Binary;
32
33namespace details {
34struct dysymtab_command;
35}
36
42 friend class BinaryParser;
43 friend class Builder;
44 friend class Binary;
45
46 public:
48 using indirect_symbols_t = std::vector<Symbol*>;
49
53
55
56 DynamicSymbolCommand(const details::dysymtab_command& cmd);
57
60
61 std::unique_ptr<LoadCommand> clone() const override {
62 return std::make_unique<DynamicSymbolCommand>(*this);
63 }
64
65 ~DynamicSymbolCommand() override = default;
66
67 void accept(Visitor& visitor) const override;
68
69 std::ostream& print(std::ostream& os) const override;
70
72 uint32_t idx_local_symbol() const {
73 return idx_local_symbol_;
74 }
75
77 uint32_t nb_local_symbols() const {
78 return nb_local_symbols_;
79 }
80
82 uint32_t idx_external_define_symbol() const {
83 return idx_external_define_symbol_;
84 }
85
87 uint32_t nb_external_define_symbols() const {
88 return nb_external_define_symbols_;
89 }
90
92 uint32_t idx_undefined_symbol() const {
93 return idx_undefined_symbol_;
94 }
95
97 uint32_t nb_undefined_symbols() const {
98 return nb_undefined_symbols_;
99 }
100
105 uint32_t toc_offset() const {
106 return toc_offset_;
107 }
108
112 uint32_t nb_toc() const {
113 return nb_toc_;
114 }
115
119 uint32_t module_table_offset() const {
120 return module_table_offset_;
121 }
122
126 uint32_t nb_module_table() const {
127 return nb_module_table_;
128 }
129
134 return external_reference_symbol_offset_;
135 }
136
141 return nb_external_reference_symbols_;
142 }
143
152 uint32_t indirect_symbol_offset() const {
153 return indirect_sym_offset_;
154 }
155
159 uint32_t nb_indirect_symbols() const {
160 return nb_indirect_symbols_;
161 }
162
163
167 uint32_t external_relocation_offset() const {
168 return external_relocation_offset_;
169 }
170
174 uint32_t nb_external_relocations() const {
175 return nb_external_relocations_;
176 }
177
181 uint32_t local_relocation_offset() const {
182 return local_relocation_offset_;
183 }
184
188 uint32_t nb_local_relocations() const {
189 return nb_local_relocations_;
190 }
191
192 void idx_local_symbol(uint32_t value) {
193 idx_local_symbol_ = value;
194 }
195 void nb_local_symbols(uint32_t value) {
196 nb_local_symbols_ = value;
197 }
198
199 void idx_external_define_symbol(uint32_t value) {
200 idx_external_define_symbol_ = value;
201 }
202 void nb_external_define_symbols(uint32_t value) {
203 nb_external_define_symbols_ = value;
204 }
205
206 void idx_undefined_symbol(uint32_t value) {
207 idx_undefined_symbol_ = value;
208 }
209 void nb_undefined_symbols(uint32_t value) {
210 nb_undefined_symbols_ = value;
211 }
212
213 void toc_offset(uint32_t value) {
214 toc_offset_ = value;
215 }
216 void nb_toc(uint32_t value) {
217 nb_toc_ = value;
218 }
219
220 void module_table_offset(uint32_t value) {
221 module_table_offset_ = value;
222 }
223 void nb_module_table(uint32_t value) {
224 nb_module_table_ = value;
225 }
226
227 void external_reference_symbol_offset(uint32_t value) {
228 external_reference_symbol_offset_ = value;
229 }
230 void nb_external_reference_symbols(uint32_t value) {
231 nb_external_reference_symbols_ = value;
232 }
233
234 void indirect_symbol_offset(uint32_t value) {
235 indirect_sym_offset_ = value;
236 }
237 void nb_indirect_symbols(uint32_t value) {
238 nb_indirect_symbols_ = value;
239 }
240
241 void external_relocation_offset(uint32_t value) {
242 external_relocation_offset_ = value;
243 }
244 void nb_external_relocations(uint32_t value) {
245 nb_external_relocations_ = value;
246 }
247
248 void local_relocation_offset(uint32_t value) {
249 local_relocation_offset_ = value;
250 }
251 void nb_local_relocations(uint32_t value) {
252 nb_local_relocations_ = value;
253 }
254
257 return indirect_symbols_;
258 }
259
261 return indirect_symbols_;
262 }
263
264 static bool classof(const LoadCommand* cmd) {
265 return cmd->command() == LoadCommand::TYPE::DYSYMTAB;
266 }
267
268 private:
269 uint32_t idx_local_symbol_ = 0;
270 uint32_t nb_local_symbols_ = 0;
271
272 uint32_t idx_external_define_symbol_ = 0;
273 uint32_t nb_external_define_symbols_ = 0;
274
275 uint32_t idx_undefined_symbol_ = 0;
276 uint32_t nb_undefined_symbols_ = 0;
277
278 uint32_t toc_offset_ = 0;
279 uint32_t nb_toc_ = 0;
280
281 uint32_t module_table_offset_ = 0;
282 uint32_t nb_module_table_ = 0;
283
284 uint32_t external_reference_symbol_offset_ = 0;
285 uint32_t nb_external_reference_symbols_ = 0;
286
287 uint32_t indirect_sym_offset_ = 0;
288 uint32_t nb_indirect_symbols_ = 0;
289
290 uint32_t external_relocation_offset_ = 0;
291 uint32_t nb_external_relocations_ = 0;
292
293 uint32_t local_relocation_offset_ = 0;
294 uint32_t nb_local_relocations_ = 0;
295
296 indirect_symbols_t indirect_symbols_;
297};
298
299}
300
301#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:79
Class which represents a MachO binary.
Definition MachO/Binary.hpp:94
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:64
uint32_t nb_module_table() const
Number of entries in the module table.
Definition DynamicSymbolCommand.hpp:126
void nb_local_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:195
void local_relocation_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:248
void idx_undefined_symbol(uint32_t value)
Definition DynamicSymbolCommand.hpp:206
void accept(Visitor &visitor) const override
uint32_t nb_undefined_symbols() const
Number of symbols in the group of undefined external symbols.
Definition DynamicSymbolCommand.hpp:97
void indirect_symbol_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:234
void external_reference_symbol_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:227
void idx_external_define_symbol(uint32_t value)
Definition DynamicSymbolCommand.hpp:199
uint32_t nb_indirect_symbols() const
Number of entries in the indirect symbol table.
Definition DynamicSymbolCommand.hpp:159
uint32_t nb_external_relocations() const
Number of entries in the external relocation table.
Definition DynamicSymbolCommand.hpp:174
void nb_module_table(uint32_t value)
Definition DynamicSymbolCommand.hpp:223
friend class BinaryParser
Definition DynamicSymbolCommand.hpp:42
void external_relocation_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:241
it_indirect_symbols indirect_symbols()
Iterator over the indirect symbols indexed by this command.
Definition DynamicSymbolCommand.hpp:256
uint32_t nb_external_define_symbols() const
Number of symbols in the group of defined external symbols.
Definition DynamicSymbolCommand.hpp:87
std::ostream & print(std::ostream &os) const override
void nb_undefined_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:209
uint32_t nb_external_reference_symbols() const
Number of entries in the external reference table.
Definition DynamicSymbolCommand.hpp:140
std::unique_ptr< LoadCommand > clone() const override
Definition DynamicSymbolCommand.hpp:61
const_ref_iterator< const indirect_symbols_t & > it_const_indirect_symbols
Definition DynamicSymbolCommand.hpp:52
void nb_indirect_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:237
DynamicSymbolCommand(const details::dysymtab_command &cmd)
void nb_local_relocations(uint32_t value)
Definition DynamicSymbolCommand.hpp:251
uint32_t external_relocation_offset() const
Byte offset from the start of the file to the external relocation table data.
Definition DynamicSymbolCommand.hpp:167
friend class Builder
Definition DynamicSymbolCommand.hpp:43
static bool classof(const LoadCommand *cmd)
Definition DynamicSymbolCommand.hpp:264
void toc_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:213
DynamicSymbolCommand(const DynamicSymbolCommand &copy)=default
uint32_t nb_local_symbols() const
Number of symbols in the group of local symbols.
Definition DynamicSymbolCommand.hpp:77
DynamicSymbolCommand & operator=(const DynamicSymbolCommand &copy)=default
friend class Binary
Definition DynamicSymbolCommand.hpp:44
uint32_t module_table_offset() const
Byte offset from the start of the file to the module table data.
Definition DynamicSymbolCommand.hpp:119
uint32_t local_relocation_offset() const
Byte offset from the start of the file to the local relocation table data.
Definition DynamicSymbolCommand.hpp:181
uint32_t indirect_symbol_offset() const
Byte offset from the start of the file to the indirect symbol table data.
Definition DynamicSymbolCommand.hpp:152
void nb_external_define_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:202
uint32_t external_reference_symbol_offset() const
Byte offset from the start of the file to the external reference table data.
Definition DynamicSymbolCommand.hpp:133
it_const_indirect_symbols indirect_symbols() const
Definition DynamicSymbolCommand.hpp:260
void nb_external_reference_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:230
std::vector< Symbol * > indirect_symbols_t
Container for the indirect symbols references (owned by MachO::Binary).
Definition DynamicSymbolCommand.hpp:48
uint32_t toc_offset() const
Byte offset from the start of the file to the table of contents data.
Definition DynamicSymbolCommand.hpp:105
void nb_toc(uint32_t value)
Definition DynamicSymbolCommand.hpp:216
uint32_t nb_local_relocations() const
Number of entries in the local relocation table.
Definition DynamicSymbolCommand.hpp:188
uint32_t idx_external_define_symbol() const
Index of the first symbol in the group of defined external symbols.
Definition DynamicSymbolCommand.hpp:82
uint32_t nb_toc() const
Number of entries in the table of contents.
Definition DynamicSymbolCommand.hpp:112
uint32_t idx_local_symbol() const
Index of the first symbol in the group of local symbols.
Definition DynamicSymbolCommand.hpp:72
void nb_external_relocations(uint32_t value)
Definition DynamicSymbolCommand.hpp:244
void module_table_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:220
void idx_local_symbol(uint32_t value)
Definition DynamicSymbolCommand.hpp:192
ref_iterator< indirect_symbols_t & > it_indirect_symbols
Iterator for the indirect symbols referenced by this command.
Definition DynamicSymbolCommand.hpp:51
~DynamicSymbolCommand() override=default
uint32_t idx_undefined_symbol() const
Index of the first symbol in the group of undefined external symbols.
Definition DynamicSymbolCommand.hpp:92
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:132
@ DYSYMTAB
Definition LoadCommand.hpp:59
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
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:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
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:316
#define LIEF_API
Definition visibility.h:45