|
@@ -5,6 +5,7 @@ import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
"os/exec"
|
|
"os/exec"
|
|
|
|
|
+ "runtime"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
|
"imuslab.com/arozos/mod/info/logger"
|
|
"imuslab.com/arozos/mod/info/logger"
|
|
@@ -87,40 +88,98 @@ func (s *Server) GetArOZInfo(w http.ResponseWriter, r *http.Request) {
|
|
|
utils.SendJSONResponse(w, string(jsonData))
|
|
utils.SendJSONResponse(w, string(jsonData))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func wmicGetinfo(wmicName string, itemName string) []string {
|
|
|
|
|
- //get systeminfo
|
|
|
|
|
- var InfoStorage []string
|
|
|
|
|
|
|
+// wmicClassName maps classic `wmic` aliases to CIM / Win32 class names.
|
|
|
|
|
+func wmicClassName(wmicName string) string {
|
|
|
|
|
+ if len(wmicName) > 6 && wmicName[0:6] == "Win32_" {
|
|
|
|
|
+ return wmicName
|
|
|
|
|
+ }
|
|
|
|
|
+ switch strings.ToLower(wmicName) {
|
|
|
|
|
+ case "cpu":
|
|
|
|
|
+ return "Win32_Processor"
|
|
|
|
|
+ case "os":
|
|
|
|
|
+ return "Win32_OperatingSystem"
|
|
|
|
|
+ case "computersystem":
|
|
|
|
|
+ return "Win32_ComputerSystem"
|
|
|
|
|
+ case "diskdrive":
|
|
|
|
|
+ return "Win32_DiskDrive"
|
|
|
|
|
+ case "nic":
|
|
|
|
|
+ return "Win32_NetworkAdapter"
|
|
|
|
|
+ case "logicaldisk":
|
|
|
|
|
+ return "Win32_LogicalDisk"
|
|
|
|
|
+ case "memorychip":
|
|
|
|
|
+ return "Win32_PhysicalMemory"
|
|
|
|
|
+ default:
|
|
|
|
|
+ return "Win32_" + wmicName
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// cimGetinfo reads a WMI property via PowerShell Get-CimInstance.
|
|
|
|
|
+// Modern Windows 11 (24H2+) no longer ships `wmic.exe` by default; CIM is the
|
|
|
|
|
+// supported replacement and exposes the same Win32_* properties.
|
|
|
|
|
+func cimGetinfo(wmicName string, itemName string) []string {
|
|
|
|
|
+ className := wmicClassName(wmicName)
|
|
|
|
|
+ psClass := strings.ReplaceAll(className, "'", "''")
|
|
|
|
|
+ psItem := strings.ReplaceAll(itemName, "'", "''")
|
|
|
|
|
+ script := fmt.Sprintf(
|
|
|
|
|
+ "Get-CimInstance -ClassName '%s' | ForEach-Object { $p = $_.PSObject.Properties['%s']; if ($null -ne $p -and $null -ne $p.Value) { [string]$p.Value } }",
|
|
|
|
|
+ psClass, psItem,
|
|
|
|
|
+ )
|
|
|
|
|
+ cmd := exec.Command("powershell.exe",
|
|
|
|
|
+ "-NoProfile",
|
|
|
|
|
+ "-NonInteractive",
|
|
|
|
|
+ "-WindowStyle", "Hidden",
|
|
|
|
|
+ "-ExecutionPolicy", "Bypass",
|
|
|
|
|
+ "-Command", script,
|
|
|
|
|
+ )
|
|
|
|
|
+ out, err := cmd.CombinedOutput()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ var info []string
|
|
|
|
|
+ for _, line := range strings.Split(string(out), "\n") {
|
|
|
|
|
+ line = strings.TrimSpace(strings.ReplaceAll(line, "\r", ""))
|
|
|
|
|
+ if line != "" {
|
|
|
|
|
+ info = append(info, line)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return info
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- cmd := exec.Command("chcp", "65001")
|
|
|
|
|
|
|
+// legacyWmicGetinfo keeps the original `wmic` path for older Windows hosts
|
|
|
|
|
+// that still ship the binary (pre-removal / optional Feature on Demand).
|
|
|
|
|
+func legacyWmicGetinfo(wmicName string, itemName string) []string {
|
|
|
|
|
+ var info []string
|
|
|
|
|
|
|
|
- cmd = exec.Command("wmic", wmicName, "list", "full", "/format:list")
|
|
|
|
|
|
|
+ cmd := exec.Command("wmic", wmicName, "list", "full", "/format:list")
|
|
|
if wmicName == "os" {
|
|
if wmicName == "os" {
|
|
|
cmd = exec.Command("wmic", wmicName, "get", "*", "/format:list")
|
|
cmd = exec.Command("wmic", wmicName, "get", "*", "/format:list")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if len(wmicName) > 6 {
|
|
|
|
|
- if wmicName[0:6] == "Win32_" {
|
|
|
|
|
- cmd = exec.Command("wmic", "path", wmicName, "get", "*", "/format:list")
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if len(wmicName) > 6 && wmicName[0:6] == "Win32_" {
|
|
|
|
|
+ cmd = exec.Command("wmic", "path", wmicName, "get", "*", "/format:list")
|
|
|
}
|
|
}
|
|
|
out, _ := cmd.CombinedOutput()
|
|
out, _ := cmd.CombinedOutput()
|
|
|
- strOut := string(out)
|
|
|
|
|
-
|
|
|
|
|
- strSplitedOut := strings.Split(strOut, "\n")
|
|
|
|
|
- for _, strConfig := range strSplitedOut {
|
|
|
|
|
|
|
+ for _, strConfig := range strings.Split(string(out), "\n") {
|
|
|
if strings.Contains(strConfig, "=") {
|
|
if strings.Contains(strConfig, "=") {
|
|
|
- strSplitedConfig := strings.SplitN(strConfig, "=", 2)
|
|
|
|
|
- if strSplitedConfig[0] == itemName {
|
|
|
|
|
- strSplitedConfigReplaced := strings.Replace(strSplitedConfig[1], "\r", "", -1)
|
|
|
|
|
- InfoStorage = append(InfoStorage, strSplitedConfigReplaced)
|
|
|
|
|
|
|
+ parts := strings.SplitN(strConfig, "=", 2)
|
|
|
|
|
+ if parts[0] == itemName {
|
|
|
|
|
+ info = append(info, strings.Replace(parts[1], "\r", "", -1))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
- if len(InfoStorage) == 0 {
|
|
|
|
|
- InfoStorage = append(InfoStorage, "Undefined")
|
|
|
|
|
|
|
+ return info
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func wmicGetinfo(wmicName string, itemName string) []string {
|
|
|
|
|
+ if runtime.GOOS == "windows" {
|
|
|
|
|
+ // Prefer CIM: wmic.exe was removed from many Windows 11 installs.
|
|
|
|
|
+ if info := cimGetinfo(wmicName, itemName); len(info) > 0 {
|
|
|
|
|
+ return info
|
|
|
|
|
+ }
|
|
|
|
|
+ if info := legacyWmicGetinfo(wmicName, itemName); len(info) > 0 {
|
|
|
|
|
+ return info
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- return InfoStorage
|
|
|
|
|
|
|
+ return []string{"Undefined"}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func filterGrepResults(result string, sep string) string {
|
|
func filterGrepResults(result string, sep string) string {
|