Class: Msf::OptBase

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/option_container.rb

Overview

The base class for all options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(in_name, attrs = []) ⇒ OptBase

Initializes a named option with the supplied attribute array. The array is composed of three values.

attrs = required (boolean type) attrs = description (string) attrs = default value attrs = possible enum values


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

def initialize(in_name, attrs = [])
  self.name     = in_name
  self.advanced = false
  self.evasion  = false
  self.required = attrs[0] || false
  self.desc     = attrs[1]
  self.default  = attrs[2]
  self.enums    = [ *(attrs[3]) ].map { |x| x.to_s }
end

Instance Attribute Details

#advancedObject

Whether or not this is an advanced option.


115
116
117
# File 'lib/msf/core/option_container.rb', line 115

def advanced
  @advanced
end

#defaultObject

The default value of the option.


107
108
109
# File 'lib/msf/core/option_container.rb', line 107

def default
  @default
end

#descObject

The description of the option.


103
104
105
# File 'lib/msf/core/option_container.rb', line 103

def desc
  @desc
end

#enumsObject

The list of potential valid values


127
128
129
# File 'lib/msf/core/option_container.rb', line 127

def enums
  @enums
end

#evasionObject

Whether or not this is an evasion option.


119
120
121
# File 'lib/msf/core/option_container.rb', line 119

def evasion
  @evasion
end

#nameObject

The name of the option.


95
96
97
# File 'lib/msf/core/option_container.rb', line 95

def name
  @name
end

#ownerObject

The module or entity that owns this option.


123
124
125
# File 'lib/msf/core/option_container.rb', line 123

def owner
  @owner
end

#requiredObject

Whether or not the option is required.


99
100
101
# File 'lib/msf/core/option_container.rb', line 99

def required
  @required
end

Instance Method Details

#advanced?Boolean

Returns true if this is an advanced option.

Returns:

  • (Boolean)

44
45
46
# File 'lib/msf/core/option_container.rb', line 44

def advanced?
  return advanced
end

#display_value(value) ⇒ Object

Returns a string representing a user-friendly display of the chosen value


88
89
90
# File 'lib/msf/core/option_container.rb', line 88

def display_value(value)
  value.to_s
end

#empty_required_value?(value) ⇒ Boolean

Returns true if the value supplied is nil and it's required to be a valid value

Returns:

  • (Boolean)

73
74
75
# File 'lib/msf/core/option_container.rb', line 73

def empty_required_value?(value)
  return (required? and value.nil?)
end

#evasion?Boolean

Returns true if this is an evasion option.

Returns:

  • (Boolean)

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

def evasion?
  return evasion
end

#normalize(value) ⇒ Object

Normalizes the supplied value to conform with the type that the option is conveying.


81
82
83
# File 'lib/msf/core/option_container.rb', line 81

def normalize(value)
  value
end

#required?Boolean

Returns true if this is a required option.

Returns:

  • (Boolean)

37
38
39
# File 'lib/msf/core/option_container.rb', line 37

def required?
  return required
end

#type?(in_type) ⇒ Boolean

Returns true if the supplied type is equivalent to this option's type.

Returns:

  • (Boolean)

58
59
60
# File 'lib/msf/core/option_container.rb', line 58

def type?(in_type)
  return (type == in_type)
end

#valid?(value) ⇒ Boolean

If it's required and the value is nil or empty, then it's not valid.

Returns:

  • (Boolean)

65
66
67
# File 'lib/msf/core/option_container.rb', line 65

def valid?(value)
  return (required? and (value == nil or value.to_s.empty?)) ? false : true
end