Class: ElfUtils::Segment::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/elf_utils/segment/base.rb

Instance Method Summary collapse

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

#addrObject



13
14
15
# File 'lib/elf_utils/segment/base.rb', line 13

def addr
  @header.p_vaddr + @offset
end

#alignObject



29
30
31
# File 'lib/elf_utils/segment/base.rb', line 29

def align
  @header.p_align
end

#filesizeObject



21
22
23
# File 'lib/elf_utils/segment/base.rb', line 21

def filesize
  @header.p_filesz
end

#flagsObject



33
34
35
# File 'lib/elf_utils/segment/base.rb', line 33

def flags
  @header.p_flags
end

#inspectObject



41
42
43
# File 'lib/elf_utils/segment/base.rb', line 41

def inspect
  @header.inspect
end

#offsetObject



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

Parameters:

  • addr

    address for section; ‘nil` clears relocation



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

#sectionsObject



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

#sizeObject



25
26
27
# File 'lib/elf_utils/segment/base.rb', line 25

def size
  @header.p_memsz
end

#to_rangeObject



37
38
39
# File 'lib/elf_utils/segment/base.rb', line 37

def to_range
  addr...(addr + size)
end

#typeObject



9
10
11
# File 'lib/elf_utils/segment/base.rb', line 9

def type
  @header.p_type
end