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