2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2006-09-10 02:21:12 +00:00
|
|
|
require 'rex/ui'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Ui
|
|
|
|
module Text
|
|
|
|
|
|
|
|
require 'rex/io/stream_abstraction'
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements input against a socket.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Input::Buffer < Rex::Ui::Text::Input
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
class BufferSock
|
|
|
|
include Rex::IO::StreamAbstraction
|
|
|
|
def write(buf, opts={})
|
|
|
|
syswrite(buf)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@sock = BufferSock.new
|
|
|
|
@sock.initialize_abstraction
|
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
@sock.cleanup_abstraction
|
|
|
|
end
|
|
|
|
|
|
|
|
def sysread(len = 1)
|
|
|
|
@sock.rsock.sysread(len)
|
|
|
|
end
|
|
|
|
|
|
|
|
def put(msg, opts={})
|
|
|
|
@sock.lsock.write(msg)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Wait for a line of input to be read from a socket.
|
|
|
|
#
|
|
|
|
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
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns whether or not EOF has been reached on stdin.
|
|
|
|
#
|
|
|
|
def eof?
|
|
|
|
@sock.lsock.closed?
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the file descriptor associated with a socket.
|
|
|
|
#
|
|
|
|
def fd
|
|
|
|
return @sock.rsock
|
|
|
|
end
|
2006-09-10 02:21:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2010-12-18 03:00:26 +00:00
|
|
|
end
|