Module: CTF::SocketWithEcho
- Included in:
- BasicSocket
- Defined in:
- lib/ctf/socket.rb
Instance Attribute Summary collapse
-
#echo ⇒ Object
Returns the value of attribute echo.
-
#echo_color ⇒ Object
Returns the value of attribute echo_color.
-
#echo_input ⇒ Object
Returns the value of attribute echo_input.
-
#echo_output ⇒ Object
Returns the value of attribute echo_output.
Instance Method Summary collapse
-
#expect(pattern, timeout = 9999999) ⇒ Object
TODO: Don’t ignore timeout.
- #gets ⇒ Object
- #interactive!(input = STDIN, output = STDOUT) ⇒ Object
- #read(length = nil, outbuf = '') ⇒ Object
- #write(str) ⇒ Object
Instance Attribute Details
#echo ⇒ Object
Returns the value of attribute echo.
9 10 11 |
# File 'lib/ctf/socket.rb', line 9 def echo @echo end |
#echo_color ⇒ Object
Returns the value of attribute echo_color.
9 10 11 |
# File 'lib/ctf/socket.rb', line 9 def echo_color @echo_color end |
#echo_input ⇒ Object
Returns the value of attribute echo_input.
9 10 11 |
# File 'lib/ctf/socket.rb', line 9 def echo_input @echo_input end |
#echo_output ⇒ Object
Returns the value of attribute echo_output.
9 10 11 |
# File 'lib/ctf/socket.rb', line 9 def echo_output @echo_output end |
Instance Method Details
#expect(pattern, timeout = 9999999) ⇒ Object
TODO: Don’t ignore timeout
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ctf/socket.rb', line 43 def expect(pattern, timeout = 9999999) result = nil loop do if pattern.is_a?(Regexp) break if result && result.match(pattern) else break if result && result.end_with?(pattern) end data = read(1) break unless data result ||= '' result.force_encoding('ASCII-8BIT') result << data end return result unless result if pattern.is_a?(Regexp) [result] + result.match(pattern).to_a[1..-1] else [result] end end |
#gets ⇒ Object
38 39 40 |
# File 'lib/ctf/socket.rb', line 38 def gets expect("\n")[0] end |
#interactive!(input = STDIN, output = STDOUT) ⇒ Object
33 34 35 36 |
# File 'lib/ctf/socket.rb', line 33 def interactive!(input = STDIN, output = STDOUT) @echo = false super input, output end |
#read(length = nil, outbuf = '') ⇒ Object
27 28 29 30 31 |
# File 'lib/ctf/socket.rb', line 27 def read(length = nil, outbuf = '') result = super length, outbuf echo_input_print result if result result end |
#write(str) ⇒ Object
22 23 24 25 |
# File 'lib/ctf/socket.rb', line 22 def write(str) echo_output_print str super str end |