Skip to content

Commit ab6ca5a

Browse files
authored
Merge pull request #159 from moonD4rk/dev
refactor: formatting code used to pass golangci-lint rules
2 parents a2bfdeb + 76554e4 commit ab6ca5a

25 files changed

Lines changed: 282 additions & 177 deletions

.golangci.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
run:
2+
timeout: '5m'
3+
skip-dirs:
4+
- 'assets'
5+
allow-parallel-runners: true
6+
modules-download-mode: 'readonly'
7+
8+
linters:
9+
enable:
10+
- 'asciicheck'
11+
- 'deadcode'
12+
- 'depguard'
13+
- 'dogsled'
14+
- 'errorlint'
15+
- 'exportloopref'
16+
- 'gofmt'
17+
- 'goheader'
18+
- 'goimports'
19+
- 'gomodguard'
20+
- 'goprintffuncname'
21+
- 'gosec'
22+
- 'govet'
23+
- 'ineffassign'
24+
- 'makezero'
25+
- 'misspell'
26+
- 'paralleltest'
27+
- 'prealloc'
28+
- 'predeclared'
29+
- 'revive'
30+
- 'typecheck'
31+
- 'unconvert'
32+
- 'varcheck'
33+
- 'whitespace'
34+
disable:
35+
# unsupported lint with golang 1.18+ ref: https://github.com/golangci/golangci-lint/issues/2649
36+
- 'bodyclose'
37+
- 'gosimple'
38+
- 'noctx'
39+
- 'sqlclosecheck'
40+
- 'staticcheck'
41+
- 'structcheck'
42+
- 'stylecheck'
43+
- 'unused'
44+
- 'errcheck'
45+
46+
issues:
47+
exclude-use-default: false
48+
exclude:
49+
- should have a package comment
50+
- should have comment
51+
# G101: Potential hardcoded credentials
52+
- G101
53+
# G103: Use of unsafe calls should be audited
54+
- G103
55+
# G304: Potential file inclusion via variable
56+
- G304
57+
# G404, G401, G502, G505: weak cryptographic list
58+
- G401
59+
- G404
60+
- G502
61+
- G505
62+
exclude-rules:
63+
- path: internal/browser/browser\.go
64+
linters:
65+
- 'deadcode'
66+
- 'varcheck'
67+
- 'unused'
68+
max-issues-per-linter: 0
69+
max-same-issues: 0

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module hack-browser-data
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9

internal/browingdata/bookmark/bookmark.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"sort"
77
"time"
88

9-
"github.com/tidwall/gjson"
10-
119
"hack-browser-data/internal/item"
1210
"hack-browser-data/internal/log"
1311
"hack-browser-data/internal/utils/fileutil"
1412
"hack-browser-data/internal/utils/typeutil"
1513

14+
// import sqlite3 driver
1615
_ "github.com/mattn/go-sqlite3"
16+
"github.com/tidwall/gjson"
1717
)
1818

