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, RelativeRelocationSection, RelocationSection, StrTabSection, SymTabSection, VersionDefinitionSection, VersionNeedSection, VersionSection
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
-
#allocated? ⇒ Boolean
Does this section take memory while the file runs?.
-
#data ⇒ String
Fetch data of this section.
-
#executable? ⇒ Boolean
Is this section executed?.
-
#initialize(header, stream, offset_from_vma: nil, section_name_table: 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_typein a simpler way. -
#writable? ⇒ Boolean
Is this section written to while the file runs?.
Constructor Details
#initialize(header, stream, offset_from_vma: nil, section_name_table: 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, section_name_table: nil, **_kwargs) @header = header @stream = stream @section_name_table = section_name_table @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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/elftools/sections/sections.rb', line 28 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_RELR then RelativeRelocationSection when Constants::SHT_GNU_versym then VersionSection when Constants::SHT_GNU_verneed then VersionNeedSection when Constants::SHT_GNU_verdef then VersionDefinitionSection 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
#allocated? ⇒ Boolean
Does this section take memory while the file runs?
The ones that do are what a file is loaded by, the rest being what is recorded about it, its symbol names and its debugging information among them.
76 77 78 |
# File 'lib/elftools/sections/section.rb', line 76 def allocated? header.sh_flags.allbits?(Constants::SHF_ALLOC) end |
#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 |
#executable? ⇒ Boolean
Is this section executed?
63 64 65 |
# File 'lib/elftools/sections/section.rb', line 63 def executable? header.sh_flags.allbits?(Constants::SHF_EXECINSTR) end |
#name ⇒ String
Get name of this section.
38 39 40 |
# File 'lib/elftools/sections/section.rb', line 38 def name @name ||= @section_name_table.call.name_at(header.sh_name) end |
#null? ⇒ Boolean
Is this a null section?
82 83 84 |
# File 'lib/elftools/sections/section.rb', line 82 def null? false end |
#type ⇒ Integer
Return header.sh_type in a simpler way.
32 33 34 |
# File 'lib/elftools/sections/section.rb', line 32 def type header.sh_type.to_i end |