Class: CTF::Rop::RelocatableELF

Inherits:
Object
  • Object
show all
Defined in:
lib/ctf/rop.rb

Direct Known Subclasses

ELF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, offset = 0) ⇒ RelocatableELF

Returns a new instance of RelocatableELF.



7
8
9
10
11
12
13
14
15
16
# File 'lib/ctf/rop.rb', line 7

def initialize(filename, offset = 0)
  @offset = offset
  @elf = ::Metasm::ELF.decode_file(filename)
  @functions = {}
  @elf.symbols.find_all do |s|
    s.name and s.type == 'FUNC' && s.shndx != 'UNDEF' && s.bind == 'GLOBAL'
  end.each do |s|
    @functions[s.name] = s.value
  end
end

Instance Attribute Details

#elfObject (readonly)

Returns the value of attribute elf.



6
7
8
# File 'lib/ctf/rop.rb', line 6

def elf
  @elf
end

#offsetObject (readonly)

Returns the value of attribute offset.



5
6
7
# File 'lib/ctf/rop.rb', line 5

def offset
  @offset
end

Instance Method Details

#function(name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/ctf/rop.rb', line 18

def function(name)
  if @functions.include? name.to_s
    @functions[name.to_s] + offset
  else
    raise RuntimeError.new("No such function #{name}")
  end
end