class ELFTools::Dynamic::Tag

A tag class.

Constants

TYPE_WITH_NAME

Some dynamic have name.

Attributes

header[R]
stream[R]

Public Class Methods

new(header, stream, str_offset) click to toggle source

Instantiate a {ELFTools::Dynamic::Tag} object. @param [ELF_Dyn] header The dynamic tag header. @param [#pos=, read] stream Streaming object. @param [Method] str_offset

Call this method to get the string offset related
to file.
# File lib/elftools/dynamic.rb, line 129
def initialize(header, stream, str_offset)
  @header = header
  @stream = stream
  @str_offset = str_offset
end

Public Instance Methods

name() click to toggle source

Return the name of this tag.

Only tags with name would return a name. Others would return nil. @return [String, nil] The name.

# 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?() click to toggle source

Is this tag has a name?

The criteria here is if this tag's type is in {TYPE_WITH_NAME}. @return [Boolean] Is this tag has a name.

# File lib/elftools/dynamic.rb, line 162
def name?
  TYPE_WITH_NAME.include?(header.d_tag)
end
value() click to toggle source

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. @return [Integer, String] The content this tag records. @example

dynamic = elf.segment_by_type(:dynamic)
dynamic.tag_by_type(:init).value
#=> 4195600 # 0x400510
dynamic.tag_by_type(:needed).value
#=> 'libc.so.6'
# File lib/elftools/dynamic.rb, line 154
def value
  name || header.d_val.to_i
end