From b824f74faef2970fa2026c53126373aa5b8fd2fb Mon Sep 17 00:00:00 2001 From: moonD4rk Date: Sun, 12 Mar 2023 18:20:15 +0800 Subject: [PATCH] fix: missing key and value in localstorage --- browingdata/localstorage/localstorage.go | 22 ++++++++++++---------- utils/byteutil/byteutil.go | 10 ++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 utils/byteutil/byteutil.go diff --git a/browingdata/localstorage/localstorage.go b/browingdata/localstorage/localstorage.go index 5158f92..cbff3ec 100644 --- a/browingdata/localstorage/localstorage.go +++ b/browingdata/localstorage/localstorage.go @@ -11,6 +11,7 @@ import ( "github.com/moond4rk/HackBrowserData/item" "github.com/moond4rk/HackBrowserData/log" + "github.com/moond4rk/HackBrowserData/utils/byteutil" "github.com/moond4rk/HackBrowserData/utils/typeutil" ) @@ -23,6 +24,8 @@ type storage struct { Value string } +const maxLocalStorageLength = 1024 * 2 + func (c *ChromiumLocalStorage) Parse(masterKey []byte) error { db, err := leveldb.OpenFile(item.TempChromiumLocalStorage, nil) if err != nil { @@ -35,16 +38,16 @@ func (c *ChromiumLocalStorage) Parse(masterKey []byte) error { for iter.Next() { key := iter.Key() value := iter.Value() - // don't parse value upper than 5kB - if len(value) > 1024*5 { - continue - } s := new(storage) s.fillKey(key) - s.fillValue(value) - // don't save meta data + // don't all value upper than 1kB + if len(value) < maxLocalStorageLength { + s.fillValue(value) + } else { + s.Value = fmt.Sprintf("value is too long, length is %d", len(value)) + } if s.IsMeta { - continue + s.Value = fmt.Sprintf("meta data, value bytes is %v", value) } *c = append(*c, *s) } @@ -84,9 +87,8 @@ func (s *storage) fillHeader(url, key []byte) { // fillValue fills value of the storage // TODO: support unicode charter func (s *storage) fillValue(b []byte) { - t := fmt.Sprintf("%c", b) - m := strings.NewReplacer(" ", "", "\x00", "", "\x01", "").Replace(t) - s.Value = m + value := bytes.Map(byteutil.OnSplitUTF8Func, b) + s.Value = string(value) } type FirefoxLocalStorage []storage diff --git a/utils/byteutil/byteutil.go b/utils/byteutil/byteutil.go new file mode 100644 index 0000000..4323f2c --- /dev/null +++ b/utils/byteutil/byteutil.go @@ -0,0 +1,10 @@ +package byteutil + +var ( + OnSplitUTF8Func = func(r rune) rune { + if r == 0x00 || r == 0x01 { + return -1 + } + return r + } +)