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)
|
|
|
|
return false if check_empty && empty_required_value?(value)
|
2014-11-03 22:20:21 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
Regexp.compile(value)
|
2016-05-23 22:33:06 +00:00
|
|
|
return true
|
2014-11-03 22:20:21 +00:00
|
|
|
rescue RegexpError, TypeError
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def normalize(value)
|
|
|
|
return nil if value.nil?
|
2016-03-16 11:44:02 +00:00
|
|
|
return Regexp.compile(value.to_s)
|
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
|
|
|
|
|
|
|
|
return super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|