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

Class that represents a Symbol in a Mach-O file. More...

#include <Symbol.hpp>

Inheritance diagram for LIEF::MachO::Symbol:
Collaboration diagram for LIEF::MachO::Symbol:

Public Types

enum class  CATEGORY : uint32_t {
  NONE = 0 , LOCAL , EXTERNAL , UNDEFINED ,
  INDIRECT_ABS , INDIRECT_LOCAL
}
 Category of the symbol when the symbol comes from the LC_SYMTAB command. The category is defined according to the LC_DYSYMTAB (DynamicSymbolCommand) command. More...
 
enum class  ORIGIN : uint32_t { UNKNOWN = 0 , DYLD_EXPORT = 1 , DYLD_BIND = 2 , LC_SYMTAB = 3 }
 
enum class  TYPE : uint32_t {
  UNDEFINED = 0x0u , ABSOLUTE_SYM = 0x2u , SECTION = 0xeu , PREBOUND = 0xcu ,
  INDIRECT = 0xau
}
 
- 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

 Symbol ()=default
 
 Symbol (const details::nlist_32 &cmd)
 
 Symbol (const details::nlist_64 &cmd)
 
Symboloperator= (Symbol other)
 
 Symbol (const Symbol &other)
 
void swap (Symbol &other) noexcept
 
 ~Symbol () override=default
 
uint8_t raw_type () const
 Raw value of nlist_xx.n_type
 
TYPE type () const
 Type as defined by nlist_xx.n_type & N_TYPE
 
uint8_t numberof_sections () const
 It returns the number of sections in which this symbol can be found. If the symbol can't be found in any section, it returns 0 (NO_SECT)
 
uint16_t description () const
 Return information about the symbol (SYMBOL_DESCRIPTIONS)
 
bool has_export_info () const
 True if the symbol is associated with an ExportInfo This value is set when the symbol comes from the Dyld Export trie.
 
const ExportInfoexport_info () const
 Return the ExportInfo associated with this symbol (or nullptr if not present)
 
ExportInfoexport_info ()
 
bool has_binding_info () const
 True if the symbol is associated with a BindingInfo This value is set when the symbol comes from the Dyld symbol bindings.
 
const BindingInfobinding_info () const
 Return the BindingInfo associated with this symbol (or nullptr if not present)
 
BindingInfobinding_info ()
 
std::string demangled_name () const
 Try to demangle the symbol or return an empty string if it is not possible.
 
bool is_external () const
 True if the symbol is defined as an external symbol.
 
const DylibCommandlibrary () const
 Return the library in which the symbol is defined. It returns a null pointer if the library can't be resolved.
 
DylibCommandlibrary ()
 
ORIGIN origin () const
 Return the origin of the symbol: from LC_SYMTAB command or from the Dyld information.
 
CATEGORY category () const
 Category of the symbol according to the LC_DYSYMTAB command.
 
void raw_type (uint8_t type)
 
void numberof_sections (uint8_t nbsections)
 
void description (uint16_t desc)
 
void accept (Visitor &visitor) const override
 
- Public Member Functions inherited from LIEF::Symbol
 Symbol ()=default
 
 Symbol (std::string name)
 
 Symbol (std::string name, uint64_t value)
 
 Symbol (std::string name, uint64_t value, uint64_t size)
 
 Symbol (const Symbol &)=default
 
Symboloperator= (const Symbol &)=default
 
 ~Symbol () override=default
 
void swap (Symbol &other) noexcept
 
virtual const std::string & name () const
 Return the symbol's name.
 
virtual std::string & name ()
 
virtual void name (std::string name)
 Set symbol name.
 
virtual uint64_t value () const
 
virtual void value (uint64_t value)
 
virtual uint64_t size () const
 This size of the symbol (when applicable)
 
virtual void size (uint64_t value)
 
void accept (Visitor &visitor) const override
 Method so that the visitor can visit us.
 
- 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 const Symbolindirect_abs ()
 
static const Symbolindirect_local ()
 

Static Public Attributes

static constexpr uint32_t TYPE_MASK = 0x0e
 Same as N_TYPE.
 

Detailed Description

Class that represents a Symbol in a Mach-O file.

A Mach-O symbol can come from:

  1. The symbols command (LC_SYMTAB / SymbolCommand)
  2. The Dyld Export trie
  3. The Dyld Symbol bindings

Member Enumeration Documentation

◆ CATEGORY

enum class LIEF::MachO::Symbol::CATEGORY : uint32_t
strong

Category of the symbol when the symbol comes from the LC_SYMTAB command. The category is defined according to the LC_DYSYMTAB (DynamicSymbolCommand) command.

Enumerator
NONE 
LOCAL 
EXTERNAL 
UNDEFINED 
INDIRECT_ABS 
INDIRECT_LOCAL 

◆ ORIGIN

enum class LIEF::MachO::Symbol::ORIGIN : uint32_t
strong
Enumerator
UNKNOWN 
DYLD_EXPORT 
DYLD_BIND 
LC_SYMTAB 

