From 77688d73b4340f72116b2aec60c97deabf06e8a0 Mon Sep 17 00:00:00 2001 From: Spoon M Date: Mon, 30 May 2005 23:46:34 +0000 Subject: [PATCH] weee git-svn-id: file:///home/svn/incoming/trunk@2537 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/module/platform.rb | 2 +- lib/msf/core/module/platform_list.rb | 28 +++++++++++++++++----- lib/msf/core/module/platform_list.rb.ut.rb | 11 +++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/msf/core/module/platform.rb b/lib/msf/core/module/platform.rb index 2b5ff9dad8..9137e5806c 100644 --- a/lib/msf/core/module/platform.rb +++ b/lib/msf/core/module/platform.rb @@ -17,7 +17,7 @@ class Msf::Module::Platform # def self.find_platform(str) # remove any whitespace and downcase - str = str.sub(' ', '').downcase + str = str.gsub(' ', '').downcase mod = Msf::Module::Platform diff --git a/lib/msf/core/module/platform_list.rb b/lib/msf/core/module/platform_list.rb index dbac7d317b..a880b7e6ce 100644 --- a/lib/msf/core/module/platform_list.rb +++ b/lib/msf/core/module/platform_list.rb @@ -10,12 +10,12 @@ require 'Msf/Core/Module/Platform' class Msf::Module::PlatformList - attr_accessor :modules + attr_accessor :platforms def initialize(*args) - self.modules = [ ] + self.platforms = [ ] args.each { |a| if a.kind_of?(String) - modules << Msf::Module::Platform.find_platform(a) + platforms << Msf::Module::Platform.find_platform(a) elsif a.kind_of?(Range) b = Msf::Module::Platform.find_platform(a.begin) e = Msf::Module::Platform.find_platform(a.end) @@ -23,17 +23,33 @@ class Msf::Module::PlatformList children = Msf::Module::Platform._find_children(b.superclass) r = (b::Rank .. e::Rank) children.each { |c| - modules << c if r.include?(c::Rank) + platforms << c if r.include?(c::Rank) } else - modules << a + platforms << a end } end def names - modules.map { |m| m.name.split('::')[3 .. -1].join(' ') } + platforms.map { |m| m.name.split('::')[3 .. -1].join(' ') } + end + + # Do I support plist (do I support all of they support?) + def supports?(plist) + plist.platforms.each { |pl| + supported = false + platforms.each { |p| + if p >= pl + supported = true + break + end + } + return false if !supported + } + + return true end end diff --git a/lib/msf/core/module/platform_list.rb.ut.rb b/lib/msf/core/module/platform_list.rb.ut.rb index 9d03401b2b..8035eb36a8 100644 --- a/lib/msf/core/module/platform_list.rb.ut.rb +++ b/lib/msf/core/module/platform_list.rb.ut.rb @@ -15,7 +15,7 @@ class Msf::Module::PlatformList::UnitTest < Test::Unit::TestCase assert_equal( [ Msf::Module::Platform::Windows::X86::XP::SP0, Msf::Module::Platform::Windows::X86::XP::SP1 - ], Msf::Module::PlatformList.new('winxpsp0' .. 'winxpsp1').modules + ], Msf::Module::PlatformList.new('winxpsp0' .. 'winxpsp1').platforms ) end @@ -24,6 +24,13 @@ class Msf::Module::PlatformList::UnitTest < Test::Unit::TestCase end def test_all - assert_equal( [ Msf::Module::Platform ], Msf::Module::PlatformList.new('').modules) + assert_equal( [ Msf::Module::Platform ], Msf::Module::PlatformList.new('').platforms) + end + + def test_supports + l1 = Msf::Module::PlatformList.new('win') + l2 = Msf::Module::PlatformList.new('win xp sp0', 'win xp sp2') + assert_equal( true, l1.supports?(l2) ) + assert_equal( false, l2.supports?(l1) ) end end