Class: ELFTools::Sections::SymTabSection
- 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
Instance Method Summary collapse
-
#each_symbol {|sym| ... } ⇒ Enumerator<ELFTools::Sections::Symbol>, Array<ELFTools::Sections::Symbol>
(also: #each_symbols)
Iterate all symbols.
-
#initialize(header, stream, section_at: nil, machine: nil, **_kwargs) ⇒ SymTabSection
constructor
Instantiate a SymTabSection object.
-
#num_symbols ⇒ Integer
Number of symbols.
-
#symbol_at(n) ⇒ ELFTools::Sections::Symbol?
Acquire the +n+-th symbol, 0-based.
-
#symbol_by_name(name) ⇒ ELFTools::Sections::Symbol
Get symbol by its name.
-
#symbols ⇒ Array<ELFTools::Sections::Symbol>
Simply use #symbols to get all symbols.
-
#symstr ⇒ ELFTools::Sections::StrTabSection
Return the symbol string section.
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.
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.
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_symbols ⇒ Integer
Number of symbols.
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.
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.
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 |
#symbols ⇒ Array<ELFTools::Sections::Symbol>
Simply use #symbols to get all symbols.
78 79 80 |
# File 'lib/elftools/sections/sym_tab_section.rb', line 78 def symbols each_symbol.to_a end |
#symstr ⇒ ELFTools::Sections::StrTabSection
Return the symbol string section. Lazy loaded.
93 94 95 |
# File 'lib/elftools/sections/sym_tab_section.rb', line 93 def symstr @symstr ||= @section_at.call(header.sh_link) end |