Performance and debugging improvements from Yoann Guillot
git-svn-id: file:///home/svn/framework3/trunk@6712 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
20b232b9d5
commit
e27691c543
|
@ -67,13 +67,13 @@ class Msf::Module::Platform
|
||||||
# Finds all inherited children from a given module.
|
# Finds all inherited children from a given module.
|
||||||
#
|
#
|
||||||
def self.find_children
|
def self.find_children
|
||||||
constants.map { |c|
|
@subclasses ||= []
|
||||||
const_get(c)
|
@subclasses.sort_by { |a| a::Rank }
|
||||||
}.delete_if { |m|
|
end
|
||||||
!m.kind_of?(Class) || ! (m < self)
|
|
||||||
}.sort { |a, b|
|
def self.inherited(subclass)
|
||||||
a::Rank <=> b::Rank
|
@subclasses ||= []
|
||||||
}
|
@subclasses << subclass
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -83,10 +83,7 @@ class Msf::Module::PlatformList
|
||||||
# Symbolic check to see if this platform list represents 'all' platforms.
|
# Symbolic check to see if this platform list represents 'all' platforms.
|
||||||
#
|
#
|
||||||
def all?
|
def all?
|
||||||
names.each do |name|
|
names.include? ''
|
||||||
return true if name == ''
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -119,39 +116,30 @@ class Msf::Module::PlatformList
|
||||||
# used for say, building a payload from a stage and stager
|
# used for say, building a payload from a stage and stager
|
||||||
#
|
#
|
||||||
def &(plist)
|
def &(plist)
|
||||||
|
# If either list has all in it, return the other one
|
||||||
|
if plist.all?
|
||||||
|
return self
|
||||||
|
elsif self.all?
|
||||||
|
return plist
|
||||||
|
end
|
||||||
|
|
||||||
list1 = plist.platforms
|
list1 = plist.platforms
|
||||||
list2 = platforms
|
list2 = platforms
|
||||||
total = []
|
total = []
|
||||||
|
|
||||||
# If either list has all in it, just merge the two
|
|
||||||
if (plist.all? or all?)
|
|
||||||
return list1.dup.concat(list2)
|
|
||||||
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...
|
|
||||||
#
|
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
# find any intersections
|
# find any intersections
|
||||||
inter = list1 & list2
|
inter = list1 & list2
|
||||||
# remove them from the two sides
|
# remove them from the two sides
|
||||||
list1 = list1 - inter
|
list1 -= inter
|
||||||
list2 = list2 - inter
|
list2 -= inter
|
||||||
# add them to the total
|
# add them to the total
|
||||||
total += inter
|
total += inter
|
||||||
|
|
||||||
if list1.empty? || list2.empty?
|
break if list1.empty? || list2.empty?
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
# try to expand to subclasses to refine the match
|
||||||
list1, list2 = _intersect_expand(list1, list2)
|
break if ! _intersect_expand(list1, list2)
|
||||||
rescue ::RuntimeError
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Msf::Module::PlatformList.new(*total)
|
return Msf::Module::PlatformList.new(*total)
|
||||||
|
@ -165,21 +153,28 @@ class Msf::Module::PlatformList
|
||||||
# been intersected with each other..
|
# been intersected with each other..
|
||||||
#
|
#
|
||||||
def _intersect_expand(list1, list2)
|
def _intersect_expand(list1, list2)
|
||||||
(list1 + list2).sort { |a, b|
|
# abort if no shared prefix is found between l1 and l2
|
||||||
a.name.split('::').length <=> b.name.split('::').length }.
|
# shortcircuits [Windows] & [Linux] without going
|
||||||
each { |m|
|
# through XP => SP2 => DE
|
||||||
children = m.find_children
|
ln1 = list1.map { |c| c.name }
|
||||||
if !children.empty?
|
ln2 = list2.map { |c| c.name }
|
||||||
if list1.include?(m)
|
return if not ln1.find { |n1|
|
||||||
return [ list1 - [ m ] + children, list2 ]
|
ln2.find { |n2| n1[0, n2.length] == n2[0, n1.length] }
|
||||||
else
|
|
||||||
return [ list1, list2 - [ m ] + children ]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# XXX what's a better exception to throw here?
|
(list1 + list2).sort { |a, b|
|
||||||
raise RuntimeError, "No more expansion possible", caller
|
# 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
|
||||||
|
|
||||||
end
|
end
|
|
@ -54,11 +54,7 @@ class ModuleSet < Hash
|
||||||
# throwing an exception.
|
# throwing an exception.
|
||||||
#
|
#
|
||||||
def get_hash_val(name)
|
def get_hash_val(name)
|
||||||
begin
|
fetch(name) if has_key?(name)
|
||||||
return self.fetch(name)
|
|
||||||
rescue IndexError
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -902,10 +898,7 @@ protected
|
||||||
usable = false
|
usable = false
|
||||||
|
|
||||||
begin
|
begin
|
||||||
usable = added.is_usable
|
usable = respond_to?(:is_usable) ? added.is_usable : true
|
||||||
# If no method is defined, assume that this module is usable.
|
|
||||||
rescue NoMethodError
|
|
||||||
usable = true
|
|
||||||
rescue
|
rescue
|
||||||
elog("Exception caught during is_usable check: #{$!}")
|
elog("Exception caught during is_usable check: #{$!}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,6 +78,8 @@ class Payload < Msf::Module
|
||||||
end
|
end
|
||||||
|
|
||||||
@staged = true
|
@staged = true
|
||||||
|
else
|
||||||
|
@staged = false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update the module info hash with the connection type
|
# Update the module info hash with the connection type
|
||||||
|
|
|
@ -928,7 +928,6 @@ class PeBase
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :code_offset, :unwind_op, :op_info, :frame_offset
|
attr_reader :code_offset, :unwind_op, :op_info, :frame_offset
|
||||||
private
|
|
||||||
attr_writer :code_offset, :unwind_op, :op_info, :frame_offset
|
attr_writer :code_offset, :unwind_op, :op_info, :frame_offset
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -973,9 +972,6 @@ class PeBase
|
||||||
|
|
||||||
attr_reader :begin_address, :end_address, :unwind_info_address
|
attr_reader :begin_address, :end_address, :unwind_info_address
|
||||||
attr_reader :unwind_info
|
attr_reader :unwind_info
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
attr_writer :unwind_info
|
attr_writer :unwind_info
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,7 +64,7 @@ class Event
|
||||||
begin
|
begin
|
||||||
# XXX: we need to replace this code
|
# XXX: we need to replace this code
|
||||||
# continuations slow down YARV
|
# continuations slow down YARV
|
||||||
require "continuation"
|
require "continuation" if not defined? callcc
|
||||||
rescue ::LoadError
|
rescue ::LoadError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue