2022-04-12 05:48:03 +00:00
package main
import (
2024-01-16 06:06:13 +00:00
"log/slog"
2022-04-12 05:48:03 +00:00
"os"
2022-04-12 10:23:02 +00:00
"github.com/urfave/cli/v2"
2023-03-10 06:52:26 +00:00
2023-06-04 05:47:43 +00:00
"github.com/moond4rk/hackbrowserdata/browser"
2024-01-16 06:06:13 +00:00
"github.com/moond4rk/hackbrowserdata/logger"
2023-06-04 05:47:43 +00:00
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
2022-04-12 05:48:03 +00:00
)
var (
2022-04-14 15:36:11 +00:00
browserName string
outputDir string
outputFormat string
verbose bool
compress bool
profilePath string
2023-03-11 09:51:40 +00:00
isFullExport bool
2022-04-12 05:48:03 +00:00
)
func main ( ) {
Execute ( )
}
func Execute ( ) {
2022-04-12 10:23:02 +00:00
app := & cli . App {
2022-04-14 15:36:11 +00:00
Name : "hack-browser-data" ,
2023-07-27 13:08:07 +00:00
Usage : "Export passwords|bookmarks|cookies|history|credit cards|download history|localStorage|extensions from browser" ,
UsageText : "[hack-browser-data -b chrome -f json -dir results --zip]\nExport all browsing data (passwords/cookies/history/bookmarks) from browser\nGithub Link: https://github.com/moonD4rk/HackBrowserData" ,
2024-01-09 10:06:31 +00:00
Version : "0.4.5" ,
2022-04-12 10:23:02 +00:00
Flags : [ ] cli . Flag {
& cli . BoolFlag { Name : "verbose" , Aliases : [ ] string { "vv" } , Destination : & verbose , Value : false , Usage : "verbose" } ,
2022-04-17 18:11:33 +00:00
& cli . BoolFlag { Name : "compress" , Aliases : [ ] string { "zip" } , Destination : & compress , Value : false , Usage : "compress result to zip" } ,
2023-03-10 06:52:26 +00:00
& cli . StringFlag { Name : "browser" , Aliases : [ ] string { "b" } , Destination : & browserName , Value : "all" , Usage : "available browsers: all|" + browser . Names ( ) } ,
2022-04-14 15:36:11 +00:00
& cli . StringFlag { Name : "results-dir" , Aliases : [ ] string { "dir" } , Destination : & outputDir , Value : "results" , Usage : "export dir" } ,
2023-07-27 13:08:07 +00:00
& cli . StringFlag { Name : "format" , Aliases : [ ] string { "f" } , Destination : & outputFormat , Value : "csv" , Usage : "output format: csv|json" } ,
2022-04-15 19:57:19 +00:00
& cli . StringFlag { Name : "profile-path" , Aliases : [ ] string { "p" } , Destination : & profilePath , Value : "" , Usage : "custom profile dir path, get with chrome://version" } ,
2023-03-11 09:51:40 +00:00
& cli . BoolFlag { Name : "full-export" , Aliases : [ ] string { "full" } , Destination : & isFullExport , Value : true , Usage : "is export full browsing data" } ,
2022-04-12 10:23:02 +00:00
} ,
HideHelpCommand : true ,
Action : func ( c * cli . Context ) error {
if verbose {
2024-01-16 06:06:13 +00:00
logger . Default . SetVerbose ( )
logger . Configure ( logger . Default )
2022-04-12 10:23:02 +00:00
}
2023-03-10 06:52:26 +00:00
browsers , err := browser . PickBrowsers ( browserName , profilePath )
2022-04-12 05:48:03 +00:00
if err != nil {
2024-01-16 06:06:13 +00:00
slog . Error ( "pick browsers error" , "err" , err )
2022-04-12 05:48:03 +00:00
}
2022-04-12 10:23:02 +00:00
for _ , b := range browsers {
2023-03-11 09:51:40 +00:00
data , err := b . BrowsingData ( isFullExport )
2022-04-12 10:23:02 +00:00
if err != nil {
2024-01-16 06:06:13 +00:00
slog . Error ( "get browsing data error" , "err" , err )
2023-07-10 09:53:13 +00:00
continue
2022-04-12 10:23:02 +00:00
}
2022-04-17 18:11:33 +00:00
data . Output ( outputDir , b . Name ( ) , outputFormat )
2022-04-12 10:23:02 +00:00
}
2023-03-11 09:51:40 +00:00
2022-04-12 10:23:02 +00:00
if compress {
2022-04-17 16:47:39 +00:00
if err = fileutil . CompressDir ( outputDir ) ; err != nil {
2024-01-16 06:06:13 +00:00
slog . Error ( "compress error: " , "err" , err )
2022-04-12 10:23:02 +00:00
}
2024-01-16 06:06:13 +00:00
slog . Info ( "compress success" )
2022-04-12 10:23:02 +00:00
}
return nil
} ,
}
err := app . Run ( os . Args )
if err != nil {
2022-10-30 04:58:35 +00:00
panic ( err )
2022-04-12 05:48:03 +00:00
}
}