HackBrowserData/internal/browingdata/browsingdata.go

100 lines
2.8 KiB
Go
Raw Normal View History

package browingdata
2022-04-02 06:47:12 +00:00
import (
2022-04-17 16:47:39 +00:00
"path"
"hack-browser-data/internal/browingdata/bookmark"
"hack-browser-data/internal/browingdata/cookie"
"hack-browser-data/internal/browingdata/creditcard"
"hack-browser-data/internal/browingdata/download"
"hack-browser-data/internal/browingdata/history"
2022-04-19 13:28:43 +00:00
"hack-browser-data/internal/browingdata/localstorage"
"hack-browser-data/internal/browingdata/password"
"hack-browser-data/internal/item"
2022-04-12 03:29:01 +00:00
"hack-browser-data/internal/log"
2022-04-17 16:47:39 +00:00
"hack-browser-data/internal/utils/fileutil"
2022-04-02 06:47:12 +00:00
)
2022-01-11 10:19:17 +00:00
2022-04-11 07:53:19 +00:00
type Data struct {
2022-04-19 11:35:30 +00:00
sources map[item.Item]Source
}
type Source interface {
Parse(masterKey []byte) error
Name() string
}
2022-01-11 10:19:17 +00:00
2022-04-11 07:53:19 +00:00
func New(sources []item.Item) *Data {
bd := &Data{
2022-04-19 11:35:30 +00:00
sources: make(map[item.Item]Source),
}
bd.addSource(sources)
return bd
}
2022-04-11 07:53:19 +00:00
func (d *Data) Recovery(masterKey []byte) error {
2022-04-19 11:35:30 +00:00
for _, source := range d.sources {
2022-04-11 07:53:19 +00:00
if err := source.Parse(masterKey); err != nil {
2022-04-19 11:35:30 +00:00
log.Errorf("parse %s error %s", source.Name(), err.Error())
2022-04-11 07:53:19 +00:00
}
}
return nil
}
func (d *Data) Output(dir, browserName, flag string) {
output := NewOutPutter(flag)
2022-04-17 16:47:39 +00:00
2022-04-19 11:35:30 +00:00
for _, source := range d.sources {
2022-04-17 16:47:39 +00:00
filename := fileutil.Filename(browserName, source.Name(), output.Ext())
2022-04-17 16:47:39 +00:00
f, err := output.CreateFile(dir, filename)
2022-04-17 16:47:39 +00:00
if err != nil {
2022-04-19 11:35:30 +00:00
log.Errorf("create file error %s", err)
2022-04-17 16:47:39 +00:00
}
if err := output.Write(source, f); err != nil {
2022-04-19 11:35:30 +00:00
log.Errorf("%s write to file %s error %s", source.Name(), filename, err.Error())
2022-04-17 16:47:39 +00:00
}
log.Noticef("output to file %s success", path.Join(dir, filename))
}
}
2022-04-11 07:53:19 +00:00
func (d *Data) addSource(Sources []item.Item) {
for _, source := range Sources {
switch source {
case item.ChromiumPassword:
2022-04-19 11:35:30 +00:00
d.sources[source] = &password.ChromiumPassword{}
case item.ChromiumCookie:
2022-04-19 11:35:30 +00:00
d.sources[source] = &cookie.ChromiumCookie{}
case item.ChromiumBookmark:
2022-04-19 11:35:30 +00:00
d.sources[source] = &bookmark.ChromiumBookmark{}
case item.ChromiumHistory:
2022-04-19 11:35:30 +00:00
d.sources[source] = &history.ChromiumHistory{}
case item.ChromiumDownload:
2022-04-19 11:35:30 +00:00
d.sources[source] = &download.ChromiumDownload{}
case item.ChromiumCreditCard:
2022-04-19 11:35:30 +00:00
d.sources[source] = &creditcard.ChromiumCreditCard{}
2022-04-19 13:28:43 +00:00
case item.ChromiumLocalStorage:
d.sources[source] = &localstorage.ChromiumLocalStorage{}
case item.YandexPassword:
2022-04-19 11:35:30 +00:00
d.sources[source] = &password.YandexPassword{}
case item.YandexCreditCard:
2022-04-19 11:35:30 +00:00
d.sources[source] = &creditcard.YandexCreditCard{}
case item.FirefoxPassword:
2022-04-19 11:35:30 +00:00
d.sources[source] = &password.FirefoxPassword{}
case item.FirefoxCookie:
2022-04-19 11:35:30 +00:00
d.sources[source] = &cookie.FirefoxCookie{}
case item.FirefoxBookmark:
2022-04-19 11:35:30 +00:00
d.sources[source] = &bookmark.FirefoxBookmark{}
case item.FirefoxHistory:
2022-04-19 11:35:30 +00:00
d.sources[source] = &history.FirefoxHistory{}
case item.FirefoxDownload:
2022-04-19 11:35:30 +00:00
d.sources[source] = &download.FirefoxDownload{}
2022-04-19 13:28:43 +00:00
case item.FirefoxLocalStorage:
d.sources[source] = &localstorage.FirefoxLocalStorage{}
}
}
}