From b65d3186c4d40355129f6f5e27b816d33f18cd09 Mon Sep 17 00:00:00 2001 From: moonD4rk Date: Fri, 10 Mar 2023 14:52:26 +0800 Subject: [PATCH 1/3] chore: update project layout --- .gitignore | 5 +- .golangci.yml | 4 +- .../bookmark/bookmark.go | 10 ++-- .../browsingdata.go | 22 +++---- .../cookie/cookie.go | 14 ++--- .../creditcard/creditcard.go | 16 +++--- .../download/download.go | 8 +-- .../extension/extension.go | 8 +-- .../history/history.go | 8 +-- .../localstorage/localstorage.go | 8 +-- .../browingdata => browingdata}/outputter.go | 0 .../outputter_test.go | 0 .../password/password.go | 26 ++++----- .../provider.go => browser/browser.go | 57 ++++++++----------- .../provider => browser}/chromium/chromium.go | 29 +++++----- .../chromium/chromium_darwin.go | 6 +- .../chromium/chromium_linux.go | 6 +- .../chromium/chromium_windows.go | 11 ++-- browser/consts.go | 26 +++++++++ .../provider => browser}/firefox/firefox.go | 33 ++++++----- .../provider => browser}/provider_darwin.go | 4 +- .../provider => browser}/provider_linux.go | 4 +- .../provider => browser}/provider_windows.go | 20 +++---- cmd/hack-browser-data/main.go | 13 ++--- .../decrypter.go => crypto/crypto.go | 2 +- .../crypto_darwin.go | 2 +- .../crypto_linux.go | 2 +- .../crypto_windows.go | 2 +- go.mod | 2 +- internal/browser/browser.go | 12 ---- {internal/item => item}/filename.go | 0 {internal/item => item}/item.go | 0 {internal/log => log}/log.go | 0 .../utils => utils}/fileutil/filetutil.go | 0 .../utils => utils}/typeutil/typeutil.go | 0 .../utils => utils}/typeutil/typeutil_test.go | 0 36 files changed, 181 insertions(+), 179 deletions(-) rename {internal/browingdata => browingdata}/bookmark/bookmark.go (94%) rename {internal/browingdata => browingdata}/browsingdata.go (81%) rename {internal/browingdata => browingdata}/cookie/cookie.go (92%) rename {internal/browingdata => browingdata}/creditcard/creditcard.go (89%) rename {internal/browingdata => browingdata}/download/download.go (95%) rename {internal/browingdata => browingdata}/extension/extension.go (92%) rename {internal/browingdata => browingdata}/history/history.go (94%) rename {internal/browingdata => browingdata}/localstorage/localstorage.go (95%) rename {internal/browingdata => browingdata}/outputter.go (100%) rename {internal/browingdata => browingdata}/outputter_test.go (100%) rename {internal/browingdata => browingdata}/password/password.go (91%) rename internal/provider/provider.go => browser/browser.go (68%) rename {internal/provider => browser}/chromium/chromium.go (83%) rename {internal/provider => browser}/chromium/chromium_darwin.go (90%) rename {internal/provider => browser}/chromium/chromium_linux.go (92%) rename {internal/provider => browser}/chromium/chromium_windows.go (71%) create mode 100644 browser/consts.go rename {internal/provider => browser}/firefox/firefox.go (72%) rename {internal/provider => browser}/provider_darwin.go (98%) rename {internal/provider => browser}/provider_linux.go (97%) rename {internal/provider => browser}/provider_windows.go (90%) rename internal/decrypter/decrypter.go => crypto/crypto.go (99%) rename internal/decrypter/decrypter_darwin.go => crypto/crypto_darwin.go (94%) rename internal/decrypter/decrypter_linux.go => crypto/crypto_linux.go (95%) rename internal/decrypter/decrypter_windows.go => crypto/crypto_windows.go (99%) delete mode 100644 internal/browser/browser.go rename {internal/item => item}/filename.go (100%) rename {internal/item => item}/item.go (100%) rename {internal/log => log}/log.go (100%) rename {internal/utils => utils}/fileutil/filetutil.go (100%) rename {internal/utils => utils}/typeutil/typeutil.go (100%) rename {internal/utils => utils}/typeutil/typeutil_test.go (100%) diff --git a/.gitignore b/.gitignore index 85d4ac9..9b6e196 100644 --- a/.gitignore +++ b/.gitignore @@ -190,4 +190,7 @@ result/ results/ hack-browser-data -!/cmd/hack-browser-data \ No newline at end of file +!/cmd/hack-browser-data +!/browingdata/history +!/browingdata/history/history.go +!/browingdata/history/history_test.go diff --git a/.golangci.yml b/.golangci.yml index 83d753e..42aacfa 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,7 +30,7 @@ linters: - 'unconvert' - 'whitespace' disable: -# unsupported lint with golang 1.18+ ref: https://github.com/golangci/golangci-lint/issues/2649 + # unsupported lint with golang 1.18+ ref: https://github.com/golangci/golangci-lint/issues/2649 - 'bodyclose' - 'gosimple' - 'noctx' @@ -60,7 +60,7 @@ issues: - G502 - G505 exclude-rules: - - path: internal/provider/provider\.go + - path: browser/browser\.go linters: - 'unused' max-issues-per-linter: 0 diff --git a/internal/browingdata/bookmark/bookmark.go b/browingdata/bookmark/bookmark.go similarity index 94% rename from internal/browingdata/bookmark/bookmark.go rename to browingdata/bookmark/bookmark.go index 0dcd03f..fd3327b 100644 --- a/internal/browingdata/bookmark/bookmark.go +++ b/browingdata/bookmark/bookmark.go @@ -6,14 +6,14 @@ import ( "sort" "time" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/fileutil" - "hack-browser-data/internal/utils/typeutil" - // import sqlite3 driver _ "github.com/mattn/go-sqlite3" "github.com/tidwall/gjson" + + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/fileutil" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) type ChromiumBookmark []bookmark diff --git a/internal/browingdata/browsingdata.go b/browingdata/browsingdata.go similarity index 81% rename from internal/browingdata/browsingdata.go rename to browingdata/browsingdata.go index 7e1c275..4f700c5 100644 --- a/internal/browingdata/browsingdata.go +++ b/browingdata/browsingdata.go @@ -3,17 +3,17 @@ package browingdata import ( "path" - "hack-browser-data/internal/browingdata/bookmark" - "hack-browser-data/internal/browingdata/cookie" - "hack-browser-data/internal/browingdata/creditcard" - "hack-browser-data/internal/browingdata/download" - "hack-browser-data/internal/browingdata/extension" - "hack-browser-data/internal/browingdata/history" - "hack-browser-data/internal/browingdata/localstorage" - "hack-browser-data/internal/browingdata/password" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/fileutil" + "github.com/moond4rk/HackBrowserData/browingdata/bookmark" + "github.com/moond4rk/HackBrowserData/browingdata/cookie" + "github.com/moond4rk/HackBrowserData/browingdata/creditcard" + "github.com/moond4rk/HackBrowserData/browingdata/download" + "github.com/moond4rk/HackBrowserData/browingdata/extension" + "github.com/moond4rk/HackBrowserData/browingdata/history" + "github.com/moond4rk/HackBrowserData/browingdata/localstorage" + "github.com/moond4rk/HackBrowserData/browingdata/password" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/fileutil" ) type Data struct { diff --git a/internal/browingdata/cookie/cookie.go b/browingdata/cookie/cookie.go similarity index 92% rename from internal/browingdata/cookie/cookie.go rename to browingdata/cookie/cookie.go index 7f0e4f4..53aa750 100644 --- a/internal/browingdata/cookie/cookie.go +++ b/browingdata/cookie/cookie.go @@ -6,13 +6,13 @@ import ( "sort" "time" - "hack-browser-data/internal/decrypter" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/typeutil" - // import sqlite3 driver _ "github.com/mattn/go-sqlite3" + + "github.com/moond4rk/HackBrowserData/crypto" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) type ChromiumCookie []cookie @@ -73,9 +73,9 @@ func (c *ChromiumCookie) Parse(masterKey []byte) error { if len(encryptValue) > 0 { var err error if masterKey == nil { - value, err = decrypter.DPAPI(encryptValue) + value, err = crypto.DPAPI(encryptValue) } else { - value, err = decrypter.Chromium(masterKey, encryptValue) + value, err = crypto.Chromium(masterKey, encryptValue) } if err != nil { log.Error(err) diff --git a/internal/browingdata/creditcard/creditcard.go b/browingdata/creditcard/creditcard.go similarity index 89% rename from internal/browingdata/creditcard/creditcard.go rename to browingdata/creditcard/creditcard.go index b77d527..48c9611 100644 --- a/internal/browingdata/creditcard/creditcard.go +++ b/browingdata/creditcard/creditcard.go @@ -4,12 +4,12 @@ import ( "database/sql" "os" - "hack-browser-data/internal/decrypter" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - // import sqlite3 driver _ "github.com/mattn/go-sqlite3" + + "github.com/moond4rk/HackBrowserData/crypto" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" ) type ChromiumCreditCard []card @@ -57,12 +57,12 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error { NickName: nickname, } if masterKey == nil { - value, err = decrypter.DPAPI(encryptValue) + value, err = crypto.DPAPI(encryptValue) if err != nil { return err } } else { - value, err = decrypter.Chromium(masterKey, encryptValue) + value, err = crypto.Chromium(masterKey, encryptValue) if err != nil { return err } @@ -113,12 +113,12 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error { NickName: nickname, } if masterKey == nil { - value, err = decrypter.DPAPI(encryptValue) + value, err = crypto.DPAPI(encryptValue) if err != nil { return err } } else { - value, err = decrypter.Chromium(masterKey, encryptValue) + value, err = crypto.Chromium(masterKey, encryptValue) if err != nil { return err } diff --git a/internal/browingdata/download/download.go b/browingdata/download/download.go similarity index 95% rename from internal/browingdata/download/download.go rename to browingdata/download/download.go index a74d242..4209677 100644 --- a/internal/browingdata/download/download.go +++ b/browingdata/download/download.go @@ -7,13 +7,13 @@ import ( "strings" "time" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/typeutil" - // import sqlite3 driver _ "github.com/mattn/go-sqlite3" "github.com/tidwall/gjson" + + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) type ChromiumDownload []download diff --git a/internal/browingdata/extension/extension.go b/browingdata/extension/extension.go similarity index 92% rename from internal/browingdata/extension/extension.go rename to browingdata/extension/extension.go index 9a1bd01..e3b06bb 100644 --- a/internal/browingdata/extension/extension.go +++ b/browingdata/extension/extension.go @@ -3,11 +3,11 @@ package extension import ( "os" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/fileutil" - "github.com/tidwall/gjson" + + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/fileutil" ) type ChromiumExtension []*extension diff --git a/internal/browingdata/history/history.go b/browingdata/history/history.go similarity index 94% rename from internal/browingdata/history/history.go rename to browingdata/history/history.go index 52e1e78..619d05c 100644 --- a/internal/browingdata/history/history.go +++ b/browingdata/history/history.go @@ -6,12 +6,12 @@ import ( "sort" "time" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/typeutil" - // import sqlite3 driver _ "github.com/mattn/go-sqlite3" + + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) type ChromiumHistory []history diff --git a/internal/browingdata/localstorage/localstorage.go b/browingdata/localstorage/localstorage.go similarity index 95% rename from internal/browingdata/localstorage/localstorage.go rename to browingdata/localstorage/localstorage.go index 8999c2c..6f3521a 100644 --- a/internal/browingdata/localstorage/localstorage.go +++ b/browingdata/localstorage/localstorage.go @@ -7,11 +7,11 @@ import ( "os" "strings" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/typeutil" - "github.com/syndtr/goleveldb/leveldb" + + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) type ChromiumLocalStorage []storage diff --git a/internal/browingdata/outputter.go b/browingdata/outputter.go similarity index 100% rename from internal/browingdata/outputter.go rename to browingdata/outputter.go diff --git a/internal/browingdata/outputter_test.go b/browingdata/outputter_test.go similarity index 100% rename from internal/browingdata/outputter_test.go rename to browingdata/outputter_test.go diff --git a/internal/browingdata/password/password.go b/browingdata/password/password.go similarity index 91% rename from internal/browingdata/password/password.go rename to browingdata/password/password.go index d6ddd06..6196c92 100644 --- a/internal/browingdata/password/password.go +++ b/browingdata/password/password.go @@ -8,14 +8,14 @@ import ( "sort" "time" - "hack-browser-data/internal/decrypter" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/typeutil" - // import sqlite3 driver _ "github.com/mattn/go-sqlite3" "github.com/tidwall/gjson" + + "github.com/moond4rk/HackBrowserData/crypto" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) type ChromiumPassword []loginData @@ -63,9 +63,9 @@ func (c *ChromiumPassword) Parse(masterKey []byte) error { if len(pwd) > 0 { var err error if masterKey == nil { - password, err = decrypter.DPAPI(pwd) + password, err = crypto.DPAPI(pwd) } else { - password, err = decrypter.Chromium(masterKey, pwd) + password, err = crypto.Chromium(masterKey, pwd) } if err != nil { log.Error(err) @@ -131,9 +131,9 @@ func (c *YandexPassword) Parse(masterKey []byte) error { if len(pwd) > 0 { var err error if masterKey == nil { - password, err = decrypter.DPAPI(pwd) + password, err = crypto.DPAPI(pwd) } else { - password, err = decrypter.Chromium(masterKey, pwd) + password, err = crypto.Chromium(masterKey, pwd) } if err != nil { log.Errorf("decrypt yandex password error %s", err) @@ -174,7 +174,7 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error { if err != nil { return err } - metaPBE, err := decrypter.NewASN1PBE(metaBytes) + metaPBE, err := crypto.NewASN1PBE(metaBytes) if err != nil { return err } @@ -187,7 +187,7 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error { if bytes.Contains(k, []byte("password-check")) { m := bytes.Compare(nssA102, keyLin) if m == 0 { - nssPBE, err := decrypter.NewASN1PBE(nssA11) + nssPBE, err := crypto.NewASN1PBE(nssA11) if err != nil { return err } @@ -201,11 +201,11 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error { return err } for _, v := range allLogin { - userPBE, err := decrypter.NewASN1PBE(v.encryptUser) + userPBE, err := crypto.NewASN1PBE(v.encryptUser) if err != nil { return err } - pwdPBE, err := decrypter.NewASN1PBE(v.encryptPass) + pwdPBE, err := crypto.NewASN1PBE(v.encryptPass) if err != nil { return err } diff --git a/internal/provider/provider.go b/browser/browser.go similarity index 68% rename from internal/provider/provider.go rename to browser/browser.go index 3b59766..3e23cfa 100644 --- a/internal/provider/provider.go +++ b/browser/browser.go @@ -1,21 +1,27 @@ -package provider +package browser import ( - "os" "path/filepath" "sort" "strings" - "hack-browser-data/internal/browser" - "hack-browser-data/internal/log" - "hack-browser-data/internal/provider/chromium" - "hack-browser-data/internal/provider/firefox" - "hack-browser-data/internal/utils/fileutil" - "hack-browser-data/internal/utils/typeutil" + "github.com/moond4rk/HackBrowserData/browingdata" + "github.com/moond4rk/HackBrowserData/browser/chromium" + "github.com/moond4rk/HackBrowserData/browser/firefox" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/fileutil" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) -func PickBrowsers(name, profile string) ([]browser.Browser, error) { - var browsers []browser.Browser +type Browser interface { + // Name is browser's name + Name() string + // BrowsingData returns all browsing data in the browser. + BrowsingData() (*browingdata.Data, error) +} + +func PickBrowsers(name, profile string) ([]Browser, error) { + var browsers []Browser clist := pickChromium(name, profile) for _, b := range clist { if b != nil { @@ -31,8 +37,8 @@ func PickBrowsers(name, profile string) ([]browser.Browser, error) { return browsers, nil } -func pickChromium(name, profile string) []browser.Browser { - var browsers []browser.Browser +func pickChromium(name, profile string) []Browser { + var browsers []Browser name = strings.ToLower(name) if name == "all" { for _, v := range chromiumList { @@ -70,8 +76,8 @@ func pickChromium(name, profile string) []browser.Browser { return browsers } -func pickFirefox(name, profile string) []browser.Browser { - var browsers []browser.Browser +func pickFirefox(name, profile string) []Browser { + var browsers []Browser name = strings.ToLower(name) if name == "all" || name == "firefox" { for _, v := range firefoxList { @@ -106,23 +112,6 @@ func ListBrowsers() []string { return l } -// home dir path for all platforms -var homeDir, _ = os.UserHomeDir() - -const ( - chromeName = "Chrome" - chromeBetaName = "Chrome Beta" - chromiumName = "Chromium" - edgeName = "Microsoft Edge" - braveName = "Brave" - operaName = "Opera" - operaGXName = "OperaGX" - vivaldiName = "Vivaldi" - coccocName = "CocCoc" - yandexName = "Yandex" - firefoxName = "Firefox" - speed360Name = "360speed" - qqBrowserName = "QQ" - dcbrowserName = "dcbrowser" - sougouName = "Sougou" -) +func Names() string { + return strings.Join(ListBrowsers(), "|") +} diff --git a/internal/provider/chromium/chromium.go b/browser/chromium/chromium.go similarity index 83% rename from internal/provider/chromium/chromium.go rename to browser/chromium/chromium.go index f1e2041..c6bce82 100644 --- a/internal/provider/chromium/chromium.go +++ b/browser/chromium/chromium.go @@ -5,14 +5,13 @@ import ( "path/filepath" "strings" - "hack-browser-data/internal/browingdata" - "hack-browser-data/internal/browser" - "hack-browser-data/internal/item" - "hack-browser-data/internal/utils/fileutil" - "hack-browser-data/internal/utils/typeutil" + "github.com/moond4rk/HackBrowserData/browingdata" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/utils/fileutil" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) -type chromium struct { +type Chromium struct { name string storage string profilePath string @@ -21,9 +20,9 @@ type chromium struct { itemPaths map[item.Item]string } -// New create instance of chromium browser, fill item's path if item is existed. -func New(name, storage, profilePath string, items []item.Item) ([]browser.Browser, error) { - c := &chromium{ +// New create instance of Chromium browser, fill item's path if item is existed. +func New(name, storage, profilePath string, items []item.Item) ([]*Chromium, error) { + c := &Chromium{ name: name, storage: storage, profilePath: profilePath, @@ -33,9 +32,9 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse if err != nil { return nil, err } - chromiumList := make([]browser.Browser, 0, len(multiItemPaths)) + chromiumList := make([]*Chromium, 0, len(multiItemPaths)) for user, itemPaths := range multiItemPaths { - chromiumList = append(chromiumList, &chromium{ + chromiumList = append(chromiumList, &Chromium{ name: fileutil.BrowserName(name, user), items: typeutil.Keys(itemPaths), itemPaths: itemPaths, @@ -45,11 +44,11 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse return chromiumList, nil } -func (c *chromium) Name() string { +func (c *Chromium) Name() string { return c.name } -func (c *chromium) BrowsingData() (*browingdata.Data, error) { +func (c *Chromium) BrowsingData() (*browingdata.Data, error) { b := browingdata.New(c.items) if err := c.copyItemToLocal(); err != nil { @@ -68,7 +67,7 @@ func (c *chromium) BrowsingData() (*browingdata.Data, error) { return b, nil } -func (c *chromium) copyItemToLocal() error { +func (c *Chromium) copyItemToLocal() error { for i, path := range c.itemPaths { filename := i.String() var err error @@ -90,7 +89,7 @@ func (c *chromium) copyItemToLocal() error { return nil } -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) { // 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) diff --git a/internal/provider/chromium/chromium_darwin.go b/browser/chromium/chromium_darwin.go similarity index 90% rename from internal/provider/chromium/chromium_darwin.go rename to browser/chromium/chromium_darwin.go index a8ebe36..08bf85d 100644 --- a/internal/provider/chromium/chromium_darwin.go +++ b/browser/chromium/chromium_darwin.go @@ -12,8 +12,8 @@ import ( "golang.org/x/crypto/pbkdf2" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" ) var ( @@ -21,7 +21,7 @@ var ( errCouldNotFindInKeychain = errors.New("could not be find in keychain") ) -func (c *chromium) GetMasterKey() ([]byte, error) { +func (c *Chromium) GetMasterKey() ([]byte, error) { var ( cmd *exec.Cmd stdout, stderr bytes.Buffer diff --git a/internal/provider/chromium/chromium_linux.go b/browser/chromium/chromium_linux.go similarity index 92% rename from internal/provider/chromium/chromium_linux.go rename to browser/chromium/chromium_linux.go index f9893bd..c3475a1 100644 --- a/internal/provider/chromium/chromium_linux.go +++ b/browser/chromium/chromium_linux.go @@ -11,11 +11,11 @@ import ( keyring "github.com/ppacher/go-dbus-keyring" "golang.org/x/crypto/pbkdf2" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" ) -func (c *chromium) GetMasterKey() ([]byte, error) { +func (c *Chromium) GetMasterKey() ([]byte, error) { // what is d-bus @https://dbus.freedesktop.org/ var chromiumSecret []byte conn, err := dbus.SessionBus() diff --git a/internal/provider/chromium/chromium_windows.go b/browser/chromium/chromium_windows.go similarity index 71% rename from internal/provider/chromium/chromium_windows.go rename to browser/chromium/chromium_windows.go index a54b0e7..17c172b 100644 --- a/internal/provider/chromium/chromium_windows.go +++ b/browser/chromium/chromium_windows.go @@ -9,15 +9,14 @@ import ( "github.com/tidwall/gjson" - "hack-browser-data/internal/decrypter" - "hack-browser-data/internal/item" - "hack-browser-data/internal/log" - "hack-browser-data/internal/utils/fileutil" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/fileutil" ) var 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) if err != nil { return nil, err @@ -31,7 +30,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) { if err != nil { return nil, errDecodeMasterKeyFailed } - c.masterKey, err = decrypter.DPAPI(pureKey[5:]) + c.masterKey, err = crypto.DPAPI(pureKey[5:]) log.Infof("%s initialized master key success", c.name) return c.masterKey, err } diff --git a/browser/consts.go b/browser/consts.go new file mode 100644 index 0000000..1fa73d1 --- /dev/null +++ b/browser/consts.go @@ -0,0 +1,26 @@ +package browser + +import ( + "os" +) + +// home dir path for all platforms +var homeDir, _ = os.UserHomeDir() + +const ( + chromeName = "Chrome" + chromeBetaName = "Chrome Beta" + chromiumName = "Chromium" + edgeName = "Microsoft Edge" + braveName = "Brave" + operaName = "Opera" + operaGXName = "OperaGX" + vivaldiName = "Vivaldi" + coccocName = "CocCoc" + yandexName = "Yandex" + firefoxName = "Firefox" + speed360Name = "360speed" + qqBrowserName = "QQ" + dcBrowserName = "DC" + sogouName = "Sogou" +) diff --git a/internal/provider/firefox/firefox.go b/browser/firefox/firefox.go similarity index 72% rename from internal/provider/firefox/firefox.go rename to browser/firefox/firefox.go index 268f342..3f75346 100644 --- a/internal/provider/firefox/firefox.go +++ b/browser/firefox/firefox.go @@ -6,14 +6,13 @@ import ( "io/fs" "path/filepath" - "hack-browser-data/internal/browingdata" - "hack-browser-data/internal/browser" - "hack-browser-data/internal/item" - "hack-browser-data/internal/utils/fileutil" - "hack-browser-data/internal/utils/typeutil" + "github.com/moond4rk/HackBrowserData/browingdata" + "github.com/moond4rk/HackBrowserData/item" + "github.com/moond4rk/HackBrowserData/utils/fileutil" + "github.com/moond4rk/HackBrowserData/utils/typeutil" ) -type firefox struct { +type Firefox struct { name string storage string profilePath string @@ -24,9 +23,9 @@ type firefox struct { var ErrProfilePathNotFound = errors.New("profile path not found") -// New returns a new firefox instance. -func New(name, storage, profilePath string, items []item.Item) ([]browser.Browser, error) { - f := &firefox{ +// New returns a new Firefox instance. +func New(name, storage, profilePath string, items []item.Item) ([]*Firefox, error) { + f := &Firefox{ name: name, storage: storage, profilePath: profilePath, @@ -37,10 +36,10 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse return nil, err } - firefoxList := make([]browser.Browser, 0, len(multiItemPaths)) + firefoxList := make([]*Firefox, 0, len(multiItemPaths)) for name, itemPaths := range multiItemPaths { - firefoxList = append(firefoxList, &firefox{ - name: fmt.Sprintf("firefox-%s", name), + firefoxList = append(firefoxList, &Firefox{ + name: fmt.Sprintf("Firefox-%s", name), items: typeutil.Keys(itemPaths), itemPaths: itemPaths, }) @@ -48,13 +47,13 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse return firefoxList, nil } -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) { multiItemPaths := make(map[string]map[item.Item]string) err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths)) return multiItemPaths, err } -func (f *firefox) copyItemToLocal() error { +func (f *Firefox) copyItemToLocal() error { for i, path := range f.itemPaths { filename := i.String() if err := fileutil.CopyFile(path, filename); err != nil { @@ -80,15 +79,15 @@ func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item] } } -func (f *firefox) GetMasterKey() ([]byte, error) { +func (f *Firefox) GetMasterKey() ([]byte, error) { return f.masterKey, nil } -func (f *firefox) Name() string { +func (f *Firefox) Name() string { return f.name } -func (f *firefox) BrowsingData() (*browingdata.Data, error) { +func (f *Firefox) BrowsingData() (*browingdata.Data, error) { b := browingdata.New(f.items) if err := f.copyItemToLocal(); err != nil { diff --git a/internal/provider/provider_darwin.go b/browser/provider_darwin.go similarity index 98% rename from internal/provider/provider_darwin.go rename to browser/provider_darwin.go index 6356436..88b99be 100644 --- a/internal/provider/provider_darwin.go +++ b/browser/provider_darwin.go @@ -1,9 +1,9 @@ //go:build darwin -package provider +package browser import ( - "hack-browser-data/internal/item" + "github.com/moond4rk/HackBrowserData/item" ) var ( diff --git a/internal/provider/provider_linux.go b/browser/provider_linux.go similarity index 97% rename from internal/provider/provider_linux.go rename to browser/provider_linux.go index 3f4a3cc..a989102 100644 --- a/internal/provider/provider_linux.go +++ b/browser/provider_linux.go @@ -1,9 +1,9 @@ //go:build linux -package provider +package browser import ( - "hack-browser-data/internal/item" + "github.com/moond4rk/HackBrowserData/item" ) var ( diff --git a/internal/provider/provider_windows.go b/browser/provider_windows.go similarity index 90% rename from internal/provider/provider_windows.go rename to browser/provider_windows.go index 812d5a5..6588eac 100644 --- a/internal/provider/provider_windows.go +++ b/browser/provider_windows.go @@ -1,9 +1,9 @@ //go:build windows -package provider +package browser import ( - "hack-browser-data/internal/item" + "github.com/moond4rk/HackBrowserData/item" ) var ( @@ -73,14 +73,14 @@ var ( profilePath: qqBrowserProfilePath, items: item.DefaultChromium, }, - "dcbrowser": { - name: dcbrowserName, - profilePath: dcbrowserUserDataPath, + "dc": { + name: dcBrowserName, + profilePath: dcBrowserProfilePath, items: item.DefaultChromium, }, - "sougou": { - name: sougouName, - profilePath: dcbrowserUserDataPath, + "sogou": { + name: sogouName, + profilePath: sogouProfilePath, items: item.DefaultChromium, }, } @@ -111,8 +111,8 @@ var ( 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/" - dcbrowserUserDataPath = homeDir + "/AppData/Local/DCBrowser/User Data/Default/" - sougouUserDataPath = homeDir + "/AppData/Roaming/SogouExplorer/Webkit/Default/" + dcBrowserProfilePath = homeDir + "/AppData/Local/DCBrowser/User Data/Default/" + sogouProfilePath = homeDir + "/AppData/Roaming/SogouExplorer/Webkit/Default/" firefoxProfilePath = homeDir + "/AppData/Roaming/Mozilla/Firefox/Profiles/" ) diff --git a/cmd/hack-browser-data/main.go b/cmd/hack-browser-data/main.go index 23355fe..07dd4b6 100644 --- a/cmd/hack-browser-data/main.go +++ b/cmd/hack-browser-data/main.go @@ -2,13 +2,12 @@ package main import ( "os" - "strings" - - "hack-browser-data/internal/log" - "hack-browser-data/internal/provider" - "hack-browser-data/internal/utils/fileutil" "github.com/urfave/cli/v2" + + "github.com/moond4rk/HackBrowserData/browser" + "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/fileutil" ) var ( @@ -33,7 +32,7 @@ func Execute() { Flags: []cli.Flag{ &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.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(provider.ListBrowsers(), "|")}, + &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + browser.Names()}, &cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &outputDir, Value: "results", Usage: "export dir"}, &cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "file name csv|json"}, &cli.StringFlag{Name: "profile-path", Aliases: []string{"p"}, Destination: &profilePath, Value: "", Usage: "custom profile dir path, get with chrome://version"}, @@ -46,7 +45,7 @@ func Execute() { log.Init("notice") } - browsers, err := provider.PickBrowsers(browserName, profilePath) + browsers, err := browser.PickBrowsers(browserName, profilePath) if err != nil { log.Error(err) } diff --git a/internal/decrypter/decrypter.go b/crypto/crypto.go similarity index 99% rename from internal/decrypter/decrypter.go rename to crypto/crypto.go index 415d681..7ada066 100644 --- a/internal/decrypter/decrypter.go +++ b/crypto/crypto.go @@ -1,4 +1,4 @@ -package decrypter +package crypto import ( "crypto/aes" diff --git a/internal/decrypter/decrypter_darwin.go b/crypto/crypto_darwin.go similarity index 94% rename from internal/decrypter/decrypter_darwin.go rename to crypto/crypto_darwin.go index 35645bc..44ed959 100644 --- a/internal/decrypter/decrypter_darwin.go +++ b/crypto/crypto_darwin.go @@ -1,6 +1,6 @@ //go:build darwin -package decrypter +package crypto func Chromium(key, encryptPass []byte) ([]byte, error) { if len(encryptPass) <= 3 { diff --git a/internal/decrypter/decrypter_linux.go b/crypto/crypto_linux.go similarity index 95% rename from internal/decrypter/decrypter_linux.go rename to crypto/crypto_linux.go index 6f8e2d5..05bd49b 100644 --- a/internal/decrypter/decrypter_linux.go +++ b/crypto/crypto_linux.go @@ -1,6 +1,6 @@ //go:build linux -package decrypter +package crypto func Chromium(key, encryptPass []byte) ([]byte, error) { if len(encryptPass) < 3 { diff --git a/internal/decrypter/decrypter_windows.go b/crypto/crypto_windows.go similarity index 99% rename from internal/decrypter/decrypter_windows.go rename to crypto/crypto_windows.go index 794d870..943f8c7 100644 --- a/internal/decrypter/decrypter_windows.go +++ b/crypto/crypto_windows.go @@ -1,6 +1,6 @@ //go:build windows -package decrypter +package crypto import ( "crypto/aes" diff --git a/go.mod b/go.mod index cea8f35..e135dab 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module hack-browser-data +module github.com/moond4rk/HackBrowserData go 1.19 diff --git a/internal/browser/browser.go b/internal/browser/browser.go deleted file mode 100644 index 18b3cc1..0000000 --- a/internal/browser/browser.go +++ /dev/null @@ -1,12 +0,0 @@ -package browser - -import ( - "hack-browser-data/internal/browingdata" -) - -type Browser interface { - // Name is browser's name - Name() string - // BrowsingData returns all browsing data in the browser. - BrowsingData() (*browingdata.Data, error) -} diff --git a/internal/item/filename.go b/item/filename.go similarity index 100% rename from internal/item/filename.go rename to item/filename.go diff --git a/internal/item/item.go b/item/item.go similarity index 100% rename from internal/item/item.go rename to item/item.go diff --git a/internal/log/log.go b/log/log.go similarity index 100% rename from internal/log/log.go rename to log/log.go diff --git a/internal/utils/fileutil/filetutil.go b/utils/fileutil/filetutil.go similarity index 100% rename from internal/utils/fileutil/filetutil.go rename to utils/fileutil/filetutil.go diff --git a/internal/utils/typeutil/typeutil.go b/utils/typeutil/typeutil.go similarity index 100% rename from internal/utils/typeutil/typeutil.go rename to utils/typeutil/typeutil.go diff --git a/internal/utils/typeutil/typeutil_test.go b/utils/typeutil/typeutil_test.go similarity index 100% rename from internal/utils/typeutil/typeutil_test.go rename to utils/typeutil/typeutil_test.go From b0cb59ec2caa150c25aa808513467d9b13f87bd5 Mon Sep 17 00:00:00 2001 From: moonD4rk Date: Fri, 10 Mar 2023 14:54:47 +0800 Subject: [PATCH 2/3] chore: update version flag --- cmd/hack-browser-data/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/hack-browser-data/main.go b/cmd/hack-browser-data/main.go index 07dd4b6..ff26680 100644 --- a/cmd/hack-browser-data/main.go +++ b/cmd/hack-browser-data/main.go @@ -28,7 +28,7 @@ func Execute() { Name: "hack-browser-data", Usage: "Export password|bookmark|cookie|history|credit card|download|localStorage|extension 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", - Version: "0.4.4", + Version: "0.5.0", Flags: []cli.Flag{ &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"}, From 4fca1a514fe0eaffa0146c6fba25939f5fc59b8d Mon Sep 17 00:00:00 2001 From: moonD4rk Date: Fri, 10 Mar 2023 15:09:50 +0800 Subject: [PATCH 3/3] refactor: rename provider name --- browser/{provider_darwin.go => browser_darwin.go} | 0 browser/{provider_linux.go => browser_linux.go} | 0 browser/{provider_windows.go => browser_windows.go} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename browser/{provider_darwin.go => browser_darwin.go} (100%) rename browser/{provider_linux.go => browser_linux.go} (100%) rename browser/{provider_windows.go => browser_windows.go} (100%) diff --git a/browser/provider_darwin.go b/browser/browser_darwin.go similarity index 100% rename from browser/provider_darwin.go rename to browser/browser_darwin.go diff --git a/browser/provider_linux.go b/browser/browser_linux.go similarity index 100% rename from browser/provider_linux.go rename to browser/browser_linux.go diff --git a/browser/provider_windows.go b/browser/browser_windows.go similarity index 100% rename from browser/provider_windows.go rename to browser/browser_windows.go