fix: add bom for csv. Closes #7

pull/83/head
ᴍᴏᴏɴD4ʀᴋ 4 years ago
parent 74f6d0ad4a
commit a5ee0b722a
  1. 10
      .github/workflows/release.yml
  2. 73
      README.md
  3. 14
      core/common.go
  4. 64
      core/output.go
  5. 2
      go.mod

@ -75,17 +75,7 @@ jobs:
cp $BINARY .; cp $BINARY .;
zip -r releases/$(basename $RELEASE_DIR).zip \ zip -r releases/$(basename $RELEASE_DIR).zip \
$(basename ${BINARY}) \ $(basename ${BINARY}) \
static/js/dist \
static/js/src/vendor/ckeditor \
static/css/dist \
static/images \
static/font \
static/db \
db \
templates \
README.md \ README.md \
VERSION \
LICENSE \
config.json; config.json;
rm $BINARY; rm $BINARY;
done done

@ -1,14 +1,30 @@
# HackBrowserData # HackBrowserData
一款支持全平台(Windows | MacOS | Linux)的浏览器数据(Password | History | Bookmark | Cookie)导出工具 hack-browser-data is an open-source tool that could help you export data from browser. It supports the most popular browsers on the market and runs on W indows and macOS.
### Supported Browser
| Browser | Password | Cookie | Bookmark | History |
### 安装编译 | :---------------------------------- | :------: | :----: | :------: | :-----: |
| Chrome <= 80 [Windows] | ✅ | ✅ | ✅ | ✅ |
你可以选择下载编译好的[二进制文件](https://github.com/moonD4rk/HackBrowserData/releases) | Chrome > 80 [Windows] | ✅ | ✅ | ✅ | ✅ |
| Chrome [MacOS]<br />(require password) | ✅ | ✅ | ✅ | ✅ |
也可以通过源码手动编译 | Edge [Windows] | ✅ | ✅ | ✅ | ✅ |
| Edge [MacOS]<br />(require password) | ✅ | ✅ | ✅ | ✅ |
| 360 Speed Browser [Windows] | ✅ | ✅ | ✅ | ✅ |
| QQ Browser [Windows] | ✅ | ✅ | ✅ | ✅ |
| FireFox [Windows] | ❌ | ❌ | ❌ | ❌ |
| FireFox [MacOS] | ❌ | ❌ | ❌ | ❌ |
| Safari [MacOS] | ❌ | ❌ | ❌ | ❌ |
| Internet Explorer [Windows] | ❌ | ❌ | ❌ | ❌ |
| 360 Secure Browser [Windows] | ❌ | ❌ | ❌ | ❌ |
| Chrome [Linux] | ❌ | ❌ | ❌ | ❌ |
### Install
Installation of hack-browser-data is dead-simple, just download [the release for your system](https://github.com/moonD4rk/HackBrowserData/releases) and run the binary.
#### Building from source
```bash ```bash
git clone https://github.com/moonD4rk/HackBrowserData git clone https://github.com/moonD4rk/HackBrowserData
@ -18,12 +34,12 @@ cd HackBrowserData && go mod tidy
go build go build
``` ```
### 运行 #### Run
```shell ```shell
./hack-browser-data -h ✗ .\hack-browser-data.exe -h
NAME: NAME:
hack-browser-data - Get passwords/cookies/history/bookmarks from browser hack-browser-data - Export passwords/cookies/history/bookmarks from browser
USAGE: USAGE:
[hack-browser-data -b chrome -f json -dir results -e all] [hack-browser-data -b chrome -f json -dir results -e all]
@ -31,44 +47,27 @@ USAGE:
GLOBAL OPTIONS: GLOBAL OPTIONS:
--verbose, --vv verbose (default: false) --verbose, --vv verbose (default: false)
--browser value, -b value available browsers: edge|chrome (default: "chrome") --browser value, -b value available browsers: chrome|edge|360speed|qq (default: "chrome")
--results-dir value, --dir value export dir (default: "results") --results-dir value, --dir value Export dir (default: "results")
--format value, -f value result format, csv|json (default: "csv") --format value, -f value result format, csv|json (default: "csv")
--export-data value, -e value all|password|cookie|history|bookmark (default: "all") --export-data value, -e value all|password|cookie|history|bookmark (default: "all")
--help, -h show help (default: false) --help, -h show help (default: false)
``` ```
```shell ```shell
✗ ./hack-browser-data -b chrome -f json -dir results -e all ✗ ./hack-browser-data.exe -b chrome -f json -dir results -e all
[x]: Get 538 bookmarks, filename is results/bookmarks_chrome.json [x]: Get 538 bookmarks, filename is results/bookmarks_chrome.json
[x]: Get 1415 cookies, filename is results/cookies_chrome.json [x]: Get 1610 cookies, filename is results/cookies_chrome.json
[x]: Get 34050 history, filename is results/history_chrome.json [x]: Get 44050 history, filename is results/history_chrome.json
[x]: Get 357 login data, filename is results/login_data_chrome.json [x]: Get 457 login data, filename is results/login_data_chrome.json
``` ```
### 目前支持平台
| Browser | Password | Cookie | Bookmark | History | ### TODO
| :---------------------------------- | :------: | :----: | :------: | :-----: |
| Chrome version <= 80 [Windows] | ✔ | ✔ | ✔ | ✔ |
| Chrome version > 80 [Windows] | ✔ | ✔ | ✔ | ✔ |
| Chrome [MacOS]<br />(require password) | ✔ | ✔ | ✔ | ✔ |
| Edge [Windows] | ✔ | ✔ | ✔ | ✔ |
| Edge [MacOS]<br />(require password) | ✔ | ✔ | ✔ | ✔ |
| 360 Speed Browser [Windows] | ✔ | ✔ | ✔ | ✔ |
| QQ Browser [Windows] | ✔ | ✔ | ✔ | ✔ |
| FireFox [Windows] | ✖ | ✖ | ✖ | ✖ |
| FireFox [MacOS] | ✖ | ✖ | ✖ | ✖ |
| Safari [MacOS] | ✖ | ✖ | ✖ | ✖ |
| Internet Explorer [Windows] | ✖ | ✖ | ✖ | ✖ |
| 360 Secure Browser [Windows] | ✖ | ✖ | ✖ | ✖ |
| Chrome [Linux] | ✖ | ✖ | ✖ | ✖ |
### Todo List
[Desktop Browser Market Share Worldwide](https://gs.statcounter.com/browser-market-share/desktop/worldwide) [Desktop Browser Market Share Worldwide](https://gs.statcounter.com/browser-market-share/desktop/worldwide)
@ -82,7 +81,7 @@ GLOBAL OPTIONS:
| :----- | :------: | :-----: | :--------: | :---: | :------------: | | :----- | :------: | :-----: | :--------: | :---: | :------------: |
| 39.85% | 22.26% | 9.28% | 6.5% | 5.65% | 4.74% | | 39.85% | 22.26% | 9.28% | 6.5% | 5.65% | 4.74% |
Based on those two lists, I would support those browsers in the future
- [x] Chrome - [x] Chrome
- [x] QQ browser - [x] QQ browser

@ -22,13 +22,11 @@ const (
) )
var ( var (
FullDataSlice []*BrowserData FullData = new(BrowserData)
FullData = new(BrowserData)
) )
type ( type (
BrowserData struct { BrowserData struct {
BrowserName string
LoginDataSlice LoginDataSlice
BookmarkSlice BookmarkSlice
CookieMap CookieMap
@ -47,17 +45,17 @@ type (
} }
bookmarks struct { bookmarks struct {
ID int64 ID int64
DateAdded time.Time
URL string
Name string Name string
Type string Type string
URL string
DateAdded time.Time
} }
cookies struct { cookies struct {
Host string
Path string
KeyName string KeyName string
encryptValue []byte encryptValue []byte
Value string Value string
Host string
Path string
IsSecure bool IsSecure bool
IsHTTPOnly bool IsHTTPOnly bool
HasExpire bool HasExpire bool
@ -66,8 +64,8 @@ type (
ExpireDate time.Time ExpireDate time.Time
} }
history struct { history struct {
Url string
Title string Title string
Url string
VisitCount int VisitCount int
LastVisitTime time.Time LastVisitTime time.Time
} }

@ -7,12 +7,13 @@ import (
"fmt" "fmt"
"hack-browser-data/log" "hack-browser-data/log"
"hack-browser-data/utils" "hack-browser-data/utils"
"io"
"os" "os"
"github.com/gocarina/gocsv" "github.com/jszwec/csvutil"
) )
var utf8Bom = []byte{239, 187, 191}
func (b BrowserData) OutPutCsv(dir, browser, format string) error { func (b BrowserData) OutPutCsv(dir, browser, format string) error {
switch { switch {
case len(b.BookmarkSlice) != 0: case len(b.BookmarkSlice) != 0:
@ -20,17 +21,18 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error {
file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644) file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0644)
defer file.Close() defer file.Close()
if err != nil { if err != nil {
log.Errorf("create file %s fail", filename) log.Errorf("create file %s fail %s", filename, err)
} }
gocsv.SetCSVWriter(func(out io.Writer) *gocsv.SafeCSVWriter { file.Write(utf8Bom)
writer := csv.NewWriter(out) w := csv.NewWriter(file)
writer.Comma = ' ' w.Comma = ';'
return gocsv.NewSafeCSVWriter(writer) enc := csvutil.NewEncoder(w)
}) for _, u := range b.BookmarkSlice {
err = gocsv.MarshalFile(b.BookmarkSlice, file) if err := enc.Encode(u); err != nil {
if err != nil { log.Error(err)
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:
@ -40,10 +42,16 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error {
if err != nil { if err != nil {
log.Errorf("create file %s fail", filename) log.Errorf("create file %s fail", filename)
} }
err = gocsv.MarshalFile(b.LoginDataSlice, file) file.Write(utf8Bom)
if err != nil { w := csv.NewWriter(file)
log.Error(err) w.Comma = ';'
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:
@ -57,10 +65,16 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error {
for _, v := range b.CookieMap { for _, v := range b.CookieMap {
tempSlice = append(tempSlice, v...) tempSlice = append(tempSlice, v...)
} }
err = gocsv.MarshalFile(tempSlice, file) file.Write(utf8Bom)
if err != nil { w := csv.NewWriter(file)
log.Error(err) w.Comma = ';'
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:
@ -70,10 +84,16 @@ func (b BrowserData) OutPutCsv(dir, browser, format string) error {
if err != nil { if err != nil {
log.Errorf("create file %s fail", filename) log.Errorf("create file %s fail", filename)
} }
err = gocsv.MarshalFile(b.HistorySlice, file) file.Write(utf8Bom)
if err != nil { w := csv.NewWriter(file)
log.Error(err) w.Comma = ';'
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

@ -3,7 +3,7 @@ module hack-browser-data
go 1.14 go 1.14
require ( require (
github.com/gocarina/gocsv v0.0.0-20200330101823-46266ca37bd3 github.com/jszwec/csvutil v1.3.0
github.com/mattn/go-sqlite3 v1.14.0 github.com/mattn/go-sqlite3 v1.14.0
github.com/tidwall/gjson v1.6.0 github.com/tidwall/gjson v1.6.0
github.com/urfave/cli/v2 v2.2.0 github.com/urfave/cli/v2 v2.2.0

Loading…
Cancel
Save