Skip to content

Commit

Permalink
Merge pull request #159 from moonD4rk/dev
Browse files Browse the repository at this point in the history
refactor: formatting code used to pass golangci-lint rules
  • Loading branch information
moonD4rk authored Aug 14, 2022
2 parents a2bfdeb + 76554e4 commit ab6ca5a
Show file tree
Hide file tree
Showing 25 changed files with 282 additions and 177 deletions.
69 changes: 69 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
run:
timeout: '5m'
skip-dirs:
- 'assets'
allow-parallel-runners: true
modules-download-mode: 'readonly'

linters:
enable:
- 'asciicheck'
- 'deadcode'
- 'depguard'
- 'dogsled'
- 'errorlint'
- 'exportloopref'
- 'gofmt'
- 'goheader'
- 'goimports'
- 'gomodguard'
- 'goprintffuncname'
- 'gosec'
- 'govet'
- 'ineffassign'
- 'makezero'
- 'misspell'
- 'paralleltest'
- 'prealloc'
- 'predeclared'
- 'revive'
- 'typecheck'
- 'unconvert'
- 'varcheck'
- 'whitespace'
disable:
# unsupported lint with golang 1.18+ ref: https://github.com/golangci/golangci-lint/issues/2649
- 'bodyclose'
- 'gosimple'
- 'noctx'
- 'sqlclosecheck'
- 'staticcheck'
- 'structcheck'
- 'stylecheck'
- 'unused'
- 'errcheck'

issues:
exclude-use-default: false
exclude:
- should have a package comment
- should have comment
# G101: Potential hardcoded credentials
- G101
# G103: Use of unsafe calls should be audited
- G103
# G304: Potential file inclusion via variable
- G304
# G404, G401, G502, G505: weak cryptographic list
- G401
- G404
- G502
- G505
exclude-rules:
- path: internal/browser/browser\.go
linters:
- 'deadcode'
- 'varcheck'
- 'unused'
max-issues-per-linter: 0
max-same-issues: 0
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module hack-browser-data

go 1.18
go 1.19

require (
github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9
Expand Down
8 changes: 4 additions & 4 deletions internal/browingdata/bookmark/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"sort"
"time"

"github.com/tidwall/gjson"

"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/fileutil"
"hack-browser-data/internal/utils/typeutil"

// import sqlite3 driver
_ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson"
)

