|
|
|
@ -2,30 +2,39 @@ package core |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"encoding/csv" |
|
|
|
|
"encoding/json" |
|
|
|
|
"fmt" |
|
|
|
|
"hack-browser-data/log" |
|
|
|
|
"hack-browser-data/utils" |
|
|
|
|
"io" |
|
|
|
|
"os" |
|
|
|
|
|
|
|
|
|
"github.com/gocarina/gocsv" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func (b BrowserData) OutPutCsv(dir, format string) error { |
|
|
|
|
func (b BrowserData) OutPutCsv(dir, browser, format string) error { |
|
|
|
|
switch { |
|
|
|
|
case len(b.BookmarkSlice) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.Bookmarks, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.Bookmarks, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Errorf("create file %s fail", filename) |
|
|
|
|
} |
|
|
|
|
gocsv.SetCSVWriter(func(out io.Writer) *gocsv.SafeCSVWriter { |
|
|
|
|
writer := csv.NewWriter(out) |
|
|
|
|
writer.Comma = ' ' |
|
|
|
|
return gocsv.NewSafeCSVWriter(writer) |
|
|
|
|
}) |
|
|
|
|
err = gocsv.MarshalFile(b.BookmarkSlice, file) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%s Get %d bookmarks, filename is %s \n", log.Prefix, len(b.BookmarkSlice), filename) |
|
|
|
|
fallthrough |
|
|
|
|
case len(b.LoginDataSlice) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.LoginData, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.LoginData, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
@ -35,9 +44,10 @@ func (b BrowserData) OutPutCsv(dir, format string) error { |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.LoginDataSlice), filename) |
|
|
|
|
fallthrough |
|
|
|
|
case len(b.CookieMap) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.Cookies, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.Cookies, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
@ -51,9 +61,10 @@ func (b BrowserData) OutPutCsv(dir, format string) error { |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%s Get %d cookies, filename is %s \n", log.Prefix, len(b.CookieMap), filename) |
|
|
|
|
fallthrough |
|
|
|
|
case len(b.HistorySlice) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.History, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.History, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
@ -63,14 +74,15 @@ func (b BrowserData) OutPutCsv(dir, format string) error { |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.HistorySlice), filename) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (b BrowserData) OutPutJson(dir, format string) error { |
|
|
|
|
func (b BrowserData) OutPutJson(dir, browser, format string) error { |
|
|
|
|
switch { |
|
|
|
|
case len(b.BookmarkSlice) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.Bookmarks, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.Bookmarks, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
@ -82,9 +94,10 @@ func (b BrowserData) OutPutJson(dir, format string) error { |
|
|
|
|
enc.SetIndent("", "\t") |
|
|
|
|
enc.Encode(b.BookmarkSlice) |
|
|
|
|
file.Write(w.Bytes()) |
|
|
|
|
fmt.Printf("%s Get %d bookmarks, filename is %s \n", log.Prefix, len(b.BookmarkSlice), filename) |
|
|
|
|
fallthrough |
|
|
|
|
case len(b.CookieMap) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.Cookies, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.Cookies, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
@ -99,9 +112,10 @@ func (b BrowserData) OutPutJson(dir, format string) error { |
|
|
|
|
log.Println(err) |
|
|
|
|
} |
|
|
|
|
file.Write(w.Bytes()) |
|
|
|
|
fmt.Printf("%s Get %d cookies, filename is %s \n", log.Prefix, len(b.CookieMap), filename) |
|
|
|
|
fallthrough |
|
|
|
|
case len(b.HistorySlice) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.History, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.History, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
@ -116,9 +130,10 @@ func (b BrowserData) OutPutJson(dir, format string) error { |
|
|
|
|
log.Println(err) |
|
|
|
|
} |
|
|
|
|
file.Write(w.Bytes()) |
|
|
|
|
fmt.Printf("%s Get %d history, filename is %s \n", log.Prefix, len(b.HistorySlice), filename) |
|
|
|
|
fallthrough |
|
|
|
|
case len(b.LoginDataSlice) != 0: |
|
|
|
|
filename := utils.FormatFileName(dir, utils.LoginData, format) |
|
|
|
|
filename := utils.FormatFileName(dir, browser, utils.LoginData, format) |
|
|
|
|
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) |
|
|
|
|
defer file.Close() |
|
|
|
|
if err != nil { |
|
|
|
@ -133,6 +148,7 @@ func (b BrowserData) OutPutJson(dir, format string) error { |
|
|
|
|
log.Println(err) |
|
|
|
|
} |
|
|
|
|
file.Write(w.Bytes()) |
|
|
|
|
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.LoginDataSlice), filename) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|