feat: test case for convert utf16 value to utf8

This commit is contained in:
moonD4rk
2023-03-12 18:54:19 +08:00
parent b824f74fae
commit 4fb2acd85c
4 changed files with 48 additions and 2 deletions
+8 -1
View File
@@ -8,6 +8,8 @@ import (
"strings"
"github.com/syndtr/goleveldb/leveldb"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
@@ -44,7 +46,7 @@ func (c *ChromiumLocalStorage) Parse(masterKey []byte) error {
if len(value) < maxLocalStorageLength {
s.fillValue(value)
} else {
s.Value = fmt.Sprintf("value is too long, length is %d", len(value))
s.Value = fmt.Sprintf("value is too long, length is %d, supportted max length is %d", len(value), maxLocalStorageLength)
}
if s.IsMeta {
s.Value = fmt.Sprintf("meta data, value bytes is %v", value)
@@ -84,6 +86,11 @@ func (s *storage) fillHeader(url, key []byte) {
s.Key = string(bytes.Trim(key, "\x01"))
}
func convertUTF16toUTF8(source []byte, endian unicode.Endianness) ([]byte, error) {
r, _, err := transform.Bytes(unicode.UTF16(endian, unicode.IgnoreBOM).NewDecoder(), source)
return r, err
}
// fillValue fills value of the storage
// TODO: support unicode charter
func (s *storage) fillValue(b []byte) {