bitrock-unpacker 0.1.1__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.
@@ -0,0 +1,4 @@
1
+ # Python
2
+ **/.ruff_cache
3
+ **/__pycache__
4
+ /dist/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Vladimir Petrigo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,117 @@
1
+ Metadata-Version: 2.4
2
+ Name: bitrock-unpacker
3
+ Version: 0.1.1
4
+ Summary: Pure-Python BitRock/InstallBuilder installer unpacker
5
+ Author-email: Vladimir Petrigo <vladimir.petrigo@gmail.com>
6
+ License-Expression: MIT
7
+ License-File: LICENSE.md
8
+ Keywords: bitrock,installbuilder,unpacker
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Classifier: Topic :: System :: Archiving
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+
24
+ [![CI](https://github.com/vpetrigo/bitrock-unpacker/actions/workflows/ci.yml/badge.svg)](https://github.com/vpetrigo/bitrock-unpacker/actions/workflows/ci.yml)
25
+ [![PyPI - Version](https://img.shields.io/pypi/v/bitrock-unpacker)](https://pypi.org/project/bitrock-unpacker)
26
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/bitrock-unpacker)
27
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/bitrock-unpacker?period=monthly&units=INTERNATIONAL_SYSTEM&left_color=GREY&right_color=GREEN&left_text=downloads%2Fmonth)](https://pepy.tech/projects/bitrock-unpacker)
28
+
29
+ # BitRock unpacker prototype
30
+
31
+ `bitrock_unpacker` is a module for extracting content of BitRock/InstallBuilder installers
32
+ without Tcl/TclKit.
33
+
34
+ I created that repo since I was not able to run original Tcl unpacker
35
+ from [here](https://gist.github.com/mickael9/0b902da7c13207d1b86e) on Windows.
36
+
37
+ Run without installing:
38
+
39
+ ```powershell
40
+ uvx bitrock-unpacker --help
41
+ ```
42
+
43
+ Run as a module:
44
+
45
+ ```powershell
46
+ python -m bitrock_unpacker --help
47
+ ```
48
+
49
+ If installed, it also exposes:
50
+
51
+ ```powershell
52
+ bitrock-unpacker --help
53
+ ```
54
+
55
+ ## Current capabilities
56
+
57
+ - Parses PE overlay boundaries.
58
+ - Locates BitRock/CookFS markers.
59
+ - Recovers `manifest.txt` from the embedded zlib stream.
60
+ - Parses old CookFS `CFS0002` suffix/page tables.
61
+ - Decompresses CookFS pages: raw, raw deflate, bzip2, and LZMA-Alone.
62
+ - Decodes the CookFS `CFS2.200` fsindex.
63
+ - Lists and extracts files by fsindex path.
64
+ - Stitches BitRock big-file chunks named `___bitrockBigFileN` into their base file by default.
65
+
66
+ ## Limitations
67
+
68
+ - Encrypted/proprietary `maui::util` payloads are not supported.
69
+ - Full installer post-processing is out of scope; extraction writes archive contents.
70
+ - Full extraction requires `--yes-all` when no `--limit` is supplied.
71
+
72
+ Use `--raw-chunks` to show or extract hidden `___bitrockBigFileN` chunk files instead of stitching them.
73
+
74
+ ## Quick checks
75
+
76
+ The `pyproject.toml` metadata exposes the `bitrock-unpacker` console script, so
77
+ the same CLI can be checked through `uv run` without installing it globally:
78
+
79
+ ```powershell
80
+ python -m bitrock_unpacker <installer.exe> --manifest-only --debug
81
+ python -m bitrock_unpacker <installer.exe> --list-pages --limit 5
82
+ python -m bitrock_unpacker <installer.exe> --list-files --limit 10
83
+ ```
84
+
85
+ Extract one file:
86
+
87
+ ```powershell
88
+ python -m bitrock_unpacker <installer.exe> `
89
+ --path path/inside/archive.txt `
90
+ --extract $env:TEMP\files `
91
+ --limit 1
92
+ ```
93
+
94
+ Inspect raw hidden chunks:
95
+
96
+ ```powershell
97
+ python -m bitrock_unpacker <installer.exe> `
98
+ --raw-chunks `
99
+ --list-files `
100
+ --path path/inside/archive.bin___bitrockBigFile1 `
101
+ --limit 5
102
+ ```
103
+
104
+ Full stitched extraction can be large:
105
+
106
+ ```powershell
107
+ python -m bitrock_unpacker <installer.exe> --extract out --yes-all
108
+ ```
109
+
110
+ ## Development
111
+
112
+ Validate the project metadata and run the self-test:
113
+
114
+ ```powershell
115
+ python -c "import tomllib; tomllib.load(open('pyproject.toml','rb')); print('pyproject: ok')"
116
+ python -m py_compile bitrock_unpacker\*.py
117
+ ```
@@ -0,0 +1,94 @@
1
+ [![CI](https://github.com/vpetrigo/bitrock-unpacker/actions/workflows/ci.yml/badge.svg)](https://github.com/vpetrigo/bitrock-unpacker/actions/workflows/ci.yml)
2
+ [![PyPI - Version](https://img.shields.io/pypi/v/bitrock-unpacker)](https://pypi.org/project/bitrock-unpacker)
3
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/bitrock-unpacker)
4
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/bitrock-unpacker?period=monthly&units=INTERNATIONAL_SYSTEM&left_color=GREY&right_color=GREEN&left_text=downloads%2Fmonth)](https://pepy.tech/projects/bitrock-unpacker)
5
+
6
+ # BitRock unpacker prototype
7
+
8
+ `bitrock_unpacker` is a module for extracting content of BitRock/InstallBuilder installers
9
+ without Tcl/TclKit.
10
+
11
+ I created that repo since I was not able to run original Tcl unpacker
12
+ from [here](https://gist.github.com/mickael9/0b902da7c13207d1b86e) on Windows.
13
+
14
+ Run without installing:
15
+
16
+ ```powershell
17
+ uvx bitrock-unpacker --help
18
+ ```
19
+
20
+ Run as a module:
21
+
22
+ ```powershell
23
+ python -m bitrock_unpacker --help
24
+ ```
25
+
26
+ If installed, it also exposes:
27
+
28
+ ```powershell
29
+ bitrock-unpacker --help
30
+ ```
31
+
32
+ ## Current capabilities
33
+
34
+ - Parses PE overlay boundaries.
35
+ - Locates BitRock/CookFS markers.
36
+ - Recovers `manifest.txt` from the embedded zlib stream.
37
+ - Parses old CookFS `CFS0002` suffix/page tables.
38
+ - Decompresses CookFS pages: raw, raw deflate, bzip2, and LZMA-Alone.
39
+ - Decodes the CookFS `CFS2.200` fsindex.
40
+ - Lists and extracts files by fsindex path.
41
+ - Stitches BitRock big-file chunks named `___bitrockBigFileN` into their base file by default.
42
+
43
+ ## Limitations
44
+
45
+ - Encrypted/proprietary `maui::util` payloads are not supported.
46
+ - Full installer post-processing is out of scope; extraction writes archive contents.
47
+ - Full extraction requires `--yes-all` when no `--limit` is supplied.
48
+
49
+ Use `--raw-chunks` to show or extract hidden `___bitrockBigFileN` chunk files instead of stitching them.
50
+
51
+ ## Quick checks
52
+
53
+ The `pyproject.toml` metadata exposes the `bitrock-unpacker` console script, so
54
+ the same CLI can be checked through `uv run` without installing it globally:
55
+
56
+ ```powershell
57
+ python -m bitrock_unpacker <installer.exe> --manifest-only --debug
58
+ python -m bitrock_unpacker <installer.exe> --list-pages --limit 5
59
+ python -m bitrock_unpacker <installer.exe> --list-files --limit 10
60
+ ```
61
+
62
+ Extract one file:
63
+
64
+ ```powershell
65
+ python -m bitrock_unpacker <installer.exe> `
66
+ --path path/inside/archive.txt `
67
+ --extract $env:TEMP\files `
68
+ --limit 1
69
+ ```
70
+
71
+ Inspect raw hidden chunks:
72
+
73
+ ```powershell
74
+ python -m bitrock_unpacker <installer.exe> `
75
+ --raw-chunks `
76
+ --list-files `
77
+ --path path/inside/archive.bin___bitrockBigFile1 `
78
+ --limit 5
79
+ ```
80
+
81
+ Full stitched extraction can be large:
82
+
83
+ ```powershell
84
+ python -m bitrock_unpacker <installer.exe> --extract out --yes-all
85
+ ```
86
+
87
+ ## Development
88
+
89
+ Validate the project metadata and run the self-test:
90
+
91
+ ```powershell
92
+ python -c "import tomllib; tomllib.load(open('pyproject.toml','rb')); print('pyproject: ok')"
93
+ python -m py_compile bitrock_unpacker\*.py
94
+ ```
@@ -0,0 +1,3 @@
1
+ from bitrock_unpacker.cli import main
2
+
3
+ __all__ = ["main"]
@@ -0,0 +1,6 @@
1
+ from __future__ import annotations
2
+
3
+ from bitrock_unpacker.cli import main
4
+
5
+ if __name__ == "__main__":
6
+ raise SystemExit(main())
@@ -0,0 +1,186 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import logging
5
+ import os
6
+ from typing import TYPE_CHECKING
7
+
8
+ from bitrock_unpacker.cookfs import (
9
+ CookFSInfo,
10
+ FsEntry,
11
+ PageReader,
12
+ build_cookfs_layout,
13
+ decompress_index_blob,
14
+ find_cookfsinfo,
15
+ find_zlib_stream,
16
+ parse_fsindex,
17
+ )
18
+ from bitrock_unpacker.extract import (
19
+ build_chunk_maps,
20
+ resolve_stitch_entries,
21
+ select_entries,
22
+ write_stitched_file,
23
+ )
24
+ from bitrock_unpacker.pe import parse_pe_overlay
25
+ from bitrock_unpacker.tcllist import parse_manifest
26
+
27
+ if TYPE_CHECKING:
28
+ from collections.abc import Iterator
29
+
30
+ logger = logging.getLogger(__name__)
31
+ MARKERS = [
32
+ b"bitrock-lzma-4.0",
33
+ b"Jbitrock-lzma-4.0",
34
+ b"manifest.txt",
35
+ b"cookfsinfo.txt",
36
+ ]
37
+
38
+
39
+ def find_all(data: bytes, needle: bytes) -> Iterator[int]:
40
+ start = 0
41
+ while True:
42
+ idx = data.find(needle, start)
43
+ if idx < 0:
44
+ return
45
+ yield idx
46
+ start = idx + 1
47
+
48
+
49
+ def recover_manifest(data: bytes, overlay_start: int) -> str | None:
50
+ hay = data[overlay_start:]
51
+ hits = []
52
+ for marker in (b"manifest.txt", b"cookfsinfo.txt"):
53
+ hits.extend(overlay_start + i for i in find_all(hay, marker))
54
+ for pos in sorted(set(hits)):
55
+ dec = find_zlib_stream(data, pos)
56
+ if dec:
57
+ return dec.decode("utf-8", "replace")
58
+ return None
59
+
60
+
61
+ def build_parser() -> argparse.ArgumentParser:
62
+ ap = argparse.ArgumentParser()
63
+ ap.add_argument("installer", nargs="?")
64
+ ap.add_argument("--out")
65
+ ap.add_argument("--manifest-only", action="store_true")
66
+ ap.add_argument("--list-pages", action="store_true")
67
+ ap.add_argument("--extract-pages")
68
+ ap.add_argument("--list-files", action="store_true")
69
+ ap.add_argument("--extract")
70
+ ap.add_argument("--path")
71
+ ap.add_argument("--yes-all", action="store_true")
72
+ ap.add_argument("--raw-chunks", action="store_true")
73
+ ap.add_argument("--limit", type=int)
74
+ ap.add_argument("--debug", action="store_true")
75
+ return ap
76
+
77
+
78
+ def main(argv: list[str] | None = None) -> int:
79
+ ap = build_parser()
80
+ ns = ap.parse_args(argv)
81
+ logging.basicConfig(
82
+ format="%(message)s", level=logging.DEBUG if ns.debug else logging.INFO
83
+ )
84
+ if not ns.installer:
85
+ ap.error("installer.exe is required")
86
+ with open(ns.installer, "rb") as f:
87
+ data = f.read()
88
+ pe = parse_pe_overlay(data)
89
+ if ns.debug:
90
+ logger.debug("overlay start=%s length=%s", pe.overlay_start, pe.overlay_length)
91
+ for m in MARKERS:
92
+ logger.debug("%s: %s", m.decode(), len(list(find_all(data, m))))
93
+ info: CookFSInfo = build_cookfs_layout(
94
+ data, pe.overlay_start, find_cookfsinfo(data, pe.overlay_start)
95
+ )
96
+ fs_entries: list[FsEntry] = []
97
+ if info.index_blob_offset is not None:
98
+ idx = decompress_index_blob(data, info)
99
+ if idx:
100
+ fs_entries = parse_fsindex(idx)
101
+ manifest_text = recover_manifest(data, pe.overlay_start)
102
+ if manifest_text is None:
103
+ logger.error("manifest recovery failed")
104
+ return 2
105
+ _, counts, total = parse_manifest(manifest_text)
106
+ logger.info(
107
+ "manifest entries: file=%s directory=%s link=%s declared_file_bytes=%s",
108
+ counts["file"],
109
+ counts["directory"],
110
+ counts["link"],
111
+ total,
112
+ )
113
+ if ns.out:
114
+ os.makedirs(ns.out, exist_ok=True)
115
+ with open(
116
+ os.path.join(ns.out, "manifest.txt"), "w", encoding="utf-8", newline="\n"
117
+ ) as f:
118
+ f.write(manifest_text)
119
+ logger.info("wrote %s", os.path.join(ns.out, "manifest.txt"))
120
+ if not ns.manifest_only:
121
+ logger.info("CookFS fsindex entries: %s", len(fs_entries))
122
+ if ns.list_pages or ns.extract_pages:
123
+ if info.num_pages is None:
124
+ logger.error("cookfs layout unavailable")
125
+ return 2
126
+ limit = ns.limit if ns.limit is not None else 20
127
+ page_reader = PageReader(data, info)
128
+ for count, idx in enumerate(range(info.num_pages), start=1):
129
+ page = page_reader.get(idx)
130
+ off = page_reader.offsets[idx]
131
+ sz = page_reader.sizes[idx]
132
+ logger.info(
133
+ "page %06d off=0x%x size=%s tag=%s dec=%s",
134
+ idx,
135
+ off,
136
+ sz,
137
+ page_reader.tag(idx),
138
+ len(page),
139
+ )
140
+ if ns.extract_pages:
141
+ os.makedirs(ns.extract_pages, exist_ok=True)
142
+ with open(
143
+ os.path.join(ns.extract_pages, f"page_{idx:06d}.bin"), "wb"
144
+ ) as f:
145
+ f.write(page)
146
+ if count >= limit:
147
+ break
148
+ if ns.list_files or ns.extract:
149
+ filtered = select_entries(fs_entries, ns.path, raw_chunks=ns.raw_chunks)
150
+ limit = ns.limit if ns.limit is not None else 20
151
+ for e in filtered[:limit]:
152
+ if (
153
+ e.kind == "file"
154
+ and not ns.raw_chunks
155
+ and not e.path.endswith("___bitrockBigFile1")
156
+ ):
157
+ _, chunk_groups = build_chunk_maps(fs_entries)
158
+ chunks = len(chunk_groups.get(e.path, []))
159
+ if chunks:
160
+ logger.info(
161
+ "%s %s blocks=%s chunks=%s",
162
+ e.kind,
163
+ e.path,
164
+ len(e.blocks),
165
+ chunks + 1,
166
+ )
167
+ else:
168
+ logger.info("%s %s blocks=%s", e.kind, e.path, len(e.blocks))
169
+ else:
170
+ logger.info("%s %s blocks=%s", e.kind, e.path, len(e.blocks))
171
+ if ns.extract:
172
+ if ns.limit is None and not ns.yes_all:
173
+ logger.error("refusing full extraction without --yes-all")
174
+ return 2
175
+ page_reader = PageReader(data, info)
176
+ _, chunk_groups = build_chunk_maps(fs_entries)
177
+ os.makedirs(ns.extract, exist_ok=True)
178
+ for e in resolve_stitch_entries(fs_entries, ns.path, raw_chunks=ns.raw_chunks)[
179
+ : (ns.limit if ns.limit is not None else 10**9)
180
+ ]:
181
+ out_path = os.path.join(ns.extract, e.path.replace("/", os.sep))
182
+ os.makedirs(os.path.dirname(out_path), exist_ok=True)
183
+ chunks = [] if ns.raw_chunks else chunk_groups.get(e.path, [])
184
+ write_stitched_file(page_reader, e, chunks, out_path)
185
+ logger.info("wrote %s", out_path)
186
+ return 0