From 107e9aaca0c3ffdf2c302af31760525127a357fa 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: Tue, 30 Jun 2020 14:13:53 +0800 Subject: [PATCH] feat: csv separator replace to comma --- cmd/cmd.go | 2 +- core/output.go | 45 ++++++++------------------------------------- go.sum | 2 ++ 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 30ab883..2d20a53 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -22,7 +22,7 @@ var ( func Execute() { app := &cli.App{ 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 -e all]\n Get all data(password/cookie/history/bookmark) from chrome", Version: "0.1.0", Flags: []cli.Flag{ diff --git a/core/output.go b/core/output.go index b848c08..967d89c 100644 --- a/core/output.go +++ b/core/output.go @@ -2,7 +2,6 @@ package core import ( "bytes" - "encoding/csv" "encoding/json" "fmt" "hack-browser-data/log" @@ -24,15 +23,8 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error { log.Errorf("create file %s fail %s", filename, err) } file.Write(utf8Bom) - w := csv.NewWriter(file) - w.Comma = ';' - enc := csvutil.NewEncoder(w) - for _, u := range b.BookmarkSlice { - if err := enc.Encode(u); err != nil { - log.Error(err) - } - } - w.Flush() + data, err := csvutil.Marshal(b.BookmarkSlice) + file.Write(data) fmt.Printf("%s Get %d bookmarks, filename is %s \n", log.Prefix, len(b.BookmarkSlice), filename) fallthrough case len(b.LoginDataSlice) != 0: @@ -43,15 +35,8 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error { log.Errorf("create file %s fail", filename) } file.Write(utf8Bom) - w := csv.NewWriter(file) - w.Comma = ';' - enc := csvutil.NewEncoder(w) - for _, u := range b.LoginDataSlice { - if err := enc.Encode(u); err != nil { - log.Error(err) - } - } - w.Flush() + data, err := csvutil.Marshal(b.LoginDataSlice) + file.Write(data) fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.LoginDataSlice), filename) fallthrough case len(b.CookieMap) != 0: @@ -66,15 +51,8 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error { tempSlice = append(tempSlice, v...) } file.Write(utf8Bom) - w := csv.NewWriter(file) - w.Comma = ';' - enc := csvutil.NewEncoder(w) - for _, u := range tempSlice { - if err := enc.Encode(u); err != nil { - log.Error(err) - } - } - w.Flush() + data, err := csvutil.Marshal(tempSlice) + file.Write(data) fmt.Printf("%s Get %d cookies, filename is %s \n", log.Prefix, len(b.CookieMap), filename) fallthrough case len(b.HistorySlice) != 0: @@ -85,15 +63,8 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error { log.Errorf("create file %s fail", filename) } file.Write(utf8Bom) - w := csv.NewWriter(file) - w.Comma = ';' - enc := csvutil.NewEncoder(w) - for _, u := range b.HistorySlice { - if err := enc.Encode(u); err != nil { - log.Error(err) - } - } - w.Flush() + data, err := csvutil.Marshal(b.HistorySlice) + file.Write(data) fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.HistorySlice), filename) } return nil diff --git a/go.sum b/go.sum index d1bbd21..6fd9e1a 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/gocarina/gocsv v0.0.0-20200330101823-46266ca37bd3 h1:B7k6N+JlLM/u1xrIkpifUfE7GRJsZIYHoHbiAa5cSP4= github.com/gocarina/gocsv v0.0.0-20200330101823-46266ca37bd3/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/jszwec/csvutil v1.3.0 h1:d0zzXKQYvc22b4La5Wcp97CDgQ7JDLGJLm2NWqJGEYg= +github.com/jszwec/csvutil v1.3.0/go.mod h1:Rpu7Uu9giO9subDyMCIQfHVDuLrcaC36UA4YcJjGBkg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=