LIEF: Library to Instrument Executable Formats Version 2.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 <memory>
19#include <ostream>
20
22#include "LIEF/span.hpp"
23#include "LIEF/visibility.h"
24
26
27
28namespace LIEF::MachO {
29class BinaryParser;
30class LinkEdit;
31
32namespace details {
33struct symtab_command;
34}
35
38 friend class BinaryParser;
39 friend class LinkEdit;
40
41 public:
42 SymbolCommand() = default;
43 SymbolCommand(const details::symtab_command& command);
44
45 SymbolCommand& operator=(const SymbolCommand& copy) = default;
46 SymbolCommand(const SymbolCommand& copy) = default;
47
48 std::unique_ptr<LoadCommand> clone() const override {
49 return std::make_unique<SymbolCommand>(*this);
50 }
51
52 ~SymbolCommand() override = default;
53
55 uint32_t symbol_offset() const {
56 return symbols_offset_;
57 }
58
60 uint32_t numberof_symbols() const {
61 return nb_symbols_;
62 }
63
65 uint32_t strings_offset() const {
66 return strings_offset_;
67 }
68
70 uint32_t strings_size() const {
71 return strings_size_;
72 }
73
74 void symbol_offset(uint32_t offset) {
75 symbols_offset_ = offset;
76 }
77 void numberof_symbols(uint32_t nb) {
78 nb_symbols_ = nb;
79 }
80 void strings_offset(uint32_t offset) {
81 strings_offset_ = offset;
82 }
83 void strings_size(uint32_t size) {
84 strings_size_ = size;
85 }
86
88 return symbol_table_;
89 }
90
92 return symbol_table_;
93 }
94
96 return string_table_;
97 }
98
100 return string_table_;
101 }
102
103 uint32_t original_str_size() const {
104 return original_str_size_;
105 }
106
107 uint32_t original_nb_symbols() const {
108 return original_nb_symbols_;
109 }
110
111 std::ostream& print(std::ostream& os) const override;
112
113 void accept(Visitor& visitor) const override;
114
115 static bool classof(const LoadCommand* cmd) {
116 return cmd->command() == LoadCommand::TYPE::SYMTAB;
117 }
118
119 private:
120 uint32_t symbols_offset_ = 0;
121 uint32_t nb_symbols_ = 0;
122 uint32_t strings_offset_ = 0;
123 uint32_t strings_size_ = 0;
124
125 uint32_t original_str_size_ = 0;
126 uint32_t original_nb_symbols_ = 0;
127
128 span<uint8_t> symbol_table_;
129 span<uint8_t> string_table_;
130};
131
132}
133
134#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:137
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:132
@ SYMTAB
Definition LoadCommand.hpp:50
span< const uint8_t > string_table() const
Definition SymbolCommand.hpp:95
uint32_t strings_offset() const
Offset from the start of the file to the string table.
Definition SymbolCommand.hpp:65
void accept(Visitor &visitor) const override
span< uint8_t > string_table()
Definition SymbolCommand.hpp:99
friend class BinaryParser
Definition SymbolCommand.hpp:38
std::ostream & print(std::ostream &os) const override
uint32_t numberof_symbols() const
Number of symbols registered.
Definition SymbolCommand.hpp:60
void numberof_symbols(uint32_t nb)
Definition SymbolCommand.hpp:77
SymbolCommand & operator=(const SymbolCommand &copy)=default
SymbolCommand(const details::symtab_command &command)
uint32_t original_nb_symbols() const
Definition SymbolCommand.hpp:107
friend class LinkEdit
Definition SymbolCommand.hpp:39
~SymbolCommand() override=default
std::unique_ptr< LoadCommand > clone() const override
Definition SymbolCommand.hpp:48
span< uint8_t > symbol_table()
Definition SymbolCommand.hpp:91
uint32_t strings_size() const
Size of the string table.
Definition SymbolCommand.hpp:70
uint32_t symbol_offset() const
Offset from the start of the file to the n_list associated with the command.
Definition SymbolCommand.hpp:55
SymbolCommand(const SymbolCommand &copy)=default
void symbol_offset(uint32_t offset)
Definition SymbolCommand.hpp:74
static bool classof(const LoadCommand *cmd)
Definition SymbolCommand.hpp:115
void strings_offset(uint32_t offset)
Definition SymbolCommand.hpp:80
span< const uint8_t > symbol_table() const
Definition SymbolCommand.hpp:87
void strings_size(uint32_t size)
Definition SymbolCommand.hpp:83
uint32_t original_str_size() const
Definition SymbolCommand.hpp:103
Definition Visitor.hpp:212
#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
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45