mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Def, Request, DirID, and Source said too little, and short variables and doc comments that skip their name hid intent. varnamelen and staticcheck ST1020-22 now keep both from coming back.
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package firefox
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
|
)
|
|
|
|
const firefoxLocalStorageQuery = `SELECT originKey, key, value FROM webappsstore2`
|
|
|
|
func extractLocalStorage(path string, out browser.Collector) error {
|
|
entries, err := sqlitex.QueryRows(path, true, firefoxLocalStorageQuery,
|
|
func(rows *sql.Rows) (record.LocalStorage, error) {
|
|
var originKey, key, value string
|
|
if err := rows.Scan(&originKey, &key, &value); err != nil {
|
|
return record.LocalStorage{}, err
|
|
}
|
|
return record.LocalStorage{
|
|
URL: parseOriginKey(originKey),
|
|
Key: key,
|
|
Value: value,
|
|
}, nil
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
emit(out, entries)
|
|
return nil
|
|
}
|
|
|
|
func reverseString(text string) string {
|
|
reversed := []byte(text)
|
|
for i, j := 0, len(reversed)-1; i < j; i, j = i+1, j-1 {
|
|
reversed[i], reversed[j] = reversed[j], reversed[i]
|
|
}
|
|
return string(reversed)
|
|
}
|
|
|
|
// parseOriginKey undoes Firefox's reversed host: "moc.buhtig.:https:443" is https://github.com:443.
|
|
func parseOriginKey(originKey string) string {
|
|
parts := strings.SplitN(originKey, ":", 3)
|
|
if len(parts) < 2 {
|
|
return originKey
|
|
}
|
|
host := reverseString(parts[0])
|
|
host = strings.TrimPrefix(host, ".")
|
|
scheme := parts[1]
|
|
if len(parts) == 3 {
|
|
return fmt.Sprintf("%s://%s:%s", scheme, host, parts[2])
|
|
}
|
|
return fmt.Sprintf("%s://%s", scheme, host)
|
|
}
|