mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: introduce category, record, and export packages (#651)
Later layers speak categories and records, and export needs nothing else. Ordering rows once in the exporter fixes Firefox history, written least visited first.
This commit is contained in:
1 parent
9937dbf9fb
commit
b04c436a73
97 files changed
+1993
-1646
No files matched your search
+3
-3
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/browser/chromium"
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||
)
|
||||
|
||||
@@ -16,14 +16,14 @@ import (
|
||||
// cross-host transport (Chromium only).
|
||||
type Archivable interface {
|
||||
BrowserKey() string
|
||||
ArchiveSources(categories []types.Category) []chromium.ArchiveSource
|
||||
ArchiveSources(categories []category.Category) []chromium.ArchiveSource
|
||||
}
|
||||
|
||||
// WriteArchive packs each browser's decryption-relevant files into a zip whose internal layout is
|
||||
// <browser-key>/<User Data layout>, so a restore can re-expand it and decrypt with a keys.json. Files
|
||||
// are staged through a locked-file session first because Windows holds exclusive SQLite locks. Returns
|
||||
// the number of source entries staged (a directory source counts once).
|
||||
func WriteArchive(browsers []Browser, categories []types.Category, outPath string) (int, error) {
|
||||
func WriteArchive(browsers []Browser, categories []category.Category, outPath string) (int, error) {
|
||||
session, err := filemanager.NewSession()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/browser/chromium"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||
)
|
||||
@@ -34,7 +35,7 @@ func TestWriteArchive_RoundTrip(t *testing.T) {
|
||||
}
|
||||
|
||||
zipPath := filepath.Join(t.TempDir(), "data.zip")
|
||||
n, err := WriteArchive([]Browser{b}, []types.Category{types.History}, zipPath)
|
||||
n, err := WriteArchive([]Browser{b}, []category.Category{category.History}, zipPath)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteArchive: %v", err)
|
||||
}
|
||||
|
||||
+3
-2
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/moond4rk/hackbrowserdata/browser/chromium"
|
||||
"github.com/moond4rk/hackbrowserdata/browser/firefox"
|
||||
"github.com/moond4rk/hackbrowserdata/browser/safari"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
@@ -19,8 +20,8 @@ type Browser interface {
|
||||
BrowserName() string
|
||||
UserDataDir() string
|
||||
Profiles() []types.Profile
|
||||
Extract(categories []types.Category) ([]types.ExtractResult, error)
|
||||
CountEntries(categories []types.Category) ([]types.CountResult, error)
|
||||
Extract(categories []category.Category) ([]types.ExtractResult, error)
|
||||
CountEntries(categories []category.Category) ([]types.CountResult, error)
|
||||
}
|
||||
|
||||
type DiscoverOptions struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ var installationFiles = []string{"Local State"}
|
||||
// ArchiveSources lists the files an archive must capture for the given categories: the User Data root
|
||||
// files (Local State), every resolved category source per profile, plus each profile's Preferences
|
||||
// marker so a restore can rediscover the profile. LayoutRel is forward-slash, relative to the root.
|
||||
func (b *Browser) ArchiveSources(categories []types.Category) []ArchiveSource {
|
||||
func (b *Browser) ArchiveSources(categories []category.Category) []ArchiveSource {
|
||||
var out []ArchiveSource
|
||||
for _, name := range installationFiles {
|
||||
abs := filepath.Join(b.cfg.UserDataDir, name)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -30,7 +31,7 @@ func TestArchiveSources_ForwardSlashLayout(t *testing.T) {
|
||||
t.Fatalf("NewBrowser: b=%v err=%v", b, err)
|
||||
}
|
||||
|
||||
srcs := b.ArchiveSources([]types.Category{types.Cookie})
|
||||
srcs := b.ArchiveSources([]category.Category{category.Cookie})
|
||||
|
||||
var gotCookie, gotMarker, gotLocalState bool
|
||||
for _, s := range srcs {
|
||||
@@ -70,7 +71,7 @@ func TestArchiveSources_FlatLayoutNoExtraLevel(t *testing.T) {
|
||||
t.Fatalf("NewBrowser: b=%v err=%v", b, err)
|
||||
}
|
||||
|
||||
srcs := b.ArchiveSources([]types.Category{types.History})
|
||||
srcs := b.ArchiveSources([]category.Category{category.History})
|
||||
|
||||
phantom := filepath.Base(udd) + "/"
|
||||
var gotHistory bool
|
||||
@@ -106,7 +107,7 @@ func TestArchiveSources_IncludesBothPasswordDatabases(t *testing.T) {
|
||||
t.Fatalf("NewBrowser: b=%v err=%v", b, err)
|
||||
}
|
||||
|
||||
srcs := b.ArchiveSources([]types.Category{types.Password})
|
||||
srcs := b.ArchiveSources([]category.Category{category.Password})
|
||||
|
||||
var gotLocal, gotAccount bool
|
||||
for _, s := range srcs {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
@@ -68,7 +69,7 @@ func (b *Browser) Profiles() []types.Profile {
|
||||
}
|
||||
|
||||
// Extract derives the installation's master key once, then extracts every profile.
|
||||
func (b *Browser) Extract(categories []types.Category) ([]types.ExtractResult, error) {
|
||||
func (b *Browser) Extract(categories []category.Category) ([]types.ExtractResult, error) {
|
||||
masterKeys := b.masterKeys()
|
||||
results := make([]types.ExtractResult, 0, len(b.profiles))
|
||||
for _, p := range b.profiles {
|
||||
@@ -81,7 +82,7 @@ func (b *Browser) Extract(categories []types.Category) ([]types.ExtractResult, e
|
||||
}
|
||||
|
||||
// CountEntries counts entries per category for every profile without decryption.
|
||||
func (b *Browser) CountEntries(categories []types.Category) ([]types.CountResult, error) {
|
||||
func (b *Browser) CountEntries(categories []category.Category) ([]types.CountResult, error) {
|
||||
results := make([]types.CountResult, 0, len(b.profiles))
|
||||
for _, p := range b.profiles {
|
||||
results = append(results, types.CountResult{
|
||||
@@ -145,7 +146,7 @@ func (b *Browser) buildHints(session *filemanager.Session) masterkey.Hints {
|
||||
// discoverProfiles lists subdirectories of userDataDir that are valid
|
||||
// Chromium profile directories. A directory is considered a profile if it
|
||||
// contains a "Preferences" file, which Chromium creates for every profile.
|
||||
func discoverProfiles(userDataDir string, sources map[types.Category][]sourcePath) []string {
|
||||
func discoverProfiles(userDataDir string, sources map[category.Category][]sourcePath) []string {
|
||||
entries, err := os.ReadDir(userDataDir)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -206,7 +207,7 @@ func isProfileDir(dir string) bool {
|
||||
}
|
||||
|
||||
// hasAnySource checks if dir contains at least one source file or directory.
|
||||
func hasAnySource(sources map[types.Category][]sourcePath, dir string) bool {
|
||||
func hasAnySource(sources map[category.Category][]sourcePath, dir string) bool {
|
||||
for _, candidates := range sources {
|
||||
for _, sp := range candidates {
|
||||
abs := filepath.Join(dir, sp.rel)
|
||||
@@ -228,8 +229,8 @@ type resolvedPath struct {
|
||||
|
||||
// resolveSourcePaths checks which sources actually exist in profileDir.
|
||||
// Candidates are tried in priority order; the first existing path wins.
|
||||
func resolveSourcePaths(sources map[types.Category][]sourcePath, profileDir string) map[types.Category]resolvedPath {
|
||||
resolved := make(map[types.Category]resolvedPath)
|
||||
func resolveSourcePaths(sources map[category.Category][]sourcePath, profileDir string) map[category.Category]resolvedPath {
|
||||
resolved := make(map[category.Category]resolvedPath)
|
||||
for cat, candidates := range sources {
|
||||
for _, sp := range candidates {
|
||||
abs := filepath.Join(profileDir, sp.rel)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -136,7 +137,7 @@ func TestNewBrowsers(t *testing.T) {
|
||||
kind types.BrowserKind
|
||||
wantProfiles []string // expected profile base names
|
||||
wantCats map[string][]string // profile → expected category base names (spot check)
|
||||
wantDirs []types.Category // categories that should be isDir=true
|
||||
wantDirs []category.Category // categories that should be isDir=true
|
||||
skipProfiles []string // should NOT appear
|
||||
}{
|
||||
{
|
||||
@@ -147,7 +148,7 @@ func TestNewBrowsers(t *testing.T) {
|
||||
wantCats: map[string][]string{
|
||||
"Default": {"Login Data", "Cookies", "History", "Bookmarks", "Web Data", "Secure Preferences", "leveldb", "Session Storage"},
|
||||
},
|
||||
wantDirs: []types.Category{types.LocalStorage, types.SessionStorage},
|
||||
wantDirs: []category.Category{category.LocalStorage, category.SessionStorage},
|
||||
skipProfiles: []string{"System Profile", "Guest Profile", "Snapshot"},
|
||||
},
|
||||
{
|
||||
@@ -194,14 +195,14 @@ func TestNewBrowsers(t *testing.T) {
|
||||
dir: fixture.leveldb,
|
||||
kind: types.Chromium,
|
||||
wantProfiles: []string{"Default"},
|
||||
wantDirs: []types.Category{types.LocalStorage, types.SessionStorage},
|
||||
wantDirs: []category.Category{category.LocalStorage, category.SessionStorage},
|
||||
},
|
||||
{
|
||||
name: "leveldb only",
|
||||
dir: fixture.leveldbOnly,
|
||||
kind: types.Chromium,
|
||||
wantProfiles: []string{"Default"},
|
||||
wantDirs: []types.Category{types.LocalStorage, types.SessionStorage},
|
||||
wantDirs: []category.Category{category.LocalStorage, category.SessionStorage},
|
||||
},
|
||||
{
|
||||
name: "empty dir",
|
||||
@@ -323,7 +324,7 @@ func assertCategories(t *testing.T, nameMap map[string]*profile, wantCats map[st
|
||||
}
|
||||
}
|
||||
|
||||
func assertDirCategories(t *testing.T, profiles []*profile, cats []types.Category) {
|
||||
func assertDirCategories(t *testing.T, profiles []*profile, cats []category.Category) {
|
||||
t.Helper()
|
||||
for _, cat := range cats {
|
||||
for _, p := range profiles {
|
||||
@@ -340,15 +341,15 @@ func assertDirCategories(t *testing.T, profiles []*profile, cats []types.Categor
|
||||
|
||||
func TestCookiePriority(t *testing.T) {
|
||||
resolved := resolveSourcePaths(chromiumSources, filepath.Join(fixture.bothCookies, "Default"))
|
||||
require.Contains(t, resolved, types.Cookie)
|
||||
assert.Contains(t, resolved[types.Cookie].absPath, "Network",
|
||||
require.Contains(t, resolved, category.Cookie)
|
||||
assert.Contains(t, resolved[category.Cookie].absPath, "Network",
|
||||
"Network/Cookies should win over root Cookies")
|
||||
}
|
||||
|
||||
func TestCookieFallback(t *testing.T) {
|
||||
resolved := resolveSourcePaths(chromiumSources, filepath.Join(fixture.oldCookies, "Default"))
|
||||
require.Contains(t, resolved, types.Cookie)
|
||||
assert.NotContains(t, resolved[types.Cookie].absPath, "Network",
|
||||
require.Contains(t, resolved, category.Cookie)
|
||||
assert.NotContains(t, resolved[category.Cookie].absPath, "Network",
|
||||
"should fallback to root Cookies when Network/Cookies missing")
|
||||
}
|
||||
|
||||
@@ -358,7 +359,7 @@ func TestCookieFallback(t *testing.T) {
|
||||
|
||||
func TestSharedSourceFile(t *testing.T) {
|
||||
resolved := resolveSourcePaths(chromiumSources, filepath.Join(fixture.chrome, "Default"))
|
||||
assert.Equal(t, resolved[types.History].absPath, resolved[types.Download].absPath)
|
||||
assert.Equal(t, resolved[category.History].absPath, resolved[category.Download].absPath)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -369,10 +370,10 @@ func TestSourcesForKind(t *testing.T) {
|
||||
chromium := sourcesForKind(types.Chromium)
|
||||
yandex := sourcesForKind(types.ChromiumYandex)
|
||||
|
||||
assert.Equal(t, "Login Data", chromium[types.Password][0].rel)
|
||||
assert.Equal(t, "Ya Passman Data", yandex[types.Password][0].rel)
|
||||
assert.Equal(t, "Login Data", chromium[category.Password][0].rel)
|
||||
assert.Equal(t, "Ya Passman Data", yandex[category.Password][0].rel)
|
||||
// Yandex inherits non-overridden categories
|
||||
assert.Equal(t, chromium[types.History][0].rel, yandex[types.History][0].rel)
|
||||
assert.Equal(t, chromium[category.History][0].rel, yandex[category.History][0].rel)
|
||||
}
|
||||
|
||||
func TestExtractorsForKind(t *testing.T) {
|
||||
@@ -380,12 +381,12 @@ func TestExtractorsForKind(t *testing.T) {
|
||||
|
||||
yandexExt := extractorsForKind(types.ChromiumYandex)
|
||||
require.NotNil(t, yandexExt)
|
||||
assert.Contains(t, yandexExt, types.Password)
|
||||
assert.Contains(t, yandexExt, types.CreditCard)
|
||||
assert.Contains(t, yandexExt, category.Password)
|
||||
assert.Contains(t, yandexExt, category.CreditCard)
|
||||
|
||||
operaExt := extractorsForKind(types.ChromiumOpera)
|
||||
require.NotNil(t, operaExt)
|
||||
assert.Contains(t, operaExt, types.Extension)
|
||||
assert.Contains(t, operaExt, category.Extension)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -608,13 +609,12 @@ func TestExtract(t *testing.T) {
|
||||
b.SetRetrievers(masterkey.Retrievers{V10: tt.retriever})
|
||||
}
|
||||
|
||||
results, err := b.Extract([]types.Category{types.History})
|
||||
results, err := b.Extract([]category.Category{category.History})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
require.NotNil(t, results[0].Data)
|
||||
require.Len(t, results[0].Data.Histories, 3)
|
||||
// setupHistoryDB: Example(200) > GitHub(100) > Go Dev(50)
|
||||
assert.Equal(t, "Example", results[0].Data.Histories[0].Title)
|
||||
assert.Equal(t, "GitHub", results[0].Data.Histories[0].Title)
|
||||
|
||||
if tt.wantRetriever {
|
||||
mock, ok := tt.retriever.(*mockRetriever)
|
||||
@@ -641,15 +641,15 @@ func TestCountEntries(t *testing.T) {
|
||||
require.NotNil(t, b)
|
||||
|
||||
// No retriever set — CountEntries should still work (no decryption needed).
|
||||
results, err := b.CountEntries([]types.Category{types.History, types.Download})
|
||||
results, err := b.CountEntries([]category.Category{category.History, category.Download})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
|
||||
assert.Equal(t, 3, results[0].Counts[types.History])
|
||||
assert.Equal(t, 3, results[0].Counts[category.History])
|
||||
// Download uses a different table in the same file; since we only
|
||||
// created the urls table (not downloads), the count query will fail
|
||||
// gracefully and return 0.
|
||||
assert.Equal(t, 0, results[0].Counts[types.Download])
|
||||
assert.Equal(t, 0, results[0].Counts[category.Download])
|
||||
}
|
||||
|
||||
func TestCountEntries_NoRetrieverNeeded(t *testing.T) {
|
||||
@@ -665,10 +665,10 @@ func TestCountEntries_NoRetrieverNeeded(t *testing.T) {
|
||||
require.NotNil(t, b)
|
||||
|
||||
// No retriever set — CountEntries succeeds without master key.
|
||||
results, err := b.CountEntries([]types.Category{types.Password})
|
||||
results, err := b.CountEntries([]category.Category{category.Password})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
assert.Equal(t, 2, results[0].Counts[types.Password])
|
||||
assert.Equal(t, 2, results[0].Counts[category.Password])
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -2,38 +2,33 @@ package chromium
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
||||
func extractBookmarks(path string) ([]record.Bookmark, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var bookmarks []types.BookmarkEntry
|
||||
var bookmarks []record.Bookmark
|
||||
roots := gjson.GetBytes(data, "roots")
|
||||
roots.ForEach(func(_, value gjson.Result) bool {
|
||||
walkBookmarks(value, "", &bookmarks)
|
||||
return true
|
||||
})
|
||||
|
||||
sort.Slice(bookmarks, func(i, j int) bool {
|
||||
return bookmarks[i].CreatedAt.After(bookmarks[j].CreatedAt)
|
||||
})
|
||||
return bookmarks, nil
|
||||
}
|
||||
|
||||
// walkBookmarks recursively traverses the bookmark tree, collecting URL entries.
|
||||
func walkBookmarks(node gjson.Result, folder string, out *[]types.BookmarkEntry) {
|
||||
func walkBookmarks(node gjson.Result, folder string, out *[]record.Bookmark) {
|
||||
nodeType := node.Get("type").String()
|
||||
if nodeType == "url" {
|
||||
*out = append(*out, types.BookmarkEntry{
|
||||
*out = append(*out, record.Bookmark{
|
||||
ID: node.Get("id").Int(),
|
||||
Name: node.Get("name").String(),
|
||||
Type: nodeType,
|
||||
|
||||
@@ -43,18 +43,18 @@ func TestExtractBookmarks(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 3)
|
||||
|
||||
// Verify sort order: date added descending (newest first)
|
||||
assert.Equal(t, "GitHub", got[0].Name)
|
||||
assert.Equal(t, "Go", got[1].Name)
|
||||
assert.Equal(t, "HN", got[2].Name)
|
||||
// Bookmarks keep the tree's order; the exporter sorts them.
|
||||
assert.Equal(t, "Go", got[0].Name)
|
||||
assert.Equal(t, "HN", got[1].Name)
|
||||
assert.Equal(t, "GitHub", got[2].Name)
|
||||
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "https://github.com", got[0].URL)
|
||||
assert.Equal(t, "Other", got[0].Folder)
|
||||
assert.Equal(t, "https://github.com", got[2].URL)
|
||||
assert.Equal(t, "Other", got[2].Folder)
|
||||
|
||||
// Verify nested folder tracking
|
||||
assert.Equal(t, "https://news.ycombinator.com", got[2].URL)
|
||||
assert.Equal(t, "News", got[2].Folder) // parent folder name
|
||||
assert.Equal(t, "https://news.ycombinator.com", got[1].URL)
|
||||
assert.Equal(t, "News", got[1].Folder) // parent folder name
|
||||
}
|
||||
|
||||
func TestCountBookmarks(t *testing.T) {
|
||||
|
||||
@@ -4,12 +4,11 @@ import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,9 +18,9 @@ const (
|
||||
countCookieQuery = `SELECT COUNT(*) FROM cookies`
|
||||
)
|
||||
|
||||
func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.CookieEntry, error) {
|
||||
func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]record.Cookie, error) {
|
||||
cookies, err := sqlitex.QueryRows(path, false, defaultCookieQuery,
|
||||
func(rows *sql.Rows) (types.CookieEntry, error) {
|
||||
func(rows *sql.Rows) (record.Cookie, error) {
|
||||
var (
|
||||
name, host, cookiePath string
|
||||
isSecure, isHTTPOnly int
|
||||
@@ -33,7 +32,7 @@ func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.Cooki
|
||||
if err := rows.Scan(&name, &encryptedValue, &host, &cookiePath,
|
||||
&createdAt, &expireAt, &isSecure, &isHTTPOnly,
|
||||
&hasExpire, &isPersistent, &sameSite); err != nil {
|
||||
return types.CookieEntry{}, err
|
||||
return record.Cookie{}, err
|
||||
}
|
||||
|
||||
value, _ := decryptValue(masterKeys, encryptedValue)
|
||||
@@ -49,7 +48,7 @@ func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.Cooki
|
||||
case -1:
|
||||
// not specified by Set-Cookie
|
||||
}
|
||||
return types.CookieEntry{
|
||||
return record.Cookie{
|
||||
Name: name,
|
||||
Host: host,
|
||||
Path: cookiePath,
|
||||
@@ -66,10 +65,6 @@ func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.Cooki
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(cookies, func(i, j int) bool {
|
||||
return cookies[i].CreatedAt.After(cookies[j].CreatedAt)
|
||||
})
|
||||
return cookies, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,20 +25,20 @@ func TestExtractCookies(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
// Verify sort order: creation time descending (newest first)
|
||||
assert.Equal(t, ".new.com", got[0].Host)
|
||||
assert.Equal(t, ".old.com", got[1].Host)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, ".old.com", got[0].Host)
|
||||
assert.Equal(t, ".new.com", got[1].Host)
|
||||
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "token", got[0].Name)
|
||||
assert.Equal(t, "/api", got[0].Path)
|
||||
assert.True(t, got[0].IsSecure)
|
||||
assert.False(t, got[0].IsHTTPOnly)
|
||||
assert.True(t, got[0].HasExpire)
|
||||
assert.True(t, got[0].IsPersistent)
|
||||
assert.False(t, got[0].CreatedAt.IsZero())
|
||||
assert.True(t, got[0].ExpireAt.After(got[0].CreatedAt))
|
||||
assert.True(t, got[1].IsHTTPOnly)
|
||||
assert.Equal(t, "token", got[1].Name)
|
||||
assert.Equal(t, "/api", got[1].Path)
|
||||
assert.True(t, got[1].IsSecure)
|
||||
assert.False(t, got[1].IsHTTPOnly)
|
||||
assert.True(t, got[1].HasExpire)
|
||||
assert.True(t, got[1].IsPersistent)
|
||||
assert.False(t, got[1].CreatedAt.IsZero())
|
||||
assert.True(t, got[1].ExpireAt.After(got[1].CreatedAt))
|
||||
assert.True(t, got[0].IsHTTPOnly)
|
||||
}
|
||||
|
||||
func TestCountCookies(t *testing.T) {
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,16 +36,16 @@ type yandexPrivateData struct {
|
||||
SecretComment string `json:"secret_comment"`
|
||||
}
|
||||
|
||||
func extractCreditCards(masterKeys masterkey.MasterKeys, path string) ([]types.CreditCardEntry, error) {
|
||||
func extractCreditCards(masterKeys masterkey.MasterKeys, path string) ([]record.CreditCard, error) {
|
||||
cards, err := sqlitex.QueryRows(path, false, defaultCreditCardQuery,
|
||||
func(rows *sql.Rows) (types.CreditCardEntry, error) {
|
||||
func(rows *sql.Rows) (record.CreditCard, error) {
|
||||
var guid, name, month, year, nickname, address string
|
||||
var encNumber []byte
|
||||
if err := rows.Scan(&guid, &name, &month, &year, &encNumber, &nickname, &address); err != nil {
|
||||
return types.CreditCardEntry{}, err
|
||||
return record.CreditCard{}, err
|
||||
}
|
||||
number, _ := decryptValue(masterKeys, encNumber)
|
||||
return types.CreditCardEntry{
|
||||
return record.CreditCard{
|
||||
GUID: guid,
|
||||
Name: name,
|
||||
Number: string(number),
|
||||
@@ -62,7 +62,7 @@ func extractCreditCards(masterKeys masterkey.MasterKeys, path string) ([]types.C
|
||||
}
|
||||
|
||||
// extractYandexCreditCards reads the records table (not Chromium's credit_cards). AAD = guid.
|
||||
func extractYandexCreditCards(masterKeys masterkey.MasterKeys, path string) ([]types.CreditCardEntry, error) {
|
||||
func extractYandexCreditCards(masterKeys masterkey.MasterKeys, path string) ([]record.CreditCard, error) {
|
||||
dataKey, err := loadYandexDataKey(path, masterKeys.V10)
|
||||
if err != nil {
|
||||
if errors.Is(err, errYandexMasterPasswordSet) {
|
||||
@@ -73,11 +73,11 @@ func extractYandexCreditCards(masterKeys masterkey.MasterKeys, path string) ([]t
|
||||
}
|
||||
|
||||
return sqlitex.QueryRows(path, false, yandexCreditCardQuery,
|
||||
func(rows *sql.Rows) (types.CreditCardEntry, error) {
|
||||
func(rows *sql.Rows) (record.CreditCard, error) {
|
||||
var guid, publicData string
|
||||
var privateData []byte
|
||||
if err := rows.Scan(&guid, &publicData, &privateData); err != nil {
|
||||
return types.CreditCardEntry{}, err
|
||||
return record.CreditCard{}, err
|
||||
}
|
||||
|
||||
var public yandexPublicData
|
||||
@@ -86,7 +86,7 @@ func extractYandexCreditCards(masterKeys masterkey.MasterKeys, path string) ([]t
|
||||
log.Debugf("yandex: parse public_data for %s: %v", guid, err)
|
||||
}
|
||||
}
|
||||
entry := types.CreditCardEntry{
|
||||
entry := record.CreditCard{
|
||||
GUID: guid,
|
||||
Name: public.CardHolder,
|
||||
ExpMonth: public.ExpireDateMonth,
|
||||
|
||||
@@ -2,11 +2,10 @@ package chromium
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,15 +14,15 @@ const (
|
||||
countDownloadQuery = `SELECT COUNT(*) FROM downloads`
|
||||
)
|
||||
|
||||
func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
func extractDownloads(path string) ([]record.Download, error) {
|
||||
downloads, err := sqlitex.QueryRows(path, false, defaultDownloadQuery,
|
||||
func(rows *sql.Rows) (types.DownloadEntry, error) {
|
||||
func(rows *sql.Rows) (record.Download, error) {
|
||||
var targetPath, url, mimeType string
|
||||
var totalBytes, startTime, endTime int64
|
||||
if err := rows.Scan(&targetPath, &url, &totalBytes, &startTime, &endTime, &mimeType); err != nil {
|
||||
return types.DownloadEntry{}, err
|
||||
return record.Download{}, err
|
||||
}
|
||||
return types.DownloadEntry{
|
||||
return record.Download{
|
||||
URL: url,
|
||||
TargetPath: targetPath,
|
||||
MimeType: mimeType,
|
||||
@@ -35,10 +34,6 @@ func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(downloads, func(i, j int) bool {
|
||||
return downloads[i].StartTime.After(downloads[j].StartTime)
|
||||
})
|
||||
return downloads, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,17 @@ func TestExtractDownloads(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
// Verify sort order: start time descending (newest first)
|
||||
assert.Equal(t, "https://new.com/doc.pdf", got[0].URL)
|
||||
assert.Equal(t, "https://old.com/file.zip", got[1].URL)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, "https://old.com/file.zip", got[0].URL)
|
||||
assert.Equal(t, "https://new.com/doc.pdf", got[1].URL)
|
||||
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "/tmp/new.pdf", got[0].TargetPath)
|
||||
assert.Equal(t, "application/pdf", got[0].MimeType)
|
||||
assert.Equal(t, int64(2048), got[0].TotalBytes)
|
||||
assert.False(t, got[0].StartTime.IsZero())
|
||||
assert.False(t, got[0].EndTime.IsZero())
|
||||
assert.True(t, got[0].StartTime.Before(got[0].EndTime))
|
||||
assert.Equal(t, "/tmp/new.pdf", got[1].TargetPath)
|
||||
assert.Equal(t, "application/pdf", got[1].MimeType)
|
||||
assert.Equal(t, int64(2048), got[1].TotalBytes)
|
||||
assert.False(t, got[1].StartTime.IsZero())
|
||||
assert.False(t, got[1].EndTime.IsZero())
|
||||
assert.True(t, got[1].StartTime.Before(got[1].EndTime))
|
||||
}
|
||||
|
||||
func TestCountDownloads(t *testing.T) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
// defaultExtensionKeys are the JSON paths tried for standard Chromium browsers.
|
||||
@@ -16,14 +16,14 @@ var defaultExtensionKeys = []string{
|
||||
"settings.settings",
|
||||
}
|
||||
|
||||
func extractExtensions(path string) ([]types.ExtensionEntry, error) {
|
||||
func extractExtensions(path string) ([]record.Extension, error) {
|
||||
return extractExtensionsWithKeys(path, defaultExtensionKeys)
|
||||
}
|
||||
|
||||
// extractExtensionsWithKeys reads Secure Preferences and looks for extension
|
||||
// settings under the given JSON key paths. This allows browser variants
|
||||
// (e.g. Opera with "extensions.opsettings") to reuse the same parsing logic.
|
||||
func extractExtensionsWithKeys(path string, keys []string) ([]types.ExtensionEntry, error) {
|
||||
func extractExtensionsWithKeys(path string, keys []string) ([]record.Extension, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -40,7 +40,7 @@ func extractExtensionsWithKeys(path string, keys []string) ([]types.ExtensionEnt
|
||||
return nil, fmt.Errorf("cannot find extensions in settings")
|
||||
}
|
||||
|
||||
var extensions []types.ExtensionEntry
|
||||
var extensions []record.Extension
|
||||
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
|
||||
@@ -54,7 +54,7 @@ func extractExtensionsWithKeys(path string, keys []string) ([]types.ExtensionEnt
|
||||
return true
|
||||
}
|
||||
|
||||
extensions = append(extensions, types.ExtensionEntry{
|
||||
extensions = append(extensions, record.Extension{
|
||||
Name: manifest.Get("name").String(),
|
||||
ID: id.String(),
|
||||
Description: manifest.Get("description").String(),
|
||||
@@ -82,7 +82,7 @@ func isExtensionEnabled(ext gjson.Result) bool {
|
||||
// extractOperaExtensions extracts extensions from Opera's Secure Preferences,
|
||||
// which stores extension data under "extensions.opsettings" instead of the
|
||||
// standard "extensions.settings".
|
||||
func extractOperaExtensions(path string) ([]types.ExtensionEntry, error) {
|
||||
func extractOperaExtensions(path string) ([]record.Extension, error) {
|
||||
return extractExtensionsWithKeys(path, []string{"extensions.opsettings"})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@ package chromium
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -14,16 +13,16 @@ const (
|
||||
countHistoryQuery = `SELECT COUNT(*) FROM urls`
|
||||
)
|
||||
|
||||
func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
func extractHistories(path string) ([]record.History, error) {
|
||||
histories, err := sqlitex.QueryRows(path, false, defaultHistoryQuery,
|
||||
func(rows *sql.Rows) (types.HistoryEntry, error) {
|
||||
func(rows *sql.Rows) (record.History, error) {
|
||||
var url, title string
|
||||
var visitCount int
|
||||
var lastVisit int64
|
||||
if err := rows.Scan(&url, &title, &visitCount, &lastVisit); err != nil {
|
||||
return types.HistoryEntry{}, err
|
||||
return record.History{}, err
|
||||
}
|
||||
return types.HistoryEntry{
|
||||
return record.History{
|
||||
URL: url,
|
||||
Title: title,
|
||||
VisitCount: visitCount,
|
||||
@@ -33,10 +32,6 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(histories, func(i, j int) bool {
|
||||
return histories[i].VisitCount > histories[j].VisitCount
|
||||
})
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ func TestExtractHistories(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 3)
|
||||
|
||||
// Verify sort order: visit count descending
|
||||
assert.Equal(t, 200, got[0].VisitCount)
|
||||
assert.Equal(t, 100, got[1].VisitCount)
|
||||
assert.Equal(t, 50, got[2].VisitCount)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, 100, got[0].VisitCount)
|
||||
assert.Equal(t, 50, got[1].VisitCount)
|
||||
assert.Equal(t, 200, got[2].VisitCount)
|
||||
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "https://example.com", got[0].URL)
|
||||
assert.Equal(t, "Example", got[0].Title)
|
||||
assert.False(t, got[0].LastVisit.IsZero())
|
||||
assert.Equal(t, "https://example.com", got[2].URL)
|
||||
assert.Equal(t, "Example", got[2].Title)
|
||||
assert.False(t, got[2].LastVisit.IsZero())
|
||||
}
|
||||
|
||||
func TestCountHistories(t *testing.T) {
|
||||
|
||||
@@ -3,14 +3,13 @@ package chromium
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,33 +23,29 @@ const (
|
||||
|
||||
// appendPasswords merges another login DB into dst. Entries are kept even when an identical
|
||||
// credential already exists — the Store field records which DB each one came from.
|
||||
func appendPasswords(masterKeys masterkey.MasterKeys, path, store string, dst []types.LoginEntry) ([]types.LoginEntry, error) {
|
||||
func appendPasswords(masterKeys masterkey.MasterKeys, path string, store record.Store, dst []record.Login) ([]record.Login, error) {
|
||||
logins, err := extractPasswords(masterKeys, path, store)
|
||||
if err != nil {
|
||||
return dst, err
|
||||
}
|
||||
dst = append(dst, logins...)
|
||||
sort.SliceStable(dst, func(i, j int) bool {
|
||||
return dst[i].CreatedAt.After(dst[j].CreatedAt)
|
||||
})
|
||||
return dst, nil
|
||||
return append(dst, logins...), nil
|
||||
}
|
||||
|
||||
func extractPasswords(masterKeys masterkey.MasterKeys, path, store string) ([]types.LoginEntry, error) {
|
||||
func extractPasswords(masterKeys masterkey.MasterKeys, path string, store record.Store) ([]record.Login, error) {
|
||||
return extractPasswordsWithQuery(masterKeys, path, store, defaultLoginQuery)
|
||||
}
|
||||
|
||||
func extractPasswordsWithQuery(masterKeys masterkey.MasterKeys, path, store, query string) ([]types.LoginEntry, error) {
|
||||
func extractPasswordsWithQuery(masterKeys masterkey.MasterKeys, path string, store record.Store, query string) ([]record.Login, error) {
|
||||
logins, err := sqlitex.QueryRows(path, false, query,
|
||||
func(rows *sql.Rows) (types.LoginEntry, error) {
|
||||
func(rows *sql.Rows) (record.Login, error) {
|
||||
var url, username string
|
||||
var pwd []byte
|
||||
var created int64
|
||||
if err := rows.Scan(&url, &username, &pwd, &created); err != nil {
|
||||
return types.LoginEntry{}, err
|
||||
return record.Login{}, err
|
||||
}
|
||||
password, _ := decryptValue(masterKeys, pwd)
|
||||
return types.LoginEntry{
|
||||
return record.Login{
|
||||
URL: url,
|
||||
Username: username,
|
||||
Password: string(password),
|
||||
@@ -61,16 +56,12 @@ func extractPasswordsWithQuery(masterKeys masterkey.MasterKeys, path, store, que
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(logins, func(i, j int) bool {
|
||||
return logins[i].CreatedAt.After(logins[j].CreatedAt)
|
||||
})
|
||||
return logins, nil
|
||||
}
|
||||
|
||||
// extractYandexPasswords walks Ya Passman Data.
|
||||
// Note: URL column is origin_url — it's what the per-row AAD is computed over (not action_url).
|
||||
func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]types.LoginEntry, error) {
|
||||
func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]record.Login, error) {
|
||||
dataKey, err := loadYandexDataKey(path, masterKeys.V10)
|
||||
if err != nil {
|
||||
if errors.Is(err, errYandexMasterPasswordSet) {
|
||||
@@ -81,18 +72,18 @@ func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]typ
|
||||
}
|
||||
|
||||
logins, err := sqlitex.QueryRows(path, false, yandexLoginQuery,
|
||||
func(rows *sql.Rows) (types.LoginEntry, error) {
|
||||
func(rows *sql.Rows) (record.Login, error) {
|
||||
var originURL, usernameElem, usernameVal, passwordElem, signonRealm string
|
||||
var passwordValue []byte
|
||||
var created int64
|
||||
if err := rows.Scan(&originURL, &usernameElem, &usernameVal, &passwordElem, &passwordValue, &signonRealm, &created); err != nil {
|
||||
return types.LoginEntry{}, err
|
||||
return record.Login{}, err
|
||||
}
|
||||
entry := types.LoginEntry{
|
||||
entry := record.Login{
|
||||
URL: originURL,
|
||||
Username: usernameVal,
|
||||
CreatedAt: timeconv.Chromium(created),
|
||||
Store: types.PasswordStoreLocal,
|
||||
Store: record.StoreLocal,
|
||||
}
|
||||
aad := yandexLoginAAD(originURL, usernameElem, usernameVal, passwordElem, signonRealm, nil)
|
||||
plaintext, err := crypto.AESGCMDecryptBlob(dataKey, passwordValue, aad)
|
||||
@@ -106,10 +97,6 @@ func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]typ
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(logins, func(i, j int) bool {
|
||||
return logins[i].CreatedAt.After(logins[j].CreatedAt)
|
||||
})
|
||||
return logins, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
func setupLoginDB(t *testing.T) string {
|
||||
@@ -23,20 +23,20 @@ func setupLoginDB(t *testing.T) string {
|
||||
func TestExtractPasswords(t *testing.T) {
|
||||
path := setupLoginDB(t)
|
||||
|
||||
got, err := extractPasswords(masterkey.MasterKeys{}, path, types.PasswordStoreLocal)
|
||||
got, err := extractPasswords(masterkey.MasterKeys{}, path, record.StoreLocal)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
// Verify sort order: date created descending (newest first)
|
||||
assert.Equal(t, "https://new.com", got[0].URL)
|
||||
assert.Equal(t, "https://old.com", got[1].URL)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, "https://old.com", got[0].URL)
|
||||
assert.Equal(t, "https://new.com", got[1].URL)
|
||||
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "bob", got[0].Username)
|
||||
assert.False(t, got[0].CreatedAt.IsZero())
|
||||
assert.Equal(t, "bob", got[1].Username)
|
||||
assert.False(t, got[1].CreatedAt.IsZero())
|
||||
// Password is empty because masterKey is nil (decrypt returns empty)
|
||||
assert.Empty(t, got[0].Password)
|
||||
assert.Equal(t, types.PasswordStoreLocal, got[0].Store)
|
||||
assert.Empty(t, got[1].Password)
|
||||
assert.Equal(t, record.StoreLocal, got[1].Store)
|
||||
}
|
||||
|
||||
// A credential whose blob cannot be decrypted must still be reported, otherwise a missing
|
||||
@@ -46,13 +46,13 @@ func TestExtractPasswords_UndecryptableBlobStillListed(t *testing.T) {
|
||||
insertLogin("https://enc.com", "https://enc.com/login", "carol", "763130deadbeef", 13350000000000000),
|
||||
)
|
||||
|
||||
got, err := extractPasswords(masterkey.MasterKeys{}, path, types.PasswordStoreAccount)
|
||||
got, err := extractPasswords(masterkey.MasterKeys{}, path, record.StoreAccount)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
|
||||
assert.Equal(t, "carol", got[0].Username)
|
||||
assert.Empty(t, got[0].Password)
|
||||
assert.Equal(t, types.PasswordStoreAccount, got[0].Store)
|
||||
assert.Equal(t, record.StoreAccount, got[0].Store)
|
||||
}
|
||||
|
||||
func TestCountPasswords(t *testing.T) {
|
||||
@@ -92,11 +92,11 @@ func TestExtractYandexPasswords(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
// Sorted newest-first on CreatedAt.
|
||||
assert.Equal(t, "https://new.yandex.ru", got[0].URL)
|
||||
assert.Equal(t, "bob", got[0].Username)
|
||||
assert.Equal(t, "sesame", got[0].Password)
|
||||
assert.Equal(t, "hunter2", got[1].Password)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, "https://new.yandex.ru", got[1].URL)
|
||||
assert.Equal(t, "bob", got[1].Username)
|
||||
assert.Equal(t, "sesame", got[1].Password)
|
||||
assert.Equal(t, "hunter2", got[0].Password)
|
||||
}
|
||||
|
||||
func TestExtractYandexPasswords_MasterPasswordSkipped(t *testing.T) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
// Chromium localStorage LevelDB key prefixes and string format bytes.
|
||||
@@ -26,7 +26,7 @@ const (
|
||||
|
||||
const maxLocalStorageValueLength = 2048
|
||||
|
||||
func extractLocalStorage(path string) ([]types.StorageEntry, error) {
|
||||
func extractLocalStorage(path string) ([]record.LocalStorage, error) {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
return nil, fmt.Errorf("leveldb path %q: %w", path, err)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func extractLocalStorage(path string) ([]types.StorageEntry, error) {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
var entries []types.StorageEntry
|
||||
var entries []record.LocalStorage
|
||||
iter := db.NewIterator(nil, nil)
|
||||
defer iter.Release()
|
||||
|
||||
@@ -52,18 +52,18 @@ func extractLocalStorage(path string) ([]types.StorageEntry, error) {
|
||||
|
||||
// parseLocalStorageEntry classifies a LevelDB key/value pair and decodes it.
|
||||
// Returns false for VERSION entries and any unrecognized keys. META entries are kept with IsMeta=true.
|
||||
func parseLocalStorageEntry(key, value []byte) (types.StorageEntry, bool) {
|
||||
func parseLocalStorageEntry(key, value []byte) (record.LocalStorage, bool) {
|
||||
switch {
|
||||
case bytes.Equal(key, []byte(localStorageVersionKey)):
|
||||
return types.StorageEntry{}, false
|
||||
return record.LocalStorage{}, false
|
||||
case bytes.HasPrefix(key, []byte(localStorageMetaAccessKey)):
|
||||
return types.StorageEntry{
|
||||
return record.LocalStorage{
|
||||
IsMeta: true,
|
||||
URL: string(bytes.TrimPrefix(key, []byte(localStorageMetaAccessKey))),
|
||||
Value: fmt.Sprintf("meta data, value bytes is %v", value),
|
||||
}, true
|
||||
case bytes.HasPrefix(key, []byte(localStorageMetaPrefix)):
|
||||
return types.StorageEntry{
|
||||
return record.LocalStorage{
|
||||
IsMeta: true,
|
||||
URL: string(bytes.TrimPrefix(key, []byte(localStorageMetaPrefix))),
|
||||
Value: fmt.Sprintf("meta data, value bytes is %v", value),
|
||||
@@ -71,13 +71,13 @@ func parseLocalStorageEntry(key, value []byte) (types.StorageEntry, bool) {
|
||||
case len(key) > 0 && key[0] == localStorageDataPrefix:
|
||||
return parseLocalStorageDataEntry(key[1:], value), true
|
||||
default:
|
||||
return types.StorageEntry{}, false
|
||||
return record.LocalStorage{}, false
|
||||
}
|
||||
}
|
||||
|
||||
// parseLocalStorageDataEntry decodes a data entry with format: origin\x00<encoded-key>.
|
||||
func parseLocalStorageDataEntry(key, value []byte) types.StorageEntry {
|
||||
entry := types.StorageEntry{
|
||||
func parseLocalStorageDataEntry(key, value []byte) record.LocalStorage {
|
||||
entry := record.LocalStorage{
|
||||
Value: decodeLocalStorageValue(value),
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func decodeLocalStorageValue(value []byte) string {
|
||||
// namespace-<guid>-<origin> → <map_id> (origin mapping)
|
||||
// map-<map_id>-<key_name> → <value> (actual data, UTF-16 LE)
|
||||
// next-map-id / version (metadata, skipped)
|
||||
func extractSessionStorage(path string) ([]types.StorageEntry, error) {
|
||||
func extractSessionStorage(path string) ([]record.SessionStorage, error) {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
return nil, fmt.Errorf("leveldb path %q: %w", path, err)
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func extractSessionStorage(path string) ([]types.StorageEntry, error) {
|
||||
}
|
||||
|
||||
// Pass 2: read map entries and resolve origins.
|
||||
var entries []types.StorageEntry
|
||||
var entries []record.SessionStorage
|
||||
iter2 := db.NewIterator(nil, nil)
|
||||
defer iter2.Release()
|
||||
|
||||
@@ -216,7 +216,7 @@ func extractSessionStorage(path string) ([]types.StorageEntry, error) {
|
||||
}
|
||||
|
||||
value := decodeSessionStorageValue(iter2.Value())
|
||||
entries = append(entries, types.StorageEntry{
|
||||
entries = append(entries, record.SessionStorage{
|
||||
URL: origin,
|
||||
Key: keyName,
|
||||
Value: value,
|
||||
|
||||
+39
-37
@@ -5,7 +5,9 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -16,8 +18,8 @@ type profile struct {
|
||||
profileDir string
|
||||
browserName string
|
||||
kind types.BrowserKind
|
||||
extractors map[types.Category]categoryExtractor
|
||||
sourcePaths map[types.Category]resolvedPath
|
||||
extractors map[category.Category]categoryExtractor
|
||||
sourcePaths map[category.Category]resolvedPath
|
||||
}
|
||||
|
||||
func (p *profile) name() string {
|
||||
@@ -31,7 +33,7 @@ func (p *profile) label() string { return p.browserName + "/" + p.name() }
|
||||
|
||||
// extract copies the profile's source files to a temp directory and extracts the
|
||||
// requested categories, decrypting with the installation's master keys.
|
||||
func (p *profile) extract(masterKeys masterkey.MasterKeys, categories []types.Category) *types.BrowserData {
|
||||
func (p *profile) extract(masterKeys masterkey.MasterKeys, categories []category.Category) *types.BrowserData {
|
||||
session, err := filemanager.NewSession()
|
||||
if err != nil {
|
||||
log.Debugf("new session for %s: %v", p.label(), err)
|
||||
@@ -49,7 +51,7 @@ func (p *profile) extract(masterKeys masterkey.MasterKeys, categories []types.Ca
|
||||
p.extractCategory(data, cat, masterKeys, path)
|
||||
}
|
||||
if accountDB, ok := p.acquireAccountPasswords(session, categories); ok {
|
||||
passwords, err := appendPasswords(masterKeys, accountDB, types.PasswordStoreAccount, data.Passwords)
|
||||
passwords, err := appendPasswords(masterKeys, accountDB, record.StoreAccount, data.Passwords)
|
||||
if err != nil {
|
||||
log.Debugf("extract account passwords for %s: %v", p.label(), err)
|
||||
} else {
|
||||
@@ -60,7 +62,7 @@ func (p *profile) extract(masterKeys masterkey.MasterKeys, categories []types.Ca
|
||||
}
|
||||
|
||||
// count counts entries per category without decryption.
|
||||
func (p *profile) count(categories []types.Category) map[types.Category]int {
|
||||
func (p *profile) count(categories []category.Category) map[category.Category]int {
|
||||
session, err := filemanager.NewSession()
|
||||
if err != nil {
|
||||
log.Debugf("new session for %s: %v", p.label(), err)
|
||||
@@ -69,7 +71,7 @@ func (p *profile) count(categories []types.Category) map[types.Category]int {
|
||||
defer session.Cleanup()
|
||||
|
||||
tempPaths := p.acquireFiles(session, categories)
|
||||
counts := make(map[types.Category]int)
|
||||
counts := make(map[category.Category]int)
|
||||
for _, cat := range categories {
|
||||
path, ok := tempPaths[cat]
|
||||
if !ok {
|
||||
@@ -81,7 +83,7 @@ func (p *profile) count(categories []types.Category) map[types.Category]int {
|
||||
if count, err := countPasswords(accountDB); err != nil {
|
||||
log.Debugf("count account passwords for %s: %v", p.label(), err)
|
||||
} else {
|
||||
counts[types.Password] += count
|
||||
counts[category.Password] += count
|
||||
}
|
||||
}
|
||||
return counts
|
||||
@@ -89,7 +91,7 @@ func (p *profile) count(categories []types.Category) map[types.Category]int {
|
||||
|
||||
// acquireAccountPasswords copies the account-synced password DB into the session, when the
|
||||
// profile has one alongside the local DB.
|
||||
func (p *profile) acquireAccountPasswords(session *filemanager.Session, categories []types.Category) (string, bool) {
|
||||
func (p *profile) acquireAccountPasswords(session *filemanager.Session, categories []category.Category) (string, bool) {
|
||||
accountPath, ok := p.accountPasswordPath(categories)
|
||||
if !ok {
|
||||
return "", false
|
||||
@@ -104,24 +106,24 @@ func (p *profile) acquireAccountPasswords(session *filemanager.Session, categori
|
||||
|
||||
// primaryPasswordStore labels the resolved primary login DB: a profile that only ever synced
|
||||
// passwords has no local Login Data, so the account DB wins candidate resolution.
|
||||
func (p *profile) primaryPasswordStore() string {
|
||||
if primary, ok := p.sourcePaths[types.Password]; ok && primary.rel == accountLoginData {
|
||||
return types.PasswordStoreAccount
|
||||
func (p *profile) primaryPasswordStore() record.Store {
|
||||
if primary, ok := p.sourcePaths[category.Password]; ok && primary.rel == accountLoginData {
|
||||
return record.StoreAccount
|
||||
}
|
||||
return types.PasswordStoreLocal
|
||||
return record.StoreLocal
|
||||
}
|
||||
|
||||
// accountPasswordPath returns the account-synced password DB when the primary source resolved to
|
||||
// the local Login Data DB. If only Login Data For Account exists, it is already the primary source.
|
||||
func (p *profile) accountPasswordPath(categories []types.Category) (string, bool) {
|
||||
func (p *profile) accountPasswordPath(categories []category.Category) (string, bool) {
|
||||
requested := false
|
||||
for _, cat := range categories {
|
||||
if cat == types.Password {
|
||||
if cat == category.Password {
|
||||
requested = true
|
||||
break
|
||||
}
|
||||
}
|
||||
primary, ok := p.sourcePaths[types.Password]
|
||||
primary, ok := p.sourcePaths[category.Password]
|
||||
if !requested || !ok || primary.rel == accountLoginData || p.kind == types.ChromiumYandex {
|
||||
return "", false
|
||||
}
|
||||
@@ -131,8 +133,8 @@ func (p *profile) accountPasswordPath(categories []types.Category) (string, bool
|
||||
}
|
||||
|
||||
// acquireFiles copies source files to the session temp directory.
|
||||
func (p *profile) acquireFiles(session *filemanager.Session, categories []types.Category) map[types.Category]string {
|
||||
tempPaths := make(map[types.Category]string)
|
||||
func (p *profile) acquireFiles(session *filemanager.Session, categories []category.Category) map[category.Category]string {
|
||||
tempPaths := make(map[category.Category]string)
|
||||
for _, cat := range categories {
|
||||
rp, ok := p.sourcePaths[cat]
|
||||
if !ok {
|
||||
@@ -150,7 +152,7 @@ func (p *profile) acquireFiles(session *filemanager.Session, categories []types.
|
||||
|
||||
// extractCategory calls the appropriate extract function for a category. A custom
|
||||
// extractor (registered via extractorsForKind) takes precedence over the switch.
|
||||
func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, masterKeys masterkey.MasterKeys, path string) {
|
||||
func (p *profile) extractCategory(data *types.BrowserData, cat category.Category, masterKeys masterkey.MasterKeys, path string) {
|
||||
if ext, ok := p.extractors[cat]; ok {
|
||||
if err := ext.extract(masterKeys, path, data); err != nil {
|
||||
log.Debugf("extract %s for %s: %v", cat, p.label(), err)
|
||||
@@ -160,23 +162,23 @@ func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, m
|
||||
|
||||
var err error
|
||||
switch cat {
|
||||
case types.Password:
|
||||
case category.Password:
|
||||
data.Passwords, err = extractPasswords(masterKeys, path, p.primaryPasswordStore())
|
||||
case types.Cookie:
|
||||
case category.Cookie:
|
||||
data.Cookies, err = extractCookies(masterKeys, path)
|
||||
case types.History:
|
||||
case category.History:
|
||||
data.Histories, err = extractHistories(path)
|
||||
case types.Download:
|
||||
case category.Download:
|
||||
data.Downloads, err = extractDownloads(path)
|
||||
case types.Bookmark:
|
||||
case category.Bookmark:
|
||||
data.Bookmarks, err = extractBookmarks(path)
|
||||
case types.CreditCard:
|
||||
case category.CreditCard:
|
||||
data.CreditCards, err = extractCreditCards(masterKeys, path)
|
||||
case types.Extension:
|
||||
case category.Extension:
|
||||
data.Extensions, err = extractExtensions(path)
|
||||
case types.LocalStorage:
|
||||
case category.LocalStorage:
|
||||
data.LocalStorage, err = extractLocalStorage(path)
|
||||
case types.SessionStorage:
|
||||
case category.SessionStorage:
|
||||
data.SessionStorage, err = extractSessionStorage(path)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -185,35 +187,35 @@ func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, m
|
||||
}
|
||||
|
||||
// countCategory calls the appropriate count function for a category.
|
||||
func (p *profile) countCategory(cat types.Category, path string) int {
|
||||
func (p *profile) countCategory(cat category.Category, path string) int {
|
||||
var count int
|
||||
var err error
|
||||
switch cat {
|
||||
case types.Password:
|
||||
case category.Password:
|
||||
count, err = countPasswords(path)
|
||||
case types.Cookie:
|
||||
case category.Cookie:
|
||||
count, err = countCookies(path)
|
||||
case types.History:
|
||||
case category.History:
|
||||
count, err = countHistories(path)
|
||||
case types.Download:
|
||||
case category.Download:
|
||||
count, err = countDownloads(path)
|
||||
case types.Bookmark:
|
||||
case category.Bookmark:
|
||||
count, err = countBookmarks(path)
|
||||
case types.CreditCard:
|
||||
case category.CreditCard:
|
||||
if p.kind == types.ChromiumYandex {
|
||||
count, err = countYandexCreditCards(path)
|
||||
} else {
|
||||
count, err = countCreditCards(path)
|
||||
}
|
||||
case types.Extension:
|
||||
case category.Extension:
|
||||
if p.kind == types.ChromiumOpera {
|
||||
count, err = countOperaExtensions(path)
|
||||
} else {
|
||||
count, err = countExtensions(path)
|
||||
}
|
||||
case types.LocalStorage:
|
||||
case category.LocalStorage:
|
||||
count, err = countLocalStorage(path)
|
||||
case types.SessionStorage:
|
||||
case category.SessionStorage:
|
||||
count, err = countSessionStorage(path)
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -33,20 +35,20 @@ func TestExtractCategory_CustomExtractor(t *testing.T) {
|
||||
// Create a profile with a custom extractor that records it was called
|
||||
called := false
|
||||
testExtractor := extensionExtractor{
|
||||
fn: func(path string) ([]types.ExtensionEntry, error) {
|
||||
fn: func(path string) ([]record.Extension, error) {
|
||||
called = true
|
||||
return []types.ExtensionEntry{{Name: "custom", ID: "test-id"}}, nil
|
||||
return []record.Extension{{Name: "custom", ID: "test-id"}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
p := &profile{
|
||||
extractors: map[types.Category]categoryExtractor{
|
||||
types.Extension: testExtractor,
|
||||
extractors: map[category.Category]categoryExtractor{
|
||||
category.Extension: testExtractor,
|
||||
},
|
||||
}
|
||||
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.Extension, masterkey.MasterKeys{}, "unused-path")
|
||||
p.extractCategory(data, category.Extension, masterkey.MasterKeys{}, "unused-path")
|
||||
|
||||
assert.True(t, called, "custom extractor should be called")
|
||||
require.Len(t, data.Extensions, 1)
|
||||
@@ -65,7 +67,7 @@ func TestExtractCategory_DefaultFallback(t *testing.T) {
|
||||
}
|
||||
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.History, masterkey.MasterKeys{}, path)
|
||||
p.extractCategory(data, category.History, masterkey.MasterKeys{}, path)
|
||||
|
||||
require.Len(t, data.Histories, 1)
|
||||
assert.Equal(t, "Example", data.Histories[0].Title)
|
||||
@@ -85,7 +87,7 @@ func TestAcquireFiles(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer session.Cleanup()
|
||||
|
||||
cats := []types.Category{types.History, types.Cookie, types.Bookmark}
|
||||
cats := []category.Category{category.History, category.Cookie, category.Bookmark}
|
||||
paths := p.acquireFiles(session, cats)
|
||||
|
||||
assert.Len(t, paths, len(cats))
|
||||
@@ -109,13 +111,14 @@ func TestExtractAndCountPasswords_MergesLocalAndAccountDatabases(t *testing.T) {
|
||||
kind: types.Chromium,
|
||||
sourcePaths: resolveSourcePaths(chromiumSources, profileDir),
|
||||
}
|
||||
data := p.extract(masterkey.MasterKeys{}, []types.Category{types.Password})
|
||||
data := p.extract(masterkey.MasterKeys{}, []category.Category{category.Password})
|
||||
require.Len(t, data.Passwords, 2)
|
||||
assert.Equal(t, "account-user", data.Passwords[0].Username)
|
||||
assert.Equal(t, types.PasswordStoreAccount, data.Passwords[0].Store)
|
||||
assert.Equal(t, "local-user", data.Passwords[1].Username)
|
||||
assert.Equal(t, types.PasswordStoreLocal, data.Passwords[1].Store)
|
||||
assert.Equal(t, 2, p.count([]types.Category{types.Password})[types.Password])
|
||||
// Account rows are emitted after local ones; the exporter's stable sort relies on that when timestamps tie.
|
||||
assert.Equal(t, "local-user", data.Passwords[0].Username)
|
||||
assert.Equal(t, record.StoreLocal, data.Passwords[0].Store)
|
||||
assert.Equal(t, "account-user", data.Passwords[1].Username)
|
||||
assert.Equal(t, record.StoreAccount, data.Passwords[1].Store)
|
||||
assert.Equal(t, 2, p.count([]category.Category{category.Password})[category.Password])
|
||||
}
|
||||
|
||||
// A credential synced to both stores is reported twice; the Store field is what tells them
|
||||
@@ -133,12 +136,12 @@ func TestExtractPasswords_IdenticalCredentialInBothStoresKeepsBoth(t *testing.T)
|
||||
kind: types.Chromium,
|
||||
sourcePaths: resolveSourcePaths(chromiumSources, profileDir),
|
||||
}
|
||||
data := p.extract(masterkey.MasterKeys{}, []types.Category{types.Password})
|
||||
data := p.extract(masterkey.MasterKeys{}, []category.Category{category.Password})
|
||||
|
||||
require.Len(t, data.Passwords, 2)
|
||||
stores := []string{data.Passwords[0].Store, data.Passwords[1].Store}
|
||||
assert.ElementsMatch(t, []string{types.PasswordStoreLocal, types.PasswordStoreAccount}, stores)
|
||||
assert.Equal(t, 2, p.count([]types.Category{types.Password})[types.Password])
|
||||
stores := []record.Store{data.Passwords[0].Store, data.Passwords[1].Store}
|
||||
assert.ElementsMatch(t, []record.Store{record.StoreLocal, record.StoreAccount}, stores)
|
||||
assert.Equal(t, 2, p.count([]category.Category{category.Password})[category.Password])
|
||||
}
|
||||
|
||||
// A profile that only ever synced passwords has no local DB, so the account DB wins candidate
|
||||
@@ -155,31 +158,31 @@ func TestExtractAndCountPasswords_AccountDatabaseOnly(t *testing.T) {
|
||||
kind: types.Chromium,
|
||||
sourcePaths: resolveSourcePaths(chromiumSources, profileDir),
|
||||
}
|
||||
data := p.extract(masterkey.MasterKeys{}, []types.Category{types.Password})
|
||||
data := p.extract(masterkey.MasterKeys{}, []category.Category{category.Password})
|
||||
|
||||
require.Len(t, data.Passwords, 1)
|
||||
assert.Equal(t, "account-user", data.Passwords[0].Username)
|
||||
assert.Equal(t, types.PasswordStoreAccount, data.Passwords[0].Store)
|
||||
assert.Equal(t, 1, p.count([]types.Category{types.Password})[types.Password])
|
||||
assert.Equal(t, record.StoreAccount, data.Passwords[0].Store)
|
||||
assert.Equal(t, 1, p.count([]category.Category{category.Password})[category.Password])
|
||||
}
|
||||
|
||||
func TestCountCategory(t *testing.T) {
|
||||
t.Run("History", func(t *testing.T) {
|
||||
path := setupHistoryDB(t)
|
||||
p := &profile{kind: types.Chromium}
|
||||
assert.Equal(t, 3, p.countCategory(types.History, path))
|
||||
assert.Equal(t, 3, p.countCategory(category.History, path))
|
||||
})
|
||||
|
||||
t.Run("Cookie", func(t *testing.T) {
|
||||
path := setupCookieDB(t)
|
||||
p := &profile{kind: types.Chromium}
|
||||
assert.Equal(t, 2, p.countCategory(types.Cookie, path))
|
||||
assert.Equal(t, 2, p.countCategory(category.Cookie, path))
|
||||
})
|
||||
|
||||
t.Run("Bookmark", func(t *testing.T) {
|
||||
path := setupBookmarkJSON(t)
|
||||
p := &profile{kind: types.Chromium}
|
||||
assert.Equal(t, 3, p.countCategory(types.Bookmark, path))
|
||||
assert.Equal(t, 3, p.countCategory(category.Bookmark, path))
|
||||
})
|
||||
|
||||
t.Run("Extension_Opera", func(t *testing.T) {
|
||||
@@ -191,11 +194,11 @@ func TestCountCategory(t *testing.T) {
|
||||
}
|
||||
}`)
|
||||
p := &profile{kind: types.ChromiumOpera}
|
||||
assert.Equal(t, 1, p.countCategory(types.Extension, path))
|
||||
assert.Equal(t, 1, p.countCategory(category.Extension, path))
|
||||
})
|
||||
|
||||
t.Run("FileNotFound", func(t *testing.T) {
|
||||
p := &profile{kind: types.Chromium}
|
||||
assert.Equal(t, 0, p.countCategory(types.History, "/nonexistent/path"))
|
||||
assert.Equal(t, 0, p.countCategory(category.History, "/nonexistent/path"))
|
||||
})
|
||||
}
|
||||
+19
-17
@@ -1,6 +1,8 @@
|
||||
package chromium
|
||||
|
||||
import (
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -20,20 +22,20 @@ func dir(rel string) sourcePath { return sourcePath{rel: rel, isDir: true} }
|
||||
// chromiumSources defines the standard Chromium file layout.
|
||||
// Each category maps to one or more candidate paths tried in priority order;
|
||||
// the first existing path wins.
|
||||
var chromiumSources = map[types.Category][]sourcePath{
|
||||
types.Password: {file("Login Data"), file(accountLoginData)},
|
||||
types.Cookie: {file("Network/Cookies"), file("Cookies")},
|
||||
types.History: {file("History")},
|
||||
types.Download: {file("History")},
|
||||
types.Bookmark: {file("Bookmarks")},
|
||||
types.CreditCard: {file("Web Data")},
|
||||
types.Extension: {file("Secure Preferences")},
|
||||
types.LocalStorage: {dir("Local Storage/leveldb")},
|
||||
types.SessionStorage: {dir("Session Storage")},
|
||||
var chromiumSources = map[category.Category][]sourcePath{
|
||||
category.Password: {file("Login Data"), file(accountLoginData)},
|
||||
category.Cookie: {file("Network/Cookies"), file("Cookies")},
|
||||
category.History: {file("History")},
|
||||
category.Download: {file("History")},
|
||||
category.Bookmark: {file("Bookmarks")},
|
||||
category.CreditCard: {file("Web Data")},
|
||||
category.Extension: {file("Secure Preferences")},
|
||||
category.LocalStorage: {dir("Local Storage/leveldb")},
|
||||
category.SessionStorage: {dir("Session Storage")},
|
||||
}
|
||||
|
||||
// sourcesForKind returns the source mapping for a browser kind.
|
||||
func sourcesForKind(kind types.BrowserKind) map[types.Category][]sourcePath {
|
||||
func sourcesForKind(kind types.BrowserKind) map[category.Category][]sourcePath {
|
||||
switch kind {
|
||||
case types.ChromiumYandex:
|
||||
return yandexSources()
|
||||
@@ -56,7 +58,7 @@ type categoryExtractor interface {
|
||||
|
||||
// passwordExtractor wraps a custom password extract function.
|
||||
type passwordExtractor struct {
|
||||
fn func(masterKeys masterkey.MasterKeys, path string) ([]types.LoginEntry, error)
|
||||
fn func(masterKeys masterkey.MasterKeys, path string) ([]record.Login, error)
|
||||
}
|
||||
|
||||
func (e passwordExtractor) extract(masterKeys masterkey.MasterKeys, path string, data *types.BrowserData) error {
|
||||
@@ -67,7 +69,7 @@ func (e passwordExtractor) extract(masterKeys masterkey.MasterKeys, path string,
|
||||
|
||||
// extensionExtractor wraps a custom extension extract function.
|
||||
type extensionExtractor struct {
|
||||
fn func(path string) ([]types.ExtensionEntry, error)
|
||||
fn func(path string) ([]record.Extension, error)
|
||||
}
|
||||
|
||||
func (e extensionExtractor) extract(_ masterkey.MasterKeys, path string, data *types.BrowserData) error {
|
||||
@@ -79,7 +81,7 @@ func (e extensionExtractor) extract(_ masterkey.MasterKeys, path string, data *t
|
||||
// creditCardExtractor wraps a custom credit-card extract function, used by Yandex whose Ya Credit Cards DB stores
|
||||
// rows as records(guid, public_data, private_data) with JSON blobs rather than Chromium's flat credit_cards table.
|
||||
type creditCardExtractor struct {
|
||||
fn func(masterKeys masterkey.MasterKeys, path string) ([]types.CreditCardEntry, error)
|
||||
fn func(masterKeys masterkey.MasterKeys, path string) ([]record.CreditCard, error)
|
||||
}
|
||||
|
||||
func (e creditCardExtractor) extract(masterKeys masterkey.MasterKeys, path string, data *types.BrowserData) error {
|
||||
@@ -90,13 +92,13 @@ func (e creditCardExtractor) extract(masterKeys masterkey.MasterKeys, path strin
|
||||
|
||||
// operaExtractors overrides Extension extraction for Opera,
|
||||
// which stores settings under "extensions.opsettings".
|
||||
var operaExtractors = map[types.Category]categoryExtractor{
|
||||
types.Extension: extensionExtractor{fn: extractOperaExtensions},
|
||||
var operaExtractors = map[category.Category]categoryExtractor{
|
||||
category.Extension: extensionExtractor{fn: extractOperaExtensions},
|
||||
}
|
||||
|
||||
// extractorsForKind returns custom category extractors for a browser kind.
|
||||
// nil means all categories use the default extractCategory switch logic.
|
||||
func extractorsForKind(kind types.BrowserKind) map[types.Category]categoryExtractor {
|
||||
func extractorsForKind(kind types.BrowserKind) map[category.Category]categoryExtractor {
|
||||
switch kind {
|
||||
case types.ChromiumYandex:
|
||||
return yandexExtractors
|
||||
|
||||
@@ -11,18 +11,18 @@ import (
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
)
|
||||
|
||||
// yandexSourceOverrides contains only the entries that differ from chromiumSources.
|
||||
var yandexSourceOverrides = map[types.Category][]sourcePath{
|
||||
types.Password: {file("Ya Passman Data")},
|
||||
types.CreditCard: {file("Ya Credit Cards")},
|
||||
var yandexSourceOverrides = map[category.Category][]sourcePath{
|
||||
category.Password: {file("Ya Passman Data")},
|
||||
category.CreditCard: {file("Ya Credit Cards")},
|
||||
}
|
||||
|
||||
// yandexSources returns chromiumSources with Yandex-specific overrides applied.
|
||||
func yandexSources() map[types.Category][]sourcePath {
|
||||
sources := make(map[types.Category][]sourcePath, len(chromiumSources))
|
||||
func yandexSources() map[category.Category][]sourcePath {
|
||||
sources := make(map[category.Category][]sourcePath, len(chromiumSources))
|
||||
for k, v := range chromiumSources {
|
||||
sources[k] = v
|
||||
}
|
||||
@@ -34,9 +34,9 @@ func yandexSources() map[types.Category][]sourcePath {
|
||||
|
||||
// yandexExtractors overrides Password and CreditCard extraction for Yandex, which wraps its data-encryption key inside
|
||||
// meta.local_encryptor_data, binds per-row AAD to GCM, and stores cards as JSON blobs in a records table.
|
||||
var yandexExtractors = map[types.Category]categoryExtractor{
|
||||
types.Password: passwordExtractor{fn: extractYandexPasswords},
|
||||
types.CreditCard: creditCardExtractor{fn: extractYandexCreditCards},
|
||||
var yandexExtractors = map[category.Category]categoryExtractor{
|
||||
category.Password: passwordExtractor{fn: extractYandexPasswords},
|
||||
category.CreditCard: creditCardExtractor{fn: extractYandexCreditCards},
|
||||
}
|
||||
|
||||
// yandexLoginAAD is SHA1(origin_url \x00 username_element \x00 username_value \x00 password_element \x00 signon_realm),
|
||||
|
||||
@@ -2,11 +2,10 @@ package firefox
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -16,16 +15,16 @@ const (
|
||||
INNER JOIN moz_places ON moz_bookmarks.fk=moz_places.id`
|
||||
)
|
||||
|
||||
func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
||||
func extractBookmarks(path string) ([]record.Bookmark, error) {
|
||||
bookmarks, err := sqlitex.QueryRows(path, true, firefoxBookmarkQuery,
|
||||
func(rows *sql.Rows) (types.BookmarkEntry, error) {
|
||||
func(rows *sql.Rows) (record.Bookmark, error) {
|
||||
var id, dateAdded int64
|
||||
var url, title string
|
||||
var bt int64
|
||||
if err := rows.Scan(&id, &url, &bt, &dateAdded, &title); err != nil {
|
||||
return types.BookmarkEntry{}, err
|
||||
return record.Bookmark{}, err
|
||||
}
|
||||
return types.BookmarkEntry{
|
||||
return record.Bookmark{
|
||||
Name: title,
|
||||
URL: url,
|
||||
Folder: bookmarkType(bt),
|
||||
@@ -35,10 +34,6 @@ func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(bookmarks, func(i, j int) bool {
|
||||
return bookmarks[i].CreatedAt.After(bookmarks[j].CreatedAt)
|
||||
})
|
||||
return bookmarks, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@ func TestExtractBookmarks(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
// Verify sort order: dateAdded descending
|
||||
assert.Equal(t, "GitHub", got[0].Name)
|
||||
assert.Equal(t, "Go Website", got[1].Name)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, "Go Website", got[0].Name)
|
||||
assert.Equal(t, "GitHub", got[1].Name)
|
||||
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "https://github.com", got[0].URL)
|
||||
assert.Equal(t, "url", got[0].Folder) // type=1 → "url"
|
||||
assert.False(t, got[0].CreatedAt.IsZero())
|
||||
assert.Equal(t, "https://github.com", got[1].URL)
|
||||
assert.Equal(t, "url", got[1].Folder) // type=1 → "url"
|
||||
assert.False(t, got[1].CreatedAt.IsZero())
|
||||
}
|
||||
|
||||
func TestCountBookmarks(t *testing.T) {
|
||||
|
||||
@@ -2,11 +2,10 @@ package firefox
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,9 +14,9 @@ const (
|
||||
firefoxCountCookieQuery = `SELECT COUNT(*) FROM moz_cookies`
|
||||
)
|
||||
|
||||
func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
func extractCookies(path string) ([]record.Cookie, error) {
|
||||
cookies, err := sqlitex.QueryRows(path, true, firefoxCookieQuery,
|
||||
func(rows *sql.Rows) (types.CookieEntry, error) {
|
||||
func(rows *sql.Rows) (record.Cookie, error) {
|
||||
var (
|
||||
name, value, host, cookiePath string
|
||||
isSecure, isHTTPOnly int
|
||||
@@ -26,7 +25,7 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
)
|
||||
if err := rows.Scan(&name, &value, &host, &cookiePath,
|
||||
&createdAt, &expiry, &isSecure, &isHTTPOnly, &sameSite); err != nil {
|
||||
return types.CookieEntry{}, err
|
||||
return record.Cookie{}, err
|
||||
}
|
||||
hasExpire := expiry > 0
|
||||
sameSiteStr := "unspecified"
|
||||
@@ -40,7 +39,7 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
case 256:
|
||||
// not specified by Set-Cookie
|
||||
}
|
||||
return types.CookieEntry{
|
||||
return record.Cookie{
|
||||
Name: name,
|
||||
Host: host,
|
||||
Path: cookiePath,
|
||||
@@ -57,10 +56,6 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(cookies, func(i, j int) bool {
|
||||
return cookies[i].CreatedAt.After(cookies[j].CreatedAt)
|
||||
})
|
||||
return cookies, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -22,21 +22,21 @@ func TestExtractCookies(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
// Verify sort order: creation time descending
|
||||
assert.Equal(t, ".new.com", got[0].Host)
|
||||
assert.Equal(t, ".example.com", got[1].Host)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, ".example.com", got[0].Host)
|
||||
assert.Equal(t, ".new.com", got[1].Host)
|
||||
|
||||
// Verify field mapping — Firefox cookies are plaintext
|
||||
assert.Equal(t, "token", got[0].Name)
|
||||
assert.Equal(t, "xyz789", got[0].Value)
|
||||
assert.Equal(t, "/api", got[0].Path)
|
||||
assert.True(t, got[0].IsSecure)
|
||||
assert.False(t, got[0].IsHTTPOnly)
|
||||
assert.True(t, got[0].HasExpire) // expiry > 0
|
||||
assert.True(t, got[0].IsPersistent) // expiry > 0
|
||||
assert.Equal(t, "token", got[1].Name)
|
||||
assert.Equal(t, "xyz789", got[1].Value)
|
||||
assert.Equal(t, "/api", got[1].Path)
|
||||
assert.True(t, got[1].IsSecure)
|
||||
assert.False(t, got[1].IsHTTPOnly)
|
||||
assert.True(t, got[1].HasExpire) // expiry > 0
|
||||
assert.True(t, got[1].IsPersistent) // expiry > 0
|
||||
|
||||
assert.Equal(t, "abc123", got[1].Value)
|
||||
assert.True(t, got[1].IsHTTPOnly)
|
||||
assert.Equal(t, "abc123", got[0].Value)
|
||||
assert.True(t, got[0].IsHTTPOnly)
|
||||
}
|
||||
|
||||
func TestCountCookies(t *testing.T) {
|
||||
|
||||
@@ -2,14 +2,13 @@ package firefox
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,16 +21,16 @@ const (
|
||||
GROUP BY place_id)`
|
||||
)
|
||||
|
||||
func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
func extractDownloads(path string) ([]record.Download, error) {
|
||||
downloads, err := sqlitex.QueryRows(path, true, firefoxDownloadQuery,
|
||||
func(rows *sql.Rows) (types.DownloadEntry, error) {
|
||||
func(rows *sql.Rows) (record.Download, error) {
|
||||
var placeID, dateAdded int64
|
||||
var content, url string
|
||||
if err := rows.Scan(&placeID, &content, &url, &dateAdded); err != nil {
|
||||
return types.DownloadEntry{}, err
|
||||
return record.Download{}, err
|
||||
}
|
||||
|
||||
entry := types.DownloadEntry{
|
||||
entry := record.Download{
|
||||
URL: url,
|
||||
StartTime: timeconv.UnixMicro(dateAdded),
|
||||
}
|
||||
@@ -53,10 +52,6 @@ func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(downloads, func(i, j int) bool {
|
||||
return downloads[i].StartTime.After(downloads[j].StartTime)
|
||||
})
|
||||
return downloads, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ func TestExtractDownloads(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
// Verify sort order: StartTime descending
|
||||
assert.Equal(t, "https://example.com/new.pdf", got[0].URL)
|
||||
assert.Equal(t, "https://example.com/old.zip", got[1].URL)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, "https://example.com/old.zip", got[0].URL)
|
||||
assert.Equal(t, "https://example.com/new.pdf", got[1].URL)
|
||||
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "/tmp/new.pdf", got[0].TargetPath)
|
||||
assert.False(t, got[0].StartTime.IsZero())
|
||||
assert.Equal(t, "/tmp/new.pdf", got[1].TargetPath)
|
||||
assert.False(t, got[1].StartTime.IsZero())
|
||||
}
|
||||
|
||||
func TestCountDownloads(t *testing.T) {
|
||||
|
||||
@@ -5,16 +5,16 @@ import (
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
func extractExtensions(path string) ([]types.ExtensionEntry, error) {
|
||||
func extractExtensions(path string) ([]record.Extension, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var extensions []types.ExtensionEntry
|
||||
var extensions []record.Extension
|
||||
for _, v := range gjson.GetBytes(data, "addons").Array() {
|
||||
// Only include user-installed extensions
|
||||
// https://searchfox.org/mozilla-central/source/toolkit/mozapps/extensions/internal/XPIDatabase.jsm#157
|
||||
@@ -22,7 +22,7 @@ func extractExtensions(path string) ([]types.ExtensionEntry, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
extensions = append(extensions, types.ExtensionEntry{
|
||||
extensions = append(extensions, record.Extension{
|
||||
Name: v.Get("defaultLocale.name").String(),
|
||||
ID: v.Get("id").String(),
|
||||
Description: v.Get("defaultLocale.description").String(),
|
||||
|
||||
@@ -2,11 +2,10 @@ package firefox
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,16 +14,16 @@ const (
|
||||
firefoxCountHistoryQuery = `SELECT COUNT(*) FROM moz_places`
|
||||
)
|
||||
|
||||
func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
func extractHistories(path string) ([]record.History, error) {
|
||||
histories, err := sqlitex.QueryRows(path, true, firefoxHistoryQuery,
|
||||
func(rows *sql.Rows) (types.HistoryEntry, error) {
|
||||
func(rows *sql.Rows) (record.History, error) {
|
||||
var url, title string
|
||||
var visitCount int
|
||||
var lastVisit int64
|
||||
if err := rows.Scan(&url, &lastVisit, &title, &visitCount); err != nil {
|
||||
return types.HistoryEntry{}, err
|
||||
return record.History{}, err
|
||||
}
|
||||
return types.HistoryEntry{
|
||||
return record.History{
|
||||
URL: url,
|
||||
Title: title,
|
||||
VisitCount: visitCount,
|
||||
@@ -34,10 +33,6 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(histories, func(i, j int) bool {
|
||||
return histories[i].VisitCount < histories[j].VisitCount
|
||||
})
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ func TestExtractHistories(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 3)
|
||||
|
||||
// Verify sort order: visit count ascending (Firefox convention)
|
||||
assert.Equal(t, 50, got[0].VisitCount)
|
||||
assert.Equal(t, 100, got[1].VisitCount)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, 100, got[0].VisitCount)
|
||||
assert.Equal(t, 50, got[1].VisitCount)
|
||||
assert.Equal(t, 200, got[2].VisitCount)
|
||||
|
||||
// Verify field mapping (first = least visited)
|
||||
assert.Equal(t, "https://go.dev", got[0].URL)
|
||||
assert.Equal(t, "Go", got[0].Title)
|
||||
assert.False(t, got[0].LastVisit.IsZero())
|
||||
// Verify field mapping
|
||||
assert.Equal(t, "https://go.dev", got[1].URL)
|
||||
assert.Equal(t, "Go", got[1].Title)
|
||||
assert.False(t, got[1].LastVisit.IsZero())
|
||||
}
|
||||
|
||||
func TestCountHistories(t *testing.T) {
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
func countPasswords(path string) (int, error) {
|
||||
@@ -39,13 +38,13 @@ func decryptPBE(encoded string, masterKey []byte) ([]byte, error) {
|
||||
return plaintext, nil
|
||||
}
|
||||
|
||||
func extractPasswords(masterKey []byte, path string) ([]types.LoginEntry, error) {
|
||||
func extractPasswords(masterKey []byte, path string) ([]record.Login, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var logins []types.LoginEntry
|
||||
var logins []record.Login
|
||||
var decryptFails int
|
||||
var lastErr error
|
||||
for _, v := range gjson.GetBytes(data, "logins").Array() {
|
||||
@@ -65,20 +64,16 @@ func extractPasswords(masterKey []byte, path string) ([]types.LoginEntry, error)
|
||||
lastErr = err
|
||||
}
|
||||
|
||||
logins = append(logins, types.LoginEntry{
|
||||
logins = append(logins, record.Login{
|
||||
URL: url,
|
||||
Username: string(user),
|
||||
Password: string(pwd),
|
||||
CreatedAt: timeconv.UnixMilli(v.Get("timeCreated").Int()),
|
||||
Store: types.PasswordStoreLocal,
|
||||
Store: record.StoreLocal,
|
||||
})
|
||||
}
|
||||
if decryptFails > 0 {
|
||||
log.Debugf("decrypt firefox login fields: %d failed: %v", decryptFails, lastErr)
|
||||
}
|
||||
|
||||
sort.Slice(logins, func(i, j int) bool {
|
||||
return logins[i].CreatedAt.After(logins[j].CreatedAt)
|
||||
})
|
||||
return logins, nil
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -14,14 +14,14 @@ const (
|
||||
firefoxCountLocalStorageQuery = `SELECT COUNT(*) FROM webappsstore2`
|
||||
)
|
||||
|
||||
func extractLocalStorage(path string) ([]types.StorageEntry, error) {
|
||||
func extractLocalStorage(path string) ([]record.LocalStorage, error) {
|
||||
return sqlitex.QueryRows(path, true, firefoxLocalStorageQuery,
|
||||
func(rows *sql.Rows) (types.StorageEntry, error) {
|
||||
func(rows *sql.Rows) (record.LocalStorage, error) {
|
||||
var originKey, key, value string
|
||||
if err := rows.Scan(&originKey, &key, &value); err != nil {
|
||||
return types.StorageEntry{}, err
|
||||
return record.LocalStorage{}, err
|
||||
}
|
||||
return types.StorageEntry{
|
||||
return record.LocalStorage{
|
||||
URL: parseOriginKey(originKey),
|
||||
Key: key,
|
||||
Value: value,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -53,7 +54,7 @@ func (b *Browser) Profiles() []types.Profile {
|
||||
}
|
||||
|
||||
// Extract extracts every profile, deriving each profile's key independently.
|
||||
func (b *Browser) Extract(categories []types.Category) ([]types.ExtractResult, error) {
|
||||
func (b *Browser) Extract(categories []category.Category) ([]types.ExtractResult, error) {
|
||||
results := make([]types.ExtractResult, 0, len(b.profiles))
|
||||
for _, p := range b.profiles {
|
||||
results = append(results, types.ExtractResult{
|
||||
@@ -65,7 +66,7 @@ func (b *Browser) Extract(categories []types.Category) ([]types.ExtractResult, e
|
||||
}
|
||||
|
||||
// CountEntries counts entries per category for every profile without decryption.
|
||||
func (b *Browser) CountEntries(categories []types.Category) ([]types.CountResult, error) {
|
||||
func (b *Browser) CountEntries(categories []category.Category) ([]types.CountResult, error) {
|
||||
results := make([]types.CountResult, 0, len(b.profiles))
|
||||
for _, p := range b.profiles {
|
||||
results = append(results, types.CountResult{
|
||||
@@ -114,7 +115,7 @@ type resolvedPath struct {
|
||||
|
||||
// discoverProfiles lists subdirectories of userDataDir that contain at least
|
||||
// one known data source. Each such directory is a Firefox profile.
|
||||
func discoverProfiles(userDataDir string, sources map[types.Category][]sourcePath) []string {
|
||||
func discoverProfiles(userDataDir string, sources map[category.Category][]sourcePath) []string {
|
||||
entries, err := os.ReadDir(userDataDir)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -134,7 +135,7 @@ func discoverProfiles(userDataDir string, sources map[types.Category][]sourcePat
|
||||
}
|
||||
|
||||
// hasAnySource checks if dir contains at least one source file or directory.
|
||||
func hasAnySource(sources map[types.Category][]sourcePath, dir string) bool {
|
||||
func hasAnySource(sources map[category.Category][]sourcePath, dir string) bool {
|
||||
for _, candidates := range sources {
|
||||
for _, sp := range candidates {
|
||||
abs := filepath.Join(dir, sp.rel)
|
||||
@@ -148,8 +149,8 @@ func hasAnySource(sources map[types.Category][]sourcePath, dir string) bool {
|
||||
|
||||
// resolveSourcePaths checks which sources actually exist in profileDir.
|
||||
// Candidates are tried in priority order; the first existing path wins.
|
||||
func resolveSourcePaths(sources map[types.Category][]sourcePath, profileDir string) map[types.Category]resolvedPath {
|
||||
resolved := make(map[types.Category]resolvedPath)
|
||||
func resolveSourcePaths(sources map[category.Category][]sourcePath, profileDir string) map[category.Category]resolvedPath {
|
||||
resolved := make(map[category.Category]resolvedPath)
|
||||
for cat, candidates := range sources {
|
||||
for _, sp := range candidates {
|
||||
abs := filepath.Join(profileDir, sp.rel)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -147,19 +148,19 @@ func TestResolveSourcePaths(t *testing.T) {
|
||||
resolved := resolveSourcePaths(firefoxSources, profileDir)
|
||||
|
||||
// All categories should be resolved
|
||||
for _, cat := range []types.Category{
|
||||
types.Password, types.Cookie, types.History,
|
||||
types.Download, types.Bookmark, types.Extension, types.LocalStorage,
|
||||
for _, cat := range []category.Category{
|
||||
category.Password, category.Cookie, category.History,
|
||||
category.Download, category.Bookmark, category.Extension, category.LocalStorage,
|
||||
} {
|
||||
assert.Contains(t, resolved, cat, "should resolve %s", cat)
|
||||
}
|
||||
|
||||
// History, Download, Bookmark share places.sqlite
|
||||
assert.Equal(t, resolved[types.History].absPath, resolved[types.Download].absPath)
|
||||
assert.Equal(t, resolved[types.History].absPath, resolved[types.Bookmark].absPath)
|
||||
assert.Equal(t, resolved[category.History].absPath, resolved[category.Download].absPath)
|
||||
assert.Equal(t, resolved[category.History].absPath, resolved[category.Bookmark].absPath)
|
||||
|
||||
// Password is a different file
|
||||
assert.NotEqual(t, resolved[types.Password].absPath, resolved[types.History].absPath)
|
||||
assert.NotEqual(t, resolved[category.Password].absPath, resolved[category.History].absPath)
|
||||
}
|
||||
|
||||
func TestResolveSourcePaths_Partial(t *testing.T) {
|
||||
@@ -167,14 +168,14 @@ func TestResolveSourcePaths_Partial(t *testing.T) {
|
||||
resolved := resolveSourcePaths(firefoxSources, profileDir)
|
||||
|
||||
// Only places.sqlite exists → History, Download, Bookmark resolved
|
||||
assert.Contains(t, resolved, types.History)
|
||||
assert.Contains(t, resolved, types.Download)
|
||||
assert.Contains(t, resolved, types.Bookmark)
|
||||
assert.Contains(t, resolved, category.History)
|
||||
assert.Contains(t, resolved, category.Download)
|
||||
assert.Contains(t, resolved, category.Bookmark)
|
||||
|
||||
// No logins.json, cookies.sqlite, etc.
|
||||
assert.NotContains(t, resolved, types.Password)
|
||||
assert.NotContains(t, resolved, types.Cookie)
|
||||
assert.NotContains(t, resolved, types.Extension)
|
||||
assert.NotContains(t, resolved, category.Password)
|
||||
assert.NotContains(t, resolved, category.Cookie)
|
||||
assert.NotContains(t, resolved, category.Extension)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -194,8 +195,8 @@ func TestCountEntries(t *testing.T) {
|
||||
require.NotNil(t, b)
|
||||
|
||||
// CountEntries works without master key.
|
||||
results, err := b.CountEntries([]types.Category{types.History})
|
||||
results, err := b.CountEntries([]category.Category{category.History})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
assert.Equal(t, 3, results[0].Counts[types.History])
|
||||
assert.Equal(t, 3, results[0].Counts[category.History])
|
||||
}
|
||||
+27
-26
@@ -5,6 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
type profile struct {
|
||||
profileDir string
|
||||
browserName string
|
||||
sourcePaths map[types.Category]resolvedPath
|
||||
sourcePaths map[category.Category]resolvedPath
|
||||
}
|
||||
|
||||
func (p *profile) name() string {
|
||||
@@ -29,7 +30,7 @@ func (p *profile) label() string { return p.browserName + "/" + p.name() }
|
||||
|
||||
// extract copies the profile's source files to a temp directory, derives the
|
||||
// per-profile master key, and extracts the requested categories.
|
||||
func (p *profile) extract(categories []types.Category) *types.BrowserData {
|
||||
func (p *profile) extract(categories []category.Category) *types.BrowserData {
|
||||
session, err := filemanager.NewSession()
|
||||
if err != nil {
|
||||
log.Debugf("new session for %s: %v", p.label(), err)
|
||||
@@ -55,7 +56,7 @@ func (p *profile) extract(categories []types.Category) *types.BrowserData {
|
||||
return data
|
||||
}
|
||||
|
||||
func (p *profile) count(categories []types.Category) map[types.Category]int {
|
||||
func (p *profile) count(categories []category.Category) map[category.Category]int {
|
||||
session, err := filemanager.NewSession()
|
||||
if err != nil {
|
||||
log.Debugf("new session for %s: %v", p.label(), err)
|
||||
@@ -64,7 +65,7 @@ func (p *profile) count(categories []types.Category) map[types.Category]int {
|
||||
defer session.Cleanup()
|
||||
|
||||
tempPaths := p.acquireFiles(session, categories)
|
||||
counts := make(map[types.Category]int)
|
||||
counts := make(map[category.Category]int)
|
||||
for _, cat := range categories {
|
||||
path, ok := tempPaths[cat]
|
||||
if !ok {
|
||||
@@ -75,8 +76,8 @@ func (p *profile) count(categories []types.Category) map[types.Category]int {
|
||||
return counts
|
||||
}
|
||||
|
||||
func (p *profile) acquireFiles(session *filemanager.Session, categories []types.Category) map[types.Category]string {
|
||||
tempPaths := make(map[types.Category]string)
|
||||
func (p *profile) acquireFiles(session *filemanager.Session, categories []category.Category) map[category.Category]string {
|
||||
tempPaths := make(map[category.Category]string)
|
||||
for _, cat := range categories {
|
||||
rp, ok := p.sourcePaths[cat]
|
||||
if !ok {
|
||||
@@ -96,7 +97,7 @@ func (p *profile) acquireFiles(session *filemanager.Session, categories []types.
|
||||
// key4.db. The key is derived via NSS ASN1 PBE decryption (platform-agnostic).
|
||||
// If logins.json was already acquired by acquireFiles, the derived key is
|
||||
// validated by attempting to decrypt an actual login entry.
|
||||
func (p *profile) getMasterKey(session *filemanager.Session, tempPaths map[types.Category]string) ([]byte, error) {
|
||||
func (p *profile) getMasterKey(session *filemanager.Session, tempPaths map[category.Category]string) ([]byte, error) {
|
||||
key4Src := filepath.Join(p.profileDir, "key4.db")
|
||||
if !fileutil.FileExists(key4Src) {
|
||||
return nil, nil
|
||||
@@ -108,28 +109,28 @@ func (p *profile) getMasterKey(session *filemanager.Session, tempPaths map[types
|
||||
|
||||
// logins.json is already acquired by acquireFiles as the Password source;
|
||||
// reuse it for master key validation if available.
|
||||
loginsPath := tempPaths[types.Password]
|
||||
loginsPath := tempPaths[category.Password]
|
||||
return retrieveMasterKey(key4Dst, loginsPath)
|
||||
}
|
||||
|
||||
func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, masterKey []byte, path string) {
|
||||
func (p *profile) extractCategory(data *types.BrowserData, cat category.Category, masterKey []byte, path string) {
|
||||
var err error
|
||||
switch cat {
|
||||
case types.Password:
|
||||
case category.Password:
|
||||
data.Passwords, err = extractPasswords(masterKey, path)
|
||||
case types.Cookie:
|
||||
case category.Cookie:
|
||||
data.Cookies, err = extractCookies(path)
|
||||
case types.History:
|
||||
case category.History:
|
||||
data.Histories, err = extractHistories(path)
|
||||
case types.Download:
|
||||
case category.Download:
|
||||
data.Downloads, err = extractDownloads(path)
|
||||
case types.Bookmark:
|
||||
case category.Bookmark:
|
||||
data.Bookmarks, err = extractBookmarks(path)
|
||||
case types.Extension:
|
||||
case category.Extension:
|
||||
data.Extensions, err = extractExtensions(path)
|
||||
case types.LocalStorage:
|
||||
case category.LocalStorage:
|
||||
data.LocalStorage, err = extractLocalStorage(path)
|
||||
case types.CreditCard, types.SessionStorage:
|
||||
case category.CreditCard, category.SessionStorage:
|
||||
// Firefox does not support CreditCard or SessionStorage extraction.
|
||||
}
|
||||
if err != nil {
|
||||
@@ -137,25 +138,25 @@ func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, m
|
||||
}
|
||||
}
|
||||
|
||||
func (p *profile) countCategory(cat types.Category, path string) int {
|
||||
func (p *profile) countCategory(cat category.Category, path string) int {
|
||||
var count int
|
||||
var err error
|
||||
switch cat {
|
||||
case types.Password:
|
||||
case category.Password:
|
||||
count, err = countPasswords(path)
|
||||
case types.Cookie:
|
||||
case category.Cookie:
|
||||
count, err = countCookies(path)
|
||||
case types.History:
|
||||
case category.History:
|
||||
count, err = countHistories(path)
|
||||
case types.Download:
|
||||
case category.Download:
|
||||
count, err = countDownloads(path)
|
||||
case types.Bookmark:
|
||||
case category.Bookmark:
|
||||
count, err = countBookmarks(path)
|
||||
case types.Extension:
|
||||
case category.Extension:
|
||||
count, err = countExtensions(path)
|
||||
case types.LocalStorage:
|
||||
case category.LocalStorage:
|
||||
count, err = countLocalStorage(path)
|
||||
case types.CreditCard, types.SessionStorage:
|
||||
case category.CreditCard, category.SessionStorage:
|
||||
// Firefox does not support CreditCard or SessionStorage.
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -13,31 +14,31 @@ func TestCountCategory(t *testing.T) {
|
||||
t.Run("History", func(t *testing.T) {
|
||||
path := setupMozHistoryDB(t)
|
||||
p := &profile{}
|
||||
assert.Equal(t, 3, p.countCategory(types.History, path))
|
||||
assert.Equal(t, 3, p.countCategory(category.History, path))
|
||||
})
|
||||
|
||||
t.Run("Cookie", func(t *testing.T) {
|
||||
path := setupMozCookieDB(t)
|
||||
p := &profile{}
|
||||
assert.Equal(t, 2, p.countCategory(types.Cookie, path))
|
||||
assert.Equal(t, 2, p.countCategory(category.Cookie, path))
|
||||
})
|
||||
|
||||
t.Run("Bookmark", func(t *testing.T) {
|
||||
path := setupMozBookmarkDB(t)
|
||||
p := &profile{}
|
||||
assert.Equal(t, 2, p.countCategory(types.Bookmark, path))
|
||||
assert.Equal(t, 2, p.countCategory(category.Bookmark, path))
|
||||
})
|
||||
|
||||
t.Run("Extension", func(t *testing.T) {
|
||||
path := setupMozExtensionJSON(t)
|
||||
p := &profile{}
|
||||
assert.Equal(t, 2, p.countCategory(types.Extension, path))
|
||||
assert.Equal(t, 2, p.countCategory(category.Extension, path))
|
||||
})
|
||||
|
||||
t.Run("UnsupportedCategory", func(t *testing.T) {
|
||||
p := &profile{}
|
||||
assert.Equal(t, 0, p.countCategory(types.CreditCard, "unused"))
|
||||
assert.Equal(t, 0, p.countCategory(types.SessionStorage, "unused"))
|
||||
assert.Equal(t, 0, p.countCategory(category.CreditCard, "unused"))
|
||||
assert.Equal(t, 0, p.countCategory(category.SessionStorage, "unused"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,12 +56,10 @@ func TestExtractCategory(t *testing.T) {
|
||||
)
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.History, nil, path)
|
||||
p.extractCategory(data, category.History, nil, path)
|
||||
|
||||
require.Len(t, data.Histories, 2)
|
||||
// Firefox sorts by visit count ascending
|
||||
assert.Equal(t, 1, data.Histories[0].VisitCount)
|
||||
assert.Equal(t, 3, data.Histories[1].VisitCount)
|
||||
assert.ElementsMatch(t, []int{3, 1}, []int{data.Histories[0].VisitCount, data.Histories[1].VisitCount})
|
||||
})
|
||||
|
||||
t.Run("Cookie", func(t *testing.T) {
|
||||
@@ -70,7 +69,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
)
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.Cookie, nil, path)
|
||||
p.extractCategory(data, category.Cookie, nil, path)
|
||||
|
||||
require.Len(t, data.Cookies, 1)
|
||||
assert.Equal(t, "session", data.Cookies[0].Name)
|
||||
@@ -85,7 +84,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
)
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.Bookmark, nil, path)
|
||||
p.extractCategory(data, category.Bookmark, nil, path)
|
||||
|
||||
require.Len(t, data.Bookmarks, 1)
|
||||
assert.Equal(t, "GitHub", data.Bookmarks[0].Name)
|
||||
@@ -110,7 +109,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
}`)
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.Extension, nil, path)
|
||||
p.extractCategory(data, category.Extension, nil, path)
|
||||
|
||||
require.Len(t, data.Extensions, 1) // system extension skipped
|
||||
assert.Equal(t, "uBlock Origin", data.Extensions[0].Name)
|
||||
@@ -120,8 +119,8 @@ func TestExtractCategory(t *testing.T) {
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
// CreditCard and SessionStorage are not supported by Firefox
|
||||
p.extractCategory(data, types.CreditCard, nil, "unused")
|
||||
p.extractCategory(data, types.SessionStorage, nil, "unused")
|
||||
p.extractCategory(data, category.CreditCard, nil, "unused")
|
||||
p.extractCategory(data, category.SessionStorage, nil, "unused")
|
||||
assert.Empty(t, data.CreditCards)
|
||||
assert.Empty(t, data.SessionStorage)
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ package firefox
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
)
|
||||
|
||||
// sourcePath describes a single candidate location for browser data,
|
||||
@@ -19,12 +19,12 @@ func file(rel string) sourcePath { return sourcePath{rel: filepath.FromSlash(rel
|
||||
// Each category maps to one or more candidate paths tried in priority order;
|
||||
// the first existing path wins.
|
||||
// Firefox does not support SessionStorage or CreditCard extraction.
|
||||
var firefoxSources = map[types.Category][]sourcePath{
|
||||
types.Password: {file("logins.json")},
|
||||
types.Cookie: {file("cookies.sqlite")},
|
||||
types.History: {file("places.sqlite")},
|
||||
types.Download: {file("places.sqlite")},
|
||||
types.Bookmark: {file("places.sqlite")},
|
||||
types.Extension: {file("extensions.json")},
|
||||
types.LocalStorage: {file("webappsstore.sqlite")},
|
||||
var firefoxSources = map[category.Category][]sourcePath{
|
||||
category.Password: {file("logins.json")},
|
||||
category.Cookie: {file("cookies.sqlite")},
|
||||
category.History: {file("places.sqlite")},
|
||||
category.Download: {file("places.sqlite")},
|
||||
category.Bookmark: {file("places.sqlite")},
|
||||
category.Extension: {file("extensions.json")},
|
||||
category.LocalStorage: {file("webappsstore.sqlite")},
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -37,11 +38,11 @@ func (m *mockBrowser) Profiles() []types.Profile {
|
||||
return out
|
||||
}
|
||||
|
||||
func (m *mockBrowser) Extract(_ []types.Category) ([]types.ExtractResult, error) {
|
||||
func (m *mockBrowser) Extract(_ []category.Category) ([]types.ExtractResult, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockBrowser) CountEntries(_ []types.Category) ([]types.CountResult, error) {
|
||||
func (m *mockBrowser) CountEntries(_ []category.Category) ([]types.CountResult, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/moond4rk/plist"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
// safariBookmark mirrors the plist structure of Safari's Bookmarks.plist.
|
||||
@@ -28,7 +28,7 @@ const (
|
||||
bookmarkTypeList = "WebBookmarkTypeList"
|
||||
)
|
||||
|
||||
func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
||||
func extractBookmarks(path string) ([]record.Bookmark, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open bookmarks: %w", err)
|
||||
@@ -40,13 +40,13 @@ func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
||||
return nil, fmt.Errorf("decode bookmarks: %w", err)
|
||||
}
|
||||
|
||||
var bookmarks []types.BookmarkEntry
|
||||
var bookmarks []record.Bookmark
|
||||
walkBookmarks(root.Children, "", &bookmarks)
|
||||
return bookmarks, nil
|
||||
}
|
||||
|
||||
// walkBookmarks recursively traverses the bookmark tree, collecting leaf entries.
|
||||
func walkBookmarks(nodes []safariBookmark, folder string, out *[]types.BookmarkEntry) {
|
||||
func walkBookmarks(nodes []safariBookmark, folder string, out *[]record.Bookmark) {
|
||||
for i, node := range nodes {
|
||||
switch node.Type {
|
||||
case bookmarkTypeLeaf:
|
||||
@@ -57,7 +57,7 @@ func walkBookmarks(nodes []safariBookmark, folder string, out *[]types.BookmarkE
|
||||
if node.URLString == "" {
|
||||
continue
|
||||
}
|
||||
*out = append(*out, types.BookmarkEntry{
|
||||
*out = append(*out, record.Bookmark{
|
||||
ID: int64(i),
|
||||
Name: title,
|
||||
URL: node.URLString,
|
||||
|
||||
@@ -3,26 +3,25 @@ package safari
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/binarycookies"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
func extractCookies(path string) ([]record.Cookie, error) {
|
||||
pages, err := decodeBinaryCookies(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cookies []types.CookieEntry
|
||||
var cookies []record.Cookie
|
||||
for _, page := range pages {
|
||||
for _, c := range page.Cookies {
|
||||
hasExpire := !c.Expires.IsZero()
|
||||
// binarycookies returns time.Time in Local; normalize to UTC
|
||||
// so exported JSON matches Chromium/Firefox cookie output.
|
||||
cookies = append(cookies, types.CookieEntry{
|
||||
cookies = append(cookies, record.Cookie{
|
||||
Host: string(c.Domain),
|
||||
Path: string(c.Path),
|
||||
Name: string(c.Name),
|
||||
@@ -36,10 +35,6 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(cookies, func(i, j int) bool {
|
||||
return cookies[i].CreatedAt.After(cookies[j].CreatedAt)
|
||||
})
|
||||
return cookies, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -133,12 +133,12 @@ func TestExtractCookies(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, cookies, 2)
|
||||
|
||||
// Sorted by CreatedAt descending (newest first)
|
||||
assert.Equal(t, ".go.dev", cookies[0].Host)
|
||||
assert.Equal(t, ".example.com", cookies[1].Host)
|
||||
// Cookies keep the file's order; the exporter sorts them.
|
||||
assert.Equal(t, ".example.com", cookies[0].Host)
|
||||
assert.Equal(t, ".go.dev", cookies[1].Host)
|
||||
|
||||
// Verify field mapping
|
||||
c := cookies[1] // .example.com cookie
|
||||
c := cookies[0] // .example.com cookie
|
||||
assert.Equal(t, "session", c.Name)
|
||||
assert.Equal(t, "abc123", c.Value)
|
||||
assert.Equal(t, "/", c.Path)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/moond4rk/plist"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
type safariDownloads struct {
|
||||
@@ -25,7 +25,7 @@ type safariDownloadEntry struct {
|
||||
// extractDownloads reads Downloads.plist (shared across Safari profiles) and returns only the entries
|
||||
// owned by ownerUUID — either "DefaultProfile" or a named profile's uppercase UUID. Entries written by
|
||||
// older Safari (no ProfileUUID field) are attributed to the default profile.
|
||||
func extractDownloads(path, ownerUUID string) ([]types.DownloadEntry, error) {
|
||||
func extractDownloads(path, ownerUUID string) ([]record.Download, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open downloads: %w", err)
|
||||
@@ -37,12 +37,12 @@ func extractDownloads(path, ownerUUID string) ([]types.DownloadEntry, error) {
|
||||
return nil, fmt.Errorf("decode downloads: %w", err)
|
||||
}
|
||||
|
||||
var downloads []types.DownloadEntry
|
||||
var downloads []record.Download
|
||||
for _, d := range dl.DownloadHistory {
|
||||
if !ownsDownload(d.ProfileUUID, ownerUUID) {
|
||||
continue
|
||||
}
|
||||
downloads = append(downloads, types.DownloadEntry{
|
||||
downloads = append(downloads, record.Download{
|
||||
URL: d.URL,
|
||||
TargetPath: d.Path,
|
||||
TotalBytes: d.TotalBytes,
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/moond4rk/plist"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
// Safari keeps extensions in two sibling plists under the container's Safari dir:
|
||||
@@ -32,7 +32,7 @@ const (
|
||||
var extensionKeyPattern = regexp.MustCompile(`^(\S+)\s+\(([^)]+)\)$`)
|
||||
|
||||
// safariExtension mirrors the per-extension dict value in Extensions.plist.
|
||||
// Only fields that map onto types.ExtensionEntry are decoded; richer fields
|
||||
// Only fields that map onto record.Extension are decoded; richer fields
|
||||
// (Permissions, AccessibleOrigins, …) are intentionally ignored for the
|
||||
// minimum implementation.
|
||||
type safariExtension struct {
|
||||
@@ -43,15 +43,15 @@ type safariExtension struct {
|
||||
// WebExtensions/Extensions.plist from the profile's Safari container and
|
||||
// returns the merged list, sorted by key for deterministic output.
|
||||
// A missing plist on either side is skipped silently.
|
||||
func extractExtensions(container string) ([]types.ExtensionEntry, error) {
|
||||
func extractExtensions(container string) ([]record.Extension, error) {
|
||||
records, err := readSafariExtensions(container)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extensions := make([]types.ExtensionEntry, 0, len(records))
|
||||
extensions := make([]record.Extension, 0, len(records))
|
||||
for _, r := range records {
|
||||
extensions = append(extensions, types.ExtensionEntry{
|
||||
extensions = append(extensions, record.Extension{
|
||||
Name: r.bundleID,
|
||||
ID: r.key,
|
||||
Enabled: r.enabled,
|
||||
|
||||
@@ -2,11 +2,10 @@ package safari
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,18 +23,18 @@ const (
|
||||
safariCountHistoryQuery = `SELECT COUNT(*) FROM history_items`
|
||||
)
|
||||
|
||||
func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
func extractHistories(path string) ([]record.History, error) {
|
||||
histories, err := sqlitex.QueryRows(path, true, safariHistoryQuery,
|
||||
func(rows *sql.Rows) (types.HistoryEntry, error) {
|
||||
func(rows *sql.Rows) (record.History, error) {
|
||||
var (
|
||||
url, title string
|
||||
visitCount int
|
||||
visitTime float64
|
||||
)
|
||||
if err := rows.Scan(&url, &title, &visitCount, &visitTime); err != nil {
|
||||
return types.HistoryEntry{}, err
|
||||
return record.History{}, err
|
||||
}
|
||||
return types.HistoryEntry{
|
||||
return record.History{
|
||||
URL: url,
|
||||
Title: title,
|
||||
VisitCount: visitCount,
|
||||
@@ -45,10 +44,6 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(histories, func(i, j int) bool {
|
||||
return histories[i].VisitCount > histories[j].VisitCount
|
||||
})
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -29,16 +29,16 @@ func TestExtractHistories(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 3)
|
||||
|
||||
// Sorted by visit count descending (most visited first).
|
||||
assert.Equal(t, 200, got[0].VisitCount)
|
||||
assert.Equal(t, 100, got[1].VisitCount)
|
||||
assert.Equal(t, 50, got[2].VisitCount)
|
||||
// Rows keep the database's order; the exporter sorts them.
|
||||
assert.Equal(t, 100, got[0].VisitCount)
|
||||
assert.Equal(t, 50, got[1].VisitCount)
|
||||
assert.Equal(t, 200, got[2].VisitCount)
|
||||
|
||||
// Verify field mapping.
|
||||
assert.Equal(t, "https://example.com", got[0].URL)
|
||||
assert.Equal(t, "https://github.com", got[1].URL)
|
||||
assert.Equal(t, "https://go.dev", got[2].URL)
|
||||
assert.False(t, got[0].LastVisit.IsZero())
|
||||
assert.Equal(t, "https://github.com", got[0].URL)
|
||||
assert.Equal(t, "https://go.dev", got[1].URL)
|
||||
assert.Equal(t, "https://example.com", got[2].URL)
|
||||
assert.False(t, got[2].LastVisit.IsZero())
|
||||
}
|
||||
|
||||
func TestExtractHistories_Dedup(t *testing.T) {
|
||||
|
||||
@@ -2,39 +2,34 @@ package safari
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/moond4rk/keychainbreaker"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
func extractPasswords(keychainPassword string) ([]types.LoginEntry, error) {
|
||||
func extractPasswords(keychainPassword string) ([]record.Login, error) {
|
||||
passwords, err := getInternetPasswords(keychainPassword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var logins []types.LoginEntry
|
||||
var logins []record.Login
|
||||
for _, p := range passwords {
|
||||
url := buildURL(p.Protocol, p.Server, p.Port, p.Path)
|
||||
if url == "" || p.Account == "" {
|
||||
continue
|
||||
}
|
||||
logins = append(logins, types.LoginEntry{
|
||||
logins = append(logins, record.Login{
|
||||
URL: url,
|
||||
Username: p.Account,
|
||||
Password: p.PlainPassword,
|
||||
CreatedAt: p.Created.UTC(),
|
||||
Store: types.PasswordStoreLocal,
|
||||
Store: record.StoreLocal,
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(logins, func(i, j int) bool {
|
||||
return logins[i].CreatedAt.After(logins[j].CreatedAt)
|
||||
})
|
||||
return logins, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
)
|
||||
|
||||
// Modern WebKit (Safari 17+) stores localStorage under a nested, partitioned layout rooted at
|
||||
@@ -52,13 +52,13 @@ const (
|
||||
originPortExplicitFlag = 0x01
|
||||
)
|
||||
|
||||
func extractLocalStorage(root string) ([]types.StorageEntry, error) {
|
||||
func extractLocalStorage(root string) ([]record.LocalStorage, error) {
|
||||
dirs, err := findOriginDataDirs(root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var entries []types.StorageEntry
|
||||
var entries []record.LocalStorage
|
||||
for _, od := range dirs {
|
||||
origin, err := readOriginFile(filepath.Join(od, webkitOriginFile))
|
||||
if err != nil {
|
||||
@@ -72,7 +72,7 @@ func extractLocalStorage(root string) ([]types.StorageEntry, error) {
|
||||
continue
|
||||
}
|
||||
for _, it := range items {
|
||||
entries = append(entries, types.StorageEntry{
|
||||
entries = append(entries, record.LocalStorage{
|
||||
URL: origin,
|
||||
Key: it.key,
|
||||
Value: it.value,
|
||||
|
||||
+27
-26
@@ -4,6 +4,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
type profile struct {
|
||||
ctx profileContext
|
||||
browserName string
|
||||
sourcePaths map[types.Category]resolvedPath
|
||||
sourcePaths map[category.Category]resolvedPath
|
||||
}
|
||||
|
||||
func (p *profile) name() string { return p.ctx.name }
|
||||
@@ -26,7 +27,7 @@ func (p *profile) dir() string {
|
||||
return filepath.Join(p.ctx.container, "Safari", "Profiles", p.ctx.uuidUpper)
|
||||
}
|
||||
|
||||
func (p *profile) extract(categories []types.Category, keychainPassword string) *types.BrowserData {
|
||||
func (p *profile) extract(categories []category.Category, keychainPassword string) *types.BrowserData {
|
||||
session, err := filemanager.NewSession()
|
||||
if err != nil {
|
||||
log.Debugf("new session for %s: %v", p.label(), err)
|
||||
@@ -39,7 +40,7 @@ func (p *profile) extract(categories []types.Category, keychainPassword string)
|
||||
data := &types.BrowserData{}
|
||||
for _, cat := range categories {
|
||||
// Keychain is user-scope, not per-profile — attribute only to default to avoid duplicates.
|
||||
if cat == types.Password {
|
||||
if cat == category.Password {
|
||||
if p.ctx.isDefault() {
|
||||
p.extractCategory(data, cat, "", keychainPassword)
|
||||
}
|
||||
@@ -47,7 +48,7 @@ func (p *profile) extract(categories []types.Category, keychainPassword string)
|
||||
}
|
||||
// Extension plists (AppExtensions + WebExtensions) live directly in the container
|
||||
// and are read in-place; attribute to default only until per-profile layouts are verified.
|
||||
if cat == types.Extension {
|
||||
if cat == category.Extension {
|
||||
if p.ctx.isDefault() {
|
||||
p.extractCategory(data, cat, "", keychainPassword)
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func (p *profile) extract(categories []types.Category, keychainPassword string)
|
||||
return data
|
||||
}
|
||||
|
||||
func (p *profile) count(categories []types.Category, keychainPassword string) map[types.Category]int {
|
||||
func (p *profile) count(categories []category.Category, keychainPassword string) map[category.Category]int {
|
||||
session, err := filemanager.NewSession()
|
||||
if err != nil {
|
||||
log.Debugf("new session for %s: %v", p.label(), err)
|
||||
@@ -72,15 +73,15 @@ func (p *profile) count(categories []types.Category, keychainPassword string) ma
|
||||
|
||||
tempPaths := p.acquireFiles(session, categories)
|
||||
|
||||
counts := make(map[types.Category]int)
|
||||
counts := make(map[category.Category]int)
|
||||
for _, cat := range categories {
|
||||
if cat == types.Password {
|
||||
if cat == category.Password {
|
||||
if p.ctx.isDefault() {
|
||||
counts[cat] = p.countCategory(cat, "", keychainPassword)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if cat == types.Extension {
|
||||
if cat == category.Extension {
|
||||
if p.ctx.isDefault() {
|
||||
counts[cat] = p.countCategory(cat, "", keychainPassword)
|
||||
}
|
||||
@@ -95,8 +96,8 @@ func (p *profile) count(categories []types.Category, keychainPassword string) ma
|
||||
return counts
|
||||
}
|
||||
|
||||
func (p *profile) acquireFiles(session *filemanager.Session, categories []types.Category) map[types.Category]string {
|
||||
tempPaths := make(map[types.Category]string)
|
||||
func (p *profile) acquireFiles(session *filemanager.Session, categories []category.Category) map[category.Category]string {
|
||||
tempPaths := make(map[category.Category]string)
|
||||
for _, cat := range categories {
|
||||
rp, ok := p.sourcePaths[cat]
|
||||
if !ok {
|
||||
@@ -112,22 +113,22 @@ func (p *profile) acquireFiles(session *filemanager.Session, categories []types.
|
||||
return tempPaths
|
||||
}
|
||||
|
||||
func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, path, keychainPassword string) {
|
||||
func (p *profile) extractCategory(data *types.BrowserData, cat category.Category, path, keychainPassword string) {
|
||||
var err error
|
||||
switch cat {
|
||||
case types.Password:
|
||||
case category.Password:
|
||||
data.Passwords, err = extractPasswords(keychainPassword)
|
||||
case types.History:
|
||||
case category.History:
|
||||
data.Histories, err = extractHistories(path)
|
||||
case types.Cookie:
|
||||
case category.Cookie:
|
||||
data.Cookies, err = extractCookies(path)
|
||||
case types.Bookmark:
|
||||
case category.Bookmark:
|
||||
data.Bookmarks, err = extractBookmarks(path)
|
||||
case types.Download:
|
||||
case category.Download:
|
||||
data.Downloads, err = extractDownloads(path, p.ctx.downloadOwnerUUID())
|
||||
case types.LocalStorage:
|
||||
case category.LocalStorage:
|
||||
data.LocalStorage, err = extractLocalStorage(path)
|
||||
case types.Extension:
|
||||
case category.Extension:
|
||||
data.Extensions, err = extractExtensions(p.ctx.container)
|
||||
default:
|
||||
return
|
||||
@@ -137,23 +138,23 @@ func (p *profile) extractCategory(data *types.BrowserData, cat types.Category, p
|
||||
}
|
||||
}
|
||||
|
||||
func (p *profile) countCategory(cat types.Category, path, keychainPassword string) int {
|
||||
func (p *profile) countCategory(cat category.Category, path, keychainPassword string) int {
|
||||
var count int
|
||||
var err error
|
||||
switch cat {
|
||||
case types.Password:
|
||||
case category.Password:
|
||||
count, err = countPasswords(keychainPassword)
|
||||
case types.History:
|
||||
case category.History:
|
||||
count, err = countHistories(path)
|
||||
case types.Cookie:
|
||||
case category.Cookie:
|
||||
count, err = countCookies(path)
|
||||
case types.Bookmark:
|
||||
case category.Bookmark:
|
||||
count, err = countBookmarks(path)
|
||||
case types.Download:
|
||||
case category.Download:
|
||||
count, err = countDownloads(path, p.ctx.downloadOwnerUUID())
|
||||
case types.LocalStorage:
|
||||
case category.LocalStorage:
|
||||
count, err = countLocalStorage(path)
|
||||
case types.Extension:
|
||||
case category.Extension:
|
||||
count, err = countExtensions(p.ctx.container)
|
||||
default:
|
||||
// Unsupported categories silently return 0.
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -16,7 +17,7 @@ func TestCountCategory(t *testing.T) {
|
||||
insertHistoryItem(1, "https://example.com", "example.com", 1),
|
||||
)
|
||||
p := &profile{}
|
||||
assert.Equal(t, 1, p.countCategory(types.History, path, ""))
|
||||
assert.Equal(t, 1, p.countCategory(category.History, path, ""))
|
||||
})
|
||||
|
||||
t.Run("Cookie", func(t *testing.T) {
|
||||
@@ -25,7 +26,7 @@ func TestCountCategory(t *testing.T) {
|
||||
{domain: ".go.dev", name: "b", path: "/", value: "2", expires: 2000000000.0, creation: 700000000.0},
|
||||
})
|
||||
p := &profile{}
|
||||
assert.Equal(t, 2, p.countCategory(types.Cookie, path, ""))
|
||||
assert.Equal(t, 2, p.countCategory(category.Cookie, path, ""))
|
||||
})
|
||||
|
||||
t.Run("Bookmark", func(t *testing.T) {
|
||||
@@ -37,7 +38,7 @@ func TestCountCategory(t *testing.T) {
|
||||
},
|
||||
})
|
||||
p := &profile{}
|
||||
assert.Equal(t, 2, p.countCategory(types.Bookmark, path, ""))
|
||||
assert.Equal(t, 2, p.countCategory(category.Bookmark, path, ""))
|
||||
})
|
||||
|
||||
t.Run("Download", func(t *testing.T) {
|
||||
@@ -47,7 +48,7 @@ func TestCountCategory(t *testing.T) {
|
||||
},
|
||||
})
|
||||
p := &profile{}
|
||||
assert.Equal(t, 1, p.countCategory(types.Download, path, ""))
|
||||
assert.Equal(t, 1, p.countCategory(category.Download, path, ""))
|
||||
})
|
||||
|
||||
t.Run("LocalStorage", func(t *testing.T) {
|
||||
@@ -56,13 +57,13 @@ func TestCountCategory(t *testing.T) {
|
||||
"https://go.dev": {{Key: "theme", Value: "dark"}},
|
||||
})
|
||||
p := &profile{}
|
||||
assert.Equal(t, 3, p.countCategory(types.LocalStorage, dir, ""))
|
||||
assert.Equal(t, 3, p.countCategory(category.LocalStorage, dir, ""))
|
||||
})
|
||||
|
||||
t.Run("UnsupportedCategory", func(t *testing.T) {
|
||||
p := &profile{}
|
||||
assert.Equal(t, 0, p.countCategory(types.CreditCard, "unused", ""))
|
||||
assert.Equal(t, 0, p.countCategory(types.SessionStorage, "unused", ""))
|
||||
assert.Equal(t, 0, p.countCategory(category.CreditCard, "unused", ""))
|
||||
assert.Equal(t, 0, p.countCategory(category.SessionStorage, "unused", ""))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -77,12 +78,10 @@ func TestExtractCategory(t *testing.T) {
|
||||
)
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.History, path, "")
|
||||
p.extractCategory(data, category.History, path, "")
|
||||
|
||||
require.Len(t, data.Histories, 2)
|
||||
// Sorted by visit count descending
|
||||
assert.Equal(t, 3, data.Histories[0].VisitCount)
|
||||
assert.Equal(t, 1, data.Histories[1].VisitCount)
|
||||
assert.ElementsMatch(t, []int{3, 1}, []int{data.Histories[0].VisitCount, data.Histories[1].VisitCount})
|
||||
})
|
||||
|
||||
t.Run("Cookie", func(t *testing.T) {
|
||||
@@ -94,7 +93,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
})
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.Cookie, path, "")
|
||||
p.extractCategory(data, category.Cookie, path, "")
|
||||
|
||||
require.Len(t, data.Cookies, 1)
|
||||
assert.Equal(t, ".example.com", data.Cookies[0].Host)
|
||||
@@ -112,7 +111,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
})
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.Bookmark, path, "")
|
||||
p.extractCategory(data, category.Bookmark, path, "")
|
||||
|
||||
require.Len(t, data.Bookmarks, 1)
|
||||
assert.Equal(t, "GitHub", data.Bookmarks[0].Name)
|
||||
@@ -127,7 +126,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
})
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.Download, path, "")
|
||||
p.extractCategory(data, category.Download, path, "")
|
||||
|
||||
require.Len(t, data.Downloads, 1)
|
||||
assert.Equal(t, "https://example.com/file.zip", data.Downloads[0].URL)
|
||||
@@ -140,7 +139,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
})
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.LocalStorage, dir, "")
|
||||
p.extractCategory(data, category.LocalStorage, dir, "")
|
||||
|
||||
require.Len(t, data.LocalStorage, 1)
|
||||
assert.Equal(t, "https://github.com", data.LocalStorage[0].URL)
|
||||
@@ -151,7 +150,7 @@ func TestExtractCategory(t *testing.T) {
|
||||
t.Run("UnsupportedCategory", func(t *testing.T) {
|
||||
p := &profile{}
|
||||
data := &types.BrowserData{}
|
||||
p.extractCategory(data, types.CreditCard, "unused", "")
|
||||
p.extractCategory(data, category.CreditCard, "unused", "")
|
||||
assert.Empty(t, data.CreditCards)
|
||||
})
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
)
|
||||
|
||||
// containerPaths returns (legacyHome, container) for a fake ~/Library tree
|
||||
@@ -223,12 +223,12 @@ func TestBuildSources_DefaultProfile(t *testing.T) {
|
||||
p := profileContext{legacyHome: legacyHome, container: container}
|
||||
sources := buildSources(p)
|
||||
|
||||
assert.Equal(t, filepath.Join(legacyHome, "History.db"), sources[types.History][0].abs)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "Bookmarks.plist"), sources[types.Bookmark][0].abs)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "Downloads.plist"), sources[types.Download][0].abs)
|
||||
require.Len(t, sources[types.Cookie], 2)
|
||||
assert.Equal(t, filepath.Join(container, "Cookies", "Cookies.binarycookies"), sources[types.Cookie][0].abs)
|
||||
assert.Equal(t, filepath.Join(library, "Cookies", "Cookies.binarycookies"), sources[types.Cookie][1].abs)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "History.db"), sources[category.History][0].abs)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "Bookmarks.plist"), sources[category.Bookmark][0].abs)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "Downloads.plist"), sources[category.Download][0].abs)
|
||||
require.Len(t, sources[category.Cookie], 2)
|
||||
assert.Equal(t, filepath.Join(container, "Cookies", "Cookies.binarycookies"), sources[category.Cookie][0].abs)
|
||||
assert.Equal(t, filepath.Join(library, "Cookies", "Cookies.binarycookies"), sources[category.Cookie][1].abs)
|
||||
}
|
||||
|
||||
func TestBuildSources_NamedProfile(t *testing.T) {
|
||||
@@ -247,13 +247,13 @@ func TestBuildSources_NamedProfile(t *testing.T) {
|
||||
|
||||
assert.Equal(t,
|
||||
filepath.Join(container, "Safari", "Profiles", uuid, "History.db"),
|
||||
sources[types.History][0].abs)
|
||||
sources[category.History][0].abs)
|
||||
assert.Equal(t,
|
||||
filepath.Join(container, "WebKit", "WebsiteDataStore", strings.ToLower(uuid), "Cookies", "Cookies.binarycookies"),
|
||||
sources[types.Cookie][0].abs)
|
||||
sources[category.Cookie][0].abs)
|
||||
// Download points at the shared plist — filtering by DownloadEntryProfileUUIDStringKey
|
||||
// happens inside extractDownloads, not at the path layer.
|
||||
assert.Equal(t, filepath.Join(legacyHome, "Downloads.plist"), sources[types.Download][0].abs)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "Downloads.plist"), sources[category.Download][0].abs)
|
||||
// Bookmark is still shared with no per-entry profile tag, so it's attributed to default only.
|
||||
assert.NotContains(t, sources, types.Bookmark)
|
||||
assert.NotContains(t, sources, category.Bookmark)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package safari
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -53,7 +54,7 @@ func (b *Browser) Profiles() []types.Profile {
|
||||
}
|
||||
|
||||
// Extract extracts every profile, threading the installation's keychain password.
|
||||
func (b *Browser) Extract(categories []types.Category) ([]types.ExtractResult, error) {
|
||||
func (b *Browser) Extract(categories []category.Category) ([]types.ExtractResult, error) {
|
||||
results := make([]types.ExtractResult, 0, len(b.profiles))
|
||||
for _, p := range b.profiles {
|
||||
results = append(results, types.ExtractResult{
|
||||
@@ -65,7 +66,7 @@ func (b *Browser) Extract(categories []types.Category) ([]types.ExtractResult, e
|
||||
}
|
||||
|
||||
// CountEntries counts entries per category for every profile.
|
||||
func (b *Browser) CountEntries(categories []types.Category) ([]types.CountResult, error) {
|
||||
func (b *Browser) CountEntries(categories []category.Category) ([]types.CountResult, error) {
|
||||
results := make([]types.CountResult, 0, len(b.profiles))
|
||||
for _, p := range b.profiles {
|
||||
results = append(results, types.CountResult{
|
||||
@@ -76,7 +77,7 @@ func (b *Browser) CountEntries(categories []types.Category) ([]types.CountResult
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func resolveProfilePaths(p profileContext) map[types.Category]resolvedPath {
|
||||
func resolveProfilePaths(p profileContext) map[category.Category]resolvedPath {
|
||||
return resolveSourcePaths(buildSources(p))
|
||||
}
|
||||
|
||||
@@ -86,8 +87,8 @@ type resolvedPath struct {
|
||||
}
|
||||
|
||||
// resolveSourcePaths returns only paths that exist; first matching candidate wins per category.
|
||||
func resolveSourcePaths(sources map[types.Category][]sourcePath) map[types.Category]resolvedPath {
|
||||
resolved := make(map[types.Category]resolvedPath)
|
||||
func resolveSourcePaths(sources map[category.Category][]sourcePath) map[category.Category]resolvedPath {
|
||||
resolved := make(map[category.Category]resolvedPath)
|
||||
for cat, candidates := range sources {
|
||||
for _, sp := range candidates {
|
||||
info, err := os.Stat(sp.abs)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -119,20 +120,20 @@ func TestNewBrowsers_MultiProfile(t *testing.T) {
|
||||
switch p.ctx.name {
|
||||
case "default":
|
||||
assert.Equal(t, legacyHome, p.dir())
|
||||
assert.Contains(t, p.sourcePaths, types.History)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "History.db"), p.sourcePaths[types.History].absPath)
|
||||
assert.Contains(t, p.sourcePaths, category.History)
|
||||
assert.Equal(t, filepath.Join(legacyHome, "History.db"), p.sourcePaths[category.History].absPath)
|
||||
// Default profile's LocalStorage root (WebsiteData/Default) isn't created in this fixture,
|
||||
// so it won't resolve — which is the point: resolveSourcePaths only registers paths that exist.
|
||||
assert.NotContains(t, p.sourcePaths, types.LocalStorage)
|
||||
assert.NotContains(t, p.sourcePaths, category.LocalStorage)
|
||||
case "work":
|
||||
assert.Equal(t, filepath.Join(container, "Safari", "Profiles", uuid), p.dir())
|
||||
assert.Contains(t, p.sourcePaths, types.History)
|
||||
assert.Contains(t, p.sourcePaths, category.History)
|
||||
assert.Equal(t,
|
||||
filepath.Join(container, "Safari", "Profiles", uuid, "History.db"),
|
||||
p.sourcePaths[types.History].absPath)
|
||||
require.Contains(t, p.sourcePaths, types.LocalStorage)
|
||||
assert.Equal(t, namedOriginsDir, p.sourcePaths[types.LocalStorage].absPath)
|
||||
assert.True(t, p.sourcePaths[types.LocalStorage].isDir)
|
||||
p.sourcePaths[category.History].absPath)
|
||||
require.Contains(t, p.sourcePaths, category.LocalStorage)
|
||||
assert.Equal(t, namedOriginsDir, p.sourcePaths[category.LocalStorage].absPath)
|
||||
assert.True(t, p.sourcePaths[category.LocalStorage].isDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,9 +148,9 @@ func TestResolveSourcePaths(t *testing.T) {
|
||||
|
||||
sources := buildSources(profileContext{legacyHome: dir, container: deriveContainerRoot(dir)})
|
||||
resolved := resolveSourcePaths(sources)
|
||||
assert.Contains(t, resolved, types.History)
|
||||
assert.Equal(t, filepath.Join(dir, "History.db"), resolved[types.History].absPath)
|
||||
assert.False(t, resolved[types.History].isDir)
|
||||
assert.Contains(t, resolved, category.History)
|
||||
assert.Equal(t, filepath.Join(dir, "History.db"), resolved[category.History].absPath)
|
||||
assert.False(t, resolved[category.History].isDir)
|
||||
}
|
||||
|
||||
func TestResolveSourcePaths_Empty(t *testing.T) {
|
||||
@@ -181,8 +182,8 @@ func TestCountEntries(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, b)
|
||||
|
||||
results, err := b.CountEntries([]types.Category{types.History})
|
||||
results, err := b.CountEntries([]category.Category{category.History})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
assert.Equal(t, 2, results[0].Counts[types.History])
|
||||
assert.Equal(t, 2, results[0].Counts[category.History])
|
||||
}
|
||||
+15
-15
@@ -3,7 +3,7 @@ package safari
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
)
|
||||
|
||||
type sourcePath struct {
|
||||
@@ -21,7 +21,7 @@ func dir(abs string) sourcePath { return sourcePath{abs: abs, isDir: true} }
|
||||
// - Download: shared plist, filtered by DownloadEntryProfileUUIDStringKey at extract time
|
||||
// - Bookmark: shared plist, attributed to default only (no per-entry UUID available)
|
||||
// - Password: macOS Keychain (shared, not listed)
|
||||
func buildSources(p profileContext) map[types.Category][]sourcePath {
|
||||
func buildSources(p profileContext) map[category.Category][]sourcePath {
|
||||
if p.isDefault() {
|
||||
return defaultSources(p)
|
||||
}
|
||||
@@ -31,18 +31,18 @@ func buildSources(p profileContext) map[types.Category][]sourcePath {
|
||||
// defaultSources: cookies try macOS 14+ container first, then the ≤13 legacy path.
|
||||
// LocalStorage for the default profile lives under WebsiteData/Default — the pre-profile-era
|
||||
// WebKit store that stays readable even after profiles are introduced.
|
||||
func defaultSources(p profileContext) map[types.Category][]sourcePath {
|
||||
func defaultSources(p profileContext) map[category.Category][]sourcePath {
|
||||
home := p.legacyHome
|
||||
containerCookies := filepath.Join(p.container, "Cookies", "Cookies.binarycookies")
|
||||
legacyCookies := filepath.Join(filepath.Dir(home), "Cookies", "Cookies.binarycookies")
|
||||
defaultLocalStorage := filepath.Join(p.container, "WebKit", "WebsiteData", "Default")
|
||||
|
||||
return map[types.Category][]sourcePath{
|
||||
types.History: {file(filepath.Join(home, "History.db"))},
|
||||
types.Cookie: {file(containerCookies), file(legacyCookies)},
|
||||
types.Bookmark: {file(filepath.Join(home, "Bookmarks.plist"))},
|
||||
types.Download: {file(filepath.Join(home, "Downloads.plist"))},
|
||||
types.LocalStorage: {dir(defaultLocalStorage)},
|
||||
return map[category.Category][]sourcePath{
|
||||
category.History: {file(filepath.Join(home, "History.db"))},
|
||||
category.Cookie: {file(containerCookies), file(legacyCookies)},
|
||||
category.Bookmark: {file(filepath.Join(home, "Bookmarks.plist"))},
|
||||
category.Download: {file(filepath.Join(home, "Downloads.plist"))},
|
||||
category.LocalStorage: {dir(defaultLocalStorage)},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +52,14 @@ func defaultSources(p profileContext) map[types.Category][]sourcePath {
|
||||
// LocalStorage lives under WebKit/WebsiteDataStore/<uuidLower>/Origins — Safari 17+ uses a nested
|
||||
// <top-frame-hash>/<frame-hash>/LocalStorage/localstorage.sqlite3 layout; the flat
|
||||
// WebsiteDataStore/<uuid>/LocalStorage directory from older builds is empty on modern Safari.
|
||||
func namedSources(p profileContext) map[types.Category][]sourcePath {
|
||||
func namedSources(p profileContext) map[category.Category][]sourcePath {
|
||||
profileDir := filepath.Join(p.container, "Safari", "Profiles", p.uuidUpper)
|
||||
webkitStore := filepath.Join(p.container, "WebKit", "WebsiteDataStore", p.uuidLower)
|
||||
|
||||
return map[types.Category][]sourcePath{
|
||||
types.History: {file(filepath.Join(profileDir, "History.db"))},
|
||||
types.Cookie: {file(filepath.Join(webkitStore, "Cookies", "Cookies.binarycookies"))},
|
||||
types.Download: {file(filepath.Join(p.legacyHome, "Downloads.plist"))},
|
||||
types.LocalStorage: {dir(filepath.Join(webkitStore, "Origins"))},
|
||||
return map[category.Category][]sourcePath{
|
||||
category.History: {file(filepath.Join(profileDir, "History.db"))},
|
||||
category.Cookie: {file(filepath.Join(webkitStore, "Cookies", "Cookies.binarycookies"))},
|
||||
category.Download: {file(filepath.Join(p.legacyHome, "Downloads.plist"))},
|
||||
category.LocalStorage: {dir(filepath.Join(webkitStore, "Origins"))},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user