Skip to content

Commit f67662d

Browse files
committed
fix(windows): silent default dump on double-click
Detect Explorer-launched binaries via mousetrap and hide the auto-created console window so the .exe runs the default dump silently. Command-line invocations are unaffected. Closes #344.
1 parent 5c0b1ad commit f67662d

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

cmd/hack-browser-data/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ GitHub: https://github.com/moonD4rk/HackBrowserData`,
4949
}
5050

5151
func main() {
52+
configureDoubleClickMode()
5253
if err := rootCmd().Execute(); err != nil {
5354
os.Exit(1)
5455
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build !windows
2+
3+
package main
4+
5+
func configureDoubleClickMode() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"github.com/inconshreveable/mousetrap"
7+
"github.com/spf13/cobra"
8+
"golang.org/x/sys/windows"
9+
)
10+
11+
const swHide = 0
12+
13+
var (
14+
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
15+
user32 = windows.NewLazySystemDLL("user32.dll")
16+
procGetConsoleWindow = kernel32.NewProc("GetConsoleWindow")
17+
procShowWindow = user32.NewProc("ShowWindow")
18+
)
19+
20+
// configureDoubleClickMode hides the console and bypasses cobra's
21+
// double-click guard when launched from Explorer (issue #344).
22+
func configureDoubleClickMode() {
23+
if !mousetrap.StartedByExplorer() {
24+
return
25+
}
26+
27+
cobra.MousetrapHelpText = ""
28+
29+
hwnd, _, _ := procGetConsoleWindow.Call()
30+
if hwnd != 0 {
31+
_, _, _ = procShowWindow.Call(hwnd, swHide)
32+
}
33+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.20
44

55
require (
66
github.com/godbus/dbus/v5 v5.2.2
7+
github.com/inconshreveable/mousetrap v1.1.0
78
github.com/moond4rk/binarycookies v1.0.2
89
github.com/moond4rk/keychainbreaker v0.2.5
910
github.com/moond4rk/plist v1.2.0
@@ -25,7 +26,6 @@ require (
2526
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
2627
github.com/google/uuid v1.6.0 // indirect
2728
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
28-
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2929
github.com/mattn/go-isatty v0.0.20 // indirect
3030
github.com/ncruces/go-strftime v0.1.9 // indirect
3131
github.com/otiai10/mint v1.6.3 // indirect

0 commit comments

Comments
 (0)