Module: Metasploit::Model::Module::Instance::ClassMethods

Included in:
Metasploit::Model::Module::Instance
Defined in:
lib/metasploit/model/module/instance.rb

Overview

Module Methods

Instance Method Summary collapse

Instance Method Details

#allows?(options = {}) ⇒ true

Whether the given :attribute is allowed to be present for the given :module_type. An attribute is considered allowed if it allows greatrr than 0 elements for a collection.

Returns:

  • (true)

    if maximum elements is greater than 0 or value can be non-nil

Raises:

  • (KeyError)

    if :attribute is not given in options.

  • (KeyError)

    if :module_type is not given in options.



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/metasploit/model/module/instance.rb', line 381

def allows?(options={})
  allowed = false
  length_validation_options = dynamic_length_validation_options(options)

  is = length_validation_options[:is]

  if is
    if is > 0
      allowed = true
    end
  else
    maximum = length_validation_options[:maximum]

    if maximum
      if maximum > 0
        allowed = true
      end
    else
      # if there is no maximum, then it's treated as infinite
      allowed = true
    end
  end

  allowed
end

#dynamic_length_validation_options(options = {}) ⇒ Hash{Symbol => Integer}

The length validation options for the given :attribute and :module_type.

Returns:

  • (Hash{Symbol => Integer})

    Hash containing either :is (meaning :maximum and :minimum are the same) or :minimum (no attribute has an explicit :maximum currently).

Raises:



415
416
417
418
419
420
421
422
# File 'lib/metasploit/model/module/instance.rb', line 415

def dynamic_length_validation_options(options={})
  options.assert_valid_keys(:attribute, :module_type)
  attribute = options.fetch(:attribute)
  module_type = options.fetch(:module_type)

  dynamic_length_validation_options_by_module_type = DYNAMIC_LENGTH_VALIDATION_OPTIONS_BY_MODULE_TYPE_BY_ATTRIBUTE.fetch(attribute)
  dynamic_length_validation_options_by_module_type.fetch(module_type)
end

#stanced?(module_type) ⇒ true, false

Whether the :module_type requires stance to be in Stance::ALL or if it must be nil.

Parameters:

  • module_type (String)

    A member of Metasploit::Model::Module::Type::ALL.

Returns:



430
431
432
# File 'lib/metasploit/model/module/instance.rb', line 430

def stanced?(module_type)
  STANCED_MODULE_TYPES.include? module_type
end