Sha256: 73aa9e5ee80f5bf089bba57100f4a29f52a0860cba2a8fcebfa2b078b5b9547e

Contents?: true

Size: 1.61 KB

Versions: 41

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby

require 'timeout'
require 'thread'

module Rex
module Post
module Meterpreter

###
#
# This class handles waiting for a response to a given request
# and the subsequent response association.
#
###
class PacketResponseWaiter

	#
	# Initializes a response waiter instance for the supplied request
	# identifier.
	#
	def initialize(rid, completion_routine = nil, completion_param = nil)
		self.rid      = rid.dup
		self.response = nil

		if (completion_routine)
			self.completion_routine = completion_routine
			self.completion_param   = completion_param
		else
			self.done  = false
		end
	end

	#
	# Checks to see if this waiter instance is waiting for the supplied
	# packet based on its request identifier.
	#
	def waiting_for?(packet)
		return (packet.rid == rid)
	end

	#
	# Notifies the waiter that the supplied response packet has arrived.
	#
	def notify(response)
		self.response = response

		if (self.completion_routine)
			self.completion_routine.call(response, self.completion_param)
		else
			self.done = true
		end
	end

	#
	# Waits for a given time interval for the response packet to arrive.
	# If the interval is -1 we can wait forever.
	#
	def wait(interval)
		if( interval and interval == -1 )
			while(not self.done)
				::IO.select(nil, nil, nil, 0.1)
			end
		else
			begin
				Timeout.timeout(interval) {
					while(not self.done)
						::IO.select(nil, nil, nil, 0.1)
					end
				}
			rescue Timeout::Error
				self.response = nil
			end
		end
		return self.response
	end

	attr_accessor :rid, :done, :response # :nodoc:
	attr_accessor :completion_routine, :completion_param # :nodoc:
end

end; end; end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.63 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.54 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.53 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.52 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.51 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.50 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.49 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.48 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.47 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.46 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.44 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.43 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.42 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.41 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.40 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.39 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.38 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.37 lib/rex/post/meterpreter/packet_response_waiter.rb
librex-0.0.36 lib/rex/post/meterpreter/packet_response_waiter.rb