refactor: refactor package with gofumpt

pull/143/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent e6aa1f0c61
commit 6d710c20e1
  1. 2
      cmd/hack-browser-data/main.go
  2. 2
      internal/browingdata/browsingdata.go
  3. 2
      internal/browingdata/creditcard/creditcard.go
  4. 8
      internal/browingdata/localstorage/localstorage.go
  5. 4
      internal/browingdata/outputter.go
  6. 4
      internal/browingdata/password/password.go
  7. 6
      internal/browser/browser.go
  8. 36
      internal/browser/browser_windows.go
  9. 7
      internal/browser/chromium/chromium.go
  10. 4
      internal/browser/chromium/chromium_darwin.go
  11. 4
      internal/browser/chromium/chromium_linux.go
  12. 6
      internal/browser/chromium/chromium_windows.go
  13. 7
      internal/browser/firefox/firefox.go
  14. 2
      internal/decrypter/decrypter_darwin.go
  15. 2
      internal/decrypter/decrypter_linux.go
  16. 6
      internal/utils/fileutil/filetutil.go
  17. 2
      internal/utils/typeutil/typeutil.go
  18. 12
      internal/utils/typeutil/typeutil_test.go

@ -29,7 +29,7 @@ func Execute() {
Name: "hack-browser-data", Name: "hack-browser-data",
Usage: "Export passwords/cookies/history/bookmarks from browser", Usage: "Export passwords/cookies/history/bookmarks from browser",
UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\nExport all browingdata(password/cookie/history/bookmark) from browser\nGithub Link: https://github.com/moonD4rk/HackBrowserData", UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\nExport all browingdata(password/cookie/history/bookmark) from browser\nGithub Link: https://github.com/moonD4rk/HackBrowserData",
Version: "0.4.2", Version: "0.4.3",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"}, &cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
&cli.BoolFlag{Name: "compress", Aliases: []string{"zip"}, Destination: &compress, Value: false, Usage: "compress result to zip"}, &cli.BoolFlag{Name: "compress", Aliases: []string{"zip"}, Destination: &compress, Value: false, Usage: "compress result to zip"},

@ -35,7 +35,6 @@ func New(sources []item.Item) *Data {
} }
func (d *Data) Recovery(masterKey []byte) error { func (d *Data) Recovery(masterKey []byte) error {
for _, source := range d.sources { for _, source := range d.sources {
if err := source.Parse(masterKey); err != nil { if err := source.Parse(masterKey); err != nil {
log.Errorf("parse %s error %s", source.Name(), err.Error()) log.Errorf("parse %s error %s", source.Name(), err.Error())
@ -48,7 +47,6 @@ func (d *Data) Output(dir, browserName, flag string) {
output := NewOutPutter(flag) output := NewOutPutter(flag)
for _, source := range d.sources { for _, source := range d.sources {
filename := fileutil.Filename(browserName, source.Name(), output.Ext()) filename := fileutil.Filename(browserName, source.Name(), output.Ext())
f, err := output.CreateFile(dir, filename) f, err := output.CreateFile(dir, filename)

@ -71,6 +71,7 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
} }
return nil return nil
} }
func (c *ChromiumCreditCard) Name() string { func (c *ChromiumCreditCard) Name() string {
return "creditcard" return "creditcard"
} }
@ -122,6 +123,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
} }
return nil return nil
} }
func (c *YandexCreditCard) Name() string { func (c *YandexCreditCard) Name() string {
return "creditcard" return "creditcard"
} }

@ -40,7 +40,7 @@ func (c *ChromiumLocalStorage) Parse(masterKey []byte) error {
if len(value) > 1024*5 { if len(value) > 1024*5 {
continue continue
} }
var s = new(storage) s := new(storage)
s.fillKey(key) s.fillKey(key)
s.fillValue(value) s.fillValue(value)
// don't save meta data // don't save meta data
@ -114,13 +114,11 @@ func (f *FirefoxLocalStorage) Parse(masterKey []byte) error {
} }
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
var ( var originKey, key, value string
originKey, key, value string
)
if err = rows.Scan(&originKey, &key, &value); err != nil { if err = rows.Scan(&originKey, &key, &value); err != nil {
log.Warn(err) log.Warn(err)
} }
var s = new(storage) s := new(storage)
s.fillFirefox(originKey, key, value) s.fillFirefox(originKey, key, value)
*f = append(*f, *s) *f = append(*f, *s)
} }

