fix: find chromium key failed on windows

pull/128/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 2de62ac1bb
commit 8c2f72ccb6
  1. 2
      internal/browingdata/creditcard/creditcard.go
  2. 4
      internal/browingdata/password/password.go
  3. 33
      internal/browser/browser.go
  4. 14
      internal/browser/chromium/chromium.go
  5. 4
      internal/browser/firefox/firefox.go
  6. 7
      internal/utils/fileutil/filetutil.go

@ -112,7 +112,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
return err return err
} }
} else { } else {
value, err = decrypter.ChromePass(masterKey, encryptValue) value, err = decrypter.ChromePassForYandex(masterKey, encryptValue)
if err != nil { if err != nil {
return err return err
} }

@ -129,10 +129,10 @@ func (c *YandexPassword) Parse(masterKey []byte) error {
if masterKey == nil { if masterKey == nil {
password, err = decrypter.DPApi(pwd) password, err = decrypter.DPApi(pwd)
} else { } else {
password, err = decrypter.ChromePass(masterKey, pwd) password, err = decrypter.ChromePassForYandex(masterKey, pwd)
} }
if err != nil { if err != nil {
log.Error(err) log.Errorf("decrypt yandex password error %s", err)
} }
} }
if create > time.Now().Unix() { if create > time.Now().Unix() {

@ -2,6 +2,7 @@ package browser
import ( import (
"os" "os"
"path/filepath"
"strings" "strings"
"hack-browser-data/internal/browingdata" "hack-browser-data/internal/browingdata"
@ -42,16 +43,15 @@ func pickChromium(name, profile string) []Browser {
// TODO: add support for 「all」 flag and set profilePath // TODO: add support for 「all」 flag and set profilePath
if name == "all" { if name == "all" {
for _, v := range chromiumList { 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 { if b, err := chromium.New(v.name, v.storage, v.profilePath, v.items); err == nil {
log.Noticef("find browser %s success", b.Name()) log.Noticef("find browser %s success", b.Name())
browsers = append(browsers, b) browsers = append(browsers, b)
} else { } else {
if err == chromium.ErrProfilePathNotFound { log.Errorf("new chromium error: %s", err.Error())
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())
}
} }
} }
} }
@ -59,15 +59,14 @@ func pickChromium(name, profile string) []Browser {
if profile == "" { if profile == "" {
profile = c.profilePath 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) b, err := chromium.New(c.name, c.storage, profile, c.items)
if err != nil { if err != nil {
if err == chromium.ErrProfilePathNotFound { log.Fatalf("new chromium error:", err)
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.Noticef("find browser %s success", b.Name())
browsers = append(browsers, b) browsers = append(browsers, b)
} }
return browsers return browsers
@ -83,17 +82,17 @@ func pickFirefox(name, profile string) []Browser {
} else { } else {
profile = fileutil.ParentDir(profile) 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 { if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil {
for _, b := range multiFirefox { for _, b := range multiFirefox {
log.Noticef("find browser firefox %s success", b.Name()) log.Noticef("find browser firefox %s success", b.Name())
browsers = append(browsers, b) browsers = append(browsers, b)
} }
} else { } else {
if err == firefox.ErrProfilePathNotFound { log.Error(err)
log.Errorf("find browser firefox %s failed, profile folder is not exist", v.name)
} else {
log.Error(err)
}
} }
} }
return browsers return browsers

@ -1,7 +1,6 @@
package chromium package chromium
import ( import (
"errors"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -9,6 +8,7 @@ import (
"hack-browser-data/internal/browingdata" "hack-browser-data/internal/browingdata"
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/fileutil" "hack-browser-data/internal/utils/fileutil"
"hack-browser-data/internal/utils/typeutil" "hack-browser-data/internal/utils/typeutil"
) )
@ -22,20 +22,12 @@ type chromium struct {
itemPaths map[item.Item]string 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. // 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) { func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
c := &chromium{ c := &chromium{
name: name, name: name,
storage: storage, storage: storage,
} }
// TODO: Handle file path is not exist
if !fileutil.FolderExists(profilePath) {
return nil, ErrProfilePathNotFound
}
itemsPaths, err := c.getItemPath(profilePath, items) itemsPaths, err := c.getItemPath(profilePath, items)
if err != nil { if err != nil {
return nil, err return nil, err
@ -72,7 +64,7 @@ func (c *chromium) BrowsingData() (*browingdata.Data, error) {
func (c *chromium) copyItemToLocal() error { func (c *chromium) copyItemToLocal() error {
for i, path := range c.itemPaths { for i, path := range c.itemPaths {
if fileutil.FolderExists(path) { 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 return err
} }
} else { } else {
@ -95,6 +87,8 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
var itemPaths = make(map[item.Item]string) var itemPaths = make(map[item.Item]string)
parentDir := fileutil.ParentDir(profilePath) parentDir := fileutil.ParentDir(profilePath)
baseDir := fileutil.BaseDir(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)) err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
if err != nil { if err != nil {
return itemPaths, err return itemPaths, err

@ -28,9 +28,7 @@ var (
// New returns a new firefox instance. // New returns a new firefox instance.
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) { func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
if !fileutil.FolderExists(profilePath) {
return nil, ErrProfilePathNotFound
}
f := &firefox{ f := &firefox{
name: name, name: name,
storage: storage, storage: storage,

@ -45,8 +45,11 @@ func ReadFile(filename string) (string, error) {
return string(s), err return string(s), err
} }
func CopyDir(src, dst string) error { func CopyDir(src, dst, skip string) error {
return cp.Copy(src, dst) 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 { func Filename(browser, item, ext string) string {

Loading…
Cancel
Save