16#ifndef LIEF_MACHO_SEGMENT_COMMAND_H
17#define LIEF_MACHO_SEGMENT_COMMAND_H
48struct segment_command_32;
49struct segment_command_64;
67 using sections_t = std::vector<std::unique_ptr<Section>>;
95 PROTECTED_VERSION_1 = 0x8u,
123 std::unique_ptr<LoadCommand>
clone()
const override {
124 return std::make_unique<SegmentCommand>(*
this);
136 return virtual_address_;
141 return virtual_size_;
156 return max_protection_;
161 return init_protection_;
210 std::unique_ptr<SpanStream>
stream()
const;
218 name_ = std::move(
name);
240 nb_sections_ = nb_section;
265 std::ostream&
print(std::ostream& os)
const override;
277 LIEF_LOCAL void content_insert(
size_t where,
size_t size);
279 void content_extend(
size_t width) {
280 content_resize(data_.size() + width);
283 using update_fnc_t = std::function<void(std::vector<uint8_t>&)>;
284 using update_fnc_ws_t =
285 std::function<void(std::vector<uint8_t>&,
size_t,
size_t)>;
287 LIEF_LOCAL virtual void update_data(
const update_fnc_t& f);
288 LIEF_LOCAL virtual void update_data(
const update_fnc_ws_t& f,
size_t where,
292 uint64_t virtual_address_ = 0;
293 uint64_t virtual_size_ = 0;
294 uint64_t file_offset_ = 0;
295 uint64_t file_size_ = 0;
296 uint32_t max_protection_ = 0;
297 uint32_t init_protection_ = 0;
298 uint32_t nb_sections_ = 0;
302 sections_t sections_;
303 relocations_t relocations_;
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:79
Class which represents a MachO binary.
Definition MachO/Binary.hpp:94
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:64
Definition DyldChainedFixupsCreator.hpp:41
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:51
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:132
span< const uint8_t > data() const
Raw command.
Definition LoadCommand.hpp:142
TYPE
Definition LoadCommand.hpp:47
@ SEGMENT_64
Definition LoadCommand.hpp:73
@ SEGMENT
Definition LoadCommand.hpp:49
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:42
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
Class that represents a Mach-O section.
Definition MachO/Section.hpp:49
uint64_t virtual_address() const
Absolute virtual base address of the segment.
Definition SegmentCommand.hpp:135
void swap(SegmentCommand &other) noexcept
friend class Section
Definition SegmentCommand.hpp:60
void file_offset(uint64_t file_offset)
Definition SegmentCommand.hpp:227
std::vector< std::unique_ptr< Relocation > > relocations_t
Internal container for storing Mach-O Relocation.
Definition SegmentCommand.hpp:76
std::ostream & print(std::ostream &os) const override
void file_size(uint64_t file_size)
Definition SegmentCommand.hpp:230
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:70
it_relocations relocations()
Return an iterator over the MachO::Relocation linked to this segment.
Definition SegmentCommand.hpp:189
const_ref_iterator< const relocations_t &, const Relocation * > it_const_relocations
Iterator which outputs const Relocation&.
Definition SegmentCommand.hpp:82
std::vector< std::unique_ptr< Section > > sections_t
Internal container for storing Mach-O Section.
Definition SegmentCommand.hpp:67
friend class BinaryParser
Definition SegmentCommand.hpp:57
static bool classof(const LoadCommand *cmd)
Definition SegmentCommand.hpp:269
void content(content_t data)
void max_protection(uint32_t max_protection)
Definition SegmentCommand.hpp:233
FLAGS
Definition SegmentCommand.hpp:85
SegmentCommand(const details::segment_command_32 &cmd)
void virtual_size(uint64_t virtual_size)
Definition SegmentCommand.hpp:224
friend class DyldChainedFixupsCreator
Definition SegmentCommand.hpp:56
span< const uint8_t > content() const
The raw content of this segment.
Definition SegmentCommand.hpp:201
std::vector< uint8_t > content_t
Definition SegmentCommand.hpp:64
Section * get_section(const std::string &name)
VM_PROTECTIONS
Values for segment_command.initprot. From <mach/vm_prot.h>.
Definition SegmentCommand.hpp:100
uint64_t file_size() const
Size of this segment in the binary file.
Definition SegmentCommand.hpp:145
friend class Builder
Definition SegmentCommand.hpp:61
std::string_view name() const
Name of the segment (e.g. __TEXT).
Definition SegmentCommand.hpp:130
span< uint8_t > content()
Definition SegmentCommand.hpp:205
ref_iterator< relocations_t &, Relocation * > it_relocations
Iterator which outputs Relocation&.
Definition SegmentCommand.hpp:79
~SegmentCommand() override
uint32_t numberof_sections() const
The number of sections associated with this segment.
Definition SegmentCommand.hpp:165
it_const_sections sections() const
Definition SegmentCommand.hpp:179
uint32_t max_protection() const
The maximum of protections for this segment (cf. VM_PROTECTIONS).
Definition SegmentCommand.hpp:155
const_ref_iterator< const sections_t &, const Section * > it_const_sections
Iterator which outputs const Section&.
Definition SegmentCommand.hpp:73
friend class Binary
Definition SegmentCommand.hpp:59
uint64_t virtual_size() const
Virtual size of the segment.
Definition SegmentCommand.hpp:140
void virtual_address(uint64_t virtual_address)
Definition SegmentCommand.hpp:221
int8_t index() const
The original index of this segment or -1 if not defined.
Definition SegmentCommand.hpp:213
friend class Parser
Definition SegmentCommand.hpp:58
uint32_t init_protection() const
The initial protections of this segment (cf. VM_PROTECTIONS).
Definition SegmentCommand.hpp:160
Section & add_section(const Section §ion)
Add a new section in this segment.
it_const_relocations relocations() const
Definition SegmentCommand.hpp:192
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:242
SegmentCommand(std::string name, content_t content)
bool is(VM_PROTECTIONS prot) const
Definition SegmentCommand.hpp:260
it_sections sections()
Return an iterator over the MachO::Section linked to this segment.
Definition SegmentCommand.hpp:175
uint64_t file_offset() const
Offset of the data of this segment in the file.
Definition SegmentCommand.hpp:150
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:123
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:217
void init_protection(uint32_t init_protection)
Definition SegmentCommand.hpp:236
void numberof_sections(uint32_t nb_section)
Definition SegmentCommand.hpp:239
uint32_t flags() const
Flags associated with this segment (cf. SegmentCommand::FLAGS).
Definition SegmentCommand.hpp:170
Definition SpanStream.hpp:32
Definition Visitor.hpp:212
Iterator which returns reference on container's values.
Definition iterators.hpp:47
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
#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:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which returns a const ref on container's values.
Definition iterators.hpp:316
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46