github.com/google/osv-scalibr@v0.4.1/extractor/standalone/windows/common/winproducts/winproducts.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package winproducts contains information about Windows products. 16 package winproducts 17 18 import ( 19 "strings" 20 21 "github.com/google/osv-scalibr/log" 22 ) 23 24 var ( 25 // windowsFlavorAndBuildToProductName maps a given Windows flavor and build number to a product 26 // name. 27 windowsFlavorAndBuildToProductName = map[string]map[string]string{ 28 "server": { 29 "6.0.6003": "windows_server_2008", 30 "6.1.7601": "windows_server_2008:r2", 31 "6.2.9200": "windows_server_2012", 32 "6.3.9600": "windows_server_2012:r2", 33 "10.0.14393": "windows_server_2016", 34 "10.0.17763": "windows_server_2019", 35 "10.0.20348": "windows_server_2022", 36 "10.0.25398": "windows_server_2022:23H2", 37 "10.0.26100": "windows_server_2025", 38 }, 39 "client": { 40 "5.1.2600": "windows_xp", 41 "10.0.10240": "windows_10:1507", 42 "10.0.14393": "windows_10:1607", 43 "10.0.17763": "windows_10:1809", 44 "10.0.19042": "windows_10:20H2", 45 "10.0.19043": "windows_10:21H1", 46 "10.0.19044": "windows_10:21H2", 47 "10.0.19045": "windows_10:22H2", 48 "10.0.22000": "windows_11:21H2", 49 "10.0.22621": "windows_11:22H2", 50 "10.0.22631": "windows_11:23H2", 51 "10.0.26100": "windows_11:24H2", 52 }, 53 } 54 ) 55 56 // windowsFlavor returns the lowercase Windows flavor (server or client) of the current system 57 // using the provided lowercase installType (found in the registry). 58 // Defaults to "server" if we don't recognize the flavor, but log so that we can add it later. 59 func windowsFlavor(installType string) string { 60 flavor := strings.ToLower(installType) 61 62 switch flavor { 63 case "client": 64 return "client" 65 case "server", "server core": 66 return "server" 67 } 68 69 log.Infof("Please report to scalibr devteam: unknown Windows flavor: %q", flavor) 70 return "server" 71 } 72 73 // WindowsProductFromVersion fetches the current Windows product name from known products using 74 // the flavor (e.g. client / server) and the image version. 75 func WindowsProductFromVersion(flavor, imgVersion string) string { 76 knownVersions, ok := windowsFlavorAndBuildToProductName[flavor] 77 if !ok { 78 return "unknownWindows" 79 } 80 81 imgVersionSplit := strings.Split(imgVersion, ".") 82 if len(imgVersionSplit) < 3 { 83 return "unknownWindows" 84 } 85 86 version := strings.Join(imgVersionSplit[:3], ".") 87 if productName, ok := knownVersions[version]; ok { 88 return productName 89 } 90 91 return "unknownWindows" 92 }