LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
SymbolCommand.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_SYMBOL_COMMAND_H
17#define LIEF_MACHO_SYMBOL_COMMAND_H
18#include <ostream>
19
21#include "LIEF/visibility.h"
22#include "LIEF/span.hpp"
23
25
26namespace LIEF {
27namespace MachO {
28class BinaryParser;
29class LinkEdit;
30
31namespace details {
32struct symtab_command;
33}
34
37 friend class BinaryParser;
38 friend class LinkEdit;
39
40 public:
41 SymbolCommand() = default;
42 SymbolCommand(const details::symtab_command& command);
43
44 SymbolCommand& operator=(const SymbolCommand& copy) = default;
45 SymbolCommand(const SymbolCommand& copy) = default;
46
47 std::unique_ptr<LoadCommand> clone() const override {
48 return std::unique_ptr<SymbolCommand>(new SymbolCommand(*this));
49 }
50
51 ~SymbolCommand() override = default;
52
54 uint32_t symbol_offset() const {
55 return symbols_offset_;
56 }
57
59 uint32_t numberof_symbols() const {
60 return nb_symbols_;
61 }
62
64 uint32_t strings_offset() const {
65 return strings_offset_;
66 }
67
69 uint32_t strings_size() const {
70 return strings_size_;
71 }
72
73 void symbol_offset(uint32_t offset) {
74 symbols_offset_ = offset;
75 }
76 void numberof_symbols(uint32_t nb) {
77 nb_symbols_ = nb;
78 }
79 void strings_offset(uint32_t offset) {
80 strings_offset_ = offset;
81 }
82 void strings_size(uint32_t size) {
83 strings_size_ = size;
84 }
85
87 return symbol_table_;
88 }
89
91 return symbol_table_;
92 }
93
95 return string_table_;
96 }
97
99 return string_table_;
100 }
101
102 uint32_t original_str_size() const {
103 return original_str_size_;
104 }
105
106 uint32_t original_nb_symbols() const {
107 return original_nb_symbols_;
108 }
109
110 std::ostream& print(std::ostream& os) const override;
111
112 void accept(Visitor& visitor) const override;
113
114 static bool classof(const LoadCommand* cmd) {
115 return cmd->command() == LoadCommand::TYPE::SYMTAB;
116 }
117
118 private:
119 uint32_t symbols_offset_ = 0;
120 uint32_t nb_symbols_ = 0;
121 uint32_t strings_offset_ = 0;
122 uint32_t strings_size_ = 0;
123
124 uint32_t original_str_size_ = 0;
125 uint32_t original_nb_symbols_ = 0;
126
127 span<uint8_t> symbol_table_;
128 span<uint8_t> string_table_;
129};
130
131}
132}
133#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:79
Definition LinkEdit.hpp:47
uint32_t size() const
Size of the command (should be greater than sizeof(load_command)).
Definition LoadCommand.hpp:135
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:130
@ SYMTAB
Definition LoadCommand.hpp:49
span< const uint8_t > string_table() const
Definition SymbolCommand.hpp:94
uint32_t strings_offset() const
Offset from the start of the file to the string table.
Definition SymbolCommand.hpp:64
void accept(Visitor &visitor) const override
span< uint8_t > string_table()
Definition SymbolCommand.hpp:98
friend class BinaryParser
Definition SymbolCommand.hpp:37
std::ostream & print(std::ostream &os) const override
uint32_t numberof_symbols() const
Number of symbols registered.
Definition SymbolCommand.hpp:59
void numberof_symbols(uint32_t nb)
Definition SymbolCommand.hpp:76
SymbolCommand & operator=(const SymbolCommand &copy)=default
SymbolCommand(const details::symtab_command &command)
uint32_t original_nb_symbols() const
Definition SymbolCommand.hpp:106
friend class LinkEdit
Definition SymbolCommand.hpp:38
~SymbolCommand() override=default
std::unique_ptr< LoadCommand > clone() const override
Definition SymbolCommand.hpp:47
span< uint8_t > symbol_table()
Definition SymbolCommand.hpp:90
uint32_t strings_size() const
Size of the string table.
Definition SymbolCommand.hpp:69
uint32_t symbol_offset() const
Offset from the start of the file to the n_list associated with the command.
Definition SymbolCommand.hpp:54
SymbolCommand(const SymbolCommand &copy)=default
void symbol_offset(uint32_t offset)
Definition SymbolCommand.hpp:73
static bool classof(const LoadCommand *cmd)
Definition SymbolCommand.hpp:114
void strings_offset(uint32_t offset)
Definition SymbolCommand.hpp:79
span< const uint8_t > symbol_table() const
Definition SymbolCommand.hpp:86
void strings_size(uint32_t size)
Definition SymbolCommand.hpp:82
uint32_t original_str_size() const
Definition SymbolCommand.hpp:102
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition endianness_support.hpp:60
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45