-
Notifications
You must be signed in to change notification settings - Fork 4
/
misc_windows.go
54 lines (44 loc) · 1.25 KB
/
misc_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"errors"
"strconv"
"unsafe"
"github.com/danieljoos/wincred"
"golang.org/x/sys/windows"
)
func getDiskSerial() string {
mainDrive := "C"
lpVolumeNameBuffer := make([]uint16, 256)
lpVolumeSerialNumber := uint32(0)
lpMaximumComponentLength := uint32(0)
lpFileSystemFlags := uint32(0)
lpFileSystemNameBuffer := make([]uint16, 256)
volpath, _ := windows.UTF16PtrFromString(mainDrive + ":/")
lpVolumeNameBufferPtr := (*uint16)(unsafe.Pointer(&lpVolumeNameBuffer))
lpFileSystemNameBufferPtr := (*uint16)(unsafe.Pointer(&lpFileSystemNameBuffer))
err := windows.GetVolumeInformation(
volpath,
lpVolumeNameBufferPtr,
uint32(len(lpVolumeNameBuffer)),
&lpVolumeSerialNumber,
&lpMaximumComponentLength,
&lpFileSystemFlags,
lpFileSystemNameBufferPtr,
uint32(len(lpFileSystemNameBuffer)))
panicFail(err)
return strconv.Itoa(int(lpVolumeSerialNumber))
}
func getSecureStorageData(service string, accountID string) []byte {
serviceURI := service + "/" + accountID
cred, err := wincred.GetGenericCredential(serviceURI)
if err != nil {
switch err.Error() {
case "Element not found.":
err = errors.New("entry not found in secure storage")
default:
panicFail(err)
}
expectedFail(err)
}
return cred.CredentialBlob
}