github.com/iDigitalFlame/xmt@v0.5.1/device/local/windows_no_crypt.go (about) 1 //go:build windows && !crypt 2 // +build windows,!crypt 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package local 21 22 import ( 23 "github.com/iDigitalFlame/xmt/device/winapi" 24 "github.com/iDigitalFlame/xmt/device/winapi/registry" 25 "github.com/iDigitalFlame/xmt/util" 26 ) 27 28 func sysID() []byte { 29 if s, err := winapi.GetSystemSID(); err == nil { 30 return []byte(s.String()) 31 } 32 // 0x101 - KEY_WOW64_64KEY | KEY_QUERY_VALUE 33 k, err := registry.Open(registry.KeyLocalMachine, `Software\Microsoft\Cryptography`, 0x101) 34 if err != nil { 35 return nil 36 } 37 v, _, err := k.String("MachineGuid") 38 if k.Close(); err == nil { 39 return []byte(v) 40 } 41 return nil 42 } 43 func version() string { 44 var n string 45 // 0x101 - KEY_WOW64_64KEY | KEY_QUERY_VALUE 46 if k, err := registry.Open(registry.KeyLocalMachine, `Software\Microsoft\Windows NT\CurrentVersion`, 0x101); err == nil { 47 n, _, _ = k.String("ProductName") 48 k.Close() 49 } 50 var ( 51 j, y, h = winapi.GetVersionNumbers() 52 b = util.Uitoa(uint64(h)) 53 v string 54 ) 55 if y > 0 { 56 v = util.Uitoa(uint64(j)) + "." + util.Uitoa(uint64(y)) 57 } else { 58 v = util.Uitoa(uint64(j)) 59 } 60 switch { 61 case len(n) == 0 && len(b) == 0 && len(v) == 0: 62 return "Windows" 63 case len(n) == 0 && len(b) > 0 && len(v) > 0: 64 return "Windows (" + v + ", " + b + ")" 65 case len(n) == 0 && len(b) == 0 && len(v) > 0: 66 return "Windows (" + v + ")" 67 case len(n) == 0 && len(b) > 0 && len(v) == 0: 68 return "Windows (" + b + ")" 69 case len(n) > 0 && len(b) > 0 && len(v) > 0: 70 return n + " (" + v + ", " + b + ")" 71 case len(n) > 0 && len(b) == 0 && len(v) > 0: 72 return n + " (" + v + ")" 73 case len(n) > 0 && len(b) > 0 && len(v) == 0: 74 return n + " (" + b + ")" 75 } 76 return "Windows" 77 }