mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
refactor: refactor package with gofumpt
This commit is contained in:
@@ -111,10 +111,8 @@ func ListBrowser() []string {
|
||||
return l
|
||||
}
|
||||
|
||||
var (
|
||||
// home dir path for all platforms
|
||||
homeDir, _ = os.UserHomeDir()
|
||||
)
|
||||
// home dir path for all platforms
|
||||
var homeDir, _ = os.UserHomeDir()
|
||||
|
||||
const (
|
||||
chromeName = "Chrome"
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
package browser
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"hack-browser-data/internal/item"
|
||||
)
|
||||
|
||||
@@ -18,7 +15,7 @@ var (
|
||||
}{
|
||||
"chrome": {
|
||||
name: chromeName,
|
||||
profilePath: getProfiles(chromeUserDataPath)[0],
|
||||
profilePath: chromeUserDataPath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"edge": {
|
||||
@@ -28,12 +25,12 @@ var (
|
||||
},
|
||||
"chromium": {
|
||||
name: chromiumName,
|
||||
profilePath: getProfiles(chromiumUserDataPath)[0],
|
||||
profilePath: chromiumUserDataPath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"chrome-beta": {
|
||||
name: chromeBetaName,
|
||||
profilePath: getProfiles(chromeBetaUserDataPath)[0],
|
||||
profilePath: chromeBetaUserDataPath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"opera": {
|
||||
@@ -91,31 +88,10 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func getProfiles(userDataPath string) []string {
|
||||
var res []string
|
||||
files, err := ioutil.ReadDir(userDataPath)
|
||||
|
||||
if err != nil {
|
||||
|
||||
res = append(res, userDataPath+"Default")
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
if f.IsDir() && f.Name() != "System Profile" {
|
||||
var thisPath = userDataPath + f.Name()
|
||||
_, err := os.Stat(thisPath + "/Login Data")
|
||||
if err == nil {
|
||||
res = append(res, userDataPath+f.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
var (
|
||||
chromeUserDataPath = homeDir + "/AppData/Local/Google/Chrome/User Data/"
|
||||
chromeBetaUserDataPath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/"
|
||||
chromiumUserDataPath = homeDir + "/AppData/Local/Chromium/User Data/"
|
||||
chromeUserDataPath = homeDir + "/AppData/Local/Google/Chrome/User Data/Default/"
|
||||
chromeBetaUserDataPath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/Default/"
|
||||
chromiumUserDataPath = homeDir + "/AppData/Local/Chromium/User Data/Default/"
|
||||
edgeProfilePath = homeDir + "/AppData/Local/Microsoft/Edge/User Data/Default/"
|
||||
braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/Default/"
|
||||
speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/Default/"
|
||||
|
||||
@@ -39,6 +39,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*chromium, err
|
||||
name: fileutil.BrowserName(name, user),
|
||||
items: typeutil.Keys(itemPaths),
|
||||
itemPaths: itemPaths,
|
||||
storage: storage,
|
||||
})
|
||||
}
|
||||
return chromiumList, nil
|
||||
@@ -90,7 +91,7 @@ func (c *chromium) copyItemToLocal() error {
|
||||
}
|
||||
|
||||
func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.Item]string, error) {
|
||||
var itemPaths = make(map[item.Item]string)
|
||||
itemPaths := make(map[item.Item]string)
|
||||
parentDir := fileutil.ParentDir(profilePath)
|
||||
baseDir := fileutil.BaseDir(profilePath)
|
||||
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
|
||||
@@ -102,7 +103,8 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
|
||||
}
|
||||
|
||||
func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
|
||||
var multiItemPaths = make(map[string]map[item.Item]string)
|
||||
// multiItemPaths is a map of user to item path, map[profile 1][item's name & path key pair]
|
||||
multiItemPaths := make(map[string]map[item.Item]string)
|
||||
parentDir := fileutil.ParentDir(profilePath)
|
||||
err := filepath.Walk(parentDir, chromiumWalkFunc2(items, multiItemPaths))
|
||||
if err != nil {
|
||||
@@ -126,6 +128,7 @@ func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[
|
||||
}
|
||||
t[userDir] = v
|
||||
t[userDir][item.ChromiumKey] = keyPath
|
||||
fillLocalStoragePath(t[userDir], item.ChromiumLocalStorage)
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build darwin
|
||||
|
||||
package chromium
|
||||
|
||||
import (
|
||||
@@ -46,7 +48,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
|
||||
if chromeSecret == nil {
|
||||
return nil, ErrWrongSecurityCommand
|
||||
}
|
||||
var chromeSalt = []byte("saltysalt")
|
||||
chromeSalt := []byte("saltysalt")
|
||||
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
|
||||
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
|
||||
if key == nil {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build linux
|
||||
|
||||
package chromium
|
||||
|
||||
import (
|
||||
@@ -60,7 +62,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
|
||||
// @https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=100
|
||||
chromiumSecret = []byte("peanuts")
|
||||
}
|
||||
var chromiumSalt = []byte("saltysalt")
|
||||
chromiumSalt := []byte("saltysalt")
|
||||
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc
|
||||
key := pbkdf2.Key(chromiumSecret, chromiumSalt, 1, 16, sha1.New)
|
||||
c.masterKey = key
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build windows
|
||||
|
||||
package chromium
|
||||
|
||||
import (
|
||||
@@ -13,9 +15,7 @@ import (
|
||||
"hack-browser-data/internal/utils/fileutil"
|
||||
)
|
||||
|
||||
var (
|
||||
errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||||
)
|
||||
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||||
|
||||
func (c *chromium) GetMasterKey() ([]byte, error) {
|
||||
keyFile, err := fileutil.ReadFile(item.TempChromiumKey)
|
||||
|
||||
@@ -21,13 +21,10 @@ type firefox struct {
|
||||
itemPaths map[item.Item]string
|
||||
}
|
||||
|
||||
var (
|
||||
ErrProfilePathNotFound = errors.New("profile path not found")
|
||||
)
|
||||
var ErrProfilePathNotFound = errors.New("profile path not found")
|
||||
|
||||
// New returns a new firefox instance.
|
||||
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
|
||||
|
||||
f := &firefox{
|
||||
name: name,
|
||||
storage: storage,
|
||||
@@ -50,7 +47,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*firefox, erro
|
||||
}
|
||||
|
||||
func (f *firefox) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
|
||||
var multiItemPaths = make(map[string]map[item.Item]string)
|
||||
multiItemPaths := make(map[string]map[item.Item]string)
|
||||
err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths))
|
||||
return multiItemPaths, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user