Skip to content

Commit 8c2f72c

Browse files
committed
fix: find chromium key failed on windows
1 parent 2de62ac commit 8c2f72c

6 files changed

Lines changed: 29 additions & 35 deletions

File tree

internal/browingdata/creditcard/creditcard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
112112
return err
113113
}
114114
} else {
115-
value, err = decrypter.ChromePass(masterKey, encryptValue)
115+
value, err = decrypter.ChromePassForYandex(masterKey, encryptValue)
116116
if err != nil {
117117
return err
118118
}

internal/browingdata/password/password.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ func (c *YandexPassword) Parse(masterKey []byte) error {
129129
if masterKey == nil {
130130
password, err = decrypter.DPApi(pwd)
131131
} else {
132-
password, err = decrypter.ChromePass(masterKey, pwd)
132+
password, err = decrypter.ChromePassForYandex(masterKey, pwd)
133133
}
134134
if err != nil {
135-
log.Error(err)
135+
log.Errorf("decrypt yandex password error %s", err)
136136
}
137137
}
138138
if create > time.Now().Unix() {

internal/browser/browser.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package browser
22

33
import (
44
"os"
5+
"path/filepath"
56
"strings"
67

78
"hack-browser-data/internal/browingdata"
@@ -42,32 +43,30 @@ func pickChromium(name, profile string) []Browser {
4243
// TODO: add support for 「all」 flag and set profilePath
4344
if name == "all" {
4445
for _, v := range chromiumList {
46+
if !fileutil.FolderExists(filepath.Clean(v.profilePath)) {
47+
log.Noticef("find browser %s failed, profile folder is not exist", v.name)
48+
continue
49+
}
4550
if b, err := chromium.New(v.name, v.storage, v.profilePath, v.items); err == nil {
4651
log.Noticef("find browser %s success", b.Name())
4752
browsers = append(browsers, b)
4853
} else {
49-
if err == chromium.ErrProfilePathNotFound {
50-
log.Errorf("find browser %s failed, profile folder is not exist, maybe not installed", v.name)
51-
continue
52-
} else {
53-
log.Errorf("new chromium error: %s", err.Error())
54-
}
54+
log.Errorf("new chromium error: %s", err.Error())
5555
}
5656
}
5757
}
5858
if c, ok := chromiumList[name]; ok {
5959
if profile == "" {
6060
profile = c.profilePath
6161
}
62+
if !fileutil.FolderExists(filepath.Clean(profile)) {
63+
log.Fatalf("find browser %s failed, profile folder is not exist", c.name)
64+
}
6265
b, err := chromium.New(c.name, c.storage, profile, c.items)
6366
if err != nil {
64-
if err == chromium.ErrProfilePathNotFound {
65-
log.Fatalf("find browser %s failed, profile folder is not exist, maybe not installed", c.name)
66-
} else {
67-
log.Fatalf("new chromium error:", err)
68-
return nil
69-
}
67+
log.Fatalf("new chromium error:", err)
7068
}
69+
log.Noticef("find browser %s success", b.Name())
7170
browsers = append(browsers, b)
7271
}
7372
return browsers
@@ -83,17 +82,17 @@ func pickFirefox(name, profile string) []Browser {
8382
} else {
8483
profile = fileutil.ParentDir(profile)
8584
}
85+
if !fileutil.FolderExists(filepath.Clean(profile)) {
86+
log.Noticef("find browser firefox %s failed, profile folder is not exist", v.name)
87+
continue
88+
}
8689
if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil {
8790
for _, b := range multiFirefox {
8891
log.Noticef("find browser firefox %s success", b.Name())
8992
browsers = append(browsers, b)
9093
}
9194
} else {
92-
if err == firefox.ErrProfilePathNotFound {
93-
log.Errorf("find browser firefox %s failed, profile folder is not exist", v.name)
94-
} else {
95-
log.Error(err)
96-
}
95+
log.Error(err)
9796
}
9897
}
9998
return browsers

internal/browser/chromium/chromium.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package chromium
22

33
import (
4-
"errors"
54
"io/ioutil"
65
"os"
76
"path/filepath"
87
"strings"
98

109
"hack-browser-data/internal/browingdata"
1110
"hack-browser-data/internal/item"
11+
"hack-browser-data/internal/log"
1212
"hack-browser-data/internal/utils/fileutil"
1313
"hack-browser-data/internal/utils/typeutil"
1414
)
@@ -22,20 +22,12 @@ type chromium struct {
2222
itemPaths map[item.Item]string
2323
}
2424

25-
var (
26-
ErrProfilePathNotFound = errors.New("profile path not found")
27-
)
28-
2925
// New create instance of chromium browser, fill item's path if item is existed.
3026
func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
3127
c := &chromium{
3228
name: name,
3329
storage: storage,
3430
}
35-
// TODO: Handle file path is not exist
36-
if !fileutil.FolderExists(profilePath) {
37-
return nil, ErrProfilePathNotFound
38-
}
3931
itemsPaths, err := c.getItemPath(profilePath, items)
4032
if err != nil {
4133
return nil, err
@@ -72,7 +64,7 @@ func (c *chromium) BrowsingData() (*browingdata.Data, error) {
7264
func (c *chromium) copyItemToLocal() error {
7365
for i, path := range c.itemPaths {
7466
if fileutil.FolderExists(path) {
75-
if err := fileutil.CopyDir(path, i.String()); err != nil {
67+
if err := fileutil.CopyDir(path, i.String(), "lock"); err != nil {
7668
return err
7769
}
7870
} else {
@@ -95,6 +87,8 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
9587
var itemPaths = make(map[item.Item]string)
9688
parentDir := fileutil.ParentDir(profilePath)
9789
baseDir := fileutil.BaseDir(profilePath)
90+
log.Infof("%s profile parentDir: %s", c.name, parentDir)
91+
log.Infof("%s profile baseDir: %s", c.name, baseDir)
9892
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
9993
if err != nil {
10094
return itemPaths, err

internal/browser/firefox/firefox.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ var (
2828

2929
// New returns a new firefox instance.
3030
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
31-
if !fileutil.FolderExists(profilePath) {
32-
return nil, ErrProfilePathNotFound
33-
}
31+
3432
f := &firefox{
3533
name: name,
3634
storage: storage,

internal/utils/fileutil/filetutil.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ func ReadFile(filename string) (string, error) {
4545
return string(s), err
4646
}
4747

48-
func CopyDir(src, dst string) error {
49-
return cp.Copy(src, dst)
48+
func CopyDir(src, dst, skip string) error {
49+
s := cp.Options{Skip: func(src string) (bool, error) {
50+
return strings.Contains(strings.ToLower(src), skip), nil
51+
}}
52+
return cp.Copy(src, dst, s)
5053
}
5154

5255
func Filename(browser, item, ext string) string {

0 commit comments

Comments
 (0)