mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-08-24 00:22:29 +02:00
feat: add Safari cookie extraction from BinaryCookies format (#566)
* feat: add Safari cookie extraction from BinaryCookies format * fix: use expiry presence instead of current time for HasExpire
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package safari
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/moond4rk/binarycookies"
|
||||
|
||||
"github.com/moond4rk/hackbrowserdata/types"
|
||||
)
|
||||
|
||||
func extractCookies(path string) ([]types.CookieEntry, error) {
|
||||
pages, err := decodeBinaryCookies(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cookies []types.CookieEntry
|
||||
for _, page := range pages {
|
||||
for _, c := range page.Cookies {
|
||||
hasExpire := !c.Expires.IsZero()
|
||||
cookies = append(cookies, types.CookieEntry{
|
||||
Host: string(c.Domain),
|
||||
Path: string(c.Path),
|
||||
Name: string(c.Name),
|
||||
Value: string(c.Value),
|
||||
IsSecure: c.Secure,
|
||||
IsHTTPOnly: c.HTTPOnly,
|
||||
HasExpire: hasExpire,
|
||||
IsPersistent: hasExpire,
|
||||
ExpireAt: c.Expires,
|
||||
CreatedAt: c.Creation,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(cookies, func(i, j int) bool {
|
||||
return cookies[i].CreatedAt.After(cookies[j].CreatedAt)
|
||||
})
|
||||
return cookies, nil
|
||||
}
|
||||
|
||||
func countCookies(path string) (int, error) {
|
||||
pages, err := decodeBinaryCookies(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var total int
|
||||
for _, page := range pages {
|
||||
total += len(page.Cookies)
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
func decodeBinaryCookies(path string) ([]binarycookies.Page, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open cookies file: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
jar := binarycookies.New(f)
|
||||
pages, err := jar.Decode()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decode cookies: %w", err)
|
||||
}
|
||||
return pages, nil
|
||||
}
|
||||
Reference in New Issue
Block a user