LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
LIEF::MachO::SegmentCommand Class Reference

Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command. More...

#include <SegmentCommand.hpp>

Inheritance diagram for LIEF::MachO::SegmentCommand:
Collaboration diagram for LIEF::MachO::SegmentCommand:

Public Types

enum class  FLAGS : uint64_t {
  HIGHVM = 0x1u , FVMLIB = 0x2u , NORELOC = 0x4u , PROTECTED_VERSION_1 = 0x8u ,
  READ_ONLY = 0x10u
}
 
enum class  VM_PROTECTIONS { READ = 0x1 , WRITE = 0x2 , EXECUTE = 0x4 }
 Values for segment_command.initprot. From <mach/vm_prot.h> More...
 
using content_t = std::vector<uint8_t>
 
using sections_t = std::vector<std::unique_ptr<Section>>
 Internal container for storing Mach-O Section.
 
using it_sections = ref_iterator<sections_t&, Section*>
 Iterator which outputs Section&.
 
using it_const_sections = const_ref_iterator<const sections_t&, const Section*>
 Iterator which outputs const Section&.
 
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::MachO::LoadCommand
enum class  TYPE : uint64_t {
  UNKNOWN = 0 , SEGMENT = 0x00000001u , SYMTAB = 0x00000002u , SYMSEG = 0x00000003u ,
  THREAD = 0x00000004u , UNIXTHREAD = 0x00000005u , LOADFVMLIB = 0x00000006u , IDFVMLIB = 0x00000007u ,
  IDENT = 0x00000008u , FVMFILE = 0x00000009u , PREPAGE = 0x0000000Au , DYSYMTAB = 0x0000000Bu ,
  LOAD_DYLIB = 0x0000000Cu , ID_DYLIB = 0x0000000Du , LOAD_DYLINKER = 0x0000000Eu , ID_DYLINKER = 0x0000000Fu ,
  PREBOUND_DYLIB = 0x00000010u , ROUTINES = 0x00000011u , SUB_FRAMEWORK = 0x00000012u , SUB_UMBRELLA = 0x00000013u ,
  SUB_CLIENT = 0x00000014u , SUB_LIBRARY = 0x00000015u , TWOLEVEL_HINTS = 0x00000016u , PREBIND_CKSUM = 0x00000017u ,
  LOAD_WEAK_DYLIB = 0x80000018u , SEGMENT_64 = 0x00000019u , ROUTINES_64 = 0x0000001Au , UUID = 0x0000001Bu ,
  RPATH = 0x8000001Cu , CODE_SIGNATURE = 0x0000001Du , SEGMENT_SPLIT_INFO = 0x0000001Eu , REEXPORT_DYLIB = 0x8000001Fu ,
  LAZY_LOAD_DYLIB = 0x00000020u , ENCRYPTION_INFO = 0x00000021u , DYLD_INFO = 0x00000022u , DYLD_INFO_ONLY = 0x80000022u ,
  LOAD_UPWARD_DYLIB = 0x80000023u , VERSION_MIN_MACOSX = 0x00000024u , VERSION_MIN_IPHONEOS = 0x00000025u , FUNCTION_STARTS = 0x00000026u ,
  DYLD_ENVIRONMENT = 0x00000027u , MAIN = 0x80000028u , DATA_IN_CODE = 0x00000029u , SOURCE_VERSION = 0x0000002Au ,
  DYLIB_CODE_SIGN_DRS = 0x0000002Bu , ENCRYPTION_INFO_64 = 0x0000002Cu , LINKER_OPTION = 0x0000002Du , LINKER_OPTIMIZATION_HINT = 0x0000002Eu ,
  VERSION_MIN_TVOS = 0x0000002Fu , VERSION_MIN_WATCHOS = 0x00000030u , NOTE = 0x00000031u , BUILD_VERSION = 0x00000032u ,
  DYLD_EXPORTS_TRIE = 0x80000033u , DYLD_CHAINED_FIXUPS = 0x80000034u , FILESET_ENTRY = 0x80000035u , ATOM_INFO = 0x00000036u ,
  LIEF_UNKNOWN = 0xffee0001u
}
 
