mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
* chore(deps): migrate to github.com/moond4rk/binarycookies/v2 v2 decodes jars that v1 rejected whole (any cookie record over 4096 bytes) and returns strings and UTC times, so extraction drops its conversions; Safari test fixtures are now written by binarycookies.Encode. * chore(deps): bump binarycookies/v2 to v2.0.0 binarycookies.Encode writes whole seconds, so the 750ms fixture offset never reached the jar.
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package safari
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/moond4rk/binarycookies/v2"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/browser"
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
)
|
|
|
|
func extractCookies(path string, out browser.Collector) error {
|
|
jar, err := decodeBinaryCookies(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, cookie := range jar.Cookies() {
|
|
hasExpire := !cookie.Expires.IsZero()
|
|
out.Add(&record.Cookie{
|
|
Host: cookie.Domain,
|
|
Path: cookie.Path,
|
|
Name: cookie.Name,
|
|
Value: cookie.Value,
|
|
IsSecure: cookie.Secure(),
|
|
IsHTTPOnly: cookie.HTTPOnly(),
|
|
HasExpire: hasExpire,
|
|
IsPersistent: hasExpire,
|
|
ExpireAt: cookie.Expires,
|
|
CreatedAt: cookie.Created,
|
|
})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func decodeBinaryCookies(path string) (*binarycookies.File, error) {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("open cookies file: %w", err)
|
|
}
|
|
defer file.Close()
|
|
|
|
jar, err := binarycookies.Decode(file)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("decode cookies: %w", err)
|
|
}
|
|
return jar, nil
|
|
}
|