Method: Rex::Text.to_guid

Defined in:
lib/rex/text.rb

.to_guid(bytes) ⇒ String

Convert 16-byte string to a GUID string

Examples:

str = "ABCDEFGHIJKLMNOP"
Rex::Text.to_guid(str) #=> "{44434241-4645-4847-494a-4b4c4d4e4f50}"

Parameters:

  • bytes (String)

    16 bytes which represent a GUID in the proper order.

Returns:

  • (String)


1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
# File 'lib/rex/text.rb', line 1298

def self.to_guid(bytes)
  return nil unless bytes
  s = bytes.unpack('H*')[0]
  parts = [
    s[6,  2] + s[4,  2] + s[2, 2] + s[0, 2],
    s[10, 2] + s[8,  2],
    s[14, 2] + s[12, 2],
    s[16, 4],
    s[20, 12]
  ]
  "{#{parts.join('-')}}"
end