feat: add copy file to local

This commit is contained in:
ᴍᴏᴏɴD4ʀᴋ
2022-04-11 19:57:40 +08:00
parent 46f2610a0a
commit dc06b1d69b
18 changed files with 83 additions and 258 deletions
+14 -9
View File
@@ -1,6 +1,7 @@
package browser
import (
"fmt"
"os"
"strings"
@@ -9,10 +10,10 @@ import (
)
type Browser interface {
GetName() string
Name() string
GetMasterKey() ([]byte, error)
// GetBrowsingData returns the browsing data for the browser.
GetBrowsingData() (*browingdata.Data, error)
}
@@ -52,7 +53,11 @@ func pickChromium(name string) []Browser {
if c, ok := chromiumList[name]; ok {
b, err := chromium.New(c.name, c.storage, c.profilePath, c.items)
if err != nil {
panic(err)
if strings.Contains(err.Error(), "profile path is not exist") {
fmt.Println(err.Error())
} else {
panic(err)
}
}
browsers = append(browsers, b)
return browsers
@@ -97,13 +102,13 @@ var (
const (
chromeName = "Chrome"
chromeBetaName = "Chrome Beta"
chromiumName = "ChromiumBookmark"
chromiumName = "Chromium"
edgeName = "Microsoft Edge"
firefoxName = "FirefoxBookmark"
firefoxBetaName = "FirefoxBookmark Beta"
firefoxDevName = "FirefoxBookmark Dev"
firefoxNightlyName = "FirefoxBookmark Nightly"
firefoxESRName = "FirefoxBookmark ESR"
firefoxName = "Firefox"
firefoxBetaName = "Firefox Beta"
firefoxDevName = "Firefox Dev"
firefoxNightlyName = "Firefox Nightly"
firefoxESRName = "Firefox ESR"
speed360Name = "360speed"
qqBrowserName = "QQ"
braveName = "Brave"
+2
View File
@@ -1,3 +1,5 @@
//go:build darwin
package browser
import (
+2
View File
@@ -1 +1,3 @@
//go:build linux
package browser
+6 -37
View File
@@ -10,38 +10,7 @@ import (
)
func TestPickChromium(t *testing.T) {
// browsers := pickChromium("chrome")
// log.InitLog("debug")
// filetype := "json"
// // dir := "result"
// output := outputter.NewOutPutter(filetype)
// _ = output
// for _, b := range browsers {
// fmt.Printf("%+v\n", b)
// if err := b.CopyItemFileToLocal(); err != nil {
// panic(err)
// }
// _, err := b.GetMasterKey()
// if err != nil {
// fmt.Println(err)
// }
// // browserName := b.GetName()
// data, err := b.GetBrowsingData()
// fmt.Println(data)
// // for _, data := range multiData {
// // if err := data.Parse(masterKey); err != nil {
// // fmt.Println(err)
// // }
// // filename := fmt.Sprintf("%s_%s.%s", browserName, data.Name(), filetype)
// // file, err := output.CreateFile(dir, filename)
// // if err != nil {
// // panic(err)
// // }
// // if err := output.Write(data, file); err != nil {
// // panic(err)
// // }
// // }
// }
}
func TestGetChromiumItemAbsPath(t *testing.T) {
@@ -55,7 +24,7 @@ func TestGetChromiumItemAbsPath(t *testing.T) {
if err != nil {
t.Error(err)
}
output := outputter.NewOutPutter("json")
output := outputter.New("json")
if err != nil {
t.Error(err)
@@ -74,18 +43,18 @@ func TestGetChromiumItemAbsPath(t *testing.T) {
func TestPickBrowsers(t *testing.T) {
browsers := PickBrowser("all")
for _, v := range browsers {
fmt.Println(v.GetName())
fmt.Println(v.Name())
}
// filetype := "json"
// dir := "result"
// output := outputter.NewOutPutter(filetype)
// output := outputter.New(filetype)
}
// func TestPickFirefox(t *testing.T) {
// browsers := pickFirefox("all")
// filetype := "json"
// dir := "result"
// output := outputter.NewOutPutter(filetype)
// output := outputter.New(filetype)
// if err := output.MakeDir("result"); err != nil {
// panic(err)
// }
@@ -98,7 +67,7 @@ func TestPickBrowsers(t *testing.T) {
// if err != nil {
// fmt.Println(err)
// }
// browserName := b.GetName()
// browserName := b.Name()
// multiData := b.GetBrowsingData()
// for _, data := range multiData {
// if err := data.Parse(masterKey); err != nil {
+2
View File
@@ -1,3 +1,5 @@
//go:build windows
package browser
import (
+8 -14
View File
@@ -32,30 +32,17 @@ func New(name, storage, profilePath string, items []item.Item) (*chromium, error
if !fileutil.FolderExists(profilePath) {
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath)
}
masterKey, err := c.GetMasterKey()
if err != nil {
return nil, err
}
itemsPaths, err := c.getItemPath(profilePath, items)
if err != nil {
return nil, err
}
c.masterKey = masterKey
c.profilePath = profilePath
c.itemPaths = itemsPaths
c.items = typeutil.Keys(itemsPaths)
return c, err
}
func (c *chromium) GetItems() []item.Item {
return c.items
}
func (c *chromium) GetItemPaths() map[item.Item]string {
return c.itemPaths
}
func (c *chromium) GetName() string {
func (c *chromium) Name() string {
return c.name
}
@@ -65,6 +52,13 @@ func (c *chromium) GetBrowsingData() (*browingdata.Data, error) {
if err := c.copyItemToLocal(); err != nil {
return nil, err
}
masterKey, err := c.GetMasterKey()
if err != nil {
return nil, err
}
c.masterKey = masterKey
if err := b.Recovery(c.masterKey); err != nil {
return nil, err
}
+13 -1
View File
@@ -4,13 +4,18 @@ import (
"bytes"
"crypto/sha1"
"errors"
"os"
"os/exec"
"strings"
"golang.org/x/crypto/pbkdf2"
"hack-browser-data/internal/item"
)
var (
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
ErrCouldNotFindInKeychain = errors.New("macOS could not find in keychain")
)
func (c *chromium) GetMasterKey() ([]byte, error) {
@@ -18,6 +23,10 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
cmd *exec.Cmd
stdout, stderr bytes.Buffer
)
// don't need chromium key file for macOS
defer os.Remove(item.TempChromiumKey)
// defer os.Remove(item.TempChromiumKey)
// Get the master key from the keychain
// $ security find-generic-password -wa 'Chrome'
cmd = exec.Command("security", "find-generic-password", "-wa", c.storage)
cmd.Stdout = &stdout
@@ -27,6 +36,9 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
return nil, err
}
if stderr.Len() > 0 {
if strings.Contains(stderr.String(), "could not be found") {
return nil, ErrCouldNotFindInKeychain
}
return nil, errors.New(stderr.String())
}
chromeSecret := bytes.TrimSpace(stdout.Bytes())
+1 -1
View File
@@ -100,7 +100,7 @@ package firefox
// return f.masterKey, nil
// }
//
// func (f *firefox) GetName() string {
// func (f *firefox) Name() string {
// return f.name
// }
//