Fixes #2070 by adding finalizers to process, event, thread, registry, and channels.
git-svn-id: file:///home/svn/framework3/trunk@10711 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
881f8e7919
commit
3e09fc30ae
|
@ -141,6 +141,11 @@ class Channel
|
|||
if (cid and client)
|
||||
client.add_channel(self)
|
||||
end
|
||||
ObjectSpace.define_finalizer( self, self.class.finalize(self.client, self.cid) )
|
||||
end
|
||||
|
||||
def self.finalize(client,cid)
|
||||
proc { self._close(client,cid) }
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -262,27 +267,29 @@ class Channel
|
|||
#
|
||||
# Closes the channel.
|
||||
#
|
||||
def _close(addends = nil)
|
||||
if (self.cid == nil)
|
||||
def self._close(client, cid, addends=nil)
|
||||
if (cid == nil)
|
||||
raise IOError, "Channel has been closed.", caller
|
||||
end
|
||||
|
||||
request = Packet.create_request('core_channel_close')
|
||||
|
||||
# Populate the request
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, cid)
|
||||
request.add_tlvs(addends)
|
||||
|
||||
self.client.send_request(request)
|
||||
client.send_request(request)
|
||||
|
||||
# Disassociate this channel instance
|
||||
self.client.remove_channel(self.cid)
|
||||
|
||||
self.cid = nil
|
||||
client.remove_channel(cid)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
def _close(addends = nil)
|
||||
self.class._close(self.client, self.cid, addends)
|
||||
self.cid = nil
|
||||
end
|
||||
#
|
||||
# Enables or disables interactive mode.
|
||||
#
|
||||
|
|
|
@ -22,7 +22,7 @@ module Sys
|
|||
###
|
||||
class EventLog
|
||||
|
||||
class <<self
|
||||
class << self
|
||||
attr_accessor :client
|
||||
end
|
||||
|
||||
|
@ -60,6 +60,11 @@ class EventLog
|
|||
def initialize(hand)
|
||||
self.client = self.class.client
|
||||
self.handle = hand
|
||||
ObjectSpace.define_finalizer( self, self.class.finalize(self.client, self.handle) )
|
||||
end
|
||||
|
||||
def self.finalize(client,handle)
|
||||
proc { self.close(client,handle) }
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -169,16 +174,19 @@ class EventLog
|
|||
end
|
||||
|
||||
#
|
||||
# Return the record number of the oldest event (not necessarily 1).
|
||||
# Close the event log
|
||||
#
|
||||
def close
|
||||
def self.close(client, handle)
|
||||
request = Packet.create_request('stdapi_sys_eventlog_close')
|
||||
|
||||
request.add_tlv(TLV_TYPE_EVENT_HANDLE, self.handle);
|
||||
|
||||
request.add_tlv(TLV_TYPE_EVENT_HANDLE, handle);
|
||||
response = client.send_request(request)
|
||||
return nil
|
||||
end
|
||||
|
||||
# Instance method
|
||||
def close
|
||||
self.class.close(self.client, self.handle)
|
||||
end
|
||||
end
|
||||
|
||||
end end end end end end
|
||||
end end end end end end
|
||||
|
|
|
@ -284,8 +284,14 @@ class Process < Rex::Post::Process
|
|||
'memory' => Rex::Post::Meterpreter::Extensions::Stdapi::Sys::ProcessSubsystem::Memory.new(self),
|
||||
'thread' => Rex::Post::Meterpreter::Extensions::Stdapi::Sys::ProcessSubsystem::Thread.new(self),
|
||||
})
|
||||
|
||||
ObjectSpace.define_finalizer( self, self.class.finalize(self.client, self.handle) )
|
||||
end
|
||||
|
||||
def self.finalize(client,handle)
|
||||
proc { self.close(client,handle) }
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the executable name of the process.
|
||||
#
|
||||
|
@ -303,20 +309,23 @@ class Process < Rex::Post::Process
|
|||
#
|
||||
# Closes the handle to the process that was opened.
|
||||
#
|
||||
def close
|
||||
def self.close(client,handle)
|
||||
request = Packet.create_request('stdapi_sys_process_close')
|
||||
|
||||
request.add_tlv(TLV_TYPE_HANDLE, handle)
|
||||
|
||||
response = client.send_request(request)
|
||||
|
||||
handle = nil;
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
#
|
||||
# Instance method
|
||||
#
|
||||
def close(handle)
|
||||
self.class.close(self.client, handle)
|
||||
end
|
||||
|
||||
#
|
||||
# Block untill this process terminates on the remote side.
|
||||
# Block until this process terminates on the remote side.
|
||||
# By default we choose not to allow a packet responce timeout to
|
||||
# occur as we may be waiting indefinatly for the process to terminate.
|
||||
#
|
||||
|
|
|
@ -126,4 +126,4 @@ protected
|
|||
|
||||
end
|
||||
|
||||
end; end; end; end; end; end; end
|
||||
end; end; end; end; end; end; end
|
||||
|
|
|
@ -29,6 +29,12 @@ class RegistryKey
|
|||
self.base_key = base_key
|
||||
self.perm = perm
|
||||
self.hkey = hkey
|
||||
|
||||
ObjectSpace.define_finalizer( self, self.class.finalize(self.client, self.hkey) )
|
||||
end
|
||||
|
||||
def self.finalize(client,hkey)
|
||||
proc { self.close(client,hkey) }
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -99,12 +105,17 @@ class RegistryKey
|
|||
# Closes the open key. This must be called if the registry
|
||||
# key was opened.
|
||||
#
|
||||
def close()
|
||||
if (self.hkey != nil)
|
||||
return self.client.sys.registry.close_key(hkey)
|
||||
def self.close(client, hkey)
|
||||
if hkey != nil
|
||||
return client.sys.registry.close_key(hkey)
|
||||
end
|
||||
|
||||
return false
|
||||
return false
|
||||
end
|
||||
|
||||
# Instance method for the same
|
||||
def close()
|
||||
self.class.close(self.client, self.hkey)
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -34,6 +34,11 @@ class Thread < Rex::Post::Thread
|
|||
self.process = process
|
||||
self.handle = handle
|
||||
self.tid = tid
|
||||
ObjectSpace.define_finalizer( self, self.class.finalize(self.process.client, self.handle) )
|
||||
end
|
||||
|
||||
def self.finalize(client,handle)
|
||||
proc { self.close(client,handle) }
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -153,17 +158,18 @@ class Thread < Rex::Post::Thread
|
|||
#
|
||||
# Closes the thread handle.
|
||||
#
|
||||
def close
|
||||
def self.close(client, handle)
|
||||
request = Packet.create_request('stdapi_sys_process_thread_close')
|
||||
|
||||
request.add_tlv(TLV_TYPE_THREAD_HANDLE, handle)
|
||||
|
||||
process.client.send_request(request)
|
||||
|
||||
client.send_request(request)
|
||||
handle = nil
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
# Instance method
|
||||
def self.close
|
||||
self.class.close(self.process.client, self.handle)
|
||||
end
|
||||
|
||||
attr_reader :process, :handle, :tid # :nodoc:
|
||||
protected
|
||||
|
@ -171,4 +177,4 @@ protected
|
|||
|
||||
end
|
||||
|
||||
end; end; end; end; end; end
|
||||
end; end; end; end; end; end
|
||||
|
|
Loading…
Reference in New Issue