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_symbols {|sym| ... } ⇒ Enumerator<ELFTools::Sections::Symbol>, Array<ELFTools::Sections::Symbol>
Iterate all symbols.
-
#initialize(header, stream, section_at: 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, **_kwargs) ⇒ SymTabSection
Instantiate a ELFTools::Sections::SymTabSection object. There’s a section_at
lambda for ELFTools::Sections::SymTabSection to easily fetch other sections.
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.
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_symbols ⇒ Integer
Number of symbols.
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.
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.
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 |
#symbols ⇒ Array<ELFTools::Sections::Symbol>
Simply use #symbols to get all symbols.
70 71 72 |
# File 'lib/elftools/sections/sym_tab_section.rb', line 70 def symbols each_symbols.to_a end |
#symstr ⇒ ELFTools::Sections::StrTabSection
Return the symbol string section. Lazy loaded.
85 86 87 |
# File 'lib/elftools/sections/sym_tab_section.rb', line 85 def symstr @symstr ||= @section_at.call(header.sh_link) end |