LIEF: Library to Instrument Executable Formats Version 0.16.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_MACHO_SEGMENT_COMMAND_H
17#define LIEF_MACHO_SEGMENT_COMMAND_H
45struct segment_command_32;
46struct segment_command_64;
52 friend class DyldChainedFixupsCreator;
53 friend class BinaryParser;
59 using content_t = std::vector<uint8_t>;
60 using sections_t = std::vector<std::unique_ptr<Section>>;
63 using it_sections = ref_iterator<sections_t&, Section*>;
66 using it_const_sections = const_ref_iterator<const sections_t&, const Section*>;
69 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
72 using it_relocations = ref_iterator<relocations_t&, Relocation*>;
75 using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>;
79 enum class FLAGS: uint64_t {
83 PROTECTED_VERSION_1 = 0x8u,
86 enum class VM_PROTECTIONS {
107 void swap(SegmentCommand& other)
noexcept;
109 std::unique_ptr<LoadCommand>
clone()
const override {
110 return std::unique_ptr<SegmentCommand>(
new SegmentCommand(*
this));
114 const std::string&
name()
const {
122 return virtual_address_;
127 return virtual_size_;
142 return max_protection_;
147 return init_protection_;
154 uint32_t
flags()
const {
180 const Section*
get_section(
const std::string& name)
const;
184 span<const uint8_t>
content()
const {
189 std::unique_ptr<SpanStream>
stream()
const;
192 int8_t
index()
const {
199 name_ = std::move(name);
203 virtual_address_ = virtual_address;
206 virtual_size_ = virtual_size;
209 file_offset_ = file_offset;
212 file_size_ = file_size;
215 max_protection_ = max_protection;
218 init_protection_ = init_protection;
221 nb_sections_ = nb_section;
234 bool has(
const Section& section)
const;
237 bool has_section(
const std::string& section_name)
const;
241 bool is(VM_PROTECTIONS prot)
const {
242 return (init_protection() & (uint32_t)prot) > 0 ||
243 (max_protection() & (uint32_t)prot) > 0;
246 std::ostream&
print(std::ostream& os)
const override;
248 void accept(Visitor& visitor)
const override;
251 const LoadCommand::TYPE type = cmd->
command();
252 return type == LoadCommand::TYPE::SEGMENT ||
253 type == LoadCommand::TYPE::SEGMENT_64;
257 span<uint8_t> writable_content() {
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:74
Class which represents a MachO binary.
Definition MachO/Binary.hpp:85
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:57
Definition DyldChainedFixupsCreator.hpp:41
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:50
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:37
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:124
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
Class that represents a Mach-O section.
Definition MachO/Section.hpp:46
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:50
uint64_t virtual_address() const
Absolute virtual base address of the segment.
Definition SegmentCommand.hpp:121
void swap(SegmentCommand &other) noexcept
void file_offset(uint64_t file_offset)
Definition SegmentCommand.hpp:208
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)
it_relocations relocations()
Return an iterator over the MachO::Relocation linked to this segment.
Definition SegmentCommand.hpp:174
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
SegmentCommand(const details::segment_command_32 &cmd)
void virtual_size(uint64_t virtual_size)
Definition SegmentCommand.hpp:205
span< const uint8_t > content() const
The raw content of this segment.
Definition SegmentCommand.hpp:186
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
uint64_t file_size() const
Size of this segment in the binary file.
Definition SegmentCommand.hpp:131
~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
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
#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:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42