dissect.database 1.2.dev12__py3-none-any.whl → 1.2.dev13__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.
- dissect/database/ese/c_ese.py +1 -0
- dissect/database/ese/c_ese.pyi +1 -0
- dissect/database/ese/compression.py +139 -14
- dissect/database/ese/table.py +1 -1
- {dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/METADATA +3 -3
- {dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/RECORD +11 -11
- {dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/WHEEL +0 -0
- {dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/entry_points.txt +0 -0
- {dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/licenses/COPYRIGHT +0 -0
- {dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/licenses/LICENSE +0 -0
- {dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/top_level.txt +0 -0
dissect/database/ese/c_ese.py
CHANGED
dissect/database/ese/c_ese.pyi
CHANGED
|
@@ -1,31 +1,74 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import struct
|
|
4
|
+
from typing import Final
|
|
4
5
|
|
|
5
|
-
from dissect.util.compression import lzxpress, sevenbit
|
|
6
|
+
from dissect.util.compression import lz4, lzxpress, lzxpress9, sevenbit
|
|
7
|
+
from dissect.util.hash import crc32c, crc64c
|
|
6
8
|
|
|
7
9
|
from dissect.database.ese.c_ese import COMPRESSION_SCHEME
|
|
8
10
|
|
|
11
|
+
_H: Final = struct.Struct("<H")
|
|
12
|
+
_I: Final = struct.Struct("<I")
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
_XPRESS_HEADER_SIZE: Final = 3
|
|
15
|
+
"""Scheme byte + u16 LE uncompressed size."""
|
|
16
|
+
|
|
17
|
+
_XPRESS9_HEADER_SIZE: Final = 5
|
|
18
|
+
"""Scheme byte + u32 LE plaintext CRC-32C (``Xpress9Header``)."""
|
|
19
|
+
|
|
20
|
+
_XPRESS10_HEADER: Final = struct.Struct("<BHIQ")
|
|
21
|
+
_XPRESS10_HEADER_SIZE: Final = 15
|
|
22
|
+
"""Scheme byte + u16 LE size + u32 LE CRC-32C + u64 LE CRC-64 (``Xpress10Header``)."""
|
|
23
|
+
|
|
24
|
+
_LZ4_HEADER: Final = struct.Struct("<BH")
|
|
25
|
+
_LZ4_HEADER_SIZE: Final = 3
|
|
26
|
+
"""Scheme byte + u16 LE uncompressed size (``Lz4Header``)."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def decompress(buf: bytes, *, verify: bool = True) -> bytes:
|
|
11
30
|
"""Decompress the given bytes according to the encoded compression scheme.
|
|
12
31
|
|
|
32
|
+
Handles all seven ESE record compression formats:
|
|
33
|
+
``COMPRESS_7BITASCII`` (0x1), ``COMPRESS_7BITUNICODE`` (0x2),
|
|
34
|
+
``COMPRESS_XPRESS`` (0x3), ``COMPRESS_SCRUB`` (0x4),
|
|
35
|
+
``COMPRESS_XPRESS9`` (0x5), ``COMPRESS_XPRESS10`` (0x6),
|
|
36
|
+
and ``COMPRESS_LZ4`` (0x7).
|
|
37
|
+
|
|
13
38
|
Args:
|
|
14
39
|
buf: The compressed bytes to decompress.
|
|
40
|
+
verify: When True, verify integrity checks on formats that carry them:
|
|
41
|
+
decoded-size match for XPRESS, CRC-32C for XPRESS9, CRC-64 and
|
|
42
|
+
CRC-32C for XPRESS10. LZ4 has no checksum. When False, skip all
|
|
43
|
+
integrity checks for speed or corrupt-data recovery.
|
|
15
44
|
|
|
16
45
|
Raises:
|
|
17
|
-
|
|
46
|
+
ValueError: If the buffer is a SCRUB erase marker or an integrity
|
|
47
|
+
check fails (when ``verify`` is True).
|
|
18
48
|
"""
|
|
19
49
|
identifier = buf[0] >> 3
|
|
50
|
+
|
|
20
51
|
if identifier == COMPRESSION_SCHEME.COMPRESS_7BITASCII:
|
|
21
52
|
return sevenbit.decompress(buf[1:])
|
|
53
|
+
|
|
22
54
|
if identifier == COMPRESSION_SCHEME.COMPRESS_7BITUNICODE:
|
|
23
55
|
return sevenbit.decompress(buf[1:], wide=True)
|
|
56
|
+
|
|
24
57
|
if identifier == COMPRESSION_SCHEME.COMPRESS_XPRESS:
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
58
|
+
return _decompress_xpress(buf, verify=verify)
|
|
59
|
+
|
|
60
|
+
if identifier == COMPRESSION_SCHEME.COMPRESS_SCRUB:
|
|
61
|
+
raise ValueError("Record is a SCRUB erase marker: no plaintext is recoverable")
|
|
62
|
+
|
|
63
|
+
if identifier == COMPRESSION_SCHEME.COMPRESS_XPRESS9:
|
|
64
|
+
return _decompress_xpress9(buf, verify=verify)
|
|
65
|
+
|
|
66
|
+
if identifier == COMPRESSION_SCHEME.COMPRESS_XPRESS10:
|
|
67
|
+
return _decompress_xpress10(buf, verify=verify)
|
|
68
|
+
|
|
69
|
+
if identifier == COMPRESSION_SCHEME.COMPRESS_LZ4:
|
|
70
|
+
return _decompress_lz4(buf)
|
|
71
|
+
|
|
29
72
|
return buf
|
|
30
73
|
|
|
31
74
|
|
|
@@ -36,15 +79,97 @@ def decompress_size(buf: bytes) -> int | None:
|
|
|
36
79
|
buf: The compressed bytes to return the decompressed size of.
|
|
37
80
|
|
|
38
81
|
Raises:
|
|
39
|
-
|
|
82
|
+
ValueError: If the buffer is a SCRUB erase marker.
|
|
40
83
|
"""
|
|
41
84
|
identifier = buf[0] >> 3
|
|
85
|
+
|
|
42
86
|
if identifier == COMPRESSION_SCHEME.COMPRESS_7BITASCII:
|
|
43
|
-
|
|
87
|
+
# Low 3 header bits hold the valid bit count of the final packed byte; the rest are full 8-bit bytes.
|
|
88
|
+
# https://github.com/microsoft/Extensible-Storage-Engine/blob/7030fe7407615160e54d152e4ef704eede2fdd7e/dev/ese/src/ese/compression.cxx#L2131-L2137
|
|
89
|
+
return ((len(buf) - 2) * 8 + (buf[0] & 7) + 1) // 7
|
|
90
|
+
|
|
44
91
|
if identifier == COMPRESSION_SCHEME.COMPRESS_7BITUNICODE:
|
|
45
|
-
return 2 * (((buf[0] & 7) +
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
92
|
+
return 2 * (((len(buf) - 2) * 8 + (buf[0] & 7) + 1) // 7)
|
|
93
|
+
|
|
94
|
+
if identifier in (
|
|
95
|
+
COMPRESSION_SCHEME.COMPRESS_XPRESS,
|
|
96
|
+
COMPRESSION_SCHEME.COMPRESS_XPRESS10,
|
|
97
|
+
COMPRESSION_SCHEME.COMPRESS_LZ4,
|
|
98
|
+
):
|
|
99
|
+
return _H.unpack_from(buf, 1)[0]
|
|
100
|
+
|
|
101
|
+
if identifier == COMPRESSION_SCHEME.COMPRESS_SCRUB:
|
|
102
|
+
raise ValueError("Record is a SCRUB erase marker: no decompressed size")
|
|
103
|
+
|
|
104
|
+
if identifier == COMPRESSION_SCHEME.COMPRESS_XPRESS9:
|
|
105
|
+
return lzxpress9.decompressed_size(buf[_XPRESS9_HEADER_SIZE:])
|
|
106
|
+
|
|
50
107
|
return None
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _decompress_xpress(buf: bytes, *, verify: bool = True) -> bytes:
|
|
111
|
+
"""Decompress an XPRESS (0x3) cell: 3-byte ESE header + Plain LZ77 stream.
|
|
112
|
+
|
|
113
|
+
When ``verify`` is True, checks that the decoded length matches the
|
|
114
|
+
header's declared uncompressed size.
|
|
115
|
+
|
|
116
|
+
References:
|
|
117
|
+
- https://github.com/microsoft/Extensible-Storage-Engine/blob/7030fe7407615160e54d152e4ef704eede2fdd7e/dev/ese/src/ese/compression.cxx#L2316-L2327
|
|
118
|
+
"""
|
|
119
|
+
declared = _H.unpack_from(buf, 1)[0]
|
|
120
|
+
plaintext = lzxpress.decompress(buf[_XPRESS_HEADER_SIZE:], declared)
|
|
121
|
+
if verify and len(plaintext) != declared:
|
|
122
|
+
raise ValueError(f"XPRESS decoded {len(plaintext)} bytes but header declares {declared}")
|
|
123
|
+
return plaintext
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _decompress_xpress9(buf: bytes, *, verify: bool = True) -> bytes:
|
|
127
|
+
"""Decompress an XPRESS9 (0x5) cell: 5-byte ESE header + XPRESS9 blocks.
|
|
128
|
+
|
|
129
|
+
When ``verify`` is True, checks the CRC-32C of the plaintext against
|
|
130
|
+
the value stored in the header.
|
|
131
|
+
|
|
132
|
+
References:
|
|
133
|
+
- https://github.com/microsoft/Extensible-Storage-Engine/blob/7030fe7407615160e54d152e4ef704eede2fdd7e/dev/ese/src/ese/compression.cxx#L2458-L2465
|
|
134
|
+
"""
|
|
135
|
+
stored_crc = _I.unpack_from(buf, 1)[0]
|
|
136
|
+
plaintext = lzxpress9.decompress(buf[_XPRESS9_HEADER_SIZE:])
|
|
137
|
+
if verify and (actual_crc := crc32c.crc32c(plaintext)) != stored_crc:
|
|
138
|
+
raise ValueError(f"XPRESS9 plaintext CRC-32C mismatch: 0x{stored_crc:08x} vs 0x{actual_crc:08x}")
|
|
139
|
+
return plaintext
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _decompress_xpress10(buf: bytes, *, verify: bool = True) -> bytes:
|
|
143
|
+
"""Decompress an XPRESS10 (0x6) cell: 15-byte ESE header + LZ4 block.
|
|
144
|
+
|
|
145
|
+
When ``verify`` is True, checks the CRC-64/NVME of the compressed payload
|
|
146
|
+
and the CRC-32C of the plaintext.
|
|
147
|
+
|
|
148
|
+
References:
|
|
149
|
+
- https://github.com/microsoft/Extensible-Storage-Engine/blob/7030fe7407615160e54d152e4ef704eede2fdd7e/dev/ese/src/ese/compression.cxx#L2581-L2593
|
|
150
|
+
- https://github.com/microsoft/Extensible-Storage-Engine/blob/7030fe7407615160e54d152e4ef704eede2fdd7e/dev/ese/src/ese/compression.cxx#L2615-L2619
|
|
151
|
+
"""
|
|
152
|
+
_, size, stored_crc32, stored_crc64 = _XPRESS10_HEADER.unpack_from(buf)
|
|
153
|
+
payload = buf[_XPRESS10_HEADER_SIZE:]
|
|
154
|
+
|
|
155
|
+
if verify and (actual_crc64 := crc64c.crc64c(payload)) != stored_crc64:
|
|
156
|
+
raise ValueError(f"XPRESS10 payload CRC-64 mismatch: 0x{stored_crc64:016x} vs 0x{actual_crc64:016x}")
|
|
157
|
+
|
|
158
|
+
plaintext = lz4.decompress(payload, size)
|
|
159
|
+
|
|
160
|
+
if verify and (actual_crc32 := crc32c.crc32c(plaintext)) != stored_crc32:
|
|
161
|
+
raise ValueError(f"XPRESS10 plaintext CRC-32C mismatch: 0x{stored_crc32:08x} vs 0x{actual_crc32:08x}")
|
|
162
|
+
|
|
163
|
+
return plaintext
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _decompress_lz4(buf: bytes) -> bytes:
|
|
167
|
+
"""Decompress an LZ4 (0x7) cell: 3-byte ESE header + LZ4 block.
|
|
168
|
+
|
|
169
|
+
LZ4 carries no checksum, so there is nothing to verify.
|
|
170
|
+
|
|
171
|
+
References:
|
|
172
|
+
- https://github.com/microsoft/Extensible-Storage-Engine/blob/7030fe7407615160e54d152e4ef704eede2fdd7e/dev/ese/src/ese/compression.cxx#L2643-L2699
|
|
173
|
+
"""
|
|
174
|
+
_, size = _LZ4_HEADER.unpack_from(buf)
|
|
175
|
+
return lz4.decompress(buf[_LZ4_HEADER_SIZE:], size)
|
dissect/database/ese/table.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dissect.database
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.dev13
|
|
4
4
|
Summary: A Dissect module implementing parsers for various database formats, including Berkeley DB, Microsofts Extensible Storage Engine (ESE) and SQLite3
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -22,13 +22,13 @@ Description-Content-Type: text/markdown
|
|
|
22
22
|
License-File: LICENSE
|
|
23
23
|
License-File: COPYRIGHT
|
|
24
24
|
Requires-Dist: dissect.cstruct<5,>=4
|
|
25
|
-
Requires-Dist: dissect.util<4,>=3.
|
|
25
|
+
Requires-Dist: dissect.util<4,>=3.25.dev24
|
|
26
26
|
Provides-Extra: full
|
|
27
27
|
Requires-Dist: pycryptodome; extra == "full"
|
|
28
28
|
Provides-Extra: dev
|
|
29
29
|
Requires-Dist: dissect.database[full]; extra == "dev"
|
|
30
30
|
Requires-Dist: dissect.cstruct<5.0.dev,>=4.0.dev; extra == "dev"
|
|
31
|
-
Requires-Dist: dissect.util<4.0.dev,>=3.
|
|
31
|
+
Requires-Dist: dissect.util<4.0.dev,>=3.25.dev; extra == "dev"
|
|
32
32
|
Dynamic: license-file
|
|
33
33
|
|
|
34
34
|
# dissect.database
|
|
@@ -13,9 +13,9 @@ dissect/database/bsd/tools/c_rpm.py,sha256=yI9JIerMRPCsO-QZRXzFmY4sAo1fvdwYvLL0S
|
|
|
13
13
|
dissect/database/bsd/tools/c_rpm.pyi,sha256=a22dZ8eMGPnj9rsKWjT7ol82Q6OmEcTgWsLNBbBJ3IM,15116
|
|
14
14
|
dissect/database/bsd/tools/rpm.py,sha256=Wpmhfr4w4_TTFpp94o1RCcjPkwrHxyebIUz-P03r3OE,7699
|
|
15
15
|
dissect/database/ese/__init__.py,sha256=aF5V41QUz6KMUtzBQ1Mak3PlK-TbidbPxRNRnngNtLc,559
|
|
16
|
-
dissect/database/ese/c_ese.py,sha256=
|
|
17
|
-
dissect/database/ese/c_ese.pyi,sha256=
|
|
18
|
-
dissect/database/ese/compression.py,sha256=
|
|
16
|
+
dissect/database/ese/c_ese.py,sha256=dZxmqMzfoE3Ra6UdcH80Pz5UwmSS3epbnBcbdcS8UQQ,24678
|
|
17
|
+
dissect/database/ese/c_ese.pyi,sha256=86IMu4ToXaMmDmpyUWvoajc81DsJZHhK3hLwcSZHS9M,18901
|
|
18
|
+
dissect/database/ese/compression.py,sha256=R8WjYKFFB279EYmCWQU-Xl1NGq8amLkC-ylLnJ4yRc4,6986
|
|
19
19
|
dissect/database/ese/cursor.py,sha256=ju-mUewhW22bVW0MMdsaKolKCiKnztRcyU0nJw5bNOg,14346
|
|
20
20
|
dissect/database/ese/ese.py,sha256=MryiOFbbAE7G1spUk0d5liQTt14nLREVAFnfaj7QW18,3575
|
|
21
21
|
dissect/database/ese/exception.py,sha256=09xbltclWIBsGbk8Ry8RlKG-OwGSQvyLKsgj0d98T0k,210
|
|
@@ -24,7 +24,7 @@ dissect/database/ese/lcmapstring.py,sha256=sI0jnSHnuCYwXS3YqBruGixlHXm44L3au5llR
|
|
|
24
24
|
dissect/database/ese/page.py,sha256=TbR_pGBKCaYag1SBAYtcQp8EnGOw3QRp3tLMNeuVdCM,8325
|
|
25
25
|
dissect/database/ese/record.py,sha256=DKBwkyuszsuUaBgu3iD41cidmw4GEpaoNNKPhI0Tnxg,19723
|
|
26
26
|
dissect/database/ese/sorting_table.py,sha256=NsBchm4-XxyDKZrdt2M_wMuGELUQed5osKbv1RxmIbk,819383
|
|
27
|
-
dissect/database/ese/table.py,sha256=
|
|
27
|
+
dissect/database/ese/table.py,sha256=JgjKBnRqPZmCX4DxaSnpJoYAJtGtfI8qyWlUDhyH3qA,13351
|
|
28
28
|
dissect/database/ese/util.py,sha256=5ZWurLGHahG4LL4iXpYCK9kbMLr53dVh18f1Ox9YHlA,3044
|
|
29
29
|
dissect/database/ese/ntds/__init__.py,sha256=Fu6_i_7fAlDfJoOgbpsVlPxM4CXpDCNtXmgzNzkmesY,264
|
|
30
30
|
dissect/database/ese/ntds/c_ds.py,sha256=ZaWdEcpJPJrRjiJFhi1s5KlOIVj0yoix4XAh-D31uLU,3055
|
|
@@ -165,10 +165,10 @@ dissect/database/sqlite3/encryption/__init__.py,sha256=kJdFWXD9Z_O_QipC-_A9dlVfR
|
|
|
165
165
|
dissect/database/sqlite3/encryption/sqlcipher/__init__.py,sha256=kJdFWXD9Z_O_QipC-_A9dlVfR6AOPSOoT8WBhpFbSsE,238
|
|
166
166
|
dissect/database/sqlite3/encryption/sqlcipher/exception.py,sha256=GKNtzcnAKlWkvjLluruA8LfzCwjRRWubibbH8WM9l2o,121
|
|
167
167
|
dissect/database/sqlite3/encryption/sqlcipher/sqlcipher.py,sha256=y_oJRKZqoJBeOQaBbniesZKm1sVTFvXZ466rJYZj2xE,11217
|
|
168
|
-
dissect_database-1.2.
|
|
169
|
-
dissect_database-1.2.
|
|
170
|
-
dissect_database-1.2.
|
|
171
|
-
dissect_database-1.2.
|
|
172
|
-
dissect_database-1.2.
|
|
173
|
-
dissect_database-1.2.
|
|
174
|
-
dissect_database-1.2.
|
|
168
|
+
dissect_database-1.2.dev13.dist-info/licenses/COPYRIGHT,sha256=pFH-OBYz6Xj23UB0Odz5IhoTR8nsTbJQNlCRV_wMaiE,317
|
|
169
|
+
dissect_database-1.2.dev13.dist-info/licenses/LICENSE,sha256=PhUqiw6jAh2KbBdVRPBq_hfAvfcTBin7nZ3CK7NQbTM,11341
|
|
170
|
+
dissect_database-1.2.dev13.dist-info/METADATA,sha256=EDrsAuGVQXZeyytuQCIeGKNSl9pfsa5jssev1UT7zC0,5551
|
|
171
|
+
dissect_database-1.2.dev13.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
172
|
+
dissect_database-1.2.dev13.dist-info/entry_points.txt,sha256=ZVVKj3Nzjkgm1kBXGWyGNVUJzTbmVgivv9lgFcuLkpk,343
|
|
173
|
+
dissect_database-1.2.dev13.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
174
|
+
dissect_database-1.2.dev13.dist-info/RECORD,,
|
|
File without changes
|
{dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/licenses/COPYRIGHT
RENAMED
|
File without changes
|
{dissect_database-1.2.dev12.dist-info → dissect_database-1.2.dev13.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|