mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
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.
This commit is contained in:
1 parent
fed6c722e2
commit
7e6f325508
39 files changed
+936
-805
No files matched your search
@@ -3,15 +3,18 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/app"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
)
|
||||
|
||||
func newDumpCommand() *cobra.Command {
|
||||
var flags app.Flags
|
||||
var (
|
||||
flags app.DumpFlags
|
||||
keychain keychainFlags
|
||||
)
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "dump",
|
||||
@@ -22,7 +25,7 @@ func newDumpCommand() *cobra.Command {
|
||||
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)
|
||||
return runDump(command.Context(), command.ErrOrStderr(), flags, keychain)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -31,33 +34,23 @@ func newDumpCommand() *cobra.Command {
|
||||
command.Flags().StringVarP(&flags.Format, "format", "f", "json", "output format: csv|json|cookie-editor")
|
||||
command.Flags().StringVarP(&flags.OutputDir, "dir", "d", "results", "output directory")
|
||||
command.Flags().StringVarP(&flags.ProfilePath, "profile-path", "p", "", "custom profile dir path, get with chrome://version")
|
||||
addKeychainPasswordFlags(command, &flags)
|
||||
addKeychainPasswordFlags(command, &keychain)
|
||||
command.Flags().BoolVar(&flags.Zip, "zip", false, "compress output to zip")
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
func addKeychainPasswordFlags(command *cobra.Command, flags *app.Flags) {
|
||||
command.Flags().StringVar(&flags.KeychainPassword, "keychain-pw", "", "macOS keychain password (visible in ps and shell history)")
|
||||
command.Flags().BoolVar(&flags.KeychainPasswordStdin, "keychain-pw-stdin", false,
|
||||
"read the macOS keychain password from the first line of stdin")
|
||||
command.MarkFlagsMutuallyExclusive("keychain-pw", "keychain-pw-stdin")
|
||||
}
|
||||
|
||||
func runDump(ctx context.Context, stderr io.Writer, flags app.Flags) error {
|
||||
options, err := app.ValidateDump(flags)
|
||||
func runDump(ctx context.Context, stderr io.Writer, flags app.DumpFlags, keychain keychainFlags) error {
|
||||
options, err := app.ValidateDump(flags, keychainPasswordFunc(keychain, os.Stdin))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
discovery := app.Discover(options)
|
||||
if len(discovery.Dirs) == 0 {
|
||||
if len(discovery.Errors) > 0 {
|
||||
report(stderr, app.Summary{Results: discovery.Errors})
|
||||
}
|
||||
log.Warnf("no browsers found")
|
||||
discovery := app.Discover(options.Target)
|
||||
if foundNothing(stderr, discovery, "no browsers found") {
|
||||
return nil
|
||||
}
|
||||
summary, err := app.Execute(ctx, app.NewPlan(discovery, options), options)
|
||||
summary, err := app.Execute(ctx, discovery, options.Categories, options.Output, options.Keychain)
|
||||
announceExport(stderr, summary.Exported)
|
||||
if ctx.Err() == nil {
|
||||
report(stderr, summary)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user