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 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H
16#define LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H
17#include <memory>
18#include <ostream>
19
20#include "LIEF/iterators.hpp"
21#include "LIEF/visibility.h"
22
24
25
26namespace LIEF::MachO {
27class Symbol;
28class BinaryParser;
29class Builder;
30class Binary;
31
32namespace details {
33struct dysymtab_command;
34}
35
41 friend class BinaryParser;
42 friend class Builder;
43 friend class Binary;
44
45 public:
47 using indirect_symbols_t = std::vector<Symbol*>;
48
52
54
55 DynamicSymbolCommand(const details::dysymtab_command& cmd);
56
59
60 std::unique_ptr<LoadCommand> clone() const override {
61 return std::make_unique<DynamicSymbolCommand>(*this);
62 }
63
64 ~DynamicSymbolCommand() override = default;
65
66 void accept(Visitor& visitor) const override;
67
68 std::ostream& print(std::ostream& os) const override;
69
71 uint32_t idx_local_symbol() const {
72 return idx_local_symbol_;
73 }
74
76 uint32_t nb_local_symbols() const {
77 return nb_local_symbols_;
78 }
79
81 uint32_t idx_external_define_symbol() const {
82 return idx_external_define_symbol_;
83 }
84
86 uint32_t nb_external_define_symbols() const {
87 return nb_external_define_symbols_;
88 }
89
91 uint32_t idx_undefined_symbol() const {
92 return idx_undefined_symbol_;
93 }
94
96 uint32_t nb_undefined_symbols() const {
97 return nb_undefined_symbols_;
98 }
99
104 uint32_t toc_offset() const {
105 return toc_offset_;
106 }
107
111 uint32_t nb_toc() const {
112 return nb_toc_;
113 }
114
118 uint32_t module_table_offset() const {
119 return module_table_offset_;
120 }
121
125 uint32_t nb_module_table() const {
126 return nb_module_table_;
127 }
128
133 return external_reference_symbol_offset_;
134 }
135
140 return nb_external_reference_symbols_;
141 }
142
151 uint32_t indirect_symbol_offset() const {
152 return indirect_sym_offset_;
153 }
154
158 uint32_t nb_indirect_symbols() const {
159 return nb_indirect_symbols_;
160 }
161
162
166 uint32_t external_relocation_offset() const {
167 return external_relocation_offset_;
168 }
169
173 uint32_t nb_external_relocations() const {
174 return nb_external_relocations_;
175 }
176
180 uint32_t local_relocation_offset() const {
181 return local_relocation_offset_;
182 }
183
187 uint32_t nb_local_relocations() const {
188 return nb_local_relocations_;
189 }
190
191 void idx_local_symbol(uint32_t value) {
192 idx_local_symbol_ = value;
193 }
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
203 void nb_external_define_symbols(uint32_t value) {
204 nb_external_define_symbols_ = value;
205 }
206
207 void idx_undefined_symbol(uint32_t value) {
208 idx_undefined_symbol_ = value;
209 }
210
211 void nb_undefined_symbols(uint32_t value) {
212 nb_undefined_symbols_ = value;
213 }
214
215 void toc_offset(uint32_t value) {
216 toc_offset_ = value;
217 }
218
219 void nb_toc(uint32_t value) {
220 nb_toc_ = value;
221 }
222
223 void module_table_offset(uint32_t value) {
224 module_table_offset_ = value;
225 }
226
227 void nb_module_table(uint32_t value) {
228 nb_module_table_ = value;
229 }
230
231 void external_reference_symbol_offset(uint32_t value) {
232 external_reference_symbol_offset_ = value;
233 }
234
235 void nb_external_reference_symbols(uint32_t value) {
236 nb_external_reference_symbols_ = value;
237 }
238
239 void indirect_symbol_offset(uint32_t value) {
240 indirect_sym_offset_ = value;
241 }
242
243 void nb_indirect_symbols(uint32_t value) {
244 nb_indirect_symbols_ = value;
245 }
246
247 void external_relocation_offset(uint32_t value) {
248 external_relocation_offset_ = value;
249 }
250
251 void nb_external_relocations(uint32_t value) {
252 nb_external_relocations_ = value;
253 }
254
255 void local_relocation_offset(uint32_t value) {
256 local_relocation_offset_ = value;
257 }
258
259 void nb_local_relocations(uint32_t value) {
260 nb_local_relocations_ = value;
261 }
262
265 return indirect_symbols_;
266 }
267
269 return indirect_symbols_;
270 }
271
272 static bool classof(const LoadCommand* cmd) {
273 return cmd->command() == LoadCommand::TYPE::DYSYMTAB;
274 }
275
276 private:
277 uint32_t idx_local_symbol_ = 0;
278 uint32_t nb_local_symbols_ = 0;
279
280 uint32_t idx_external_define_symbol_ = 0;
281 uint32_t nb_external_define_symbols_ = 0;
282
283 uint32_t idx_undefined_symbol_ = 0;
284 uint32_t nb_undefined_symbols_ = 0;
285
286 uint32_t toc_offset_ = 0;
287 uint32_t nb_toc_ = 0;
288
289 uint32_t module_table_offset_ = 0;
290 uint32_t nb_module_table_ = 0;
291
292 uint32_t external_reference_symbol_offset_ = 0;
293 uint32_t nb_external_reference_symbols_ = 0;
294
295 uint32_t indirect_sym_offset_ = 0;
296 uint32_t nb_indirect_symbols_ = 0;
297
298 uint32_t external_relocation_offset_ = 0;
299 uint32_t nb_external_relocations_ = 0;
300
301 uint32_t local_relocation_offset_ = 0;
302 uint32_t nb_local_relocations_ = 0;
303
304 indirect_symbols_t indirect_symbols_;
305};
306
307}
308
309#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:80
Class which represents a MachO binary.
Definition MachO/Binary.hpp:93
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:63
uint32_t nb_module_table() const
Number of entries in the module table.
Definition DynamicSymbolCommand.hpp:125
void nb_local_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:195
void local_relocation_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:255
void idx_undefined_symbol(uint32_t value)
Definition DynamicSymbolCommand.hpp:207
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:96
void indirect_symbol_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:239
void external_reference_symbol_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:231
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:158
uint32_t nb_external_relocations() const
Number of entries in the external relocation table.
Definition DynamicSymbolCommand.hpp:173
void nb_module_table(uint32_t value)
Definition DynamicSymbolCommand.hpp:227
friend class BinaryParser
Definition DynamicSymbolCommand.hpp:41
void external_relocation_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:247
it_indirect_symbols indirect_symbols()
Iterator over the indirect symbols indexed by this command.
Definition DynamicSymbolCommand.hpp:264
uint32_t nb_external_define_symbols() const
Number of symbols in the group of defined external symbols.
Definition DynamicSymbolCommand.hpp:86
std::ostream & print(std::ostream &os) const override
void nb_undefined_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:211
uint32_t nb_external_reference_symbols() const
Number of entries in the external reference table.
Definition DynamicSymbolCommand.hpp:139
std::unique_ptr< LoadCommand > clone() const override
Definition DynamicSymbolCommand.hpp:60
const_ref_iterator< const indirect_symbols_t & > it_const_indirect_symbols
Definition DynamicSymbolCommand.hpp:51
void nb_indirect_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:243
DynamicSymbolCommand(const details::dysymtab_command &cmd)
void nb_local_relocations(uint32_t value)
Definition DynamicSymbolCommand.hpp:259
uint32_t external_relocation_offset() const
Byte offset from the start of the file to the external relocation table data.
Definition DynamicSymbolCommand.hpp:166
friend class Builder
Definition DynamicSymbolCommand.hpp:42
static bool classof(const LoadCommand *cmd)
Definition DynamicSymbolCommand.hpp:272
void toc_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:215
DynamicSymbolCommand(const DynamicSymbolCommand &copy)=default
uint32_t nb_local_symbols() const
Number of symbols in the group of local symbols.
Definition DynamicSymbolCommand.hpp:76
DynamicSymbolCommand & operator=(const DynamicSymbolCommand &copy)=default
friend class Binary
Definition DynamicSymbolCommand.hpp:43
uint32_t module_table_offset() const
Byte offset from the start of the file to the module table data.
Definition DynamicSymbolCommand.hpp:118
uint32_t local_relocation_offset() const
Byte offset from the start of the file to the local relocation table data.
Definition DynamicSymbolCommand.hpp:180
uint32_t indirect_symbol_offset() const
Byte offset from the start of the file to the indirect symbol table data.
Definition DynamicSymbolCommand.hpp:151
void nb_external_define_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:203
uint32_t external_reference_symbol_offset() const
Byte offset from the start of the file to the external reference table data.
Definition DynamicSymbolCommand.hpp:132
it_const_indirect_symbols indirect_symbols() const
Definition DynamicSymbolCommand.hpp:268
void nb_external_reference_symbols(uint32_t value)
Definition DynamicSymbolCommand.hpp:235
std::vector< Symbol * > indirect_symbols_t
Container for the indirect symbols references (owned by MachO::Binary).
Definition DynamicSymbolCommand.hpp:47
uint32_t toc_offset() const
Byte offset from the start of the file to the table of contents data.
Definition DynamicSymbolCommand.hpp:104
void nb_toc(uint32_t value)
Definition DynamicSymbolCommand.hpp:219
uint32_t nb_local_relocations() const
Number of entries in the local relocation table.
Definition DynamicSymbolCommand.hpp:187
uint32_t idx_external_define_symbol() const
Index of the first symbol in the group of defined external symbols.
Definition DynamicSymbolCommand.hpp:81
uint32_t nb_toc() const
Number of entries in the table of contents.
Definition DynamicSymbolCommand.hpp:111
uint32_t idx_local_symbol() const
Index of the first symbol in the group of local symbols.
Definition DynamicSymbolCommand.hpp:71
void nb_external_relocations(uint32_t value)
Definition DynamicSymbolCommand.hpp:251
void module_table_offset(uint32_t value)
Definition DynamicSymbolCommand.hpp:223
void idx_local_symbol(uint32_t value)
Definition DynamicSymbolCommand.hpp:191
ref_iterator< indirect_symbols_t & > it_indirect_symbols
Iterator for the indirect symbols referenced by this command.
Definition DynamicSymbolCommand.hpp:50
~DynamicSymbolCommand() override=default
uint32_t idx_undefined_symbol() const
Index of the first symbol in the group of undefined external symbols.
Definition DynamicSymbolCommand.hpp:91
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:131
@ DYSYMTAB
Definition LoadCommand.hpp:58
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:46
Definition Visitor.hpp:211
Iterator which returns reference on container's values.
Definition iterators.hpp:120
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition endianness_support.hpp:62
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:35
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:385
#define LIEF_API
Definition visibility.h:44