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
@@ -3,12 +3,14 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/browser"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/app"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
)
|
||||
|
||||
func listCmd() *cobra.Command {
|
||||
@@ -20,18 +22,26 @@ func listCmd() *cobra.Command {
|
||||
Example: ` hack-browser-data list
|
||||
hack-browser-data list --detail`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
browsers, err := browser.DiscoverBrowsers(browser.DiscoverOptions{Name: "all"})
|
||||
req, err := app.ListRequest()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(browsers) == 0 {
|
||||
d := app.Discover(req)
|
||||
for _, r := range d.Failed {
|
||||
log.Warnf("%s: %v", r.DirID, r.Err)
|
||||
}
|
||||
if len(d.Dirs) == 0 {
|
||||
cmd.Println("No browsers found.")
|
||||
return nil
|
||||
}
|
||||
if detail {
|
||||
return printDetail(cmd.OutOrStdout(), browsers)
|
||||
if !detail {
|
||||
return printBasic(cmd.OutOrStdout(), d)
|
||||
}
|
||||
return printBasic(cmd.OutOrStdout(), browsers)
|
||||
summary, err := app.Count(cmd.Context(), app.NewPlan(d, req), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return printDetail(cmd.OutOrStdout(), d, summary)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -39,32 +49,34 @@ func listCmd() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func printBasic(out io.Writer, browsers []browser.Browser) error {
|
||||
func printBasic(out io.Writer, d app.Discovery) error {
|
||||
w := tabwriter.NewWriter(out, 0, 0, 3, ' ', 0)
|
||||
fmt.Fprintln(w, "Browser\tProfile\tPath")
|
||||
for _, b := range browsers {
|
||||
for _, p := range b.Profiles() {
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\n", b.BrowserName(), p.Name, p.Dir)
|
||||
for _, dir := range d.Dirs {
|
||||
for _, p := range dir.Profiles {
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\n", dir.Def.Name, p.Name, filepath.Join(dir.Path, filepath.FromSlash(p.Dir)))
|
||||
}
|
||||
}
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
func printDetail(out io.Writer, browsers []browser.Browser) error {
|
||||
// Build header: Browser Profile Password Cookie ...
|
||||
func printDetail(out io.Writer, d app.Discovery, s app.Summary) error {
|
||||
counts := make(map[app.Extraction]int, len(s.Results))
|
||||
for _, r := range s.Results {
|
||||
counts[r.Extraction] = r.Count
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(out, 0, 0, 3, ' ', 0)
|
||||
fmt.Fprint(w, "Browser\tProfile")
|
||||
for _, c := range category.All() {
|
||||
fmt.Fprintf(w, "\t%s", c.String())
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
|
||||
for _, b := range browsers {
|
||||
results, _ := b.CountEntries(category.All())
|
||||
for _, r := range results {
|
||||
fmt.Fprintf(w, "%s\t%s", b.BrowserName(), r.Name)
|
||||
for _, dir := range d.Dirs {
|
||||
for _, p := range dir.Profiles {
|
||||
fmt.Fprintf(w, "%s\t%s", dir.Def.Name, p.Name)
|
||||
for _, c := range category.All() {
|
||||
fmt.Fprintf(w, "\t%d", r.Counts[c])
|
||||
fmt.Fprintf(w, "\t%d", counts[app.Extraction{DirID: dir.ID, Profile: p.Name, Category: c}])
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user