2014-11-03 22:20:21 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Integer option.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class OptInt < OptBase
|
|
|
|
def type
|
|
|
|
return 'integer'
|
|
|
|
end
|
|
|
|
|
|
|
|
def normalize(value)
|
2016-05-23 19:56:19 +00:00
|
|
|
if value.to_s.match(/^0x[a-fA-F\d]+$/)
|
2014-11-03 22:20:21 +00:00
|
|
|
value.to_i(16)
|
|
|
|
else
|
|
|
|
value.to_i
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
if value and not value.to_s.match(/^0x[0-9a-fA-F]+$|^-?\d+$/)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
return super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|