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, #enable_color, #reset_color, #reset_tab_completion, #update_prompt

Constructor Details

#initializeBidirectionalPipe

Returns a new instance of BidirectionalPipe.


12
13
14
15
16
17
18
19
20
21
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 12

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


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

def input
  @input
end

#outputObject

Wrappers for shell methods


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

def output
  @output
end

#promptObject

Wrappers for shell methods


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

def prompt
  @prompt
end

Instance Method Details

#closeObject

Wrappers for the pipe_input methods


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

def close
  @pipe_input.close
end

#create_subscriber(id = nil) ⇒ Object


35
36
37
38
39
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 35

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


41
42
43
44
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 41

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

#eof?Boolean

Returns:

  • (Boolean)

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

def eof?
  @pipe_input.eof?
end

#fdObject


128
129
130
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 128

def fd
  @pipe_input.fd
end

#flushObject


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

def flush
end

#getsObject


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

def gets
  @pipe_input.gets
end

#has_subscriber?(id) ⇒ Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 31

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

#intrinsic_shell?Boolean

Returns:

  • (Boolean)

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

def intrinsic_shell?
  true
end

#pgetsObject


150
151
152
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 150

def pgets
  gets
end

#pipe_inputObject


23
24
25
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 23

def pipe_input
  @pipe_input
end

67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 67

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

79
80
81
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 79

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

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

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

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

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

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

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

100
101
102
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 100

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

#put(msg) ⇒ Object


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

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

#read_subscriber(id) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 55

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

  return '' if output.nil?

  buf = output.buf

  output.reset

  buf
end

#remove_subscriber(id) ⇒ Object


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

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

#supports_color?Boolean

Returns:

  • (Boolean)

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

def supports_color?
  false
end

#supports_readlineObject


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

def supports_readline
  false
end

#sysread(len = 1) ⇒ Object


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

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

#write_input(buf) ⇒ Object


51
52
53
# File 'lib/rex/ui/text/bidirectional_pipe.rb', line 51

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