using raw_t = std::vector<uint8_t>
 
- 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

 SegmentCommand ()
 
 SegmentCommand (const details::segment_command_32 &cmd)
 
 SegmentCommand (const details::segment_command_64 &cmd)
 
SegmentCommandoperator= (SegmentCommand other)
 
 SegmentCommand (const SegmentCommand &copy)
 
 SegmentCommand (std::string name, content_t content)
 
 SegmentCommand (std::string name)
 
void swap (SegmentCommand &other) noexcept
 
std::unique_ptr< LoadCommandclone () const override
 
 ~SegmentCommand () override
 
const std::string & name () const
 Name of the segment (e.g. __TEXT)
 
uint64_t virtual_address () const
 Absolute virtual base address of the segment.
 
uint64_t virtual_size () const
 Virtual size of the segment.
 
uint64_t file_size () const
 Size of this segment in the binary file.
 
uint64_t file_offset () const
 Offset of the data of this segment in the file.
 
uint32_t max_protection () const
 The maximum of protections for this segment (cf. VM_PROTECTIONS)
 
uint32_t init_protection () const
 The initial protections of this segment (cf. VM_PROTECTIONS)
 
uint32_t numberof_sections () const
 The number of sections associated with this segment.
 
uint32_t flags () const
 Flags associated with this segment (cf. SegmentCommand::FLAGS)
 
it_sections sections ()
 Return an iterator over the MachO::Section linked to this segment.
 
it_const_sections sections () const
 
it_relocations relocations ()
 Return an iterator over the MachO::Relocation linked to this segment.
 
it_const_relocations relocations () const
 
const Sectionget_section (const std::string &name) const
 Get the section with the given name.
 
Sectionget_section (const std::string &name)
 
span< const uint8_t > content () const
 The raw content of this segment.
 
std::unique_ptr< SpanStreamstream () const
 Return a stream over the content of this segment.
 
int8_t index () const
 The original index of this segment or -1 if not defined.
 
void name (std::string name)
 
void virtual_address (uint64_t virtual_address)
 
void virtual_size (uint64_t virtual_size)
 
void file_offset (uint64_t file_offset)
 
void file_size (uint64_t file_size)
 
void max_protection (uint32_t max_protection)
 
void init_protection (uint32_t init_protection)
 
void numberof_sections (uint32_t nb_section)
 
void flags (uint32_t flags)
 
void content (content_t data)
 
Sectionadd_section (const Section &section)
 Add a new section in this segment.
 
void remove_all_sections ()
 Remove all the sections linked to this segment.
 
bool has (const Section &section) const
 Check if the current segment embeds the given section.
 
bool has_section (const std::string &section_name) const
 Check if the current segment embeds the given section name.
 
bool is (VM_PROTECTIONS prot) const
 
std::ostream & print (std::ostream &os) const override
 
void accept (Visitor &visitor) const override
 
- Public Member Functions inherited from LIEF::MachO::LoadCommand
 LoadCommand ()=default
 
 LoadCommand (const details::load_command &command)
 
 LoadCommand (LoadCommand::TYPE type, uint32_t size)
 
LoadCommandoperator= (const LoadCommand &copy)=default
 
 LoadCommand (const LoadCommand &copy)=default
 
void swap (LoadCommand &other) noexcept
 
 ~LoadCommand () override=default
 
LoadCommand::TYPE command () const
 Command type.
 
uint32_t size () const
 Size of the command (should be greather than sizeof(load_command))
 
span< const uint8_t > data () const
 Raw command.
 
uint64_t command_offset () const
 Offset of the command within the Load Command Table
 
void data (raw_t data)
 
void command (LoadCommand::TYPE command)
 
void size (uint32_t size)
 
void command_offset (uint64_t offset)
 
template<class T >
const T * cast () const
 
template<class T >
T * cast ()
 
- Public Member Functions inherited from LIEF::Object
 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
 
virtual ~Object ()
 

Static Public Member Functions

static bool classof (const LoadCommand *cmd)
 
- Static Public Member Functions inherited from LIEF::MachO::LoadCommand
static bool is_linkedit_data (const LoadCommand &cmd)
 

