Class: Elf::SymbolTable

Inherits:
Section show all
Includes:
Enumerable
Defined in:
lib/elf/symboltable.rb

Defined Under Namespace

Classes: UnknownSymbol

Constant Summary

Constants inherited from Section

Elf::Section::Abs, Elf::Section::Common, Elf::Section::FlagsToChars, Elf::Section::OsSpecific, Elf::Section::ProcSpecific, Elf::Section::Reserved, Elf::Section::SunW, Elf::Section::SunWIgnore, Elf::Section::Undef, Elf::Section::XIndex

Instance Attribute Summary

Attributes inherited from Section

#addr, #addralign, #entsize, #file, #index, #info, #offset, #size, #type

Instance Method Summary collapse

Methods inherited from Section

#==, #flags, #flags_i, #flags_s, #initialize, #link, #load, #name, read, #summary

Constructor Details

This class inherits a constructor from Elf::Section

Instance Method Details

#[](idx) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/elf/symboltable.rb', line 48

def [](idx)
  load unless @symbols

  if idx.is_a?(Numeric)
    raise UnknownSymbol.new(idx, self) unless @symbols[idx] != nil
    return @symbols[idx]
  elsif idx.respond_to?("to_s")
    idx = idx.to_s
    raise UnknownSymbol.new(idx, self) unless @symbol_names.has_key?(idx)
    return @symbols[@symbol_names[idx]]
  else
    raise TypeError.new("wrong argument type #{sect_idx_or_name.class} (expected String or Integer)")
  end
end

#countObject

Return the number of symbols in the section



71
72
73
# File 'lib/elf/symboltable.rb', line 71

def count
  symbols.size
end

#defined_symbolsObject

Get a set with all the symbols in the table that are defined, ignoring common, absolute and undefined symbols.



77
78
79
80
81
# File 'lib/elf/symboltable.rb', line 77

def defined_symbols
  symbols.find_all do |sym|
    sym.defined?
  end.to_set
end

#each(&block) ⇒ Object

Iterate over each symbols, replaces section.symbol.each



64
65
66
# File 'lib/elf/symboltable.rb', line 64

def each(&block)
  symbols.each(&block)
end

#load_internalObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elf/symboltable.rb', line 28

def load_internal
  @symbols = []
  @symbol_names = {}
  for i in 1..(@numentries)
    sym = Symbol.new(@file, self, i-1)
    @symbols << sym
    @symbol_names[sym.name] = sym.idx
  end

  return nil
end