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, #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 = [], required: false, desc: nil, default: nil, enums: [], regex: nil, aliases: [], max_length: nil) ⇒ OptString

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


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

def initialize(in_name, attrs = [],
             required: false, desc: nil, default: nil, enums: [], regex: nil, aliases: [], max_length: nil)
  super
end

Instance Method Details

#normalize(value) ⇒ Object


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

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


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

def type
  return 'string'
end

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

Returns:

  • (Boolean)

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

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)

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

def validate_on_assignment?
  true
end