这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions browser/edge/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func ReadCookies(filename string, filters ...kooky.Filter) ([]*kooky.Cookie, err
// CookieJar returns an initiated http.CookieJar based on the cookies stored by
// the Edge browser. Set cookies are memory stored and do not modify any
// browser files.
//
func CookieJar(filename string, filters ...kooky.Filter) (http.CookieJar, error) {
j, err := cookieStore(filename, filters...)
if err != nil {
Expand All @@ -41,7 +40,6 @@ func CookieJar(filename string, filters ...kooky.Filter) (http.CookieJar, error)
}

// CookieStore has to be closed with CookieStore.Close() after use.
//
func CookieStore(filename string, filters ...kooky.Filter) (kooky.CookieStore, error) {
return cookieStore(filename, filters...)
}
Expand Down
51 changes: 15 additions & 36 deletions browser/edge/find.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
//go:build windows

package edge

import (
"errors"
"os"
"path/filepath"

"github.com/zellyn/kooky"
"github.com/zellyn/kooky/internal/chrome"
"github.com/zellyn/kooky/internal/chrome/find"
"github.com/zellyn/kooky/internal/cookies"
"github.com/zellyn/kooky/internal/ie"
_ "github.com/zellyn/kooky/internal/ie/find"
edgefind "github.com/zellyn/kooky/internal/edge/find"
)

// TODO !windows platforms

type edgeFinder struct{}

var _ kooky.CookieStoreFinder = (*edgeFinder)(nil)
Expand All @@ -26,41 +17,29 @@ func init() {
}

func (f *edgeFinder) FindCookieStores() ([]kooky.CookieStore, error) {
locApp := os.Getenv(`LocalAppData`)
if len(locApp) == 0 {
return nil, errors.New(`%LocalAppData% is empty`)
}

var cookiesFiles []kooky.CookieStore

// Blink based
newRoot := func() ([]string, error) {
return []string{filepath.Join(locApp, `Microsoft`, `Edge`, `User Data`)}, nil
}
blinkCookiesFiles, err := find.FindCookieStoreFiles(newRoot, `edge`)
files, err := find.FindCookieStoreFiles(edgefind.GetEdgeRoots(), `edge`)
if err != nil {
return nil, err
}
for _, cookiesFile := range blinkCookiesFiles {
cookiesFiles = append(
cookiesFiles,

var ret []kooky.CookieStore
for _, file := range files {
ret = append(
ret,
&cookies.CookieJar{
CookieStore: &ie.CookieStore{
CookieStore: &chrome.CookieStore{
DefaultCookieStore: cookies.DefaultCookieStore{
BrowserStr: cookiesFile.Browser,
ProfileStr: cookiesFile.Profile,
OSStr: cookiesFile.OS,
IsDefaultProfileBool: cookiesFile.IsDefaultProfile,
FileNameStr: cookiesFile.Path,
},
CookieStore: &chrome.CookieStore{
DefaultCookieStore: cookies.DefaultCookieStore{
BrowserStr: file.Browser,
ProfileStr: file.Profile,
OSStr: file.OS,
IsDefaultProfileBool: file.IsDefaultProfile,
FileNameStr: file.Path,
},
},
},
)
}

return cookiesFiles, nil
return ret, nil
}

/*
Expand Down
24 changes: 22 additions & 2 deletions internal/chrome/chrome_darwin_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,32 @@ func (s *CookieStore) getKeyringPassword(useSaved bool) ([]byte, error) {
}
}

password, err := keychain.GetGenericPassword("Chrome Safe Storage", "Chrome", "", "")
localSafeStorage := describeSafeStorage(s.BrowserStr)
password, err := keychain.GetGenericPassword(localSafeStorage.name, localSafeStorage.account, "", "")
if err != nil {
return nil, fmt.Errorf("error reading 'Chrome Safe Storage' keychain password: %w", err)
return nil, fmt.Errorf(localSafeStorage.errorMsg, localSafeStorage.name, err)
}
s.KeyringPasswordBytes = password
keyringPasswordMap.set(kpmKey, password)

return s.KeyringPasswordBytes, nil
}

type safeStorage struct {
name string
account string
errorMsg string
}

func describeSafeStorage(browserName string) safeStorage {
defaultStore := safeStorage{
name: "Chrome Safe Storage",
account: "Chrome",
errorMsg: "error reading '%s' keychain password: %w",
}
if browserName == `edge` {
defaultStore.name = "Microsoft Edge Safe Storage"
defaultStore.account = "Microsoft Edge"
}
return defaultStore
}
5 changes: 5 additions & 0 deletions internal/edge/find/find.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package find

func GetEdgeRoots() (rootsFunc func() ([]string, error)) {
return edgeRoots
}
17 changes: 17 additions & 0 deletions internal/edge/find/find_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build darwin

package find

import (
"os"
"path/filepath"
)

func edgeRoots() ([]string, error) {
// "$HOME/Library/Application Support"
cfgDir, err := os.UserConfigDir()
if err != nil {
return nil, err
}
return []string{filepath.Join(cfgDir, `Microsoft Edge`)}, nil
}
9 changes: 9 additions & 0 deletions internal/edge/find/find_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build plan9 || android || ios || js || aix

package find

import "errors"

func edgeRoots() ([]string, error) {
return nil, errors.New(`not implemented`)
}
12 changes: 12 additions & 0 deletions internal/edge/find/find_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !windows && !darwin && !plan9 && !android && !js && !aix

package find

import (
"os"
"path/filepath"
)

func edgeRoots() ([]string, error) {
return nil, errors.New(`not implemented`)
}
24 changes: 24 additions & 0 deletions internal/edge/find/find_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build windows
// +build windows

package find

import (
"errors"
"os"
"path/filepath"
)

func edgeRoots() ([]string, error) {
// AppData Local
locApp := os.Getenv(`LocalAppData`)
if len(locApp) == 0 {
return nil, errors.New(`%LocalAppData% is empty`)
}

var ret = []string{
filepath.Join(locApp, `Microsoft`, `Edge`, `User Data`),
}

return ret, nil
}