From 714e8a57b95a6bea4d69e908bd5ccece5a929e58 Mon Sep 17 00:00:00 2001 From: moonD4rk Date: Mon, 24 Oct 2022 13:36:01 +0800 Subject: [PATCH 1/2] chore: remove abandoned linter --- .golangci.yml | 8 +++--- .../chromium/chromium.go | 0 .../chromium/chromium_darwin.go | 0 .../chromium/chromium_linux.go | 0 .../chromium/chromium_windows.go | 0 .../{browser => provider}/firefox/firefox.go | 0 .../browser.go => provider/provider.go} | 27 +++++++------------ .../provider_darwin.go} | 2 +- .../provider_linux.go} | 2 +- .../provider_windows.go} | 2 +- 10 files changed, 16 insertions(+), 25 deletions(-) rename internal/{browser => provider}/chromium/chromium.go (100%) rename internal/{browser => provider}/chromium/chromium_darwin.go (100%) rename internal/{browser => provider}/chromium/chromium_linux.go (100%) rename internal/{browser => provider}/chromium/chromium_windows.go (100%) rename internal/{browser => provider}/firefox/firefox.go (100%) rename internal/{browser/browser.go => provider/provider.go} (83%) rename internal/{browser/browser_darwin.go => provider/provider_darwin.go} (99%) rename internal/{browser/browser_linux.go => provider/provider_linux.go} (99%) rename internal/{browser/browser_windows.go => provider/provider_windows.go} (99%) diff --git a/.golangci.yml b/.golangci.yml index 9702cb9..8705eb7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,7 +8,6 @@ run: linters: enable: - 'asciicheck' - - 'deadcode' - 'depguard' - 'dogsled' - 'errorlint' @@ -29,7 +28,6 @@ linters: - 'revive' - 'typecheck' - 'unconvert' - - 'varcheck' - 'whitespace' disable: # unsupported lint with golang 1.18+ ref: https://github.com/golangci/golangci-lint/issues/2649 @@ -42,6 +40,8 @@ linters: - 'stylecheck' - 'unused' - 'errcheck' + - 'deadcode' + - 'varcheck' issues: exclude-use-default: false @@ -60,10 +60,8 @@ issues: - G502 - G505 exclude-rules: - - path: internal/browser/browser\.go + - path: internal/provider/provider\.go linters: - - 'deadcode' - - 'varcheck' - 'unused' max-issues-per-linter: 0 max-same-issues: 0 diff --git a/internal/browser/chromium/chromium.go b/internal/provider/chromium/chromium.go similarity index 100% rename from internal/browser/chromium/chromium.go rename to internal/provider/chromium/chromium.go diff --git a/internal/browser/chromium/chromium_darwin.go b/internal/provider/chromium/chromium_darwin.go similarity index 100% rename from internal/browser/chromium/chromium_darwin.go rename to internal/provider/chromium/chromium_darwin.go diff --git a/internal/browser/chromium/chromium_linux.go b/internal/provider/chromium/chromium_linux.go similarity index 100% rename from internal/browser/chromium/chromium_linux.go rename to internal/provider/chromium/chromium_linux.go diff --git a/internal/browser/chromium/chromium_windows.go b/internal/provider/chromium/chromium_windows.go similarity index 100% rename from internal/browser/chromium/chromium_windows.go rename to internal/provider/chromium/chromium_windows.go diff --git a/internal/browser/firefox/firefox.go b/internal/provider/firefox/firefox.go similarity index 100% rename from internal/browser/firefox/firefox.go rename to internal/provider/firefox/firefox.go diff --git a/internal/browser/browser.go b/internal/provider/provider.go similarity index 83% rename from internal/browser/browser.go rename to internal/provider/provider.go index a3476e9..cc5b46e 100644 --- a/internal/browser/browser.go +++ b/internal/provider/provider.go @@ -1,4 +1,4 @@ -package browser +package provider import ( "os" @@ -6,23 +6,16 @@ import ( "sort" "strings" - "hack-browser-data/internal/browingdata" - "hack-browser-data/internal/browser/chromium" - "hack-browser-data/internal/browser/firefox" + "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" ) -type Browser interface { - // Name is browser's name - Name() string - // BrowsingData returns all browsing data in the browser. - BrowsingData() (*browingdata.Data, error) -} - -func PickBrowser(name, profile string) ([]Browser, error) { - var browsers []Browser +func PickBrowsers(name, profile string) ([]browser.Browser, error) { + var browsers []browser.Browser clist := pickChromium(name, profile) for _, b := range clist { if b != nil { @@ -38,8 +31,8 @@ func PickBrowser(name, profile string) ([]Browser, error) { return browsers, nil } -func pickChromium(name, profile string) []Browser { - var browsers []Browser +func pickChromium(name, profile string) []browser.Browser { + var browsers []browser.Browser name = strings.ToLower(name) if name == "all" { for _, v := range chromiumList { @@ -77,8 +70,8 @@ func pickChromium(name, profile string) []Browser { return browsers } -func pickFirefox(name, profile string) []Browser { - var browsers []Browser +func pickFirefox(name, profile string) []browser.Browser { + var browsers []browser.Browser name = strings.ToLower(name) if name == "all" || name == "firefox" { for _, v := range firefoxList { diff --git a/internal/browser/browser_darwin.go b/internal/provider/provider_darwin.go similarity index 99% rename from internal/browser/browser_darwin.go rename to internal/provider/provider_darwin.go index 55b0ba8..6356436 100644 --- a/internal/browser/browser_darwin.go +++ b/internal/provider/provider_darwin.go @@ -1,6 +1,6 @@ //go:build darwin -package browser +package provider import ( "hack-browser-data/internal/item" diff --git a/internal/browser/browser_linux.go b/internal/provider/provider_linux.go similarity index 99% rename from internal/browser/browser_linux.go rename to internal/provider/provider_linux.go index 08ca83f..3f4a3cc 100644 --- a/internal/browser/browser_linux.go +++ b/internal/provider/provider_linux.go @@ -1,6 +1,6 @@ //go:build linux -package browser +package provider import ( "hack-browser-data/internal/item" diff --git a/internal/browser/browser_windows.go b/internal/provider/provider_windows.go similarity index 99% rename from internal/browser/browser_windows.go rename to internal/provider/provider_windows.go index b4c964d..adb3507 100644 --- a/internal/browser/browser_windows.go +++ b/internal/provider/provider_windows.go @@ -1,6 +1,6 @@ //go:build windows -package browser +package provider import ( "hack-browser-data/internal/item" From 877fcd2c843b6a5e2b699de5914495d0ece898a9 Mon Sep 17 00:00:00 2001 From: moonD4rk Date: Mon, 24 Oct 2022 13:42:31 +0800 Subject: [PATCH 2/2] refactor: add provider software folder --- cmd/hack-browser-data/main.go | 13 +++++-------- internal/browser/browser.go | 12 ++++++++++++ internal/provider/chromium/chromium.go | 5 +++-- internal/provider/firefox/firefox.go | 5 +++-- internal/provider/provider.go | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 internal/browser/browser.go diff --git a/cmd/hack-browser-data/main.go b/cmd/hack-browser-data/main.go index 0b1ea46..db19bbd 100644 --- a/cmd/hack-browser-data/main.go +++ b/cmd/hack-browser-data/main.go @@ -4,8 +4,8 @@ import ( "os" "strings" - "hack-browser-data/internal/browser" "hack-browser-data/internal/log" + "hack-browser-data/internal/provider" "hack-browser-data/internal/utils/fileutil" "github.com/urfave/cli/v2" @@ -29,11 +29,11 @@ func Execute() { Name: "hack-browser-data", 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", - Version: "0.4.3", + Version: "0.4.4", 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(browser.ListBrowser(), "|")}, + &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(provider.ListBrowsers(), "|")}, &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"}, @@ -45,11 +45,8 @@ func Execute() { } else { log.Init("notice") } - var ( - browsers []browser.Browser - err error - ) - browsers, err = browser.PickBrowser(browserName, profilePath) + + browsers, err := provider.PickBrowsers(browserName, profilePath) if err != nil { log.Error(err) } diff --git a/internal/browser/browser.go b/internal/browser/browser.go new file mode 100644 index 0000000..18b3cc1 --- /dev/null +++ b/internal/browser/browser.go @@ -0,0 +1,12 @@ +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/provider/chromium/chromium.go b/internal/provider/chromium/chromium.go index 9a7319e..f1e2041 100644 --- a/internal/provider/chromium/chromium.go +++ b/internal/provider/chromium/chromium.go @@ -6,6 +6,7 @@ import ( "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" @@ -21,7 +22,7 @@ type chromium struct { } // 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) { +func New(name, storage, profilePath string, items []item.Item) ([]browser.Browser, error) { c := &chromium{ name: name, storage: storage, @@ -32,7 +33,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*chromium, err if err != nil { return nil, err } - chromiumList := make([]*chromium, 0, len(multiItemPaths)) + chromiumList := make([]browser.Browser, 0, len(multiItemPaths)) for user, itemPaths := range multiItemPaths { chromiumList = append(chromiumList, &chromium{ name: fileutil.BrowserName(name, user), diff --git a/internal/provider/firefox/firefox.go b/internal/provider/firefox/firefox.go index fc0dcbd..268f342 100644 --- a/internal/provider/firefox/firefox.go +++ b/internal/provider/firefox/firefox.go @@ -7,6 +7,7 @@ import ( "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" @@ -24,7 +25,7 @@ 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) ([]*firefox, error) { +func New(name, storage, profilePath string, items []item.Item) ([]browser.Browser, error) { f := &firefox{ name: name, storage: storage, @@ -36,7 +37,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*firefox, erro return nil, err } - firefoxList := make([]*firefox, 0, len(multiItemPaths)) + firefoxList := make([]browser.Browser, 0, len(multiItemPaths)) for name, itemPaths := range multiItemPaths { firefoxList = append(firefoxList, &firefox{ name: fmt.Sprintf("firefox-%s", name), diff --git a/internal/provider/provider.go b/internal/provider/provider.go index cc5b46e..21177ce 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -98,7 +98,7 @@ func pickFirefox(name, profile string) []browser.Browser { return nil } -func ListBrowser() []string { +func ListBrowsers() []string { var l []string l = append(l, typeutil.Keys(chromiumList)...) l = append(l, typeutil.Keys(firefoxList)...)