16#ifndef LIEF_MACHO_SEGMENT_COMMAND_H
17#define LIEF_MACHO_SEGMENT_COMMAND_H
43struct segment_command_32;
44struct segment_command_64;
59 using sections_t = std::vector<std::unique_ptr<Section>>;
80 PROTECTED_VERSION_1 = 0x8u,
106 std::unique_ptr<LoadCommand>
clone()
const override {
107 return std::unique_ptr<SegmentCommand>(
new SegmentCommand(*
this));
113 const std::string&
name()
const {
119 return virtual_address_;
124 return virtual_size_;
139 return max_protection_;
144 return init_protection_;
193 name_ = std::move(name);
197 virtual_address_ = virtual_address;
200 virtual_size_ = virtual_size;
203 file_offset_ = file_offset;
206 file_size_ = file_size;
209 max_protection_ = max_protection;
212 init_protection_ = init_protection;
215 nb_sections_ = nb_section;
235 std::ostream&
print(std::ostream& os)
const override;
241 return type == LoadCommand::TYPE::SEGMENT ||
242 type == LoadCommand::TYPE::SEGMENT_64;
250 void content_resize(
size_t size);
251 void content_insert(
size_t where,
size_t size);
253 void content_extend(
size_t width) {
254 content_resize(data_.size() + width);
257 using update_fnc_t = std::function<void(std::vector<uint8_t>&)>;
258 using update_fnc_ws_t = std::function<void(std::vector<uint8_t>&,
size_t,
size_t)>;
260 LIEF_LOCAL virtual void update_data(
const update_fnc_t& f);
261 LIEF_LOCAL virtual void update_data(
const update_fnc_ws_t& f,
262 size_t where,
size_t size);
265 uint64_t virtual_address_ = 0;
266 uint64_t virtual_size_ = 0;
267 uint64_t file_offset_ = 0;
268 uint64_t file_size_ = 0;
269 uint32_t max_protection_ = 0;
270 uint32_t init_protection_ = 0;
271 uint32_t nb_sections_ = 0;
275 sections_t sections_;
276 relocations_t relocations_;
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
Class which represents a MachO binary.
Definition MachO/Binary.hpp:77
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:55
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:36
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:122
TYPE
Definition LoadCommand.hpp:42
Class that represents a Mach-O section.
Definition MachO/Section.hpp:44
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:48
uint64_t virtual_address() const
Absolute virtual base address of the segment.
Definition SegmentCommand.hpp:118
void swap(SegmentCommand &other) noexcept
void file_offset(uint64_t file_offset)
Definition SegmentCommand.hpp:202
std::vector< std::unique_ptr< Relocation > > relocations_t
Internal container for storing Mach-O Relocation.
Definition SegmentCommand.hpp:68
std::ostream & print(std::ostream &os) const override
void file_size(uint64_t file_size)
Definition SegmentCommand.hpp:205
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)
it_relocations relocations()
Return an iterator over the MachO::Relocation linked to this segment.
Definition SegmentCommand.hpp:171
std::vector< std::unique_ptr< Section > > sections_t
Internal container for storing Mach-O Section.
Definition SegmentCommand.hpp:59
static bool classof(const LoadCommand *cmd)
Definition SegmentCommand.hpp:239
void content(content_t data)
void max_protection(uint32_t max_protection)
Definition SegmentCommand.hpp:208
FLAGS
Definition SegmentCommand.hpp:76
SegmentCommand(const details::segment_command_32 &cmd)
void virtual_size(uint64_t virtual_size)
Definition SegmentCommand.hpp:199
span< const uint8_t > content() const
The raw content of this segment.
Definition SegmentCommand.hpp:183
std::vector< uint8_t > content_t
Definition SegmentCommand.hpp:56
Section * get_section(const std::string &name)
const std::string & name() const
Name of the segment (e.g. __TEXT)
Definition SegmentCommand.hpp:113
VM_PROTECTIONS
Values for segment_command.initprot. From <mach/vm_prot.h>
Definition SegmentCommand.hpp:86
uint64_t file_size() const
Size of this segment in the binary file.
Definition SegmentCommand.hpp:128
~SegmentCommand() override
uint32_t numberof_sections() const
The number of sections associated with this segment.
Definition SegmentCommand.hpp:148
it_const_sections sections() const
Definition SegmentCommand.hpp:162
uint32_t max_protection() const
The maximum of protections for this segment (cf. VM_PROTECTIONS)
Definition SegmentCommand.hpp:138
uint64_t virtual_size() const
Virtual size of the segment.
Definition SegmentCommand.hpp:123
void virtual_address(uint64_t virtual_address)
Definition SegmentCommand.hpp:196
int8_t index() const
The original index of this segment or -1 if not defined.
Definition SegmentCommand.hpp:188
uint32_t init_protection() const
The initial protections of this segment (cf. VM_PROTECTIONS)
Definition SegmentCommand.hpp:143
Section & add_section(const Section §ion)
Add a new section in this segment.
it_const_relocations relocations() const
Definition SegmentCommand.hpp:174
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:217
SegmentCommand(std::string name, content_t content)
it_sections sections()
Return an iterator over the MachO::Section linked to this segment.
Definition SegmentCommand.hpp:158
uint64_t file_offset() const
Offset of the data of this segment in the file.
Definition SegmentCommand.hpp:133
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:106
SegmentCommand(std::string name)
void remove_all_sections()
Remove all the sections linked to this segment.
void name(std::string name)
Definition SegmentCommand.hpp:192
void init_protection(uint32_t init_protection)
Definition SegmentCommand.hpp:211
void numberof_sections(uint32_t nb_section)
Definition SegmentCommand.hpp:214
uint32_t flags() const
Flags associated with this segment (cf. SegmentCommand::FLAGS)
Definition SegmentCommand.hpp:153
Definition Visitor.hpp:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF namespace.
Definition Abstract/Binary.hpp:32
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42