mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: run every command on the pipeline (#665)
dump, dumpkeys, archive, restore, and list now run on the app stages, so cmd's old path goes away. archive writes manifest.json and restore reads it, falling back to today's layout for older archives. Windows and macOS smoke matched today's output apart from the planned changes.
This commit is contained in:
1 parent
cebfa97ed6
commit
bbd353f314
45 files changed
+1516
-664
No files matched your search
@@ -1,22 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/browser"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/app"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
)
|
||||
|
||||
func dumpCmd() *cobra.Command {
|
||||
var (
|
||||
browserName string
|
||||
category string
|
||||
outputFormat string
|
||||
outputDir string
|
||||
profilePath string
|
||||
keychainPw string
|
||||
compress bool
|
||||
)
|
||||
var f app.Flags
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "dump",
|
||||
@@ -27,33 +21,41 @@ func dumpCmd() *cobra.Command {
|
||||
hack-browser-data dump -f cookie-editor
|
||||
hack-browser-data dump --zip`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
browsers, err := browser.DiscoverBrowsersWithKeys(browser.DiscoverOptions{
|
||||
Name: browserName,
|
||||
ProfilePath: profilePath,
|
||||
KeychainPassword: keychainPw,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(browsers) == 0 {
|
||||
log.Warnf("no browsers found")
|
||||
return nil
|
||||
}
|
||||
categories, err := parseCategories(category)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return extractAndWrite(browsers, categories, outputDir, outputFormat, compress)
|
||||
return runDump(cmd.Context(), f)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&browserName, "browser", "b", "all", "target browser: all|"+browser.Names())
|
||||
cmd.Flags().StringVarP(&category, "category", "c", "all", "data categories (comma-separated): all|"+categoryNames())
|
||||
cmd.Flags().StringVarP(&outputFormat, "format", "f", "json", "output format: csv|json|cookie-editor")
|
||||
cmd.Flags().StringVarP(&outputDir, "dir", "d", "results", "output directory")
|
||||
cmd.Flags().StringVarP(&profilePath, "profile-path", "p", "", "custom profile dir path, get with chrome://version")
|
||||
cmd.Flags().StringVar(&keychainPw, "keychain-pw", "", "macOS keychain password")
|
||||
cmd.Flags().BoolVar(&compress, "zip", false, "compress output to zip")
|
||||
cmd.Flags().StringVarP(&f.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
|
||||
cmd.Flags().StringVarP(&f.Categories, "category", "c", "all", "data categories (comma-separated): all|"+categoryNames())
|
||||
cmd.Flags().StringVarP(&f.Format, "format", "f", "json", "output format: csv|json|cookie-editor")
|
||||
cmd.Flags().StringVarP(&f.Dir, "dir", "d", "results", "output directory")
|
||||
cmd.Flags().StringVarP(&f.ProfilePath, "profile-path", "p", "", "custom profile dir path, get with chrome://version")
|
||||
keychainPasswordFlags(cmd, &f)
|
||||
cmd.Flags().BoolVar(&f.Zip, "zip", false, "compress output to zip")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func keychainPasswordFlags(cmd *cobra.Command, f *app.Flags) {
|
||||
cmd.Flags().StringVar(&f.KeychainPassword, "keychain-pw", "", "macOS keychain password (visible in ps and shell history)")
|
||||
cmd.Flags().BoolVar(&f.KeychainPasswordStdin, "keychain-pw-stdin", false, "read the macOS keychain password from the first line of stdin")
|
||||
cmd.MarkFlagsMutuallyExclusive("keychain-pw", "keychain-pw-stdin")
|
||||
}
|
||||
|
||||
func runDump(ctx context.Context, f app.Flags) error {
|
||||
req, err := app.Validate(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d := app.Discover(req)
|
||||
if len(d.Dirs) == 0 {
|
||||
if len(d.Failed) > 0 {
|
||||
report(app.Summary{Results: d.Failed})
|
||||
}
|
||||
log.Warnf("no browsers found")
|
||||
return nil
|
||||
}
|
||||
summary, err := app.Execute(ctx, app.NewPlan(d, req), req)
|
||||
report(summary)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user