mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
eed1d12282
* refactor: Refactor file paths and use map to store item names - Refactored file paths for various browsing data types to use a consistent method of generating temporary file names - Modified parsing functions in many browsing data types to use the new temporary file naming scheme - Renamed `FileName` to `Filename` for consistency in the `item` package - Removed unnecessary code and comments throughout various files - Made minor improvements to some Item methods such as `TempFilename` and `FileName` * ci: Optimize GitHub actions and update Go versions. (#274) * ci: Optimize GitHub actions and update Go versions. - Add GitHub actions for unit testing, linting, building, and releasing - Use a matrix strategy to test on different versions and platforms - Update setup-go and go-version options for compatibility - Format code and build zip files for different operating systems - Upload releases to GitHub with specific asset names and types * fix: Refactor item file naming convention - Update `filename()` function to return `UnsupportedItem` in specific cases - Replace `UnknownItem` with `UnsupportedItem` in `Filename` method of `Item` struct - Refactor code for clarity and consistency * ci: Update GitHub workflow with latest setup-go version - Update setup-go action to v3 in lint.yml GitHub workflow - Omits some big changes in file diff summary - Improve overall workflow reliability and efficiency * ci: Improve GitHub actions across platforms - Improve Windows compatibility in build workflow - Optimize unit testing for pull requests - Upgrade Coveralls GitHub action to v2 for improved coverage tracking * build: Optimize build process for consistency and efficiency - Ensure consistency of line endings by disabling Git's automatic conversion - Add format check for Windows systems - Update Go version in strategy matrix to `1.21.x` - Remove unused dependencies from build process - Include all packages in repository in build command * ci: Refactor GitHub workflow configuration - Remove unnecessary checks for `windows-latest` in github workflow - Change `gofmt` check to `diff` for formatting - Remove unneeded Git configuration for encoding of line endings - Close #273 * ci: Update default branch references in GitHub Actions workflows (#277) - Update Github Actions workflows to use `main` branch instead of `master`. - Rename `master` branch to `main` in `lint.yml` and `build.yml` files. - Change default branch to `main` in `contributors.yml` workflow file.
166 lines
3.8 KiB
Go
166 lines
3.8 KiB
Go
package sessionstorage
|
|
|
|
import (
|
|
"bytes"
|
|
"database/sql"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
"golang.org/x/text/encoding/unicode"
|
|
"golang.org/x/text/transform"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/item"
|
|
"github.com/moond4rk/hackbrowserdata/log"
|
|
"github.com/moond4rk/hackbrowserdata/utils/byteutil"
|
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
|
)
|
|
|
|
type ChromiumSessionStorage []session
|
|
|
|
type session struct {
|
|
IsMeta bool
|
|
URL string
|
|
Key string
|
|
Value string
|
|
}
|
|
|
|
const maxLocalStorageValueLength = 1024 * 2
|
|
|
|
func (c *ChromiumSessionStorage) Parse(_ []byte) error {
|
|
db, err := leveldb.OpenFile(item.ChromiumSessionStorage.TempFilename(), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer os.RemoveAll(item.ChromiumSessionStorage.TempFilename())
|
|
defer db.Close()
|
|
|
|
iter := db.NewIterator(nil, nil)
|
|
for iter.Next() {
|
|
key := iter.Key()
|
|
value := iter.Value()
|
|
s := new(session)
|
|
s.fillKey(key)
|
|
// don't all value upper than 2KB
|
|
if len(value) < maxLocalStorageValueLength {
|
|
s.fillValue(value)
|
|
} else {
|
|
s.Value = fmt.Sprintf("value is too long, length is %d, supportted max length is %d", len(value), maxLocalStorageValueLength)
|
|
}
|
|
if s.IsMeta {
|
|
s.Value = fmt.Sprintf("meta data, value bytes is %v", value)
|
|
}
|
|
*c = append(*c, *s)
|
|
}
|
|
iter.Release()
|
|
err = iter.Error()
|
|
return err
|
|
}
|
|
|
|
func (c *ChromiumSessionStorage) Name() string {
|
|
return "sessionStorage"
|
|
}
|
|
|
|
func (c *ChromiumSessionStorage) Len() int {
|
|
return len(*c)
|
|
}
|
|
|
|
func (s *session) fillKey(b []byte) {
|
|
keys := bytes.Split(b, []byte("-"))
|
|
if len(keys) == 1 && bytes.HasPrefix(keys[0], []byte("META:")) {
|
|
s.IsMeta = true
|
|
s.fillMetaHeader(keys[0])
|
|
}
|
|
if len(keys) == 2 && bytes.HasPrefix(keys[0], []byte("_")) {
|
|
s.fillHeader(keys[0], keys[1])
|
|
}
|
|
if len(keys) == 3 {
|
|
if string(keys[0]) == "map" {
|
|
s.Key = string(keys[2])
|
|
} else if string(keys[0]) == "namespace" {
|
|
s.URL = string(keys[2])
|
|
s.Key = string(keys[1])
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *session) fillMetaHeader(b []byte) {
|
|
s.URL = string(bytes.Trim(b, "META:"))
|
|
}
|
|
|
|
func (s *session) fillHeader(url, key []byte) {
|
|
s.URL = string(bytes.Trim(url, "_"))
|
|
s.Key = string(bytes.Trim(key, "\x01"))
|
|
}
|
|
|
|
func convertUTF16toUTF8(source []byte, endian unicode.Endianness) ([]byte, error) {
|
|
r, _, err := transform.Bytes(unicode.UTF16(endian, unicode.IgnoreBOM).NewDecoder(), source)
|
|
return r, err
|
|
}
|
|
|
|
// fillValue fills value of the storage
|
|
// TODO: support unicode charter
|
|
func (s *session) fillValue(b []byte) {
|
|
value := bytes.Map(byteutil.OnSplitUTF8Func, b)
|
|
s.Value = string(value)
|
|
}
|
|
|
|
type FirefoxSessionStorage []session
|
|
|
|
const (
|
|
querySessionStorage = `SELECT originKey, key, value FROM webappsstore2`
|
|
closeJournalMode = `PRAGMA journal_mode=off`
|
|
)
|
|
|
|
func (f *FirefoxSessionStorage) Parse(_ []byte) error {
|
|
db, err := sql.Open("sqlite3", item.FirefoxSessionStorage.TempFilename())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer os.Remove(item.FirefoxSessionStorage.TempFilename())
|
|
defer db.Close()
|
|
|
|
_, err = db.Exec(closeJournalMode)
|
|
if err != nil {
|
|
log.Error(err)
|
|
}
|
|
rows, err := db.Query(querySessionStorage)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
var originKey, key, value string
|
|
if err = rows.Scan(&originKey, &key, &value); err != nil {
|
|
log.Warn(err)
|
|
}
|
|
s := new(session)
|
|
s.fillFirefox(originKey, key, value)
|
|
*f = append(*f, *s)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *session) fillFirefox(originKey, key, value string) {
|
|
// originKey = moc.buhtig.:https:443
|
|
p := strings.Split(originKey, ":")
|
|
h := typeutil.Reverse([]byte(p[0]))
|
|
if bytes.HasPrefix(h, []byte(".")) {
|
|
h = h[1:]
|
|
}
|
|
if len(p) == 3 {
|
|
s.URL = fmt.Sprintf("%s://%s:%s", p[1], string(h), p[2])
|
|
}
|
|
s.Key = key
|
|
s.Value = value
|
|
}
|
|
|
|
func (f *FirefoxSessionStorage) Name() string {
|
|
return "sessionStorage"
|
|
}
|
|
|
|
func (f *FirefoxSessionStorage) Len() int {
|
|
return len(*f)
|
|
}
|