csv separator replace to comma

v0.1.1
ᴍᴏᴏɴD4ʀᴋ 4 years ago
parent c027aee5c8
commit 4b9d313cd2
  1. 2
      cmd/cmd.go
  2. 45
      core/output.go
  3. 2
      go.sum

@ -22,7 +22,7 @@ var (
func Execute() { func Execute() {
app := &cli.App{ app := &cli.App{
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 -e all]\n Get all data(password/cookie/history/bookmark) from chrome", 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", Version: "0.1.0",
Flags: []cli.Flag{ Flags: []cli.Flag{

@ -2,7 +2,6 @@ package core
import ( import (
"bytes" "bytes"
"encoding/csv"
"encoding/json" "encoding/json"
"fmt" "fmt"
"hack-browser-data/log" "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) log.Errorf("create file %s fail %s", filename, err)
} }
file.Write(utf8Bom) file.Write(utf8Bom)
w := csv.NewWriter(file) data, err := csvutil.Marshal(b.BookmarkSlice)
w.Comma = ';' file.Write(data)
enc := csvutil.NewEncoder(w)
for _, u := range b.BookmarkSlice {
if err := enc.Encode(u); err != nil {
log.Error(err)
}
}
w.Flush()
fmt.Printf("%s Get %d bookmarks, filename is %s \n", log.Prefix, len(b.BookmarkSlice), filename) fmt.Printf("%s Get %d bookmarks, filename is %s \n", log.Prefix, len(b.BookmarkSlice), filename)
fallthrough fallthrough
case len(b.LoginDataSlice) != 0: 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) log.Errorf("create file %s fail", filename)
} }
file.Write(utf8Bom) file.Write(utf8Bom)
w := csv.NewWriter(file) data, err := csvutil.Marshal(b.LoginDataSlice)
w.Comma = ';' file.Write(data)
enc := csvutil.NewEncoder(w)
for _, u := range b.LoginDataSlice {
if err := enc.Encode(u); err != nil {
log.Error(err)
}
}
w.Flush()
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.LoginDataSlice), filename) fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.LoginDataSlice), filename)
fallthrough fallthrough
case len(b.CookieMap) != 0: case len(b.CookieMap) != 0:
@ -66,15 +51,8 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error {
tempSlice = append(tempSlice, v...) tempSlice = append(tempSlice, v...)
} }
file.Write(utf8Bom) file.Write(utf8Bom)
w := csv.NewWriter(file) data, err := csvutil.Marshal(tempSlice)
w.Comma = ';' file.Write(data)
enc := csvutil.NewEncoder(w)
for _, u := range tempSlice {
if err := enc.Encode(u); err != nil {
log.Error(err)
}
}
w.Flush()
fmt.Printf("%s Get %d cookies, filename is %s \n", log.Prefix, len(b.CookieMap), filename) fmt.Printf("%s Get %d cookies, filename is %s \n", log.Prefix, len(b.CookieMap), filename)
fallthrough fallthrough
case len(b.HistorySlice) != 0: 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) log.Errorf("create file %s fail", filename)
} }
file.Write(utf8Bom) file.Write(utf8Bom)
w := csv.NewWriter(file) data, err := csvutil.Marshal(b.HistorySlice)
w.Comma = ';' file.Write(data)
enc := csvutil.NewEncoder(w)
for _, u := range b.HistorySlice {
if err := enc.Encode(u); err != nil {
log.Error(err)
}
}
w.Flush()
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.HistorySlice), filename) fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.HistorySlice), filename)
} }
return nil return nil

@ -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 h1:B7k6N+JlLM/u1xrIkpifUfE7GRJsZIYHoHbiAa5cSP4=
github.com/gocarina/gocsv v0.0.0-20200330101823-46266ca37bd3/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= 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/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/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 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

Loading…
Cancel
Save