You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
package browserdata
|
|
|
|
import (
|
|
"database/sql"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
|
)
|
|
|
|
type Extractor interface {
|
|
Extract() (interface{}, error)
|
|
}
|
|
|
|
type RowsHandler func([]byte, interface{}) (interface{}, error)
|
|
|
|
type ExtractorHandler func([]byte, string, string, RowsHandler) (interface{}, error)
|
|
|
|
func DefaultDBHandler(masterKey []byte, dbpath, dbQuery string, rowsHandler RowsHandler) (interface{}, error) {
|
|
tempFile := filepath.Join(os.TempDir(), filepath.Base(dbpath))
|
|
if err := fileutil.CopyFile(dbpath, tempFile); err != nil {
|
|
return nil, err
|
|
}
|
|
defer os.Remove(tempFile)
|
|
db, err := sql.Open("sqlite3", tempFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer db.Close()
|
|
rows, err := db.Query(dbQuery)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
return rowsHandler(masterKey, rows)
|
|
}
|
|
|
|
func DefaultJSONHandler(masterKey []byte, dbpath, dbQuery string, rowsHandler RowsHandler) (interface{}, error) {
|
|
tempFile := filepath.Join(os.TempDir(), filepath.Base(dbpath))
|
|
if err := fileutil.CopyFile(dbpath, tempFile); err != nil {
|
|
return nil, err
|
|
}
|
|
defer os.Remove(tempFile)
|
|
s, err := os.ReadFile(tempFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return rowsHandler(masterKey, s)
|
|
}
|
|
|