Class: ElfUtils::Segment::Base
- Inherits:
-
Object
- Object
- ElfUtils::Segment::Base
- Defined in:
- lib/elf_utils/segment/base.rb
Instance Method Summary collapse
- #addr ⇒ Object
- #align ⇒ Object
- #filesize ⇒ Object
- #flags ⇒ Object
-
#initialize(file, header) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
- #offset ⇒ Object
-
#relocate(addr) ⇒ Object
relocate this segement and all sections within it.
- #sections ⇒ Object
- #size ⇒ Object
- #to_range ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(file, header) ⇒ Base
Returns a new instance of Base.
3 4 5 6 7 |
# File 'lib/elf_utils/segment/base.rb', line 3 def initialize(file, header) @file = file @header = header @offset = 0 end |
Instance Method Details
#addr ⇒ Object
13 14 15 |
# File 'lib/elf_utils/segment/base.rb', line 13 def addr @header.p_vaddr + @offset end |
#align ⇒ Object
29 30 31 |
# File 'lib/elf_utils/segment/base.rb', line 29 def align @header.p_align end |
#filesize ⇒ Object
21 22 23 |
# File 'lib/elf_utils/segment/base.rb', line 21 def filesize @header.p_filesz end |
#flags ⇒ Object
33 34 35 |
# File 'lib/elf_utils/segment/base.rb', line 33 def flags @header.p_flags end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/elf_utils/segment/base.rb', line 41 def inspect @header.inspect end |
#offset ⇒ Object
17 18 19 |
# File 'lib/elf_utils/segment/base.rb', line 17 def offset @header.p_offset end |
#relocate(addr) ⇒ Object
relocate this segement and all sections within it
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/elf_utils/segment/base.rb', line 57 def relocate(addr) if addr.nil? sections.relocate(nil) @offset = 0 return end # calculate the offset, then relocate the sections by that offset offset = addr - @header.p_vaddr sections.each do |section| section.relocate(offset, relative: true) end @offset = offset end |
#sections ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/elf_utils/segment/base.rb', line 45 def sections a = addr...(addr + size) @file.sections.select do |section| next unless section.alloc? a.include?(section.addr) || a.include?(section.addr + section.size - 1) end end |
#size ⇒ Object
25 26 27 |
# File 'lib/elf_utils/segment/base.rb', line 25 def size @header.p_memsz end |
#to_range ⇒ Object
37 38 39 |
# File 'lib/elf_utils/segment/base.rb', line 37 def to_range addr...(addr + size) end |
#type ⇒ Object
9 10 11 |
# File 'lib/elf_utils/segment/base.rb', line 9 def type @header.p_type end |