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

146 lines
4.6 KiB

4 years ago
package core
import (
"bytes"
"encoding/json"
4 years ago
"fmt"
4 years ago
"hack-browser-data/log"
"hack-browser-data/utils"
"os"
"github.com/jszwec/csvutil"
4 years ago
)
var utf8Bom = []byte{239, 187, 191}
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 %s", filename, err)
4 years ago
}
file.Write(utf8Bom)
data, err := csvutil.Marshal(b.BookmarkSlice)
file.Write(data)
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)
}
file.Write(utf8Bom)
data, err := csvutil.Marshal(b.LoginDataSlice)
file.Write(data)
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...)
}
file.Write(utf8Bom)
data, err := csvutil.Marshal(tempSlice)
file.Write(data)
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)
}
file.Write(utf8Bom)
data, err := csvutil.Marshal(b.HistorySlice)
file.Write(data)
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
}