mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: name dirs by what they hold, trim exports (#692)
Bare dir now always means a user data dir, so the snapshot root, the export listing, and the keys.json kind get their own words; names used only inside their package are no longer exported.
This commit is contained in:
1 parent
2e7ee3c69f
commit
a7741eaab2
40 files changed
+242
-256
No files matched your search
@@ -24,7 +24,7 @@ func newArchiveCommand() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
discovery := app.Discover(options.Target)
|
||||
if foundNothing(command.ErrOrStderr(), discovery, "no browsers found") {
|
||||
if warnIfNothingFound(command.ErrOrStderr(), discovery, "no browsers found") {
|
||||
return nil
|
||||
}
|
||||
fileCount, err := app.Archive(command.Context(), discovery, options.Categories, outputPath)
|
||||
|
||||
@@ -46,7 +46,7 @@ func runDump(ctx context.Context, stderr io.Writer, flags app.DumpFlags, keychai
|
||||
return err
|
||||
}
|
||||
discovery := app.Discover(options.Target)
|
||||
if foundNothing(stderr, discovery, "no browsers found") {
|
||||
if warnIfNothingFound(stderr, discovery, "no browsers found") {
|
||||
return nil
|
||||
}
|
||||
summary, err := app.Execute(ctx, discovery, options.Categories, options.Output, options.Keychain)
|
||||
|
||||
@@ -80,8 +80,8 @@ func report(writer io.Writer, summary app.Summary) {
|
||||
}
|
||||
}
|
||||
|
||||
// foundNothing reports discovery's failures, the likely reason it found no browser data, then says so.
|
||||
func foundNothing(stderr io.Writer, discovery app.Discovery, message string) bool {
|
||||
// warnIfNothingFound reports discovery's failures, the likely reason it found no browser data, then says so.
|
||||
func warnIfNothingFound(stderr io.Writer, discovery app.Discovery, message string) bool {
|
||||
if len(discovery.Dirs) > 0 {
|
||||
return false
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func foundNothing(stderr io.Writer, discovery app.Discovery, message string) boo
|
||||
}
|
||||
|
||||
// announceExport lists the files a run wrote, even when it stopped early, so the user finds what it left.
|
||||
func announceExport(stderr io.Writer, exported export.Output) {
|
||||
func announceExport(stderr io.Writer, exported export.Listing) {
|
||||
if len(exported.Files) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -47,17 +47,17 @@ func runRestore(ctx context.Context, stderr io.Writer, flags app.RestoreFlags) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := openRestoreData(flags.DataDir, flags.DataZip)
|
||||
root, err := openRestoreData(flags.DataDir, flags.DataZip)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer closeRestoreData(data)
|
||||
defer closeRestoreData(root)
|
||||
|
||||
discovery, keys, err := app.DiscoverRestore(data.Path(), keyFile, options.Target.BrowserName)
|
||||
discovery, keys, err := app.DiscoverRestore(root.Path(), keyFile, options.Target.BrowserName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if foundNothing(stderr, discovery, "no browsers to restore from the supplied keys and data") {
|
||||
if warnIfNothingFound(stderr, discovery, "no browsers to restore from the supplied keys and data") {
|
||||
return nil
|
||||
}
|
||||
summary, err := app.ExecuteWithKeys(ctx, discovery, options.Categories, options.Output, keys)
|
||||
@@ -68,19 +68,19 @@ func runRestore(ctx context.Context, stderr io.Writer, flags app.RestoreFlags) e
|
||||
return err
|
||||
}
|
||||
|
||||
func openRestoreData(dataDir, dataZip string) (*snapshot.Dir, error) {
|
||||
func openRestoreData(dataDir, dataZip string) (*snapshot.Root, error) {
|
||||
if dataDir != "" {
|
||||
return snapshot.Open(dataDir), nil
|
||||
}
|
||||
snapshots, err := snapshot.Unzip(dataZip)
|
||||
root, err := snapshot.Unzip(dataZip)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("extract %s: %w", dataZip, err)
|
||||
}
|
||||
return snapshots, nil
|
||||
return root, nil
|
||||
}
|
||||
|
||||
func closeRestoreData(snapshots *snapshot.Dir) {
|
||||
if err := snapshots.Close(); err != nil {
|
||||
func closeRestoreData(root *snapshot.Root) {
|
||||
if err := root.Close(); err != nil {
|
||||
log.Warnf("restore: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user