Skip to content

fix(windows): silent default dump on double-click#591

Merged
moonD4rk merged 3 commits intomainfrom
fix/issue-344-double-click-silent
Apr 27, 2026
Merged

fix(windows): silent default dump on double-click#591
moonD4rk merged 3 commits intomainfrom
fix/issue-344-double-click-silent

Conversation

@moonD4rk
Copy link
Copy Markdown
Owner

Summary

  • Detect Explorer-launched binaries (double-click) via cobra's mousetrap dependency and hide the auto-created console window
  • The .exe runs the default dump -b all -c all silently, writing results/ next to the .exe
  • Command-line invocations (cmd.exe / PowerShell) are unchanged: full cobra CLI, all flags, verbose logging continue to work as before

Implementation

  • cmd/hack-browser-data/main_windows.go — Windows-only; calls mousetrap.StartedByExplorer() and user32!ShowWindow to hide console
  • cmd/hack-browser-data/main_others.go — No-op stub for non-Windows platforms
  • cmd/hack-browser-data/main.go — Calls configureDoubleClickMode() as the first line of main()
  • mousetrap upgraded from indirect → direct dependency

Test plan

  • macOS / Linux build unchanged (stub is no-op)
  • Windows cross-compile produces 11M binary (size unchanged from previous releases)
  • CLI mode on Windows sandbox: hbd.exe -c password shows full logs, exports 6 passwords with ABE retrieval intact (parent=ssh, mousetrap.StartedByExplorer() → false, configureDoubleClickMode no-op)
  • Double-click via Shell.Application.ShellExecute (parent=explorer.exe) — manually verified by maintainer: no cmd window, results written silently next to the .exe

Closes #344.

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.
Copilot AI review requested due to automatic review settings April 27, 2026 06:02
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.60%. Comparing base (5c0b1ad) to head (cff501c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #591   +/-   ##
=======================================
  Coverage   73.60%   73.60%           
=======================================
  Files          61       61           
  Lines        2815     2815           
=======================================
  Hits         2072     2072           
  Misses        553      553           
  Partials      190      190           
Flag Coverage Δ
unittests 73.60% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a Windows-only “double-click mode” so Explorer-launched executions don’t show Cobra’s mousetrap warning and the console window is hidden, while keeping normal CLI behavior unchanged.

Changes:

  • Promote github.com/inconshreveable/mousetrap to a direct dependency for Explorer-launch detection.
  • Add configureDoubleClickMode() with Windows and non-Windows implementations.
  • Invoke configureDoubleClickMode() at the start of main().

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
go.mod Adds mousetrap as a direct dependency to support Windows double-click detection.
cmd/hack-browser-data/main.go Calls configureDoubleClickMode() before executing the Cobra root command.
cmd/hack-browser-data/main_windows.go Windows implementation: detect Explorer launch, disable Cobra mousetrap help text, and hide the console window via Win32 APIs.
cmd/hack-browser-data/main_others.go Non-Windows stub implementation (no-op).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/hack-browser-data/main_windows.go Outdated
Comment on lines +13 to +18
var (
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
user32 = windows.NewLazySystemDLL("user32.dll")
procGetConsoleWindow = kernel32.NewProc("GetConsoleWindow")
procShowWindow = user32.NewProc("ShowWindow")
)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reintroduces per-file NewLazySystemDLL/NewProc boilerplate and bypasses the existing utils/winapi convention that centralizes Win32 DLL/proc handles + error-handling (see utils/winapi/winapi_windows.go:3-45). Consider moving GetConsoleWindow/ShowWindow proc definitions (and a User32 handle) into utils/winapi and calling a typed wrapper from here, so future Win32 calls follow one pattern and can share consistent error handling.

Copilot uses AI. Check for mistakes.
Move ShowWindow / GetConsoleWindow proc declarations into utils/winapi
to follow the existing centralization convention (see review feedback).
Adds a User32 LazyDLL handle and a typed HideConsoleWindow() wrapper.

main_windows.go is now a thin caller that uses the wrapper.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +52 to 55
configureDoubleClickMode()
if err := rootCmd().Execute(); err != nil {
os.Exit(1)
}
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When StartedByExplorer() is true, the console is hidden and cobra’s mousetrap help is suppressed, but errors from rootCmd().Execute() still only surface via stderr and exit code. In double-click mode this can lead to “nothing happened” with no user-visible diagnostics if extraction fails (e.g., permission issues writing results). Consider special-casing Explorer launches to persist errors to a log file under the output directory and/or showing a Windows dialog for fatal errors, while keeping CLI behavior unchanged for terminal launches.

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +20
func configureDoubleClickMode() {
if !mousetrap.StartedByExplorer() {
return
}

cobra.MousetrapHelpText = ""
winapi.HideConsoleWindow()
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Explorer/double-click mode the default output dir is still the relative "results" (see dump.go), so where data is written depends on the current working directory. If a user launches via a shortcut or ShellExecute with a different working dir, results may not end up next to the .exe as described in the PR. Consider, when StartedByExplorer() is true, setting the process working directory to the executable’s directory (os.Executable + filepath.Dir + os.Chdir) or otherwise resolving the output path relative to the .exe to make the behavior deterministic.

Copilot uses AI. Check for mistakes.
Capture ShowWindow's previous-visibility return as the function's
boolean result instead of dropping all three returns with a blank
assignment. Cleaner than blank-identifier juggling and gives the
caller actionable info if needed.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@moonD4rk moonD4rk merged commit 439ff52 into main Apr 27, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Double-click to execute without popping up the command line black box.

3 participants