Class: ElfUtils::Section::Base

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

Instance Attribute Summary collapse

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/section/base.rb', line 3

def initialize(file, header)
  @file = file
  @header = header
  @offset = 0
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



8
9
10
# File 'lib/elf_utils/section/base.rb', line 8

def header
  @header
end

Instance Method Details

#addrObject



22
23
24
# File 'lib/elf_utils/section/base.rb', line 22

def addr
  @header.sh_addr + @offset
end

#alloc?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/elf_utils/section/base.rb', line 38

def alloc?
  flags.include?(:alloc)
end

#bytesObject



18
19
20
# File 'lib/elf_utils/section/base.rb', line 18

def bytes
  @file.pread(@header.sh_size, @header.sh_offset)
end

#flagsObject



30
31
32
# File 'lib/elf_utils/section/base.rb', line 30

def flags
  @header.sh_flags
end

#inspectObject



14
15
16
# File 'lib/elf_utils/section/base.rb', line 14

def inspect
  "<%p %s %p 0x%08x %p>" % [self.class, name, @header.sh_type, addr, flags]
end

#load_segmentObject

get the load_segment this section belongs to



73
74
75
# File 'lib/elf_utils/section/base.rb', line 73

def load_segment
  @file.load_segments.find { |s| s.sections.include?(self) }
end

#nameObject



10
11
12
# File 'lib/elf_utils/section/base.rb', line 10

def name
  @file.shstrtab[@header.sh_name]
end

#offsetObject



34
35
36
# File 'lib/elf_utils/section/base.rb', line 34

def offset
  @header.sh_offset
end

#relocate(addr, relative: false) ⇒ Object

relocate this section

Parameters:

  • addr

    address for section; ‘nil` clears relocation



57
58
59
60
61
62
63
64
65
# File 'lib/elf_utils/section/base.rb', line 57

def relocate(addr, relative: false)
  @offset = if addr.nil?
    0
  elsif relative
    addr
  else
    addr - @header.sh_addr
  end
end

#relocation_offsetObject

return the relocation offset for this section



68
69
70
# File 'lib/elf_utils/section/base.rb', line 68

def relocation_offset
  @offset
end

#sizeObject



26
27
28
# File 'lib/elf_utils/section/base.rb', line 26

def size
  @header.sh_size
end

#symbol(name) ⇒ Object



50
51
52
# File 'lib/elf_utils/section/base.rb', line 50

def symbol(name)
  @file.symtab.symbols.find { |s| s.section == self && s.name == name }
end

#symbolsObject



46
47
48
# File 'lib/elf_utils/section/base.rb', line 46

def symbols
  @file.symtab.symbols.select { |s| s.section == self }
end

#to_rangeObject



42
43
44
# File 'lib/elf_utils/section/base.rb', line 42

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