Class: ELFTools::Sections::VersionSection

Inherits:
Section
  • Object
show all
Defined in:
lib/elftools/sections/version_section.rb

Overview

Class of the section recording which version each symbol binds to.

This section is usually named .gnu.version, and holds an index per symbol of the table its sh_link names, the very indices the DT_VERSYM tag points at.

Instance Attribute Summary

Attributes inherited from Section

#header, #stream

Instance Method Summary collapse

Methods inherited from Section

#allocated?, create, #data, #executable?, #initialize, #name, #null?, #type, #writable?

Constructor Details

This class inherits a constructor from ELFTools::Sections::Section

Instance Method Details

#num_versionsInteger

How many symbols the section records a version for.

Returns:

  • (Integer)

    The number.



15
16
17
# File 'lib/elftools/sections/version_section.rb', line 15

def num_versions
  header.sh_size.to_i / entry_size
end

#version_at(n) ⇒ Integer?

What the +n+-th symbol records as its version, which is an index into the versions a file needs or defines, with the highest bit marking a version the symbol asks for by name rather than the default one.

Examples:

section.version_at(1)
#=> 2

Parameters:

  • n (Integer)

    The symbol index.

Returns:

  • (Integer, nil)

    The index, nil if the section records none for it.



27
28
29
30
31
32
# File 'lib/elftools/sections/version_section.rb', line 27

def version_at(n)
  return if n.negative? || n >= num_versions

  stream.pos = header.sh_offset.to_i + (n * entry_size)
  stream.read(entry_size).unpack1(header.class.self_endian == :big ? 'S>' : 'S<')
end