mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
feat: rename item name
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user