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
@@ -0,0 +1,56 @@
|
||||
package types
|
||||
|
||||
import "github.com/moond4rk/hackbrowserdata/internal/record"
|
||||
|
||||
// BrowserKind identifies the browser engine type.
|
||||
type BrowserKind int
|
||||
|
||||
const (
|
||||
Chromium BrowserKind = iota
|
||||
ChromiumYandex // Chromium variant with different file names and extract logic
|
||||
ChromiumOpera // Opera: extensions in "opsettings" key, data in Roaming
|
||||
Firefox
|
||||
Safari
|
||||
)
|
||||
|
||||
// String returns the canonical lowercase name of the engine kind; the chromium-family values are
|
||||
// also the stable wire form carried in a keys dump, so don't change them lightly.
|
||||
func (k BrowserKind) String() string {
|
||||
switch k {
|
||||
case Chromium:
|
||||
return "chromium"
|
||||
case ChromiumYandex:
|
||||
return "chromium-yandex"
|
||||
case ChromiumOpera:
|
||||
return "chromium-opera"
|
||||
case Firefox:
|
||||
return "firefox"
|
||||
case Safari:
|
||||
return "safari"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// BrowserConfig holds the declarative configuration for a browser installation.
|
||||
type BrowserConfig struct {
|
||||
Key string // lookup key; doubles as the Windows ABE / winutil.Table key when WindowsABE is true
|
||||
Name string // display name
|
||||
Kind BrowserKind // engine type
|
||||
KeychainLabel string // macOS Keychain account / Linux D-Bus Secret Service label; "" = none
|
||||
WindowsABE bool // enable Windows App-Bound Encryption v20 (reflective injection)
|
||||
UserDataDir string // base browser directory
|
||||
}
|
||||
|
||||
// BrowserData holds all extracted browser data with typed slices.
|
||||
type BrowserData struct {
|
||||
Passwords []record.Login
|
||||
Cookies []record.Cookie
|
||||
Histories []record.History
|
||||
Downloads []record.Download
|
||||
Bookmarks []record.Bookmark
|
||||
CreditCards []record.CreditCard
|
||||
Extensions []record.Extension
|
||||
LocalStorage []record.LocalStorage
|
||||
SessionStorage []record.SessionStorage
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBrowserKind_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
kind BrowserKind
|
||||
want string
|
||||
}{
|
||||
{Chromium, "chromium"},
|
||||
{ChromiumYandex, "chromium-yandex"},
|
||||
{ChromiumOpera, "chromium-opera"},
|
||||
{Firefox, "firefox"},
|
||||
{Safari, "safari"},
|
||||
{BrowserKind(999), "unknown"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
assert.Equal(t, tt.want, tt.kind.String())
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package types
|
||||
|
||||
// Category represents a kind of browser data.
|
||||
// It is browser-agnostic — a password is a password regardless of which browser it came from.
|
||||
type Category int
|
||||
|
||||
const (
|
||||
Password Category = iota
|
||||
Cookie
|
||||
Bookmark
|
||||
History
|
||||
Download
|
||||
CreditCard
|
||||
Extension
|
||||
LocalStorage
|
||||
SessionStorage
|
||||
)
|
||||
|
||||
// AllCategories returns all supported data categories.
|
||||
var AllCategories = []Category{
|
||||
Password, Cookie, Bookmark, History, Download,
|
||||
CreditCard, Extension, LocalStorage, SessionStorage,
|
||||
}
|
||||
|
||||
// String returns the human-readable name of the category.
|
||||
func (c Category) String() string {
|
||||
switch c {
|
||||
case Password:
|
||||
return "password"
|
||||
case Cookie:
|
||||
return "cookie"
|
||||
case Bookmark:
|
||||
return "bookmark"
|
||||
case History:
|
||||
return "history"
|
||||
case Download:
|
||||
return "download"
|
||||
case CreditCard:
|
||||
return "creditcard"
|
||||
case Extension:
|
||||
return "extension"
|
||||
case LocalStorage:
|
||||
return "localstorage"
|
||||
case SessionStorage:
|
||||
return "sessionstorage"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// IsSensitive returns whether the category contains sensitive data
|
||||
// that requires explicit opt-in to export.
|
||||
func (c Category) IsSensitive() bool {
|
||||
switch c {
|
||||
case Password, Cookie, CreditCard:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// NonSensitiveCategories returns categories that are safe to export by default.
|
||||
func NonSensitiveCategories() []Category {
|
||||
var cats []Category
|
||||
for _, c := range AllCategories {
|
||||
if !c.IsSensitive() {
|
||||
cats = append(cats, c)
|
||||
}
|
||||
}
|
||||
return cats
|
||||
}
|
||||
|
||||
// BrowserKind identifies the browser engine type.
|
||||
type BrowserKind int
|
||||
|
||||
const (
|
||||
Chromium BrowserKind = iota
|
||||
ChromiumYandex // Chromium variant with different file names and extract logic
|
||||
ChromiumOpera // Opera: extensions in "opsettings" key, data in Roaming
|
||||
Firefox
|
||||
Safari
|
||||
)
|
||||
|
||||
// String returns the canonical lowercase name of the engine kind; the chromium-family values are
|
||||
// also the stable wire form carried in a keys dump, so don't change them lightly.
|
||||
func (k BrowserKind) String() string {
|
||||
switch k {
|
||||
case Chromium:
|
||||
return "chromium"
|
||||
case ChromiumYandex:
|
||||
return "chromium-yandex"
|
||||
case ChromiumOpera:
|
||||
return "chromium-opera"
|
||||
case Firefox:
|
||||
return "firefox"
|
||||
case Safari:
|
||||
return "safari"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// BrowserConfig holds the declarative configuration for a browser installation.
|
||||
type BrowserConfig struct {
|
||||
Key string // lookup key; doubles as the Windows ABE / winutil.Table key when WindowsABE is true
|
||||
Name string // display name
|
||||
Kind BrowserKind // engine type
|
||||
KeychainLabel string // macOS Keychain account / Linux D-Bus Secret Service label; "" = none
|
||||
WindowsABE bool // enable Windows App-Bound Encryption v20 (reflective injection)
|
||||
UserDataDir string // base browser directory
|
||||
}
|
||||
|
||||
// BrowserData holds all extracted browser data with typed slices.
|
||||
type BrowserData struct {
|
||||
Passwords []LoginEntry
|
||||
Cookies []CookieEntry
|
||||
Histories []HistoryEntry
|
||||
Downloads []DownloadEntry
|
||||
Bookmarks []BookmarkEntry
|
||||
CreditCards []CreditCardEntry
|
||||
Extensions []ExtensionEntry
|
||||
LocalStorage []StorageEntry
|
||||
SessionStorage []StorageEntry
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCategory_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
cat Category
|
||||
want string
|
||||
}{
|
||||
{Password, "password"},
|
||||
{Cookie, "cookie"},
|
||||
{Bookmark, "bookmark"},
|
||||
{History, "history"},
|
||||
{Download, "download"},
|
||||
{CreditCard, "creditcard"},
|
||||
{Extension, "extension"},
|
||||
{LocalStorage, "localstorage"},
|
||||
{SessionStorage, "sessionstorage"},
|
||||
{Category(999), "unknown"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
assert.Equal(t, tt.want, tt.cat.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserKind_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
kind BrowserKind
|
||||
want string
|
||||
}{
|
||||
{Chromium, "chromium"},
|
||||
{ChromiumYandex, "chromium-yandex"},
|
||||
{ChromiumOpera, "chromium-opera"},
|
||||
{Firefox, "firefox"},
|
||||
{Safari, "safari"},
|
||||
{BrowserKind(999), "unknown"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
assert.Equal(t, tt.want, tt.kind.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCategory_IsSensitive(t *testing.T) {
|
||||
sensitive := []Category{Password, Cookie, CreditCard}
|
||||
for _, c := range sensitive {
|
||||
assert.True(t, c.IsSensitive(), "%s should be sensitive", c)
|
||||
}
|
||||
|
||||
notSensitive := []Category{Bookmark, History, Download, Extension, LocalStorage, SessionStorage}
|
||||
for _, c := range notSensitive {
|
||||
assert.False(t, c.IsSensitive(), "%s should not be sensitive", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllCategories(t *testing.T) {
|
||||
assert.Len(t, AllCategories, 9)
|
||||
}
|
||||
|
||||
func TestNonSensitiveCategories(t *testing.T) {
|
||||
cats := NonSensitiveCategories()
|
||||
assert.Len(t, cats, 6)
|
||||
for _, c := range cats {
|
||||
assert.False(t, c.IsSensitive())
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
// Chromium keeps profile-local credentials in "Login Data" and account-synced ones in
|
||||
// "Login Data For Account". The same credential may exist in both, so exported entries
|
||||
// carry their origin instead of being silently merged.
|
||||
const (
|
||||
PasswordStoreLocal = "local"
|
||||
PasswordStoreAccount = "account"
|
||||
)
|
||||
|
||||
// LoginEntry represents a single saved login credential.
|
||||
type LoginEntry struct {
|
||||
URL string `json:"url" csv:"url"`
|
||||
Username string `json:"username" csv:"username"`
|
||||
Password string `json:"password" csv:"password"`
|
||||
CreatedAt time.Time `json:"created_at" csv:"created_at"`
|
||||
Store string `json:"store" csv:"store"`
|
||||
}
|
||||
|
||||
// CookieEntry represents a single browser cookie.
|
||||
type CookieEntry struct {
|
||||
Host string `json:"host" csv:"host"`
|
||||
Path string `json:"path" csv:"path"`
|
||||
Name string `json:"name" csv:"name"`
|
||||
Value string `json:"value" csv:"value"`
|
||||
IsSecure bool `json:"is_secure" csv:"is_secure"`
|
||||
IsHTTPOnly bool `json:"is_http_only" csv:"is_http_only"`
|
||||
HasExpire bool `json:"has_expire" csv:"has_expire"`
|
||||
IsPersistent bool `json:"is_persistent" csv:"is_persistent"`
|
||||
ExpireAt time.Time `json:"expire_at" csv:"expire_at"`
|
||||
CreatedAt time.Time `json:"created_at" csv:"created_at"`
|
||||
SameSite string `json:"same_site" csv:"same_site"`
|
||||
}
|
||||
|
||||
// BookmarkEntry represents a single browser bookmark.
|
||||
type BookmarkEntry struct {
|
||||
ID int64 `json:"id" csv:"id"`
|
||||
Name string `json:"name" csv:"name"`
|
||||
Type string `json:"type" csv:"type"`
|
||||
URL string `json:"url" csv:"url"`
|
||||
Folder string `json:"folder" csv:"folder"`
|
||||
CreatedAt time.Time `json:"created_at" csv:"created_at"`
|
||||
}
|
||||
|
||||
// HistoryEntry represents a single browser history record.
|
||||
type HistoryEntry struct {
|
||||
URL string `json:"url" csv:"url"`
|
||||
Title string `json:"title" csv:"title"`
|
||||
VisitCount int `json:"visit_count" csv:"visit_count"`
|
||||
LastVisit time.Time `json:"last_visit" csv:"last_visit"`
|
||||
}
|
||||
|
||||
// DownloadEntry represents a single browser download record.
|
||||
type DownloadEntry struct {
|
||||
URL string `json:"url" csv:"url"`
|
||||
TargetPath string `json:"target_path" csv:"target_path"`
|
||||
MimeType string `json:"mime_type" csv:"mime_type"`
|
||||
TotalBytes int64 `json:"total_bytes" csv:"total_bytes"`
|
||||
StartTime time.Time `json:"start_time" csv:"start_time"`
|
||||
EndTime time.Time `json:"end_time" csv:"end_time"`
|
||||
}
|
||||
|
||||
// CreditCardEntry represents a single saved credit card. CVC and Comment are
|
||||
// Yandex-specific; Chromium leaves them empty.
|
||||
type CreditCardEntry struct {
|
||||
GUID string `json:"guid" csv:"guid"`
|
||||
Name string `json:"name" csv:"name"`
|
||||
Number string `json:"number" csv:"number"`
|
||||
ExpMonth string `json:"exp_month" csv:"exp_month"`
|
||||
ExpYear string `json:"exp_year" csv:"exp_year"`
|
||||
NickName string `json:"nick_name" csv:"nick_name"`
|
||||
Address string `json:"address" csv:"address"`
|
||||
CVC string `json:"cvc" csv:"cvc"`
|
||||
Comment string `json:"comment" csv:"comment"`
|
||||
}
|
||||
|
||||
// StorageEntry represents a single key-value pair from local or session storage.
|
||||
type StorageEntry struct {
|
||||
IsMeta bool `json:"is_meta" csv:"is_meta"`
|
||||
URL string `json:"url" csv:"url"`
|
||||
Key string `json:"key" csv:"key"`
|
||||
Value string `json:"value" csv:"value"`
|
||||
}
|
||||
|
||||
// ExtensionEntry represents a single browser extension.
|
||||
type ExtensionEntry struct {
|
||||
Name string `json:"name" csv:"name"`
|
||||
ID string `json:"id" csv:"id"`
|
||||
Description string `json:"description" csv:"description"`
|
||||
Version string `json:"version" csv:"version"`
|
||||
HomepageURL string `json:"homepage_url" csv:"homepage_url"`
|
||||
Enabled bool `json:"enabled" csv:"enabled"`
|
||||
}
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package types
|
||||
|
||||
import "github.com/moond4rk/hackbrowserdata/internal/category"
|
||||
|
||||
// Profile identifies one browser profile — a leaf under an installation.
|
||||
type Profile struct {
|
||||
Name string
|
||||
@@ -15,5 +17,5 @@ type ExtractResult struct {
|
||||
// CountResult pairs a profile with its per-category entry counts.
|
||||
type CountResult struct {
|
||||
Profile
|
||||
Counts map[Category]int
|
||||
Counts map[category.Category]int
|
||||
}
|
||||
Reference in new issue
Block a user