Class: Rex::IO::BidirectionalPipe

Inherits:
Ui::Text::Input show all
Defined in:
lib/rex/io/bidirectional_pipe.rb

Constant Summary

Constants included from Ui::Text::Color

Ui::Text::Color::AnsiAttributes

Instance Attribute Summary collapse

Attributes inherited from Ui::Text::Input

#config, #eof, #prompt_char

Instance Method Summary collapse

Methods inherited from Ui::Text::Input

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

Methods included from Ui::Text::Color

#ansi, #colorize, #do_colorize, #reset_color, #substitute_colors

Constructor Details

#initializeBidirectionalPipe

Returns a new instance of BidirectionalPipe.



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

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



137
138
139
# File 'lib/rex/io/bidirectional_pipe.rb', line 137

def input
  @input
end

#outputObject

Wrappers for shell methods



137
138
139
# File 'lib/rex/io/bidirectional_pipe.rb', line 137

def output
  @output
end

#promptObject

Wrappers for shell methods



137
138
139
# File 'lib/rex/io/bidirectional_pipe.rb', line 137

def prompt
  @prompt
end

Instance Method Details

#closeObject

Wrappers for the pipe_input methods



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

def close
  @pipe_input.close
end

#create_subscriber(id = nil) ⇒ Object



34
35
36
37
38
# File 'lib/rex/io/bidirectional_pipe.rb', line 34

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



40
41
42
43
# File 'lib/rex/io/bidirectional_pipe.rb', line 40

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

#eof?Boolean

Returns:

  • (Boolean)


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

def eof?
  @pipe_input.eof?
end

#fdObject



129
130
131
# File 'lib/rex/io/bidirectional_pipe.rb', line 129

def fd
  @pipe_input.fd
end

#flushObject



94
95
# File 'lib/rex/io/bidirectional_pipe.rb', line 94

def flush
end

#getsObject



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

def gets
  @pipe_input.gets
end

#has_subscriber?(id) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/rex/io/bidirectional_pipe.rb', line 30

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

#intrinsic_shell?Boolean

Returns:

  • (Boolean)


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

def intrinsic_shell?
  true
end

#pgetsObject



151
152
153
# File 'lib/rex/io/bidirectional_pipe.rb', line 151

def pgets
  gets
end

#pipe_inputObject



22
23
24
# File 'lib/rex/io/bidirectional_pipe.rb', line 22

def pipe_input
  @pipe_input
end


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

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


90
91
92
# File 'lib/rex/io/bidirectional_pipe.rb', line 90

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


78
79
80
# File 'lib/rex/io/bidirectional_pipe.rb', line 78

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


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

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


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

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


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

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


101
102
103
# File 'lib/rex/io/bidirectional_pipe.rb', line 101

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

#put(msg) ⇒ Object



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

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

#read_subscriber(id) ⇒ Object



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

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

  return '' if output.nil?

  buf = output.buf

  output.reset

  buf
end

#remove_subscriber(id) ⇒ Object



45
46
47
48
# File 'lib/rex/io/bidirectional_pipe.rb', line 45

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

#supports_color?Boolean

Returns:

  • (Boolean)


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

def supports_color?
  false
end

#supports_readlineObject



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

def supports_readline
  false
end

#sysread(len = 1) ⇒ Object



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

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

#write_input(buf) ⇒ Object



50
51
52
# File 'lib/rex/io/bidirectional_pipe.rb', line 50

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