Files
HackBrowserData/browser/chromium/extract_extension.go
T
Roger 1ec2781131 feat: add Firefox extract methods and complete data model fields (#527)
* feat: add Firefox extract methods and complete data model fields

Firefox extract methods:
- extractPasswords: JSON + ASN1PBE decryption via decryptPBE helper
- extractCookies: SQLite, plaintext (no encryption), journalOff
- extractHistories: SQLite, visit count ASC sort (matches old behavior)
- extractDownloads: SQLite, moz_annos JOIN with JSON content parsing
- extractBookmarks: SQLite, moz_bookmarks JOIN moz_places
- extractExtensions: JSON, filter by location=app-profile
- extractLocalStorage: SQLite webappsstore2, reversed originKey parsing

Complete data model fields (union of Chromium and Firefox):
- CookieEntry: add HasExpire, IsPersistent
- DownloadEntry: add MimeType
- CreditCardEntry: add NickName, Address
- ExtensionEntry: add HomepageURL, Enabled

Update Chromium extractors to populate new fields:
- extract_cookie.go: fill HasExpire, IsPersistent
- extract_download.go: SELECT and fill mime_type
- extract_creditcard.go: SELECT nickname, billing_address_id
- extract_extension.go: fill HomepageURL, Enabled (state==1)

Tests:
- Full test coverage for all 7 Firefox extract functions
- Password test uses known ASN1PBE test vectors from crypto package
- Table-driven tests for parseOriginKey
- Updated Chromium tests for new fields

* fix: add COALESCE for nullable bookmark title in Firefox query

Firefox moz_bookmarks.title can be NULL (PR #500 fixed this in old code).
Add COALESCE to handle NULL gracefully in SQL instead of relying on
driver-specific NULL→string conversion behavior.

* fix: enable journalOff for all Firefox SQLite extractors and populate cookie flags

- Set journalOff=true for extract_history, extract_download, extract_bookmark
  (Firefox databases require PRAGMA journal_mode=off to avoid lock errors)
- Populate HasExpire and IsPersistent for Firefox cookies (derived from expiry>0)
- Add test assertions for HasExpire/IsPersistent in both Chromium and Firefox
2026-04-04 01:41:02 +08:00

62 lines
1.4 KiB
Go

package chromium
import (
"fmt"
"os"
"github.com/tidwall/gjson"
"github.com/moond4rk/hackbrowserdata/types"
)
func extractExtensions(path string) ([]types.ExtensionEntry, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
// Try known JSON paths for extension settings
settingKeys := []string{
"extensions.settings",
"settings.extensions",
"settings.settings",
}
var settings gjson.Result
for _, key := range settingKeys {
settings = gjson.GetBytes(data, key)
if settings.Exists() {
break
}
}
if !settings.Exists() {
return nil, fmt.Errorf("cannot find extensions in settings")
}
var extensions []types.ExtensionEntry
settings.ForEach(func(id, ext gjson.Result) bool {
// Skip system/component extensions
// https://source.chromium.org/chromium/chromium/src/+/main:extensions/common/mojom/manifest.mojom
location := ext.Get("location").Int()
if location == 5 || location == 10 {
return true
}
manifest := ext.Get("manifest")
if !manifest.Exists() {
return true
}
extensions = append(extensions, types.ExtensionEntry{
Name: manifest.Get("name").String(),
ID: id.String(),
Description: manifest.Get("description").String(),
Version: manifest.Get("version").String(),
HomepageURL: manifest.Get("homepage_url").String(),
Enabled: ext.Get("state").Int() == 1,
})
return true
})
return extensions, nil
}