made ModuleManager a ModuleSet so a global snapshot can be gotten at

git-svn-id: file:///home/svn/incoming/trunk@2507 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-05-22 07:58:02 +00:00
parent 4fd9efdc9f
commit e69dece1b0
1 changed files with 25 additions and 22 deletions

View File

@ -13,7 +13,7 @@ module Msf
# #
### ###
class ModuleSet < Hash class ModuleSet < Hash
def initialize(type) def initialize(type = nil)
self.module_type = type self.module_type = type
self.full_names = {} self.full_names = {}
self.ambiguous_names = {} self.ambiguous_names = {}
@ -28,7 +28,7 @@ class ModuleSet < Hash
def create(name) def create(name)
# If the supplied name is known-ambiguous, prevent its creation # If the supplied name is known-ambiguous, prevent its creation
if (ambiguous_names[name]) if (ambiguous_names[name])
raise(NameError.new("The supplied module name is ambiguous", name), raise(NameError.new("The supplied module name is ambiguous with: #{ambiguous_names[name].join}", name),
caller) caller)
end end
@ -66,11 +66,16 @@ class ModuleSet < Hash
} }
end end
attr_reader :module_type, :full_names
protected
# Adds a module with a supplied short name, full name, and associated # Adds a module with a supplied short name, full name, and associated
# module class # module class
def add_module(short_name, full_name, module_class) def add_module(short_name, full_name, module_class)
if (self[short_name]) if (self[short_name])
ambiguous_names << short_name ambiguous_names[short_name] = [] if (!ambiguous_names[short_name])
ambiguous_names[short_name] << full_name
else else
self[short_name] = module_class self[short_name] = module_class
end end
@ -78,10 +83,6 @@ class ModuleSet < Hash
full_names[full_name] = module_class full_names[full_name] = module_class
end end
attr_reader :module_type, :full_names
protected
attr_writer :module_type, :full_names attr_writer :module_type, :full_names
attr_accessor :ambiguous_names attr_accessor :ambiguous_names
attr_accessor :mod_arch_hash, :mod_platform_hash attr_accessor :mod_arch_hash, :mod_platform_hash
@ -104,18 +105,19 @@ end
# - add unload support # - add unload support
# #
### ###
class ModuleManager < Array class ModuleManager < ModuleSet
def initialize() def initialize()
self.module_paths = [] self.module_paths = []
self.module_history = {} self.module_history = {}
self.module_history_mtime = {} self.module_history_mtime = {}
self.modules_by_type = {} self.module_sets = {}
self.modules = []
MODULE_TYPES.each { |type| MODULE_TYPES.each { |type|
self.modules_by_type[type] = ModuleSet.new(type) self.module_sets[type] = ModuleSet.new(type)
} }
super
end end
# #
@ -124,27 +126,27 @@ class ModuleManager < Array
# Returns the set of loaded encoder module classes # Returns the set of loaded encoder module classes
def encoders def encoders
return modules_by_type[MODULE_ENCODER] return module_sets[MODULE_ENCODER]
end end
# Returns the set of loaded exploit module classes # Returns the set of loaded exploit module classes
def exploits def exploits
return modules_by_type[MODULE_EXPLOIT] return module_sets[MODULE_EXPLOIT]
end end
# Returns the set of loaded nop module classes # Returns the set of loaded nop module classes
def nops def nops
return modules_by_type[MODULE_NOPS] return module_sets[MODULE_NOPS]
end end
# Returns the set of loaded payload module classes # Returns the set of loaded payload module classes
def payloads def payloads
return modules_by_type[MODULE_PAYLOAD] return module_sets[MODULE_PAYLOAD]
end end
# Returns the set of loaded recon module classes # Returns the set of loaded recon module classes
def recon def recon
return modules_by_type[MODULE_RECON] return module_sets[MODULE_RECON]
end end
# #
@ -299,21 +301,22 @@ protected
def on_module_load(type, mod) def on_module_load(type, mod)
# Extract the module name information # Extract the module name information
mod_full_name = mod.to_s.gsub('::', '_') mod_full_name = mod.to_s.gsub('::', '_')
mod_full_name.sub!(/^Msf_(.*?)_/, '') mod_full_name.sub!(/^Msf_/, '')
mod_short_name = mod_full_name mod_short_name = mod_full_name
if ((md = mod_full_name.match(/_(.*)$/))) if ((md = mod_full_name.match(/^(.*)_(.*)$/)))
mod_short_name = md[1] mod_short_name = md[2]
end end
# Add the module class to the list of modules and add it to the # Add the module class to the list of modules and add it to the
# type separated set of module classes # type separated set of module classes
modules << mod add_module(mod_short_name, mod_full_name, mod)
modules_by_type[type].add_module(mod_short_name, mod_full_name, mod)
module_sets[type].add_module(mod_short_name, mod_full_name, mod)
end end
attr_accessor :modules, :modules_by_type attr_accessor :modules, :module_sets
attr_accessor :module_paths attr_accessor :module_paths
attr_accessor :module_history, :module_history_mtime attr_accessor :module_history, :module_history_mtime