type ChromiumBookmark []bookmark
Expand Down Expand Up @@ -51,7 +51,7 @@ func getBookmarkChildren(value gjson.Result, w *ChromiumBookmark) (children gjso
const (
bookmarkID = "id"
bookmarkAdded = "date_added"
bookmarkUrl = "url"
bookmarkURL = "url"
bookmarkName = "name"
bookmarkType = "type"
bookmarkChildren = "children"
Expand All @@ -60,7 +60,7 @@ func getBookmarkChildren(value gjson.Result, w *ChromiumBookmark) (children gjso
bm := bookmark{
ID: value.Get(bookmarkID).Int(),
Name: value.Get(bookmarkName).String(),
URL: value.Get(bookmarkUrl).String(),
URL: value.Get(bookmarkURL).String(),
DateAdded: typeutil.TimeEpoch(value.Get(bookmarkAdded).Int()),
}
children = value.Get(bookmarkChildren)
Expand Down
13 changes: 9 additions & 4 deletions internal/browingdata/browsingdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@ func (d *Data) Output(dir, browserName, flag string) {
// 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())
filename := fileutil.ItemName(browserName, source.Name(), output.Ext())

f, err := output.CreateFile(dir, filename)
if err != nil {
log.Errorf("create file error %s", err)
log.Errorf("create file %s error %s", filename, err.Error())
continue
}
if err := output.Write(source, f); err != nil {
log.Errorf("%s write to file %s error %s", source.Name(), filename, err.Error())
log.Errorf("write to file %s error %s", filename, err.Error())
continue
}
if err := f.Close(); err != nil {
log.Errorf("close file %s error %s", filename, err.Error())
continue
}
log.Noticef("output to file %s success", path.Join(dir, filename))
f.Close()
}
}

Expand Down
13 changes: 7 additions & 6 deletions internal/browingdata/cookie/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"sort"
"time"

_ "github.com/mattn/go-sqlite3"

"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"

// import sqlite3 driver
_ "github.com/mattn/go-sqlite3"
)

type ChromiumCookie []cookie
Expand Down Expand Up @@ -72,7 +73,7 @@ func (c *ChromiumCookie) Parse(masterKey []byte) error {
if len(encryptValue) > 0 {
var err error
if masterKey == nil {
value, err = decrypter.DPApi(encryptValue)
value, err = decrypter.DPAPI(encryptValue)
} else {
value, err = decrypter.Chromium(masterKey, encryptValue)
}
Expand Down Expand Up @@ -118,18 +119,18 @@ func (f *FirefoxCookie) Parse(masterKey []byte) error {
for rows.Next() {
var (
name, value, host, path string
isSecure, isHttpOnly int
isSecure, isHTTPOnly int
creationTime, expiry int64
)
if err = rows.Scan(&name, &value, &host, &path, &creationTime, &expiry, &isSecure, &isHttpOnly); err != nil {
if err = rows.Scan(&name, &value, &host, &path, &creationTime, &expiry, &isSecure, &isHTTPOnly); err != nil {
log.Warn(err)
}
*f = append(*f, cookie{
KeyName: name,
Host: host,
Path: path,
IsSecure: typeutil.IntToBool(isSecure),
IsHTTPOnly: typeutil.IntToBool(isHttpOnly),
IsHTTPOnly: typeutil.IntToBool(isHTTPOnly),
CreateDate: typeutil.TimeStamp(creationTime / 1000000),
ExpireDate: typeutil.TimeStamp(expiry),
Value: value,
Expand Down
9 changes: 5 additions & 4 deletions internal/browingdata/creditcard/creditcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"database/sql"
"os"

_ "github.com/mattn/go-sqlite3"

"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"

// import sqlite3 driver
_ "github.com/mattn/go-sqlite3"
)

type ChromiumCreditCard []card
Expand Down Expand Up @@ -56,7 +57,7 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
NickName: nickname,
}
if masterKey == nil {
value, err = decrypter.DPApi(encryptValue)
value, err = decrypter.DPAPI(encryptValue)
if err != nil {
return err
}
Expand Down Expand Up @@ -112,7 +113,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
NickName: nickname,
}
if masterKey == nil {
value, err = decrypter.DPApi(encryptValue)
value, err = decrypter.DPAPI(encryptValue)
if err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions internal/browingdata/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"

// import sqlite3 driver
_ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson"
)
Expand All @@ -19,7 +20,7 @@ type ChromiumDownload []download

type download struct {
TargetPath string
Url string
URL string
TotalBytes int64
StartTime time.Time
EndTime time.Time
Expand All @@ -44,15 +45,15 @@ func (c *ChromiumDownload) Parse(masterKey []byte) error {
defer rows.Close()
for rows.Next() {
var (
targetPath, tabUrl, mimeType string
targetPath, tabURL, mimeType string
totalBytes, startTime, endTime int64
)
if err := rows.Scan(&targetPath, &tabUrl, &totalBytes, &startTime, &endTime, &mimeType); err != nil {
if err := rows.Scan(&targetPath, &tabURL, &totalBytes, &startTime, &endTime, &mimeType); err != nil {
log.Warn(err)
}
data := download{
TargetPath: targetPath,
Url: tabUrl,
URL: tabURL,
TotalBytes: totalBytes,
StartTime: typeutil.TimeEpoch(startTime),
EndTime: typeutil.TimeEpoch(endTime),
Expand Down Expand Up @@ -119,7 +120,7 @@ func (f *FirefoxDownload) Parse(masterKey []byte) error {
fileSize := gjson.Get(json, "fileSize")
*f = append(*f, download{
TargetPath: path,
Url: url,
URL: url,
TotalBytes: fileSize.Int(),
StartTime: typeutil.TimeStamp(dateAdded / 1000000),
EndTime: typeutil.TimeStamp(endTime.Int() / 1000),
Expand Down
4 changes: 2 additions & 2 deletions internal/browingdata/extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package extension
import (
"os"

"github.com/tidwall/gjson"

"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/fileutil"

"github.com/tidwall/gjson"
)

type ChromiumExtension []*extension
Expand Down
11 changes: 6 additions & 5 deletions internal/browingdata/history/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import (
"sort"
"time"

_ "github.com/mattn/go-sqlite3"

"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"

// import sqlite3 driver
_ "github.com/mattn/go-sqlite3"
)

type ChromiumHistory []history

type history struct {
Title string
Url string
URL string
VisitCount int
LastVisitTime time.Time
}
Expand Down Expand Up @@ -48,7 +49,7 @@ func (c *ChromiumHistory) Parse(masterKey []byte) error {
log.Warn(err)
}
data := history{
Url: url,
URL: url,
Title: title,
VisitCount: visitCount,
LastVisitTime: typeutil.TimeEpoch(lastVisitTime),
Expand Down Expand Up @@ -109,7 +110,7 @@ func (f *FirefoxHistory) Parse(masterKey []byte) error {
}
*f = append(*f, history{
Title: title,
Url: url,
URL: url,
VisitCount: visitCount,
LastVisitTime: typeutil.TimeStamp(visitDate / 1000000),
})
Expand Down
4 changes: 2 additions & 2 deletions internal/browingdata/localstorage/localstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"os"
"strings"

"github.com/syndtr/goleveldb/leveldb"

"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"

"github.com/syndtr/goleveldb/leveldb"
)

type ChromiumLocalStorage []storage
Expand Down
7 changes: 3 additions & 4 deletions internal/browingdata/outputter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {

if dir != "" {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0o777)
err := os.MkdirAll(dir, 0o750)
if err != nil {
return nil, err
}
Expand All @@ -62,7 +62,7 @@ func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
var file *os.File
var err error
p := filepath.Join(dir, filename)
file, err = os.OpenFile(p, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
file, err = os.OpenFile(filepath.Clean(p), os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
if err != nil {
return nil, err
}
Expand All @@ -72,7 +72,6 @@ func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
func (o *OutPutter) Ext() string {
if o.json {
return "json"
} else {
return "csv"
}
return "csv"
}
1 change: 1 addition & 0 deletions internal/browingdata/outputter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

func TestNewOutPutter(t *testing.T) {
t.Parallel()
out := NewOutPutter("json")
if out == nil {
t.Error("New() returned nil")
Expand Down
Loading

0 comments on commit ab6ca5a

Please sign in to comment.