From 2c0eca9d40100ae0e89c5a422e3030fae04e481d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=E1=B4=8F=E1=B4=8F=C9=B4D4=CA=80=E1=B4=8B?= Date: Sat, 1 Aug 2020 19:34:50 +0800 Subject: [PATCH] add output to console Close #14 --- README.md | 7 +++---- README_ZH.md | 8 ++++---- cmd/cmd.go | 4 ++-- core/common/output.go | 24 ++++++++++++++++++++++++ core/common/parse.go | 40 ++++++++++++++++++++++++---------------- 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 689af0b..fe722f2 100644 --- a/README.md +++ b/README.md @@ -66,11 +66,10 @@ USAGE: GLOBAL OPTIONS: --verbose, --vv Verbose (default: false) - --browser value, -b value Available browsers: all|chrome|edge|360|qq|firefox (default: "all") + --browser value, -b value Available browsers: all|chrome|edge|firefox (default: "all") --results-dir value, --dir value Export dir (default: "results") - --format value, -f value Format, csv|json (default: "csv") - --export-data value, -e value all|bookmark|cookie|history|password (default: "all") - --help, -h show help (default: false) + --format value, -f value Format, csv|json|console (default: "json") + --export-data value, -e value all|cookie|history|password|bookmark (default: "all") PS C:\test> .\hack-browser-data.exe -b all -f json -e all --dir results diff --git a/README_ZH.md b/README_ZH.md index beb29fb..ecae1fe 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -67,11 +67,11 @@ USAGE: GLOBAL OPTIONS: --verbose, --vv Verbose (default: false) - --browser value, -b value Available browsers: all|chrome|edge|360|qq|firefox (default: "all") + --browser value, -b value Available browsers: all|chrome|edge|firefox (default: "all") --results-dir value, --dir value Export dir (default: "results") - --format value, -f value Format, csv|json (default: "csv") - --export-data value, -e value all|bookmark|cookie|history|password (default: "all") - --help, -h show help (default: false) + --format value, -f value Format, csv|json|console (default: "json") + --export-data value, -e value all|cookie|history|password|bookmark (default: "all") + PS C:\test> .\hack-browser-data.exe -b all -f json -e all --dir results diff --git a/cmd/cmd.go b/cmd/cmd.go index 321a120..b930c70 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -23,12 +23,12 @@ func Execute() { Name: "hack-browser-data", Usage: "Export passwords/cookies/history/bookmarks from browser", UsageText: "[hack-browser-data -b chrome -f json -dir results -e all]\n Get all data(password/cookie/history/bookmark) from chrome", - Version: "0.1.9", + Version: "0.2.0", Flags: []cli.Flag{ &cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "Verbose"}, &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browser, Value: "all", Usage: "Available browsers: all|" + strings.Join(core.ListBrowser(), "|")}, &cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &exportDir, Value: "results", Usage: "Export dir"}, - &cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "Format, csv|json"}, + &cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "json", Usage: "Format, csv|json|console"}, &cli.StringFlag{Name: "export-data", Aliases: []string{"e"}, Destination: &exportData, Value: "all", Usage: "all|" + strings.Join(core.ListItem(), "|")}, }, HideHelpCommand: true, diff --git a/core/common/output.go b/core/common/output.go index 8bda64d..4cbe60a 100644 --- a/core/common/output.go +++ b/core/common/output.go @@ -145,3 +145,27 @@ func writeToCsv(filename string, data interface{}) error { } return nil } + +func (b *bookmarks) outPutConsole() { + for _, v := range b.bookmarks { + fmt.Printf("%+v\n", v) + } +} + +func (c *cookies) outPutConsole() { + for host, value := range c.cookies { + fmt.Printf("%s\n%+v\n", host, value) + } +} + +func (h *historyData) outPutConsole() { + for _, v := range h.history { + fmt.Printf("%+v\n", v) + } +} + +func (p *passwords) outPutConsole() { + for _, v := range p.logins { + fmt.Printf("%+v\n", v) + } +} diff --git a/core/common/parse.go b/core/common/parse.go index b53c445..c94a4b5 100644 --- a/core/common/parse.go +++ b/core/common/parse.go @@ -156,14 +156,16 @@ func (b *bookmarks) OutPut(format, browser, dir string) error { return b.bookmarks[i].ID < b.bookmarks[j].ID }) switch format { - case "json": - err := b.outPutJson(browser, dir) - return err case "csv": err := b.outPutCsv(browser, dir) return err + case "console": + b.outPutConsole() + return nil + default: + err := b.outPutJson(browser, dir) + return err } - return nil } type cookies struct { @@ -279,14 +281,16 @@ func (c *cookies) Release() error { func (c *cookies) OutPut(format, browser, dir string) error { switch format { - case "json": - err := c.outPutJson(browser, dir) - return err case "csv": err := c.outPutCsv(browser, dir) return err + case "console": + c.outPutConsole() + return nil + default: + err := c.outPutJson(browser, dir) + return err } - return nil } type historyData struct { @@ -400,14 +404,16 @@ func (h *historyData) OutPut(format, browser, dir string) error { return h.history[i].VisitCount > h.history[j].VisitCount }) switch format { - case "json": - err := h.outPutJson(browser, dir) - return err case "csv": err := h.outPutCsv(browser, dir) return err + case "console": + h.outPutConsole() + return nil + default: + err := h.outPutJson(browser, dir) + return err } - return nil } type passwords struct { @@ -566,14 +572,16 @@ func (p *passwords) Release() error { func (p *passwords) OutPut(format, browser, dir string) error { sort.Sort(p) switch format { - case "json": - err := p.outPutJson(browser, dir) - return err case "csv": err := p.outPutCsv(browser, dir) return err + case "console": + p.outPutConsole() + return nil + default: + err := p.outPutJson(browser, dir) + return err } - return nil } func getDecryptKey() (item1, item2, a11, a102 []byte, err error) {