Class: Msf::ModuleDataStore

Inherits:
DataStore show all
Defined in:
lib/msf/core/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 Method Summary collapse

Methods inherited from DataStore

#[]=, #clear, #clear_non_user_defined, #each, #from_file, #import_option, #import_options, #import_options_from_hash, #import_options_from_s, #store, #to_file, #to_h, #to_s, #update_value, #user_defined

Constructor Details

#initialize(m) ⇒ ModuleDataStore

Returns a new instance of ModuleDataStore


257
258
259
260
261
# File 'lib/msf/core/data_store.rb', line 257

def initialize(m)
  super()

  @_module = m
end

Instance Method Details

#[](key) ⇒ Object

Same as fetch


281
282
283
284
285
286
287
288
289
290
# File 'lib/msf/core/data_store.rb', line 281

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.


302
303
304
305
306
307
308
# File 'lib/msf/core/data_store.rb', line 302

def copy
  clone = self.class.new(@_module)
  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
end

#default?(key) ⇒ Boolean

Was this entry actually set or just using its default

Returns:

  • (Boolean)

295
296
297
# File 'lib/msf/core/data_store.rb', line 295

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


267
268
269
270
271
272
273
274
275
276
# File 'lib/msf/core/data_store.rb', line 267

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