You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HackBrowserData/core/output.go

155 lines
4.8 KiB

4 years ago
package core
import (
"bytes"
4 years ago
"encoding/csv"
4 years ago
"encoding/json"
4 years ago
"fmt"
4 years ago
"hack-browser-data/log"
"hack-browser-data/utils"
4 years ago
"io"
4 years ago
"os"
"github.com/gocarina/gocsv"
)
4 years ago
func (b BrowserData) OutPutCsv(dir, browser, format string) error {
4 years ago
switch {
case len(b.BookmarkSlice) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.Bookmarks, format)
4 years ago
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)
}
4 years ago
gocsv.SetCSVWriter(func(out io.Writer) *gocsv.SafeCSVWriter {
writer := csv.NewWriter(out)
writer.Comma = ' '
return gocsv.NewSafeCSVWriter(writer)
})
4 years ago
err = gocsv.MarshalFile(b.BookmarkSlice, file)
if err != nil {
log.Error(err)
}
4 years ago
fmt.Printf("%s Get %d bookmarks, filename is %s \n", log.Prefix, len(b.BookmarkSlice), filename)
4 years ago
fallthrough
case len(b.LoginDataSlice) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.LoginData, format)
4 years ago
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)
}
err = gocsv.MarshalFile(b.LoginDataSlice, file)
if err != nil {
log.Error(err)
}
4 years ago
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.LoginDataSlice), filename)
4 years ago
fallthrough
case len(b.CookieMap) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.Cookies, format)
4 years ago
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)
}
var tempSlice []cookies
for _, v := range b.CookieMap {
tempSlice = append(tempSlice, v...)
}
err = gocsv.MarshalFile(tempSlice, file)
if err != nil {
log.Error(err)
}
4 years ago
fmt.Printf("%s Get %d cookies, filename is %s \n", log.Prefix, len(b.CookieMap), filename)
4 years ago
fallthrough
case len(b.HistorySlice) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.History, format)
4 years ago
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)
}
err = gocsv.MarshalFile(b.HistorySlice, file)
if err != nil {
log.Error(err)
}
4 years ago
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.HistorySlice), filename)
4 years ago
}
return nil
}
4 years ago
func (b BrowserData) OutPutJson(dir, browser, format string) error {
4 years ago
switch {
case len(b.BookmarkSlice) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.Bookmarks, format)
4 years ago
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)
}
w := new(bytes.Buffer)
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
enc.SetIndent("", "\t")
enc.Encode(b.BookmarkSlice)
file.Write(w.Bytes())
4 years ago
fmt.Printf("%s Get %d bookmarks, filename is %s \n", log.Prefix, len(b.BookmarkSlice), filename)
4 years ago
fallthrough
case len(b.CookieMap) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.Cookies, format)
4 years ago
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)
}
w := new(bytes.Buffer)
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
enc.SetIndent("", "\t")
err = enc.Encode(b.CookieMap)
if err != nil {
log.Println(err)
}
file.Write(w.Bytes())
4 years ago
fmt.Printf("%s Get %d cookies, filename is %s \n", log.Prefix, len(b.CookieMap), filename)
4 years ago
fallthrough
case len(b.HistorySlice) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.History, format)
4 years ago
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)
}
w := new(bytes.Buffer)
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
enc.SetIndent("", "\t")
err = enc.Encode(b.HistorySlice)
if err != nil {
log.Println(err)
}
file.Write(w.Bytes())
4 years ago
fmt.Printf("%s Get %d history, filename is %s \n", log.Prefix, len(b.HistorySlice), filename)
4 years ago
fallthrough
case len(b.LoginDataSlice) != 0:
4 years ago
filename := utils.FormatFileName(dir, browser, utils.LoginData, format)
4 years ago
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)
}
w := new(bytes.Buffer)
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
enc.SetIndent("", "\t")
err = enc.Encode(b.LoginDataSlice)
if err != nil {
log.Println(err)
}
file.Write(w.Bytes())
4 years ago
fmt.Printf("%s Get %d login data, filename is %s \n", log.Prefix, len(b.LoginDataSlice), filename)
4 years ago
}
return nil
}