Files
HackBrowserData/cmd/hack-browser-data/dumpkeys.go
T
Roger 7e6f325508 refactor(app): per-stage inputs and per-dir planning (#689)
* refactor(app): per-command flags and per-stage inputs

One Options bag fed every stage and cmd patched restore's keys into it after validation; each stage now takes what it
reads, dir-level failures are their own type, and cmd prints what a run exported.

* refactor(app): group the plan by dir and profile

Execute now walks the plan's own shape instead of filtering a flat list and looking profiles up by name.

* refactor(app): file code by command and stage

Pure moves: each command's flags and validation sit beside its stage, and execute.go keeps only the runner.

* refactor: read the keychain password in cmd

Prompting and reading stdin are terminal work, so app now receives the password func; cobra already rejects both flags.

* refactor(app): plan each user data dir right before it runs

A run-wide Plan had to drop its extractors and rebuild them with the keychain; per-dir planning keeps one extractor.
2026-11-09 17:25:36 +08:00

45 lines
1.2 KiB
Go

package main
import (
"os"
"github.com/spf13/cobra"
"github.com/moond4rk/hackbrowserdata/internal/app"
"github.com/moond4rk/hackbrowserdata/internal/log"
)
func newDumpKeysCommand() *cobra.Command {
var (
flags app.DumpKeysFlags
keychain keychainFlags
outputPath string
)
command := &cobra.Command{
Use: "dumpkeys",
Short: "Export Chromium master keys as JSON for cross-host decryption",
Example: ` hack-browser-data dumpkeys -o keys.json
hack-browser-data dumpkeys -b chrome`,
RunE: func(command *cobra.Command, args []string) error {
options, err := app.ValidateDumpKeys(flags, keychainPasswordFunc(keychain, os.Stdin))
if err != nil {
return err
}
discovery := app.Discover(options.Target)
vaultCount, err := app.DumpKeys(command.Context(), discovery, options.Keychain, command.OutOrStdout(), outputPath)
if err != nil {
return err
}
log.Infof("Exported keys for %d vault(s)", vaultCount)
return nil
},
}
command.Flags().StringVarP(&flags.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
command.Flags().StringVarP(&outputPath, "output", "o", "", "output file (default: stdout)")
addKeychainPasswordFlags(command, &keychain)
return command
}