feat: support export chromium local storage

pull/125/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 2452b2670a
commit 4fe266d954
  1. 1
      go.mod
  2. 7
      go.sum
  3. 14
      internal/browingdata/localstorage/localstorage.go
  4. 40
      internal/browser/chromium/chromium.go
  5. 23
      internal/utils/fileutil/filetutil.go

@ -9,6 +9,7 @@ require (
github.com/gookit/slog v0.2.2-0.20220415153407-dd89ed7b0448 github.com/gookit/slog v0.2.2-0.20220415153407-dd89ed7b0448
github.com/json-iterator/go v1.1.12 github.com/json-iterator/go v1.1.12
github.com/mattn/go-sqlite3 v1.14.9 github.com/mattn/go-sqlite3 v1.14.9
github.com/otiai10/copy v1.7.0
github.com/ppacher/go-dbus-keyring v1.0.1 github.com/ppacher/go-dbus-keyring v1.0.1
github.com/syndtr/goleveldb v1.0.0 github.com/syndtr/goleveldb v1.0.0
github.com/tidwall/gjson v1.9.3 github.com/tidwall/gjson v1.9.3

@ -38,6 +38,13 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ppacher/go-dbus-keyring v1.0.1 h1:dM4dMfP5w9MxY+foFHCQiN7izEGpFdKr3tZeMGmvqD0= github.com/ppacher/go-dbus-keyring v1.0.1 h1:dM4dMfP5w9MxY+foFHCQiN7izEGpFdKr3tZeMGmvqD0=

@ -5,7 +5,6 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"os" "os"
"path"
"strings" "strings"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
@ -25,11 +24,11 @@ type storage struct {
} }
func (c *ChromiumLocalStorage) Parse(masterKey []byte) error { func (c *ChromiumLocalStorage) Parse(masterKey []byte) error {
home, _ := os.UserHomeDir() db, err := leveldb.OpenFile(item.TempChromiumLocalStorage, nil)
db, err := leveldb.OpenFile(path.Join(home, "tmp/Local Storage/leveldb"), nil)
if err != nil { if err != nil {
return err return err
} }
defer os.RemoveAll(item.TempChromiumLocalStorage)
// log.Info("parsing local storage now") // log.Info("parsing local storage now")
defer db.Close() defer db.Close()
@ -37,10 +36,17 @@ func (c *ChromiumLocalStorage) Parse(masterKey []byte) error {
for iter.Next() { for iter.Next() {
key := iter.Key() key := iter.Key()
value := iter.Value() value := iter.Value()
// don't parse value upper than 5kB
if len(value) > 1024*5 {
continue
}
var s = new(storage) var s = new(storage)
s.fillKey(key) s.fillKey(key)
s.fillValue(value) s.fillValue(value)
// don't save meta data
if s.IsMeta {
continue
}
*c = append(*c, *s) *c = append(*c, *s)
} }
iter.Release() iter.Release()

@ -71,16 +71,21 @@ func (c *chromium) BrowsingData() (*browingdata.Data, error) {
func (c *chromium) copyItemToLocal() error { func (c *chromium) copyItemToLocal() error {
for i, path := range c.itemPaths { for i, path := range c.itemPaths {
// var dstFilename = item.TempName() if fileutil.FolderExists(path) {
var filename = i.String() if err := fileutil.CopyDir(path, i.String()); err != nil {
// TODO: Handle read file error return err
d, err := ioutil.ReadFile(path) }
if err != nil { } else {
return err var filename = i.String()
} // TODO: Handle read file error
err = ioutil.WriteFile(filename, d, 0777) d, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
return err return err
}
err = ioutil.WriteFile(filename, d, 0777)
if err != nil {
return err
}
} }
} }
return nil return nil
@ -91,7 +96,11 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
parentDir := fileutil.ParentDir(profilePath) parentDir := fileutil.ParentDir(profilePath)
baseDir := fileutil.BaseDir(profilePath) baseDir := fileutil.BaseDir(profilePath)
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir)) err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
return itemPaths, err if err != nil {
return itemPaths, err
}
fillLocalStoragePath(itemPaths, item.ChromiumLocalStorage)
return itemPaths, nil
} }
func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string, baseDir string) filepath.WalkFunc { func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string, baseDir string) filepath.WalkFunc {
@ -110,3 +119,12 @@ func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string, baseDir
return err return err
} }
} }
func fillLocalStoragePath(itemPaths map[item.Item]string, storage item.Item) {
if p, ok := itemPaths[item.ChromiumHistory]; ok {
lsp := filepath.Join(filepath.Dir(p), storage.FileName())
if fileutil.FolderExists(lsp) {
itemPaths[item.ChromiumLocalStorage] = lsp
}
}
}

@ -10,8 +10,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log" "hack-browser-data/internal/log"
cp "github.com/otiai10/copy"
) )
// FileExists checks if the file exists in the provided path // FileExists checks if the file exists in the provided path
@ -44,22 +45,8 @@ func ReadFile(filename string) (string, error) {
return string(s), err return string(s), err
} }
// CopyItemToLocal copies the file from the provided path to the local path func CopyDir(src, dst string) error {
func CopyItemToLocal(itemPaths map[item.Item]string) error { return cp.Copy(src, dst)
for i, p := range itemPaths {
// var dstFilename = item.TempName()
var filename = i.String()
// TODO: Handle read file error
d, err := ioutil.ReadFile(p)
if err != nil {
log.Error(err.Error())
}
err = ioutil.WriteFile(filename, d, 0777)
if err != nil {
return err
}
}
return nil
} }
func Filename(browser, item, ext string) string { func Filename(browser, item, ext string) string {
@ -68,7 +55,7 @@ func Filename(browser, item, ext string) string {
} }
func ParentDir(p string) string { func ParentDir(p string) string {
return filepath.Dir(p) return filepath.Dir(filepath.Clean(p))
} }
func BaseDir(p string) string { func BaseDir(p string) string {

Loading…
Cancel
Save