Class: ELFTools::Dynamic::HashTable::SysV

Inherits:
HashTable
  • Object
show all
Defined in:
lib/elftools/dynamic/hash_table.rb

Overview

The table DT_HASH points at, which the System V ABI defines.

A chain of it belongs to every symbol, so it is the one table that records how many there are.

Constant Summary collapse

HEADER =

The header the table starts with.

Structs::ELF_Hash

Instance Method Summary collapse

Instance Method Details

#index_of(name) {|index| ... } ⇒ Integer?

The index a name sits at.

A bucket leads to a chain of the indices whose names hash alike, so the block is what tells them apart.

Parameters:

  • name (String)

    The name.

Yield Parameters:

  • index (Integer)

    An index whose name hashes like name.

Yield Returns:

  • (Boolean)

    Whether the symbol there is the one wanted.

Returns:

  • (Integer, nil)

    The index, nil if the table does not lead to the name.



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/elftools/dynamic/hash_table.rb', line 78

def index_of(name)
  return if header.nbucket.to_i.zero?

  n = word_at(buckets + ((hash_of(name) % header.nbucket.to_i) * 4))
  # Index zero is the undefined symbol, so it ends a chain instead of
  # belonging to one.
  while n.positive? && n < num_symbols
    return n if yield(n)

    n = word_at(chain + (n * 4))
  end
end

#num_symbolsInteger

How many symbols the table is built over, which it records outright.

Returns:

  • (Integer)

    The number.



65
66
67
# File 'lib/elftools/dynamic/hash_table.rb', line 65

def num_symbols
  header.nchain.to_i
end