rclone/lib/terminal/hidden_windows.go
albertony 7692ef289f Replace Windows-specific NewLazyDLL with NewLazySystemDLL
This will only search Windows System directory for the DLL if name is a base
name (like "advapi32.dll"), which prevents DLL preloading attacks.

To get access to NewLazySystemDLL imports of syscall needs to be swapped with
golang.org/x/sys/windows.
2025-01-08 17:35:00 +01:00

20 lines
503 B
Go

//go:build windows
package terminal
import (
"golang.org/x/sys/windows"
)
// HideConsole hides the console window and activates another window
func HideConsole() {
getConsoleWindow := windows.NewLazySystemDLL("kernel32.dll").NewProc("GetConsoleWindow")
showWindow := windows.NewLazySystemDLL("user32.dll").NewProc("ShowWindow")
if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
hwnd, _, _ := getConsoleWindow.Call()
if hwnd != 0 {
_, _, _ = showWindow.Call(hwnd, 0)
}
}
}