16#ifndef LIEF_MACHO_SECTION_H
17#define LIEF_MACHO_SECTION_H
62 static constexpr auto FLAGS_MASK = uint32_t(0xffffff00u);
63 static constexpr auto TYPE_MASK = uint32_t(0xff);
65 enum class TYPE: uint64_t {
68 CSTRING_LITERALS = 0x02u,
69 S_4BYTE_LITERALS = 0x03u,
70 S_8BYTE_LITERALS = 0x04u,
71 LITERAL_POINTERS = 0x05u,
72 NON_LAZY_SYMBOL_POINTERS = 0x06u,
73 LAZY_SYMBOL_POINTERS = 0x07u,
75 MOD_INIT_FUNC_POINTERS = 0x09u,
76 MOD_TERM_FUNC_POINTERS = 0x0au,
80 S_16BYTE_LITERALS = 0x0eu,
82 LAZY_DYLIB_SYMBOL_POINTERS = 0x10u,
83 THREAD_LOCAL_REGULAR = 0x11u,
84 THREAD_LOCAL_ZEROFILL = 0x12u,
85 THREAD_LOCAL_VARIABLES = 0x13u,
86 THREAD_LOCAL_VARIABLE_POINTERS = 0x14u,
87 THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15u,
88 INIT_FUNC_OFFSETS = 0x16u,
92 PURE_INSTRUCTIONS = 0x80000000u,
94 STRIP_STATIC_SYMS = 0x20000000u,
95 NO_DEAD_STRIP = 0x10000000u,
96 LIVE_SUPPORT = 0x08000000u,
97 SELF_MODIFYING_CODE = 0x04000000u,
98 DEBUG_INFO = 0x02000000u,
100 SOME_INSTRUCTIONS = 0x00000400u,
101 EXT_RELOC = 0x00000200u,
102 LOC_RELOC = 0x00000100u,
107 Section(
const details::section_32& section_cmd);
108 Section(
const details::section_64& section_cmd);
130 return virtual_address();
146 return relocations_offset_;
151 return nbof_relocations_;
158 return FLAGS(flags_ & FLAGS_MASK);
164 return TYPE(flags_ & TYPE_MASK);
196 return segment() !=
nullptr;
225 virtual_address(address);
231 relocations_offset_ = offset;
234 nbof_relocations_ = nb_reloc;
237 flags_ = flags_ | flags;
239 void flags(std::vector<FLAGS> flags);
241 flags_ = (flags_ & FLAGS_MASK) | uint8_t(type);
244 reserved1_ = reserved1;
247 reserved2_ = reserved2;
250 reserved3_ = reserved3;
276 std::string segment_name_;
277 uint64_t original_size_ = 0;
279 uint32_t relocations_offset_ = 0;
280 uint32_t nbof_relocations_ = 0;
282 uint32_t reserved1_ = 0;
283 uint32_t reserved2_ = 0;
284 uint32_t reserved3_ = 0;
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 that represents a Mach-O section.
Definition MachO/Section.hpp:44
span< const uint8_t > content() const override
section's content
void relocation_offset(uint32_t offset)
Definition MachO/Section.hpp:230
Section(const Section ©)
uint32_t reserved1() const
According to the official loader.h file, this value is reserved for offset or index
Definition MachO/Section.hpp:169
Section(std::string name, content_t content)
void address(uint64_t address)
Definition MachO/Section.hpp:224
std::vector< FLAGS > flags_list() const
Return the Section::flags as a list of Section::FLAGS.
Section & operator+=(FLAGS flag)
Definition MachO/Section.hpp:262
void add(FLAGS flag)
Append a Section::FLAGS to the current section.
void alignment(uint32_t align)
Definition MachO/Section.hpp:227
it_const_relocations relocations() const
Definition MachO/Section.hpp:219
std::vector< std::unique_ptr< Relocation > > relocations_t
Internal container for storing Mach-O Relocation.
Definition MachO/Section.hpp:54
uint32_t raw_flags() const
Section flags without applying the SECTION_FLAGS_MASK mask.
Definition MachO/Section.hpp:190
SegmentCommand * segment()
The segment associated with this section or a nullptr if not present.
Definition MachO/Section.hpp:201
void type(TYPE type)
Definition MachO/Section.hpp:240
void swap(Section &other) noexcept
friend std::ostream & operator<<(std::ostream &os, const Section §ion)
void flags(std::vector< FLAGS > flags)
std::vector< uint8_t > content_t
Definition MachO/Section.hpp:51
uint32_t relocation_offset() const
Offset of the relocation table. This value should be 0 for executable and libraries as the relocation...
Definition MachO/Section.hpp:145
const std::string & segment_name() const
Return the name of the segment linked to this section.
void clear(uint8_t v)
Clear the content of this section by filling its values with the byte provided in parameter.
Section(const details::section_32 §ion_cmd)
uint64_t address() const
Virtual base address of the section.
Definition MachO/Section.hpp:129
bool has_segment() const
Check if this section is correctly linked with a MachO::SegmentCommand.
Definition MachO/Section.hpp:195
uint32_t reserved3() const
This value is only present for 64 bits Mach-O files. In that case, the value is reserved.
Definition MachO/Section.hpp:181
void remove(FLAGS flag)
Remove a Section::FLAGS to the current section.
Section(const details::section_64 §ion_cmd)
void content(const content_t &data) override
Update the content of the section.
FLAGS
Definition MachO/Section.hpp:91
void reserved3(uint32_t reserved3)
Definition MachO/Section.hpp:249
void reserved1(uint32_t reserved1)
Definition MachO/Section.hpp:243
uint32_t alignment() const
Section alignment as a power of 2.
Definition MachO/Section.hpp:134
it_relocations relocations()
Return an iterator over the MachO::Relocation associated with this section.
Definition MachO/Section.hpp:216
TYPE type() const
Type of the section. This value can help to determine the purpose of the section (e....
Definition MachO/Section.hpp:163
bool has(FLAGS flag) const
Check if the section has the given Section::FLAGS flag.
uint32_t numberof_relocations() const
Number of relocations associated with this section.
Definition MachO/Section.hpp:150
TYPE
Definition MachO/Section.hpp:65
void numberof_relocations(uint32_t nb_reloc)
Definition MachO/Section.hpp:233
Section & operator-=(FLAGS flag)
Definition MachO/Section.hpp:266
const SegmentCommand * segment() const
Definition MachO/Section.hpp:204
Section & operator=(Section copy)
void flags(uint32_t flags)
Definition MachO/Section.hpp:236
Section(std::string name)
void accept(Visitor &visitor) const override
uint32_t reserved2() const
According to the official loader.h file, this value is reserved for count or sizeof
Definition MachO/Section.hpp:175
void reserved2(uint32_t reserved2)
Definition MachO/Section.hpp:246
FLAGS flags() const
Section's flags masked with SECTION_FLAGS_MASK (see: Section::FLAGS)
Definition MachO/Section.hpp:157
void segment_name(const std::string &name)
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:48
Class which represents an abstracted section.
Definition Abstract/Section.hpp:29
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
uint64_t align(uint64_t value, uint64_t align_on)
Definition utils.hpp:29
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41