Method: Rex::Text.ascii_safe_hex

Defined in:
lib/rex/text.rb

.ascii_safe_hex(str, whitespace = false) ⇒ Object

Turn non-printable chars into hex representations, leaving others alone

If whitespace is true, converts whitespace (0x20, 0x09, etc) to hex as well.



973
974
975
976
977
978
979
# File 'lib/rex/text.rb', line 973

def self.ascii_safe_hex(str, whitespace=false)
  if whitespace
    str.gsub(/([\x00-\x20\x80-\xFF])/n){ |x| "\\x%.2x" % x.unpack("C*")[0] }
  else
    str.gsub(/([\x00-\x08\x0b\x0c\x0e-\x1f\x80-\xFF])/n){ |x| "\\x%.2x" % x.unpack("C*")[0]}
  end
end