Class: ELFTools::Dynamic::Tag

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

Overview

A tag class.

Constant Summary collapse

TYPE_WITH_NAME =

Some dynamic have name.

[Constants::DT_NEEDED,
Constants::DT_SONAME,
Constants::DT_RPATH,
Constants::DT_RUNPATH].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, stream, strtab) ⇒ Tag

Instantiate a ELFTools::Dynamic::Tag object.

Parameters:



20
21
22
23
24
# File 'lib/elftools/dynamic/tag.rb', line 20

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

Instance Attribute Details

#stream#pos=, #read (readonly)

Returns Streaming object.

Returns:

  • (#pos=, #read)

    Streaming object.



10
11
12
# File 'lib/elftools/dynamic/tag.rb', line 10

def stream
  @stream
end

Instance Method Details

#headerELFTools::Structs::ELF_Dyn

The structure the file records this tag in.

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

Returns:



32
33
34
# File 'lib/elftools/dynamic/tag.rb', line 32

def header
  @fields.struct
end

#nameString?

Return the name of this tag.

Only tags with name would return a name. Others would return nil.

Returns:

  • (String, nil)

    The name.



81
82
83
84
85
# File 'lib/elftools/dynamic/tag.rb', line 81

def name
  return nil unless name?

  @strtab.name_at(@fields[:d_val])
end

#name?Boolean

Is this tag has a name?

The criteria here is if this tag's type is in TYPE_WITH_NAME.

Returns:

  • (Boolean)

    Is this tag has a name.



72
73
74
# File 'lib/elftools/dynamic/tag.rb', line 72

def name?
  TYPE_WITH_NAME.include?(type)
end

#typeInteger

What kind of tag this is, which Constants::DT names.

Examples:

dynamic.tag_by_type(:needed).type == ELFTools::Constants::DT_NEEDED
#=> true

Returns:

  • (Integer)

    The type.



41
42
43
# File 'lib/elftools/dynamic/tag.rb', line 41

def type
  @fields[:d_tag]
end

#valueInteger, String

Return the content of this tag records.

For normal tags, this method just return header.d_val. For tags with header.d_val in meaning of string offset (e.g. DT_NEEDED), this method would return the string it specified. Tags with type in TYPE_WITH_NAME are those tags with name.

Examples:

dynamic = elf.segment_by_type(:dynamic)
dynamic.tag_by_type(:init).value
#=> 4195600 # 0x400510
dynamic.tag_by_type(:needed).value
#=> 'libc.so.6'

Returns:

  • (Integer, String)

    The content this tag records.



64
65
66
# File 'lib/elftools/dynamic/tag.rb', line 64

def value
  name || @fields[:d_val]
end