diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-07 04:18:27 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-07 04:39:59 +0100 |
commit | ea59177f1c6ab9031d5d30771410c9514fa551d9 (patch) | |
tree | cfe5c11f9340d468dfd5f80b76db78584a9ef20a /tun/wintun/guid/guid_windows.go | |
parent | 306d08e692bc9b2249078c0b4ab7eb3e42078230 (diff) |
wintun: Introduce new package for obscuring Windows bits
Diffstat (limited to 'tun/wintun/guid/guid_windows.go')
-rw-r--r-- | tun/wintun/guid/guid_windows.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tun/wintun/guid/guid_windows.go b/tun/wintun/guid/guid_windows.go new file mode 100644 index 0000000..0078d2c --- /dev/null +++ b/tun/wintun/guid/guid_windows.go @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package guid + +import ( + "fmt" + "syscall" + + "golang.org/x/sys/windows" +) + +//sys clsidFromString(lpsz *uint16, pclsid *windows.GUID) (hr int32) = ole32.CLSIDFromString + +// +// FromString parses "{XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" string to GUID. +// +func FromString(str string) (*windows.GUID, error) { + strUTF16, err := syscall.UTF16PtrFromString(str) + if err != nil { + return nil, err + } + + guid := &windows.GUID{} + + hr := clsidFromString(strUTF16, guid) + if hr < 0 { + return nil, syscall.Errno(hr) + } + + return guid, nil +} + +// +// ToString function converts GUID to string +// "{XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}". +// +// The resulting string is uppercase. +// +func ToString(guid *windows.GUID) string { + return fmt.Sprintf("{%06X-%04X-%04X-%04X-%012X}", guid.Data1, guid.Data2, guid.Data3, guid.Data4[:2], guid.Data4[2:]) +} |