mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
* refactor(app): export one function per command Step 2 of #710. A command's logic was split between cmd and stage-shaped app calls; cmd now parses flags, calls one function and prints what it returns. An error means the command never ran, and a run that ended early says so in Summary.Err. * fix(app): check dumpkeys and archive -o up front A missing output directory was reported only after the keys were retrieved or the files copied. * docs(rfcs): move restore's input out of the command layer Restore now discovers its directories in an archive itself, so the command layer no longer holds the data it reads.
43 lines
1.2 KiB
Go
43 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 passwordFlags
|
|
)
|
|
|
|
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
|
|
}
|
|
vaultCount, err := app.DumpKeys(command.Context(), options, command.OutOrStdout())
|
|
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(&flags.OutputPath, "output", "o", "", "output file (default: stdout)")
|
|
addPasswordFlags(command, &keychain, "keychain-pw", "macOS keychain password")
|
|
|
|
return command
|
|
}
|