1919
type ChromiumBookmark []bookmark
@@ -51,7 +51,7 @@ func getBookmarkChildren(value gjson.Result, w *ChromiumBookmark) (children gjso
5151
const (
5252
bookmarkID = "id"
5353
bookmarkAdded = "date_added"
54-
bookmarkUrl = "url"
54+
bookmarkURL = "url"
5555
bookmarkName = "name"
5656
bookmarkType = "type"
5757
bookmarkChildren = "children"
@@ -60,7 +60,7 @@ func getBookmarkChildren(value gjson.Result, w *ChromiumBookmark) (children gjso
6060
bm := bookmark{
6161
ID: value.Get(bookmarkID).Int(),
6262
Name: value.Get(bookmarkName).String(),
63-
URL: value.Get(bookmarkUrl).String(),
63+
URL: value.Get(bookmarkURL).String(),
6464
DateAdded: typeutil.TimeEpoch(value.Get(bookmarkAdded).Int()),
6565
}
6666
children = value.Get(bookmarkChildren)

internal/browingdata/browsingdata.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,22 @@ func (d *Data) Output(dir, browserName, flag string) {
5353
// if the length of the export data is 0, then it is not necessary to output
5454
continue
5555
}
56-
filename := fileutil.Filename(browserName, source.Name(), output.Ext())
56+
filename := fileutil.ItemName(browserName, source.Name(), output.Ext())
5757

5858
f, err := output.CreateFile(dir, filename)
5959
if err != nil {
60-
log.Errorf("create file error %s", err)
60+
log.Errorf("create file %s error %s", filename, err.Error())
61+
continue
6162
}
6263
if err := output.Write(source, f); err != nil {
63-
log.Errorf("%s write to file %s error %s", source.Name(), filename, err.Error())
64+
log.Errorf("write to file %s error %s", filename, err.Error())
65+
continue
66+
}
67+
if err := f.Close(); err != nil {
68+
log.Errorf("close file %s error %s", filename, err.Error())
69+
continue
6470
}
6571
log.Noticef("output to file %s success", path.Join(dir, filename))
66-
f.Close()
6772
}
6873
}
6974

internal/browingdata/cookie/cookie.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"sort"
77
"time"
88

9-
_ "github.com/mattn/go-sqlite3"
10-
119
"hack-browser-data/internal/decrypter"
1210
"hack-browser-data/internal/item"
1311
"hack-browser-data/internal/log"
1412
"hack-browser-data/internal/utils/typeutil"
13+
14+
// import sqlite3 driver
15+
_ "github.com/mattn/go-sqlite3"
1516
)
1617

