16#ifndef LIEF_MACHO_SECTION_H
17#define LIEF_MACHO_SECTION_H
24#include "LIEF/types.hpp"
25#include "LIEF/visibility.h"
27#include "LIEF/Abstract/Section.hpp"
29#include "LIEF/MachO/LoadCommand.hpp"
30#include "LIEF/iterators.hpp"
54 using content_t = std::vector<uint8_t>;
55 using flag_list_t = std::set<MACHO_SECTION_FLAGS>;
68 Section(
const details::section_32& section_cmd);
69 Section(
const details::section_64& section_cmd);
72 Section(std::string name, content_t content);
81 span<const uint8_t>
content()
const override;
84 void content(
const content_t& data)
override;
155 void segment_name(
const std::string& name);
156 void address(uint64_t address);
157 void alignment(uint32_t align);
158 void relocation_offset(uint32_t relocOffset);
159 void numberof_relocations(uint32_t nbReloc);
160 void flags(uint32_t flags);
161 void flags(flag_list_t flags);
163 void reserved1(uint32_t reserved1);
164 void reserved2(uint32_t reserved2);
165 void reserved3(uint32_t reserved3);
179 void accept(
Visitor& visitor)
const override;
182 LIEF_API
friend std::ostream& operator<<(std::ostream& os,
const Section& section);
185 std::string segment_name_;
186 uint64_t original_size_ = 0;
188 uint32_t relocations_offset_ = 0;
189 uint32_t nbof_relocations_ = 0;
191 uint32_t reserved1_ = 0;
192 uint32_t reserved2_ = 0;
193 uint32_t reserved3_ = 0;
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:73
Class which represents a MachO binary.
Definition MachO/Binary.hpp:74
Class that represents a Mach-O section.
Definition MachO/Section.hpp:46
span< const uint8_t > content() const override
section's content
uint32_t reserved1() const
According to the official loader.h file, this value is reserved for offset or index
void remove(MACHO_SECTION_FLAGS flag)
Remove a MACHO_SECTION_FLAGS to the current section.
uint32_t raw_flags() const
Section flags without applying the SECTION_FLAGS_MASK mask.
SegmentCommand * segment()
The segment associated with this section or a nullptr if not present.
void add(MACHO_SECTION_FLAGS flag)
Append a MACHO_SECTION_FLAGS to the current section.
uint32_t flags() const
Section's flags masked with SECTION_FLAGS_MASK (see: MACHO_SECTION_FLAGS)
uint32_t relocation_offset() const
Offset of the relocation table. This value should be 0 for executable and libraries as the relocation...
const std::string & segment_name() const
Return the name of the segment linked to this section.
flag_list_t flags_list() const
Return the Section::flags as an std::set of MACHO_SECTION_FLAGS.
void clear(uint8_t v)
Clear the content of this section by filling its values with the byte provided in parameter.
uint64_t address() const
Virtual base address of the section.
bool has_segment() const
Check if this section is correctly linked with a MachO::SegmentCommand.
uint32_t reserved3() const
This value is only present for 64 bits Mach-O files. In that case, the value is reserved.
void content(const content_t &data) override
Update the content of the section.
std::vector< std::unique_ptr< Relocation > > relocations_t
Internal container for storing Mach-O Relocation.
Definition MachO/Section.hpp:58
MACHO_SECTION_TYPES type() const
Type of the section. This value can help to determine the purpose of the section (e....
uint32_t alignment() const
Section alignment as a power of 2.
it_relocations relocations()
Return an iterator over the MachO::Relocation associated with this section.
uint32_t numberof_relocations() const
Number of relocations associated with this section.
bool has(MACHO_SECTION_FLAGS flag) const
Check if the section has the given MACHO_SECTION_FLAGS flag.
uint32_t reserved2() const
According to the official loader.h file, this value is reserved for count or sizeof
Class which represents a LOAD_COMMAND_TYPES::LC_SEGMENT / LOAD_COMMAND_TYPES::LC_SEGMENT_64 command.
Definition SegmentCommand.hpp:48
Class which represents an abstracted section.
Definition Abstract/Section.hpp:30
Definition Visitor.hpp:219
Iterator which returns reference on container's values.
Definition iterators.hpp:48
MACHO_SECTION_FLAGS
Definition MachO/enums.hpp:193
MACHO_SECTION_TYPES
These are the section type and attributes fields. A MachO section can have only one Type,...
Definition MachO/enums.hpp:164
LIEF namespace.
Definition Abstract/Binary.hpp:32