mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
refactor: move leaf utilities under internal/ (#650)
Phase 1: the packages with no project dependencies move first, so every later phase builds on finished leaves; the goldens pin the behavior.
This commit is contained in:
1 parent
fb86bd368e
commit
9937dbf9fb
54 files changed
+319
-335
No files matched your search
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/browser/chromium"
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||
)
|
||||
|
||||
+1
-1
@@ -9,7 +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/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/moond4rk/keychainbreaker"
|
||||
"golang.org/x/term"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -4,10 +4,9 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||
@@ -256,20 +255,3 @@ func isSkippedDir(name string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Offset from the Chromium epoch (1601-01-01 UTC) to the Unix epoch,
|
||||
// matching base::Time::kTimeTToMicrosecondsOffset in Chromium.
|
||||
const chromiumEpochOffsetMicros int64 = 11644473600000000
|
||||
|
||||
// timeEpoch converts a Chromium base::Time (μs since 1601 UTC) to UTC.
|
||||
// Returns zero for non-positive input or out-of-JSON-range values.
|
||||
func timeEpoch(epoch int64) time.Time {
|
||||
if epoch <= 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
t := time.UnixMicro(epoch - chromiumEpochOffsetMicros).UTC()
|
||||
if t.Year() < 1 || t.Year() > 9999 {
|
||||
return time.Time{}
|
||||
}
|
||||
return t
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -682,47 +681,3 @@ func TestSetRetrievers_SatisfiesInterface(t *testing.T) {
|
||||
SetRetrievers(masterkey.Retrievers)
|
||||
} = (*Browser)(nil)
|
||||
}
|
||||
|
||||
// Anchor: 2024-01-15T10:30:00Z as Chromium microseconds since 1601 UTC.
|
||||
const anchorUnixSeconds = int64(1705314600)
|
||||
|
||||
var anchorChromiumMicros = (anchorUnixSeconds + 11644473600) * 1_000_000
|
||||
|
||||
func TestTimeEpoch_AnchorDate(t *testing.T) {
|
||||
got := timeEpoch(anchorChromiumMicros)
|
||||
want := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
|
||||
assert.Equal(t, want, got)
|
||||
assert.Equal(t, anchorUnixSeconds, got.Unix())
|
||||
}
|
||||
|
||||
func TestTimeEpoch_ZeroReturnsZeroTime(t *testing.T) {
|
||||
assert.True(t, timeEpoch(0).IsZero())
|
||||
}
|
||||
|
||||
func TestTimeEpoch_NegativeReturnsZeroTime(t *testing.T) {
|
||||
assert.True(t, timeEpoch(-1).IsZero())
|
||||
}
|
||||
|
||||
func TestTimeEpoch_AlwaysUTC(t *testing.T) {
|
||||
// assert.Same checks pointer equality: time.UTC and time.Local are
|
||||
// distinct *Location globals, so this catches any regression that
|
||||
// drops .UTC() even when the runner's TZ happens to be UTC.
|
||||
got := timeEpoch(anchorChromiumMicros)
|
||||
assert.Same(t, time.UTC, got.Location())
|
||||
}
|
||||
|
||||
func TestTimeEpoch_MicrosecondPrecisionPreserved(t *testing.T) {
|
||||
got := timeEpoch(anchorChromiumMicros + 123456)
|
||||
assert.Equal(t, 123456*int64(time.Microsecond), int64(got.Nanosecond()))
|
||||
}
|
||||
|
||||
func TestTimeEpoch_UnixEpochBoundary(t *testing.T) {
|
||||
got := timeEpoch(chromiumEpochOffsetMicros)
|
||||
assert.Equal(t, time.Unix(0, 0).UTC(), got)
|
||||
}
|
||||
|
||||
func TestTimeEpoch_OutOfJSONRangeReturnsZero(t *testing.T) {
|
||||
jsonBytes, err := timeEpoch(1 << 62).MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
assert.JSONEq(t, `"0001-01-01T00:00:00Z"`, string(jsonBytes))
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -38,7 +39,7 @@ func walkBookmarks(node gjson.Result, folder string, out *[]types.BookmarkEntry)
|
||||
Type: nodeType,
|
||||
URL: node.Get("url").String(),
|
||||
Folder: folder,
|
||||
CreatedAt: timeEpoch(node.Get("date_added").Int()),
|
||||
CreatedAt: timeconv.Chromium(node.Get("date_added").Int()),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@ import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,7 +20,7 @@ const (
|
||||
)
|
||||
|
||||
func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.CookieEntry, error) {
|
||||
cookies, err := sqliteutil.QueryRows(path, false, defaultCookieQuery,
|
||||
cookies, err := sqlitex.QueryRows(path, false, defaultCookieQuery,
|
||||
func(rows *sql.Rows) (types.CookieEntry, error) {
|
||||
var (
|
||||
name, host, cookiePath string
|
||||
@@ -57,8 +58,8 @@ func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.Cooki
|
||||
IsHTTPOnly: isHTTPOnly != 0,
|
||||
HasExpire: hasExpire != 0,
|
||||
IsPersistent: isPersistent != 0,
|
||||
ExpireAt: timeEpoch(expireAt),
|
||||
CreatedAt: timeEpoch(createdAt),
|
||||
ExpireAt: timeconv.Chromium(expireAt),
|
||||
CreatedAt: timeconv.Chromium(createdAt),
|
||||
SameSite: sameSiteStr,
|
||||
}, nil
|
||||
})
|
||||
@@ -73,7 +74,7 @@ func extractCookies(masterKeys masterkey.MasterKeys, path string) ([]types.Cooki
|
||||
}
|
||||
|
||||
func countCookies(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, false, countCookieQuery)
|
||||
return sqlitex.CountRows(path, false, countCookieQuery)
|
||||
}
|
||||
|
||||
// stripCookieHash removes the SHA256(host_key) prefix from a decrypted cookie value. Chrome 130+
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -37,7 +37,7 @@ type yandexPrivateData struct {
|
||||
}
|
||||
|
||||
func extractCreditCards(masterKeys masterkey.MasterKeys, path string) ([]types.CreditCardEntry, error) {
|
||||
cards, err := sqliteutil.QueryRows(path, false, defaultCreditCardQuery,
|
||||
cards, err := sqlitex.QueryRows(path, false, defaultCreditCardQuery,
|
||||
func(rows *sql.Rows) (types.CreditCardEntry, error) {
|
||||
var guid, name, month, year, nickname, address string
|
||||
var encNumber []byte
|
||||
@@ -72,7 +72,7 @@ func extractYandexCreditCards(masterKeys masterkey.MasterKeys, path string) ([]t
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sqliteutil.QueryRows(path, false, yandexCreditCardQuery,
|
||||
return sqlitex.QueryRows(path, false, yandexCreditCardQuery,
|
||||
func(rows *sql.Rows) (types.CreditCardEntry, error) {
|
||||
var guid, publicData string
|
||||
var privateData []byte
|
||||
@@ -113,9 +113,9 @@ func extractYandexCreditCards(masterKeys masterkey.MasterKeys, path string) ([]t
|
||||
}
|
||||
|
||||
func countCreditCards(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, false, countCreditCardQuery)
|
||||
return sqlitex.CountRows(path, false, countCreditCardQuery)
|
||||
}
|
||||
|
||||
func countYandexCreditCards(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, false, yandexCreditCardCountQuery)
|
||||
return sqlitex.CountRows(path, false, yandexCreditCardCountQuery)
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,7 +16,7 @@ const (
|
||||
)
|
||||
|
||||
func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
downloads, err := sqliteutil.QueryRows(path, false, defaultDownloadQuery,
|
||||
downloads, err := sqlitex.QueryRows(path, false, defaultDownloadQuery,
|
||||
func(rows *sql.Rows) (types.DownloadEntry, error) {
|
||||
var targetPath, url, mimeType string
|
||||
var totalBytes, startTime, endTime int64
|
||||
@@ -27,8 +28,8 @@ func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
TargetPath: targetPath,
|
||||
MimeType: mimeType,
|
||||
TotalBytes: totalBytes,
|
||||
StartTime: timeEpoch(startTime),
|
||||
EndTime: timeEpoch(endTime),
|
||||
StartTime: timeconv.Chromium(startTime),
|
||||
EndTime: timeconv.Chromium(endTime),
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -42,5 +43,5 @@ func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
}
|
||||
|
||||
func countDownloads(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, false, countDownloadQuery)
|
||||
return sqlitex.CountRows(path, false, countDownloadQuery)
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -14,7 +15,7 @@ const (
|
||||
)
|
||||
|
||||
func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
histories, err := sqliteutil.QueryRows(path, false, defaultHistoryQuery,
|
||||
histories, err := sqlitex.QueryRows(path, false, defaultHistoryQuery,
|
||||
func(rows *sql.Rows) (types.HistoryEntry, error) {
|
||||
var url, title string
|
||||
var visitCount int
|
||||
@@ -26,7 +27,7 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
URL: url,
|
||||
Title: title,
|
||||
VisitCount: visitCount,
|
||||
LastVisit: timeEpoch(lastVisit),
|
||||
LastVisit: timeconv.Chromium(lastVisit),
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -40,5 +41,5 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
}
|
||||
|
||||
func countHistories(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, false, countHistoryQuery)
|
||||
return sqlitex.CountRows(path, false, countHistoryQuery)
|
||||
}
|
||||
@@ -6,10 +6,11 @@ import (
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -40,7 +41,7 @@ func extractPasswords(masterKeys masterkey.MasterKeys, path, store string) ([]ty
|
||||
}
|
||||
|
||||
func extractPasswordsWithQuery(masterKeys masterkey.MasterKeys, path, store, query string) ([]types.LoginEntry, error) {
|
||||
logins, err := sqliteutil.QueryRows(path, false, query,
|
||||
logins, err := sqlitex.QueryRows(path, false, query,
|
||||
func(rows *sql.Rows) (types.LoginEntry, error) {
|
||||
var url, username string
|
||||
var pwd []byte
|
||||
@@ -53,7 +54,7 @@ func extractPasswordsWithQuery(masterKeys masterkey.MasterKeys, path, store, que
|
||||
URL: url,
|
||||
Username: username,
|
||||
Password: string(password),
|
||||
CreatedAt: timeEpoch(created),
|
||||
CreatedAt: timeconv.Chromium(created),
|
||||
Store: store,
|
||||
}, nil
|
||||
})
|
||||
@@ -79,7 +80,7 @@ func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]typ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logins, err := sqliteutil.QueryRows(path, false, yandexLoginQuery,
|
||||
logins, err := sqlitex.QueryRows(path, false, yandexLoginQuery,
|
||||
func(rows *sql.Rows) (types.LoginEntry, error) {
|
||||
var originURL, usernameElem, usernameVal, passwordElem, signonRealm string
|
||||
var passwordValue []byte
|
||||
@@ -90,7 +91,7 @@ func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]typ
|
||||
entry := types.LoginEntry{
|
||||
URL: originURL,
|
||||
Username: usernameVal,
|
||||
CreatedAt: timeEpoch(created),
|
||||
CreatedAt: timeconv.Chromium(created),
|
||||
Store: types.PasswordStoreLocal,
|
||||
}
|
||||
aad := yandexLoginAAD(originURL, usernameElem, usernameVal, passwordElem, signonRealm, nil)
|
||||
@@ -113,5 +114,5 @@ func extractYandexPasswords(masterKeys masterkey.MasterKeys, path string) ([]typ
|
||||
}
|
||||
|
||||
func countPasswords(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, false, countLoginQuery)
|
||||
return sqlitex.CountRows(path, false, countLoginQuery)
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -16,7 +17,7 @@ const (
|
||||
)
|
||||
|
||||
func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
||||
bookmarks, err := sqliteutil.QueryRows(path, true, firefoxBookmarkQuery,
|
||||
bookmarks, err := sqlitex.QueryRows(path, true, firefoxBookmarkQuery,
|
||||
func(rows *sql.Rows) (types.BookmarkEntry, error) {
|
||||
var id, dateAdded int64
|
||||
var url, title string
|
||||
@@ -28,7 +29,7 @@ func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
||||
Name: title,
|
||||
URL: url,
|
||||
Folder: bookmarkType(bt),
|
||||
CreatedAt: firefoxMicros(dateAdded),
|
||||
CreatedAt: timeconv.UnixMicro(dateAdded),
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -51,5 +52,5 @@ func bookmarkType(bt int64) string {
|
||||
}
|
||||
|
||||
func countBookmarks(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, true, firefoxCountBookmarkQuery)
|
||||
return sqlitex.CountRows(path, true, firefoxCountBookmarkQuery)
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,7 +16,7 @@ const (
|
||||
)
|
||||
|
||||
func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
cookies, err := sqliteutil.QueryRows(path, true, firefoxCookieQuery,
|
||||
cookies, err := sqlitex.QueryRows(path, true, firefoxCookieQuery,
|
||||
func(rows *sql.Rows) (types.CookieEntry, error) {
|
||||
var (
|
||||
name, value, host, cookiePath string
|
||||
@@ -48,8 +49,8 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
IsHTTPOnly: isHTTPOnly != 0,
|
||||
HasExpire: hasExpire,
|
||||
IsPersistent: hasExpire,
|
||||
ExpireAt: firefoxSeconds(expiry),
|
||||
CreatedAt: firefoxMicros(createdAt),
|
||||
ExpireAt: timeconv.Unix(expiry),
|
||||
CreatedAt: timeconv.UnixMicro(createdAt),
|
||||
SameSite: sameSiteStr,
|
||||
}, nil
|
||||
})
|
||||
@@ -64,5 +65,5 @@ func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
}
|
||||
|
||||
func countCookies(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, true, firefoxCountCookieQuery)
|
||||
return sqlitex.CountRows(path, true, firefoxCountCookieQuery)
|
||||
}
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
downloads, err := sqliteutil.QueryRows(path, true, firefoxDownloadQuery,
|
||||
downloads, err := sqlitex.QueryRows(path, true, firefoxDownloadQuery,
|
||||
func(rows *sql.Rows) (types.DownloadEntry, error) {
|
||||
var placeID, dateAdded int64
|
||||
var content, url string
|
||||
@@ -32,7 +33,7 @@ func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
|
||||
entry := types.DownloadEntry{
|
||||
URL: url,
|
||||
StartTime: firefoxMicros(dateAdded),
|
||||
StartTime: timeconv.UnixMicro(dateAdded),
|
||||
}
|
||||
|
||||
// Firefox stores download metadata as: "target_path,{json}"
|
||||
@@ -42,7 +43,7 @@ func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
entry.TargetPath = contentList[0]
|
||||
json := "{" + contentList[1]
|
||||
entry.TotalBytes = gjson.Get(json, "fileSize").Int()
|
||||
entry.EndTime = firefoxMillis(gjson.Get(json, "endTime").Int())
|
||||
entry.EndTime = timeconv.UnixMilli(gjson.Get(json, "endTime").Int())
|
||||
} else {
|
||||
entry.TargetPath = content
|
||||
}
|
||||
@@ -60,5 +61,5 @@ func extractDownloads(path string) ([]types.DownloadEntry, error) {
|
||||
}
|
||||
|
||||
func countDownloads(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, true, firefoxCountDownloadQuery)
|
||||
return sqlitex.CountRows(path, true, firefoxCountDownloadQuery)
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,7 +16,7 @@ const (
|
||||
)
|
||||
|
||||
func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
histories, err := sqliteutil.QueryRows(path, true, firefoxHistoryQuery,
|
||||
histories, err := sqlitex.QueryRows(path, true, firefoxHistoryQuery,
|
||||
func(rows *sql.Rows) (types.HistoryEntry, error) {
|
||||
var url, title string
|
||||
var visitCount int
|
||||
@@ -27,7 +28,7 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
URL: url,
|
||||
Title: title,
|
||||
VisitCount: visitCount,
|
||||
LastVisit: firefoxMicros(lastVisit),
|
||||
LastVisit: timeconv.UnixMicro(lastVisit),
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -41,5 +42,5 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
}
|
||||
|
||||
func countHistories(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, true, firefoxCountHistoryQuery)
|
||||
return sqlitex.CountRows(path, true, firefoxCountHistoryQuery)
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -68,7 +69,7 @@ func extractPasswords(masterKey []byte, path string) ([]types.LoginEntry, error)
|
||||
URL: url,
|
||||
Username: string(user),
|
||||
Password: string(pwd),
|
||||
CreatedAt: firefoxMillis(v.Get("timeCreated").Int()),
|
||||
CreatedAt: timeconv.UnixMilli(v.Get("timeCreated").Int()),
|
||||
Store: types.PasswordStoreLocal,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
)
|
||||
|
||||
func extractLocalStorage(path string) ([]types.StorageEntry, error) {
|
||||
return sqliteutil.QueryRows(path, true, firefoxLocalStorageQuery,
|
||||
return sqlitex.QueryRows(path, true, firefoxLocalStorageQuery,
|
||||
func(rows *sql.Rows) (types.StorageEntry, error) {
|
||||
var originKey, key, value string
|
||||
if err := rows.Scan(&originKey, &key, &value); err != nil {
|
||||
@@ -30,7 +30,7 @@ func extractLocalStorage(path string) ([]types.StorageEntry, error) {
|
||||
}
|
||||
|
||||
func countLocalStorage(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, true, firefoxCountLocalStorageQuery)
|
||||
return sqlitex.CountRows(path, true, firefoxCountLocalStorageQuery)
|
||||
}
|
||||
|
||||
func reverseString(s string) string {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -166,39 +165,3 @@ func resolveSourcePaths(sources map[types.Category][]sourcePath, profileDir stri
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
|
||||
// Firefox uses three timestamp units. Helpers emit UTC and return the zero
|
||||
// time.Time for non-positive or out-of-JSON-range input.
|
||||
//
|
||||
// - firefoxMicros: PRTime (μs since Unix epoch) — moz_* tables.
|
||||
// - firefoxMillis: Date.now() (ms) — logins.json, download endTime.
|
||||
// - firefoxSeconds: seconds — moz_cookies.expiry only.
|
||||
func firefoxMicros(us int64) time.Time {
|
||||
if us <= 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return clampJSON(time.UnixMicro(us).UTC())
|
||||
}
|
||||
|
||||
func firefoxMillis(ms int64) time.Time {
|
||||
if ms <= 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return clampJSON(time.UnixMilli(ms).UTC())
|
||||
}
|
||||
|
||||
func firefoxSeconds(s int64) time.Time {
|
||||
if s <= 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return clampJSON(time.Unix(s, 0).UTC())
|
||||
}
|
||||
|
||||
// clampJSON maps years outside time.Time.MarshalJSON's [1, 9999] window
|
||||
// to the zero time, so JSON export can't crash on sentinel inputs.
|
||||
func clampJSON(t time.Time) time.Time {
|
||||
if t.Year() < 1 || t.Year() > 9999 {
|
||||
return time.Time{}
|
||||
}
|
||||
return t
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -200,79 +199,3 @@ func TestCountEntries(t *testing.T) {
|
||||
require.Len(t, results, 1)
|
||||
assert.Equal(t, 3, results[0].Counts[types.History])
|
||||
}
|
||||
|
||||
// Anchor: 2024-01-15T10:30:00Z.
|
||||
const anchorUnixSeconds = int64(1705314600)
|
||||
|
||||
func TestFirefoxMicros_AnchorDate(t *testing.T) {
|
||||
got := firefoxMicros(anchorUnixSeconds * 1_000_000)
|
||||
want := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestFirefoxMicros_PrecisionPreserved(t *testing.T) {
|
||||
got := firefoxMicros(anchorUnixSeconds*1_000_000 + 123456)
|
||||
assert.Equal(t, 123456*int64(time.Microsecond), int64(got.Nanosecond()))
|
||||
}
|
||||
|
||||
func TestFirefoxMillis_AnchorDate(t *testing.T) {
|
||||
got := firefoxMillis(anchorUnixSeconds * 1_000)
|
||||
want := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestFirefoxMillis_PrecisionPreserved(t *testing.T) {
|
||||
got := firefoxMillis(anchorUnixSeconds*1_000 + 789)
|
||||
assert.Equal(t, 789*int64(time.Millisecond), int64(got.Nanosecond()))
|
||||
}
|
||||
|
||||
func TestFirefoxSeconds_AnchorDate(t *testing.T) {
|
||||
got := firefoxSeconds(anchorUnixSeconds)
|
||||
want := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestFirefoxHelpers_ZeroReturnsZeroTime(t *testing.T) {
|
||||
assert.True(t, firefoxMicros(0).IsZero(), "micros")
|
||||
assert.True(t, firefoxMillis(0).IsZero(), "millis")
|
||||
assert.True(t, firefoxSeconds(0).IsZero(), "seconds")
|
||||
}
|
||||
|
||||
func TestFirefoxHelpers_NegativeReturnsZeroTime(t *testing.T) {
|
||||
assert.True(t, firefoxMicros(-1).IsZero(), "micros")
|
||||
assert.True(t, firefoxMillis(-1).IsZero(), "millis")
|
||||
assert.True(t, firefoxSeconds(-1).IsZero(), "seconds")
|
||||
}
|
||||
|
||||
func TestFirefoxHelpers_AlwaysUTC(t *testing.T) {
|
||||
// assert.Same: pointer equality reliably catches any helper that
|
||||
// leaks time.Local, independent of the runner's configured TZ.
|
||||
assert.Same(t, time.UTC, firefoxMicros(anchorUnixSeconds*1_000_000).Location())
|
||||
assert.Same(t, time.UTC, firefoxMillis(anchorUnixSeconds*1_000).Location())
|
||||
assert.Same(t, time.UTC, firefoxSeconds(anchorUnixSeconds).Location())
|
||||
}
|
||||
|
||||
func TestFirefoxHelpers_SameMomentAcrossUnits(t *testing.T) {
|
||||
us := firefoxMicros(anchorUnixSeconds * 1_000_000)
|
||||
ms := firefoxMillis(anchorUnixSeconds * 1_000)
|
||||
s := firefoxSeconds(anchorUnixSeconds)
|
||||
assert.True(t, us.Equal(ms))
|
||||
assert.True(t, ms.Equal(s))
|
||||
}
|
||||
|
||||
func TestFirefoxHelpers_OutOfJSONRangeReturnsZero(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
got time.Time
|
||||
}{
|
||||
{"seconds", firefoxSeconds(1 << 50)},
|
||||
{"millis", firefoxMillis(1 << 60)},
|
||||
{"micros", firefoxMicros(1 << 62)},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
b, err := tc.got.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
assert.JSONEq(t, `"0001-01-01T00:00:00Z"`, string(b))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
)
|
||||
|
||||
// key4DB holds the parsed contents of Firefox's key4.db NSS key storage.
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||
)
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/masterkey"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/internal/sqlitex"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/timeconv"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,7 +25,7 @@ const (
|
||||
)
|
||||
|
||||
func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
histories, err := sqliteutil.QueryRows(path, true, safariHistoryQuery,
|
||||
histories, err := sqlitex.QueryRows(path, true, safariHistoryQuery,
|
||||
func(rows *sql.Rows) (types.HistoryEntry, error) {
|
||||
var (
|
||||
url, title string
|
||||
@@ -38,7 +39,7 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
URL: url,
|
||||
Title: title,
|
||||
VisitCount: visitCount,
|
||||
LastVisit: coredataTimestamp(visitTime),
|
||||
LastVisit: timeconv.CoreData(visitTime),
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -52,5 +53,5 @@ func extractHistories(path string) ([]types.HistoryEntry, error) {
|
||||
}
|
||||
|
||||
func countHistories(path string) (int, error) {
|
||||
return sqliteutil.CountRows(path, true, safariCountHistoryQuery)
|
||||
return sqlitex.CountRows(path, true, safariCountHistoryQuery)
|
||||
}
|
||||
@@ -93,14 +93,3 @@ func TestExtractHistories_NullTitle(t *testing.T) {
|
||||
assert.Equal(t, "https://null.test", got[0].URL)
|
||||
assert.Empty(t, got[0].Title)
|
||||
}
|
||||
|
||||
func TestCoredataTimestamp(t *testing.T) {
|
||||
// A zero Core Data value is treated as "no timestamp" and returns
|
||||
// the zero time.Time rather than literal 2001-01-01 — matches the
|
||||
// convention used by the Chromium and Firefox helpers.
|
||||
assert.True(t, coredataTimestamp(0).IsZero())
|
||||
|
||||
// Known value: 700000000 Core Data = 1678307200 Unix
|
||||
ts2 := coredataTimestamp(700000000)
|
||||
assert.Equal(t, int64(1678307200), ts2.Unix())
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/moond4rk/keychainbreaker"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/filemanager"
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/log"
|
||||
"github.com/moond4rk/hackbrowserdata/internal/log"
|
||||
)
|
||||
|
||||
// profileContext tracks the uppercase (Safari/Profiles/<UUID>) and lowercase
|
||||
|
||||
@@ -2,7 +2,6 @@ package safari
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
@@ -103,23 +102,3 @@ func resolveSourcePaths(sources map[types.Category][]sourcePath) map[types.Categ
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
|
||||
// Offset from the Core Data epoch (2001-01-01 UTC) to the Unix epoch.
|
||||
const coreDataEpochOffset = 978307200
|
||||
|
||||
// maxCoreDataSeconds guards against CFAbsoluteTime values that would exceed
|
||||
// time.Time.MarshalJSON's year-9999 ceiling, and bounds the float→int64
|
||||
// conversion below (Go spec: out-of-range result is implementation-dependent).
|
||||
const maxCoreDataSeconds = 252423993600
|
||||
|
||||
// coredataTimestamp converts Core Data seconds (CFAbsoluteTime) to UTC.
|
||||
// Returns zero for non-positive input or out-of-JSON-range values.
|
||||
func coredataTimestamp(seconds float64) time.Time {
|
||||
if seconds <= 0 || seconds > maxCoreDataSeconds {
|
||||
return time.Time{}
|
||||
}
|
||||
whole := int64(seconds)
|
||||
frac := seconds - float64(whole)
|
||||
nanos := int64(frac * 1e9)
|
||||
return time.Unix(whole+coreDataEpochOffset, nanos).UTC()
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -187,32 +186,3 @@ func TestCountEntries(t *testing.T) {
|
||||
require.Len(t, results, 1)
|
||||
assert.Equal(t, 2, results[0].Counts[types.History])
|
||||
}
|
||||
|
||||
// Anchor: 2024-01-15T10:30:00Z, in seconds past the Core Data epoch (2001-01-01Z).
|
||||
const anchorCoreDataSeconds = 1705314600 - 978307200
|
||||
|
||||
func TestCoredataTimestamp_AnchorDate(t *testing.T) {
|
||||
got := coredataTimestamp(float64(anchorCoreDataSeconds))
|
||||
want := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestCoredataTimestamp_EpochZero(t *testing.T) {
|
||||
assert.True(t, coredataTimestamp(0).IsZero())
|
||||
}
|
||||
|
||||
func TestCoredataTimestamp_NegativeReturnsZeroTime(t *testing.T) {
|
||||
assert.True(t, coredataTimestamp(-1).IsZero())
|
||||
}
|
||||
|
||||
func TestCoredataTimestamp_FractionalSecondsPreserved(t *testing.T) {
|
||||
got := coredataTimestamp(float64(anchorCoreDataSeconds) + 0.5)
|
||||
assert.Equal(t, 500*int64(time.Millisecond), int64(got.Nanosecond()))
|
||||
}
|
||||
|
||||
func TestCoredataTimestamp_AlwaysUTC(t *testing.T) {
|
||||
// assert.Same: pointer equality reliably catches any regression that
|
||||
// leaks time.Local, independent of the runner's configured TZ.
|
||||
got := coredataTimestamp(float64(anchorCoreDataSeconds))
|
||||
assert.Same(t, time.UTC, got.Location())
|
||||
}
|
||||
Reference in new issue
Block a user