Skip to content

Commit

Permalink
fix: skip chromium snapshot dir to find right database
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
moonD4rk committed Jul 15, 2024
1 parent f783570 commit 5a3a218
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
8 changes: 4 additions & 4 deletions browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func pickChromium(name, profile string) []Browser {
if !fileutil.IsDirExists(filepath.Clean(profile)) {
slog.Error("find browser failed, profile folder does not exist", "browser", c.name)
}
chromiumList, err := chromium.New(c.name, c.storage, profile, c.dataTypes)
chromes, err := chromium.New(c.name, c.storage, profile, c.dataTypes)
if err != nil {
slog.Error("new chromium error", "err", err)
}
for _, b := range chromiumList {
slog.Warn("find browser success", "browser", b.Name())
browsers = append(browsers, b)
for _, chrome := range chromes {
slog.Warn("find browser success", "browser", chrome.Name())
browsers = append(browsers, chrome)
}
}
return browsers
Expand Down
22 changes: 15 additions & 7 deletions browser/chromium/chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/fs"
"log/slog"
"path/filepath"
"slices"
"strings"

"github.com/moond4rk/hackbrowserdata/browserdata"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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", ""))
Expand Down
10 changes: 5 additions & 5 deletions browser/firefox/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ func (f *Firefox) Name() string {
}

func (f *Firefox) BrowsingData(isFullExport bool) (*browserdata.BrowserData, error) {
items := f.items
dataTypes := f.items
if !isFullExport {
items = types.FilterSensitiveItems(f.items)
dataTypes = types.FilterSensitiveItems(f.items)
}

b := browserdata.New(items)
data := browserdata.New(dataTypes)

if err := f.copyItemToLocal(); err != nil {
return nil, err
Expand All @@ -177,8 +177,8 @@ func (f *Firefox) BrowsingData(isFullExport bool) (*browserdata.BrowserData, err
}

f.masterKey = masterKey
if err := b.Recovery(f.masterKey); err != nil {
if err := data.Recovery(f.masterKey); err != nil {
return nil, err
}
return b, nil
return data, nil
}

0 comments on commit 5a3a218

Please sign in to comment.