diff --git a/lib/msf/core/module/platform.rb b/lib/msf/core/module/platform.rb index 83e9fbf397..c16f7cf998 100644 --- a/lib/msf/core/module/platform.rb +++ b/lib/msf/core/module/platform.rb @@ -67,13 +67,13 @@ class Msf::Module::Platform # Finds all inherited children from a given module. # def self.find_children - constants.map { |c| - const_get(c) - }.delete_if { |m| - !m.kind_of?(Class) || ! (m < self) - }.sort { |a, b| - a::Rank <=> b::Rank - } + @subclasses ||= [] + @subclasses.sort_by { |a| a::Rank } + end + + def self.inherited(subclass) + @subclasses ||= [] + @subclasses << subclass end # @@ -431,4 +431,4 @@ class Msf::Module::Platform Rank = 100 Alias = "php" end -end \ No newline at end of file +end diff --git a/lib/msf/core/module/platform_list.rb b/lib/msf/core/module/platform_list.rb index f558b8daab..f5c4a0c7f4 100644 --- a/lib/msf/core/module/platform_list.rb +++ b/lib/msf/core/module/platform_list.rb @@ -83,10 +83,7 @@ class Msf::Module::PlatformList # Symbolic check to see if this platform list represents 'all' platforms. # def all? - names.each do |name| - return true if name == '' - end - return false + names.include? '' end # @@ -119,39 +116,30 @@ class Msf::Module::PlatformList # used for say, building a payload from a stage and stager # def &(plist) - list1 = plist.platforms - list2 = platforms - total = [ ] - - # If either list has all in it, just merge the two - if (plist.all? or all?) - return list1.dup.concat(list2) + # If either list has all in it, return the other one + if plist.all? + return self + elsif self.all? + return plist end - # - # um, yeah, expand the lowest depth (like highest superset) - # each time and then do another intersection, keep doing - # this until no one has any children anymore... - # + list1 = plist.platforms + list2 = platforms + total = [] loop do # find any intersections inter = list1 & list2 # remove them from the two sides - list1 = list1 - inter - list2 = list2 - inter + list1 -= inter + list2 -= inter # add them to the total total += inter - if list1.empty? || list2.empty? - break - end + break if list1.empty? || list2.empty? - begin - list1, list2 = _intersect_expand(list1, list2) - rescue ::RuntimeError - break - end + # try to expand to subclasses to refine the match + break if ! _intersect_expand(list1, list2) end return Msf::Module::PlatformList.new(*total) @@ -165,21 +153,28 @@ class Msf::Module::PlatformList # been intersected with each other.. # def _intersect_expand(list1, list2) - (list1 + list2).sort { |a, b| - a.name.split('::').length <=> b.name.split('::').length }. - each { |m| - children = m.find_children - if !children.empty? - if list1.include?(m) - return [ list1 - [ m ] + children, list2 ] - else - return [ list1, list2 - [ m ] + children ] - end - end + # abort if no shared prefix is found between l1 and l2 + # shortcircuits [Windows] & [Linux] without going + # through XP => SP2 => DE + ln1 = list1.map { |c| c.name } + ln2 = list2.map { |c| c.name } + return if not ln1.find { |n1| + ln2.find { |n2| n1[0, n2.length] == n2[0, n1.length] } } - # XXX what's a better exception to throw here? - raise RuntimeError, "No more expansion possible", caller + (list1 + list2).sort { |a, b| + # find the superest class in both lists + a.name.count(':') <=> b.name.count(':') + }.find { |m| + # which has children + children = m.find_children + next if children.empty? + # replace this class in its list by its children + l = list1.include?(m) ? list1 : list2 + l.delete m + l.concat children + true + } end end \ No newline at end of file diff --git a/lib/msf/core/module_manager.rb b/lib/msf/core/module_manager.rb index e54ebea0b6..aaf96ba585 100644 --- a/lib/msf/core/module_manager.rb +++ b/lib/msf/core/module_manager.rb @@ -54,11 +54,7 @@ class ModuleSet < Hash # throwing an exception. # def get_hash_val(name) - begin - return self.fetch(name) - rescue IndexError - return nil - end + fetch(name) if has_key?(name) end # @@ -902,10 +898,7 @@ protected usable = false begin - usable = added.is_usable - # If no method is defined, assume that this module is usable. - rescue NoMethodError - usable = true + usable = respond_to?(:is_usable) ? added.is_usable : true rescue elog("Exception caught during is_usable check: #{$!}") end diff --git a/lib/msf/core/payload.rb b/lib/msf/core/payload.rb index 6902529c33..d57d97c238 100644 --- a/lib/msf/core/payload.rb +++ b/lib/msf/core/payload.rb @@ -78,6 +78,8 @@ class Payload < Msf::Module end @staged = true + else + @staged = false end # Update the module info hash with the connection type diff --git a/lib/rex/peparsey/pebase.rb b/lib/rex/peparsey/pebase.rb index 3e398644f4..a8d5b8bb89 100644 --- a/lib/rex/peparsey/pebase.rb +++ b/lib/rex/peparsey/pebase.rb @@ -928,7 +928,6 @@ class PeBase end attr_reader :code_offset, :unwind_op, :op_info, :frame_offset - private attr_writer :code_offset, :unwind_op, :op_info, :frame_offset end @@ -973,9 +972,6 @@ class PeBase attr_reader :begin_address, :end_address, :unwind_info_address attr_reader :unwind_info - - private - attr_writer :unwind_info end diff --git a/lib/rex/sync/event.rb b/lib/rex/sync/event.rb index 79dc41fb3c..fae7667384 100644 --- a/lib/rex/sync/event.rb +++ b/lib/rex/sync/event.rb @@ -64,7 +64,7 @@ class Event begin # XXX: we need to replace this code # continuations slow down YARV - require "continuation" + require "continuation" if not defined? callcc rescue ::LoadError end