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 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.


351
352
353
354
355
# File 'lib/msf/core/data_store.rb', line 351

def initialize(m)
  super()

  @_module = m
end

Instance Method Details

#[](key) ⇒ Object

Same as fetch


375
376
377
378
379
380
381
382
383
384
# File 'lib/msf/core/data_store.rb', line 375

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.


396
397
398
399
400
401
402
403
# File 'lib/msf/core/data_store.rb', line 396

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)

389
390
391
# File 'lib/msf/core/data_store.rb', line 389

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


361
362
363
364
365
366
367
368
369
370
# File 'lib/msf/core/data_store.rb', line 361

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