mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
feat: support profile path cmd options
This commit is contained in:
+37
-10
@@ -1,13 +1,14 @@
|
||||
package browser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"hack-browser-data/internal/browingdata"
|
||||
"hack-browser-data/internal/browser/chromium"
|
||||
"hack-browser-data/internal/browser/firefox"
|
||||
"hack-browser-data/internal/log"
|
||||
"hack-browser-data/internal/utils/fileutil"
|
||||
)
|
||||
|
||||
type Browser interface {
|
||||
@@ -18,15 +19,15 @@ type Browser interface {
|
||||
GetBrowsingData() (*browingdata.Data, error)
|
||||
}
|
||||
|
||||
func PickBrowser(name string) ([]Browser, error) {
|
||||
func PickBrowser(name, profile string) ([]Browser, error) {
|
||||
var browsers []Browser
|
||||
clist := pickChromium(name)
|
||||
clist := pickChromium(name, profile)
|
||||
for _, b := range clist {
|
||||
if b != nil {
|
||||
browsers = append(browsers, b)
|
||||
}
|
||||
}
|
||||
flist := pickFirefox(name)
|
||||
flist := pickFirefox(name, profile)
|
||||
for _, b := range flist {
|
||||
if b != nil {
|
||||
browsers = append(browsers, b)
|
||||
@@ -35,9 +36,27 @@ func PickBrowser(name string) ([]Browser, error) {
|
||||
return browsers, nil
|
||||
}
|
||||
|
||||
func pickChromium(name string) []Browser {
|
||||
func PickBrowserByProfilePath(name, profile string) ([]Browser, error) {
|
||||
var browsers []Browser
|
||||
clist := pickChromium(name, profile)
|
||||
for _, b := range clist {
|
||||
if b != nil {
|
||||
browsers = append(browsers, b)
|
||||
}
|
||||
}
|
||||
flist := pickFirefox(name, profile)
|
||||
for _, b := range flist {
|
||||
if b != nil {
|
||||
browsers = append(browsers, b)
|
||||
}
|
||||
}
|
||||
return browsers, nil
|
||||
}
|
||||
|
||||
func pickChromium(name, profile string) []Browser {
|
||||
var browsers []Browser
|
||||
name = strings.ToLower(name)
|
||||
// TODO: add support for 「all」 flag and set profilePath
|
||||
if name == "all" {
|
||||
for _, c := range chromiumList {
|
||||
if b, err := chromium.New(c.name, c.storage, c.profilePath, c.items); err == nil {
|
||||
@@ -53,10 +72,13 @@ func pickChromium(name string) []Browser {
|
||||
return browsers
|
||||
}
|
||||
if c, ok := chromiumList[name]; ok {
|
||||
b, err := chromium.New(c.name, c.storage, c.profilePath, c.items)
|
||||
if profile == "" {
|
||||
profile = c.profilePath
|
||||
}
|
||||
b, err := chromium.New(c.name, c.storage, profile, c.items)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "profile path is not exist") {
|
||||
fmt.Println(err.Error())
|
||||
log.Error(err.Error())
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
@@ -67,16 +89,21 @@ func pickChromium(name string) []Browser {
|
||||
return nil
|
||||
}
|
||||
|
||||
func pickFirefox(name string) []Browser {
|
||||
func pickFirefox(name, profile string) []Browser {
|
||||
var browsers []Browser
|
||||
name = strings.ToLower(name)
|
||||
if name == "all" || name == "firefox" {
|
||||
for _, v := range firefoxList {
|
||||
multiFirefox, err := firefox.New(v.name, v.storage, v.profilePath, v.items)
|
||||
if profile == "" {
|
||||
profile = v.profilePath
|
||||
} else {
|
||||
profile = fileutil.ParentDir(profile)
|
||||
}
|
||||
multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items)
|
||||
// TODO: Handle error
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "profile path is not exist") {
|
||||
fmt.Println(err.Error())
|
||||
log.Error(err.Error())
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -89,16 +89,16 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
chromeProfilePath = homeDir + "/Library/Application Support/Google/Chrome/"
|
||||
chromeBetaProfilePath = homeDir + "/Library/Application Support/Google/Chrome Beta/"
|
||||
chromiumProfilePath = homeDir + "/Library/Application Support/Chromium/"
|
||||
edgeProfilePath = homeDir + "/Library/Application Support/Microsoft Edge/"
|
||||
braveProfilePath = homeDir + "/Library/Application Support/BraveSoftware/Brave-Browser/"
|
||||
operaProfilePath = homeDir + "/Library/Application Support/com.operasoftware.Opera/"
|
||||
operaGXProfilePath = homeDir + "/Library/Application Support/com.operasoftware.OperaGX/"
|
||||
vivaldiProfilePath = homeDir + "/Library/Application Support/Vivaldi/"
|
||||
coccocProfilePath = homeDir + "/Library/Application Support/Coccoc/"
|
||||
yandexProfilePath = homeDir + "/Library/Application Support/Yandex/YandexBrowser/"
|
||||
chromeProfilePath = homeDir + "/Library/Application Support/Google/Chrome/Default/"
|
||||
chromeBetaProfilePath = homeDir + "/Library/Application Support/Google/Chrome Beta/Default/"
|
||||
chromiumProfilePath = homeDir + "/Library/Application Support/Chromium/Default/"
|
||||
edgeProfilePath = homeDir + "/Library/Application Support/Microsoft Edge/Default/"
|
||||
braveProfilePath = homeDir + "/Library/Application Support/BraveSoftware/Brave-Browser/Default/"
|
||||
operaProfilePath = homeDir + "/Library/Application Support/com.operasoftware.Opera/Default/"
|
||||
operaGXProfilePath = homeDir + "/Library/Application Support/com.operasoftware.OperaGX/Default/"
|
||||
vivaldiProfilePath = homeDir + "/Library/Application Support/Vivaldi/Default/"
|
||||
coccocProfilePath = homeDir + "/Library/Application Support/Coccoc/Default/"
|
||||
yandexProfilePath = homeDir + "/Library/Application Support/Yandex/YandexBrowser/Default/"
|
||||
|
||||
firefoxProfilePath = homeDir + "/Library/Application Support/Firefox/Profiles/"
|
||||
)
|
||||
|
||||
@@ -72,13 +72,13 @@ var (
|
||||
|
||||
var (
|
||||
firefoxProfilePath = homeDir + "/.mozilla/firefox/"
|
||||
chromeProfilePath = homeDir + "/.config/google-chrome/"
|
||||
chromiumProfilePath = homeDir + "/.config/chromium/"
|
||||
edgeProfilePath = homeDir + "/.config/microsoft-edge*/"
|
||||
braveProfilePath = homeDir + "/.config/BraveSoftware/Brave-Browser/"
|
||||
chromeBetaProfilePath = homeDir + "/.config/google-chrome-beta/"
|
||||
operaProfilePath = homeDir + "/.config/opera/"
|
||||
vivaldiProfilePath = homeDir + "/.config/vivaldi/"
|
||||
chromeProfilePath = homeDir + "/.config/google-chrome/Default/"
|
||||
chromiumProfilePath = homeDir + "/.config/chromium/Default/"
|
||||
edgeProfilePath = homeDir + "/.config/microsoft-edge*/Default/"
|
||||
braveProfilePath = homeDir + "/.config/BraveSoftware/Brave-Browser/Default/"
|
||||
chromeBetaProfilePath = homeDir + "/.config/google-chrome-beta/Default/"
|
||||
operaProfilePath = homeDir + "/.config/opera/Default/"
|
||||
vivaldiProfilePath = homeDir + "/.config/vivaldi/Default/"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -89,18 +89,18 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
chromeProfilePath = homeDir + "/AppData/Local/Google/Chrome/User Data/"
|
||||
chromeBetaProfilePath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/"
|
||||
chromiumProfilePath = homeDir + "/AppData/Local/Chromium/User Data/"
|
||||
edgeProfilePath = homeDir + "/AppData/Local/Microsoft/Edge/User Data/"
|
||||
braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/"
|
||||
speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/"
|
||||
qqBrowserProfilePath = homeDir + "/AppData/Local/Tencent/QQBrowser/User Data/"
|
||||
operaProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera Stable/"
|
||||
operaGXProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera GX Stable/"
|
||||
vivaldiProfilePath = homeDir + "/AppData/Local/Vivaldi/User Data/"
|
||||
coccocProfilePath = homeDir + "/AppData/Local/CocCoc/Browser/User Data/"
|
||||
yandexProfilePath = homeDir + "/AppData/Local/Yandex/YandexBrowser/User Data/"
|
||||
chromeProfilePath = homeDir + "/AppData/Local/Google/Chrome/User Data/Default/"
|
||||
chromeBetaProfilePath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/Default/"
|
||||
chromiumProfilePath = homeDir + "/AppData/Local/Chromium/User Data/Default/"
|
||||
edgeProfilePath = homeDir + "/AppData/Local/Microsoft/Edge/User Data/Default/"
|
||||
braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/Default/"
|
||||
speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/Default/"
|
||||
qqBrowserProfilePath = homeDir + "/AppData/Local/Tencent/QQBrowser/User Data/Default/"
|
||||
operaProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera Stable/Default/"
|
||||
operaGXProfilePath = homeDir + "/AppData/Roaming/Opera Software/Opera GX Stable/Default/"
|
||||
vivaldiProfilePath = homeDir + "/AppData/Local/Vivaldi/User Data/Default/"
|
||||
coccocProfilePath = homeDir + "/AppData/Local/CocCoc/Browser/User Data/Default/"
|
||||
yandexProfilePath = homeDir + "/AppData/Local/Yandex/YandexBrowser/User Data/Default/"
|
||||
|
||||
firefoxProfilePath = homeDir + "/AppData/Roaming/Mozilla/Firefox/Profiles/"
|
||||
)
|
||||
|
||||
@@ -84,11 +84,13 @@ func (c *chromium) copyItemToLocal() error {
|
||||
|
||||
func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.Item]string, error) {
|
||||
var itemPaths = make(map[item.Item]string)
|
||||
err := filepath.Walk(profilePath, chromiumWalkFunc(items, itemPaths))
|
||||
parentDir := fileutil.ParentDir(profilePath)
|
||||
baseDir := fileutil.BaseDir(profilePath)
|
||||
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
|
||||
return itemPaths, err
|
||||
}
|
||||
|
||||
func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string) filepath.WalkFunc {
|
||||
func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string, baseDir string) filepath.WalkFunc {
|
||||
return func(path string, info os.FileInfo, err error) error {
|
||||
for _, it := range items {
|
||||
switch {
|
||||
@@ -96,8 +98,7 @@ func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string) filepat
|
||||
if it == item.ChromiumKey {
|
||||
itemPaths[it] = path
|
||||
}
|
||||
// TODO: check file path is not in Default folder
|
||||
if strings.Contains(path, "Default") {
|
||||
if strings.Contains(path, baseDir) {
|
||||
itemPaths[it] = path
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,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"
|
||||
)
|
||||
@@ -24,20 +25,19 @@ type firefox struct {
|
||||
|
||||
// New returns a new firefox instance.
|
||||
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
|
||||
if !fileutil.FolderExists(profilePath) {
|
||||
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath)
|
||||
}
|
||||
f := &firefox{
|
||||
name: name,
|
||||
storage: storage,
|
||||
profilePath: profilePath,
|
||||
items: items,
|
||||
}
|
||||
if !fileutil.FolderExists(profilePath) {
|
||||
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath)
|
||||
}
|
||||
|
||||
multiItemPaths, err := f.getMultiItemPath(f.profilePath, f.items)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "profile path is not exist") {
|
||||
fmt.Println(err)
|
||||
log.Error(err)
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
@@ -55,7 +55,6 @@ func New(name, storage, profilePath string, items []item.Item) ([]*firefox, erro
|
||||
|
||||
func (f *firefox) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
|
||||
var multiItemPaths = make(map[string]map[item.Item]string)
|
||||
|
||||
err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths))
|
||||
return multiItemPaths, err
|
||||
}
|
||||
@@ -81,11 +80,11 @@ func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]
|
||||
return func(path string, info fs.FileInfo, err error) error {
|
||||
for _, v := range items {
|
||||
if info.Name() == v.FileName() {
|
||||
parentDir := getParentDir(path)
|
||||
if _, exist := multiItemPaths[parentDir]; exist {
|
||||
multiItemPaths[parentDir][v] = path
|
||||
parentBaseDir := fileutil.ParentBaseDir(path)
|
||||
if _, exist := multiItemPaths[parentBaseDir]; exist {
|
||||
multiItemPaths[parentBaseDir][v] = path
|
||||
} else {
|
||||
multiItemPaths[parentDir] = map[item.Item]string{v: path}
|
||||
multiItemPaths[parentBaseDir] = map[item.Item]string{v: path}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,10 +92,6 @@ func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]
|
||||
}
|
||||
}
|
||||
|
||||
func getParentDir(absPath string) string {
|
||||
return filepath.Base(filepath.Dir(absPath))
|
||||
}
|
||||
|
||||
func (f *firefox) GetMasterKey() ([]byte, error) {
|
||||
return f.masterKey, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user