Class: ELFTools::Dynamic::HashTable::Gnu

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

Overview

The table DT_GNU_HASH points at.

It only indexes the defined symbols a file exports under a name, and the symbols before #symndx are by construction not among them, so a name it does not lead to may still be in the symbol table.

Constant Summary collapse

HEADER =

The header the table starts with.

Structs::ELF_GnuHash

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.



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/elftools/dynamic/hash_table.rb', line 146

def index_of(name, &block)
  return if header.nbuckets.to_i.zero? || header.maskwords.to_i.zero?

  h = hash_of(name)
  return unless may_index?(h)

  n = word_at(buckets + ((h % header.nbuckets.to_i) * 4))
  return if n.zero? || n < symndx

  walk(n, h, &block)
end

#num_symbolsInteger

How far the table reaches, i.e. the highest index it indexes plus one.

Returns:

  • (Integer)

    The number.



128
129
130
131
132
133
134
135
# File 'lib/elftools/dynamic/hash_table.rb', line 128

def num_symbols
  last = Array.new(header.nbuckets.to_i) { |i| word_at(buckets + (i * 4)) }.max || 0
  return symndx if last < symndx

  n = last - symndx
  n += 1 while word_at(chain + (n * 4)).even?
  symndx + n + 1
end