Skip to content

Commit b48792b

Browse files
committed
sort result
1 parent 3273d62 commit b48792b

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func Execute() {
8383
core.ParseResult(dst)
8484
}
8585
}
86-
86+
core.FullData.Sorted()
8787
if outputFormat == "json" {
8888
err := core.FullData.OutPutJson(exportDir, browser, outputFormat)
8989
if err != nil {

core/common.go

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"io"
1616
"io/ioutil"
1717
"os"
18-
"sort"
1918
"time"
2019

2120
_ "github.com/mattn/go-sqlite3"
@@ -117,9 +116,6 @@ func parseBookmarks() {
117116
return true
118117
})
119118
}
120-
sort.Slice(bookmarkList, func(i, j int) bool {
121-
return bookmarkList[i].ID < bookmarkList[j].ID
122-
})
123119
FullData.BookmarkSlice = bookmarkList
124120
}
125121

@@ -174,7 +170,6 @@ func parseLogin() {
174170
}
175171
loginItemList = append(loginItemList, login)
176172
}
177-
sort.Sort(loginItemList)
178173
FullData.LoginDataSlice = loginItemList
179174
}
180175

@@ -278,9 +273,6 @@ func parseHistory() {
278273
}
279274
historyList = append(historyList, h)
280275
}
281-
sort.Slice(historyList, func(i, j int) bool {
282-
return historyList[i].VisitCount > historyList[j].VisitCount
283-
})
284276
FullData.HistorySlice = historyList
285277
}
286278

@@ -311,11 +303,11 @@ var queryFirefoxHistory = `SELECT id, url, title, last_visit_date, visit_count F
311303
func parseFirefoxData() {
312304
var historyList HistorySlice
313305
var (
314-
err error
315-
keyDB *sql.DB
316-
bookmarkRows, historyRow *sql.Rows
317-
tempMap map[int64]string
318-
bookmarkUrl string
306+
err error
307+
keyDB *sql.DB
308+
bookmarkRows, historyRows *sql.Rows
309+
tempMap map[int64]string
310+
bookmarkUrl string
319311
)
320312
tempMap = make(map[int64]string)
321313
keyDB, err = sql.Open("sqlite3", utils.FirefoxData)
@@ -329,38 +321,39 @@ func parseFirefoxData() {
329321
if err != nil {
330322
log.Error(err)
331323
}
332-
bookmarkRows, err = keyDB.Query(queryFirefoxBookMarks)
333-
historyRow, err = keyDB.Query(queryFirefoxHistory)
324+
historyRows, err = keyDB.Query(queryFirefoxHistory)
334325
if err != nil {
335326
log.Error(err)
336327
}
328+
337329
defer func() {
338-
if err := bookmarkRows.Close(); err != nil {
339-
log.Error(err)
340-
}
341-
}()
342-
defer func() {
343-
if err := historyRow.Close(); err != nil {
330+
if err := historyRows.Close(); err != nil {
344331
log.Error(err)
345332
}
346333
}()
347-
for historyRow.Next() {
334+
for historyRows.Next() {
348335
var (
349336
id, visitDate int64
350337
url, title string
351338
visitCount int
352339
)
353-
err = historyRow.Scan(&id, &url, &title, &visitDate, &visitCount)
340+
err = historyRows.Scan(&id, &url, &title, &visitDate, &visitCount)
354341
historyList = append(historyList, history{
355342
Title: title,
356343
Url: url,
357344
VisitCount: visitCount,
358-
LastVisitTime: utils.TimeStampFormat(visitDate / 100000),
345+
LastVisitTime: utils.TimeStampFormat(visitDate / 1000000),
359346
})
360347
tempMap[id] = url
361348
}
362349
FullData.HistorySlice = historyList
363350

351+
bookmarkRows, err = keyDB.Query(queryFirefoxBookMarks)
352+
defer func() {
353+
if err := bookmarkRows.Close(); err != nil {
354+
log.Error(err)
355+
}
356+
}()
364357
for bookmarkRows.Next() {
365358
var (
366359
id, fk, bType, dateAdded int64
@@ -550,15 +543,11 @@ func parseFirefoxKey4() {
550543
blockMode2.CryptBlocks(sq2, s2.Encrypted)
551544
FullData.LoginDataSlice = append(FullData.LoginDataSlice, loginData{
552545
LoginUrl: v.LoginUrl,
553-
UserName: string(utils.PKCS7UnPadding(sq)),
554-
Password: string(utils.PKCS7UnPadding(sq2)),
546+
UserName: string(utils.PKCS5UnPadding(sq)),
547+
Password: string(utils.PKCS5UnPadding(sq2)),
555548
CreateDate: v.CreateDate,
556549
})
557550
}
558-
//err := os.Remove("key4.db")
559-
//if err != nil {
560-
// fmt.Println(err)
561-
//}
562551
}
563552

564553
var queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`

core/output.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"hack-browser-data/log"
88
"hack-browser-data/utils"
99
"os"
10+
"sort"
1011

1112
"github.com/jszwec/csvutil"
1213
)
@@ -143,3 +144,13 @@ func (b BrowserData) OutPutJson(dir, browser, format string) error {
143144
}
144145
return nil
145146
}
147+
148+
func (b BrowserData) Sorted() {
149+
sort.Slice(b.BookmarkSlice, func(i, j int) bool {
150+
return b.BookmarkSlice[i].ID < b.BookmarkSlice[j].ID
151+
})
152+
sort.Slice(b.HistorySlice, func(i, j int) bool {
153+
return b.HistorySlice[i].VisitCount > b.HistorySlice[j].VisitCount
154+
})
155+
sort.Sort(b.LoginDataSlice)
156+
}

0 commit comments

Comments
 (0)