style: add more debug log

pull/125/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent d7cad1b52d
commit f5c3e6da5e
  1. 2
      README.md
  2. 2
      README_ZH.md
  3. 1
      cmd/hack-browser-data/main.go
  4. 40
      internal/browingdata/browsingdata.go
  5. 17
      internal/browser/browser.go
  6. 8
      internal/browser/chromium/chromium.go
  7. 13
      internal/browser/firefox/firefox.go

@ -103,7 +103,7 @@ Need install target OS's `gcc` library, here's an example of use `Mac` building
```shell ```shell
brew install mingw-w64 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 #### For Linux

@ -99,7 +99,7 @@ $ CGO_ENABLED=1 go build
``` shell ``` shell
brew install mingw-w64 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 #### Linux

@ -49,7 +49,6 @@ func Execute() {
browsers []browser.Browser browsers []browser.Browser
err error err error
) )
log.Debugf("browser: %s", browserName)
browsers, err = browser.PickBrowser(browserName, profilePath) browsers, err = browser.PickBrowser(browserName, profilePath)
if err != nil { if err != nil {
log.Error(err) log.Error(err)

@ -15,7 +15,7 @@ import (
) )
type Data struct { type Data struct {
Sources map[item.Item]Source sources map[item.Item]Source
} }
type Source interface { type Source interface {
@ -26,7 +26,7 @@ type Source interface {
func New(sources []item.Item) *Data { func New(sources []item.Item) *Data {
bd := &Data{ bd := &Data{
Sources: make(map[item.Item]Source), sources: make(map[item.Item]Source),
} }
bd.addSource(sources) bd.addSource(sources)
return bd return bd
@ -34,9 +34,9 @@ func New(sources []item.Item) *Data {
func (d *Data) Recovery(masterKey []byte) error { func (d *Data) Recovery(masterKey []byte) error {
for _, source := range d.Sources { for _, source := range d.sources {
if err := source.Parse(masterKey); err != nil { if err := source.Parse(masterKey); err != nil {
log.Error(err) log.Errorf("parse %s error %s", source.Name(), err.Error())
} }
} }
return nil return nil
@ -45,16 +45,16 @@ func (d *Data) Recovery(masterKey []byte) error {
func (d *Data) Output(dir, browserName, flag string) { func (d *Data) Output(dir, browserName, flag string) {
output := NewOutPutter(flag) output := NewOutPutter(flag)
for _, source := range d.Sources { for _, source := range d.sources {
filename := fileutil.Filename(browserName, source.Name(), output.Ext()) filename := fileutil.Filename(browserName, source.Name(), output.Ext())
f, err := output.CreateFile(dir, filename) f, err := output.CreateFile(dir, filename)
if err != nil { if err != nil {
log.Error(err) log.Errorf("create file error %s", err)
} }
if err := output.Write(source, f); err != nil { 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)) 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 { for _, source := range Sources {
switch source { switch source {
case item.ChromiumPassword: case item.ChromiumPassword:
d.Sources[source] = &password.ChromiumPassword{} d.sources[source] = &password.ChromiumPassword{}
case item.ChromiumCookie: case item.ChromiumCookie:
d.Sources[source] = &cookie.ChromiumCookie{} d.sources[source] = &cookie.ChromiumCookie{}
case item.ChromiumBookmark: case item.ChromiumBookmark:
d.Sources[source] = &bookmark.ChromiumBookmark{} d.sources[source] = &bookmark.ChromiumBookmark{}
case item.ChromiumHistory: case item.ChromiumHistory:
d.Sources[source] = &history.ChromiumHistory{} d.sources[source] = &history.ChromiumHistory{}
case item.ChromiumDownload: case item.ChromiumDownload:
d.Sources[source] = &download.ChromiumDownload{} d.sources[source] = &download.ChromiumDownload{}
case item.ChromiumCreditCard: case item.ChromiumCreditCard:
d.Sources[source] = &creditcard.ChromiumCreditCard{} d.sources[source] = &creditcard.ChromiumCreditCard{}
case item.YandexPassword: case item.YandexPassword:
d.Sources[source] = &password.YandexPassword{} d.sources[source] = &password.YandexPassword{}
case item.YandexCreditCard: case item.YandexCreditCard:
d.Sources[source] = &creditcard.YandexCreditCard{} d.sources[source] = &creditcard.YandexCreditCard{}
case item.FirefoxPassword: case item.FirefoxPassword:
d.Sources[source] = &password.FirefoxPassword{} d.sources[source] = &password.FirefoxPassword{}
case item.FirefoxCookie: case item.FirefoxCookie:
d.Sources[source] = &cookie.FirefoxCookie{} d.sources[source] = &cookie.FirefoxCookie{}
case item.FirefoxBookmark: case item.FirefoxBookmark:
d.Sources[source] = &bookmark.FirefoxBookmark{} d.sources[source] = &bookmark.FirefoxBookmark{}
case item.FirefoxHistory: case item.FirefoxHistory:
d.Sources[source] = &history.FirefoxHistory{} d.sources[source] = &history.FirefoxHistory{}
case item.FirefoxDownload: 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()) log.Noticef("find browser %s success", b.Name())
browsers = append(browsers, b) browsers = append(browsers, b)
} else { } else {
// TODO: show which browser find failed if err == chromium.ErrProfilePathNotFound {
if strings.Contains(err.Error(), "profile folder is not exist") {
log.Errorf("find browser %s failed, profile folder is not exist, maybe not installed", v.name) log.Errorf("find browser %s failed, profile folder is not exist, maybe not installed", v.name)
continue continue
} else { } 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) b, err := chromium.New(c.name, c.storage, profile, c.items)
if err != nil { 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) log.Fatalf("find browser %s failed, profile folder is not exist, maybe not installed", c.name)
} else { } else {
log.Fatalf("new chromium error:", err) log.Fatalf("new chromium error:", err)
return nil
} }
} }
browsers = append(browsers, b) browsers = append(browsers, b)
@ -89,13 +89,12 @@ func pickFirefox(name, profile string) []Browser {
browsers = append(browsers, b) browsers = append(browsers, b)
} }
} else { } 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) log.Errorf("find browser firefox %s failed, profile folder is not exist", v.name)
} else { } else {
log.Error(err) log.Error(err)
} }
} }
} }
return browsers return browsers
} }
@ -128,9 +127,5 @@ const (
coccocName = "CocCoc" coccocName = "CocCoc"
yandexName = "Yandex" yandexName = "Yandex"
firefoxName = "Firefox" firefoxName = "Firefox"
firefoxBetaName = "Firefox Beta"
firefoxDevName = "Firefox Dev"
firefoxNightlyName = "Firefox Nightly"
firefoxESRName = "Firefox ESR"
) )

