LIEF: Library to Instrument Executable Formats Version 0.16.0
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}
33class LIEF_API SymbolCommand : public LoadCommand {
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 uint32_t symbol_offset() const {
54 return symbols_offset_;
55 }
56 uint32_t numberof_symbols() const {
59 return nb_symbols_;
60 }
61 uint32_t strings_offset() const {
64 return strings_offset_;
65 }
66 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
85 span<const uint8_t> symbol_table() const {
86 return symbol_table_;
87 }
88
89 span<uint8_t> symbol_table() {
90 return symbol_table_;
91 }
92
93 span<const uint8_t> string_table() const {
94 return string_table_;
95 }
96
97 span<uint8_t> string_table() {
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
LoadCommand.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
LIEF::MachO::LinkEdit
Definition LinkEdit.hpp:42
LIEF::MachO::LoadCommand
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:37
LIEF::MachO::LoadCommand::command
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:124
LIEF::MachO::SymbolCommand
Class that represents the LC_SYMTAB command.
Definition SymbolCommand.hpp:35
LIEF::MachO::SymbolCommand::SymbolCommand
SymbolCommand()=default
LIEF::MachO::SymbolCommand::string_table
span< const uint8_t > string_table() const
Definition SymbolCommand.hpp:93
LIEF::MachO::SymbolCommand::strings_offset
uint32_t strings_offset() const
Offset from the start of the file to the string table.
Definition SymbolCommand.hpp:63
LIEF::MachO::SymbolCommand::accept
void accept(Visitor &visitor) const override
LIEF::MachO::SymbolCommand::string_table
span< uint8_t > string_table()
Definition SymbolCommand.hpp:97
LIEF::MachO::SymbolCommand::print
std::ostream & print(std::ostream &os) const override
LIEF::MachO::SymbolCommand::numberof_symbols
uint32_t numberof_symbols() const
Number of symbols registered.
Definition SymbolCommand.hpp:58
LIEF::MachO::SymbolCommand::numberof_symbols
void numberof_symbols(uint32_t nb)
Definition SymbolCommand.hpp:75
LIEF::MachO::SymbolCommand::operator=
SymbolCommand & operator=(const SymbolCommand &copy)=default
LIEF::MachO::SymbolCommand::SymbolCommand
SymbolCommand(const details::symtab_command &command)
LIEF::MachO::SymbolCommand::original_nb_symbols
uint32_t original_nb_symbols() const
Definition SymbolCommand.hpp:105
LIEF::MachO::SymbolCommand::~SymbolCommand
~SymbolCommand() override=default
LIEF::MachO::SymbolCommand::clone
std::unique_ptr< LoadCommand > clone() const override
Definition SymbolCommand.hpp:46
LIEF::MachO::SymbolCommand::symbol_table
span< uint8_t > symbol_table()
Definition SymbolCommand.hpp:89
LIEF::MachO::SymbolCommand::strings_size
uint32_t strings_size() const
Size of the size string table.
Definition SymbolCommand.hpp:68
LIEF::MachO::SymbolCommand::symbol_offset
uint32_t symbol_offset() const
Offset from the start of the file to the n_list associated with the command.
Definition SymbolCommand.hpp:53
LIEF::MachO::SymbolCommand::SymbolCommand
SymbolCommand(const SymbolCommand &copy)=default
LIEF::MachO::SymbolCommand::symbol_offset
void symbol_offset(uint32_t offset)
Definition SymbolCommand.hpp:72
LIEF::MachO::SymbolCommand::classof
static bool classof(const LoadCommand *cmd)
Definition SymbolCommand.hpp:113
LIEF::MachO::SymbolCommand::strings_offset
void strings_offset(uint32_t offset)
Definition SymbolCommand.hpp:78
LIEF::MachO::SymbolCommand::symbol_table
span< const uint8_t > symbol_table() const
Definition SymbolCommand.hpp:85
LIEF::MachO::SymbolCommand::strings_size
void strings_size(uint32_t size)
Definition SymbolCommand.hpp:81
LIEF::MachO::SymbolCommand::original_str_size
uint32_t original_str_size() const
Definition SymbolCommand.hpp:101
LIEF::MachO::details
Definition endianness_support.hpp:59
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41