From 44bccb4dc32e72f1da3a1782a20a7dc8b0f05138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=E1=B4=8F=E1=B4=8F=C9=B4D4=CA=80=E1=B4=8B?= Date: Mon, 22 Jun 2020 17:23:18 +0800 Subject: [PATCH] add history parse --- cmd/cmd.go | 56 +++++++++++++++++++++++ core/common/common.go | 104 +++++++++++++++++++++++++++++++++++++----- go.mod | 2 + go.sum | 79 ++++++++++++++++++++++++++++++++ log/log.go | 2 +- main.go | 36 ++++++++++----- utils/utils.go | 40 +++++++++++++--- utils/utils_darwin.go | 32 ++++++++----- utils/utils_test.go | 12 +++++ 9 files changed, 322 insertions(+), 41 deletions(-) create mode 100644 cmd/cmd.go create mode 100644 go.sum create mode 100644 utils/utils_test.go diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100644 index 0000000..577c2b5 --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,56 @@ +package cmd + +import ( + "hack-browser-data/log" + "hack-browser-data/utils" + "os" + "runtime" + + "github.com/urfave/cli/v2" +) + +var ( + browser string + exportData string + exportDir string + outputFormat string + verbose bool +) + +func Execute() { + app := &cli.App{ + Name: "hack-browser-data", + Usage: "export password/cookie/history/bookmark from browser", + Version: "0.0.1", + Flags: []cli.Flag{ + &cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"}, + &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browser, Value: "all", Usage: "browser name, all|chrome|safari"}, + &cli.StringFlag{Name: "dir", Aliases: []string{"d"}, Destination: &exportDir, Value: "data", Usage: "export dir"}, + &cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "result format, csv|json"}, + &cli.StringFlag{Name: "export-data", Aliases: []string{"e"}, Destination: &exportData, Value: "all", Usage: "all|password|cookie|history|bookmark"}, + }, + Action: func(c *cli.Context) error { + log.InitLog() + switch runtime.GOOS { + case "darwin": + err := utils.InitChromeKey() + if err != nil { + + } + case "windows": + } + switch { + case browser == "all": + case exportDir == "data": + case exportData == "all": + case outputFormat == "json": + } + return nil + }, + } + err := app.Run(os.Args) + if err != nil { + panic(err) + return + } +} diff --git a/core/common/common.go b/core/common/common.go index 9717bbd..9714acc 100644 --- a/core/common/common.go +++ b/core/common/common.go @@ -5,8 +5,10 @@ import ( "fmt" "hack-browser-data/log" "hack-browser-data/utils" + "time" _ "github.com/mattn/go-sqlite3" + "github.com/tidwall/gjson" ) const ( @@ -14,26 +16,98 @@ const ( Safari = "Safari" ) +var ( + browserData = new(BrowserData) + bookmarkList []*Bookmarks +) + +const ( + bookmarkID = "id" + bookmarkAdded = "date_added" + bookmarkUrl = "url" + bookmarkName = "name" + bookmarkType = "type" + bookmarkChildren = "children" +) + type ( BrowserData struct { BrowserName string - LoginData []LoginData + LoginData []*LoginData + Bookmarks []*Bookmarks } LoginData struct { UserName string encryptPass []byte Password string LoginUrl string + CreateDate time.Time } - History struct { + Bookmarks struct { + ID string `json:"id"` + DateAdded time.Time `json:"date_added"` + URL string `json:"url"` + Name string `json:"name"` + Type string `json:"type"` } Cookie struct { } - BookMark struct { + History struct { } ) -func ParseDB() (results []*LoginData) { +func ParseDB(dbname string) { + switch dbname { + case utils.LoginData: + r, err := parseLogin() + if err != nil { + fmt.Println(err) + } + for _, v := range r { + fmt.Printf("%+v\n", v) + } + case utils.Bookmarks: + parseBookmarks() + } +} + +func parseBookmarks() { + bookmarks, err := utils.ReadFile(utils.Bookmarks) + if err != nil { + log.Println(err) + } + r := gjson.Parse(bookmarks) + if r.Exists() { + roots := r.Get("roots") + roots.ForEach(func(key, value gjson.Result) bool { + getBookmarkValue(value) + return true + }) + fmt.Println(len(bookmarkList)) + } +} + +func getBookmarkValue(value gjson.Result) (children gjson.Result) { + b := new(Bookmarks) + b.ID = value.Get(bookmarkID).String() + nodeType := value.Get(bookmarkType) + b.DateAdded = utils.TimeEpochFormat(value.Get(bookmarkAdded).Int()) + b.URL = value.Get(bookmarkUrl).String() + b.Name = value.Get(bookmarkName).String() + children = value.Get(bookmarkChildren) + if nodeType.Exists() { + b.Type = nodeType.String() + bookmarkList = append(bookmarkList, b) + if children.Exists() && children.IsArray() { + for _, v := range children.Array() { + children = getBookmarkValue(v) + } + } + } + return children +} + +func parseLogin() (results []*LoginData, err error) { //datetime(visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch') loginD := &LoginData{} logins, err := sql.Open("sqlite3", utils.LoginData) @@ -46,39 +120,47 @@ func ParseDB() (results []*LoginData) { log.Println(err) } err = logins.Ping() - log.Println(err) - rows, err := logins.Query(`SELECT origin_url, username_value, password_value FROM logins`) + rows, err := logins.Query(`SELECT origin_url, username_value, password_value, date_created FROM logins`) defer func() { if err := rows.Close(); err != nil { log.Println(err) } }() - log.Println(err) for rows.Next() { var ( url string username string pwd []byte password string + create int64 ) - err = rows.Scan(&url, &username, &pwd) + err = rows.Scan(&url, &username, &pwd, &create) loginD = &LoginData{ UserName: username, encryptPass: pwd, LoginUrl: url, + CreateDate: utils.TimeEpochFormat(create), } if len(pwd) > 3 { - password, err = utils.Aes128CBCDecrypt(pwd[3:]) if err != nil { - panic(err) + log.Println(err) + continue } + password, err = utils.Aes128CBCDecrypt(pwd[3:]) } loginD.Password = password if err != nil { log.Println(err) } - fmt.Printf("%+v\n", loginD) results = append(results, loginD) } return } + +func parseHistory() { + +} + +func parseCookie() { + +} diff --git a/go.mod b/go.mod index 372468e..6f19508 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.14 require ( github.com/mattn/go-sqlite3 v1.14.0 + github.com/tidwall/gjson v1.6.0 + github.com/urfave/cli/v2 v2.2.0 go.uber.org/zap v1.15.0 golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 ) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8a8270f --- /dev/null +++ b/go.sum @@ -0,0 +1,79 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= +github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= +github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= +github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= +github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM= +go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM= +golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/log/log.go b/log/log.go index 6e88baf..f6bfa8a 100644 --- a/log/log.go +++ b/log/log.go @@ -20,7 +20,7 @@ var ( } ) -func init() { +func InitLog() { logger := newLogger("debug") formatLogger = logger.Sugar() } diff --git a/main.go b/main.go index 5c672ae..e09af90 100644 --- a/main.go +++ b/main.go @@ -5,26 +5,40 @@ import ( "hack-browser-data/core/common" "hack-browser-data/log" "hack-browser-data/utils" - "os" + "path/filepath" "runtime" ) func main() { + log.InitLog() + parse() +} + +func parse() { osName := runtime.GOOS switch osName { case "darwin": - chromePath, err := utils.GetDBPath(utils.LoginData) - if err != nil { - log.Error("can't find chrome.app in OS") - } - err = utils.CopyDB(chromePath, utils.LoginData) + //err := utils.InitChromeKey() + //if err != nil { + // log.Println(err) + // panic("init chrome key failed") + //} + case "windows": + fmt.Println("Windows") + } + //chromePath, err := utils.GetDBPath(utils.LoginData, utils.History, utils.BookMarks, utils.Cookies, utils.WebData) + chromePath, err := utils.GetDBPath(utils.Bookmarks) + if err != nil { + log.Error("can't find chrome.app in OS") + } + for _, v := range chromePath { + dst := filepath.Base(v) + err := utils.CopyDB(v, dst) if err != nil { log.Println(err) + continue } - utils.InitChromeKey() - common.ParseDB() - case "windows": - fmt.Println("Windows") + common.ParseDB(dst) } - os.Remove(utils.LoginData) + } diff --git a/utils/utils.go b/utils/utils.go index 41133c6..e1a6758 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path/filepath" + "time" ) const ( @@ -12,28 +13,53 @@ const ( History = "History" Cookies = "Cookies" WebData = "Web Data" + Bookmarks = "Bookmarks" ) -func CopyDB(source, dest string) error { - // remove current path db file first +func CopyDB(src, dst string) error { locals, _ := filepath.Glob("*") for _, v := range locals { - if v == dest { - err := os.Remove(dest) + if v == dst { + err := os.Remove(dst) if err != nil { return err } } } - sourceFile, err := ioutil.ReadFile(source) + sourceFile, err := ioutil.ReadFile(src) if err != nil { log.Println(err.Error()) } - err = ioutil.WriteFile(dest, sourceFile, 644) + err = ioutil.WriteFile(dst, sourceFile, 0777) if err != nil { log.Println(err.Error()) } - err = os.Chmod(dest, 0777) return err } + +func ParseBookMarks() { + +} + +func RemoveFile() { + +} + +func TimeEpochFormat(epoch int64) time.Time { + t := time.Date(1601, 1, 1, 0, 0, 0, 0, time.UTC) + d := time.Duration(epoch) + for i := 0; i < 1000; i++ { + t = t.Add(d) + } + return t +} + +func ReadFile(filename string) (string, error) { + s, err := ioutil.ReadFile(filename) + return string(s), err +} + +//func MakeDir(dirName string) error { +// +//} diff --git a/utils/utils_darwin.go b/utils/utils_darwin.go index c567d32..1cb9cf7 100644 --- a/utils/utils_darwin.go +++ b/utils/utils_darwin.go @@ -5,6 +5,7 @@ import ( "crypto/aes" "crypto/cipher" "crypto/sha1" + "errors" "hack-browser-data/log" "os/exec" "path/filepath" @@ -24,15 +25,20 @@ var ( chromePass []byte ) -func GetDBPath(dbName string) (string, error) { - s, err := filepath.Glob(macChromeDir + dbName) - if err != nil && len(s) == 0 { - return "", err +func GetDBPath(dbName ...string) (dbFile []string, err error) { + for _, v := range dbName { + s, err := filepath.Glob(macChromeDir + v) + if err != nil && len(s) == 0 { + continue + } + if len(s) > 0{ + dbFile = append(dbFile, s[0]) + } } - return s[0], nil + return dbFile, nil } -func InitChromeKey() { +func InitChromeKey() error { var ( cmd *exec.Cmd stdout, stderr bytes.Buffer @@ -43,22 +49,26 @@ func InitChromeKey() { err := cmd.Run() if err != nil { log.Println(err) - panic(err) + return err } if stderr.Len() > 0 { - panic(stderr.String()) + log.Println(stderr.String()) + err = errors.New(stderr.String()) } - // replace /n temp := stdout.Bytes() chromePass = temp[:len(temp)-1] - DecryptPass(chromePass) + decryptPass(chromePass) + return err } -func DecryptPass(chromePass []byte) { +func decryptPass(chromePass []byte) { chromeKey = pbkdf2.Key(chromePass, chromeSalt, 1003, 16, sha1.New) } func Aes128CBCDecrypt(encryptPass []byte) (string, error) { + if chromeKey == nil { + return "", nil + } block, err := aes.NewCipher(chromeKey) if err != nil { return "", err diff --git a/utils/utils_test.go b/utils/utils_test.go new file mode 100644 index 0000000..9741324 --- /dev/null +++ b/utils/utils_test.go @@ -0,0 +1,12 @@ +package utils + +import ( + "fmt" + "testing" +) + +func TestTimeEpochFormat(t *testing.T) { + dateAdded := int64(13220074277028707) + s := TimeEpochFormat(dateAdded) + fmt.Println(s) +}