feat: sort result with timestamp

pull/83/head
ᴍᴏᴏɴD4ʀᴋ 4 years ago
parent 22eccce30d
commit b86b9c54ca
  1. 2
      cmd/cmd.go
  2. 41
      core/common.go
  3. 11
      core/output.go

@ -83,7 +83,7 @@ func Execute() {
core.ParseResult(dst) core.ParseResult(dst)
} }
} }
core.FullData.Sorted()
if outputFormat == "json" { if outputFormat == "json" {
err := core.FullData.OutPutJson(exportDir, browser, outputFormat) err := core.FullData.OutPutJson(exportDir, browser, outputFormat)
if err != nil { if err != nil {

@ -15,7 +15,6 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"sort"
"time" "time"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -117,9 +116,6 @@ func parseBookmarks() {
return true return true
}) })
} }
sort.Slice(bookmarkList, func(i, j int) bool {
return bookmarkList[i].ID < bookmarkList[j].ID
})
FullData.BookmarkSlice = bookmarkList FullData.BookmarkSlice = bookmarkList
} }
@ -174,7 +170,6 @@ func parseLogin() {
} }
loginItemList = append(loginItemList, login) loginItemList = append(loginItemList, login)
} }
sort.Sort(loginItemList)
FullData.LoginDataSlice = loginItemList FullData.LoginDataSlice = loginItemList
} }
@ -278,9 +273,6 @@ func parseHistory() {
} }
historyList = append(historyList, h) historyList = append(historyList, h)
} }
sort.Slice(historyList, func(i, j int) bool {
return historyList[i].VisitCount > historyList[j].VisitCount
})
FullData.HistorySlice = historyList FullData.HistorySlice = historyList
} }
@ -313,7 +305,7 @@ func parseFirefoxData() {
var ( var (
err error err error
keyDB *sql.DB keyDB *sql.DB
bookmarkRows, historyRow *sql.Rows bookmarkRows, historyRows *sql.Rows
tempMap map[int64]string tempMap map[int64]string
bookmarkUrl string bookmarkUrl string
) )
@ -329,38 +321,39 @@ func parseFirefoxData() {
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
bookmarkRows, err = keyDB.Query(queryFirefoxBookMarks) historyRows, err = keyDB.Query(queryFirefoxHistory)
historyRow, err = keyDB.Query(queryFirefoxHistory)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
defer func() { defer func() {
if err := bookmarkRows.Close(); err != nil { if err := historyRows.Close(); err != nil {
log.Error(err)
}
}()
defer func() {
if err := historyRow.Close(); err != nil {
log.Error(err) log.Error(err)
} }
}() }()
for historyRow.Next() { for historyRows.Next() {
var ( var (
id, visitDate int64 id, visitDate int64
url, title string url, title string
visitCount int visitCount int
) )
err = historyRow.Scan(&id, &url, &title, &visitDate, &visitCount) err = historyRows.Scan(&id, &url, &title, &visitDate, &visitCount)
historyList = append(historyList, history{ historyList = append(historyList, history{
Title: title, Title: title,
Url: url, Url: url,
VisitCount: visitCount, VisitCount: visitCount,
LastVisitTime: utils.TimeStampFormat(visitDate / 100000), LastVisitTime: utils.TimeStampFormat(visitDate / 1000000),
}) })
tempMap[id] = url tempMap[id] = url
} }
FullData.HistorySlice = historyList FullData.HistorySlice = historyList
bookmarkRows, err = keyDB.Query(queryFirefoxBookMarks)
defer func() {
if err := bookmarkRows.Close(); err != nil {
log.Error(err)
}
}()
for bookmarkRows.Next() { for bookmarkRows.Next() {
var ( var (
id, fk, bType, dateAdded int64 id, fk, bType, dateAdded int64
@ -550,15 +543,11 @@ func parseFirefoxKey4() {
blockMode2.CryptBlocks(sq2, s2.Encrypted) blockMode2.CryptBlocks(sq2, s2.Encrypted)
FullData.LoginDataSlice = append(FullData.LoginDataSlice, loginData{ FullData.LoginDataSlice = append(FullData.LoginDataSlice, loginData{
LoginUrl: v.LoginUrl, LoginUrl: v.LoginUrl,
UserName: string(utils.PKCS7UnPadding(sq)), UserName: string(utils.PKCS5UnPadding(sq)),
Password: string(utils.PKCS7UnPadding(sq2)), Password: string(utils.PKCS5UnPadding(sq2)),
CreateDate: v.CreateDate, CreateDate: v.CreateDate,
}) })
} }
//err := os.Remove("key4.db")
//if err != nil {
// fmt.Println(err)
//}
} }
var queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies` var queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`

@ -7,6 +7,7 @@ import (
"hack-browser-data/log" "hack-browser-data/log"
"hack-browser-data/utils" "hack-browser-data/utils"
"os" "os"
"sort"
"github.com/jszwec/csvutil" "github.com/jszwec/csvutil"
) )
@ -143,3 +144,13 @@ func (b BrowserData) OutPutJson(dir, browser, format string) error {
} }
return nil return nil
} }
func (b BrowserData) Sorted() {
sort.Slice(b.BookmarkSlice, func(i, j int) bool {
return b.BookmarkSlice[i].ID < b.BookmarkSlice[j].ID
})
sort.Slice(b.HistorySlice, func(i, j int) bool {
return b.HistorySlice[i].VisitCount > b.HistorySlice[j].VisitCount
})
sort.Sort(b.LoginDataSlice)
}

Loading…
Cancel
Save