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.
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser/chromium"
|
|
"github.com/moond4rk/hackbrowserdata/internal/log"
|
|
"github.com/moond4rk/hackbrowserdata/internal/snapshot"
|
|
)
|
|
|
|
// Archive returns how many files and directories it captured.
|
|
func Archive(ctx context.Context, discovery Discovery, options Options, archivePath string) (int, error) {
|
|
var dirs []browser.UserDataDir
|
|
for _, dir := range discovery.Dirs {
|
|
if dir.Browser.Base == browser.Chromium {
|
|
dirs = append(dirs, dir)
|
|
}
|
|
}
|
|
files := archiveFiles(NewPlan(Discovery{Dirs: dirs}, options), dirs)
|
|
|
|
snapshots, err := snapshot.Temp()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer closeSnapshot(snapshots)
|
|
if err := snapshots.Capture(ctx, files); err != nil {
|
|
return 0, err
|
|
}
|
|
fileCount := countCaptured(snapshots, files)
|
|
if fileCount == 0 {
|
|
return 0, errors.New("no decryption-relevant files found to archive")
|
|
}
|
|
if err := snapshots.Zip(archivePath); err != nil {
|
|
return 0, fmt.Errorf("write archive %s: %w", archivePath, err)
|
|
}
|
|
return fileCount, nil
|
|
}
|
|
|
|
func archiveFiles(plan Plan, dirs []browser.UserDataDir) []snapshot.File {
|
|
var files []snapshot.File
|
|
seen := make(map[snapshot.File]bool)
|
|
add := func(file snapshot.File) {
|
|
if !seen[file] {
|
|
seen[file] = true
|
|
files = append(files, file)
|
|
}
|
|
}
|
|
for _, dir := range dirs {
|
|
for _, profile := range dir.Profiles {
|
|
for _, source := range chromium.ArchiveSources() {
|
|
if file, ok, err := firstOnDisk(dir, profile, source); err == nil && ok {
|
|
add(file)
|
|
}
|
|
}
|
|
}
|
|
for _, file := range filesOf(plan, dir.ID) {
|
|
add(file)
|
|
}
|
|
}
|
|
return files
|
|
}
|
|
|
|
// countCaptured counts the files that reached the snapshot, reporting each one whose copy failed.
|
|
func countCaptured(snapshots *snapshot.Dir, files []snapshot.File) int {
|
|
fileCount := 0
|
|
for _, file := range files {
|
|
if _, err := snapshots.Snapshot(file.UserDataDirID).Path(file.RelativePath); err != nil {
|
|
log.Warnf("archive: acquire %s/%s: %v", file.UserDataDirID, file.RelativePath, err)
|
|
continue
|
|
}
|
|
fileCount++
|
|
}
|
|
return fileCount
|
|
}
|