Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

opt_regexp.rb 742B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: binary -*-
  2. module Msf
  3. ###
  4. #
  5. # Regexp option
  6. #
  7. ###
  8. class OptRegexp < OptBase
  9. def type
  10. return 'regexp'
  11. end
  12. def valid?(value, check_empty: true)
  13. if check_empty && empty_required_value?(value)
  14. return false
  15. elsif value.nil?
  16. return true
  17. end
  18. begin
  19. Regexp.compile(value)
  20. return super
  21. rescue RegexpError, TypeError
  22. return false
  23. end
  24. end
  25. def normalize(value)
  26. if value.nil? || value.kind_of?(Regexp)
  27. value
  28. else
  29. Regexp.compile(value.to_s)
  30. end
  31. end
  32. def display_value(value)
  33. if value.kind_of?(Regexp)
  34. return value.source
  35. elsif value.kind_of?(String)
  36. return display_value(normalize(value))
  37. end
  38. super
  39. end
  40. end
  41. end