Class: ProcessRun

Inherits:
Object
  • Object
show all
Defined in:
lib/pwnlib/process.rb

Instance Method Summary collapse

Constructor Details

#initialize(stdin, stdout) ⇒ ProcessRun

Returns a new instance of ProcessRun.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pwnlib/process.rb', line 4

def initialize stdin, stdout
  @stdin = stdin
  @stdout = stdout
  @output_buf = []

  @get_input = true
  @stdout_thr = Thread.new do
    while @get_input
      data = @stdout.readpartial(4096)
      if data
        lines = data.split("\n")
        @output_buf += lines
      end
    end
  end
end

Instance Method Details

#closeObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/pwnlib/process.rb', line 69

def close
  @stdout.flush
  @stdin.flush
  @get_input = false

  output

  @stdin.close
  @stdout.close unless @stdin == @stdout
end

#interactiveObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pwnlib/process.rb', line 53

def interactive
  while 1
    print "\n$> "
    input = gets.chomp

    if input == "exit" or input == "quit"
      break
    end

    @stdin.puts(input)

    sleep 0.1
    output
  end
end

#outputObject



21
22
23
24
25
# File 'lib/pwnlib/process.rb', line 21

def output
  sleep 0.1
  @output_buf.each {|l| puts l; }
  output_clear
end

#output_clearObject



32
33
34
35
# File 'lib/pwnlib/process.rb', line 32

def output_clear
  sleep 0.1
  @output_buf = []
end

#raw_bufferObject



27
28
29
30
# File 'lib/pwnlib/process.rb', line 27

def raw_buffer
  sleep 0.1
  @output_buf
end

#recvObject



37
38
39
40
# File 'lib/pwnlib/process.rb', line 37

def recv
  sleep 0.1
  @output_buf.shift
end

#send(msg) ⇒ Object



42
43
44
45
# File 'lib/pwnlib/process.rb', line 42

def send msg
  @stdin.write msg
  sleep 0.1
end

#write(msg) ⇒ Object



47
48
49
50
51
# File 'lib/pwnlib/process.rb', line 47

def write msg
  File.open("sploit", "w") do |f|
    f.puts msg
  end
end