add alias support for datastore options

bug/bundler_fix
Brent Cook 2017-08-05 02:22:55 -05:00
parent b35d53bd02
commit bca8e77163
2 changed files with 24 additions and 4 deletions

View File

@ -14,10 +14,13 @@ class DataStore < Hash
#
def initialize()
@options = Hash.new
@aliases = Hash.new
@imported = Hash.new
@imported_by = Hash.new
end
attr_accessor :aliases
#
# Clears the imported flag for the supplied key since it's being set
# directly.
@ -133,11 +136,16 @@ class DataStore < Hash
}
end
def import_option(key, val, imported=true, imported_by=nil, option=nil)
def import_option(key, val, imported = true, imported_by = nil, option = nil)
self.store(key, val)
if option
option.aliases.each do |a|
@aliases[a.downcase] = key.downcase
end
end
@options[key] = option
@imported[key] = imported
@imported[key] = imported
@imported_by[key] = imported_by
end
@ -245,9 +253,15 @@ protected
#
def find_key_case(k)
# Scan each alias looking for a key
search_k = k.downcase
if @aliases.has_key?(search_k)
search_k = @aliases[search_k]
end
# Scan each key looking for a match
self.each_key do |rk|
if (rk.downcase == k.downcase)
if rk.downcase == search_k
return rk
end
end
@ -317,6 +331,7 @@ class ModuleDataStore < DataStore
self.keys.each do |k|
clone.import_option(k, self[k].kind_of?(String) ? self[k].dup : self[k], @imported[k], @imported_by[k])
end
clone.aliases = self.aliases
clone
end
end

View File

@ -22,7 +22,7 @@ module Msf
# attrs[3] = possible enum values
# attrs[4] = Regex to validate the option
#
def initialize(in_name, attrs = [])
def initialize(in_name, attrs = [], aliases: [])
self.name = in_name
self.advanced = false
self.evasion = false
@ -45,6 +45,7 @@ module Msf
raise("Invalid Regex #{regex_temp}: #{e}")
end
end
self.aliases = aliases
end
#
@ -159,6 +160,10 @@ module Msf
# A optional regex to validate the option value
#
attr_accessor :regex
#
# Aliases for this option for backward compatibility
#
attr_accessor :aliases
protected