fix: report unreadable sources and tidy the pipeline (#675)

A Stat error other than not-exist was reported as absent, and the --zip archive was readable by other users.
The rest is review follow-up: export no longer prints, one runner type, shared name helpers, a trimmed log API.
This commit is contained in:
Roger authored and GitHub committed 2026-11-01 23:42:13 +08:00
1 parent 6d6191b4c6
commit 4e98ba7884
33 files changed
+303 -315

No files matched your search

+5 -4
View File
@@ -2,6 +2,7 @@ package main
import (
"context"
"io"
"github.com/spf13/cobra"
@@ -21,7 +22,7 @@ func dumpCmd() *cobra.Command {
hack-browser-data dump -f cookie-editor
hack-browser-data dump --zip`,
RunE: func(cmd *cobra.Command, args []string) error {
return runDump(cmd.Context(), f)
return runDump(cmd.Context(), cmd.ErrOrStderr(), f)
},
}
@@ -42,7 +43,7 @@ func keychainPasswordFlags(cmd *cobra.Command, f *app.Flags) {
cmd.MarkFlagsMutuallyExclusive("keychain-pw", "keychain-pw-stdin")
}
func runDump(ctx context.Context, f app.Flags) error {
func runDump(ctx context.Context, stderr io.Writer, f app.Flags) error {
req, err := app.Validate(f)
if err != nil {
return err
@@ -50,14 +51,14 @@ func runDump(ctx context.Context, f app.Flags) error {
d := app.Discover(req)
if len(d.Dirs) == 0 {
if len(d.Failed) > 0 {
report(app.Summary{Results: d.Failed})
report(stderr, app.Summary{Results: d.Failed})
}
log.Warnf("no browsers found")
return nil
}
summary, err := app.Execute(ctx, app.NewPlan(d, req), req)
if ctx.Err() == nil {
report(summary)
report(stderr, summary)
}
return err
}
+1 -2
View File
@@ -13,9 +13,8 @@ import (
"github.com/moond4rk/hackbrowserdata/internal/log"
)
var verbose bool
func rootCmd() *cobra.Command {
var verbose bool
root := &cobra.Command{
Use: "hack-browser-data",
Short: "A CLI tool for decrypting and exporting browser data",
+5 -18
View File
@@ -1,8 +1,7 @@
package main
import (
"os"
"sort"
"io"
"strings"
"github.com/moond4rk/hackbrowserdata/internal/app"
@@ -11,29 +10,17 @@ import (
"github.com/moond4rk/hackbrowserdata/internal/log"
)
// browserNames lists this OS's browser IDs for the usage strings, sorted as they have always been listed.
func browserNames() string {
defs := browser.Supported()
ids := make([]string, 0, len(defs))
for _, d := range defs {
ids = append(ids, d.ID)
}
sort.Strings(ids)
return strings.Join(ids, "|")
return strings.Join(browser.IDs(), "|")
}
func categoryNames() string {
all := category.All()
names := make([]string, len(all))
for i, c := range all {
names[i] = c.String()
}
return strings.Join(names, ",")
return strings.Join(category.Names(), ",")
}
// report prints the run's summary; it is not part of the output, so failing to print it never fails the run.
func report(s app.Summary) {
if err := app.Report(os.Stderr, s); err != nil {
func report(w io.Writer, s app.Summary) {
if err := app.Report(w, s); err != nil {
log.Warnf("print summary: %v", err)
}
}
+4 -3
View File
@@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"io"
"github.com/spf13/cobra"
@@ -22,7 +23,7 @@ func restoreCmd() *cobra.Command {
hack-browser-data restore --keys keys.json --data-dir ./chrome-userdata -b chrome
ssh origin "hack-browser-data dumpkeys" | hack-browser-data restore --keys - --data-zip data.zip`,
RunE: func(cmd *cobra.Command, args []string) error {
return runRestore(cmd.Context(), f)
return runRestore(cmd.Context(), cmd.ErrOrStderr(), f)
},
}
@@ -41,7 +42,7 @@ func restoreCmd() *cobra.Command {
return cmd
}
func runRestore(ctx context.Context, f app.RestoreFlags) error {
func runRestore(ctx context.Context, stderr io.Writer, f app.RestoreFlags) error {
req, dump, err := app.ValidateRestore(f)
if err != nil {
return err
@@ -63,7 +64,7 @@ func runRestore(ctx context.Context, f app.RestoreFlags) error {
req.Keys = keys
summary, err := app.Execute(ctx, app.NewPlan(d, req), req)
if ctx.Err() == nil {
report(summary)
report(stderr, summary)
}
return err
}