Class: ELFTools::Sections::RelocationSection

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

Overview

Class of note section. Note section records notes

Instance Attribute Summary

Attributes inherited from Section

#header, #stream

Instance Method Summary collapse

Methods inherited from Section

create, #data, #initialize, #name, #null?, #type

Constructor Details

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

Instance Method Details

#each_relocations {|rel| ... } ⇒ Enumerator<ELFTools::Relocation>, Array<ELFTools::Relocation>

Iterate all relocations.

All relocations are lazy loading, the relocation only be created whenever accessing it.

Yield Parameters:

Yield Returns:

  • (void)

Returns:



45
46
47
48
49
50
51
# File 'lib/elftools/sections/relocation_section.rb', line 45

def each_relocations(&block)
  return enum_for(:each_relocations) unless block_given?

  Array.new(num_relocations) do |i|
    relocation_at(i).tap(&block)
  end
end

#num_relocationsInteger

Number of relocations in this section.

Returns:

  • (Integer)

    The number.



20
21
22
# File 'lib/elftools/sections/relocation_section.rb', line 20

def num_relocations
  header.sh_size / header.sh_entsize
end

#rela?Boolean

Is this relocation a RELA or REL type.

Returns:

  • (Boolean)

    If is RELA.



14
15
16
# File 'lib/elftools/sections/relocation_section.rb', line 14

def rela?
  header.sh_type == Constants::SHT_RELA
end

#relocation_at(n) ⇒ ELFTools::Relocation?

Acquire the n-th relocation, 0-based.

relocations are lazy loaded.

Parameters:

  • n (Integer)

    The index.

Returns:



31
32
33
34
# File 'lib/elftools/sections/relocation_section.rb', line 31

def relocation_at(n)
  @relocations ||= LazyArray.new(num_relocations, &method(:create_relocation))
  @relocations[n]
end

#relocationsArray<ELFTools::Relocation>

Simply use #relocations to get all relocations.

Returns:



56
57
58
# File 'lib/elftools/sections/relocation_section.rb', line 56

def relocations
  each_relocations.to_a
end