Class: ELFTools::Dynamic::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/elftools/dynamic.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, str_offset) ⇒ Tag

Instantiate a ELFTools::Dynamic::Tag object.

Parameters:

  • header (ELF_Dyn)

    The dynamic tag header.

  • stream (#pos=, #read)

    Streaming object.

  • str_offset (Method)

    Call this method to get the string offset related to file.



129
130
131
132
133
# File 'lib/elftools/dynamic.rb', line 129

def initialize(header, stream, str_offset)
  @header = header
  @stream = stream
  @str_offset = str_offset
end

Instance Attribute Details

#headerELFTools::Structs::ELF_Dyn (readonly)

Returns The dynamic tag header.

Returns:



120
121
122
# File 'lib/elftools/dynamic.rb', line 120

def header
  @header
end

#stream#pos=, #read (readonly)

Returns Streaming object.

Returns:

  • (#pos=, #read)

    Streaming object.



121
122
123
# File 'lib/elftools/dynamic.rb', line 121

def stream
  @stream
end

Instance Method Details

#nameString?

Return the name of this tag.

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

Returns:

  • (String, nil)

    The name.



171
172
173
174
175
# File 'lib/elftools/dynamic.rb', line 171

def name
  return nil unless name?

  Util.cstring(stream, @str_offset.call + header.d_val.to_i)
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.



162
163
164
# File 'lib/elftools/dynamic.rb', line 162

def name?
  TYPE_WITH_NAME.include?(header.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.



154
155
156
# File 'lib/elftools/dynamic.rb', line 154

def value
  name || header.d_val.to_i
end