github.com/iDigitalFlame/xmt@v0.5.4/device/local/macos_crypt.go (about) 1 //go:build (darwin || ios) && crypt 2 // +build darwin ios 3 // +build crypt 4 5 // Copyright (C) 2020 - 2023 iDigitalFlame 6 // 7 // This program is free software: you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License as published by 9 // the Free Software Foundation, either version 3 of the License, or 10 // any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 // You should have received a copy of the GNU General Public License 18 // along with this program. If not, see <https://www.gnu.org/licenses/>. 19 // 20 21 package local 22 23 import ( 24 "os/exec" 25 "strings" 26 27 "github.com/iDigitalFlame/xmt/device/unix" 28 "github.com/iDigitalFlame/xmt/util/crypt" 29 ) 30 31 func sysID() []byte { 32 o, err := output(crypt.Get(84)) // /usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice 33 if err != nil || len(o) == 0 { 34 return nil 35 } 36 for _, v := range strings.Split(string(o), "\n") { 37 if !strings.Contains(v, crypt.Get(85)) { // IOPlatformUUID 38 continue 39 } 40 x := strings.IndexByte(v, '=') 41 if x < 14 || len(v)-x < 2 { 42 continue 43 } 44 c, s := len(v)-1, x+1 45 for ; c > x && (v[c] == '"' || v[c] == ' ' || v[c] == 9); c-- { 46 } 47 for ; s < c && (v[s] == '"' || v[s] == ' ' || v[s] == 9); s++ { 48 } 49 if s == c || s > len(v) || s > c { 50 continue 51 } 52 return []byte(v[s : c+1]) 53 } 54 return nil 55 } 56 func version() string { 57 var b, n, v string 58 if o, err := exec.Command(crypt.Get(86)).CombinedOutput(); err == nil { // /usr/bin/sw_vers 59 m := make(map[string]string) 60 for _, v := range strings.Split(string(o), "\n") { 61 x := strings.IndexByte(v, ':') 62 if x < 1 || len(v)-x < 2 { 63 continue 64 } 65 c, s := len(v)-1, x+1 66 for ; c > x && (v[c] == ' ' || v[c] == 9); c-- { 67 } 68 for ; s < c && (v[s] == ' ' || v[s] == 9); s++ { 69 } 70 m[strings.ToUpper(v[:x])] = v[s : c+1] 71 } 72 n = m[crypt.Get(87)] // PRODUCTNAME 73 b = m[crypt.Get(88)] // BUILDVERSION 74 v = m[crypt.Get(89)] // PRODUCTVERSION 75 } 76 if len(v) == 0 { 77 v = unix.Release() 78 } 79 switch { 80 case len(n) == 0 && len(b) == 0 && len(v) == 0: 81 return crypt.Get(90) // MacOS 82 case len(n) == 0 && len(b) > 0 && len(v) > 0: 83 return crypt.Get(90) + " (" + v + ", " + b + ")" // MacOS 84 case len(n) == 0 && len(b) == 0 && len(v) > 0: 85 return crypt.Get(90) + " (" + v + ")" // MacOS 86 case len(n) == 0 && len(b) > 0 && len(v) == 0: 87 return crypt.Get(90) + " (" + b + ")" // MacOS 88 case len(n) > 0 && len(b) > 0 && len(v) > 0: 89 return n + " (" + v + ", " + b + ")" 90 case len(n) > 0 && len(b) == 0 && len(v) > 0: 91 return n + " (" + v + ")" 92 case len(n) > 0 && len(b) > 0 && len(v) == 0: 93 return n + " (" + b + ")" 94 } 95 return crypt.Get(90) // MacOS 96 }