1718
type ChromiumCookie []cookie
@@ -72,7 +73,7 @@ func (c *ChromiumCookie) Parse(masterKey []byte) error {
7273
if len(encryptValue) > 0 {
7374
var err error
7475
if masterKey == nil {
75-
value, err = decrypter.DPApi(encryptValue)
76+
value, err = decrypter.DPAPI(encryptValue)
7677
} else {
7778
value, err = decrypter.Chromium(masterKey, encryptValue)
7879
}
@@ -118,18 +119,18 @@ func (f *FirefoxCookie) Parse(masterKey []byte) error {
118119
for rows.Next() {
119120
var (
120121
name, value, host, path string
121-
isSecure, isHttpOnly int
122+
isSecure, isHTTPOnly int
122123
creationTime, expiry int64
123124
)
124-
if err = rows.Scan(&name, &value, &host, &path, &creationTime, &expiry, &isSecure, &isHttpOnly); err != nil {
125+
if err = rows.Scan(&name, &value, &host, &path, &creationTime, &expiry, &isSecure, &isHTTPOnly); err != nil {
125126
log.Warn(err)
126127
}
127128
*f = append(*f, cookie{
128129
KeyName: name,
129130
Host: host,
130131
Path: path,
131132
IsSecure: typeutil.IntToBool(isSecure),
132-
IsHTTPOnly: typeutil.IntToBool(isHttpOnly),
133+
IsHTTPOnly: typeutil.IntToBool(isHTTPOnly),
133134
CreateDate: typeutil.TimeStamp(creationTime / 1000000),
134135
ExpireDate: typeutil.TimeStamp(expiry),
135136
Value: value,

internal/browingdata/creditcard/creditcard.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"database/sql"
55
"os"
66

7-
_ "github.com/mattn/go-sqlite3"
8-
97
"hack-browser-data/internal/decrypter"
108
"hack-browser-data/internal/item"
119
"hack-browser-data/internal/log"
10+
11+
// import sqlite3 driver
12+
_ "github.com/mattn/go-sqlite3"
1213
)
1314

1415
type ChromiumCreditCard []card
@@ -56,7 +57,7 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
5657
NickName: nickname,
5758
}
5859
if masterKey == nil {
59-
value, err = decrypter.DPApi(encryptValue)
60+
value, err = decrypter.DPAPI(encryptValue)
6061
if err != nil {
6162
return err
6263
}
@@ -112,7 +113,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
112113
NickName: nickname,
113114
}
114115
if masterKey == nil {
115-
value, err = decrypter.DPApi(encryptValue)
116+
value, err = decrypter.DPAPI(encryptValue)
116117
if err != nil {
117118
return err
118119
}

internal/browingdata/download/download.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"hack-browser-data/internal/log"
1212
"hack-browser-data/internal/utils/typeutil"
1313

14+
// import sqlite3 driver
1415
_ "github.com/mattn/go-sqlite3"
1516
"github.com/tidwall/gjson"
1617
)
@@ -19,7 +20,7 @@ type ChromiumDownload []download
1920

2021
type download struct {
2122
TargetPath string
22-
Url string
23+
URL string
2324
TotalBytes int64
2425
StartTime time.Time
2526
EndTime time.Time
@@ -44,15 +45,15 @@ func (c *ChromiumDownload) Parse(masterKey []byte) error {
4445
defer rows.Close()
4546
for rows.Next() {
4647
var (
47-
targetPath, tabUrl, mimeType string
48+
targetPath, tabURL, mimeType string
4849
totalBytes, startTime, endTime int64
4950
)
50-
if err := rows.Scan(&targetPath, &tabUrl, &totalBytes, &startTime, &endTime, &mimeType); err != nil {
51+
if err := rows.Scan(&targetPath, &tabURL, &totalBytes, &startTime, &endTime, &mimeType); err != nil {
5152
log.Warn(err)
5253
}
5354
data := download{
5455
TargetPath: targetPath,
55-
Url: tabUrl,
56+
URL: tabURL,
5657
TotalBytes: totalBytes,
5758
StartTime: typeutil.TimeEpoch(startTime),
5859
EndTime: typeutil.TimeEpoch(endTime),
@@ -119,7 +120,7 @@ func (f *FirefoxDownload) Parse(masterKey []byte) error {
119120
fileSize := gjson.Get(json, "fileSize")
120121
*f = append(*f, download{
121122
TargetPath: path,
122-
Url: url,
123+
URL: url,
123124
TotalBytes: fileSize.Int(),
124125
StartTime: typeutil.TimeStamp(dateAdded / 1000000),
125126
EndTime: typeutil.TimeStamp(endTime.Int() / 1000),

internal/browingdata/extension/extension.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package extension
33
import (
44
"os"
55

6-
"github.com/tidwall/gjson"
7-
86
"hack-browser-data/internal/item"
97
"hack-browser-data/internal/log"
108
"hack-browser-data/internal/utils/fileutil"
9+
10+
"github.com/tidwall/gjson"
1111
)
1212

1313
type ChromiumExtension []*extension

internal/browingdata/history/history.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import (
66
"sort"
77
"time"
88

9-
_ "github.com/mattn/go-sqlite3"
10-
119
"hack-browser-data/internal/item"
1210
"hack-browser-data/internal/log"
1311
"hack-browser-data/internal/utils/typeutil"
12+
13+
// import sqlite3 driver
14+
_ "github.com/mattn/go-sqlite3"
1415
)
1516

1617
type ChromiumHistory []history
1718

1819
type history struct {
1920
Title string
20-
Url string
21+
URL string
2122
VisitCount int
2223
LastVisitTime time.Time
2324
}
@@ -48,7 +49,7 @@ func (c *ChromiumHistory) Parse(masterKey []byte) error {
4849
log.Warn(err)
4950
}
5051
data := history{
51-
Url: url,
52+
URL: url,
5253
Title: title,
5354
VisitCount: visitCount,
5455
LastVisitTime: typeutil.TimeEpoch(lastVisitTime),
@@ -109,7 +110,7 @@ func (f *FirefoxHistory) Parse(masterKey []byte) error {
109110
}
110111
*f = append(*f, history{
111112
Title: title,
112-
Url: url,
113+
URL: url,
113114
VisitCount: visitCount,
114115
LastVisitTime: typeutil.TimeStamp(visitDate / 1000000),
115116
})

internal/browingdata/localstorage/localstorage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"os"
88
"strings"
99

10-
"github.com/syndtr/goleveldb/leveldb"
11-
1210
"hack-browser-data/internal/item"
1311
"hack-browser-data/internal/log"
1412
"hack-browser-data/internal/utils/typeutil"
13+
14+
"github.com/syndtr/goleveldb/leveldb"
1515
)
1616

1717
type ChromiumLocalStorage []storage

0 commit comments

Comments
 (0)