ntcompress 0.1.0__tar.gz

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.

Potentially problematic release.


This version of ntcompress might be problematic. Click here for more details.

@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,14 @@
1
+ ntcompress
2
+ Copyright 2026 ntcompress contributors
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
+ these files except in compliance with the License. You may obtain a copy of the
6
+ License in the LICENSE file or at http://www.apache.org/licenses/LICENSE-2.0.
7
+
8
+ This product contains software derived from the Microsoft Extensible Storage
9
+ Engine (https://github.com/microsoft/Extensible-Storage-Engine), licensed under
10
+ the MIT License, Copyright (c) Microsoft Corporation. The XPRESS9 decoder and the
11
+ CRC-32C / CRC-64 routines are ports of that MIT-licensed source. It also contains
12
+ codecs derived from the published Microsoft Open Specification [MS-XCA] and an
13
+ implementation of the LZ4 block format (Yann Collet). See THIRD-PARTY-NOTICES.md
14
+ for the full attributions and license texts.
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: ntcompress
3
+ Version: 0.1.0
4
+ Summary: Pure-Python implementations of every Microsoft ESE record-compression scheme and Windows ntdll RtlCompressBuffer/RtlDecompressBuffer format.
5
+ Keywords: ese,esent,jet,ntdll,xpress,xpress9,xpress10,lznt1,lz4,ms-xca,compression,forensics
6
+ Author: ntcompress contributors
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ License-File: NOTICE
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Security
18
+ Classifier: Topic :: System :: Archiving :: Compression
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Project-URL: Repository, https://github.com/StrongWind1/ntcompress
22
+ Project-URL: Documentation, https://strongwind1.github.io/ntcompress/
23
+ Project-URL: Changelog, https://github.com/StrongWind1/ntcompress/blob/main/CHANGELOG.md
24
+ Project-URL: Issues, https://github.com/StrongWind1/ntcompress/issues
25
+ Description-Content-Type: text/markdown
26
+
27
+ # ntcompress
28
+
29
+ Pure-Python, standard-library-only implementations of every compression format used by Microsoft's Extensible Storage Engine (ESE/ESENT, the "JET Blue" engine behind `NTDS.dit`, Exchange stores, `Windows.edb`, `SRUDB.dat`, and `WebCacheV01.dat`) and Windows `ntdll.dll` compression (`RtlCompressBuffer` / `RtlDecompressBuffer`). No runtime dependencies beyond the standard library.
30
+
31
+ ## Scope
32
+
33
+ This library covers two distinct compression layers used by Windows:
34
+
35
+ ### ESE record compression (vs `esent.dll`)
36
+
37
+ ESE stores a one-byte header on each compressed record cell; the top 5 bits select the scheme (`first_byte >> 3`) and the low 3 bits carry scheme-specific flags.
38
+
39
+ | ESE ID | Format | Decompress | Compress | Byte-Identical to esent.dll | Authority |
40
+ |--------|--------|-----------|----------|---------------------------|-----------|
41
+ | `0x0` | NONE (uncompressed sentinel) | — | — | — | `compression.cxx:504` |
42
+ | `0x1` | 7-bit ASCII | yes | yes | yes | ESE source |
43
+ | `0x2` | 7-bit Unicode | yes | yes | yes | ESE source |
44
+ | `0x3` | XPRESS (Plain LZ77) | yes | yes | yes | `[MS-XCA] §2.3/2.4` |
45
+ | `0x4` | SCRUB (erase marker) | produce | recognize | n/a | ESE source |
46
+ | `0x5` | XPRESS9 | yes | yes | yes* | ESE MIT source (ported) |
47
+ | `0x6` | XPRESS10 (LZ4 + CRC) | yes | yes | yes** | ESE source |
48
+ | `0x7` | LZ4 (standard block) | yes | yes | yes | LZ4 block format |
49
+
50
+ \*XPRESS9 encoder matches the MIT ESE C reference byte-for-byte excluding the non-deterministic session signature (`CRC32(__rdtsc())`), which even `esent.dll` varies on every call. \*\*XPRESS10 verified byte-identical by component construction (LZ4 block + CRC-32C + CRC-64/NVME each individually proven); not triggerable on commodity hardware (requires Corsica/QAT flight flag).
51
+
52
+ ### ntdll compression (vs `RtlCompressBuffer`)
53
+
54
+ Windows `ntdll.dll` exposes a separate set of `CompressionFormatAndEngine` IDs used by SMB, NTFS, RDP, and other protocols. These use raw bitstreams with no ESE framing.
55
+
56
+ | ntdll ID | Name | Decompress | Compress | Byte-Identical to ntdll | Builds |
57
+ |----------|------|-----------|----------|------------------------|--------|
58
+ | `0x0002` | LZNT1 | yes | yes | yes (ENGINE_MAX) | XP SP3 – Server 2025 |
59
+ | `0x0003` | XPRESS (Plain LZ77) | yes | yes | yes | Win8.1 – Server 2025 |
60
+ | `0x0004` | XPRESS_HUFF (LZ77+Huffman) | yes | yes | yes (default engine) | Win8.1 – Server 2025 |
61
+ | `0x0005` | undocumented | — | — | — | Server 2022+ |
62
+ | `0x0006` | XP10 (LZ4 block) | yes | yes | yes | Win11 / Server 2025 |
63
+ | `0x0007` | raw DEFLATE | yes | yes | yes (both levels) | Win11 / Server 2025 |
64
+ | `0x0008` | ZLIB | yes | yes | yes (both levels) | Win11 / Server 2025 |
65
+
66
+ ntdll format 0x0005 is an undocumented format (block magic `0xC039E510`) unrelated to XPRESS9 despite sharing the slot number. No public specification or source code exists. Format 0x0006 (XP10) is the same LZ4 block codec used by ESE scheme 0x6 and 0x7, without the ESE header.
67
+
68
+ ## Design principles
69
+
70
+ - **Standard library only at runtime.** No third-party dependencies. `zlib`/`lz4` are deliberately not used; the CRCs and the LZ4 block codec are implemented directly.
71
+ - **Two subpackages, one interface pattern.** `ntcompress.ese` for ESE record-compression, `ntcompress.ntdll` for ntdll standalone codecs. Both offer Shape A (enum dispatch) and Shape B (direct module import) APIs.
72
+ - **Traceable to a spec or a source line.** Every wire constant cites `[MS-XCA] §x.y` or an ESE `file:line`. Where the shipped C diverges from the spec text, both are documented.
73
+ - **Byte-identical verification.** Compress output is verified against gold vectors captured from `esent.dll` and `ntdll.dll` on 16 Windows builds (XP SP3 through Server 2025).
74
+ - **Typed and documented.** Python 3.11+, full type hints, Google-style docstrings, `ruff`-clean under `select = ["ALL"]`, `ty`-clean.
75
+
76
+ ## Installation
77
+
78
+ ```bash
79
+ uv add ntcompress # once published
80
+ ```
81
+
82
+ Requires Python >= 3.11.
83
+
84
+ ## Usage
85
+
86
+ ### ESE record compression
87
+
88
+ ```python
89
+ import ntcompress.ese as ese
90
+
91
+ # Decompress a cell (format is in byte 0)
92
+ plaintext = ese.decompress(cell)
93
+ size = ese.decompressed_size(cell)
94
+
95
+ # Compress with a specific format
96
+ cell = ese.compress(plaintext, ese.Format.XPRESS)
97
+ cell = ese.compress(plaintext, ese.Format.LZ4)
98
+ cell = ese.compress(plaintext, ese.Format.XPRESS9)
99
+
100
+ # Or use Shape B (direct module access)
101
+ from ntcompress.ese import xpress
102
+ cell = xpress.compress(plaintext)
103
+ plaintext = xpress.decompress(cell)
104
+ ```
105
+
106
+ ### ntdll standalone codecs
107
+
108
+ ```python
109
+ import ntcompress.ntdll as ntdll
110
+
111
+ # Shape A (enum dispatch)
112
+ compressed = ntdll.compress(data, ntdll.Format.LZNT1)
113
+ plaintext = ntdll.decompress(compressed, ntdll.Format.LZNT1)
114
+
115
+ # Windows constant aliases
116
+ compressed = ntdll.compress(data, ntdll.COMPRESSION_FORMAT_XPRESS_HUFF)
117
+
118
+ # Shape B (direct module access)
119
+ from ntcompress.ntdll import lznt1, xpress_huff, deflate
120
+ from ntcompress.ntdll import zlib as ntdll_zlib
121
+
122
+ plaintext = lznt1.decompress(compressed_stream)
123
+ compressed = xpress_huff.compress(data)
124
+ compressed = deflate.compress(data) # matches ntdll 0x0007
125
+ compressed = ntdll_zlib.compress(data) # matches ntdll 0x0008
126
+ ```
127
+
128
+ ## License and attribution
129
+
130
+ Apache-2.0 (`LICENSE`). The XPRESS9 codec is an attributed port of Microsoft's MIT-licensed ESE source; the Plain LZ77, Xpress Huffman, and LZNT1 codecs are derived from the published `[MS-XCA]` specification; the LZ4 block codec follows the public LZ4 format. Full notices are in `THIRD-PARTY-NOTICES.md`.
@@ -0,0 +1,104 @@
1
+ # ntcompress
2
+
3
+ Pure-Python, standard-library-only implementations of every compression format used by Microsoft's Extensible Storage Engine (ESE/ESENT, the "JET Blue" engine behind `NTDS.dit`, Exchange stores, `Windows.edb`, `SRUDB.dat`, and `WebCacheV01.dat`) and Windows `ntdll.dll` compression (`RtlCompressBuffer` / `RtlDecompressBuffer`). No runtime dependencies beyond the standard library.
4
+
5
+ ## Scope
6
+
7
+ This library covers two distinct compression layers used by Windows:
8
+
9
+ ### ESE record compression (vs `esent.dll`)
10
+
11
+ ESE stores a one-byte header on each compressed record cell; the top 5 bits select the scheme (`first_byte >> 3`) and the low 3 bits carry scheme-specific flags.
12
+
13
+ | ESE ID | Format | Decompress | Compress | Byte-Identical to esent.dll | Authority |
14
+ |--------|--------|-----------|----------|---------------------------|-----------|
15
+ | `0x0` | NONE (uncompressed sentinel) | — | — | — | `compression.cxx:504` |
16
+ | `0x1` | 7-bit ASCII | yes | yes | yes | ESE source |
17
+ | `0x2` | 7-bit Unicode | yes | yes | yes | ESE source |
18
+ | `0x3` | XPRESS (Plain LZ77) | yes | yes | yes | `[MS-XCA] §2.3/2.4` |
19
+ | `0x4` | SCRUB (erase marker) | produce | recognize | n/a | ESE source |
20
+ | `0x5` | XPRESS9 | yes | yes | yes* | ESE MIT source (ported) |
21
+ | `0x6` | XPRESS10 (LZ4 + CRC) | yes | yes | yes** | ESE source |
22
+ | `0x7` | LZ4 (standard block) | yes | yes | yes | LZ4 block format |
23
+
24
+ \*XPRESS9 encoder matches the MIT ESE C reference byte-for-byte excluding the non-deterministic session signature (`CRC32(__rdtsc())`), which even `esent.dll` varies on every call. \*\*XPRESS10 verified byte-identical by component construction (LZ4 block + CRC-32C + CRC-64/NVME each individually proven); not triggerable on commodity hardware (requires Corsica/QAT flight flag).
25
+
26
+ ### ntdll compression (vs `RtlCompressBuffer`)
27
+
28
+ Windows `ntdll.dll` exposes a separate set of `CompressionFormatAndEngine` IDs used by SMB, NTFS, RDP, and other protocols. These use raw bitstreams with no ESE framing.
29
+
30
+ | ntdll ID | Name | Decompress | Compress | Byte-Identical to ntdll | Builds |
31
+ |----------|------|-----------|----------|------------------------|--------|
32
+ | `0x0002` | LZNT1 | yes | yes | yes (ENGINE_MAX) | XP SP3 – Server 2025 |
33
+ | `0x0003` | XPRESS (Plain LZ77) | yes | yes | yes | Win8.1 – Server 2025 |
34
+ | `0x0004` | XPRESS_HUFF (LZ77+Huffman) | yes | yes | yes (default engine) | Win8.1 – Server 2025 |
35
+ | `0x0005` | undocumented | — | — | — | Server 2022+ |
36
+ | `0x0006` | XP10 (LZ4 block) | yes | yes | yes | Win11 / Server 2025 |
37
+ | `0x0007` | raw DEFLATE | yes | yes | yes (both levels) | Win11 / Server 2025 |
38
+ | `0x0008` | ZLIB | yes | yes | yes (both levels) | Win11 / Server 2025 |
39
+
40
+ ntdll format 0x0005 is an undocumented format (block magic `0xC039E510`) unrelated to XPRESS9 despite sharing the slot number. No public specification or source code exists. Format 0x0006 (XP10) is the same LZ4 block codec used by ESE scheme 0x6 and 0x7, without the ESE header.
41
+
42
+ ## Design principles
43
+
44
+ - **Standard library only at runtime.** No third-party dependencies. `zlib`/`lz4` are deliberately not used; the CRCs and the LZ4 block codec are implemented directly.
45
+ - **Two subpackages, one interface pattern.** `ntcompress.ese` for ESE record-compression, `ntcompress.ntdll` for ntdll standalone codecs. Both offer Shape A (enum dispatch) and Shape B (direct module import) APIs.
46
+ - **Traceable to a spec or a source line.** Every wire constant cites `[MS-XCA] §x.y` or an ESE `file:line`. Where the shipped C diverges from the spec text, both are documented.
47
+ - **Byte-identical verification.** Compress output is verified against gold vectors captured from `esent.dll` and `ntdll.dll` on 16 Windows builds (XP SP3 through Server 2025).
48
+ - **Typed and documented.** Python 3.11+, full type hints, Google-style docstrings, `ruff`-clean under `select = ["ALL"]`, `ty`-clean.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ uv add ntcompress # once published
54
+ ```
55
+
56
+ Requires Python >= 3.11.
57
+
58
+ ## Usage
59
+
60
+ ### ESE record compression
61
+
62
+ ```python
63
+ import ntcompress.ese as ese
64
+
65
+ # Decompress a cell (format is in byte 0)
66
+ plaintext = ese.decompress(cell)
67
+ size = ese.decompressed_size(cell)
68
+
69
+ # Compress with a specific format
70
+ cell = ese.compress(plaintext, ese.Format.XPRESS)
71
+ cell = ese.compress(plaintext, ese.Format.LZ4)
72
+ cell = ese.compress(plaintext, ese.Format.XPRESS9)
73
+
74
+ # Or use Shape B (direct module access)
75
+ from ntcompress.ese import xpress
76
+ cell = xpress.compress(plaintext)
77
+ plaintext = xpress.decompress(cell)
78
+ ```
79
+
80
+ ### ntdll standalone codecs
81
+
82
+ ```python
83
+ import ntcompress.ntdll as ntdll
84
+
85
+ # Shape A (enum dispatch)
86
+ compressed = ntdll.compress(data, ntdll.Format.LZNT1)
87
+ plaintext = ntdll.decompress(compressed, ntdll.Format.LZNT1)
88
+
89
+ # Windows constant aliases
90
+ compressed = ntdll.compress(data, ntdll.COMPRESSION_FORMAT_XPRESS_HUFF)
91
+
92
+ # Shape B (direct module access)
93
+ from ntcompress.ntdll import lznt1, xpress_huff, deflate
94
+ from ntcompress.ntdll import zlib as ntdll_zlib
95
+
96
+ plaintext = lznt1.decompress(compressed_stream)
97
+ compressed = xpress_huff.compress(data)
98
+ compressed = deflate.compress(data) # matches ntdll 0x0007
99
+ compressed = ntdll_zlib.compress(data) # matches ntdll 0x0008
100
+ ```
101
+
102
+ ## License and attribution
103
+
104
+ Apache-2.0 (`LICENSE`). The XPRESS9 codec is an attributed port of Microsoft's MIT-licensed ESE source; the Plain LZ77, Xpress Huffman, and LZNT1 codecs are derived from the published `[MS-XCA]` specification; the LZ4 block codec follows the public LZ4 format. Full notices are in `THIRD-PARTY-NOTICES.md`.
@@ -0,0 +1,85 @@
1
+ [project]
2
+ name = "ntcompress"
3
+ version = "0.1.0"
4
+ description = "Pure-Python implementations of every Microsoft ESE record-compression scheme and Windows ntdll RtlCompressBuffer/RtlDecompressBuffer format."
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE", "NOTICE"]
9
+ authors = [{ name = "ntcompress contributors" }]
10
+ keywords = ["ese", "esent", "jet", "ntdll", "xpress", "xpress9", "xpress10", "lznt1", "lz4", "ms-xca", "compression", "forensics"]
11
+ classifiers = [
12
+ "Development Status :: 2 - Pre-Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Programming Language :: Python :: 3.11",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Topic :: Security",
20
+ "Topic :: System :: Archiving :: Compression",
21
+ "Typing :: Typed",
22
+ ]
23
+ dependencies = []
24
+
25
+ [project.urls]
26
+ Repository = "https://github.com/StrongWind1/ntcompress"
27
+ Documentation = "https://strongwind1.github.io/ntcompress/"
28
+ Changelog = "https://github.com/StrongWind1/ntcompress/blob/main/CHANGELOG.md"
29
+ Issues = "https://github.com/StrongWind1/ntcompress/issues"
30
+
31
+ [dependency-groups]
32
+ dev = [
33
+ "pytest",
34
+ "hypothesis",
35
+ "ruff",
36
+ "ty",
37
+ ]
38
+ docs = ["mkdocs", "mkdocs-material", "mkdocstrings[python]"]
39
+
40
+ [build-system]
41
+ requires = ["uv_build>=0.11.12,<0.12.0"]
42
+ build-backend = "uv_build"
43
+
44
+ [tool.ruff]
45
+ target-version = "py311"
46
+ line-length = 320
47
+ src = ["src"]
48
+
49
+ [tool.ruff.lint]
50
+ select = ["ALL"]
51
+ ignore = [
52
+ "COM812", # Trailing comma - conflicts with the ruff formatter
53
+ "ISC001", # Implicit string concat - conflicts with the ruff formatter
54
+ "D203", # No blank line before class docstring - conflicts with D211
55
+ "D213", # Multi-line docstring summary on second line - conflicts with D212
56
+ "PLR0913", # Too many arguments - wire-format and decoder functions legitimately need many params
57
+ "PLC0415", # Import not at top level - deferred imports used pervasively for circular-import avoidance between ese/__init__.py and format modules
58
+ ]
59
+
60
+ [tool.ruff.lint.per-file-ignores]
61
+ "tests/**" = ["ALL"]
62
+ "src/**/xpress9.py" = ["C901", "PLR0912", "PLR0915", "PLR2004"]
63
+
64
+ [tool.ruff.lint.pydocstyle]
65
+ convention = "google"
66
+
67
+ [tool.ty.environment]
68
+ python-version = "3.11"
69
+ root = ["src"]
70
+
71
+ [tool.ty.rules]
72
+ all = "error"
73
+
74
+ [tool.ty.terminal]
75
+ error-on-warning = true
76
+
77
+ [[tool.ty.overrides]]
78
+ include = ["tests/**"]
79
+
80
+ [tool.ty.overrides.rules]
81
+ all = "ignore"
82
+
83
+ [tool.pytest.ini_options]
84
+ testpaths = ["tests"]
85
+ addopts = "-ra"
@@ -0,0 +1,20 @@
1
+ """Pure-Python codecs for Microsoft ESE record-compression and Windows ntdll compression formats.
2
+
3
+ ``ntcompress`` compresses and decompresses all ESE record schemes (7-bit ASCII/Unicode,
4
+ XPRESS, SCRUB, XPRESS9, XPRESS10, LZ4) and all supported ntdll ``RtlCompressBuffer``
5
+ formats (LZNT1, XPRESS, XPRESS_HUFF, XP10, DEFLATE, ZLIB). Compress output is verified
6
+ byte-identical to ``esent.dll`` and ``ntdll.dll`` across 16 Windows builds. No runtime
7
+ dependencies beyond the standard library.
8
+
9
+ ESE codecs live under :mod:`ntcompress.ese`; ntdll standalone codecs under
10
+ :mod:`ntcompress.ntdll`.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from importlib.metadata import PackageNotFoundError, version
16
+
17
+ try:
18
+ __version__ = version("ntcompress")
19
+ except PackageNotFoundError: # pragma: no cover - source checkout without install metadata
20
+ __version__ = "0.0.0"
@@ -0,0 +1,8 @@
1
+ """Shared type aliases used across both the ESE and ntdll subpackages."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TypeAlias
6
+
7
+ Buffer: TypeAlias = bytes | bytearray | memoryview
8
+ """Any read-only bytes-like input accepted by the codecs."""