From 303e00cd289d0061f1227dc80ea42d8a0bae43e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=E1=B4=8F=E1=B4=8F=C9=B4D4=CA=80=E1=B4=8B?= Date: Sat, 2 Apr 2022 14:47:12 +0800 Subject: [PATCH] feat: rename item name --- go.mod | 3 - go.sum | 6 - internal/browser/browser.go | 221 -------------------------- internal/browser/browser_darwin.go | 22 +-- internal/browser/browser_windows.go | 6 +- internal/browser/chromium/chromium.go | 12 +- internal/browser/data/bookmark.go | 11 +- internal/browser/data/browsingdata.go | 4 +- internal/browser/firefox/firefox.go | 128 +++++++++++++++ internal/browser/item/filename.go | 47 ------ internal/browser/item/item.go | 165 ------------------- internal/item/filename.go | 26 +++ internal/item/item.go | 201 +++++++++++++++++++++++ internal/{browser => }/item/sql.go | 0 14 files changed, 387 insertions(+), 465 deletions(-) delete mode 100644 internal/browser/item/filename.go delete mode 100644 internal/browser/item/item.go create mode 100644 internal/item/filename.go create mode 100644 internal/item/item.go rename internal/{browser => }/item/sql.go (100%) diff --git a/go.mod b/go.mod index 75049e9..233bbdc 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,8 @@ go 1.18 require ( github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9 - github.com/godbus/dbus/v5 v5.0.3 github.com/json-iterator/go v1.1.12 - github.com/jszwec/csvutil v1.3.0 github.com/mattn/go-sqlite3 v1.14.9 - github.com/ppacher/go-dbus-keyring v1.0.1 github.com/tidwall/gjson v1.9.3 github.com/urfave/cli/v2 v2.2.0 golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 diff --git a/go.sum b/go.sum index 08103ca..87e5a74 100644 --- a/go.sum +++ b/go.sum @@ -6,13 +6,9 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9 h1:ptTza/LLPmfRtmz77X+6J61Wyf5e1hz5xYMvRk/hkE4= github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI= -github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME= -github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jszwec/csvutil v1.3.0 h1:d0zzXKQYvc22b4La5Wcp97CDgQ7JDLGJLm2NWqJGEYg= -github.com/jszwec/csvutil v1.3.0/go.mod h1:Rpu7Uu9giO9subDyMCIQfHVDuLrcaC36UA4YcJjGBkg= github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA= github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= @@ -21,8 +17,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 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/ppacher/go-dbus-keyring v1.0.1 h1:dM4dMfP5w9MxY+foFHCQiN7izEGpFdKr3tZeMGmvqD0= -github.com/ppacher/go-dbus-keyring v1.0.1/go.mod h1:JEmkRwBVPBFkOHedAsoZALWmhNJxR/R/ykkFpbEHtGE= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= diff --git a/internal/browser/browser.go b/internal/browser/browser.go index 9c02b40..7d5b7cc 100644 --- a/internal/browser/browser.go +++ b/internal/browser/browser.go @@ -1,16 +1,10 @@ package browser import ( - "fmt" - "io/fs" - "io/ioutil" "os" - "path" - "path/filepath" "strings" "hack-browser-data/internal/browser/data" - "hack-browser-data/internal/browser/item" ) type Browser interface { @@ -90,185 +84,6 @@ func pickFirefox(name string) []Browser { return nil } -type chromium struct { - browserInfo *browserInfo - items []item.Item - itemPaths map[item.Item]string -} - -// newChromium 根据浏览器信息生成 Browser Interface -func newChromium(info *browserInfo, items []item.Item) (*chromium, error) { - c := &chromium{ - browserInfo: info, - items: items, - } - absProfilePath := path.Join(homeDir, filepath.Clean(c.browserInfo.profilePath)) - // TODO: Handle file path is not exist - if !isFileExist(absProfilePath) { - return nil, fmt.Errorf("%s profile path is not exist", absProfilePath) - } - itemsPaths, err := getChromiumItemPath(absProfilePath, c.items) - if err != nil { - return nil, err - } - c.itemPaths = itemsPaths - return c, err -} - -func (c *chromium) GetName() string { - return c.browserInfo.name -} - -func (c *chromium) GetBrowsingData() []data.BrowsingData { - var browsingData []data.BrowsingData - for item := range c.itemPaths { - d := item.NewBrowsingData() - if d != nil { - browsingData = append(browsingData, d) - } - } - return browsingData -} - -func (c *chromium) CopyItemFileToLocal() error { - for item, sourcePath := range c.itemPaths { - var dstFilename = item.FileName() - locals, _ := filepath.Glob("*") - for _, v := range locals { - if v == dstFilename { - err := os.Remove(dstFilename) - // TODO: Should Continue all iteration error - if err != nil { - return err - } - } - } - - // TODO: Handle read file error - sourceFile, err := ioutil.ReadFile(sourcePath) - if err != nil { - fmt.Println(err.Error()) - } - err = ioutil.WriteFile(dstFilename, sourceFile, 0777) - if err != nil { - return err - } - } - return nil -} - -type firefox struct { - browserInfo *browserInfo - items []item.Item - itemPaths map[item.Item]string - multiItemPaths map[string]map[item.Item]string -} - -// newFirefox -func newMultiFirefox(info *browserInfo, items []item.Item) ([]*firefox, error) { - f := &firefox{ - browserInfo: info, - items: items, - } - multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items) - if err != nil { - if strings.Contains(err.Error(), "profile path is not exist") { - fmt.Println(err) - return nil, nil - } - panic(err) - } - var firefoxList []*firefox - for name, value := range multiItemPaths { - firefoxList = append(firefoxList, &firefox{ - browserInfo: &browserInfo{ - name: name, - masterKey: nil, - }, - items: items, - itemPaths: value, - }) - } - return firefoxList, nil -} - -func getFirefoxItemAbsPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { - var multiItemPaths = make(map[string]map[item.Item]string) - absProfilePath := path.Join(homeDir, filepath.Clean(profilePath)) - // TODO: Handle read file error - if !isFileExist(absProfilePath) { - return nil, fmt.Errorf("%s profile path is not exist", absProfilePath) - } - err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths)) - return multiItemPaths, err -} - -func (f *firefox) CopyItemFileToLocal() error { - for item, sourcePath := range f.itemPaths { - var dstFilename = item.FileName() - locals, _ := filepath.Glob("*") - for _, v := range locals { - if v == dstFilename { - err := os.Remove(dstFilename) - // TODO: Should Continue all iteration error - if err != nil { - return err - } - } - } - - // TODO: Handle read file name error - sourceFile, err := ioutil.ReadFile(sourcePath) - if err != nil { - fmt.Println(err.Error()) - } - err = ioutil.WriteFile(dstFilename, sourceFile, 0777) - if err != nil { - return err - } - } - return nil -} - -func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc { - return func(path string, info fs.FileInfo, err error) error { - for _, v := range items { - if info.Name() == v.DefaultName() { - parentDir := getParentDir(path) - if _, exist := multiItemPaths[parentDir]; exist { - multiItemPaths[parentDir][v] = path - } else { - multiItemPaths[parentDir] = map[item.Item]string{v: path} - } - } - } - return err - } -} - -func getParentDir(absPath string) string { - return filepath.Base(filepath.Dir(absPath)) -} - -func (f *firefox) GetMasterKey() ([]byte, error) { - return f.browserInfo.masterKey, nil -} - -func (f *firefox) GetName() string { - return f.browserInfo.name -} - -func (f *firefox) GetBrowsingData() []data.BrowsingData { - var browsingData []data.BrowsingData - for item := range f.itemPaths { - d := item.NewBrowsingData() - if d != nil { - browsingData = append(browsingData, d) - } - } - return browsingData -} - func ListBrowser() []string { var l []string for c := range chromiumList { @@ -313,39 +128,3 @@ const ( coccocName = "CocCoc" yandexName = "Yandex" ) - -var defaultFirefoxItems = []item.Item{ - item.firefoxKey4, - item.firefoxPassword, - item.firefoxCookie, - item.firefoxBookmark, - item.firefoxHistory, - item.firefoxDownload, - item.firefoxCreditCard, - item.firefoxLocalStorage, - item.firefoxExtension, -} - -var defaultYandexItems = []item.Item{ - item.chromiumKey, - item.yandexPassword, - item.chromiumCookie, - item.chromiumBookmark, - item.chromiumHistory, - item.chromiumDownload, - item.yandexCreditCard, - item.chromiumLocalStorage, - item.chromiumExtension, -} - -var defaultChromiumItems = []item.Item{ - item.chromiumKey, - item.chromiumPassword, - item.chromiumCookie, - item.chromiumBookmark, - item.chromiumHistory, - item.chromiumDownload, - item.chromiumCreditCard, - item.chromiumLocalStorage, - item.chromiumExtension, -} diff --git a/internal/browser/browser_darwin.go b/internal/browser/browser_darwin.go index 7a54eaa..d582ca1 100644 --- a/internal/browser/browser_darwin.go +++ b/internal/browser/browser_darwin.go @@ -8,7 +8,7 @@ import ( "golang.org/x/crypto/pbkdf2" - "hack-browser-data/internal/browser/item" + "hack-browser-data/internal/item" ) var ( @@ -18,43 +18,43 @@ var ( }{ "chrome": { browserInfo: chromeInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "edge": { browserInfo: edgeInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "chromium": { browserInfo: chromiumInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "chrome-beta": { browserInfo: chromeBetaInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "opera": { browserInfo: operaInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "opera-gx": { browserInfo: operaGXInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "vivaldi": { browserInfo: vivaldiInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "coccoc": { browserInfo: coccocInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "brave": { browserInfo: braveInfo, - items: defaultChromiumItems, + items: item.DefaultChromium, }, "yandex": { browserInfo: yandexInfo, - items: defaultYandexItems, + items: item.DefaultYandex, }, } firefoxList = map[string]struct { diff --git a/internal/browser/browser_windows.go b/internal/browser/browser_windows.go index 2ae20d1..3f8e91b 100644 --- a/internal/browser/browser_windows.go +++ b/internal/browser/browser_windows.go @@ -7,14 +7,16 @@ import ( "github.com/tidwall/gjson" "hack-browser-data/internal/browser/item" + "hack-browser-data/internal/decrypter" + item2 "hack-browser-data/internal/item" "hack-browser-data/internal/utils" ) var ( chromiumList = map[string]struct { browserInfo *browserInfo - items []item.Item + items []item2.Item }{ "chrome": { browserInfo: chromeInfo, @@ -31,7 +33,7 @@ var ( } firefoxList = map[string]struct { browserInfo *browserInfo - items []item.Item + items []item2.Item }{ "firefox": { browserInfo: firefoxInfo, diff --git a/internal/browser/chromium/chromium.go b/internal/browser/chromium/chromium.go index b3063e0..874b673 100644 --- a/internal/browser/chromium/chromium.go +++ b/internal/browser/chromium/chromium.go @@ -9,7 +9,7 @@ import ( "strings" "hack-browser-data/internal/browser/data" - "hack-browser-data/internal/browser/item" + "hack-browser-data/internal/item" ) type chromium struct { @@ -21,15 +21,15 @@ type chromium struct { itemPaths map[item.Item]string } -// newChromium 根据浏览器信息生成 Browser Interface -func newChromium(name, storage, profilePath string, items []item.Item) (*chromium, error) { +// New 根据浏览器信息生成 Browser Interface +func New(name, storage, profilePath string, items []item.Item) (*chromium, error) { c := &chromium{ name: name, storage: storage, profilePath: profilePath, items: items, } - absProfilePath := path.Join(homeDir, filepath.Clean(c.browserInfo.profilePath)) + absProfilePath := path.Join(homeDir, filepath.Clean(c.ProfilePath)) // TODO: Handle file path is not exist if !isFileExist(absProfilePath) { return nil, fmt.Errorf("%s profile path is not exist", absProfilePath) @@ -59,7 +59,7 @@ func (c *chromium) GetBrowsingData() []data.BrowsingData { func (c *chromium) CopyItemFileToLocal() error { for item, sourcePath := range c.itemPaths { - var dstFilename = item.FileName() + var dstFilename = item.TempName() locals, _ := filepath.Glob("*") for _, v := range locals { if v == dstFilename { @@ -94,7 +94,7 @@ func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string) filepat return func(path string, info os.FileInfo, err error) error { for _, it := range items { switch { - case it.DefaultName() == info.Name(): + case it.FileName() == info.Name(): if it == it.chromiumKey { itemPaths[it] = path } diff --git a/internal/browser/data/bookmark.go b/internal/browser/data/bookmark.go index 7c21c30..dae1913 100644 --- a/internal/browser/data/bookmark.go +++ b/internal/browser/data/bookmark.go @@ -8,10 +8,15 @@ import ( "github.com/tidwall/gjson" "hack-browser-data/internal/browser/item" + + item2 "hack-browser-data/internal/item" "hack-browser-data/internal/utils" ) -type ChromiumBookmark []bookmark +type ChromiumBookmark struct { + bookmarks []bookmark + item item2.Item +} func (c *ChromiumBookmark) Parse(masterKey []byte) error { bookmarks, err := utils.ReadFile(item.ChromiumBookmarkFilename) @@ -27,8 +32,8 @@ func (c *ChromiumBookmark) Parse(masterKey []byte) error { }) } // TODO: 使用泛型重构 - sort.Slice(*c, func(i, j int) bool { - return (*c)[i].DateAdded.After((*c)[j].DateAdded) + sort.Slice(c.bookmarks, func(i, j int) bool { + return (c.bookmarks)[i].DateAdded.After((c.bookmarks)[j].DateAdded) }) return nil } diff --git a/internal/browser/data/browsingdata.go b/internal/browser/data/browsingdata.go index b5586ef..f01dadd 100644 --- a/internal/browser/data/browsingdata.go +++ b/internal/browser/data/browsingdata.go @@ -1,6 +1,8 @@ package data -import "time" +import ( + "time" +) type BrowsingData interface { Parse(masterKey []byte) error diff --git a/internal/browser/firefox/firefox.go b/internal/browser/firefox/firefox.go index 2b4484a..12a22da 100644 --- a/internal/browser/firefox/firefox.go +++ b/internal/browser/firefox/firefox.go @@ -1 +1,129 @@ package firefox + +import ( + "fmt" + "io/fs" + "io/ioutil" + "os" + "path" + "path/filepath" + "strings" + + "hack-browser-data/internal/browser/data" + "hack-browser-data/internal/item" +) + +type firefox struct { + name string + storage string + profilePath string + masterKey []byte + items []item.Item + itemPaths map[item.Item]string + multiItemPaths map[string]map[item.Item]string +} + +// New +func New(info *browserInfo, items []item.Item) ([]*firefox, error) { + f := &firefox{ + browserInfo: info, + items: items, + } + multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items) + if err != nil { + if strings.Contains(err.Error(), "profile path is not exist") { + fmt.Println(err) + return nil, nil + } + panic(err) + } + var firefoxList []*firefox + for name, value := range multiItemPaths { + firefoxList = append(firefoxList, &firefox{ + browserInfo: &browserInfo{ + name: name, + masterKey: nil, + }, + items: items, + itemPaths: value, + }) + } + return firefoxList, nil +} + +func getFirefoxItemAbsPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { + var multiItemPaths = make(map[string]map[item.Item]string) + absProfilePath := path.Join(homeDir, filepath.Clean(profilePath)) + // TODO: Handle read file error + if !isFileExist(absProfilePath) { + return nil, fmt.Errorf("%s profile path is not exist", absProfilePath) + } + err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths)) + return multiItemPaths, err +} + +func (f *firefox) CopyItemFileToLocal() error { + for item, sourcePath := range f.itemPaths { + var dstFilename = item.TempName() + locals, _ := filepath.Glob("*") + for _, v := range locals { + if v == dstFilename { + err := os.Remove(dstFilename) + // TODO: Should Continue all iteration error + if err != nil { + return err + } + } + } + + // TODO: Handle read file name error + sourceFile, err := ioutil.ReadFile(sourcePath) + if err != nil { + fmt.Println(err.Error()) + } + err = ioutil.WriteFile(dstFilename, sourceFile, 0777) + if err != nil { + return err + } + } + return nil +} + +func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc { + return func(path string, info fs.FileInfo, err error) error { + for _, v := range items { + if info.Name() == v.FileName() { + parentDir := getParentDir(path) + if _, exist := multiItemPaths[parentDir]; exist { + multiItemPaths[parentDir][v] = path + } else { + multiItemPaths[parentDir] = map[item.Item]string{v: path} + } + } + } + return err + } +} + +func getParentDir(absPath string) string { + return filepath.Base(filepath.Dir(absPath)) +} + +func (f *firefox) GetMasterKey() ([]byte, error) { + return f.masterKey, nil +} + +func (f *firefox) GetName() string { + return f.name +} + +func (f *firefox) GetBrowsingData() []data.BrowsingData { + var browsingData []data.BrowsingData + for item := range f.itemPaths { + d := item.NewBrowsingData() + if d != nil { + browsingData = append(browsingData, d) + } + } + return browsingData +} diff --git a/internal/browser/item/filename.go b/internal/browser/item/filename.go deleted file mode 100644 index d8172ab..0000000 --- a/internal/browser/item/filename.go +++ /dev/null @@ -1,47 +0,0 @@ -package item - -// item's default filename -const ( - FileChromiumKey = "Local State" - FileChromiumCredit = "Web Data" - FileChromiumPassword = "Login Data" - FileChromiumHistory = "History" - FileChromiumDownload = "History" - FileChromiumCookie = "Cookies" - FileChromiumBookmark = "Bookmarks" - FileChromiumLocalStorage = "chromiumLocalStorage" - - FileYandexPassword = "Ya PassMan Data" - FileYandexCredit = "Ya Credit Cards" - - FileFirefoxKey4 = "key4.db" - FileFirefoxCookie = "cookies.sqlite" - FileFirefoxPassword = "logins.json" - FileFirefoxData = "places.sqlite" - - FileUnknownItem = "unknown item" - FileUnsupportedItem = "unsupported item" -) - -// item's renamed filename -const ( - TempChromiumKey = "TempChromiumKey" - TempChromiumCredit = "TempChromiumCredit" - TempChromiumPassword = "TempChromiumPassword" - TempChromiumHistory = "TempChromiumHistory" - TempChromiumDownload = "TempChromiumDownload" - TempChromiumCookie = "TempChromiumCookie" - TempChromiumBookmark = "TempChromiumBookmark" - TempChromiumLocalStorage = "TempChromiumLocalStorage" - - TempYandexPassword = "TempYandexPassword" - TempYandexCredit = "TempYandexCredit" - - TempFirefoxKey4 = "TempFirefoxKey4" - TempFirefoxCookie = "TempFirefoxCookie" - TempFirefoxPassword = "TempFirefoxPassword" - TempFirefoxDownload = "TempFirefoxDownload" - TempFirefoxHistory = "TempFirefoxHistory" - TempFirefoxBookmark = "TempFirefoxBookmark" - TempFirefoxData = "TempFirefoxData" -) diff --git a/internal/browser/item/item.go b/internal/browser/item/item.go deleted file mode 100644 index 0d1738c..0000000 --- a/internal/browser/item/item.go +++ /dev/null @@ -1,165 +0,0 @@ -package item - -import ( - data2 "hack-browser-data/internal/browser/data" -) - -type Item int - -const ( - ItemChromiumKey Item = iota - ItemChromiumPassword - ItemChromiumCookie - ItemChromiumBookmark - ItemChromiumHistory - ItemChromiumDownload - ItemChromiumCreditCard - ItemChromiumLocalStorage - ItemChromiumExtension - - ItemYandexPassword - ItemYandexCreditCard - - ItemFirefoxKey4 - ItemFirefoxPassword - ItemFirefoxCookie - ItemFirefoxBookmark - ItemFirefoxHistory - ItemFirefoxDownload - ItemFirefoxCreditCard - ItemFirefoxLocalStorage - ItemFirefoxExtension -) - -func (i Item) DefaultName() string { - switch i { - case ItemChromiumKey: - return ChromiumKey - case ItemChromiumPassword: - return ChromiumPassword - case ItemChromiumCookie: - return ChromiumCookie - case ItemChromiumBookmark: - return ChromiumBookmark - case ItemChromiumDownload: - return ChromiumDownload - case ItemChromiumLocalStorage: - return ChromiumLocalStorage - case ItemChromiumCreditCard: - return ChromiumCredit - case ItemChromiumExtension: - return UnknownItem - case ItemChromiumHistory: - return ChromiumHistory - case ItemYandexPassword: - return YandexPassword - case ItemYandexCreditCard: - return YandexCredit - case ItemFirefoxKey4: - return FirefoxKey4 - case ItemFirefoxPassword: - return FirefoxPassword - case ItemFirefoxCookie: - return FirefoxCookie - case ItemFirefoxBookmark: - return FirefoxData - case ItemFirefoxDownload: - return FirefoxData - case ItemFirefoxLocalStorage: - return UnsupportedItem - case ItemFirefoxCreditCard: - return UnsupportedItem - case ItemFirefoxHistory: - return FirefoxData - case ItemFirefoxExtension: - return UnsupportedItem - default: - return UnknownItem - } -} - -func (i Item) FileName() string { - switch i { - case chromiumKey: - return TempChromiumKey - case chromiumPassword: - return TempChromiumPassword - case chromiumCookie: - return ChromiumCookieFilename - case chromiumBookmark: - return ChromiumBookmarkFilename - case chromiumDownload: - return ChromiumDownloadFilename - case chromiumLocalStorage: - return ChromiumLocalStorageFilename - case chromiumCreditCard: - return TempChromiumCredit - case chromiumHistory: - return TempChromiumHistory - case chromiumExtension: - return UnsupportedItem - case yandexPassword: - return TempChromiumPassword - case yandexCreditCard: - return TempChromiumCredit - case firefoxKey4: - return FirefoxKey4Filename - case firefoxPassword: - return FirefoxPasswordFilename - case firefoxCookie: - return FirefoxCookieFilename - case firefoxBookmark: - return FirefoxBookmarkFilename - case firefoxDownload: - return FirefoxDownloadFilename - case firefoxLocalStorage: - return UnsupportedItem - case firefoxCreditCard: - return UnsupportedItem - case firefoxHistory: - return FirefoxHistoryFilename - case firefoxExtension: - return UnsupportedItem - default: - return UnknownItem - } -} - -func (i Item) NewBrowsingData() data2.BrowsingData { - switch i { - case chromiumKey: - return nil - case chromiumPassword: - return &data2.ChromiumPassword{} - case chromiumCookie: - return &data2.ChromiumCookie{} - case chromiumBookmark: - return &data2.ChromiumBookmark{} - case chromiumDownload: - return &data2.ChromiumDownload{} - case chromiumLocalStorage: - return nil - case chromiumCreditCard: - return &data2.ChromiumCreditCard{} - case chromiumExtension: - return nil - case chromiumHistory: - return &data2.ChromiumHistory{} - case yandexPassword: - return &data2.ChromiumPassword{} - case yandexCreditCard: - return &data2.ChromiumCreditCard{} - case firefoxPassword: - return &data2.FirefoxPassword{} - case firefoxCookie: - return &data2.FirefoxCookie{} - case firefoxBookmark: - return &data2.FirefoxBookmark{} - case firefoxDownload: - return &data2.FirefoxDownload{} - case firefoxHistory: - return &data2.FirefoxHistory{} - default: - return nil - } -} diff --git a/internal/item/filename.go b/internal/item/filename.go new file mode 100644 index 0000000..15741d3 --- /dev/null +++ b/internal/item/filename.go @@ -0,0 +1,26 @@ +package item + +// item's default filename +const ( + fileChromiumKey = "Local State" + fileChromiumCredit = "Web Data" + fileChromiumPassword = "Login Data" + fileChromiumHistory = "History" + fileChromiumDownload = "History" + fileChromiumCookie = "Cookies" + fileChromiumBookmark = "Bookmarks" + fileChromiumLocalStorage = "chromiumLocalStorage" + + fileYandexPassword = "Ya PassMan Data" + fileYandexCredit = "Ya Credit Cards" + + fileFirefoxKey4 = "key4.db" + fileFirefoxCookie = "cookies.sqlite" + fileFirefoxPassword = "logins.json" + fileFirefoxData = "places.sqlite" +) + +const ( + UnknownItem = "unknown item" + UnsupportedItem = "unsupported item" +) diff --git a/internal/item/item.go b/internal/item/item.go new file mode 100644 index 0000000..79f3933 --- /dev/null +++ b/internal/item/item.go @@ -0,0 +1,201 @@ +package item + +import ( + "hack-browser-data/internal/browser/data" +) + +type Item int + +const ( + ChromiumKey Item = iota + ChromiumPassword + ChromiumCookie + ChromiumBookmark + ChromiumHistory + ChromiumDownload + ChromiumCreditCard + ChromiumLocalStorage + ChromiumExtension + + YandexPassword + YandexCreditCard + + FirefoxKey4 + FirefoxPassword + FirefoxCookie + FirefoxBookmark + FirefoxHistory + FirefoxDownload + FirefoxCreditCard + FirefoxLocalStorage + FirefoxExtension +) + +var DefaultFirefox = []Item{ + FirefoxKey4, + FirefoxPassword, + FirefoxCookie, + FirefoxBookmark, + FirefoxHistory, + FirefoxDownload, + FirefoxCreditCard, + FirefoxLocalStorage, + FirefoxExtension, +} + +var DefaultYandex = []Item{ + ChromiumKey, + ChromiumCookie, + ChromiumBookmark, + ChromiumHistory, + ChromiumDownload, + ChromiumLocalStorage, + ChromiumExtension, + YandexPassword, + YandexCreditCard, +} + +var DefaultChromium = []Item{ + ChromiumKey, + ChromiumPassword, + ChromiumCookie, + ChromiumBookmark, + ChromiumHistory, + ChromiumDownload, + ChromiumCreditCard, + ChromiumLocalStorage, + ChromiumExtension, +} + +func (i Item) FileName() string { + switch i { + case ChromiumKey: + return fileChromiumKey + case ChromiumPassword: + return fileChromiumPassword + case ChromiumCookie: + return fileChromiumCookie + case ChromiumBookmark: + return fileChromiumBookmark + case ChromiumDownload: + return fileChromiumDownload + case ChromiumLocalStorage: + return fileChromiumLocalStorage + case ChromiumCreditCard: + return fileChromiumCredit + case ChromiumExtension: + return UnknownItem + case ChromiumHistory: + return fileChromiumHistory + case YandexPassword: + return fileYandexPassword + case YandexCreditCard: + return fileYandexCredit + case FirefoxKey4: + return fileFirefoxKey4 + case FirefoxPassword: + return fileFirefoxPassword + case FirefoxCookie: + return fileFirefoxCookie + case FirefoxBookmark: + return fileFirefoxData + case FirefoxDownload: + return fileFirefoxData + case FirefoxLocalStorage: + return UnsupportedItem + case FirefoxCreditCard: + return UnsupportedItem + case FirefoxHistory: + return fileFirefoxData + case FirefoxExtension: + return UnsupportedItem + default: + return UnknownItem + } +} + +func (i Item) String() string { + switch i { + case ChromiumKey: + return "chromiumKey" + case ChromiumPassword: + return "password" + case ChromiumCookie: + return "cookie" + case ChromiumBookmark: + return "bookmark" + case ChromiumDownload: + return "download" + case ChromiumLocalStorage: + return "localStorage" + case ChromiumCreditCard: + return "creditCard" + case ChromiumExtension: + return UnsupportedItem + case ChromiumHistory: + return "history" + case YandexPassword: + return "yandexPassword" + case YandexCreditCard: + return "yandexCreditCard" + case FirefoxKey4: + return "firefoxKey4" + case FirefoxPassword: + return "firefoxPassword" + case FirefoxCookie: + return "firefoxCookie" + case FirefoxBookmark: + return "firefoxBookmark" + case FirefoxDownload: + return "firefoxDownload" + case FirefoxHistory: + return "firefoxHistory" + case FirefoxLocalStorage: + return UnsupportedItem + case FirefoxCreditCard: + return UnsupportedItem + case FirefoxExtension: + return UnsupportedItem + default: + return UnknownItem + } +} + +func (i Item) NewBrowsingData() data.BrowsingData { + switch i { + case ChromiumKey: + return nil + case ChromiumPassword: + return &data.ChromiumPassword{} + case ChromiumCookie: + return &data.ChromiumCookie{} + case ChromiumBookmark: + return &data.ChromiumBookmark{} + case ChromiumDownload: + return &data.ChromiumDownload{} + case ChromiumLocalStorage: + return nil + case ChromiumCreditCard: + return &data.ChromiumCreditCard{} + case ChromiumExtension: + return nil + case ChromiumHistory: + return &data.ChromiumHistory{} + case YandexPassword: + return &data.ChromiumPassword{} + case YandexCreditCard: + return &data.ChromiumCreditCard{} + case FirefoxPassword: + return &data.FirefoxPassword{} + case FirefoxCookie: + return &data.FirefoxCookie{} + case FirefoxBookmark: + return &data.FirefoxBookmark{} + case FirefoxDownload: + return &data.FirefoxDownload{} + case FirefoxHistory: + return &data.FirefoxHistory{} + default: + return nil + } +} diff --git a/internal/browser/item/sql.go b/internal/item/sql.go similarity index 100% rename from internal/browser/item/sql.go rename to internal/item/sql.go