Class: Rex::Post::Meterpreter::PacketResponseWaiter
- Inherits:
-
Object
- Object
- Rex::Post::Meterpreter::PacketResponseWaiter
- Defined in:
- lib/rex/post/meterpreter/packet_response_waiter.rb
Overview
This class handles waiting for a response to a given request and the subsequent response association.
Instance Attribute Summary collapse
-
#completion_param ⇒ Object?
Arbitrary argument to #completion_routine.
-
#completion_routine ⇒ Proc?
A callback to be called when this waiter is notified of a packet’s arrival.
- #cond ⇒ ConditionVariable
- #mutex ⇒ Mutex
- #response ⇒ Packet
-
#rid ⇒ Integer
Request ID to wait for.
Instance Method Summary collapse
-
#initialize(rid, completion_routine = nil, completion_param = nil) ⇒ PacketResponseWaiter
constructor
Initializes a response waiter instance for the supplied request identifier.
-
#notify(response) ⇒ void
Notifies the waiter that the supplied response packet has arrived.
-
#wait(interval) ⇒ Packet?
Wait for a given time interval for the response packet to arrive.
-
#waiting_for?(packet) ⇒ Boolean
Checks to see if this waiter instance is waiting for the supplied packet based on its request identifier.
Constructor Details
#initialize(rid, completion_routine = nil, completion_param = nil) ⇒ PacketResponseWaiter
Initializes a response waiter instance for the supplied request identifier.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 46 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 |
Instance Attribute Details
#completion_param ⇒ Object?
Arbitrary argument to #completion_routine
21 22 23 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 21 def completion_param @completion_param end |
#completion_routine ⇒ Proc?
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.
28 29 30 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 28 def completion_routine @completion_routine end |
#cond ⇒ ConditionVariable
31 32 33 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 31 def cond @cond end |
#mutex ⇒ Mutex
34 35 36 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 34 def mutex @mutex end |
#response ⇒ Packet
37 38 39 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 37 def response @response end |
#rid ⇒ Integer
Returns request ID to wait for.
40 41 42 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 40 def rid @rid end |
Instance Method Details
#notify(response) ⇒ void
This method returns an undefined value.
Notifies the waiter that the supplied response packet has arrived.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 72 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) ⇒ Packet?
Wait for a given time interval for the response packet to arrive.
91 92 93 94 95 96 97 98 99 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 91 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) ⇒ Boolean
Checks to see if this waiter instance is waiting for the supplied packet based on its request identifier.
63 64 65 |
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 63 def waiting_for?(packet) return (packet.rid == rid) end |