Class: ELFTools::Sections::Symbol

Inherits:
Object
  • Object
show all
Defined in:
lib/elftools/sections/symbol.rb

Overview

Class of symbol.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, stream, symstr: nil, machine: nil) ⇒ Symbol

Instantiate a ELFTools::Sections::Symbol object.

Parameters:



22
23
24
25
26
27
# File 'lib/elftools/sections/symbol.rb', line 22

def initialize(header, stream, symstr: nil, machine: nil)
  @header = header
  @stream = stream
  @symstr = symstr
  @machine = machine
end

Instance Attribute Details

#headerELFTools::Structs::ELF32_sym, ELFTools::Structs::ELF64_sym (readonly)

Returns Section header.



9
10
11
# File 'lib/elftools/sections/symbol.rb', line 9

def header
  @header
end

#stream#pos=, #read (readonly)

Returns Streaming object.

Returns:

  • (#pos=, #read)

    Streaming object.



10
11
12
# File 'lib/elftools/sections/symbol.rb', line 10

def stream
  @stream
end

Instance Method Details

#bindInteger

How this symbol is linked against others with the same name.

The available bindings are listed in Constants::STB.

Examples:

symbol.bind == ELFTools::Constants::STB_GLOBAL
#=> true

Returns:

  • (Integer)

    The binding.



65
66
67
# File 'lib/elftools/sections/symbol.rb', line 65

def bind
  header.st_info >> 4
end

#bind_nameString

The name of #bind.

Examples:

symbol.bind_name
#=> 'STB_GLOBAL'

Returns:

  • (String)

    The name.



74
75
76
# File 'lib/elftools/sections/symbol.rb', line 74

def bind_name
  Constants::STB.mapping(@machine, bind)
end

#nameString

Return the symbol name.

Returns:

  • (String)

    The name.



31
32
33
# File 'lib/elftools/sections/symbol.rb', line 31

def name
  @name ||= @symstr.call.name_at(header.st_name)
end

#section_indexInteger

The index of the section this symbol is defined in.

Values in Constants::SHN have special meanings instead of being an index.

Examples:

symbol.section_index == ELFTools::Constants::SHN_UNDEF
#=> true # the symbol is undefined and to be resolved at runtime

Returns:

  • (Integer)

    The section index.



107
108
109
# File 'lib/elftools/sections/symbol.rb', line 107

def section_index
  header.st_shndx.to_i
end

#typeInteger

What kind of entity this symbol refers to.

The available types are listed in Constants::STT.

Examples:

symbol.type == ELFTools::Constants::STT_FUNC
#=> true

Returns:

  • (Integer)

    The type.



42
43
44
# File 'lib/elftools/sections/symbol.rb', line 42

def type
  header.st_info & 0xf
end

#type_nameString

The name of #type.

A machine names types of its own, so the name is only known when the machine of the file is.

Examples:

symbol.type_name
#=> 'STT_FUNC'

Returns:

  • (String)

    The name.



54
55
56
# File 'lib/elftools/sections/symbol.rb', line 54

def type_name
  Constants::STT.mapping(@machine, type)
end

#visibilityInteger

How this symbol is accessed once it becomes part of an executable or shared object.

The available visibilities are listed in Constants::STV.

Examples:

symbol.visibility == ELFTools::Constants::STV_HIDDEN
#=> true

Returns:

  • (Integer)

    The visibility.



86
87
88
# File 'lib/elftools/sections/symbol.rb', line 86

def visibility
  header.st_other & 0x3
end

#visibility_nameString

The name of #visibility.

Examples:

symbol.visibility_name
#=> 'STV_DEFAULT'

Returns:

  • (String)

    The name.



95
96
97
# File 'lib/elftools/sections/symbol.rb', line 95

def visibility_name
  Constants::STV.mapping(@machine, visibility)
end