dfindexeddb 20240224__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dfindexeddb/__init__.py +14 -0
- dfindexeddb/errors.py +23 -0
- dfindexeddb/indexeddb/__init__.py +13 -0
- dfindexeddb/indexeddb/blink.py +115 -0
- dfindexeddb/indexeddb/chromium.py +1283 -0
- dfindexeddb/indexeddb/definitions.py +306 -0
- dfindexeddb/indexeddb/v8.py +642 -0
- dfindexeddb/leveldb/__init__.py +14 -0
- dfindexeddb/leveldb/ldb.py +259 -0
- dfindexeddb/leveldb/log.py +308 -0
- dfindexeddb/utils.py +295 -0
- dfindexeddb/version.py +22 -0
- dfindexeddb-20240224.dist-info/AUTHORS +12 -0
- dfindexeddb-20240224.dist-info/LICENSE +202 -0
- dfindexeddb-20240224.dist-info/METADATA +277 -0
- dfindexeddb-20240224.dist-info/RECORD +18 -0
- dfindexeddb-20240224.dist-info/WHEEL +5 -0
- dfindexeddb-20240224.dist-info/top_level.txt +1 -0
dfindexeddb/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
dfindexeddb/errors.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""Errors for indexeddb parsers."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DecoderError(Exception):
|
|
19
|
+
"""A decoder error."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ParserError(Exception):
|
|
23
|
+
"""A parser error."""
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2024 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""Parsers for blink javascript serialized objects."""
|
|
16
|
+
import io
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from dfindexeddb import utils
|
|
20
|
+
from dfindexeddb.indexeddb import definitions
|
|
21
|
+
from dfindexeddb.indexeddb import v8
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class V8ScriptValueDecoder:
|
|
26
|
+
"""A Blink V8 Serialized Script Value (SSV) decoder.
|
|
27
|
+
|
|
28
|
+
Attributes:
|
|
29
|
+
deserializer (v8.ValueDeserializer): the V8 value deserializer.
|
|
30
|
+
raw_data (bytes): the raw bytes containing the serialized javascript
|
|
31
|
+
value.
|
|
32
|
+
version (int): the blink version.
|
|
33
|
+
"""
|
|
34
|
+
_MIN_VERSION_FOR_SEPARATE_ENVELOPE = 16
|
|
35
|
+
|
|
36
|
+
# As defined in trailer_reader.h
|
|
37
|
+
_MIN_WIRE_FORMAT_VERSION = 21
|
|
38
|
+
|
|
39
|
+
def __init__(self, raw_data: bytes):
|
|
40
|
+
self.deserializer = None
|
|
41
|
+
self.raw_data = raw_data
|
|
42
|
+
self.version = 0
|
|
43
|
+
|
|
44
|
+
def _ReadVersionEnvelope(self) -> int:
|
|
45
|
+
"""Reads the Blink version envelope.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
The number of bytes consumed reading the Blink version envelope or zero
|
|
49
|
+
if no blink envelope is detected.
|
|
50
|
+
"""
|
|
51
|
+
if not self.raw_data:
|
|
52
|
+
return 0
|
|
53
|
+
|
|
54
|
+
decoder = utils.StreamDecoder(io.BytesIO(self.raw_data))
|
|
55
|
+
_, tag_value = decoder.DecodeUint8()
|
|
56
|
+
tag = definitions.BlinkSerializationTag(tag_value)
|
|
57
|
+
if tag != definitions.BlinkSerializationTag.VERSION:
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
_, version = decoder.DecodeUint32Varint()
|
|
61
|
+
if version < self._MIN_VERSION_FOR_SEPARATE_ENVELOPE:
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
consumed_bytes = decoder.stream.tell()
|
|
65
|
+
|
|
66
|
+
if version >= self._MIN_WIRE_FORMAT_VERSION:
|
|
67
|
+
trailer_offset_data_size = 1 + 8 + 4 # 1 + sizeof(uint64) + sizeof(uint32)
|
|
68
|
+
consumed_bytes += trailer_offset_data_size
|
|
69
|
+
if consumed_bytes >= len(self.raw_data):
|
|
70
|
+
return 0
|
|
71
|
+
return consumed_bytes
|
|
72
|
+
|
|
73
|
+
def ReadTag(self) -> definitions.BlinkSerializationTag:
|
|
74
|
+
"""Reads a blink serialization tag.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The blink serialization tag.
|
|
78
|
+
"""
|
|
79
|
+
_, tag_value = self.deserializer.decoder.DecodeUint8()
|
|
80
|
+
return definitions.BlinkSerializationTag(tag_value)
|
|
81
|
+
|
|
82
|
+
def ReadHostObject(self) -> Any:
|
|
83
|
+
"""Reads a host DOM object.
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
NotImplementedError: when called.
|
|
87
|
+
"""
|
|
88
|
+
tag = self.ReadTag()
|
|
89
|
+
raise NotImplementedError(f'V8ScriptValueDecoder.ReadHostObject - {tag}')
|
|
90
|
+
|
|
91
|
+
def Deserialize(self) -> Any:
|
|
92
|
+
"""Deserializes a Blink SSV.
|
|
93
|
+
|
|
94
|
+
The serialization format has two 'envelopes'.
|
|
95
|
+
[version tag] [Blink version] [version tag] [v8 version] ...
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
The deserialized script value.
|
|
99
|
+
"""
|
|
100
|
+
version_envelope_size = self._ReadVersionEnvelope()
|
|
101
|
+
self.deserializer = v8.ValueDeserializer(
|
|
102
|
+
io.BytesIO(self.raw_data[version_envelope_size:]), delegate=self)
|
|
103
|
+
v8_version = self.deserializer.ReadHeader()
|
|
104
|
+
if not self.version:
|
|
105
|
+
self.version = v8_version
|
|
106
|
+
return self.deserializer.ReadValue()
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def FromBytes(cls, data: bytes) -> Any:
|
|
110
|
+
"""Deserializes a Blink SSV from the data array.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
The deserialized script value.
|
|
114
|
+
"""
|
|
115
|
+
return cls(data).Deserialize()
|