Class: ELFTools::Sections::Section
- Inherits:
-
Object
- Object
- ELFTools::Sections::Section
- Defined in:
- lib/elftools/sections/section.rb
Overview
Base class of sections.
Direct Known Subclasses
DynamicSection, NoteSection, NullSection, RelocationSection, StrTabSection, SymTabSection
Instance Attribute Summary collapse
-
#header ⇒ ELFTools::Structs::ELF_Shdr
readonly
Section header.
-
#stream ⇒ #pos=, #read
readonly
Streaming object.
Class Method Summary collapse
-
.create(header, stream, *args, **kwargs) ⇒ ELFTools::Sections::Section
Use different class according to
header.sh_type
.
Instance Method Summary collapse
-
#data ⇒ String
Fetch data of this section.
-
#initialize(header, stream, offset_from_vma: nil, strtab: nil, **_kwargs) ⇒ Section
constructor
Instantiate a Section object.
-
#name ⇒ String
Get name of this section.
-
#null? ⇒ Boolean
Is this a null section?.
-
#type ⇒ Integer
Return
header.sh_type
in a simplier way.
Constructor Details
#initialize(header, stream, offset_from_vma: nil, strtab: nil, **_kwargs) ⇒ Section
Instantiate a ELFTools::Sections::Section object.
22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#header ⇒ ELFTools::Structs::ELF_Shdr (readonly)
Returns Section header.
8 9 10 |
# File 'lib/elftools/sections/section.rb', line 8 def header @header end |
#stream ⇒ #pos=, #read (readonly)
Returns Streaming object.
9 10 11 |
# File 'lib/elftools/sections/section.rb', line 9 def stream @stream end |
Class Method Details
.create(header, stream, *args, **kwargs) ⇒ ELFTools::Sections::Section
Use different class according to header.sh_type
.
24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Method Details
#data ⇒ String
Fetch data of this section.
44 45 46 47 |
# File 'lib/elftools/sections/section.rb', line 44 def data stream.pos = header.sh_offset stream.read(header.sh_size) end |
#name ⇒ String
Get name of this section.
38 39 40 |
# File 'lib/elftools/sections/section.rb', line 38 def name @name ||= @strtab.call.name_at(header.sh_name) end |
#null? ⇒ Boolean
Is this a null section?
51 52 53 |
# File 'lib/elftools/sections/section.rb', line 51 def null? false end |
#type ⇒ Integer
Return header.sh_type
in a simplier way.
32 33 34 |
# File 'lib/elftools/sections/section.rb', line 32 def type header.sh_type.to_i end |