Skip to content

Commit 439ff52

Browse files
authored
fix(windows): silent default dump on double-click (#591)
1 parent 5c0b1ad commit 439ff52

6 files changed

Lines changed: 50 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"github.com/inconshreveable/mousetrap"
7+
"github.com/spf13/cobra"
8+
9+
"github.com/moond4rk/hackbrowserdata/utils/winapi"
10+
)
11+
12+
// configureDoubleClickMode hides the console and bypasses cobra's
13+
// double-click guard when launched from Explorer (issue #344).
14+
func configureDoubleClickMode() {
15+
if !mousetrap.StartedByExplorer() {
16+
return
17+
}
18+
19+
cobra.MousetrapHelpText = ""
20+
winapi.HideConsoleWindow()
21+
}

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

utils/winapi/console_windows.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build windows
2+
3+
package winapi
4+
5+
var (
6+
procGetConsoleWindow = Kernel32.NewProc("GetConsoleWindow")
7+
procShowWindow = User32.NewProc("ShowWindow")
8+
)
9+
10+
const swHide = 0
11+
12+
// HideConsoleWindow hides the console window attached to the current
13+
// process. Returns true if the window was previously visible.
14+
func HideConsoleWindow() bool {
15+
hwnd, _, _ := procGetConsoleWindow.Call()
16+
if hwnd == 0 {
17+
return false
18+
}
19+
prev, _, _ := procShowWindow.Call(hwnd, swHide)
20+
return prev != 0
21+
}

utils/winapi/winapi_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var (
2424
Kernel32 = windows.NewLazySystemDLL("kernel32.dll")
2525
Ntdll = windows.NewLazySystemDLL("ntdll.dll")
2626
Crypt32 = windows.NewLazySystemDLL("crypt32.dll")
27+
User32 = windows.NewLazySystemDLL("user32.dll")
2728
)
2829

2930
// CallBoolErr wraps the common "r1 == 0 means failure" Win32 convention.

0 commit comments

Comments
 (0)