LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
TwoLevelHints.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_TWO_LEVEL_HINTS_H
17#define LIEF_MACHO_TWO_LEVEL_HINTS_H
18#include <vector>
19#include <ostream>
20
21#include "LIEF/visibility.h"
22#include "LIEF/span.hpp"
23#include "LIEF/iterators.hpp"
24
26
27namespace LIEF {
28namespace MachO {
29
30class BinaryParser;
31class Builder;
32class LinkEdit;
33
34namespace details {
35struct twolevel_hints_command;
36}
37
40 friend class BinaryParser;
41 friend class LinkEdit;
42 friend class Builder;
43
44 public:
45 using hints_list_t = std::vector<uint32_t>;
48
49 TwoLevelHints() = default;
50 TwoLevelHints(const details::twolevel_hints_command& cmd);
51
52 TwoLevelHints& operator=(const TwoLevelHints& copy) = default;
53 TwoLevelHints(const TwoLevelHints& copy) = default;
54
55 std::unique_ptr<LoadCommand> clone() const override {
56 return std::unique_ptr<TwoLevelHints>(new TwoLevelHints(*this));
57 }
58
60 span<const uint8_t> content() const { return content_; }
61 span<uint8_t> content() { return content_; }
62
64 it_hints_t hints() { return hints_; }
65 it_const_hints_t hints() const { return hints_; }
66
69 uint32_t offset() const { return offset_; }
70 void offset(uint32_t offset) { offset_ = offset; }
71
72 uint32_t original_nb_hints() const {
73 return original_nb_hints_;
74 }
75
76 ~TwoLevelHints() override = default;
77
78 void accept(Visitor& visitor) const override;
79
80 std::ostream& print(std::ostream& os) const override;
81
82 static bool classof(const LoadCommand* cmd) {
83 return cmd->command() == LoadCommand::TYPE::TWOLEVEL_HINTS;
84 }
85
86 private:
87 uint32_t offset_ = 0;
88 hints_list_t hints_;
89 span<uint8_t> content_;
90 uint32_t original_nb_hints_ = 0;
91};
92
93}
94}
95#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:55
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 which represents the LC_TWOLEVEL_HINTS command.
Definition TwoLevelHints.hpp:39
static bool classof(const LoadCommand *cmd)
Definition TwoLevelHints.hpp:82
std::ostream & print(std::ostream &os) const override
std::unique_ptr< LoadCommand > clone() const override
Definition TwoLevelHints.hpp:55
uint32_t original_nb_hints() const
Definition TwoLevelHints.hpp:72
it_const_hints_t hints() const
Definition TwoLevelHints.hpp:65
~TwoLevelHints() override=default
TwoLevelHints(const TwoLevelHints &copy)=default
span< const uint8_t > content() const
Original payload of the command.
Definition TwoLevelHints.hpp:60
void offset(uint32_t offset)
Definition TwoLevelHints.hpp:70
uint32_t offset() const
Original offset of the command. It should point in the __LINKEDIT segment.
Definition TwoLevelHints.hpp:69
std::vector< uint32_t > hints_list_t
Definition TwoLevelHints.hpp:45
it_hints_t hints()
Iterator over the hints (uint32_t integers)
Definition TwoLevelHints.hpp:64
void accept(Visitor &visitor) const override
TwoLevelHints(const details::twolevel_hints_command &cmd)
TwoLevelHints & operator=(const TwoLevelHints &copy)=default
span< uint8_t > content()
Definition TwoLevelHints.hpp:61
Definition Visitor.hpp:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41