Class: Rex::Ui::Text::Input::Buffer

Inherits:
Rex::Ui::Text::Input show all
Defined in:
lib/rex/ui/text/input/buffer.rb

Overview

This class implements input against a socket.

Defined Under Namespace

Classes: BufferSock

Instance Attribute Summary

Attributes inherited from Rex::Ui::Text::Input

#config, #eof, #prompt, #prompt_char

Instance Method Summary collapse

Methods inherited from Rex::Ui::Text::Input

#auto_color, #disable_color, #disable_readline, #enable_color, #enable_readline, #intrinsic_shell?, #reset_color, #reset_tab_completion, #supports_readline, #update_prompt

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



27
28
29
30
# File 'lib/rex/ui/text/input/buffer.rb', line 27

def initialize
  @sock = BufferSock.new
  @sock.initialize_abstraction
end

Instance Method Details

#closeObject



32
33
34
# File 'lib/rex/ui/text/input/buffer.rb', line 32

def close
  @sock.cleanup_abstraction
end

#eof?Boolean

Returns whether or not EOF has been reached on stdin.

Returns:

  • (Boolean)


68
69
70
# File 'lib/rex/ui/text/input/buffer.rb', line 68

def eof?
  @sock.lsock.closed?
end

#fdObject

Returns the file descriptor associated with a socket.



75
76
77
# File 'lib/rex/ui/text/input/buffer.rb', line 75

def fd
  return @sock.rsock
end

#getsObject

Wait for a line of input to be read from a socket.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rex/ui/text/input/buffer.rb', line 47

def gets
  # Initialize the line buffer
  line = ''

  # Read data one byte at a time until we see a LF
  while (true)
    break if line.include?("\n")

    # Read another character of input
    char = @sock.rsock.getc

    # Append this character to the string
    line << char
  end

  return line
end

#put(msg, opts = {}) ⇒ Object



40
41
42
# File 'lib/rex/ui/text/input/buffer.rb', line 40

def put(msg, opts={})
  @sock.lsock.write(msg)
end

#sysread(len = 1) ⇒ Object



36
37
38
# File 'lib/rex/ui/text/input/buffer.rb', line 36

def sysread(len = 1)
  @sock.rsock.sysread(len)
end