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:

  • header (ELF_Dyn)

    The dynamic tag header.

  • stream (#pos=, #read)

    Streaming object.

  • strtab (ELFTools::Dynamic::StringTable)

    The string table the names of tags are recorded in.



17
18
19
20
21
# File 'lib/elftools/dynamic/tag.rb', line 17

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

Instance Attribute Details

#headerELFTools::Structs::ELF_Dyn (readonly)

Returns The dynamic tag header.

Returns:



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

def header
  @header
end

#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

#nameString?

Return the name of this tag.

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

Returns:

  • (String, nil)

    The name.



59
60
61
62
63
# File 'lib/elftools/dynamic/tag.rb', line 59

def name
  return nil unless name?

  @strtab.name_at(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.



50
51
52
# File 'lib/elftools/dynamic/tag.rb', line 50

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.



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

def value
  name || header.d_val.to_i
end