add alias support for datastore options
parent
b35d53bd02
commit
bca8e77163
|
@ -14,10 +14,13 @@ class DataStore < Hash
|
||||||
#
|
#
|
||||||
def initialize()
|
def initialize()
|
||||||
@options = Hash.new
|
@options = Hash.new
|
||||||
|
@aliases = Hash.new
|
||||||
@imported = Hash.new
|
@imported = Hash.new
|
||||||
@imported_by = Hash.new
|
@imported_by = Hash.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_accessor :aliases
|
||||||
|
|
||||||
#
|
#
|
||||||
# Clears the imported flag for the supplied key since it's being set
|
# Clears the imported flag for the supplied key since it's being set
|
||||||
# directly.
|
# directly.
|
||||||
|
@ -133,11 +136,16 @@ class DataStore < Hash
|
||||||
}
|
}
|
||||||
end
|
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)
|
self.store(key, val)
|
||||||
|
|
||||||
|
if option
|
||||||
|
option.aliases.each do |a|
|
||||||
|
@aliases[a.downcase] = key.downcase
|
||||||
|
end
|
||||||
|
end
|
||||||
@options[key] = option
|
@options[key] = option
|
||||||
@imported[key] = imported
|
@imported[key] = imported
|
||||||
@imported_by[key] = imported_by
|
@imported_by[key] = imported_by
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -245,9 +253,15 @@ protected
|
||||||
#
|
#
|
||||||
def find_key_case(k)
|
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
|
# Scan each key looking for a match
|
||||||
self.each_key do |rk|
|
self.each_key do |rk|
|
||||||
if (rk.downcase == k.downcase)
|
if rk.downcase == search_k
|
||||||
return rk
|
return rk
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -317,6 +331,7 @@ class ModuleDataStore < DataStore
|
||||||
self.keys.each do |k|
|
self.keys.each do |k|
|
||||||
clone.import_option(k, self[k].kind_of?(String) ? self[k].dup : self[k], @imported[k], @imported_by[k])
|
clone.import_option(k, self[k].kind_of?(String) ? self[k].dup : self[k], @imported[k], @imported_by[k])
|
||||||
end
|
end
|
||||||
|
clone.aliases = self.aliases
|
||||||
clone
|
clone
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Msf
|
||||||
# attrs[3] = possible enum values
|
# attrs[3] = possible enum values
|
||||||
# attrs[4] = Regex to validate the option
|
# attrs[4] = Regex to validate the option
|
||||||
#
|
#
|
||||||
def initialize(in_name, attrs = [])
|
def initialize(in_name, attrs = [], aliases: [])
|
||||||
self.name = in_name
|
self.name = in_name
|
||||||
self.advanced = false
|
self.advanced = false
|
||||||
self.evasion = false
|
self.evasion = false
|
||||||
|
@ -45,6 +45,7 @@ module Msf
|
||||||
raise("Invalid Regex #{regex_temp}: #{e}")
|
raise("Invalid Regex #{regex_temp}: #{e}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self.aliases = aliases
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -159,6 +160,10 @@ module Msf
|
||||||
# A optional regex to validate the option value
|
# A optional regex to validate the option value
|
||||||
#
|
#
|
||||||
attr_accessor :regex
|
attr_accessor :regex
|
||||||
|
#
|
||||||
|
# Aliases for this option for backward compatibility
|
||||||
|
#
|
||||||
|
attr_accessor :aliases
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue