From 6c1f653b4f30d0689e95a46cedd5382133422c34 Mon Sep 17 00:00:00 2001 From: moonD4rk Date: Mon, 8 May 2023 19:09:17 +0800 Subject: [PATCH] refactor: Refactor storage queries and filters. - Update local storage query constant and function calls - Remove null and control characters from UTF-8 split function --- browingdata/localstorage/localstorage.go | 6 +++--- browingdata/sessionstorage/sessionstorage.go | 16 +++++++--------- utils/byteutil/byteutil.go | 12 +++++------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/browingdata/localstorage/localstorage.go b/browingdata/localstorage/localstorage.go index 3eb8fef..6ce49b9 100644 --- a/browingdata/localstorage/localstorage.go +++ b/browingdata/localstorage/localstorage.go @@ -101,8 +101,8 @@ func (s *storage) fillValue(b []byte) { type FirefoxLocalStorage []storage const ( - queryFirefoxHistory = `SELECT originKey, key, value FROM webappsstore2` - closeJournalMode = `PRAGMA journal_mode=off` + queryLocalStorage = `SELECT originKey, key, value FROM webappsstore2` + closeJournalMode = `PRAGMA journal_mode=off` ) func (f *FirefoxLocalStorage) Parse(_ []byte) error { @@ -117,7 +117,7 @@ func (f *FirefoxLocalStorage) Parse(_ []byte) error { if err != nil { log.Error(err) } - rows, err := db.Query(queryFirefoxHistory) + rows, err := db.Query(queryLocalStorage) if err != nil { return err } diff --git a/browingdata/sessionstorage/sessionstorage.go b/browingdata/sessionstorage/sessionstorage.go index 64da0a8..e6cf55b 100644 --- a/browingdata/sessionstorage/sessionstorage.go +++ b/browingdata/sessionstorage/sessionstorage.go @@ -76,14 +76,12 @@ func (s *session) fillKey(b []byte) { s.fillHeader(keys[0], keys[1]) } if len(keys) == 3 { - if string(keys[0]) == "map"{ + if string(keys[0]) == "map" { s.Key = string(keys[2]) - } else if string(keys[0]) == "namespace"{ + } else if string(keys[0]) == "namespace" { s.URL = string(keys[2]) s.Key = string(keys[1]) } - - } } @@ -111,23 +109,23 @@ func (s *session) fillValue(b []byte) { type FirefoxSessionStorage []session const ( - queryFirefoxHistory = `SELECT originKey, key, value FROM webappsstore2` + querySessionStorage = `SELECT originKey, key, value FROM webappsstore2` closeJournalMode = `PRAGMA journal_mode=off` ) func (f *FirefoxSessionStorage) Parse(_ []byte) error { - db, err := sql.Open("sqlite3", item.TempFirefoxLocalStorage) + db, err := sql.Open("sqlite3", item.TempFirefoxSessionStorage) if err != nil { return err } - defer os.Remove(item.TempFirefoxLocalStorage) + defer os.Remove(item.TempFirefoxSessionStorage) defer db.Close() _, err = db.Exec(closeJournalMode) if err != nil { log.Error(err) } - rows, err := db.Query(queryFirefoxHistory) + rows, err := db.Query(querySessionStorage) if err != nil { return err } @@ -159,7 +157,7 @@ func (s *session) fillFirefox(originKey, key, value string) { } func (f *FirefoxSessionStorage) Name() string { - return "localStorage" + return "sessionStorage" } func (f *FirefoxSessionStorage) Len() int { diff --git a/utils/byteutil/byteutil.go b/utils/byteutil/byteutil.go index 4323f2c..8b1268b 100644 --- a/utils/byteutil/byteutil.go +++ b/utils/byteutil/byteutil.go @@ -1,10 +1,8 @@ package byteutil -var ( - OnSplitUTF8Func = func(r rune) rune { - if r == 0x00 || r == 0x01 { - return -1 - } - return r +var OnSplitUTF8Func = func(r rune) rune { + if r == 0x00 || r == 0x01 { + return -1 } -) + return r +}