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:



21
22
23
24
25
# File 'lib/elftools/relocation.rb', line 21

def initialize(header, stream, machine: nil)
  @header = header
  @stream = stream
  @machine = machine
end

Instance Attribute Details

#headerELFTools::Structs::ELF_Rel, ELFTools::Structs::ELF_Rela (readonly)

Returns Rel(a) header.



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

def header
  @header
end

#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

#symbol_indexInteger

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

Returns:

  • (Integer)

    The symbol index.



30
31
32
# File 'lib/elftools/relocation.rb', line 30

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.



46
47
48
# File 'lib/elftools/relocation.rb', line 46

def symbol_index=(index)
  header.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.



37
38
39
# File 'lib/elftools/relocation.rb', line 37

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.



55
56
57
# File 'lib/elftools/relocation.rb', line 55

def type=(type)
  header.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.



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

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