The symbol comes from the binding opcodes.

◆ TYPE

enum class LIEF::MachO::Symbol::TYPE : uint32_t
strong
Enumerator
UNDEFINED 

The symbol is undefined. It is referenced in a different module.

ABSOLUTE_SYM 

The symbol is absolute. The linker doesn't update his value.

SECTION 

The symbol is defined in the section number given in nlist_base.n_sect .

PREBOUND 

The symbol is undefined and the image is using a prebound value for the symbol. Set the n_sect field to NO_SECT .

INDIRECT 

The symbol is defined to be the same as another symbol. The n_value field is an index into the string table specifying the name of the other symbol. When that symbol is linked, both this and the other symbol point to the same defined type and value.

Constructor & Destructor Documentation

◆ Symbol() [1/4]

LIEF::MachO::Symbol::Symbol ( )
default

◆ Symbol() [2/4]

LIEF::MachO::Symbol::Symbol ( const details::nlist_32 & cmd)

◆ Symbol() [3/4]

LIEF::MachO::Symbol::Symbol ( const details::nlist_64 & cmd)

◆ Symbol() [4/4]

LIEF::MachO::Symbol::Symbol ( const Symbol & other)

◆ ~Symbol()

LIEF::MachO::Symbol::~Symbol ( )
overridedefault

Member Function Documentation

◆ accept()

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

Implements LIEF::Object.

◆ binding_info() [1/2]

BindingInfo * LIEF::MachO::Symbol::binding_info ( )
inline

◆ binding_info() [2/2]

const BindingInfo * LIEF::MachO::Symbol::binding_info ( ) const
inline

Return the BindingInfo associated with this symbol (or nullptr if not present)

See also
has_binding_info

◆ category()

CATEGORY LIEF::MachO::Symbol::category ( ) const
inline

Category of the symbol according to the LC_DYSYMTAB command.

◆ demangled_name()

std::string LIEF::MachO::Symbol::demangled_name ( ) const

Try to demangle the symbol or return an empty string if it is not possible.

◆ description() [1/2]

uint16_t LIEF::MachO::Symbol::description ( ) const
inline

Return information about the symbol (SYMBOL_DESCRIPTIONS)

◆ description() [2/2]

void LIEF::MachO::Symbol::description ( uint16_t desc)
inline

◆ export_info() [1/2]

ExportInfo * LIEF::MachO::Symbol::export_info ( )
inline

◆ export_info() [2/2]

const ExportInfo * LIEF::MachO::Symbol::export_info ( ) const
inline

Return the ExportInfo associated with this symbol (or nullptr if not present)

See also
has_export_info

◆ has_binding_info()

bool LIEF::MachO::Symbol::has_binding_info ( ) const
inline

True if the symbol is associated with a BindingInfo This value is set when the symbol comes from the Dyld symbol bindings.

◆ has_export_info()

bool LIEF::MachO::Symbol::has_export_info ( ) const
inline

True if the symbol is associated with an ExportInfo This value is set when the symbol comes from the Dyld Export trie.

◆ indirect_abs()

static const Symbol & LIEF::MachO::Symbol::indirect_abs ( )
static

◆ indirect_local()

static const Symbol & LIEF::MachO::Symbol::indirect_local ( )
static

◆ is_external()

bool LIEF::MachO::Symbol::is_external ( ) const
inline

True if the symbol is defined as an external symbol.

◆ library() [1/2]

DylibCommand * LIEF::MachO::Symbol::library ( )
inline

◆ library() [2/2]

const DylibCommand * LIEF::MachO::Symbol::library ( ) const
inline

Return the library in which the symbol is defined. It returns a null pointer if the library can't be resolved.

◆ numberof_sections() [1/2]

uint8_t LIEF::MachO::Symbol::numberof_sections ( ) const
inline

It returns the number of sections in which this symbol can be found. If the symbol can't be found in any section, it returns 0 (NO_SECT)

◆ numberof_sections() [2/2]

void LIEF::MachO::Symbol::numberof_sections ( uint8_t nbsections)
inline

◆ operator=()

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

◆ origin()

ORIGIN LIEF::MachO::Symbol::origin ( ) const
inline

Return the origin of the symbol: from LC_SYMTAB command or from the Dyld information.

◆ raw_type() [1/2]

uint8_t LIEF::MachO::Symbol::raw_type ( ) const
inline

Raw value of nlist_xx.n_type

◆ raw_type() [2/2]

void LIEF::MachO::Symbol::raw_type ( uint8_t type)
inline

◆ swap()

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

◆ type()

TYPE LIEF::MachO::Symbol::type ( ) const
inline

Type as defined by nlist_xx.n_type & N_TYPE

Member Data Documentation

◆ TYPE_MASK

uint32_t LIEF::MachO::Symbol::TYPE_MASK = 0x0e
staticconstexpr

Same as N_TYPE.


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