class ELFTools::Sections::Section

Base class of sections.

Class methods of {Sections::Section}.

Attributes

header[R]
stream[R]

Public Class Methods

create(header, stream, *args, **kwargs) click to toggle source

Use different class according to header.sh_type. @param [ELFTools::Structs::ELF_Shdr] header Section header. @param [#pos=, read] stream Streaming object. @return [ELFTools::Sections::Section]

Return object dependes on +header.sh_type+.
# File lib/elftools/sections/sections.rb, line 24
def create(header, stream, *args, **kwargs)
  klass = case header.sh_type
          when Constants::SHT_DYNAMIC then DynamicSection
          when Constants::SHT_NULL then NullSection
          when Constants::SHT_NOTE then NoteSection
          when Constants::SHT_RELA, Constants::SHT_REL then RelocationSection
          when Constants::SHT_STRTAB then StrTabSection
          when Constants::SHT_SYMTAB, Constants::SHT_DYNSYM then SymTabSection
          else Section
          end
  klass.new(header, stream, *args, **kwargs)
end
new(header, stream, offset_from_vma: nil, strtab: nil, **_kwargs) click to toggle source

Instantiate a {Section} object. @param [ELFTools::Structs::ELF_Shdr] header

The section header object.

@param [#pos=, read] stream

The streaming object for further dump.

@param [ELFTools::Sections::StrTabSection, Proc] strtab

The string table object. For fetching section names.
If +Proc+ if given, it will call at the first
time access +#name+.

@param [Method] offset_from_vma

The method to get offset of file, given virtual memory address.
# File lib/elftools/sections/section.rb, line 22
def initialize(header, stream, offset_from_vma: nil, strtab: nil, **_kwargs)
  @header = header
  @stream = stream
  @strtab = strtab
  @offset_from_vma = offset_from_vma
end

Public Instance Methods

data() click to toggle source

Fetch data of this section. @return [String] Data.

# File lib/elftools/sections/section.rb, line 44
def data
  stream.pos = header.sh_offset
  stream.read(header.sh_size)
end
name() click to toggle source

Get name of this section. @return [String] The name.

# File lib/elftools/sections/section.rb, line 38
def name
  @name ||= @strtab.call.name_at(header.sh_name)
end
null?() click to toggle source

Is this a null section? @return [Boolean] No it's not.

# File lib/elftools/sections/section.rb, line 51
def null?
  false
end
type() click to toggle source

Return header.sh_type in a simplier way. @return [Integer]

The type, meaning of types are defined in {Constants::SHT}.
# File lib/elftools/sections/section.rb, line 32
def type
  header.sh_type.to_i
end