LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
DataInCode.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_DATA_IN_CODE_COMMAND_H
17#define LIEF_MACHO_DATA_IN_CODE_COMMAND_H
18#include <vector>
19#include <ostream>
20
21#include "LIEF/visibility.h"
22#include "LIEF/iterators.hpp"
23#include "LIEF/span.hpp"
24
27
28namespace LIEF {
29namespace MachO {
30class BinaryParser;
31class LinkEdit;
32
33namespace details {
34struct linkedit_data_command;
35}
36
43 friend class BinaryParser;
44 friend class LinkEdit;
45 public:
46 using entries_t = std::vector<DataCodeEntry>;
49
50 public:
51 DataInCode() = default;
52 DataInCode(const details::linkedit_data_command& cmd);
53
54 DataInCode& operator=(const DataInCode&) = default;
55 DataInCode(const DataInCode&) = default;
56
57 std::unique_ptr<LoadCommand> clone() const override {
58 return std::unique_ptr<DataInCode>(new DataInCode(*this));
59 }
60
62 uint32_t data_offset() const {
63 return data_offset_;
64 }
65
67 uint32_t data_size() const {
68 return data_size_;
69 }
70
71 void data_offset(uint32_t offset) {
72 data_offset_ = offset;
73 }
74 void data_size(uint32_t size) {
75 data_size_ = size;
76 }
77
80 entries_.push_back(std::move(entry));
81 return *this;
82 }
83
86 return entries_;
87 }
88
90 return entries_;
91 }
92
94 return content_;
95 }
96
98 return content_;
99 }
100
101 ~DataInCode() override = default;
102
103 void accept(Visitor& visitor) const override;
104
105 std::ostream& print(std::ostream& os) const override;
106
107 static bool classof(const LoadCommand* cmd) {
108 return cmd->command() == LoadCommand::TYPE::DATA_IN_CODE;
109 }
110
111 private:
112 uint32_t data_offset_ = 0;
113 uint32_t data_size_ = 0;
114 entries_t entries_;
115 span<uint8_t> content_;
116
117};
118
119}
120}
121#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
Interface over an entry in the DataInCode command.
Definition DataCodeEntry.hpp:33
Interface of the LC_DATA_IN_CODE command This command is used to list slices of code sections that co...
Definition DataInCode.hpp:42
uint32_t data_size() const
Size of the raw array (size = sizeof(DataCodeEntry) * nb_elements)
Definition DataInCode.hpp:67
std::unique_ptr< LoadCommand > clone() const override
Definition DataInCode.hpp:57
void data_offset(uint32_t offset)
Definition DataInCode.hpp:71
uint32_t data_offset() const
Start of the array of the DataCodeEntry entries.
Definition DataInCode.hpp:62
span< const uint8_t > content() const
Definition DataInCode.hpp:97
DataInCode & operator=(const DataInCode &)=default
DataInCode & add(DataCodeEntry entry)
Add a new entry.
Definition DataInCode.hpp:79
std::ostream & print(std::ostream &os) const override
void data_size(uint32_t size)
Definition DataInCode.hpp:74
~DataInCode() override=default
it_const_entries entries() const
Iterator over the DataCodeEntry.
Definition DataInCode.hpp:85
std::vector< DataCodeEntry > entries_t
Definition DataInCode.hpp:46
DataInCode(const DataInCode &)=default
it_entries entries()
Definition DataInCode.hpp:89
DataInCode(const details::linkedit_data_command &cmd)
span< uint8_t > content()
Definition DataInCode.hpp:93
void accept(Visitor &visitor) const override
static bool classof(const LoadCommand *cmd)
Definition DataInCode.hpp:107
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
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