refactor: format firefox download code

pull/83/head
moond4rk 4 years ago committed by ᴍᴏᴏɴD4ʀᴋ
parent d1b05814ea
commit d1a8b85a6e
  1. 31
      core/data/parse.go

@ -8,8 +8,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
"time"
"strings" "strings"
"time"
"hack-browser-data/core/decrypt" "hack-browser-data/core/decrypt"
"hack-browser-data/log" "hack-browser-data/log"
@ -56,7 +56,7 @@ var (
queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads` queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads`
queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies` queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places` queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places`
queryFirefoxDownload = `SELECT place_id, GROUP_CONCAT(content) , url, dateAdded FROM (SELECT * FROM moz_annos INNER JOIN moz_places ON moz_annos.place_id=moz_places.id) t GROUP BY place_id` queryFirefoxDownload = `SELECT place_id, GROUP_CONCAT(content), url, dateAdded FROM (SELECT * FROM moz_annos INNER JOIN moz_places ON moz_annos.place_id=moz_places.id) t GROUP BY place_id`
queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks` queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks`
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies` queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'` queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
@ -503,10 +503,10 @@ func (d *downloads) ChromeParse(key []byte) error {
func (d *downloads) FirefoxParse() error { func (d *downloads) FirefoxParse() error {
var ( var (
err error err error
keyDB *sql.DB keyDB *sql.DB
downloadRows *sql.Rows downloadRows *sql.Rows
tempMap map[int64]string tempMap map[int64]string
) )
tempMap = make(map[int64]string) tempMap = make(map[int64]string)
keyDB, err = sql.Open("sqlite3", FirefoxDataFile) keyDB, err = sql.Open("sqlite3", FirefoxDataFile)
@ -534,10 +534,10 @@ func (d *downloads) FirefoxParse() error {
}() }()
for downloadRows.Next() { for downloadRows.Next() {
var ( var (
content, url string content, url string
place_id, dateAdded int64 placeID, dateAdded int64
) )
err = downloadRows.Scan(&place_id, &content, &url, &dateAdded) err = downloadRows.Scan(&placeID, &content, &url, &dateAdded)
if err != nil { if err != nil {
log.Warn(err) log.Warn(err)
} }
@ -546,19 +546,20 @@ func (d *downloads) FirefoxParse() error {
path := contentList[0] path := contentList[0]
json := "{" + contentList[1] json := "{" + contentList[1]
endTime := gjson.Get(json, "endTime") endTime := gjson.Get(json, "endTime")
fileSize:= gjson.Get(json, "fileSize") fileSize := gjson.Get(json, "fileSize")
d.downloads = append(d.downloads, download{ d.downloads = append(d.downloads, download{
TargetPath: path, TargetPath: path,
Url: url, Url: url,
TotalBytes: fileSize.Int(), TotalBytes: fileSize.Int(),
StartTime: utils.TimeStampFormat(dateAdded / 1000000), StartTime: utils.TimeStampFormat(dateAdded / 1000000),
EndTime: utils.TimeStampFormat(endTime.Int() / 1000), EndTime: utils.TimeStampFormat(endTime.Int() / 1000),
}) })
} }
tempMap[place_id] = url tempMap[placeID] = url
} }
return nil return nil
} }
func (d *downloads) CopyDB() error { func (d *downloads) CopyDB() error {
return copyToLocalPath(d.mainPath, filepath.Base(d.mainPath)) return copyToLocalPath(d.mainPath, filepath.Base(d.mainPath))
} }

Loading…
Cancel
Save