@ -50,7 +50,7 @@ func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
if dir != "" { if dir != "" {
if _, err := os.Stat(dir); os.IsNotExist(err) { if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0777) err := os.MkdirAll(dir, 0o777)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -60,7 +60,7 @@ func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
var file *os.File var file *os.File
var err error var err error
p := filepath.Join(dir, filename) p := filepath.Join(dir, filename)
file, err = os.OpenFile(p, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) file, err = os.OpenFile(p, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -229,9 +229,7 @@ func (f *FirefoxPassword) Name() string {
} }
func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err error) { func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err error) {
var ( var keyDB *sql.DB
keyDB *sql.DB
)
keyDB, err = sql.Open("sqlite3", key4file) keyDB, err = sql.Open("sqlite3", key4file)
if err != nil { if err != nil {
return nil, nil, nil, nil, err return nil, nil, nil, nil, err

@ -111,10 +111,8 @@ func ListBrowser() []string {
return l return l
} }
var ( // home dir path for all platforms
// home dir path for all platforms var homeDir, _ = os.UserHomeDir()
homeDir, _ = os.UserHomeDir()
)
const ( const (
chromeName = "Chrome" chromeName = "Chrome"

@ -3,9 +3,6 @@
package browser package browser
import ( import (
"io/ioutil"
"os"
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
) )
@ -18,7 +15,7 @@ var (
}{ }{
"chrome": { "chrome": {
name: chromeName, name: chromeName,
profilePath: getProfiles(chromeUserDataPath)[0], profilePath: chromeUserDataPath,
items: item.DefaultChromium, items: item.DefaultChromium,
}, },
"edge": { "edge": {
@ -28,12 +25,12 @@ var (
}, },
"chromium": { "chromium": {
name: chromiumName, name: chromiumName,
profilePath: getProfiles(chromiumUserDataPath)[0], profilePath: chromiumUserDataPath,
items: item.DefaultChromium, items: item.DefaultChromium,
}, },
"chrome-beta": { "chrome-beta": {
name: chromeBetaName, name: chromeBetaName,
profilePath: getProfiles(chromeBetaUserDataPath)[0], profilePath: chromeBetaUserDataPath,
items: item.DefaultChromium, items: item.DefaultChromium,
}, },
"opera": { "opera": {
@ -91,31 +88,10 @@ var (
} }
) )
func getProfiles(userDataPath string) []string {
var res []string
files, err := ioutil.ReadDir(userDataPath)
if err != nil {
res = append(res, userDataPath+"Default")
}
for _, f := range files {
if f.IsDir() && f.Name() != "System Profile" {
var thisPath = userDataPath + f.Name()
_, err := os.Stat(thisPath + "/Login Data")
if err == nil {
res = append(res, userDataPath+f.Name())
}
}
}
return res
}
var ( var (
chromeUserDataPath = homeDir + "/AppData/Local/Google/Chrome/User Data/" chromeUserDataPath = homeDir + "/AppData/Local/Google/Chrome/User Data/Default/"
chromeBetaUserDataPath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/" chromeBetaUserDataPath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/Default/"
chromiumUserDataPath = homeDir + "/AppData/Local/Chromium/User Data/" chromiumUserDataPath = homeDir + "/AppData/Local/Chromium/User Data/Default/"
edgeProfilePath = homeDir + "/AppData/Local/Microsoft/Edge/User Data/Default/" edgeProfilePath = homeDir + "/AppData/Local/Microsoft/Edge/User Data/Default/"
braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/Default/" braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/Default/"
speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/Default/" speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/Default/"

@ -39,6 +39,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*chromium, err
name: fileutil.BrowserName(name, user), name: fileutil.BrowserName(name, user),
items: typeutil.Keys(itemPaths), items: typeutil.Keys(itemPaths),
itemPaths: itemPaths, itemPaths: itemPaths,
storage: storage,
}) })
} }
return chromiumList, nil return chromiumList, nil
@ -90,7 +91,7 @@ func (c *chromium) copyItemToLocal() error {
} }
func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.Item]string, error) { func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.Item]string, error) {
var itemPaths = make(map[item.Item]string) itemPaths := make(map[item.Item]string)
parentDir := fileutil.ParentDir(profilePath) parentDir := fileutil.ParentDir(profilePath)
baseDir := fileutil.BaseDir(profilePath) baseDir := fileutil.BaseDir(profilePath)
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir)) err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
@ -102,7 +103,8 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
} }
func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
var multiItemPaths = make(map[string]map[item.Item]string) // multiItemPaths is a map of user to item path, map[profile 1][item's name & path key pair]
multiItemPaths := make(map[string]map[item.Item]string)
parentDir := fileutil.ParentDir(profilePath) parentDir := fileutil.ParentDir(profilePath)
err := filepath.Walk(parentDir, chromiumWalkFunc2(items, multiItemPaths)) err := filepath.Walk(parentDir, chromiumWalkFunc2(items, multiItemPaths))
if err != nil { if err != nil {
@ -126,6 +128,7 @@ func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[
} }
t[userDir] = v t[userDir] = v
t[userDir][item.ChromiumKey] = keyPath t[userDir][item.ChromiumKey] = keyPath
fillLocalStoragePath(t[userDir], item.ChromiumLocalStorage)
} }
return t, nil return t, nil
} }

