Class: Msf::OptString

Inherits:
OptBase show all
Defined in:
lib/msf/core/opt_string.rb

Overview

Mult-byte character string option.

Instance Attribute Summary

Attributes inherited from OptBase

#advanced, #aliases, #conditions, #default, #desc, #enums, #evasion, #fallbacks, #max_length, #name, #owner, #regex, #required

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #display_value, #empty_required_value?, #evasion?, #invalid_value_length?, #required?, #type?

Constructor Details

#initialize(in_name, attrs = [], **kwargs) ⇒ OptString

This adds a length parameter to check for the maximum length of strings.



13
14
15
# File 'lib/msf/core/opt_string.rb', line 13

def initialize(in_name, attrs = [], **kwargs)
  super
end

Instance Method Details

#normalize(value) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/msf/core/opt_string.rb', line 25

def normalize(value)
  if (value.to_s =~ /^file:(.*)/)
    path = $1
    begin
      value = File.read(path)
    rescue ::Errno::ENOENT, ::Errno::EISDIR
      value = nil
    end
  end
  value
end

#typeObject



17
18
19
# File 'lib/msf/core/opt_string.rb', line 17

def type
  return 'string'
end

#valid?(value = self.value, check_empty: true) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/msf/core/opt_string.rb', line 37

def valid?(value=self.value, check_empty: true)
  value = normalize(value)
  return false if check_empty && empty_required_value?(value)
  return false if invalid_value_length?(value)
  return super(value, check_empty: false)
end

#validate_on_assignment?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/msf/core/opt_string.rb', line 21

def validate_on_assignment?
  true
end