Skip to content

Commit

Permalink
[KATC] Support fields with JS Date type for Chrome/Firefox extension …
Browse files Browse the repository at this point in the history
…databases (kolide#2054)
  • Loading branch information
RebeccaMahany authored Jan 22, 2025
1 parent cdb1b5a commit 16d2d79
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ee/indexeddb/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
// strings
tokenAsciiStr byte = 0x22 // "
tokenUtf16Str byte = 0x63 // c
// dates
tokenDate byte = 0x44 // D
// types: object
tokenObjectBegin byte = 0x6f // o
tokenObjectEnd byte = 0x7b // {
Expand Down Expand Up @@ -214,6 +216,12 @@ func deserializeObject(ctx context.Context, slogger *slog.Logger, srcReader *byt
return obj, fmt.Errorf("decoding double for `%s`: %w", currentPropertyName, err)
}
obj[currentPropertyName] = []byte(strconv.FormatFloat(d, 'f', -1, 64))
case tokenDate:
var d float64
if err := binary.Read(srcReader, binary.NativeEndian, &d); err != nil {
return obj, fmt.Errorf("decoding double as date for `%s`: %w", currentPropertyName, err)
}
obj[currentPropertyName] = []byte(strconv.FormatFloat(d, 'f', -1, 64))
case tokenBeginSparseArray:
arr, err := deserializeSparseArray(ctx, slogger, srcReader)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions ee/katc/deserialize_firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
tagBoolean uint32 = 0xffff0002
tagInt32 uint32 = 0xffff0003
tagString uint32 = 0xffff0004
tagDateObject uint32 = 0xffff0005
tagArrayObject uint32 = 0xffff0007
tagObjectObject uint32 = 0xffff0008
tagBooleanObject uint32 = 0xffff000a
Expand Down Expand Up @@ -137,6 +138,17 @@ func deserializeObject(srcReader io.ByteReader) (map[string][]byte, error) {
} else {
resultObj[nextKeyStr] = []byte("false")
}
case tagDateObject:
// Date objects are stored as follows:
// * first, a tagDateObject with valData `0`
// * next, a double
// So, we want to ignore our current `valData`, and read the next pair as a double.
nextTag, nextData, err := nextPair(srcReader)
if err != nil {
return nil, fmt.Errorf("reading next pair as date object for key `%s`: %w", nextKeyStr, err)
}
d := uint64(nextData) | uint64(nextTag)<<32
resultObj[nextKeyStr] = []byte(strconv.FormatUint(d, 10))
case tagObjectObject:
obj, err := deserializeNestedObject(srcReader)
if err != nil {
Expand Down
Binary file modified ee/katc/test_data/indexeddbs/1985929987lbadutnscehter.sqlite.zip
Binary file not shown.
Binary file modified ee/katc/test_data/indexeddbs/file__0.indexeddb.leveldb.zip
Binary file not shown.
6 changes: 4 additions & 2 deletions ee/katc/test_data/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
],
noDetails: [], // Empty array
email: "[email protected]",
someTimestamp: 1720034607 // *unint32
someTimestamp: 1720034607, // *unint32
someDate: new Date() // Date object, empty
},
{
uuid: "03b3e669-3e7a-482c-83b2-8a800b9f804f",
Expand Down Expand Up @@ -88,7 +89,8 @@
],
noDetails: [], // Empty array
email: "[email protected]",
someTimestamp: 1726096312 // *unint32
someTimestamp: 1726096312, // *unint32
someDate: new Date("December 17, 1995 03:24:00") // Date object, not empty
},
];
objectStore.transaction.oncomplete = (event) => {
Expand Down

0 comments on commit 16d2d79

Please sign in to comment.