style: add more debug log
This commit is contained in:
parent
d7cad1b52d
commit
f5c3e6da5e
|
@ -103,7 +103,7 @@ Need install target OS's `gcc` library, here's an example of use `Mac` building
|
|||
```shell
|
||||
brew install mingw-w64
|
||||
|
||||
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="x86_64-w64-mingw32-gcc" go build
|
||||
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build
|
||||
```
|
||||
|
||||
#### For Linux
|
||||
|
|
|
@ -99,7 +99,7 @@ $ CGO_ENABLED=1 go build
|
|||
``` shell
|
||||
brew install mingw-w64
|
||||
|
||||
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="x86_64-w64-mingw32-gcc" go build
|
||||
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build
|
||||
```
|
||||
|
||||
#### Linux
|
||||
|
|
|
@ -49,7 +49,6 @@ func Execute() {
|
|||
browsers []browser.Browser
|
||||
err error
|
||||
)
|
||||
log.Debugf("browser: %s", browserName)
|
||||
browsers, err = browser.PickBrowser(browserName, profilePath)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
type Data struct {
|
||||
Sources map[item.Item]Source
|
||||
sources map[item.Item]Source
|
||||
}
|
||||
|
||||
type Source interface {
|
||||
|
@ -26,7 +26,7 @@ type Source interface {
|
|||
|
||||
func New(sources []item.Item) *Data {
|
||||
bd := &Data{
|
||||
Sources: make(map[item.Item]Source),
|
||||
sources: make(map[item.Item]Source),
|
||||
}
|
||||
bd.addSource(sources)
|
||||
return bd
|
||||
|
@ -34,9 +34,9 @@ func New(sources []item.Item) *Data {
|
|||
|
||||
func (d *Data) Recovery(masterKey []byte) error {
|
||||
|
||||
for _, source := range d.Sources {
|
||||
for _, source := range d.sources {
|
||||
if err := source.Parse(masterKey); err != nil {
|
||||
log.Error(err)
|
||||
log.Errorf("parse %s error %s", source.Name(), err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -45,16 +45,16 @@ func (d *Data) Recovery(masterKey []byte) error {
|
|||
func (d *Data) Output(dir, browserName, flag string) {
|
||||
output := NewOutPutter(flag)
|
||||
|
||||
for _, source := range d.Sources {
|
||||
for _, source := range d.sources {
|
||||
|
||||
filename := fileutil.Filename(browserName, source.Name(), output.Ext())
|
||||
|
||||
f, err := output.CreateFile(dir, filename)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Errorf("create file error %s", err)
|
||||
}
|
||||
if err := output.Write(source, f); err != nil {
|
||||
log.Error(err)
|
||||
log.Errorf("%s write to file %s error %s", source.Name(), filename, err.Error())
|
||||
}
|
||||
log.Noticef("output to file %s success", path.Join(dir, filename))
|
||||
}
|
||||
|
@ -64,31 +64,31 @@ func (d *Data) addSource(Sources []item.Item) {
|
|||
for _, source := range Sources {
|
||||
switch source {
|
||||
case item.ChromiumPassword:
|
||||
d.Sources[source] = &password.ChromiumPassword{}
|
||||
d.sources[source] = &password.ChromiumPassword{}
|
||||
case item.ChromiumCookie:
|
||||
d.Sources[source] = &cookie.ChromiumCookie{}
|
||||
d.sources[source] = &cookie.ChromiumCookie{}
|
||||
case item.ChromiumBookmark:
|
||||
d.Sources[source] = &bookmark.ChromiumBookmark{}
|
||||
d.sources[source] = &bookmark.ChromiumBookmark{}
|
||||
case item.ChromiumHistory:
|
||||
d.Sources[source] = &history.ChromiumHistory{}
|
||||
d.sources[source] = &history.ChromiumHistory{}
|
||||
case item.ChromiumDownload:
|
||||
d.Sources[source] = &download.ChromiumDownload{}
|
||||
d.sources[source] = &download.ChromiumDownload{}
|
||||
case item.ChromiumCreditCard:
|
||||
d.Sources[source] = &creditcard.ChromiumCreditCard{}
|
||||
d.sources[source] = &creditcard.ChromiumCreditCard{}
|
||||
case item.YandexPassword:
|
||||
d.Sources[source] = &password.YandexPassword{}
|
||||
d.sources[source] = &password.YandexPassword{}
|
||||
case item.YandexCreditCard:
|
||||
d.Sources[source] = &creditcard.YandexCreditCard{}
|
||||
d.sources[source] = &creditcard.YandexCreditCard{}
|
||||
case item.FirefoxPassword:
|
||||
d.Sources[source] = &password.FirefoxPassword{}
|
||||
d.sources[source] = &password.FirefoxPassword{}
|
||||
case item.FirefoxCookie:
|
||||
d.Sources[source] = &cookie.FirefoxCookie{}
|
||||
d.sources[source] = &cookie.FirefoxCookie{}
|
||||
case item.FirefoxBookmark:
|
||||
d.Sources[source] = &bookmark.FirefoxBookmark{}
|
||||
d.sources[source] = &bookmark.FirefoxBookmark{}
|
||||
case item.FirefoxHistory:
|
||||
d.Sources[source] = &history.FirefoxHistory{}
|
||||
d.sources[source] = &history.FirefoxHistory{}
|
||||
case item.FirefoxDownload:
|
||||
d.Sources[source] = &download.FirefoxDownload{}
|
||||
d.sources[source] = &download.FirefoxDownload{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,12 +46,11 @@ func pickChromium(name, profile string) []Browser {
|
|||
log.Noticef("find browser %s success", b.Name())
|
||||
browsers = append(browsers, b)
|
||||
} else {
|
||||
// TODO: show which browser find failed
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
if err == chromium.ErrProfilePathNotFound {
|
||||
log.Errorf("find browser %s failed, profile folder is not exist, maybe not installed", v.name)
|
||||
continue
|
||||
} else {
|
||||
log.Errorf("new chromium error:", err)
|
||||
log.Errorf("new chromium error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,10 +61,11 @@ func pickChromium(name, profile string) []Browser {
|
|||
}
|
||||
b, err := chromium.New(c.name, c.storage, profile, c.items)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
if err == chromium.ErrProfilePathNotFound {
|
||||
log.Fatalf("find browser %s failed, profile folder is not exist, maybe not installed", c.name)
|
||||
} else {
|
||||
log.Fatalf("new chromium error:", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
browsers = append(browsers, b)
|
||||
|
@ -89,13 +89,12 @@ func pickFirefox(name, profile string) []Browser {
|
|||
browsers = append(browsers, b)
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
if err == firefox.ErrProfilePathNotFound {
|
||||
log.Errorf("find browser firefox %s failed, profile folder is not exist", v.name)
|
||||
} else {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return browsers
|
||||
}
|
||||
|
@ -128,9 +127,5 @@ const (
|
|||
coccocName = "CocCoc"
|
||||
yandexName = "Yandex"
|
||||
|
||||
firefoxName = "Firefox"
|
||||
firefoxBetaName = "Firefox Beta"
|
||||
firefoxDevName = "Firefox Dev"
|
||||
firefoxNightlyName = "Firefox Nightly"
|
||||
firefoxESRName = "Firefox ESR"
|
||||
firefoxName = "Firefox"
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package chromium
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -22,6 +22,10 @@ type chromium struct {
|
|||
itemPaths map[item.Item]string
|
||||
}
|
||||
|
||||
var (
|
||||
ErrProfilePathNotFound = errors.New("profile path not found")
|
||||
)
|
||||
|
||||
// New create instance of chromium browser, fill item's path if item is existed.
|
||||
func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
|
||||
c := &chromium{
|
||||
|
@ -30,7 +34,7 @@ func New(name, storage, profilePath string, items []item.Item) (*chromium, error
|
|||
}
|
||||
// TODO: Handle file path is not exist
|
||||
if !fileutil.FolderExists(profilePath) {
|
||||
return nil, fmt.Errorf("%s profile folder is not exist: %s", name, profilePath)
|
||||
return nil, ErrProfilePathNotFound
|
||||
}
|
||||
itemsPaths, err := c.getItemPath(profilePath, items)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package firefox
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"hack-browser-data/internal/browingdata"
|
||||
"hack-browser-data/internal/item"
|
||||
"hack-browser-data/internal/log"
|
||||
"hack-browser-data/internal/utils/fileutil"
|
||||
"hack-browser-data/internal/utils/typeutil"
|
||||
)
|
||||
|
@ -23,10 +22,14 @@ type firefox struct {
|
|||
itemPaths map[item.Item]string
|
||||
}
|
||||
|
||||
var (
|
||||
ErrProfilePathNotFound = errors.New("profile path not found")
|
||||
)
|
||||
|
||||
// New returns a new firefox instance.
|
||||
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
|
||||
if !fileutil.FolderExists(profilePath) {
|
||||
return nil, fmt.Errorf("%s profile folder is not exist: %s", name, profilePath)
|
||||
return nil, ErrProfilePathNotFound
|
||||
}
|
||||
f := &firefox{
|
||||
name: name,
|
||||
|
@ -36,10 +39,6 @@ func New(name, storage, profilePath string, items []item.Item) ([]*firefox, erro
|
|||
}
|
||||
multiItemPaths, err := f.getMultiItemPath(f.profilePath, f.items)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
log.Error(err)
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var firefoxList []*firefox
|
||||
|
|
Loading…
Reference in New Issue