Detailed Description

Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.

Member Typedef Documentation

◆ content_t

using LIEF::MachO::SegmentCommand::content_t = std::vector<uint8_t>

◆ it_const_relocations

◆ it_const_sections

Iterator which outputs const Section&.

◆ it_relocations

◆ it_sections

◆ relocations_t

using LIEF::MachO::SegmentCommand::relocations_t = std::vector<std::unique_ptr<Relocation>>

Internal container for storing Mach-O Relocation.

◆ sections_t

using LIEF::MachO::SegmentCommand::sections_t = std::vector<std::unique_ptr<Section>>

Internal container for storing Mach-O Section.

Member Enumeration Documentation

◆ FLAGS

enum class LIEF::MachO::SegmentCommand::FLAGS : uint64_t
strong
Enumerator
HIGHVM 

The file contents for this segment are for the high part of the virtual memory space; the low part is zero filled (for stacks in core files).

FVMLIB 

this segment is the VM that is allocated by a fixed VM library, for overlap checking in the link editor.

NORELOC 

This segment has nothing that was relocated in it and nothing relocated to it. It may be safely replaced without relocation.

PROTECTED_VERSION_1 
READ_ONLY 

◆ VM_PROTECTIONS

Values for segment_command.initprot. From <mach/vm_prot.h>

Enumerator
READ 

Reading data within the segment is allowed.

WRITE 

Writing data within the segment is allowed.

EXECUTE 

Executing data within the segment is allowed.

Constructor & Destructor Documentation

◆ SegmentCommand() [1/6]

LIEF::MachO::SegmentCommand::SegmentCommand ( )

◆ SegmentCommand() [2/6]

LIEF::MachO::SegmentCommand::SegmentCommand ( const details::segment_command_32 & cmd)

◆ SegmentCommand() [3/6]

LIEF::MachO::SegmentCommand::SegmentCommand ( const details::segment_command_64 & cmd)

◆ SegmentCommand() [4/6]

LIEF::MachO::SegmentCommand::SegmentCommand ( const SegmentCommand & copy)

◆ SegmentCommand() [5/6]

LIEF::MachO::SegmentCommand::SegmentCommand ( std::string name,
content_t content )

◆ SegmentCommand() [6/6]

LIEF::MachO::SegmentCommand::SegmentCommand ( std::string name)

◆ ~SegmentCommand()

LIEF::MachO::SegmentCommand::~SegmentCommand ( )
override

Member Function Documentation

◆ accept()

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

Reimplemented from LIEF::MachO::LoadCommand.

◆ add_section()

Section & LIEF::MachO::SegmentCommand::add_section ( const Section & section)

Add a new section in this segment.

◆ classof()

static bool LIEF::MachO::SegmentCommand::classof ( const LoadCommand * cmd)
inlinestatic

◆ clone()

std::unique_ptr< LoadCommand > LIEF::MachO::SegmentCommand::clone ( ) const
inlineoverridevirtual

Reimplemented from LIEF::MachO::LoadCommand.

◆ content() [1/2]

span< const uint8_t > LIEF::MachO::SegmentCommand::content ( ) const
inline

The raw content of this segment.

◆ content() [2/2]

void LIEF::MachO::SegmentCommand::content ( content_t data)

◆ file_offset() [1/2]

uint64_t LIEF::MachO::SegmentCommand::file_offset ( ) const
inline

Offset of the data of this segment in the file.

◆ file_offset() [2/2]

void LIEF::MachO::SegmentCommand::file_offset ( uint64_t file_offset)
inline

◆ file_size() [1/2]

uint64_t LIEF::MachO::SegmentCommand::file_size ( ) const
inline

Size of this segment in the binary file.

◆ file_size() [2/2]

void LIEF::MachO::SegmentCommand::file_size ( uint64_t file_size)
inline

◆ flags() [1/2]

uint32_t LIEF::MachO::SegmentCommand::flags ( ) const
inline

Flags associated with this segment (cf. SegmentCommand::FLAGS)

◆ flags() [2/2]

void LIEF::MachO::SegmentCommand::flags ( uint32_t flags)
inline

