class Rex::Post::Meterpreter::PacketResponseWaiter

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

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 21
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

Public Instance Methods

notify(response) click to toggle source

Notifies the waiter that the supplied response packet has arrived.

# File lib/rex/post/meterpreter/packet_response_waiter.rb, line 44
def notify(response)
  self.response = response

  if (self.completion_routine)
    self.completion_routine.call(response, self.completion_param)
  else
    self.done = true
  end
end
wait(interval) click to toggle source

Waits for a given time interval for the response packet to arrive. If the interval is -1 we can wait forever.

# File lib/rex/post/meterpreter/packet_response_waiter.rb, line 58
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
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 37
def waiting_for?(packet)
  return (packet.rid == rid)
end