16#ifndef LIEF_MACHO_SEGMENT_COMMAND_H
17#define LIEF_MACHO_SEGMENT_COMMAND_H
45struct segment_command_32;
46struct segment_command_64;
62 using sections_t = std::vector<std::unique_ptr<Section>>;
109 std::unique_ptr<LoadCommand>
clone()
const override {
110 return std::unique_ptr<SegmentCommand>(
new SegmentCommand(*
this));
116 const std::string&
name()
const {
122 return virtual_address_;
127 return virtual_size_;
142 return max_protection_;
147 return init_protection_;
191 std::unique_ptr<SpanStream>
stream()
const;
199 name_ = std::move(
name);
221 nb_sections_ = nb_section;
246 std::ostream&
print(std::ostream& os)
const override;
262 LIEF_LOCAL void content_insert(
size_t where,
size_t size);
264 void content_extend(
size_t width) {
265 content_resize(data_.size() + width);
268 using update_fnc_t = std::function<void(std::vector<uint8_t>&)>;
269 using update_fnc_ws_t = std::function<void(std::vector<uint8_t>&,
size_t,
size_t)>;
271 LIEF_LOCAL virtual void update_data(
const update_fnc_t& f);
272 LIEF_LOCAL virtual void update_data(
const update_fnc_ws_t& f,
273 size_t where,
size_t size);
276 uint64_t virtual_address_ = 0;
277 uint64_t virtual_size_ = 0;
278 uint64_t file_offset_ = 0;
279 uint64_t file_size_ = 0;
280 uint32_t max_protection_ = 0;
281 uint32_t init_protection_ = 0;
282 uint32_t nb_sections_ = 0;
286 sections_t sections_;
287 relocations_t relocations_;
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:78
Class which represents a MachO binary.
Definition MachO/Binary.hpp:88
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:63
Definition DyldChainedFixupsCreator.hpp:41
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:50
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:128
span< const uint8_t > data() const
Raw command.
Definition LoadCommand.hpp:138
TYPE
Definition LoadCommand.hpp:44
@ SEGMENT_64
Definition LoadCommand.hpp:70
@ SEGMENT
Definition LoadCommand.hpp:46
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
Class that represents a Mach-O section.
Definition MachO/Section.hpp:46
uint64_t virtual_address() const
Absolute virtual base address of the segment.
Definition SegmentCommand.hpp:121
void swap(SegmentCommand &other) noexcept
friend class Section
Definition SegmentCommand.hpp:55
void file_offset(uint64_t file_offset)
Definition SegmentCommand.hpp:208
const_ref_iterator< const relocations_t &, const Relocation * > it_const_relocations
Iterator which outputs const Relocation&.
Definition SegmentCommand.hpp:77
std::vector< std::unique_ptr< Relocation > > relocations_t
Internal container for storing Mach-O Relocation.
Definition SegmentCommand.hpp:71
std::ostream & print(std::ostream &os) const override
void file_size(uint64_t file_size)
Definition SegmentCommand.hpp:211
const Section * get_section(const std::string &name) const
Get the section with the given name.
SegmentCommand & operator=(SegmentCommand other)
SegmentCommand(const details::segment_command_64 &cmd)
ref_iterator< sections_t &, Section * > it_sections
Iterator which outputs Section&.
Definition SegmentCommand.hpp:65
it_relocations relocations()
Return an iterator over the MachO::Relocation linked to this segment.
Definition SegmentCommand.hpp:174
std::vector< std::unique_ptr< Section > > sections_t
Internal container for storing Mach-O Section.
Definition SegmentCommand.hpp:62
friend class BinaryParser
Definition SegmentCommand.hpp:53
static bool classof(const LoadCommand *cmd)
Definition SegmentCommand.hpp:250
void content(content_t data)
void max_protection(uint32_t max_protection)
Definition SegmentCommand.hpp:214
FLAGS
Definition SegmentCommand.hpp:79
@ PROTECTED_VERSION_1
Definition SegmentCommand.hpp:83
@ READ_ONLY
Definition SegmentCommand.hpp:84
@ NORELOC
This segment has nothing that was relocated in it and nothing relocated to it. It may be safely repla...
Definition SegmentCommand.hpp:82
@ FVMLIB
this segment is the VM that is allocated by a fixed VM library, for overlap checking in the link edit...
Definition SegmentCommand.hpp:81
@ HIGHVM
The file contents for this segment are for the high part of the virtual memory space; the low part is...
Definition SegmentCommand.hpp:80
SegmentCommand(const details::segment_command_32 &cmd)
void virtual_size(uint64_t virtual_size)
Definition SegmentCommand.hpp:205
friend class DyldChainedFixupsCreator
Definition SegmentCommand.hpp:52
span< const uint8_t > content() const
The raw content of this segment.
Definition SegmentCommand.hpp:186
std::vector< uint8_t > content_t
Definition SegmentCommand.hpp:59
Section * get_section(const std::string &name)
const std::string & name() const
Name of the segment (e.g. __TEXT).
Definition SegmentCommand.hpp:116
VM_PROTECTIONS
Values for segment_command.initprot. From <mach/vm_prot.h>.
Definition SegmentCommand.hpp:89
@ READ
Reading data within the segment is allowed.
Definition SegmentCommand.hpp:90
@ EXECUTE
Executing data within the segment is allowed.
Definition SegmentCommand.hpp:92
@ WRITE
Writing data within the segment is allowed.
Definition SegmentCommand.hpp:91
uint64_t file_size() const
Size of this segment in the binary file.
Definition SegmentCommand.hpp:131
friend class Builder
Definition SegmentCommand.hpp:56
ref_iterator< relocations_t &, Relocation * > it_relocations
Iterator which outputs Relocation&.
Definition SegmentCommand.hpp:74
~SegmentCommand() override
uint32_t numberof_sections() const
The number of sections associated with this segment.
Definition SegmentCommand.hpp:151
it_const_sections sections() const
Definition SegmentCommand.hpp:165
uint32_t max_protection() const
The maximum of protections for this segment (cf. VM_PROTECTIONS).
Definition SegmentCommand.hpp:141
const_ref_iterator< const sections_t &, const Section * > it_const_sections
Iterator which outputs const Section&.
Definition SegmentCommand.hpp:68
friend class Binary
Definition SegmentCommand.hpp:54
uint64_t virtual_size() const
Virtual size of the segment.
Definition SegmentCommand.hpp:126
void virtual_address(uint64_t virtual_address)
Definition SegmentCommand.hpp:202
int8_t index() const
The original index of this segment or -1 if not defined.
Definition SegmentCommand.hpp:194
uint32_t init_protection() const
The initial protections of this segment (cf. VM_PROTECTIONS).
Definition SegmentCommand.hpp:146
Section & add_section(const Section §ion)
Add a new section in this segment.
it_const_relocations relocations() const
Definition SegmentCommand.hpp:177
void accept(Visitor &visitor) const override
bool has_section(const std::string §ion_name) const
Check if the current segment embeds the given section name.
void flags(uint32_t flags)
Definition SegmentCommand.hpp:223
SegmentCommand(std::string name, content_t content)
bool is(VM_PROTECTIONS prot) const
Definition SegmentCommand.hpp:241
it_sections sections()
Return an iterator over the MachO::Section linked to this segment.
Definition SegmentCommand.hpp:161
uint64_t file_offset() const
Offset of the data of this segment in the file.
Definition SegmentCommand.hpp:136
bool has(const Section §ion) const
Check if the current segment embeds the given section.
SegmentCommand(const SegmentCommand ©)
std::unique_ptr< LoadCommand > clone() const override
Definition SegmentCommand.hpp:109
std::unique_ptr< SpanStream > stream() const
Return a stream over the content of this segment.
SegmentCommand(std::string name)
void remove_all_sections()
Remove all the sections linked to this segment.
void name(std::string name)
Definition SegmentCommand.hpp:198
void init_protection(uint32_t init_protection)
Definition SegmentCommand.hpp:217
void numberof_sections(uint32_t nb_section)
Definition SegmentCommand.hpp:220
uint32_t flags() const
Flags associated with this segment (cf. SegmentCommand::FLAGS).
Definition SegmentCommand.hpp:156
Definition SpanStream.hpp:32
Definition Visitor.hpp:210
Iterator which returns reference on container's values.
Definition iterators.hpp:46
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:257
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42