Module: ELFTools::Dynamic
- Included in:
- Sections::DynamicSection, Segments::DynamicSegment
- Defined in:
- lib/elftools/dynamic.rb
Overview
Note:
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
Classes: Tag
Instance Method Summary collapse
-
#each_tags {|tag| ... } ⇒ Enumerator<ELFTools::Dynamic::Tag>, Array<ELFTools::Dynamic::Tag>
Iterate all tags.
-
#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.
Instance Method Details
#each_tags {|tag| ... } ⇒ Enumerator<ELFTools::Dynamic::Tag>, Array<ELFTools::Dynamic::Tag>
Note:
This method assume the following methods already exist:
header
tag_start
Iterate all tags.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/elftools/dynamic.rb', line 21 def (&block) return enum_for(:each_tags) 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 |
#tag_at(n) ⇒ ELFTools::Dynamic::Tag
Note:
This method assume the following methods already exist:
header
tag_start
Note:
We 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.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/elftools/dynamic.rb', line 93 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, method(:str_offset)) end |
#tag_by_type(type) ⇒ ELFTools::Dynamic::Tag
Get a tag of specific type.
64 65 66 67 |
# File 'lib/elftools/dynamic.rb', line 64 def tag_by_type(type) type = Util.to_constant(Constants::DT, type) .find { |tag| tag.header.d_tag == type } end |
#tags ⇒ Array<ELFTools::Dynamic::Tag>
Use #tags to get all tags.
36 37 38 |
# File 'lib/elftools/dynamic.rb', line 36 def @tags ||= .to_a end |
#tags_by_type(type) ⇒ Array<ELFTools::Dynamic::Tag>
Get tags of specific type.
76 77 78 79 |
# File 'lib/elftools/dynamic.rb', line 76 def (type) type = Util.to_constant(Constants::DT, type) .select { |tag| tag.header.d_tag == type } end |