class Rex::Post::Meterpreter::PacketResponseWaiter

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

Attributes

completion_param[RW]

Arbitrary argument to {#completion_routine}

@return [Object,nil]

completion_routine[RW]

A callback to be called when this waiter is notified of a packet's arrival. If not nil, this will be called with the response packet as first parameter and {#completion_param} as the second.

@return [Proc,nil]

cond[RW]

@return [ConditionVariable]

mutex[RW]

@return [Mutex]

response[RW]

@return [Packet]

rid[RW]

@return [Fixnum] request ID to wait for

Public Class Methods

new(rid, completion_routine = nil, completion_param = nil) click to toggle source

Initializes a response waiter instance for the supplied request identifier.

# File lib/rex/post/meterpreter/packet_response_waiter.rb, line 45
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.mutex = Mutex.new
    self.cond  = ConditionVariable.new
  end
end

Public Instance Methods

notify(response) click to toggle source

Notifies the waiter that the supplied response packet has arrived.

@param response [Packet] @return [void]

# File lib/rex/post/meterpreter/packet_response_waiter.rb, line 71
def notify(response)
  if (self.completion_routine)
    self.response = response
    self.completion_routine.call(response, self.completion_param)
  else
    self.mutex.synchronize do
      self.response = response
      self.cond.signal
    end
  end
end
wait(interval) click to toggle source

Wait for a given time interval for the response packet to arrive.

@param interval [Fixnum,nil] number of seconds to wait, or nil to wait

forever

@return [Packet,nil] the response, or nil if the interval elapsed before

receiving one
# File lib/rex/post/meterpreter/packet_response_waiter.rb, line 90
def wait(interval)
  interval = nil if interval and interval == -1
  self.mutex.synchronize do
    if self.response.nil?
      self.cond.wait(self.mutex, interval)
    end
  end
  return self.response
end
waiting_for?(packet) click to toggle source

Checks to see if this waiter instance is waiting for the supplied packet based on its request identifier.

# File lib/rex/post/meterpreter/packet_response_waiter.rb, line 62
def waiting_for?(packet)
  return (packet.rid == rid)
end