made each_module better
git-svn-id: file:///home/svn/incoming/trunk@2506 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
4e3e97d83d
commit
4fd9efdc9f
|
@ -98,7 +98,7 @@ protected
|
|||
|
||||
# Sets the modules unsupplied info fields to their default values
|
||||
def set_defaults
|
||||
{
|
||||
self.module_info = {
|
||||
'Name' => 'No module name',
|
||||
'Description' => 'No module description',
|
||||
'Version' => '0',
|
||||
|
@ -106,11 +106,7 @@ protected
|
|||
'Arch' => nil,
|
||||
'Platform' => nil,
|
||||
'Ref' => nil
|
||||
}.each_pair { |field, value|
|
||||
if (module_info[field] == nil)
|
||||
module_info[field] = value
|
||||
end
|
||||
}
|
||||
}.update(self.module_info)
|
||||
end
|
||||
|
||||
attr_accessor :module_info
|
||||
|
|
|
@ -14,9 +14,14 @@ module Msf
|
|||
###
|
||||
class ModuleSet < Hash
|
||||
def initialize(type)
|
||||
self.module_type = type
|
||||
self.full_names = {}
|
||||
self.ambiguous_names = {}
|
||||
self.module_type = type
|
||||
self.full_names = {}
|
||||
self.ambiguous_names = {}
|
||||
|
||||
# Hashes that convey the supported architectures and platforms for a
|
||||
# given module
|
||||
self.mod_arch_hash = {}
|
||||
self.mod_platform_hash = {}
|
||||
end
|
||||
|
||||
# Create an instance of the supplied module by its name
|
||||
|
@ -37,8 +42,28 @@ class ModuleSet < Hash
|
|||
end
|
||||
|
||||
# Enumerates each module class in the set
|
||||
def each_module(&block)
|
||||
return each_value(&block)
|
||||
def each_module(opts = {}, &block)
|
||||
each_value { |mod|
|
||||
# Filter out incompatible architectures
|
||||
if (opts['arch'])
|
||||
if (!mod_arch_hash[mod])
|
||||
mod_arch_hash[mod] = mod.new.arch
|
||||
end
|
||||
|
||||
next if (mod_arch_hash[mod].include?(opts['arch']) == false)
|
||||
end
|
||||
|
||||
# Filter out incompatible platforms
|
||||
if (opts['platform'])
|
||||
if (!mod_platform_hash[mod])
|
||||
mod_platform_hash[mod] = mod.new.platform
|
||||
end
|
||||
|
||||
next if (mod_platform_hash[mod].include?(opts['platform']) == false)
|
||||
end
|
||||
|
||||
block.call(mod)
|
||||
}
|
||||
end
|
||||
|
||||
# Adds a module with a supplied short name, full name, and associated
|
||||
|
@ -59,6 +84,7 @@ protected
|
|||
|
||||
attr_writer :module_type, :full_names
|
||||
attr_accessor :ambiguous_names
|
||||
attr_accessor :mod_arch_hash, :mod_platform_hash
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -13,8 +13,13 @@ framework = Msf::Framework.new
|
|||
framework.modules.add_module_path('/home/mmiller/msf/rubyhacks/prototype/Modules')
|
||||
|
||||
|
||||
framework.encoders.each { |name, mod|
|
||||
puts "got encoder #{name} => #{mod}"
|
||||
framework.encoders.each_module { |mod|
|
||||
puts "default: got encoder #{mod}"
|
||||
}
|
||||
|
||||
framework.encoders.each_module(
|
||||
'arch' => Msf::ARCH_IA32) { |mod|
|
||||
puts "arch filter: got encoder #{mod}"
|
||||
}
|
||||
|
||||
encoder = framework.encoders.create('JmpCallAdditive')
|
||||
|
|
Loading…
Reference in New Issue