diff --git a/internal/browingdata/creditcard/creditcard.go b/internal/browingdata/creditcard/creditcard.go index 3580f11..40bd811 100644 --- a/internal/browingdata/creditcard/creditcard.go +++ b/internal/browingdata/creditcard/creditcard.go @@ -112,7 +112,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error { return err } } else { - value, err = decrypter.ChromePass(masterKey, encryptValue) + value, err = decrypter.ChromePassForYandex(masterKey, encryptValue) if err != nil { return err } diff --git a/internal/browingdata/password/password.go b/internal/browingdata/password/password.go index dc264b6..064efc6 100644 --- a/internal/browingdata/password/password.go +++ b/internal/browingdata/password/password.go @@ -129,10 +129,10 @@ func (c *YandexPassword) Parse(masterKey []byte) error { if masterKey == nil { password, err = decrypter.DPApi(pwd) } else { - password, err = decrypter.ChromePass(masterKey, pwd) + password, err = decrypter.ChromePassForYandex(masterKey, pwd) } if err != nil { - log.Error(err) + log.Errorf("decrypt yandex password error %s", err) } } if create > time.Now().Unix() { diff --git a/internal/browser/browser.go b/internal/browser/browser.go index 3d82c5a..7871d5f 100644 --- a/internal/browser/browser.go +++ b/internal/browser/browser.go @@ -2,6 +2,7 @@ package browser import ( "os" + "path/filepath" "strings" "hack-browser-data/internal/browingdata" @@ -42,16 +43,15 @@ func pickChromium(name, profile string) []Browser { // TODO: add support for 「all」 flag and set profilePath if name == "all" { for _, v := range chromiumList { + if !fileutil.FolderExists(filepath.Clean(v.profilePath)) { + log.Noticef("find browser %s failed, profile folder is not exist", v.name) + continue + } if b, err := chromium.New(v.name, v.storage, v.profilePath, v.items); err == nil { log.Noticef("find browser %s success", b.Name()) browsers = append(browsers, b) } else { - if err == chromium.ErrProfilePathNotFound { - log.Errorf("find browser %s failed, profile folder is not exist, maybe not installed", v.name) - continue - } else { - log.Errorf("new chromium error: %s", err.Error()) - } + log.Errorf("new chromium error: %s", err.Error()) } } } @@ -59,15 +59,14 @@ func pickChromium(name, profile string) []Browser { if profile == "" { profile = c.profilePath } + if !fileutil.FolderExists(filepath.Clean(profile)) { + log.Fatalf("find browser %s failed, profile folder is not exist", c.name) + } b, err := chromium.New(c.name, c.storage, profile, c.items) if err != nil { - if err == chromium.ErrProfilePathNotFound { - log.Fatalf("find browser %s failed, profile folder is not exist, maybe not installed", c.name) - } else { - log.Fatalf("new chromium error:", err) - return nil - } + log.Fatalf("new chromium error:", err) } + log.Noticef("find browser %s success", b.Name()) browsers = append(browsers, b) } return browsers @@ -83,17 +82,17 @@ func pickFirefox(name, profile string) []Browser { } else { profile = fileutil.ParentDir(profile) } + if !fileutil.FolderExists(filepath.Clean(profile)) { + log.Noticef("find browser firefox %s failed, profile folder is not exist", v.name) + continue + } if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil { for _, b := range multiFirefox { log.Noticef("find browser firefox %s success", b.Name()) browsers = append(browsers, b) } } else { - if err == firefox.ErrProfilePathNotFound { - log.Errorf("find browser firefox %s failed, profile folder is not exist", v.name) - } else { - log.Error(err) - } + log.Error(err) } } return browsers diff --git a/internal/browser/chromium/chromium.go b/internal/browser/chromium/chromium.go index 5a8673d..b4404a1 100644 --- a/internal/browser/chromium/chromium.go +++ b/internal/browser/chromium/chromium.go @@ -1,7 +1,6 @@ package chromium import ( - "errors" "io/ioutil" "os" "path/filepath" @@ -9,6 +8,7 @@ import ( "hack-browser-data/internal/browingdata" "hack-browser-data/internal/item" + "hack-browser-data/internal/log" "hack-browser-data/internal/utils/fileutil" "hack-browser-data/internal/utils/typeutil" ) @@ -22,20 +22,12 @@ type chromium struct { itemPaths map[item.Item]string } -var ( - ErrProfilePathNotFound = errors.New("profile path not found") -) - // New create instance of chromium browser, fill item's path if item is existed. func New(name, storage, profilePath string, items []item.Item) (*chromium, error) { c := &chromium{ name: name, storage: storage, } - // TODO: Handle file path is not exist - if !fileutil.FolderExists(profilePath) { - return nil, ErrProfilePathNotFound - } itemsPaths, err := c.getItemPath(profilePath, items) if err != nil { return nil, err @@ -72,7 +64,7 @@ func (c *chromium) BrowsingData() (*browingdata.Data, error) { func (c *chromium) copyItemToLocal() error { for i, path := range c.itemPaths { if fileutil.FolderExists(path) { - if err := fileutil.CopyDir(path, i.String()); err != nil { + if err := fileutil.CopyDir(path, i.String(), "lock"); err != nil { return err } } else { @@ -95,6 +87,8 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item. var itemPaths = make(map[item.Item]string) parentDir := fileutil.ParentDir(profilePath) baseDir := fileutil.BaseDir(profilePath) + log.Infof("%s profile parentDir: %s", c.name, parentDir) + log.Infof("%s profile baseDir: %s", c.name, baseDir) err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir)) if err != nil { return itemPaths, err diff --git a/internal/browser/firefox/firefox.go b/internal/browser/firefox/firefox.go index d0578ac..17878b0 100644 --- a/internal/browser/firefox/firefox.go +++ b/internal/browser/firefox/firefox.go @@ -28,9 +28,7 @@ var ( // New returns a new firefox instance. func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) { - if !fileutil.FolderExists(profilePath) { - return nil, ErrProfilePathNotFound - } + f := &firefox{ name: name, storage: storage, diff --git a/internal/utils/fileutil/filetutil.go b/internal/utils/fileutil/filetutil.go index 4e54c25..b8c8b92 100644 --- a/internal/utils/fileutil/filetutil.go +++ b/internal/utils/fileutil/filetutil.go @@ -45,8 +45,11 @@ func ReadFile(filename string) (string, error) { return string(s), err } -func CopyDir(src, dst string) error { - return cp.Copy(src, dst) +func CopyDir(src, dst, skip string) error { + s := cp.Options{Skip: func(src string) (bool, error) { + return strings.Contains(strings.ToLower(src), skip), nil + }} + return cp.Copy(src, dst, s) } func Filename(browser, item, ext string) string {