Files
metasploit-gs/lib/rex/ui/text/input/buffer.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
1.3 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2006-09-10 02:21:12 +00:00
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
2007-01-19 08:46:06 +00:00
class BufferSock
2012-05-24 17:10:26 -06:00
include Rex::IO::StreamAbstraction
2011-05-03 05:25:41 +00:00
def write(buf, opts={})
syswrite(buf)
end
2022-07-27 13:11:11 +01:00
def monitor_rsock(*args, **kwargs)
dlog('monitor_rsock: Skipping - functionality not required')
end
2007-01-19 08:46:06 +00:00
end
2013-08-30 16:28:33 -05:00
2007-01-19 08:46:06 +00:00
def initialize
@sock = BufferSock.new
2006-09-10 02:21:12 +00:00
@sock.initialize_abstraction
end
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
def close
@sock.cleanup_abstraction
end
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
def sysread(len = 1)
2008-05-26 08:42:17 +00:00
@sock.rsock.sysread(len)
2006-09-10 02:21:12 +00:00
end
2013-08-30 16:28:33 -05:00
2011-05-03 05:25:41 +00:00
def put(msg, opts={})
2006-09-10 02:21:12 +00:00
@sock.lsock.write(msg)
end
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
#
# Wait for a line of input to be read from a socket.
#
def gets
# Initialize the line buffer
line = ''
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
# Read data one byte at a time until we see a LF
while (true)
break if line.include?("\n")
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
# Read another character of input
char = @sock.rsock.getc
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
# Append this character to the string
line << char
end
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
return line
end
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
#
# Returns whether or not EOF has been reached on stdin.
#
def eof?
@sock.lsock.closed?
end
2013-08-30 16:28:33 -05:00
2006-09-10 02:21:12 +00:00
#
# Returns the file descriptor associated with a socket.
#
def fd
return @sock.rsock
end
end
end
end
end