Skip to content

Commit

Permalink
fix: filter result if item is empty and add utf8 encoder to csv
Browse files Browse the repository at this point in the history
Merge pull request #144 from moonD4rk/fix/bug
  • Loading branch information
moonD4rk authored Jun 5, 2022
2 parents 645e260 + 6de08b6 commit 0f0db46
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ USAGE:
Github Link: https://github.com/moonD4rk/HackBrowserData
VERSION:
0.4.2
0.4.3
GLOBAL OPTIONS:
--verbose, --vv verbose (default: false)
Expand Down
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ USAGE:
Github Link: https://github.com/moonD4rk/HackBrowserData
VERSION:
0.4.2
0.4.3
GLOBAL OPTIONS:
--verbose, --vv verbose (default: false)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/urfave/cli/v2 v2.4.0
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd
golang.org/x/text v0.3.6
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
22 changes: 15 additions & 7 deletions internal/browingdata/bookmark/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,23 @@ func getBookmarkChildren(value gjson.Result, w *ChromiumBookmark) (children gjso
return children
}

func bookmarkType(a int64) string {
switch a {
case 1:
return "url"
default:
return "folder"
}
}

func (c *ChromiumBookmark) Name() string {
return "bookmark"
}

func (c *ChromiumBookmark) Length() int {
return len(*c)
}

type FirefoxBookmark []bookmark

const (
Expand Down Expand Up @@ -134,11 +147,6 @@ func (f *FirefoxBookmark) Name() string {
return "bookmark"
}

func bookmarkType(a int64) string {
switch a {
case 1:
return "url"
default:
return "folder"
}
func (f *FirefoxBookmark) Length() int {
return len(*f)
}
6 changes: 6 additions & 0 deletions internal/browingdata/browsingdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Source interface {
Parse(masterKey []byte) error

Name() string

Length() int
}

func New(sources []item.Item) *Data {
Expand All @@ -47,6 +49,10 @@ func (d *Data) Output(dir, browserName, flag string) {
output := NewOutPutter(flag)

for _, source := range d.sources {
if source.Length() == 0 {
// if the length of the export data is 0, then it is not necessary to output
continue
}
filename := fileutil.Filename(browserName, source.Name(), output.Ext())

f, err := output.CreateFile(dir, filename)
Expand Down
8 changes: 8 additions & 0 deletions internal/browingdata/cookie/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (c *ChromiumCookie) Name() string {
return "cookie"
}

func (c *ChromiumCookie) Length() int {
return len(*c)
}

type FirefoxCookie []cookie

const (
Expand Down Expand Up @@ -137,3 +141,7 @@ func (f *FirefoxCookie) Parse(masterKey []byte) error {
func (f *FirefoxCookie) Name() string {
return "cookie"
}

func (f *FirefoxCookie) Length() int {
return len(*f)
}
8 changes: 8 additions & 0 deletions internal/browingdata/creditcard/creditcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (c *ChromiumCreditCard) Name() string {
return "creditcard"
}

func (c *ChromiumCreditCard) Length() int {
return len(*c)
}

type YandexCreditCard []card

func (c *YandexCreditCard) Parse(masterKey []byte) error {
Expand Down Expand Up @@ -127,3 +131,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
func (c *YandexCreditCard) Name() string {
return "creditcard"
}

func (c *YandexCreditCard) Length() int {
return len(*c)
}
8 changes: 8 additions & 0 deletions internal/browingdata/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (c *ChromiumDownload) Name() string {
return "download"
}

func (c *ChromiumDownload) Length() int {
return len(*c)
}

type FirefoxDownload []download

const (
Expand Down Expand Up @@ -131,3 +135,7 @@ func (f *FirefoxDownload) Parse(masterKey []byte) error {
func (f *FirefoxDownload) Name() string {
return "download"
}

func (f *FirefoxDownload) Length() int {
return len(*f)
}
8 changes: 8 additions & 0 deletions internal/browingdata/extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func (c *ChromiumExtension) Name() string {
return "extension"
}

func (c *ChromiumExtension) Length() int {
return len(*c)
}

type FirefoxExtension []*extension

func (f *FirefoxExtension) Parse(masterKey []byte) error {
Expand All @@ -73,3 +77,7 @@ func (f *FirefoxExtension) Parse(masterKey []byte) error {
func (f *FirefoxExtension) Name() string {
return "extension"
}

func (f *FirefoxExtension) Length() int {
return len(*f)
}
8 changes: 8 additions & 0 deletions internal/browingdata/history/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (c *ChromiumHistory) Name() string {
return "history"
}

func (c *ChromiumHistory) Length() int {
return len(*c)
}

type FirefoxHistory []history

const (
Expand Down Expand Up @@ -119,3 +123,7 @@ func (f *FirefoxHistory) Parse(masterKey []byte) error {
func (f *FirefoxHistory) Name() string {
return "history"
}

func (f *FirefoxHistory) Length() int {
return len(*f)
}
8 changes: 8 additions & 0 deletions internal/browingdata/localstorage/localstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (c *ChromiumLocalStorage) Name() string {
return "localStorage"
}

func (c *ChromiumLocalStorage) Length() int {
return len(*c)
}

func (s *storage) fillKey(b []byte) {
keys := bytes.Split(b, []byte("\x00"))
if len(keys) == 1 && bytes.HasPrefix(keys[0], []byte("META:")) {
Expand Down Expand Up @@ -142,3 +146,7 @@ func (s *storage) fillFirefox(originKey, key, value string) {
func (f *FirefoxLocalStorage) Name() string {
return "localStorage"
}

func (f *FirefoxLocalStorage) Length() int {
return len(*f)
}
4 changes: 3 additions & 1 deletion internal/browingdata/outputter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/gocarina/gocsv"
jsoniter "github.com/json-iterator/go"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)

type OutPutter struct {
Expand All @@ -35,7 +37,7 @@ func (o *OutPutter) Write(data Source, writer io.Writer) error {
return encoder.Encode(data)
default:
gocsv.SetCSVWriter(func(w io.Writer) *gocsv.SafeCSVWriter {
writer := csv.NewWriter(w)
writer := csv.NewWriter(transform.NewWriter(w, unicode.UTF8BOM.NewEncoder()))
writer.Comma = ','
return gocsv.NewSafeCSVWriter(writer)
})
Expand Down
20 changes: 16 additions & 4 deletions internal/browingdata/password/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (c *ChromiumPassword) Name() string {
return "password"
}

func (c *ChromiumPassword) Length() int {
return len(*c)
}

type YandexPassword []loginData

const (
Expand Down Expand Up @@ -154,6 +158,10 @@ func (c *YandexPassword) Name() string {
return "password"
}

func (c *YandexPassword) Length() int {
return len(*c)
}

type FirefoxPassword []loginData

const (
Expand Down Expand Up @@ -224,10 +232,6 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
return nil
}

func (f *FirefoxPassword) Name() string {
return "password"
}

func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err error) {
var keyDB *sql.DB
keyDB, err = sql.Open("sqlite3", key4file)
Expand Down Expand Up @@ -278,3 +282,11 @@ func getFirefoxLoginData(loginJson string) (l []loginData, err error) {
}
return l, nil
}

func (f *FirefoxPassword) Name() string {
return "password"
}

func (f *FirefoxPassword) Length() int {
return len(*f)
}

0 comments on commit 0f0db46

Please sign in to comment.