@ -1,7 +1,7 @@
package chromium package chromium
import ( import (
"fmt" "errors"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -22,6 +22,10 @@ type chromium struct {
itemPaths map[item.Item]string 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. // 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) { func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
c := &chromium{ c := &chromium{
@ -30,7 +34,7 @@ func New(name, storage, profilePath string, items []item.Item) (*chromium, error
} }
// TODO: Handle file path is not exist // TODO: Handle file path is not exist
if !fileutil.FolderExists(profilePath) { 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) itemsPaths, err := c.getItemPath(profilePath, items)
if err != nil { if err != nil {

@ -1,15 +1,14 @@
package firefox package firefox
import ( import (
"errors"
"fmt" "fmt"
"io/fs" "io/fs"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"strings"
"hack-browser-data/internal/browingdata" "hack-browser-data/internal/browingdata"
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/fileutil" "hack-browser-data/internal/utils/fileutil"
"hack-browser-data/internal/utils/typeutil" "hack-browser-data/internal/utils/typeutil"
) )
@ -23,10 +22,14 @@ type firefox struct {
itemPaths map[item.Item]string itemPaths map[item.Item]string
} }
var (
ErrProfilePathNotFound = errors.New("profile path not found")
)
// New returns a new firefox instance. // New returns a new firefox instance.
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) { func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
if !fileutil.FolderExists(profilePath) { if !fileutil.FolderExists(profilePath) {
return nil, fmt.Errorf("%s profile folder is not exist: %s", name, profilePath) return nil, ErrProfilePathNotFound
} }
f := &firefox{ f := &firefox{
name: name, 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) multiItemPaths, err := f.getMultiItemPath(f.profilePath, f.items)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "profile folder is not exist") {
log.Error(err)
return nil, nil
}
return nil, err return nil, err
} }
var firefoxList []*firefox var firefoxList []*firefox

Loading…
Cancel
Save