linear-mcp-fast 0.1.0__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.
- ccl_chromium_reader/__init__.py +2 -0
- ccl_chromium_reader/ccl_chromium_cache.py +1335 -0
- ccl_chromium_reader/ccl_chromium_filesystem.py +302 -0
- ccl_chromium_reader/ccl_chromium_history.py +357 -0
- ccl_chromium_reader/ccl_chromium_indexeddb.py +1060 -0
- ccl_chromium_reader/ccl_chromium_localstorage.py +454 -0
- ccl_chromium_reader/ccl_chromium_notifications.py +268 -0
- ccl_chromium_reader/ccl_chromium_profile_folder.py +568 -0
- ccl_chromium_reader/ccl_chromium_sessionstorage.py +368 -0
- ccl_chromium_reader/ccl_chromium_snss2.py +332 -0
- ccl_chromium_reader/ccl_shared_proto_db_downloads.py +189 -0
- ccl_chromium_reader/common.py +19 -0
- ccl_chromium_reader/download_common.py +78 -0
- ccl_chromium_reader/profile_folder_protocols.py +276 -0
- ccl_chromium_reader/serialization_formats/__init__.py +0 -0
- ccl_chromium_reader/serialization_formats/ccl_blink_value_deserializer.py +401 -0
- ccl_chromium_reader/serialization_formats/ccl_easy_chromium_pickle.py +133 -0
- ccl_chromium_reader/serialization_formats/ccl_protobuff.py +276 -0
- ccl_chromium_reader/serialization_formats/ccl_v8_value_deserializer.py +627 -0
- ccl_chromium_reader/storage_formats/__init__.py +0 -0
- ccl_chromium_reader/storage_formats/ccl_leveldb.py +582 -0
- ccl_simplesnappy/__init__.py +1 -0
- ccl_simplesnappy/ccl_simplesnappy.py +306 -0
- linear_mcp_fast/__init__.py +8 -0
- linear_mcp_fast/__main__.py +6 -0
- linear_mcp_fast/reader.py +433 -0
- linear_mcp_fast/server.py +367 -0
- linear_mcp_fast/store_detector.py +117 -0
- linear_mcp_fast-0.1.0.dist-info/METADATA +160 -0
- linear_mcp_fast-0.1.0.dist-info/RECORD +39 -0
- linear_mcp_fast-0.1.0.dist-info/WHEEL +5 -0
- linear_mcp_fast-0.1.0.dist-info/entry_points.txt +2 -0
- linear_mcp_fast-0.1.0.dist-info/top_level.txt +4 -0
- tools_and_utilities/Chromium_dump_local_storage.py +111 -0
- tools_and_utilities/Chromium_dump_session_storage.py +92 -0
- tools_and_utilities/benchmark.py +35 -0
- tools_and_utilities/ccl_chrome_audit.py +651 -0
- tools_and_utilities/dump_indexeddb_details.py +59 -0
- tools_and_utilities/dump_leveldb.py +53 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2020, CCL Forensics
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
8
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
9
|
+
so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import sys
|
|
24
|
+
import struct
|
|
25
|
+
import io
|
|
26
|
+
import typing
|
|
27
|
+
import enum
|
|
28
|
+
|
|
29
|
+
__version__ = "0.4"
|
|
30
|
+
__description__ = "Pure Python reimplementation of Google's Snappy decompression"
|
|
31
|
+
__contact__ = "Alex Caithness"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
DEBUG = False
|
|
35
|
+
FRAME_MAGIC = bytes.fromhex("73 4E 61 50 70 59")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def make_crc_table(poly):
|
|
39
|
+
table = []
|
|
40
|
+
for i in range(256):
|
|
41
|
+
crc = 0
|
|
42
|
+
for _ in range(8):
|
|
43
|
+
if (i ^ crc) & 1:
|
|
44
|
+
crc = (crc >> 1) ^ poly
|
|
45
|
+
else:
|
|
46
|
+
crc >>= 1
|
|
47
|
+
i >>= 1
|
|
48
|
+
table.append(crc)
|
|
49
|
+
return table
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
CRC_POLY = 0x82F63B78
|
|
53
|
+
CRC_QUICK_TABLE = tuple(make_crc_table(CRC_POLY))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def crc32c(data, xor_value=0xffffffff):
|
|
57
|
+
value = 0xffffffff
|
|
58
|
+
for b in data:
|
|
59
|
+
value = CRC_QUICK_TABLE[(b ^ value) & 0xff] ^ (value >> 8)
|
|
60
|
+
|
|
61
|
+
value ^= xor_value
|
|
62
|
+
return value
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# def log(msg):
|
|
66
|
+
# if DEBUG:
|
|
67
|
+
# print(msg)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class NoMoreData(Exception):
|
|
71
|
+
...
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ElementType(enum.IntEnum):
|
|
75
|
+
"""Run type in the compressed snappy data (literal data or offset to backreferenced data_"""
|
|
76
|
+
Literal = 0
|
|
77
|
+
CopyOneByte = 1
|
|
78
|
+
CopyTwoByte = 2
|
|
79
|
+
CopyFourByte = 3
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _read_le_varint(stream: typing.BinaryIO) -> typing.Optional[typing.Tuple[int, bytes]]:
|
|
83
|
+
"""Read varint from a stream.
|
|
84
|
+
If the read is successful: returns a tuple of the (unsigned) value and the raw bytes making up that varint,
|
|
85
|
+
otherwise returns None"""
|
|
86
|
+
# this only outputs unsigned
|
|
87
|
+
i = 0
|
|
88
|
+
result = 0
|
|
89
|
+
underlying_bytes = []
|
|
90
|
+
while i < 10: # 64 bit max possible?
|
|
91
|
+
raw = stream.read(1)
|
|
92
|
+
if len(raw) < 1:
|
|
93
|
+
return None
|
|
94
|
+
tmp, = raw
|
|
95
|
+
underlying_bytes.append(tmp)
|
|
96
|
+
result |= ((tmp & 0x7f) << (i * 7))
|
|
97
|
+
if (tmp & 0x80) == 0:
|
|
98
|
+
break
|
|
99
|
+
i += 1
|
|
100
|
+
return result, bytes(underlying_bytes)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def read_le_varint(stream: typing.BinaryIO) -> typing.Optional[int]:
|
|
104
|
+
"""Convenience version of _read_le_varint that only returns the value or None"""
|
|
105
|
+
x = _read_le_varint(stream)
|
|
106
|
+
if x is None:
|
|
107
|
+
return None
|
|
108
|
+
else:
|
|
109
|
+
return x[0]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def read_uint16(stream: typing.BinaryIO) -> int:
|
|
113
|
+
"""Reads an Uint16 from stream"""
|
|
114
|
+
return struct.unpack("<H", stream.read(2))[0]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def read_uint24(stream: typing.BinaryIO) -> int:
|
|
118
|
+
"""Reads an Uint24 from stream"""
|
|
119
|
+
return struct.unpack("<I", stream.read(3) + b"\x00")[0]
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def read_uint32(stream: typing.BinaryIO) -> int:
|
|
123
|
+
"""Reads an Uint32 from stream"""
|
|
124
|
+
return struct.unpack("<I", stream.read(4))[0]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def read_byte(stream: typing.BinaryIO) -> typing.Optional[int]:
|
|
128
|
+
"""Reads a single byte from stream (or returns None if EOD is met)"""
|
|
129
|
+
x = stream.read(1)
|
|
130
|
+
if x:
|
|
131
|
+
return x[0]
|
|
132
|
+
|
|
133
|
+
return None
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def decompress(data: typing.BinaryIO) -> bytes:
|
|
137
|
+
"""Decompresses the snappy compressed data stream"""
|
|
138
|
+
uncompressed_length = read_le_varint(data)
|
|
139
|
+
# log(f"Uncompressed length: {uncompressed_length}")
|
|
140
|
+
|
|
141
|
+
out = io.BytesIO()
|
|
142
|
+
|
|
143
|
+
while True:
|
|
144
|
+
start_offset = data.tell()
|
|
145
|
+
# log(f"Reading tag at offset {start_offset}")
|
|
146
|
+
type_byte = read_byte(data)
|
|
147
|
+
if type_byte is None:
|
|
148
|
+
break
|
|
149
|
+
|
|
150
|
+
# log(f"Type Byte is {type_byte:02x}")
|
|
151
|
+
|
|
152
|
+
tag = type_byte & 0x03
|
|
153
|
+
|
|
154
|
+
# log(f"Element Type is: {ElementType(tag)}")
|
|
155
|
+
|
|
156
|
+
if tag == ElementType.Literal:
|
|
157
|
+
if ((type_byte & 0xFC) >> 2) < 60: # embedded in tag
|
|
158
|
+
length = 1 + ((type_byte & 0xFC) >> 2)
|
|
159
|
+
# log(f"Literal length is embedded in type byte and is {length}")
|
|
160
|
+
elif ((type_byte & 0xFC) >> 2) == 60: # 8 bit
|
|
161
|
+
length = 1 + read_byte(data)
|
|
162
|
+
# log(f"Literal length is 8bit and is {length}")
|
|
163
|
+
elif ((type_byte & 0xFC) >> 2) == 61: # 16 bit
|
|
164
|
+
length = 1 + read_uint16(data)
|
|
165
|
+
# log(f"Literal length is 16bit and is {length}")
|
|
166
|
+
elif ((type_byte & 0xFC) >> 2) == 62: # 16 bit
|
|
167
|
+
length = 1 + read_uint24(data)
|
|
168
|
+
# log(f"Literal length is 24bit and is {length}")
|
|
169
|
+
elif ((type_byte & 0xFC) >> 2) == 63: # 16 bit
|
|
170
|
+
length = 1 + read_uint32(data)
|
|
171
|
+
# log(f"Literal length is 32bit and is {length}")
|
|
172
|
+
else:
|
|
173
|
+
raise ValueError() # cannot ever happen
|
|
174
|
+
|
|
175
|
+
literal_data = data.read(length)
|
|
176
|
+
if len(literal_data) < length:
|
|
177
|
+
raise ValueError("Couldn't read enough literal data")
|
|
178
|
+
|
|
179
|
+
out.write(literal_data)
|
|
180
|
+
|
|
181
|
+
else:
|
|
182
|
+
if tag == ElementType.CopyOneByte:
|
|
183
|
+
length = ((type_byte & 0x1C) >> 2) + 4
|
|
184
|
+
offset = ((type_byte & 0xE0) << 3) | read_byte(data)
|
|
185
|
+
elif tag == ElementType.CopyTwoByte:
|
|
186
|
+
length = 1 + ((type_byte & 0xFC) >> 2)
|
|
187
|
+
offset = read_uint16(data)
|
|
188
|
+
elif tag == ElementType.CopyFourByte:
|
|
189
|
+
length = 1 + ((type_byte & 0xFC) >> 2)
|
|
190
|
+
offset = read_uint32(data)
|
|
191
|
+
else:
|
|
192
|
+
raise ValueError() # cannot ever happen
|
|
193
|
+
|
|
194
|
+
if offset == 0:
|
|
195
|
+
raise ValueError("Offset cannot be 0")
|
|
196
|
+
|
|
197
|
+
actual_offset = out.tell() - offset
|
|
198
|
+
# log(f"Current Outstream Length: {out.tell()}")
|
|
199
|
+
# log(f"Backreference length: {length}")
|
|
200
|
+
# log(f"Backreference relative offset: {offset}")
|
|
201
|
+
# log(f"Backreference absolute offset: {actual_offset}")
|
|
202
|
+
|
|
203
|
+
# have to read incrementally because you might have to read data that you've just written
|
|
204
|
+
# for i in range(length):
|
|
205
|
+
# out.write(out.getbuffer()[actual_offset + i: actual_offset + i + 1].tobytes())
|
|
206
|
+
buffer = out.getbuffer()[actual_offset: actual_offset + length].tobytes()
|
|
207
|
+
if offset - length <= 0:
|
|
208
|
+
# better safe than sorry, this way we're sure to extend it
|
|
209
|
+
# as much as needed without doing some extra calculations
|
|
210
|
+
buffer = (buffer * length)[:length]
|
|
211
|
+
out.write(buffer)
|
|
212
|
+
|
|
213
|
+
result = out.getvalue()
|
|
214
|
+
if uncompressed_length != len(result):
|
|
215
|
+
raise ValueError("Wrong data length in uncompressed data")
|
|
216
|
+
# TODO: allow a partial / potentially bad result via a flag in the function call?
|
|
217
|
+
|
|
218
|
+
return result
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def check_masked_crc(crc, data, xor_value=0xffffffff):
|
|
222
|
+
check = crc32c(data, xor_value=xor_value)
|
|
223
|
+
|
|
224
|
+
check = ((check >> 15) | (check << 17)) & 0xffffffff # rotate
|
|
225
|
+
check += 0xa282ead8 # add constant
|
|
226
|
+
check %= 0x100000000 # wraparound as an uint32
|
|
227
|
+
|
|
228
|
+
return crc == check
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def read_frame(frame_stream: typing.BinaryIO):
|
|
232
|
+
frame_header = frame_stream.read(4)
|
|
233
|
+
if not frame_header:
|
|
234
|
+
raise NoMoreData()
|
|
235
|
+
if len(frame_header) < 4:
|
|
236
|
+
raise ValueError("Could not read entire frame header")
|
|
237
|
+
|
|
238
|
+
frame_id = frame_header[0]
|
|
239
|
+
frame_length, = struct.unpack("<I", frame_header[1:] + b"\x00")
|
|
240
|
+
|
|
241
|
+
data = frame_stream.read(frame_length)
|
|
242
|
+
if len(data) != frame_length:
|
|
243
|
+
raise ValueError(f"Could not read all data; wanted: {frame_length}; got: {len(data)}")
|
|
244
|
+
|
|
245
|
+
return frame_id, data
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def decompress_framed(frame_stream: typing.BinaryIO, out_stream: typing.BinaryIO, *, mozilla_mode=False):
|
|
249
|
+
"""
|
|
250
|
+
Decompresses a Snappy framed format stream into another stream.
|
|
251
|
+
|
|
252
|
+
:param frame_stream: Stream containing the Snappy Framed data
|
|
253
|
+
:param out_stream: Stream that the decompressed data will be written to.
|
|
254
|
+
:param mozilla_mode: If True, use the (non-standard) checksum format used by Mozilla
|
|
255
|
+
:return:
|
|
256
|
+
"""
|
|
257
|
+
header_type, header_raw = read_frame(frame_stream)
|
|
258
|
+
if header_type != 0xff or header_raw != FRAME_MAGIC:
|
|
259
|
+
raise ValueError("Invalid magic")
|
|
260
|
+
|
|
261
|
+
while True:
|
|
262
|
+
frame_offset = frame_stream.tell()
|
|
263
|
+
try:
|
|
264
|
+
frame_type, frame_data = read_frame(frame_stream)
|
|
265
|
+
except NoMoreData:
|
|
266
|
+
break
|
|
267
|
+
|
|
268
|
+
if frame_type == 0x00: # compressed
|
|
269
|
+
crc_raw = frame_data[0:4]
|
|
270
|
+
with io.BytesIO(frame_data[4:]) as compressed:
|
|
271
|
+
decompressed = decompress(compressed)
|
|
272
|
+
stored_crc, = struct.unpack("<I", crc_raw)
|
|
273
|
+
crc_match = check_masked_crc(stored_crc, decompressed, xor_value=0x0 if mozilla_mode else 0xffffffff)
|
|
274
|
+
if not crc_match:
|
|
275
|
+
raise ValueError(f"CRC mismatch in frame starting at {frame_offset}")
|
|
276
|
+
|
|
277
|
+
out_stream.write(decompressed)
|
|
278
|
+
elif frame_type == 0x01: # decompressed
|
|
279
|
+
crc_raw = frame_data[0:4]
|
|
280
|
+
stored_crc, = struct.unpack("<I", crc_raw)
|
|
281
|
+
crc_match = check_masked_crc(stored_crc, frame_data[4:], xor_value=0x0 if mozilla_mode else 0xffffffff)
|
|
282
|
+
if not crc_match:
|
|
283
|
+
raise ValueError(f"CRC mismatch in frame starting at {frame_offset}")
|
|
284
|
+
out_stream.write(frame_data[4:])
|
|
285
|
+
elif frame_type == 0xfe: # padding
|
|
286
|
+
pass
|
|
287
|
+
elif 0x02 <= frame_type <= 0x7f: # reserved, unskippable
|
|
288
|
+
raise ValueError("Reserved unskippable data")
|
|
289
|
+
elif 0x80 <= frame_type <= 0xfe: # reserved, skippable
|
|
290
|
+
pass
|
|
291
|
+
else:
|
|
292
|
+
raise ValueError("unexpected frame")
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def _main(in_path, out_path):
|
|
296
|
+
import pathlib
|
|
297
|
+
|
|
298
|
+
in_path = pathlib.Path(in_path)
|
|
299
|
+
out_path = pathlib.Path(out_path)
|
|
300
|
+
with in_path.open("rb") as f:
|
|
301
|
+
with out_path.open("wb") as out:
|
|
302
|
+
decompress_framed(f, out)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
if __name__ == "__main__":
|
|
306
|
+
_main(sys.argv[1], sys.argv[2])
|