module WinRM::PSRP::UUID

UUID helper methods

Public Instance Methods

uuid_to_windows_guid_bytes(uuid) click to toggle source

Format a UUID into a GUID compatible byte array for Windows

msdn.microsoft.com/en-us/library/windows/desktop/aa373931(v=vs.85).aspx typedef struct _GUID {

DWORD Data1;
WORD  Data2;
WORD  Data3;
BYTE  Data4[8];

} GUID;

@param uuid [String] Canonical hex format with hypens. @return [Array<byte>] UUID in a Windows GUID compatible byte array layout.

# File lib/winrm/psrp/uuid.rb, line 31
def uuid_to_windows_guid_bytes(uuid)
  return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] unless uuid

  b = uuid.scan(/[0-9a-fA-F]{2}/).map { |x| x.to_i(16) }
  b[0..3].reverse + b[4..5].reverse + b[6..7].reverse + b[8..15]
end