◆ get_section() [1/2]

Section * LIEF::MachO::SegmentCommand::get_section ( const std::string & name)

◆ get_section() [2/2]

const Section * LIEF::MachO::SegmentCommand::get_section ( const std::string & name) const

Get the section with the given name.

◆ has()

bool LIEF::MachO::SegmentCommand::has ( const Section & section) const

Check if the current segment embeds the given section.

◆ has_section()

bool LIEF::MachO::SegmentCommand::has_section ( const std::string & section_name) const

Check if the current segment embeds the given section name.

◆ index()

int8_t LIEF::MachO::SegmentCommand::index ( ) const
inline

The original index of this segment or -1 if not defined.

◆ init_protection() [1/2]

uint32_t LIEF::MachO::SegmentCommand::init_protection ( ) const
inline

The initial protections of this segment (cf. VM_PROTECTIONS)

◆ init_protection() [2/2]

void LIEF::MachO::SegmentCommand::init_protection ( uint32_t init_protection)
inline

◆ is()

bool LIEF::MachO::SegmentCommand::is ( VM_PROTECTIONS prot) const
inline

◆ max_protection() [1/2]

uint32_t LIEF::MachO::SegmentCommand::max_protection ( ) const
inline

The maximum of protections for this segment (cf. VM_PROTECTIONS)

◆ max_protection() [2/2]

void LIEF::MachO::SegmentCommand::max_protection ( uint32_t max_protection)
inline

◆ name() [1/2]

const std::string & LIEF::MachO::SegmentCommand::name ( ) const
inline

Name of the segment (e.g. __TEXT)

Referenced by LIEF::MachO::LinkEdit::segmentof().

◆ name() [2/2]

void LIEF::MachO::SegmentCommand::name ( std::string name)
inline

◆ numberof_sections() [1/2]

uint32_t LIEF::MachO::SegmentCommand::numberof_sections ( ) const
inline

The number of sections associated with this segment.

◆ numberof_sections() [2/2]

void LIEF::MachO::SegmentCommand::numberof_sections ( uint32_t nb_section)
inline

◆ operator=()

SegmentCommand & LIEF::MachO::SegmentCommand::operator= ( SegmentCommand other)

◆ print()

std::ostream & LIEF::MachO::SegmentCommand::print ( std::ostream & os) const
overridevirtual

Reimplemented from LIEF::MachO::LoadCommand.

◆ relocations() [1/2]

it_relocations LIEF::MachO::SegmentCommand::relocations ( )
inline

Return an iterator over the MachO::Relocation linked to this segment.

For Mach-O executable or library this iterator should be empty as the relocations are managed by the Dyld::rebase_opcodes. On the other hand, for object files (.o) this iterator should not be empty

◆ relocations() [2/2]

it_const_relocations LIEF::MachO::SegmentCommand::relocations ( ) const
inline

◆ remove_all_sections()

void LIEF::MachO::SegmentCommand::remove_all_sections ( )

Remove all the sections linked to this segment.

◆ sections() [1/2]

it_sections LIEF::MachO::SegmentCommand::sections ( )
inline

Return an iterator over the MachO::Section linked to this segment.

◆ sections() [2/2]

it_const_sections LIEF::MachO::SegmentCommand::sections ( ) const
inline

◆ stream()

std::unique_ptr< SpanStream > LIEF::MachO::SegmentCommand::stream ( ) const

Return a stream over the content of this segment.

◆ swap()

void LIEF::MachO::SegmentCommand::swap ( SegmentCommand & other)
noexcept

◆ virtual_address() [1/2]

uint64_t LIEF::MachO::SegmentCommand::virtual_address ( ) const
inline

Absolute virtual base address of the segment.

◆ virtual_address() [2/2]

void LIEF::MachO::SegmentCommand::virtual_address ( uint64_t virtual_address)
inline

◆ virtual_size() [1/2]

uint64_t LIEF::MachO::SegmentCommand::virtual_size ( ) const
inline

Virtual size of the segment.

◆ virtual_size() [2/2]

void LIEF::MachO::SegmentCommand::virtual_size ( uint64_t virtual_size)
inline

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