mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
feat: add browserdata/datautil helpers (#513)
* feat: add browserdata/datautil helpers (QuerySQLite, QueryRows, DecryptChromiumValue) Phase 2 of architecture refactoring (RFC-002 Section 3): - datautil/sqlite.go: QuerySQLite() — shared SQLite open/query/scan helper with optional journal_mode=off for Firefox databases - datautil/query.go: QueryRows[T]() — generic helper (Go 1.20) that wraps QuerySQLite and collects results into a typed slice - datautil/decrypt.go: DecryptChromiumValue() — unified Chromium decryption (DPAPI first, then AES-GCM/CBC fallback) - datautil/sqlite_test.go: tests for all helpers * refactor: move DecryptChromiumValue from datautil to browser/chromium - Remove browserdata/datautil/decrypt.go (Chromium-specific, not a generic util) - Will be added as browser/chromium/decrypt.go (unexported decryptValue) in the chromium extract methods PR - Update RFCs to reflect the change - Remove decrypt test from datautil tests * refactor: move datautil to utils/sqliteutil for consistency - Rename browserdata/datautil/ → utils/sqliteutil/ - Aligns with existing utils/ convention (fileutil, typeutil, byteutil) - QuerySQLite/QueryRows are generic SQLite helpers, not browserdata-specific - Update package name from datautil to sqliteutil - Update both RFCs to reflect new location * fix: apply review suggestions for sqliteutil - QuerySQLite: validate dbPath exists before sql.Open to prevent silently creating empty databases - Tests: check db.Close() errors with require.NoError
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package sqliteutil
|
||||
|
||||
import "database/sql"
|
||||
|
||||
// QueryRows is a generic helper (Go 1.18+) that wraps QuerySQLite and collects
|
||||
// results into a typed slice. Each extract method only needs to provide the
|
||||
// scan function that converts one database row into a typed value.
|
||||
//
|
||||
// Rows that fail to scan are skipped (logged at debug level by QuerySQLite).
|
||||
func QueryRows[T any](dbPath string, journalOff bool, query string, scanRow func(*sql.Rows) (T, error)) ([]T, error) {
|
||||
var items []T
|
||||
err := QuerySQLite(dbPath, journalOff, query, func(rows *sql.Rows) error {
|
||||
item, err := scanRow(rows)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
items = append(items, item)
|
||||
return nil
|
||||
})
|
||||
return items, err
|
||||
}
|
||||
Reference in New Issue
Block a user