Module: ELFTools::Dynamic
- Includes:
- Symbols
- Included in:
- Sections::DynamicSection, Segments::DynamicSegment
- Defined in:
- lib/elftools/dynamic.rb,
lib/elftools/dynamic/tag.rb,
lib/elftools/dynamic/symbols.rb,
lib/elftools/dynamic/hash_table.rb,
lib/elftools/dynamic/string_table.rb
Overview
This module can only be included by Sections::DynamicSection and Segments::DynamicSegment because methods here assume some attributes exist.
Define common methods for dynamic sections and dynamic segments.
Defined Under Namespace
Modules: Symbols Classes: HashTable, StringTable, Tag
Instance Method Summary collapse
-
#each_tag {|tag| ... } ⇒ Enumerator<ELFTools::Dynamic::Tag>, Array<ELFTools::Dynamic::Tag>
(also: #each_tags)
Iterate all tags.
-
#relocations ⇒ Array<ELFTools::Relocation>
The relocations the tags point at.
-
#tag_at(n) ⇒ ELFTools::Dynamic::Tag
Get the +n+-th tag.
-
#tag_by_type(type) ⇒ ELFTools::Dynamic::Tag
Get a tag of specific type.
-
#tags ⇒ Array<ELFTools::Dynamic::Tag>
Use #tags to get all tags.
-
#tags_by_type(type) ⇒ Array<ELFTools::Dynamic::Tag>
Get tags of specific type.
Methods included from Symbols
#each_symbol, #num_symbols, #symbol_at, #symbol_by_name, #symbols
Instance Method Details
#each_tag {|tag| ... } ⇒ Enumerator<ELFTools::Dynamic::Tag>, Array<ELFTools::Dynamic::Tag> Also known as:
This method assume the following methods already exist:
header
tag_startIterate all tags.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/elftools/dynamic.rb', line 31 def each_tag(&block) return enum_for(:each_tag) unless block_given? arr = [] 0.step do |i| tag = tag_at(i).tap(&block) arr << tag break if tag.header.d_tag == ELFTools::Constants::DT_NULL end arr end |
#relocations ⇒ Array<ELFTools::Relocation>
The relocations the tags point at.
Two tables record them: the one DT_REL or DT_RELA names, and the one
DT_JMPREL names, whose entries are of the kind DT_PLTREL names.
130 131 132 |
# File 'lib/elftools/dynamic.rb', line 130 def relocations @relocations ||= relocation_tables.flat_map { |start, size, rela| read_relocations(start, size, rela) } end |
#tag_at(n) ⇒ ELFTools::Dynamic::Tag
This method assume the following methods already exist:
header
tag_startWe cannot do bound checking of n here since the only way to get size
of tags is calling tags.size.
Get the +n+-th tag.
Tags are lazy loaded.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/elftools/dynamic.rb', line 106 def tag_at(n) return if n.negative? @tag_at_map ||= {} return @tag_at_map[n] if @tag_at_map[n] dyn = Structs::ELF_Dyn.new(endian:) dyn.elf_class = header.elf_class stream.pos = tag_start + n * dyn.num_bytes dyn.offset = stream.pos @tag_at_map[n] = Tag.new(dyn.read(stream), stream, string_table) end |
#tag_by_type(type) ⇒ ELFTools::Dynamic::Tag
Get a tag of specific type.
77 78 79 80 |
# File 'lib/elftools/dynamic.rb', line 77 def tag_by_type(type) type = Util.to_constant(Constants::DT, type) each_tag.find { |tag| tag.header.d_tag == type } end |
#tags ⇒ Array<ELFTools::Dynamic::Tag>
Use #tags to get all tags.
49 50 51 |
# File 'lib/elftools/dynamic.rb', line 49 def @tags ||= each_tag.to_a end |
#tags_by_type(type) ⇒ Array<ELFTools::Dynamic::Tag>
Get tags of specific type.
89 90 91 92 |
# File 'lib/elftools/dynamic.rb', line 89 def (type) type = Util.to_constant(Constants::DT, type) each_tag.select { |tag| tag.header.d_tag == type } end |