@ -1,3 +1,5 @@
//go:build darwin
package chromium package chromium
import ( import (
@ -46,7 +48,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
if chromeSecret == nil { if chromeSecret == nil {
return nil, ErrWrongSecurityCommand return nil, ErrWrongSecurityCommand
} }
var chromeSalt = []byte("saltysalt") chromeSalt := []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157 // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New) key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
if key == nil { if key == nil {

@ -1,3 +1,5 @@
//go:build linux
package chromium package chromium
import ( import (
@ -60,7 +62,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
// @https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=100 // @https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=100
chromiumSecret = []byte("peanuts") chromiumSecret = []byte("peanuts")
} }
var chromiumSalt = []byte("saltysalt") chromiumSalt := []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc
key := pbkdf2.Key(chromiumSecret, chromiumSalt, 1, 16, sha1.New) key := pbkdf2.Key(chromiumSecret, chromiumSalt, 1, 16, sha1.New)
c.masterKey = key c.masterKey = key

@ -1,3 +1,5 @@
//go:build windows
package chromium package chromium
import ( import (
@ -13,9 +15,7 @@ import (
"hack-browser-data/internal/utils/fileutil" "hack-browser-data/internal/utils/fileutil"
) )
var ( var errDecodeMasterKeyFailed = errors.New("decode master key failed")
errDecodeMasterKeyFailed = errors.New("decode master key failed")
)
func (c *chromium) GetMasterKey() ([]byte, error) { func (c *chromium) GetMasterKey() ([]byte, error) {
keyFile, err := fileutil.ReadFile(item.TempChromiumKey) keyFile, err := fileutil.ReadFile(item.TempChromiumKey)

@ -21,13 +21,10 @@ type firefox struct {
itemPaths map[item.Item]string itemPaths map[item.Item]string
} }
var ( var ErrProfilePathNotFound = errors.New("profile path not found")
ErrProfilePathNotFound = errors.New("profile path not found")
)
// 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) {
f := &firefox{ f := &firefox{
name: name, name: name,
storage: storage, storage: storage,
@ -50,7 +47,7 @@ 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) { 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) multiItemPaths := make(map[string]map[item.Item]string)
err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths)) err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths))
return multiItemPaths, err return multiItemPaths, err
} }

@ -5,7 +5,7 @@ func Chromium(key, encryptPass []byte) ([]byte, error) {
if len(key) == 0 { if len(key) == 0 {
return nil, errSecurityKeyIsEmpty return nil, errSecurityKeyIsEmpty
} }
var chromeIV = []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32} chromeIV := []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
return aes128CBCDecrypt(key, chromeIV, encryptPass[3:]) return aes128CBCDecrypt(key, chromeIV, encryptPass[3:])
} else { } else {
return nil, errDecryptFailed return nil, errDecryptFailed

@ -1,7 +1,7 @@
package decrypter package decrypter
func Chromium(key, encryptPass []byte) ([]byte, error) { func Chromium(key, encryptPass []byte) ([]byte, error) {
var chromeIV = []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32} chromeIV := []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
if len(encryptPass) > 3 { if len(encryptPass) > 3 {
if len(key) == 0 { if len(key) == 0 {
return nil, errSecurityKeyIsEmpty return nil, errSecurityKeyIsEmpty

@ -81,7 +81,7 @@ func CopyDirHasSuffix(src, dst, suffix string) error {
if err != nil { if err != nil {
return err return err
} }
if err := os.MkdirAll(dst, 0755); err != nil { if err := os.MkdirAll(dst, 0o755); err != nil {
return err return err
} }
for index, file := range filelist { for index, file := range filelist {
@ -102,7 +102,7 @@ func CopyFile(src, dst string) error {
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(dst, d, 0777) err = ioutil.WriteFile(dst, d, 0o777)
if err != nil { if err != nil {
return err return err
} }
@ -141,7 +141,7 @@ func CompressDir(dir string) error {
if err != nil { if err != nil {
return err return err
} }
var b = new(bytes.Buffer) b := new(bytes.Buffer)
zw := zip.NewWriter(b) zw := zip.NewWriter(b)
for _, f := range files { for _, f := range files {
fw, _ := zw.Create(f.Name()) fw, _ := zw.Create(f.Name())

@ -24,7 +24,7 @@ func IntToBool[T constraints.Signed](a T) bool {
} }
func Reverse[T any](s []T) []T { func Reverse[T any](s []T) []T {
var h = make([]T, len(s)) h := make([]T, len(s))
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
h[i] = s[len(s)-i-1] h[i] = s[len(s)-i-1]
} }

@ -4,13 +4,11 @@ import (
"testing" "testing"
) )
var ( var reverseTestCases = [][]any{
reverseTestCases = [][]any{ {1, 2, 3, 4, 5},
[]any{1, 2, 3, 4, 5}, {"1", "2", "3", "4", "5"},
[]any{"1", "2", "3", "4", "5"}, {"1", 2, "3", "4", 5},
[]any{"1", 2, "3", "4", 5}, }
}
)
func TestReverse(t *testing.T) { func TestReverse(t *testing.T) {
for _, ts := range reverseTestCases { for _, ts := range reverseTestCases {

Loading…
Cancel
Save