1 Star 0 Fork 0

wengo/kooky

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
find.go 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
package find
import (
"encoding/json"
"errors"
"io/ioutil"
"path/filepath"
"runtime"
)
type chromeCookieStoreFile struct {
Path string
Browser string
Profile string
OS string
IsDefaultProfile bool
}
func FindChromeCookieStoreFiles() ([]*chromeCookieStoreFile, error) {
return FindCookieStoreFiles(chromeRoots, `chrome`)
}
func FindChromiumCookieStoreFiles() ([]*chromeCookieStoreFile, error) {
return FindCookieStoreFiles(chromiumRoots, `chromium`)
}
func FindCookieStoreFiles(rootsFunc func() ([]string, error), browserName string) ([]*chromeCookieStoreFile, error) {
if rootsFunc == nil {
return nil, errors.New(`passed roots function is nil`)
}
var files []*chromeCookieStoreFile
roots, err := rootsFunc()
if err != nil {
return nil, err
}
for _, root := range roots {
localStateBytes, err := ioutil.ReadFile(filepath.Join(root, `Local State`))
if err != nil {
continue
}
var localState struct {
Profile struct {
InfoCache map[string]struct {
IsUsingDefaultName bool `json:"is_using_default_name"`
Name string
} `json:"info_cache"`
}
}
if err := json.Unmarshal(localStateBytes, &localState); err != nil {
// fallback - json file exists, json structure unknown
files = append(
files,
&chromeCookieStoreFile{
Browser: browserName,
Profile: `Profile 1`,
IsDefaultProfile: true,
Path: filepath.Join(root, `Default`, `Cookies`),
OS: runtime.GOOS,
},
)
continue
}
for profDir, profStr := range localState.Profile.InfoCache {
files = append(
files,
&chromeCookieStoreFile{
Browser: browserName,
Profile: profStr.Name,
IsDefaultProfile: profStr.IsUsingDefaultName,
Path: filepath.Join(root, profDir, `Cookies`),
OS: runtime.GOOS,
},
)
}
}
return files, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wengo/kooky.git
git@gitee.com:wengo/kooky.git
wengo
kooky
kooky
dc41c5585b72

搜索帮助