Files
HackBrowserData/browser/chromium/archive.go
T
moonD4rk 96ed041fa0 feat(cli): add archive command for cross-host data transport
Bundles each browser's decryption-relevant files + Local State into a <browser-key>/<User Data> zip (forward-slash entries) for cross-host restore.
2026-06-06 20:45:06 +08:00

60 lines
1.8 KiB
Go

package chromium
import (
"path"
"path/filepath"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
)
// ArchiveSource is one decryption-relevant file or directory plus its path inside the browser's
// User Data tree (forward-slash), so an archive can be re-expanded into a working profile layout.
type ArchiveSource struct {
AbsPath string
LayoutRel string
IsDir bool
}
// installationFiles live at the User Data root (shared across profiles); archived for fidelity even
// though keys.json-based restore does not read them.
var installationFiles = []string{"Local State"}
// ArchiveSources lists the files an archive must capture for the given categories: the User Data root
// files (Local State), every resolved category source per profile, plus each profile's Preferences
// marker so a restore can rediscover the profile. LayoutRel is forward-slash, relative to the root.
func (b *Browser) ArchiveSources(categories []types.Category) []ArchiveSource {
var out []ArchiveSource
for _, name := range installationFiles {
abs := filepath.Join(b.cfg.UserDataDir, name)
if fileutil.FileExists(abs) {
out = append(out, ArchiveSource{AbsPath: abs, LayoutRel: name, IsDir: false})
}
}
for _, p := range b.profiles {
profileRel := filepath.Base(p.profileDir)
for _, marker := range profileMarkers {
abs := filepath.Join(p.profileDir, marker)
if fileutil.FileExists(abs) {
out = append(out, ArchiveSource{
AbsPath: abs,
LayoutRel: path.Join(profileRel, marker),
IsDir: false,
})
}
}
for _, cat := range categories {
rp, ok := p.sourcePaths[cat]
if !ok {
continue
}
out = append(out, ArchiveSource{
AbsPath: rp.absPath,
LayoutRel: path.Join(profileRel, rp.rel),
IsDir: rp.isDir,
})
}
}
return out
}