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