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, **_kwargs) ⇒ SymTabSection

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

Parameters:



21
22
23
24
25
# File 'lib/elftools/sections/sym_tab_section.rb', line 21

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

Instance Method Details

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

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:



59
60
61
62
63
64
65
# File 'lib/elftools/sections/sym_tab_section.rb', line 59

def each_symbols(&block)
  return enum_for(:each_symbols) 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.



32
33
34
# File 'lib/elftools/sections/sym_tab_section.rb', line 32

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:



43
44
45
46
# File 'lib/elftools/sections/sym_tab_section.rb', line 43

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:



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

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

#symbolsArray<ELFTools::Sections::Symbol>

Simply use #symbols to get all symbols.

Returns:



70
71
72
# File 'lib/elftools/sections/sym_tab_section.rb', line 70

def symbols
  each_symbols.to_a
end

#symstrELFTools::Sections::StrTabSection

Return the symbol string section. Lazy loaded.

Returns:



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

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