mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-06 05:53:25 +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.
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/app"
|
|
)
|
|
|
|
func newDumpCommand() *cobra.Command {
|
|
var (
|
|
flags app.DumpFlags
|
|
keychain passwordFlags
|
|
firefox passwordFlags
|
|
)
|
|
|
|
command := &cobra.Command{
|
|
Use: "dump",
|
|
Short: "Extract and decrypt browser data (default command)",
|
|
Example: ` hack-browser-data dump
|
|
hack-browser-data dump -b chrome -c password,cookie
|
|
hack-browser-data dump -b chrome -f json -d output
|
|
hack-browser-data dump -f cookie-editor
|
|
hack-browser-data dump --zip`,
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
return runDump(command.Context(), command.ErrOrStderr(), flags, keychain, firefox)
|
|
},
|
|
}
|
|
|
|
command.Flags().StringVarP(&flags.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
|
|
command.Flags().StringVarP(&flags.Categories, "category", "c", "all", "data categories (comma-separated): all|"+categoryNames())
|
|
command.Flags().StringVarP(&flags.ProfilePath, "profile-path", "p", "", "custom profile dir path, get with chrome://version")
|
|
addOutputFlags(command, &flags.Output)
|
|
addPasswordFlags(command, &keychain, "keychain-pw", "macOS keychain password")
|
|
addPasswordFlags(command, &firefox, "firefox-pw", "Firefox primary password")
|
|
command.MarkFlagsMutuallyExclusive("keychain-pw-stdin", "firefox-pw-stdin")
|
|
|
|
return command
|
|
}
|
|
|
|
func runDump(ctx context.Context, stderr io.Writer, flags app.DumpFlags, keychain, firefox passwordFlags) error {
|
|
options, err := app.ValidateDump(flags, keychainPasswordFunc(keychain, os.Stdin), firefoxPasswordFunc(firefox, os.Stdin))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
discovery, summary, err := app.Dump(ctx, options)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(discovery.Dirs) == 0 {
|
|
printNothingFound(stderr, discovery, "no browsers found")
|
|
return nil
|
|
}
|
|
printExported(stderr, summary.Exported)
|
|
if ctx.Err() == nil {
|
|
printSummary(stderr, summary)
|
|
}
|
|
return summary.Err
|
|
}
|