Class: Msf::ModuleDataStore

Inherits:
DataStore show all
Defined in:
lib/msf/core/module_data_store.rb

Overview

DataStore wrapper for modules that will attempt to back values against the framework's datastore if they aren't found in the module's datastore. This is done to simulate global data store values.

Instance Attribute Summary

Attributes inherited from DataStore

#aliases, #imported, #imported_by, #options

Instance Method Summary collapse

Methods inherited from DataStore

#[]=, #clear, #clear_non_user_defined, #delete, #each, #find_key_case, #from_file, #import_option, #import_options, #import_options_from_hash, #import_options_from_s, #merge, #merge!, #store, #to_file, #to_h, #to_nested_values, #to_s, #update_value, #user_defined

Constructor Details

#initialize(m) ⇒ ModuleDataStore

Returns a new instance of ModuleDataStore.


13
14
15
16
17
# File 'lib/msf/core/module_data_store.rb', line 13

def initialize(m)
  super()

  @_module = m
end

Instance Method Details

#[](key) ⇒ Object

Same as fetch


37
38
39
40
41
42
43
44
45
46
# File 'lib/msf/core/module_data_store.rb', line 37

def [](key)
  key = find_key_case(key)
  val = nil
  val = super if(@imported_by[key] != 'self')
  if (val.nil? and @_module and @_module.framework)
    val = @_module.framework.datastore[key]
  end
  val = super if val.nil?
  val
end

#copyObject

Return a deep copy of this datastore.


58
59
60
61
62
63
64
65
# File 'lib/msf/core/module_data_store.rb', line 58

def copy
  ds = self.class.new(@_module)
  self.keys.each do |k|
    ds.import_option(k, self[k].kind_of?(String) ? self[k].dup : self[k], @imported[k], @imported_by[k])
  end
  ds.aliases = self.aliases.dup
  ds
end

#default?(key) ⇒ Boolean

Was this entry actually set or just using its default

Returns:

  • (Boolean)

51
52
53
# File 'lib/msf/core/module_data_store.rb', line 51

def default?(key)
  (@imported_by[key] == 'self')
end

#fetch(key) ⇒ Object

Fetch the key from the local hash first, or from the framework datastore if we can't directly find it


23
24
25
26
27
28
29
30
31
32
# File 'lib/msf/core/module_data_store.rb', line 23

def fetch(key)
  key = find_key_case(key)
  val = nil
  val = super if(@imported_by[key] != 'self')
  if (val.nil? and @_module and @_module.framework)
    val = @_module.framework.datastore[key]
  end
  val = super if val.nil?
  val
end