Class: ELFTools::Sections::SymTabSection

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

Overview

Class of symbol table section. Usually for section .symtab and .dynsym, which will refer to symbols in ELF file.

Instance Attribute Summary

Attributes inherited from Section

#header, #stream

Instance Method Summary collapse

Methods inherited from Section

create, #data, #name, #null?, #type

Constructor Details

#initialize(header, stream, section_at: nil, machine: nil, **_kwargs) ⇒ SymTabSection

Instantiate a ELFTools::Sections::SymTabSection object. There's a section_at lambda for ELFTools::Sections::SymTabSection to easily fetch other sections.

Parameters:



25
26
27
28
29
30
# File 'lib/elftools/sections/sym_tab_section.rb', line 25

def initialize(header, stream, section_at: nil, machine: nil, **_kwargs)
  @section_at = section_at
  @machine = machine
  # For faster #symbol_by_name
  super
end

Instance Method Details

#each_symbol {|sym| ... } ⇒ Enumerator<ELFTools::Sections::Symbol>, Array<ELFTools::Sections::Symbol> Also known as: each_symbols

Iterate all symbols.

All symbols are lazy loading, the symbol only be created whenever accessing it. This method is useful for #symbol_by_name since not all symbols need to be created.

Yield Parameters:

Yield Returns:

  • (void)

Returns:



64
65
66
67
68
69
70
# File 'lib/elftools/sections/sym_tab_section.rb', line 64

def each_symbol(&block)
  return enum_for(:each_symbol) unless block_given?

  Array.new(num_symbols) do |i|
    symbol_at(i).tap(&block)
  end
end

#num_symbolsInteger

Number of symbols.

Examples:

symtab.num_symbols
#=> 75

Returns:

  • (Integer)

    The number.



37
38
39
# File 'lib/elftools/sections/sym_tab_section.rb', line 37

def num_symbols
  header.sh_size / header.sh_entsize
end

#symbol_at(n) ⇒ ELFTools::Sections::Symbol?

Acquire the +n+-th symbol, 0-based.

Symbols are lazy loaded.

Parameters:

  • n (Integer)

    The index.

Returns:



48
49
50
51
# File 'lib/elftools/sections/sym_tab_section.rb', line 48

def symbol_at(n)
  @symbols ||= LazyArray.new(num_symbols, &method(:create_symbol))
  @symbols[n]
end

#symbol_by_name(name) ⇒ ELFTools::Sections::Symbol

Get symbol by its name.

Parameters:

  • name (String)

    The name of symbol.

Returns:



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

def symbol_by_name(name)
  each_symbol.find { |symbol| symbol.name == name }
end

#symbolsArray<ELFTools::Sections::Symbol>

Simply use #symbols to get all symbols.

Returns:



78
79
80
# File 'lib/elftools/sections/sym_tab_section.rb', line 78

def symbols
  each_symbol.to_a
end

#symstrELFTools::Sections::StrTabSection

Return the symbol string section. Lazy loaded.

Returns:



93
94
95
# File 'lib/elftools/sections/sym_tab_section.rb', line 93

def symstr
  @symstr ||= @section_at.call(header.sh_link)
end