Class: ELFTools::RelativeRelocations

Inherits:
Object
  • Object
show all
Defined in:
lib/elftools/relative_relocations.rb

Overview

The relocations a file packs into a bitmap instead of recording one by one.

Almost every relocation of a file that is loaded anywhere only adds the load bias to a word, which takes an entry recording an address, a type that is the same every time, and an addend that repeats what the word already holds. A file may pack them instead, as a run of addresses in ascending order, and spend a bit rather than an entry on each.

An even entry is an address, and relocates the word there. An odd entry is a bitmap of the words following the last address, a set bit relocating one of them. Nothing records a type, because every relocation here is the one Constants::R.relative names.

Instance Method Summary collapse

Constructor Details

#initialize(stream, bytes, elf_class:, endian:, machine:) ⇒ RelativeRelocations

Instantiate a ELFTools::RelativeRelocations object.

Parameters:

  • stream (#pos=, #read)

    Streaming object.

  • bytes (Range<Integer>)

    The file offsets the table occupies.

  • elf_class (Integer)

    32 or 64, the width of an entry.

  • endian (Symbol)

    :little or :big.

  • machine (Integer)

    The machine of the file, which decides what these relocations are of.



28
29
30
31
32
33
34
# File 'lib/elftools/relative_relocations.rb', line 28

def initialize(stream, bytes, elf_class:, endian:, machine:)
  @stream = stream
  @bytes = bytes
  @elf_class = elf_class
  @endian = endian
  @machine = machine
end

Instance Method Details

#to_aArray<ELFTools::Relocation>

The relocations the table packs.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elftools/relative_relocations.rb', line 39

def to_a
  type = Constants::R.relative(@machine)
  addresses.map do |address, from|
    rel = Structs::ELF_Rel.new(endian: @endian, offset: from)
    rel.elf_class = @elf_class
    rel.r_offset = address
    relocation = Relocation.new(rel, @stream, machine: @machine)
    # Through the relocation, so that the type is laid out in +r_info+ the
    # way the machine lays it out.
    relocation.type = type if type
    relocation
  end
end