mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
e48f35cfd3
* refactor: Refactor logging to use structured slog package. - Remove `gookit` dependencies from `go.sum` - Improve error logging in multiple packages by replacing `log` with `log/slog` - Update dependencies in `go.mod` - Add new `logger` package with test cases - Refactor logging statements in multiple packages to use `slog` instead of `log` - Change logging format and level in multiple packages for better structured logging * refactor: Refactor logger package and add handler interface - Refactor logger package - Rename `defaultHandler` to `DefaultLogger` - Move `ReplaceAttr` function to `Logger` struct - Implement `LogHandler` struct with `slog.Handler` interface - Add new `Logger` methods for configuration - Add `SetMaxLevel`, `SetJSONHandler`, `SetTextHandler`, `SetOutput`, `SetVerbose`, `SetReplaceAttrFunc` - Add verbose flag to `cmd/hack-browser-data/main.go` to increase logging * refactor: Refactor logger package to use simplified handler initialization. - Refactor logger package to use Default instead of DefaultLogger - Update `NewHandler` method to correctly reference `Default` logger and simplify handler initialization - Update tests for logger to reflect changes in Default usage - Rename `DefaultLogger` to `Default` and update comments to better reflect its purpose - Update function calls in hack-browser-data main.go to reflect logger package updates * refactor: Refactor logging in Chromium implementation Refactor logging and simplify decryption in chromium files - Replace logger package import with shared slog package - Change logging messages to use slog instead of logger - Simplify decryption process by removing first 5 characters of encrypted key - Refactor error logging in linux file to use shared slog package - Replace string concatenation with formatted string in linux error message
128 lines
2.6 KiB
Go
128 lines
2.6 KiB
Go
package history
|
|
|
|
import (
|
|
"database/sql"
|
|
"log/slog"
|
|
"os"
|
|
"sort"
|
|
"time"
|
|
|
|
// import sqlite3 driver
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/item"
|
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
|
)
|
|
|
|
type ChromiumHistory []history
|
|
|
|
type history struct {
|
|
Title string
|
|
URL string
|
|
VisitCount int
|
|
LastVisitTime time.Time
|
|
}
|
|
|
|
const (
|
|
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
|
)
|
|
|
|
func (c *ChromiumHistory) Parse(_ []byte) error {
|
|
db, err := sql.Open("sqlite3", item.ChromiumHistory.TempFilename())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer os.Remove(item.ChromiumHistory.TempFilename())
|
|
defer db.Close()
|
|
|
|
rows, err := db.Query(queryChromiumHistory)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
var (
|
|
url, title string
|
|
visitCount int
|
|
lastVisitTime int64
|
|
)
|
|
if err := rows.Scan(&url, &title, &visitCount, &lastVisitTime); err != nil {
|
|
slog.Warn("scan chromium history error", "err", err)
|
|
}
|
|
data := history{
|
|
URL: url,
|
|
Title: title,
|
|
VisitCount: visitCount,
|
|
LastVisitTime: typeutil.TimeEpoch(lastVisitTime),
|
|
}
|
|
*c = append(*c, data)
|
|
}
|
|
sort.Slice(*c, func(i, j int) bool {
|
|
return (*c)[i].VisitCount > (*c)[j].VisitCount
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (c *ChromiumHistory) Name() string {
|
|
return "history"
|
|
}
|
|
|
|
func (c *ChromiumHistory) Len() int {
|
|
return len(*c)
|
|
}
|
|
|
|
type FirefoxHistory []history
|
|
|
|
const (
|
|
queryFirefoxHistory = `SELECT id, url, COALESCE(last_visit_date, 0), COALESCE(title, ''), visit_count FROM moz_places`
|
|
closeJournalMode = `PRAGMA journal_mode=off`
|
|
)
|
|
|
|
func (f *FirefoxHistory) Parse(_ []byte) error {
|
|
db, err := sql.Open("sqlite3", item.FirefoxHistory.TempFilename())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer os.Remove(item.FirefoxHistory.TempFilename())
|
|
defer db.Close()
|
|
|
|
_, err = db.Exec(closeJournalMode)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer db.Close()
|
|
rows, err := db.Query(queryFirefoxHistory)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
var (
|
|
id, visitDate int64
|
|
url, title string
|
|
visitCount int
|
|
)
|
|
if err = rows.Scan(&id, &url, &visitDate, &title, &visitCount); err != nil {
|
|
slog.Error("scan firefox history error", "err", err)
|
|
}
|
|
*f = append(*f, history{
|
|
Title: title,
|
|
URL: url,
|
|
VisitCount: visitCount,
|
|
LastVisitTime: typeutil.TimeStamp(visitDate / 1000000),
|
|
})
|
|
}
|
|
sort.Slice(*f, func(i, j int) bool {
|
|
return (*f)[i].VisitCount < (*f)[j].VisitCount
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (f *FirefoxHistory) Name() string {
|
|
return "history"
|
|
}
|
|
|
|
func (f *FirefoxHistory) Len() int {
|
|
return len(*f)
|
|
}
|