2014-11-03 22:20:21 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Regexp option
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class OptRegexp < OptBase
|
|
|
|
def type
|
|
|
|
return 'regexp'
|
|
|
|
end
|
|
|
|
|
2016-05-23 19:56:19 +00:00
|
|
|
def valid?(value, check_empty: true)
|
2016-05-24 01:08:38 +00:00
|
|
|
if check_empty && empty_required_value?(value)
|
|
|
|
return false
|
|
|
|
elsif value.nil?
|
|
|
|
return true
|
|
|
|
end
|
2014-11-03 22:20:21 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
Regexp.compile(value)
|
2016-05-24 01:08:38 +00:00
|
|
|
return super
|
2014-11-03 22:20:21 +00:00
|
|
|
rescue RegexpError, TypeError
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def normalize(value)
|
2016-07-12 03:05:00 +00:00
|
|
|
if value.nil? || value.kind_of?(Regexp)
|
|
|
|
value
|
|
|
|
else
|
|
|
|
Regexp.compile(value.to_s)
|
|
|
|
end
|
2014-11-03 22:20:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_value(value)
|
|
|
|
if value.kind_of?(Regexp)
|
|
|
|
return value.source
|
|
|
|
elsif value.kind_of?(String)
|
|
|
|
return display_value(normalize(value))
|
|
|
|
end
|
2016-07-12 03:05:00 +00:00
|
|
|
super
|
2014-11-03 22:20:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|