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,20 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/browser"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/app"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
)
|
||||
|
||||
func dumpKeysCmd() *cobra.Command {
|
||||
var (
|
||||
browserName string
|
||||
outputPath string
|
||||
keychainPw string
|
||||
f app.Flags
|
||||
outputPath string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -23,32 +23,27 @@ func dumpKeysCmd() *cobra.Command {
|
||||
Example: ` hack-browser-data dumpkeys -o keys.json
|
||||
hack-browser-data dumpkeys -b chrome`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
browsers, err := browser.DiscoverBrowsersWithKeys(browser.DiscoverOptions{
|
||||
Name: browserName,
|
||||
KeychainPassword: keychainPw,
|
||||
})
|
||||
req, err := app.ValidateKeys(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dump := browser.BuildDump(browsers)
|
||||
dump := app.DumpKeys(cmd.Context(), app.Discover(req), req)
|
||||
log.Infof("Exported keys for %d vault(s)", len(dump.Vaults))
|
||||
|
||||
if outputPath == "" {
|
||||
return dump.WriteJSON(os.Stdout)
|
||||
}
|
||||
f, err := os.OpenFile(outputPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
|
||||
file, err := os.OpenFile(outputPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create %s: %w", outputPath, err)
|
||||
}
|
||||
defer f.Close()
|
||||
return dump.WriteJSON(f)
|
||||
return errors.Join(dump.WriteJSON(file), file.Close())
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&browserName, "browser", "b", "all", "target browser: all|"+browser.Names())
|
||||
cmd.Flags().StringVarP(&f.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
|
||||
cmd.Flags().StringVarP(&outputPath, "output", "o", "", "output file (default: stdout)")
|
||||
cmd.Flags().StringVar(&keychainPw, "keychain-pw", "", "macOS keychain password")
|
||||
keychainPasswordFlags(cmd, &f)
|
||||
|
||||
return cmd
|
||||
}
|
||||
Reference in new issue
Block a user