Module: Metasploit::Credential::Text
- Defined in:
- lib/metasploit/credential/text.rb
Overview
Helper module that contains methods for manipulating text into different formats.
Class Method Summary collapse
-
.ascii_safe_hex(str, whitespace = false) ⇒ String
Turn non-printable chars into hex representations, leaving others alone If
whitespace
is true, converts whitespace (0x20, 0x09, etc) to hex as well. -
.dehex(str) ⇒ String
Convert hex into characters.
Class Method Details
.ascii_safe_hex(str, whitespace = false) ⇒ String
Turn non-printable chars into hex representations, leaving others alone If whitespace
is true, converts whitespace (0x20, 0x09, etc) to hex as well. param [Boolean] whitespace converts whitespace to ASCII-safe hex if true, ignores if false
9 10 11 12 13 14 15 |
# File 'lib/metasploit/credential/text.rb', line 9 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 |
.dehex(str) ⇒ String
Convert hex into characters
19 20 21 22 23 24 25 |
# File 'lib/metasploit/credential/text.rb', line 19 def self.dehex(str) hexen = str.scan(/\x5cx[0-9a-fA-F]{2}/n) hexen.each { |h| str.gsub!(h,h[2,2].to_i(16).chr) } str end |