mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
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:
1 parent
6d6191b4c6
commit
4e98ba7884
33 files changed
+303
-315
No files matched your search
@@ -2,7 +2,11 @@
|
||||
// and the extractors that read them.
|
||||
package browser
|
||||
|
||||
import "github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
||||
)
|
||||
|
||||
// Def is one browser HBD knows. ID is the -b value and the keys.json vault key; Name is stamped on every record.
|
||||
type Def struct {
|
||||
@@ -58,6 +62,17 @@ func Supported() []Def {
|
||||
return out
|
||||
}
|
||||
|
||||
// IDs are this OS's browser IDs, sorted as the -b help has always listed them.
|
||||
func IDs() []string {
|
||||
defs := Supported()
|
||||
ids := make([]string, len(defs))
|
||||
for i, d := range defs {
|
||||
ids[i] = d.ID
|
||||
}
|
||||
sort.Strings(ids)
|
||||
return ids
|
||||
}
|
||||
|
||||
// Lookup finds a browser by ID in the whole table, whatever the running OS, so restore resolves another host's vaults.
|
||||
func Lookup(id string) (Def, bool) {
|
||||
for _, d := range defs {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -129,3 +130,9 @@ func TestABERowsMatchPayloadTable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIDs_AreSupportedSorted(t *testing.T) {
|
||||
ids := IDs()
|
||||
assert.True(t, sort.StringsAreSorted(ids), "the -b help has always listed them sorted")
|
||||
assert.ElementsMatch(t, idsOn(Def.Platform), ids)
|
||||
}
|
||||
@@ -22,6 +22,18 @@ type Source struct {
|
||||
Optional bool // the extraction still runs without it
|
||||
}
|
||||
|
||||
// Candidates are the Paths for profile p, relative to the user data dir, in priority order.
|
||||
func (s Source) Candidates(p Profile) []string {
|
||||
rels := make([]string, len(s.Paths))
|
||||
for i, rel := range s.Paths {
|
||||
if !s.Shared {
|
||||
rel = path.Join(p.Dir, rel)
|
||||
}
|
||||
rels[i] = rel
|
||||
}
|
||||
return rels
|
||||
}
|
||||
|
||||
// Extractor declares the sources a category needs and how to parse them.
|
||||
type Extractor struct {
|
||||
Sources []Source
|
||||
@@ -55,10 +67,7 @@ func NewProfileSnapshot(snap snapshot.Snapshot, p Profile, masterKeys func(conte
|
||||
// Path returns where src was captured: its first candidate present in the snapshot. A candidate that was never captured
|
||||
// is skipped; one whose copy failed returns that copy's error.
|
||||
func (ps ProfileSnapshot) Path(src Source) (string, error) {
|
||||
for _, rel := range src.Paths {
|
||||
if !src.Shared {
|
||||
rel = path.Join(ps.Profile.Dir, rel)
|
||||
}
|
||||
for _, rel := range src.Candidates(ps.Profile) {
|
||||
p, err := ps.snap.Path(rel)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
continue
|
||||
|
||||
@@ -84,3 +84,11 @@ func TestProfileSnapshotMasterKeys(t *testing.T) {
|
||||
assert.Equal(t, want, ps.MasterKeys(context.Background()))
|
||||
assert.Equal(t, 1, calls)
|
||||
}
|
||||
|
||||
func TestSource_Candidates(t *testing.T) {
|
||||
p := Profile{Name: "Default", Dir: "Default"}
|
||||
assert.Equal(t, []string{"Default/Network/Cookies", "Default/Cookies"}, Source{Paths: []string{"Network/Cookies", "Cookies"}}.Candidates(p))
|
||||
assert.Equal(t, []string{"Local State"}, Source{Paths: []string{"Local State"}, Shared: true}.Candidates(p))
|
||||
assert.Equal(t, []string{"History"}, Source{Paths: []string{"History"}}.Candidates(Profile{Name: "default"}),
|
||||
"a user data dir that is itself the profile")
|
||||
}
|
||||
Reference in new issue
Block a user