Class: ELFTools::Sections::RelocationSection
- Defined in:
- lib/elftools/sections/relocation_section.rb
Overview
Class of relocation section. Usually for sections .rel.* and .rela.*, which record relocations in ELF file.
Instance Attribute Summary
Attributes inherited from Section
Instance Method Summary collapse
-
#each_relocation {|rel| ... } ⇒ Enumerator<ELFTools::Relocation>, Array<ELFTools::Relocation>
(also: #each_relocations)
Iterate all relocations.
-
#initialize(header, stream, machine: nil, **_kwargs) ⇒ RelocationSection
constructor
Instantiate a RelocationSection object.
-
#num_relocations ⇒ Integer
Number of relocations in this section.
-
#rela? ⇒ Boolean
Is this relocation a RELA or REL type.
-
#relocation_at(n) ⇒ ELFTools::Relocation?
Acquire the +n+-th relocation, 0-based.
-
#relocations ⇒ Array<ELFTools::Relocation>
Simply use #relocations to get all relocations.
Methods inherited from Section
create, #data, #name, #null?, #type
Constructor Details
#initialize(header, stream, machine: nil, **_kwargs) ⇒ RelocationSection
Instantiate a ELFTools::Sections::RelocationSection object.
22 23 24 25 |
# File 'lib/elftools/sections/relocation_section.rb', line 22 def initialize(header, stream, machine: nil, **_kwargs) @machine = machine super end |
Instance Method Details
#each_relocation {|rel| ... } ⇒ Enumerator<ELFTools::Relocation>, Array<ELFTools::Relocation> Also known as: each_relocations
Iterate all relocations.
All relocations are lazy loading, the relocation only be created whenever accessing it.
60 61 62 63 64 65 66 |
# File 'lib/elftools/sections/relocation_section.rb', line 60 def each_relocation(&block) return enum_for(:each_relocation) unless block_given? Array.new(num_relocations) do |i| relocation_at(i).tap(&block) end end |
#num_relocations ⇒ Integer
Number of relocations in this section.
35 36 37 |
# File 'lib/elftools/sections/relocation_section.rb', line 35 def num_relocations header.sh_size / header.sh_entsize end |
#rela? ⇒ Boolean
Is this relocation a RELA or REL type.
29 30 31 |
# File 'lib/elftools/sections/relocation_section.rb', line 29 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.
46 47 48 49 |
# File 'lib/elftools/sections/relocation_section.rb', line 46 def relocation_at(n) @relocations ||= LazyArray.new(num_relocations, &method(:create_relocation)) @relocations[n] end |
#relocations ⇒ Array<ELFTools::Relocation>
Simply use #relocations to get all relocations.
74 75 76 |
# File 'lib/elftools/sections/relocation_section.rb', line 74 def relocations each_relocation.to_a end |