Class: Rex::Ui::Text::BidirectionalPipe

Inherits:
Input
  • Object
show all
Defined in:
lib/rex/ui/text/bidirectional_pipe.rb

Instance Attribute Summary collapse

Attributes inherited from Input

#config, #eof, #prompt_char

Instance Method Summary collapse

Methods inherited from Input

#auto_color, #disable_color, #disable_readline, #enable_color, #enable_readline, #reset_color, #reset_tab_completion, #update_prompt

Constructor Details

#initializeBidirectionalPipe

Returns a new instance of BidirectionalPipe.



9
10
11
12
13
14
15
16
17
18
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 9

def initialize
  @subscribers_out = {}
  @subscribers_ref = {}
  @subscribers_idx = 0
  @pipe_input = Rex::Ui::Text::Input::Buffer.new

  # We are the shell, the input, and the output
  self.output = self
  self.input  = self
end

Instance Attribute Details

#inputObject

Wrappers for shell methods



133
134
135
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 133

def input
  @input
end

#outputObject

Wrappers for shell methods



133
134
135
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 133

def output
  @output
end

#promptObject

Wrappers for shell methods



133
134
135
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 133

def prompt
  @prompt
end

Instance Method Details

#closeObject

Wrappers for the pipe_input methods



105
106
107
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 105

def close
  @pipe_input.close
end

#create_subscriber(id = nil) ⇒ Object



32
33
34
35
36
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 32

def create_subscriber(id=nil)
  id ||= (@subscribers_idx += 1).to_s
  @subscribers_out[id] = Rex::Ui::Text::Output::Buffer.new
  return id
end

#create_subscriber_proc(id = nil, &block) ⇒ Object



38
39
40
41
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 38

def create_subscriber_proc(id=nil, &block)
  id = create_subscriber(id)
  @subscribers_ref[id] = block
end

#eof?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 121

def eof?
  @pipe_input.eof?
end

#fdObject



125
126
127
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 125

def fd
  @pipe_input.fd
end

#flushObject



90
91
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 90

def flush
end

#getsObject



117
118
119
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 117

def gets
  @pipe_input.gets
end

#has_subscriber?(id) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 28

def has_subscriber?(id)
  @subscribers_out.has_key?(id)
end

#intrinsic_shell?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 135

def intrinsic_shell?
  true
end

#pgetsObject



147
148
149
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 147

def pgets
  gets
end

#pipe_inputObject



20
21
22
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 20

def pipe_input
  @pipe_input
end


64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 64

def print(msg='')
  @subscribers_out.each_pair { |id, buf|
    begin
      @subscribers_ref[id] ? @subscribers_ref[id].call(msg) : buf.print(msg)
    rescue ::Exception => e
      # $stderr.puts "Error handling subscriber #{id}: #{e} #{e.backtrace.inspect}"
      raise e
    end
  }
  msg
end


76
77
78
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 76

def print_error(msg='')
  print_line('[-] ' + msg)
end


86
87
88
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 86

def print_good(msg='')
  print_line('[+] ' + msg)
end


82
83
84
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 82

def print_line(msg='')
  print(msg + "\n")
end


93
94
95
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 93

def print_status(msg='')
  print_line('[*] ' + msg)
end


97
98
99
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 97

def print_warning(msg='')
  print_line('[!] ' + msg)
end

#put(msg) ⇒ Object



113
114
115
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 113

def put(msg)
  @pipe_input.put(msg)
end

#read_subscriber(id) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 52

def read_subscriber(id)
  output = @subscribers_out[id]

  return '' if output.nil?

  buf = output.buf

  output.reset

  buf
end

#remove_subscriber(id) ⇒ Object



43
44
45
46
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 43

def remove_subscriber(id)
  @subscribers_out.delete(id)
  @subscribers_ref.delete(id)
end

#supports_color?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 143

def supports_color?
  false
end

#supports_readlineObject



139
140
141
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 139

def supports_readline
  false
end

#sysread(len = 1) ⇒ Object



109
110
111
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 109

def sysread(len = 1)
  @pipe_input.sysread(len)
end

#write_input(buf) ⇒ Object



48
49
50
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 48

def write_input(buf)
  @pipe_input.put(buf)
end