Method: Rex::Text.dehex

Defined in:
lib/rex/text/hex.rb

.dehex(str) ⇒ Object

Convert hex-encoded characters to literals.

Examples:

Rex::Text.dehex("AA\\x42CC") # => "AABCC"

Parameters:

  • str (String)

See Also:



185
186
187
188
189
190
191
192
193
194
# File 'lib/rex/text/hex.rb', line 185

def self.dehex(str)
  return str unless str.respond_to? :match
  return str unless str.respond_to? :gsub
  regex = /\x5cx[0-9a-f]{2}/nmi
  if str.match(regex)
    str.gsub(regex) { |x| x[2,2].to_i(16).chr }
  else
    str
  end
end