mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-06 05:53:25 +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
@@ -24,6 +24,20 @@ const (
|
||||
Safari
|
||||
)
|
||||
|
||||
// String is the base's name in a snapshot manifest.
|
||||
func (b Base) String() string {
|
||||
switch b {
|
||||
case Chromium:
|
||||
return "chromium"
|
||||
case Firefox:
|
||||
return "firefox"
|
||||
case Safari:
|
||||
return "safari"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// Platform is how one browser appears on one OS; a Platform without UserDataDirs means the OS is not supported.
|
||||
type Platform struct {
|
||||
UserDataDirs []string // slash-separated, relative to the home directory; globs allowed
|
||||
|
||||
@@ -43,6 +43,17 @@ func Discover(def browser.Def, opts browser.DiscoverOptions) ([]browser.UserData
|
||||
return dirs, errors.Join(errs...)
|
||||
}
|
||||
|
||||
// DiscoverAt reads the profiles of a user data dir the table does not name, such as a copy restore was given.
|
||||
func DiscoverAt(def browser.Def, id browser.DirID, path string) (browser.UserDataDir, error) {
|
||||
dir := browser.UserDataDir{ID: id, Def: def, Path: path}
|
||||
profiles, err := discoverProfiles(dir)
|
||||
if err != nil {
|
||||
return dir, err
|
||||
}
|
||||
dir.Profiles = profiles
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
// profileAt reads -p as the path chrome://version shows: a directory with a profile marker but no Local State is one
|
||||
// profile, so its parent is the user data dir that holds the keys, and only that profile is selected.
|
||||
func profileAt(def browser.Def, path string) (browser.UserDataDir, bool) {
|
||||
@@ -173,6 +184,11 @@ func KeyLocator(dir browser.UserDataDir, snap snapshot.Snapshot) (masterkey.Loca
|
||||
return loc, nil
|
||||
}
|
||||
|
||||
// KeySources are the files KeyLocator reads from a snapshot.
|
||||
func KeySources(_ browser.UserDataDir) []browser.Source {
|
||||
return []browser.Source{localState}
|
||||
}
|
||||
|
||||
// ArchiveSources are what an archive keeps beside the categories' own files: Local State, and each profile's marker so
|
||||
// that a reader without the manifest still finds every profile.
|
||||
func ArchiveSources(_ browser.UserDataDir) []browser.Source {
|
||||
|
||||
@@ -186,6 +186,34 @@ func TestOverrides_KeysAreChromiumBrowsers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A vault's kind must lead a reader back to the same fork's files, or a restore would parse them as plain Chromium.
|
||||
func TestVaultKind_RoundTripsEveryFork(t *testing.T) {
|
||||
assert.Len(t, kinds, len(overrides))
|
||||
for id := range overrides {
|
||||
kind := VaultKind(browser.Def{ID: id})
|
||||
require.NotEqualf(t, kindChromium, kind, "override %q has no keys.json kind", id)
|
||||
formatID, err := FormatID(kind, "unknown")
|
||||
require.NoError(t, err)
|
||||
assert.Equalf(t, categoriesOf(overrides[id]), categoriesOf(overrides[formatID]), "kind %s of %q", kind, id)
|
||||
}
|
||||
assert.Equal(t, kindChromium, VaultKind(browser.Def{ID: "chrome"}))
|
||||
formatID, err := FormatID(kindChromium, "unknown")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "unknown", formatID)
|
||||
_, err = FormatID("bogus", "unknown")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func categoriesOf(ex browser.Extractors) []category.Category {
|
||||
var out []category.Category
|
||||
for _, c := range category.All() {
|
||||
if _, ok := ex[c]; ok {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestExtractors_OverridesFollowTheBrowserNotTheDirectory(t *testing.T) {
|
||||
yandex, ok := browser.Lookup("yandex")
|
||||
require.True(t, ok)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package chromium
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
||||
)
|
||||
|
||||
// A keys.json vault names its on-disk format by kind, so a reader without the browser in its table still picks the
|
||||
// forks' own files.
|
||||
const (
|
||||
kindChromium = "chromium"
|
||||
kindYandex = "chromium-yandex"
|
||||
kindOpera = "chromium-opera"
|
||||
)
|
||||
|
||||
// kinds holds the forks of overrides; every other Chromium browser is kindChromium.
|
||||
var kinds = map[string]string{
|
||||
"yandex": kindYandex,
|
||||
"opera": kindOpera,
|
||||
"opera-gx": kindOpera,
|
||||
"vought": kindOpera,
|
||||
}
|
||||
|
||||
// VaultKind is def's kind in keys.json.
|
||||
func VaultKind(def browser.Def) string {
|
||||
if kind, ok := kinds[def.ID]; ok {
|
||||
return kind
|
||||
}
|
||||
return kindChromium
|
||||
}
|
||||
|
||||
// FormatID is the Def.ID whose extractors read a vault of kind; a plain Chromium vault keeps its own id.
|
||||
func FormatID(kind, id string) (string, error) {
|
||||
switch kind {
|
||||
case kindChromium:
|
||||
return id, nil
|
||||
case kindYandex:
|
||||
return "yandex", nil
|
||||
case kindOpera:
|
||||
return "opera", nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown engine kind %q", kind)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user