fix: skip chromium snapshot dir to find right database

- Refactored variable names for clarity and consistency in multiple files
- Updated logic to filter sensitive items based on a flag
- Implemented a function to skip processing specific paths to improve performance
This commit is contained in:
moonD4rk
2024-07-15 17:22:12 +08:00
committed by ᴍᴏᴏɴD4ʀᴋ
parent fc8a3515d8
commit a6c6f2dd92
3 changed files with 24 additions and 16 deletions
+15 -7
View File
@@ -4,6 +4,7 @@ import (
"io/fs"
"log/slog"
"path/filepath"
"slices"
"strings"
"github.com/moond4rk/hackbrowserdata/browserdata"
@@ -50,12 +51,16 @@ func (c *Chromium) Name() string {
}
func (c *Chromium) BrowsingData(isFullExport bool) (*browserdata.BrowserData, error) {
items := c.dataTypes
// delete chromiumKey from dataTypes, doesn't need to export key
dataTypes := slices.DeleteFunc(c.dataTypes, func(i types.DataType) bool {
return i == types.ChromiumKey
})
if !isFullExport {
items = types.FilterSensitiveItems(c.dataTypes)
dataTypes = types.FilterSensitiveItems(c.dataTypes)
}
data := browserdata.New(items)
data := browserdata.New(dataTypes)
if err := c.copyItemToLocal(); err != nil {
return nil, err
@@ -107,10 +112,10 @@ func (c *Chromium) userDataTypePaths(profilePath string, items []types.DataType)
}
var keyPath string
var dir string
for userDir, v := range multiItemPaths {
for _, p := range v {
if strings.HasSuffix(p, types.ChromiumKey.Filename()) {
keyPath = p
for userDir, profiles := range multiItemPaths {
for _, profile := range profiles {
if strings.HasSuffix(profile, types.ChromiumKey.Filename()) {
keyPath = profile
dir = userDir
break
}
@@ -138,6 +143,9 @@ func chromiumWalkFunc(items []types.DataType, multiItemPaths map[string]map[type
if strings.Contains(path, "System Profile") {
continue
}
if strings.Contains(path, "Snapshot") {
continue
}
profileFolder := fileutil.ParentBaseDir(path)
if strings.Contains(filepath.ToSlash(path), "/Network/Cookies") {
profileFolder = fileutil.BaseDir(strings.ReplaceAll(filepath.ToSlash(path), "/Network/Cookies", ""))