mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
* refactor(chromium): consolidate decryption and fork variants Keys are fetched by the first value that needs one, as the secrets design says, so an empty store retrieves none. One version type, one override table (browsers, kind, extractors), and all Yandex code in yandex.go replace lists that had to agree. * refactor(chromium): build the password row with a constructor Every other row of the extractor table is a constructor call; Safari already names its row newPasswordExtractor. * refactor(browser): build password rows like every other row A decrypting extractor now reads each file it lists, so Chromium's two login stores and Firefox's key4.db need no hand-built row. Parse functions lead each call because Go puts the variadic file specs last. * refactor(browser): declare each browser's sources in one block Files were declared four ways: literals, three newFileSpec signatures, newDirectorySpec, and withKeyFiles. FileSpec becomes Source with Path and Fallbacks, so a fallback no longer reads like a second file to read.
95 lines
2.9 KiB
Go
95 lines
2.9 KiB
Go
package browser
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/category"
|
|
"github.com/moond4rk/hackbrowserdata/internal/masterkey"
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
"github.com/moond4rk/hackbrowserdata/internal/snapshot"
|
|
)
|
|
|
|
// Source is one file or directory an extractor reads.
|
|
type Source struct {
|
|
Path string // slash-separated, relative to the profile dir, or to the user data dir when Shared
|
|
Fallbacks []string // older locations, read only when Path is absent
|
|
IsDir bool
|
|
Shared bool // belongs to the whole user data dir, such as Local State, so it is captured once per dir
|
|
Optional bool // the extraction still runs without it
|
|
}
|
|
|
|
// Paths lists Path and then its Fallbacks, the order they are tried in.
|
|
func (s Source) Paths() []string {
|
|
return append([]string{s.Path}, s.Fallbacks...)
|
|
}
|
|
|
|
// CandidatePaths are the Paths for a profile, relative to the user data dir.
|
|
func (s Source) CandidatePaths(profile Profile) []string {
|
|
paths := s.Paths()
|
|
if !s.Shared {
|
|
for i, relativePath := range paths {
|
|
paths[i] = path.Join(profile.RelativePath, relativePath)
|
|
}
|
|
}
|
|
return paths
|
|
}
|
|
|
|
type Extractor struct {
|
|
Sources []Source
|
|
Extract func(ctx context.Context, profileSnapshot ProfileSnapshot, out Collector) error
|
|
}
|
|
|
|
type Extractors map[category.Category]Extractor
|
|
|
|
// Collector sets every record's Browser and Profile; Fail reports a bad record and the extraction goes on.
|
|
type Collector interface {
|
|
Add(row record.Record)
|
|
Fail(err error)
|
|
}
|
|
|
|
// AddAll hands rows to out by pointer, because out sets each record's Browser and Profile in place.
|
|
func AddAll[T any, P interface {
|
|
*T
|
|
record.Record
|
|
}](out Collector, rows []T) {
|
|
for i := range rows {
|
|
out.Add(P(&rows[i]))
|
|
}
|
|
}
|
|
|
|
type ProfileSnapshot struct {
|
|
Profile Profile
|
|
snapshot snapshot.Snapshot
|
|
masterKeys func(ctx context.Context) masterkey.Set
|
|
}
|
|
|
|
// NewProfileSnapshot takes masterKeys, the dir's call-once retrieval, nil for bases that keep no Chromium keys.
|
|
func NewProfileSnapshot(dirSnapshot snapshot.Snapshot, profile Profile, masterKeys func(context.Context) masterkey.Set) ProfileSnapshot {
|
|
return ProfileSnapshot{Profile: profile, snapshot: dirSnapshot, masterKeys: masterKeys}
|
|
}
|
|
|
|
// Path skips a candidate that was never captured but returns the error of one whose copy failed.
|
|
func (ps ProfileSnapshot) Path(source Source) (string, error) {
|
|
for _, relativePath := range source.CandidatePaths(ps.Profile) {
|
|
capturedPath, err := ps.snapshot.Path(relativePath)
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
continue
|
|
}
|
|
return capturedPath, err
|
|
}
|
|
return "", fmt.Errorf("%s: %w", strings.Join(source.Paths(), " or "), fs.ErrNotExist)
|
|
}
|
|
|
|
// MasterKeys may block on its first call; a key version that could not be retrieved is absent from the Set.
|
|
func (ps ProfileSnapshot) MasterKeys(ctx context.Context) masterkey.Set {
|
|
if ps.masterKeys == nil {
|
|
return nil
|
|
}
|
|
return ps.masterKeys(ctx)
|
|
}
|