LIEF: Library to Instrument Executable Formats Version 0.16.0
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}
36class LIEF_API DataInCode : public LoadCommand {
43 friend class BinaryParser;
44 friend class LinkEdit;
45 public:
46 using entries_t = std::vector<DataCodeEntry>;
47 using it_const_entries = const_ref_iterator<const entries_t&>;
48 using it_entries = ref_iterator<entries_t&>;
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 uint32_t data_offset() const {
63 return data_offset_;
64 }
65 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 DataInCode& add(DataCodeEntry entry) {
80 entries_.push_back(std::move(entry));
81 return *this;
82 }
83 it_const_entries entries() const {
86 return entries_;
87 }
88
89 it_entries entries() {
90 return entries_;
91 }
92
93 span<uint8_t> content() {
94 return content_;
95 }
96
97 span<const uint8_t> content() const {
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
DataCodeEntry.hpp
LoadCommand.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
LIEF::MachO::DataInCode
Interface of the LC_DATA_IN_CODE command This command is used to list slices of code sections that co...
Definition DataInCode.hpp:42
LIEF::MachO::DataInCode::data_size
uint32_t data_size() const
Size of the raw array (size = sizeof(DataCodeEntry) * nb_elements)
Definition DataInCode.hpp:67
LIEF::MachO::DataInCode::DataInCode
DataInCode()=default
LIEF::MachO::DataInCode::clone
std::unique_ptr< LoadCommand > clone() const override
Definition DataInCode.hpp:57
LIEF::MachO::DataInCode::data_offset
void data_offset(uint32_t offset)
Definition DataInCode.hpp:71
LIEF::MachO::DataInCode::data_offset
uint32_t data_offset() const
Start of the array of the DataCodeEntry entries.
Definition DataInCode.hpp:62
LIEF::MachO::DataInCode::content
span< const uint8_t > content() const
Definition DataInCode.hpp:97
LIEF::MachO::DataInCode::operator=
DataInCode & operator=(const DataInCode &)=default
LIEF::MachO::DataInCode::add
DataInCode & add(DataCodeEntry entry)
Add a new entry.
Definition DataInCode.hpp:79
LIEF::MachO::DataInCode::print
std::ostream & print(std::ostream &os) const override
LIEF::MachO::DataInCode::data_size
void data_size(uint32_t size)
Definition DataInCode.hpp:74
LIEF::MachO::DataInCode::~DataInCode
~DataInCode() override=default
LIEF::MachO::DataInCode::entries
it_const_entries entries() const
Iterator over the DataCodeEntry.
Definition DataInCode.hpp:85
LIEF::MachO::DataInCode::DataInCode
DataInCode(const DataInCode &)=default
LIEF::MachO::DataInCode::entries
it_entries entries()
Definition DataInCode.hpp:89
LIEF::MachO::DataInCode::DataInCode
DataInCode(const details::linkedit_data_command &cmd)
LIEF::MachO::DataInCode::content
span< uint8_t > content()
Definition DataInCode.hpp:93
LIEF::MachO::DataInCode::accept
void accept(Visitor &visitor) const override
LIEF::MachO::DataInCode::classof
static bool classof(const LoadCommand *cmd)
Definition DataInCode.hpp:107
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
iterators.hpp
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