Class: ELFTools::Relocation

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

Overview

A relocation entry.

Can be either a REL or RELA relocation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, stream, machine: nil) ⇒ Relocation

Instantiate a ELFTools::Relocation object.

Parameters:



23
24
25
26
27
# File 'lib/elftools/relocation.rb', line 23

def initialize(header, stream, machine: nil)
  @fields = header.is_a?(Structs::Fields) ? header : Structs::Fields.of(header)
  @stream = stream
  @machine = machine
end

Instance Attribute Details

#stream#pos=, #read (readonly)

Returns Streaming object.

Returns:

  • (#pos=, #read)

    Streaming object.



12
13
14
# File 'lib/elftools/relocation.rb', line 12

def stream
  @stream
end

Instance Method Details

#headerELFTools::Structs::ELF_Rel, ELFTools::Structs::ELF_Rela

The structure the file records this relocation in.

One is built here for a relocation read without it, which is what assigning to a field of one needs and what ELFFile#patches reports the changes of.



35
36
37
# File 'lib/elftools/relocation.rb', line 35

def header
  @fields.struct
end

#symbol_indexInteger

Which symbol this relocation is against, as an index into the symbol table.

Returns:

  • (Integer)

    The symbol index.



42
43
44
# File 'lib/elftools/relocation.rb', line 42

def symbol_index
  sym_and_type.first
end

#symbol_index=(index) ⇒ Object

Sets which symbol this relocation is against.

Examples:

relocation.symbol_index = 3

Parameters:

  • index (Integer)

    The symbol index.

Raises:

  • (ArgumentError)

    If the bits recording it cannot hold it.



58
59
60
# File 'lib/elftools/relocation.rb', line 58

def symbol_index=(index)
  @fields[:r_info] = info_of(Util.fits!(index, index_bits, 'Symbol index'), type)
end

#typeInteger

What this relocation does, which only means something together with the machine of the file. #type_name names it.

Returns:

  • (Integer)

    The relocation type.



49
50
51
# File 'lib/elftools/relocation.rb', line 49

def type
  sym_and_type.last
end

#type=(type) ⇒ Object

Sets what this relocation does.

Examples:

relocation.type = ELFTools::Constants::R::X86_64::R_X86_64_JUMP_SLOT

Parameters:

  • type (Integer)

    The relocation type.

Raises:

  • (ArgumentError)

    If the bits recording it cannot hold it.



67
68
69
# File 'lib/elftools/relocation.rb', line 67

def type=(type)
  @fields[:r_info] = info_of(symbol_index, Util.fits!(type, type_bits, 'Relocation type'))
end

#type_nameString

The name of #type.

Every architecture numbers relocation types on its own, so the name is only known when the machine of the file is.

Examples:

relocation.type_name
#=> 'R_X86_64_JUMP_SLOT'

Returns:

  • (String)

    The name.



79
80
81
# File 'lib/elftools/relocation.rb', line 79

def type_name
  Constants::R.mapping(@machine, type)
end