LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_MACHO_SECTION_H
17#define LIEF_MACHO_SECTION_H
48 friend class BinaryParser;
50 friend class SegmentCommand;
53 using content_t = std::vector<uint8_t>;
54 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
57 using it_relocations = ref_iterator<relocations_t&, Relocation*>;
60 using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>;
64 static constexpr auto FLAGS_MASK = uint32_t(0xffffff00u);
65 static constexpr auto TYPE_MASK = uint32_t(0xff);
67 enum class TYPE: uint64_t {
70 CSTRING_LITERALS = 0x02u,
71 S_4BYTE_LITERALS = 0x03u,
72 S_8BYTE_LITERALS = 0x04u,
73 LITERAL_POINTERS = 0x05u,
74 NON_LAZY_SYMBOL_POINTERS = 0x06u,
75 LAZY_SYMBOL_POINTERS = 0x07u,
77 MOD_INIT_FUNC_POINTERS = 0x09u,
78 MOD_TERM_FUNC_POINTERS = 0x0au,
82 S_16BYTE_LITERALS = 0x0eu,
84 LAZY_DYLIB_SYMBOL_POINTERS = 0x10u,
85 THREAD_LOCAL_REGULAR = 0x11u,
86 THREAD_LOCAL_ZEROFILL = 0x12u,
87 THREAD_LOCAL_VARIABLES = 0x13u,
88 THREAD_LOCAL_VARIABLE_POINTERS = 0x14u,
89 THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15u,
90 INIT_FUNC_OFFSETS = 0x16u,
93 enum class FLAGS: uint64_t {
94 PURE_INSTRUCTIONS = 0x80000000u,
96 STRIP_STATIC_SYMS = 0x20000000u,
97 NO_DEAD_STRIP = 0x10000000u,
98 LIVE_SUPPORT = 0x08000000u,
99 SELF_MODIFYING_CODE = 0x04000000u,
100 DEBUG_INFO = 0x02000000u,
102 SOME_INSTRUCTIONS = 0x00000400u,
103 EXT_RELOC = 0x00000200u,
104 LOC_RELOC = 0x00000100u,
109 Section(
const details::section_32& section_cmd);
110 Section(
const details::section_64& section_cmd);
118 void swap(Section& other)
noexcept;
123 void content(
const content_t& data)
override;
132 return virtual_address();
148 return relocations_offset_;
153 return nbof_relocations_;
155 FLAGS
flags()
const {
160 return FLAGS(flags_ & FLAGS_MASK);
166 return TYPE(flags_ & TYPE_MASK);
198 return segment() !=
nullptr;
209 std::unique_ptr<SpanStream>
stream()
const;
212 void clear(uint8_t v);
230 virtual_address(address);
236 relocations_offset_ = offset;
239 nbof_relocations_ = nb_reloc;
242 flags_ = flags_ | flags;
244 void flags(std::vector<FLAGS> flags);
246 flags_ = (flags_ & FLAGS_MASK) | uint8_t(type);
249 reserved1_ = reserved1;
252 reserved2_ = reserved2;
255 reserved3_ = reserved3;
257 bool has(FLAGS flag)
const;
260 void add(FLAGS flag);
276 void accept(Visitor& visitor)
const override;
281 std::string segment_name_;
282 uint64_t original_size_ = 0;
284 uint32_t relocations_offset_ = 0;
285 uint32_t nbof_relocations_ = 0;
287 uint32_t reserved1_ = 0;
288 uint32_t reserved2_ = 0;
289 uint32_t reserved3_ = 0;
291 SegmentCommand *segment_ =
nullptr;
292 relocations_t relocations_;
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:75
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
Class that represents a Mach-O section.
Definition MachO/Section.hpp:46
span< const uint8_t > content() const override
section's content
void relocation_offset(uint32_t offset)
Definition MachO/Section.hpp:235
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:171
Section(std::string name, content_t content)
void address(uint64_t address)
Definition MachO/Section.hpp:229
std::vector< FLAGS > flags_list() const
Return the Section::flags as a list of Section::FLAGS.
Section & operator+=(FLAGS flag)
Definition MachO/Section.hpp:267
void add(FLAGS flag)
Append a Section::FLAGS to the current section.
void alignment(uint32_t align)
Definition MachO/Section.hpp:232
it_const_relocations relocations() const
Definition MachO/Section.hpp:224
uint32_t raw_flags() const
Section flags without applying the SECTION_FLAGS_MASK mask.
Definition MachO/Section.hpp:192
SegmentCommand * segment()
The segment associated with this section or a nullptr if not present.
Definition MachO/Section.hpp:203
void type(TYPE type)
Definition MachO/Section.hpp:245
void swap(Section &other) noexcept
friend std::ostream & operator<<(std::ostream &os, const Section §ion)
void flags(std::vector< FLAGS > flags)
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:147
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:131
bool has_segment() const
Check if this section is correctly linked with a MachO::SegmentCommand.
Definition MachO/Section.hpp:197
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:183
std::unique_ptr< SpanStream > stream() const
Return a stream over the content of this section.
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:93
void reserved3(uint32_t reserved3)
Definition MachO/Section.hpp:254
void reserved1(uint32_t reserved1)
Definition MachO/Section.hpp:248
uint32_t alignment() const
Section alignment as a power of 2.
Definition MachO/Section.hpp:136
it_relocations relocations()
Return an iterator over the MachO::Relocation associated with this section.
Definition MachO/Section.hpp:221
TYPE type() const
Type of the section. This value can help to determine the purpose of the section (e....
Definition MachO/Section.hpp:165
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:152
TYPE
Definition MachO/Section.hpp:67
void numberof_relocations(uint32_t nb_reloc)
Definition MachO/Section.hpp:238
Section & operator-=(FLAGS flag)
Definition MachO/Section.hpp:271
const SegmentCommand * segment() const
Definition MachO/Section.hpp:206
Section & operator=(Section copy)
void flags(uint32_t flags)
Definition MachO/Section.hpp:241
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:177
void reserved2(uint32_t reserved2)
Definition MachO/Section.hpp:251
FLAGS flags() const
Section's flags masked with SECTION_FLAGS_MASK (see: Section::FLAGS)
Definition MachO/Section.hpp:159
void segment_name(const std::string &name)
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:50
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
uint64_t align(uint64_t value, uint64_t align_on)
Definition utils.hpp:25
#define LIEF_API
Definition visibility.h:41