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

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.


23
24
25
26
# File 'lib/rex/ui/text/input/buffer.rb', line 23

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

Instance Method Details

#closeObject


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

def close
  @sock.cleanup_abstraction
end

#eof?Boolean

Returns whether or not EOF has been reached on stdin.

Returns:

  • (Boolean)

64
65
66
# File 'lib/rex/ui/text/input/buffer.rb', line 64

def eof?
  @sock.lsock.closed?
end

#fdObject

Returns the file descriptor associated with a socket.


71
72
73
# File 'lib/rex/ui/text/input/buffer.rb', line 71

def fd
  return @sock.rsock
end

#getsObject

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


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rex/ui/text/input/buffer.rb', line 43

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


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

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

#sysread(len = 1) ⇒ Object


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

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