diff --git a/cmd/hack-browser-data/main.go b/cmd/hack-browser-data/main.go index f40f15a..d0b9ccd 100644 --- a/cmd/hack-browser-data/main.go +++ b/cmd/hack-browser-data/main.go @@ -49,6 +49,7 @@ GitHub: https://github.com/moonD4rk/HackBrowserData`, } func main() { + configureDoubleClickMode() if err := rootCmd().Execute(); err != nil { os.Exit(1) } diff --git a/cmd/hack-browser-data/main_others.go b/cmd/hack-browser-data/main_others.go new file mode 100644 index 0000000..61e7611 --- /dev/null +++ b/cmd/hack-browser-data/main_others.go @@ -0,0 +1,5 @@ +//go:build !windows + +package main + +func configureDoubleClickMode() {} diff --git a/cmd/hack-browser-data/main_windows.go b/cmd/hack-browser-data/main_windows.go new file mode 100644 index 0000000..2eeeee0 --- /dev/null +++ b/cmd/hack-browser-data/main_windows.go @@ -0,0 +1,21 @@ +//go:build windows + +package main + +import ( + "github.com/inconshreveable/mousetrap" + "github.com/spf13/cobra" + + "github.com/moond4rk/hackbrowserdata/utils/winapi" +) + +// configureDoubleClickMode hides the console and bypasses cobra's +// double-click guard when launched from Explorer (issue #344). +func configureDoubleClickMode() { + if !mousetrap.StartedByExplorer() { + return + } + + cobra.MousetrapHelpText = "" + winapi.HideConsoleWindow() +} diff --git a/go.mod b/go.mod index 554dbcb..56b32e4 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/godbus/dbus/v5 v5.2.2 + github.com/inconshreveable/mousetrap v1.1.0 github.com/moond4rk/binarycookies v1.0.2 github.com/moond4rk/keychainbreaker v0.2.5 github.com/moond4rk/plist v1.2.0 @@ -25,7 +26,6 @@ require ( github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect github.com/otiai10/mint v1.6.3 // indirect diff --git a/utils/winapi/console_windows.go b/utils/winapi/console_windows.go new file mode 100644 index 0000000..5372c5f --- /dev/null +++ b/utils/winapi/console_windows.go @@ -0,0 +1,21 @@ +//go:build windows + +package winapi + +var ( + procGetConsoleWindow = Kernel32.NewProc("GetConsoleWindow") + procShowWindow = User32.NewProc("ShowWindow") +) + +const swHide = 0 + +// HideConsoleWindow hides the console window attached to the current +// process. Returns true if the window was previously visible. +func HideConsoleWindow() bool { + hwnd, _, _ := procGetConsoleWindow.Call() + if hwnd == 0 { + return false + } + prev, _, _ := procShowWindow.Call(hwnd, swHide) + return prev != 0 +} diff --git a/utils/winapi/winapi_windows.go b/utils/winapi/winapi_windows.go index be49287..c6d624d 100644 --- a/utils/winapi/winapi_windows.go +++ b/utils/winapi/winapi_windows.go @@ -24,6 +24,7 @@ var ( Kernel32 = windows.NewLazySystemDLL("kernel32.dll") Ntdll = windows.NewLazySystemDLL("ntdll.dll") Crypt32 = windows.NewLazySystemDLL("crypt32.dll") + User32 = windows.NewLazySystemDLL("user32.dll") ) // CallBoolErr wraps the common "r1 == 0 means failure" Win32 convention.