LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
DynamicSymbolCommand.hpp
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_DYNAMIC_SYMBOL_COMMAND_H
17#define LIEF_MACHO_DYNAMIC_SYMBOL_COMMAND_H
18#include <ostream>
19
20#include "LIEF/visibility.h"
21
22#include "LIEF/MachO/LoadCommand.hpp"
23
24namespace LIEF {
25namespace MachO {
26class Symbol;
27class BinaryParser;
28class Builder;
29class Binary;
30
31namespace details {
32struct dysymtab_command;
33}
34
39class LIEF_API DynamicSymbolCommand : public LoadCommand {
40 friend class BinaryParser;
41 friend class Builder;
42 friend class Binary;
43
44 public:
46
47 DynamicSymbolCommand(const details::dysymtab_command& cmd);
48
49 DynamicSymbolCommand& operator=(const DynamicSymbolCommand& copy) = default;
50 DynamicSymbolCommand(const DynamicSymbolCommand& copy) = default;
51
52 std::unique_ptr<LoadCommand> clone() const override {
53 return std::unique_ptr<DynamicSymbolCommand>(new DynamicSymbolCommand(*this));
54 }
55
56 ~DynamicSymbolCommand() override = default;
57
58 void accept(Visitor& visitor) const override;
59
60 std::ostream& print(std::ostream& os) const override;
61
63 uint32_t idx_local_symbol() const {
64 return idx_local_symbol_;
65 }
66
68 uint32_t nb_local_symbols() const {
69 return nb_local_symbols_;
70 }
71
73 uint32_t idx_external_define_symbol() const {
74 return idx_external_define_symbol_;
75 }
76
78 uint32_t nb_external_define_symbols() const {
79 return nb_external_define_symbols_;
80 }
81
83 uint32_t idx_undefined_symbol() const {
84 return idx_undefined_symbol_;
85 }
86
88 uint32_t nb_undefined_symbols() const {
89 return nb_undefined_symbols_;
90 }
91
96 uint32_t toc_offset() const {
97 return toc_offset_;
98 }
99
103 uint32_t nb_toc() const {
104 return nb_toc_;
105 }
106
110 uint32_t module_table_offset() const {
111 return module_table_offset_;
112 }
113
117 uint32_t nb_module_table() const {
118 return nb_module_table_;
119 }
120
125 return external_reference_symbol_offset_;
126 }
127
132 return nb_external_reference_symbols_;
133 }
134
143 uint32_t indirect_symbol_offset() const {
144 return indirect_sym_offset_;
145 }
146
150 uint32_t nb_indirect_symbols() const {
151 return nb_indirect_symbols_;
152 }
153
154
158 uint32_t external_relocation_offset() const {
159 return external_relocation_offset_;
160 }
161
165 uint32_t nb_external_relocations() const {
166 return nb_external_relocations_;
167 }
168
172 uint32_t local_relocation_offset() const {
173 return local_relocation_offset_;
174 }
175
179 uint32_t nb_local_relocations() const {
180 return nb_local_relocations_;
181 }
182
183 void idx_local_symbol(uint32_t value) {
184 idx_local_symbol_ = value;
185 }
186 void nb_local_symbols(uint32_t value) {
187 nb_local_symbols_ = value;
188 }
189
190 void idx_external_define_symbol(uint32_t value) {
191 idx_external_define_symbol_ = value;
192 }
193 void nb_external_define_symbols(uint32_t value) {
194 nb_external_define_symbols_ = value;
195 }
196
197 void idx_undefined_symbol(uint32_t value) {
198 idx_undefined_symbol_ = value;
199 }
200 void nb_undefined_symbols(uint32_t value) {
201 nb_undefined_symbols_ = value;
202 }
203
204 void toc_offset(uint32_t value) {
205 toc_offset_ = value;
206 }
207 void nb_toc(uint32_t value) {
208 nb_toc_ = value;
209 }
210
211 void module_table_offset(uint32_t value) {
212 module_table_offset_ = value;
213 }
214 void nb_module_table(uint32_t value) {
215 nb_module_table_ = value;
216 }
217
218 void external_reference_symbol_offset(uint32_t value) {
219 external_reference_symbol_offset_ = value;
220 }
221 void nb_external_reference_symbols(uint32_t value) {
222 nb_external_reference_symbols_ = value;
223 }
224
225 void indirect_symbol_offset(uint32_t value) {
226 indirect_sym_offset_ = value;
227 }
228 void nb_indirect_symbols(uint32_t value) {
229 nb_indirect_symbols_ = value;
230 }
231
232 void external_relocation_offset(uint32_t value) {
233 external_relocation_offset_ = value;
234 }
235 void nb_external_relocations(uint32_t value) {
236 nb_external_relocations_ = value;
237 }
238
239 void local_relocation_offset(uint32_t value) {
240 local_relocation_offset_ = value;
241 }
242 void nb_local_relocations(uint32_t value) {
243 nb_local_relocations_ = value;
244 }
245
246 static bool classof(const LoadCommand* cmd) {
247 return cmd->command() == LoadCommand::TYPE::DYSYMTAB;
248 }
249
250 private:
251 uint32_t idx_local_symbol_ = 0;
252 uint32_t nb_local_symbols_ = 0;
253
254 uint32_t idx_external_define_symbol_ = 0;
255 uint32_t nb_external_define_symbols_ = 0;
256
257 uint32_t idx_undefined_symbol_ = 0;
258 uint32_t nb_undefined_symbols_ = 0;
259
260 uint32_t toc_offset_ = 0;
261 uint32_t nb_toc_ = 0;
262
263 uint32_t module_table_offset_ = 0;
264 uint32_t nb_module_table_ = 0;
265
266 uint32_t external_reference_symbol_offset_ = 0;
267 uint32_t nb_external_reference_symbols_ = 0;
268
269 uint32_t indirect_sym_offset_ = 0;
270 uint32_t nb_indirect_symbols_ = 0;
271
272 uint32_t external_relocation_offset_ = 0;
273 uint32_t nb_external_relocations_ = 0;
274
275 uint32_t local_relocation_offset_ = 0;
276 uint32_t nb_local_relocations_ = 0;
277
278 std::vector<Symbol*> indirect_symbols_;
279};
280
281}
282}
283#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:73
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:54
Class that represents the LC_DYSYMTAB command.
Definition DynamicSymbolCommand.hpp:39
uint32_t nb_module_table() const
Number of entries in the module table.
Definition DynamicSymbolCommand.hpp:117
uint32_t nb_undefined_symbols() const
Number of symbols in the group of undefined external symbols.
Definition DynamicSymbolCommand.hpp:88
uint32_t nb_indirect_symbols() const
Number of entries in the indirect symbol table.
Definition DynamicSymbolCommand.hpp:150
uint32_t nb_external_relocations() const
Number of entries in the external relocation table.
Definition DynamicSymbolCommand.hpp:165
uint32_t nb_external_define_symbols() const
Number of symbols in the group of defined external symbols.
Definition DynamicSymbolCommand.hpp:78
uint32_t nb_external_reference_symbols() const
Number of entries in the external reference table.
Definition DynamicSymbolCommand.hpp:131
uint32_t external_relocation_offset() const
Byte offset from the start of the file to the external relocation table data.
Definition DynamicSymbolCommand.hpp:158
uint32_t nb_local_symbols() const
Number of symbols in the group of local symbols.
Definition DynamicSymbolCommand.hpp:68
uint32_t module_table_offset() const
Byte offset from the start of the file to the module table data.
Definition DynamicSymbolCommand.hpp:110
uint32_t local_relocation_offset() const
Byte offset from the start of the file to the local relocation table data.
Definition DynamicSymbolCommand.hpp:172
uint32_t indirect_symbol_offset() const
Byte offset from the start of the file to the indirect symbol table data.
Definition DynamicSymbolCommand.hpp:143
uint32_t external_reference_symbol_offset() const
Byte offset from the start of the file to the external reference table data.
Definition DynamicSymbolCommand.hpp:124
uint32_t toc_offset() const
Byte offset from the start of the file to the table of contents data.
Definition DynamicSymbolCommand.hpp:96
uint32_t nb_local_relocations() const
Number of entries in the local relocation table.
Definition DynamicSymbolCommand.hpp:179
uint32_t idx_external_define_symbol() const
Index of the first symbol in the group of defined external symbols.
Definition DynamicSymbolCommand.hpp:73
uint32_t nb_toc() const
Number of entries in the table of contents.
Definition DynamicSymbolCommand.hpp:103
uint32_t idx_local_symbol() const
Index of the first symbol in the group of local symbols.
Definition DynamicSymbolCommand.hpp:63
uint32_t idx_undefined_symbol() const
Index of the first symbol in the group of undefined external symbols.
Definition DynamicSymbolCommand.hpp:83
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:36
Definition Visitor.hpp:219
LIEF namespace.
Definition Abstract/Binary.hpp:32