Class: Xploit::Libc

Inherits:
Object
  • Object
show all
Defined in:
lib/xploit/libc.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Libc

Returns a new instance of Libc.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/xploit/libc.rb', line 7

def initialize(path)
  
  @func = {}
  @string = {}
  
  res = `nm -t d -D #{path}`.split("\n")
  res.each do |line|
    offset, name = line.match(/(.+) . (.+)/)[1,2]
    @func[name] = offset.to_i
  end
  
  res = `strings -tx -a -t d #{path}`.split("\n")
  res.each do |line|
    offset, name = line.match(/(.+) (.+)/)[1,2]
    @string[name] = offset.to_i
  end
  
end

Instance Method Details

#string(key) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xploit/libc.rb', line 40

def string(key)
  
  if key.class != String
    raise ArgumentError
  end
  
  if @string.keys.include?(key)
    @string[key]
  else
    raise ArgumentError, "Not found string: #{key}"
  end
  
end

#symbol(key) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/xploit/libc.rb', line 26

def symbol(key)
  
  if key.class != String
    raise ArgumentError
  end
  
  if @func.keys.include?(key)
    @func[key]
  else
    raise ArgumentError, "Not found symbol: #{key}"
  end
  
end