Files
HackBrowserData/internal/browser/chromium/extract_password.go
T
Roger fed6c722e2 refactor: open SQLite in one place and stream records (#688)
* 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.
2026-11-09 17:25:36 +08:00

59 lines
1.5 KiB
Go

package chromium
import (
"fmt"
"path/filepath"
"github.com/moond4rk/hackbrowserdata/internal/browser"
"github.com/moond4rk/hackbrowserdata/internal/record"
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
)
const (
defaultLoginQuery = `SELECT origin_url, username_value, password_value, date_created FROM logins`
)
// accountLoginData holds the signed-in account's logins, which Chrome keeps apart from Login Data.
const accountLoginData = "Login Data For Account"
func extractPasswords(masterKeys masterKeysFunc, path string, out browser.Collector) error {
store := record.StoreLocal
if filepath.Base(path) == accountLoginData {
store = record.StoreAccount
}
database, err := sqlitex.Open(path)
if err != nil {
return err
}
defer database.Close()
rows, err := database.Query(defaultLoginQuery)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
var url, username string
var encryptedPassword []byte
var created int64
if err := rows.Scan(&url, &username, &encryptedPassword, &created); err != nil {
out.Fail(err)
continue
}
password, err := masterKeys.decrypt(encryptedPassword)
if err != nil {
out.Fail(fmt.Errorf("decrypt password for %s: %w", url, err))
}
out.Add(&record.Login{
URL: url,
Username: username,
Password: string(password),
CreatedAt: timeconv.Chromium(created),
Store: store,
})
}
return rows.Err()
}