mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
* refactor: stream records through sqlitex and the collector A row that failed to scan was logged at debug and dropped, so it never counted toward partial; it now reaches Collector.Fail. Every SQLite open goes through sqlitex with options instead of a bool, and extractors add records as they read them. * refactor: read SQLite rows with plain loops EachRow hid each extractor's loop and its skip rule behind two callbacks; every extractor now opens, queries, and walks its own rows, so the control flow reads top to bottom. * refactor(browser): drop the memoizing key closures Firefox derives its key once before the login loop, and Yandex loads its data key at the first row, so the state sits in plain variables where the loop uses it instead of inside a closure. * fix(safari): report unreadable localStorage origins A broken origin, database or row was only logged at debug level, so it never counted toward a partial result.
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package firefox
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
|
)
|
|
|
|
const localStorageQuery = `SELECT originKey, key, value FROM webappsstore2`
|
|
|
|
func extractLocalStorage(path string, out browser.Collector) error {
|
|
database, err := sqlitex.Open(path, sqlitex.JournalOff)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer database.Close()
|
|
|
|
rows, err := database.Query(localStorageQuery)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var originKey, key, value string
|
|
if err := rows.Scan(&originKey, &key, &value); err != nil {
|
|
out.Fail(err)
|
|
continue
|
|
}
|
|
out.Add(&record.LocalStorage{
|
|
URL: parseOriginKey(originKey),
|
|
Key: key,
|
|
Value: value,
|
|
})
|
|
}
|
|
return rows.Err()
|
|
}
|
|
|
|
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)
|
|
}
|