LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
LIEF::MachO::Section Class Reference

Class that represents a Mach-O section. More...

#include <Section.hpp>

Inheritance diagram for LIEF::MachO::Section:
Inheritance graph
[legend]
Collaboration diagram for LIEF::MachO::Section:
Collaboration graph
[legend]

Public Types

using content_t = std::vector<uint8_t>
 
using flag_list_t = std::set<MACHO_SECTION_FLAGS>
 
using relocations_t = std::vector<std::unique_ptr<Relocation>>
 Internal container for storing Mach-O Relocation.
 
using it_relocations = ref_iterator<relocations_t&, Relocation*>
 Iterator which outputs Relocation&.
 
using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>
 Iterator which outputs const Relocation&.
 
- Public Types inherited from LIEF::Object
template<class T >
using output_t = add_pointer_t<decay_t<T>>
 
template<class T >
using output_const_t = add_pointer_t<add_const_t<decay_t<T>>>
 

Public Member Functions

 Section (const details::section_32 &section_cmd)
 
 Section (const details::section_64 &section_cmd)
 
 Section (std::string name)
 
 Section (std::string name, content_t content)
 
Sectionoperator= (Section copy)
 
 Section (const Section &copy)
 
void swap (Section &other)
 
span< const uint8_t > content () const override
 section's content
 
void content (const content_t &data) override
 Update the content of the section.
 
const std::string & segment_name () const
 Return the name of the segment linked to this section.
 
uint64_t address () const
 Virtual base address of the section.
 
uint32_t alignment () const
 Section alignment as a power of 2.
 
uint32_t relocation_offset () const
 Offset of the relocation table. This value should be 0 for executable and libraries as the relocations are managed by the DyldInfo::rebase.
 
uint32_t numberof_relocations () const
 Number of relocations associated with this section.
 
uint32_t flags () const
 Section's flags masked with SECTION_FLAGS_MASK (see: MACHO_SECTION_FLAGS)
 
MACHO_SECTION_TYPES type () const
 Type of the section. This value can help to determine the purpose of the section (e.g. MACHO_SECTION_TYPES::MACHO_SECTION_TYPES)
 
uint32_t reserved1 () const
 According to the official loader.h file, this value is reserved for offset or index
 
uint32_t reserved2 () const
 According to the official loader.h file, this value is reserved for count or sizeof
 
uint32_t reserved3 () const
 This value is only present for 64 bits Mach-O files. In that case, the value is reserved.
 
flag_list_t flags_list () const
 Return the Section::flags as an std::set of MACHO_SECTION_FLAGS.
 
uint32_t raw_flags () const
 Section flags without applying the SECTION_FLAGS_MASK mask.
 
bool has_segment () const
 Check if this section is correctly linked with a MachO::SegmentCommand.
 
SegmentCommandsegment ()
 The segment associated with this section or a nullptr if not present.
 
const SegmentCommandsegment () const
 
void clear (uint8_t v)
 Clear the content of this section by filling its values with the byte provided in parameter.
 
it_relocations relocations ()
 Return an iterator over the MachO::Relocation associated with this section.
 
it_const_relocations relocations () const
 
void segment_name (const std::string &name)
 
void address (uint64_t address)
 
void alignment (uint32_t align)
 
void relocation_offset (uint32_t relocOffset)
 
void numberof_relocations (uint32_t nbReloc)
 
void flags (uint32_t flags)
 
void flags (flag_list_t flags)
 
void type (MACHO_SECTION_TYPES type)
 
void reserved1 (uint32_t reserved1)
 
void reserved2 (uint32_t reserved2)
 
void reserved3 (uint32_t reserved3)
 
bool has (MACHO_SECTION_FLAGS flag) const
 Check if the section has the given MACHO_SECTION_FLAGS flag.
 
void add (MACHO_SECTION_FLAGS flag)
 Append a MACHO_SECTION_FLAGS to the current section.
 
void remove (MACHO_SECTION_FLAGS flag)
 Remove a MACHO_SECTION_FLAGS to the current section.
 
Sectionoperator+= (MACHO_SECTION_FLAGS flag)
 
Sectionoperator-= (MACHO_SECTION_FLAGS flag)
 
void accept (Visitor &visitor) const override
 
- Public Member Functions inherited from LIEF::Section
 Section (std::string name)
 
Sectionoperator= (const Section &)
 
 Section (const Section &)
 
virtual std::string name () const
 section's name
 
virtual const std::string & fullname () const
 Return the complete section's name which might trailing (0) bytes.
 
virtual void size (uint64_t size)
 Change the section size.
 
virtual uint64_t size () const
 section's size (size in the binary, not the virtual size)
 
virtual uint64_t offset () const
 Offset in the binary.
 
virtual uint64_t virtual_address () const
 Address where the section should be mapped.
 
virtual void virtual_address (uint64_t virtual_address)
 
virtual void name (const std::string &name)
 Change the section's name.
 
virtual void offset (uint64_t offset)
 
double entropy () const
 Section's entropy.
 
size_t search (uint64_t integer, size_t pos, size_t size) const
 
size_t search (const std::vector< uint8_t > &pattern, size_t pos=0) const
 
size_t search (const std::string &pattern, size_t pos=0) const
 
size_t search (uint64_t integer, size_t pos=0) const
 
std::vector< size_t > search_all (uint64_t v, size_t size) const
 
std::vector< size_t > search_all (uint64_t v) const
 
std::vector< size_t > search_all (const std::string &v) const
 
void accept (Visitor &visitor) const override
 Method so that the visitor can visit us.
 
- Public Member Functions inherited from LIEF::Object
 Object (const Object &other)
 
Objectoperator= (const Object &other)
 
template<class T >
output_t< T > as ()
 
template<class T >
output_const_t< T > as () const
 
virtual bool operator== (const Object &other) const
 
virtual bool operator!= (const Object &other) const
 

Additional Inherited Members

- Static Public Attributes inherited from LIEF::Section
static constexpr size_t npos = -1
 

Detailed Description

Class that represents a Mach-O section.

Member Function Documentation

◆ accept()

void LIEF::MachO::Section::accept ( Visitor & visitor) const
overridevirtual

Implements LIEF::Object.

◆ content() [1/2]

span< const uint8_t > LIEF::MachO::Section::content ( ) const
overridevirtual

section's content

Reimplemented from LIEF::Section.

◆ content() [2/2]

void LIEF::MachO::Section::content ( const content_t & data)
overridevirtual

Update the content of the section.

Reimplemented from LIEF::Section.

◆ flags()

uint32_t LIEF::MachO::Section::flags ( ) const

Section's flags masked with SECTION_FLAGS_MASK (see: MACHO_SECTION_FLAGS)

See also
flags

◆ flags_list()

flag_list_t LIEF::MachO::Section::flags_list ( ) const

Return the Section::flags as an std::set of MACHO_SECTION_FLAGS.

See also
flags

◆ relocation_offset()

uint32_t LIEF::MachO::Section::relocation_offset ( ) const

Offset of the relocation table. This value should be 0 for executable and libraries as the relocations are managed by the DyldInfo::rebase.

Other the other hand, for object files (.o) this value should not be 0

See also
numberof_relocations
relocations

◆ relocations()

it_relocations LIEF::MachO::Section::relocations ( )

Return an iterator over the MachO::Relocation associated with this section.

This iterator is likely to be empty of executable and libraries while it should not for object files (.o)


The documentation for this class was generated from the following file: