Skip to content

Commit 6d710c2

Browse files
committed
refactor: refactor package with gofumpt
1 parent e6aa1f0 commit 6d710c2

18 files changed

Lines changed: 44 additions & 72 deletions

File tree

cmd/hack-browser-data/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Execute() {
2929
Name: "hack-browser-data",
3030
Usage: "Export passwords/cookies/history/bookmarks from browser",
3131
UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\nExport all browingdata(password/cookie/history/bookmark) from browser\nGithub Link: https://github.com/moonD4rk/HackBrowserData",
32-
Version: "0.4.2",
32+
Version: "0.4.3",
3333
Flags: []cli.Flag{
3434
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
3535
&cli.BoolFlag{Name: "compress", Aliases: []string{"zip"}, Destination: &compress, Value: false, Usage: "compress result to zip"},

internal/browingdata/browsingdata.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func New(sources []item.Item) *Data {
3535
}
3636

3737
func (d *Data) Recovery(masterKey []byte) error {
38-
3938
for _, source := range d.sources {
4039
if err := source.Parse(masterKey); err != nil {
4140
log.Errorf("parse %s error %s", source.Name(), err.Error())
@@ -48,7 +47,6 @@ func (d *Data) Output(dir, browserName, flag string) {
4847
output := NewOutPutter(flag)
4948

5049
for _, source := range d.sources {
51-
5250
filename := fileutil.Filename(browserName, source.Name(), output.Ext())
5351

5452
f, err := output.CreateFile(dir, filename)

internal/browingdata/creditcard/creditcard.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
7171
}
7272
return nil
7373
}
74+
7475
func (c *ChromiumCreditCard) Name() string {
7576
return "creditcard"
7677
}
@@ -122,6 +123,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
122123
}
123124
return nil
124125
}
126+
125127
func (c *YandexCreditCard) Name() string {
126128
return "creditcard"
127129
}

internal/browingdata/localstorage/localstorage.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (c *ChromiumLocalStorage) Parse(masterKey []byte) error {
4040
if len(value) > 1024*5 {
4141
continue
4242
}
43-
var s = new(storage)
43+
s := new(storage)
4444
s.fillKey(key)
4545
s.fillValue(value)
4646
// don't save meta data
@@ -114,13 +114,11 @@ func (f *FirefoxLocalStorage) Parse(masterKey []byte) error {
114114
}
115115
defer rows.Close()
116116
for rows.Next() {
117-
var (
118-
originKey, key, value string
119-
)
117+
var originKey, key, value string
120118
if err = rows.Scan(&originKey, &key, &value); err != nil {
121119
log.Warn(err)
122120
}
123-
var s = new(storage)
121+
s := new(storage)
124122
s.fillFirefox(originKey, key, value)
125123
*f = append(*f, *s)
126124
}

internal/browingdata/outputter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
5050

5151
if dir != "" {
5252
if _, err := os.Stat(dir); os.IsNotExist(err) {
53-
err := os.MkdirAll(dir, 0777)
53+
err := os.MkdirAll(dir, 0o777)
5454
if err != nil {
5555
return nil, err
5656
}
@@ -60,7 +60,7 @@ func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
6060
var file *os.File
6161
var err error
6262
p := filepath.Join(dir, filename)
63-
file, err = os.OpenFile(p, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
63+
file, err = os.OpenFile(p, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
6464
if err != nil {
6565
return nil, err
6666
}

internal/browingdata/password/password.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ func (f *FirefoxPassword) Name() string {
229229
}
230230

231231
func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err error) {
232-
var (
233-
keyDB *sql.DB
234-
)
232+
var keyDB *sql.DB
235233
keyDB, err = sql.Open("sqlite3", key4file)
236234
if err != nil {
237235
return nil, nil, nil, nil, err

internal/browser/browser.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ func ListBrowser() []string {
111111
return l
112112
}
113113

114-
var (
115-
// home dir path for all platforms
116-
homeDir, _ = os.UserHomeDir()
117-
)
114+
// home dir path for all platforms
115+
var homeDir, _ = os.UserHomeDir()
118116

119117
const (
120118
chromeName = "Chrome"

internal/browser/browser_windows.go

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
package browser
44

55
import (
6-
"io/ioutil"
7-
"os"
8-
96
"hack-browser-data/internal/item"
107
)
118

@@ -18,7 +15,7 @@ var (
1815
}{
1916
"chrome": {
2017
name: chromeName,
21-
profilePath: getProfiles(chromeUserDataPath)[0],
18+
profilePath: chromeUserDataPath,
2219
items: item.DefaultChromium,
2320
},
2421
"edge": {
@@ -28,12 +25,12 @@ var (
2825
},
2926
"chromium": {
3027
name: chromiumName,
31-
profilePath: getProfiles(chromiumUserDataPath)[0],
28+
profilePath: chromiumUserDataPath,
3229
items: item.DefaultChromium,
3330
},
3431
"chrome-beta": {
3532
name: chromeBetaName,
36-
profilePath: getProfiles(chromeBetaUserDataPath)[0],
33+
profilePath: chromeBetaUserDataPath,
3734
items: item.DefaultChromium,
3835
},
3936
"opera": {
@@ -91,31 +88,10 @@ var (
9188
}
9289
)
9390

94-
func getProfiles(userDataPath string) []string {
95-
var res []string
96-
files, err := ioutil.ReadDir(userDataPath)
97-
98-
if err != nil {
99-
100-
res = append(res, userDataPath+"Default")
101-
}
102-
103-
for _, f := range files {
104-
if f.IsDir() && f.Name() != "System Profile" {
105-
var thisPath = userDataPath + f.Name()
106-
_, err := os.Stat(thisPath + "/Login Data")
107-
if err == nil {
108-
res = append(res, userDataPath+f.Name())
109-
}
110-
}
111-
}
112-
return res
113-
}
114-
11591
var (
116-
chromeUserDataPath = homeDir + "/AppData/Local/Google/Chrome/User Data/"
117-
chromeBetaUserDataPath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/"
118-
chromiumUserDataPath = homeDir + "/AppData/Local/Chromium/User Data/"
92+
chromeUserDataPath = homeDir + "/AppData/Local/Google/Chrome/User Data/Default/"
93+
chromeBetaUserDataPath = homeDir + "/AppData/Local/Google/Chrome Beta/User Data/Default/"
94+
chromiumUserDataPath = homeDir + "/AppData/Local/Chromium/User Data/Default/"
11995
edgeProfilePath = homeDir + "/AppData/Local/Microsoft/Edge/User Data/Default/"
12096
braveProfilePath = homeDir + "/AppData/Local/BraveSoftware/Brave-Browser/User Data/Default/"
12197
speed360ProfilePath = homeDir + "/AppData/Local/360chrome/Chrome/User Data/Default/"

internal/browser/chromium/chromium.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*chromium, err
3939
name: fileutil.BrowserName(name, user),
4040
items: typeutil.Keys(itemPaths),
4141
itemPaths: itemPaths,
42+
storage: storage,
4243
})
4344
}
4445
return chromiumList, nil
@@ -90,7 +91,7 @@ func (c *chromium) copyItemToLocal() error {
9091
}
9192

9293
func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.Item]string, error) {
93-
var itemPaths = make(map[item.Item]string)
94+
itemPaths := make(map[item.Item]string)
9495
parentDir := fileutil.ParentDir(profilePath)
9596
baseDir := fileutil.BaseDir(profilePath)
9697
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
@@ -102,7 +103,8 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
102103
}
103104

104105
func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
105-
var multiItemPaths = make(map[string]map[item.Item]string)
106+
// multiItemPaths is a map of user to item path, map[profile 1][item's name & path key pair]
107+
multiItemPaths := make(map[string]map[item.Item]string)
106108
parentDir := fileutil.ParentDir(profilePath)
107109
err := filepath.Walk(parentDir, chromiumWalkFunc2(items, multiItemPaths))
108110
if err != nil {
@@ -126,6 +128,7 @@ func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[
126128
}
127129
t[userDir] = v
128130
t[userDir][item.ChromiumKey] = keyPath
131+
fillLocalStoragePath(t[userDir], item.ChromiumLocalStorage)
129132
}
130133
return t, nil
131134
}

internal/browser/chromium/chromium_darwin.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin
2+
13
package chromium
24

35
import (
@@ -46,7 +48,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
4648
if chromeSecret == nil {
4749
return nil, ErrWrongSecurityCommand
4850
}
49-
var chromeSalt = []byte("saltysalt")
51+
chromeSalt := []byte("saltysalt")
5052
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
5153
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
5254
if key == nil {

0 commit comments

Comments
 (0)