dsh-snowbreak-heimdall 3.0.0

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.
Files changed (68) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +175 -0
  3. package/SHA256SUMS.txt +61 -0
  4. package/TEST-REPORT.md +96 -0
  5. package/assets/icons/app-512.png +0 -0
  6. package/assets/icons/app-light-512.png +0 -0
  7. package/assets/icons/app.ico +0 -0
  8. package/assets/icons/apple-touch-icon.png +0 -0
  9. package/assets/icons/favicon-dark.svg +5 -0
  10. package/assets/icons/favicon.svg +5 -0
  11. package/assets/icons/icon-192.png +0 -0
  12. package/assets/icons/icon-512.png +0 -0
  13. package/assets/icons/icon-maskable-512.png +0 -0
  14. package/assets/icons/icon.svg +5 -0
  15. package/assets/icons/res-icon.png +0 -0
  16. package/assets/icons/tray.ico +0 -0
  17. package/assets/previews/assets/hm-mark-blue.png +0 -0
  18. package/assets/previews/brand-fix.png +0 -0
  19. package/assets/previews/exe-icon-test.png +0 -0
  20. package/assets/previews/loading-dark.html +443 -0
  21. package/assets/previews/loading-dark.png +0 -0
  22. package/assets/previews/loading-fallback.html +443 -0
  23. package/assets/previews/loading-fallback.png +0 -0
  24. package/assets/previews/loading-handoff.html +457 -0
  25. package/assets/previews/loading-light.html +443 -0
  26. package/assets/previews/loading-light.png +0 -0
  27. package/assets/previews/mask-test.png +0 -0
  28. package/assets/previews/progress-winforms-complete.png +0 -0
  29. package/assets/previews/progress-winforms.png +0 -0
  30. package/assets/previews/ui-chrome.html +24 -0
  31. package/assets/previews/ui-chrome.png +0 -0
  32. package/assets/source/brand-client.js +95 -0
  33. package/assets/source/client-template.js +217 -0
  34. package/assets/source/hm-mark-blue.png +0 -0
  35. package/assets/source/hm-mark-ink.png +0 -0
  36. package/assets/source/hm-mark-light.png +0 -0
  37. package/assets/source/loading.css +373 -0
  38. package/assets/source/loading.html +58 -0
  39. package/assets/source/logo.webp +0 -0
  40. package/assets/source/mark-alpha.png +0 -0
  41. package/assets/source/mark-color.png +0 -0
  42. package/assets/source/progress.ps1 +312 -0
  43. package/assets/source/shell.css +475 -0
  44. package/assets/source/shell.js +293 -0
  45. package/assets/source/update.css +47 -0
  46. package/assets/source/watermark-soft.png +0 -0
  47. package/assets/source/welcome-brand.svg +18 -0
  48. package/assets/source/welcome-mark-ink.png +0 -0
  49. package/assets/source/welcome-mark-light.png +0 -0
  50. package/assets/source/welcome.css +121 -0
  51. package/cordis.patch.yml +4 -0
  52. package/icon.svg +5 -0
  53. package/lib/client.js +217 -0
  54. package/lib/index.js +239 -0
  55. package/locale/en.json +6 -0
  56. package/locale/zh.json +6 -0
  57. package/package.json +47 -0
  58. package/patch/asar.py +237 -0
  59. package/patch/patcher.py +1307 -0
  60. package/tools/build_assets.py +206 -0
  61. package/tools/build_client.py +21 -0
  62. package/tools/test_lock.py +28 -0
  63. package/tools/test_progress_launch.py +44 -0
  64. package/tools/test_progress_ps1.py +38 -0
  65. package/tools/test_progress_ps1_complete.py +38 -0
  66. package/vendor/rcedit/LICENSE +20 -0
  67. package/vendor/rcedit/README.md +51 -0
  68. package/vendor/rcedit/rcedit-x64.exe +0 -0
package/patch/asar.py ADDED
@@ -0,0 +1,237 @@
1
+ #!/usr/bin/env python3
2
+ """Dependency-free Electron ASAR reader/rewriter for the Heimdall skin.
3
+
4
+ Only the operations needed by the skin are implemented: read the entry tree,
5
+ replace/add normal files, keep ``unpacked``/``link`` entries intact, and write a
6
+ new archive with recalculated offsets and per-entry integrity blocks.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import json
12
+ import os
13
+ import struct
14
+
15
+ MAGIC = 4
16
+ HEADER_OFFSET = 8
17
+ BLOCK = 4 * 1024 * 1024
18
+
19
+
20
+ class AsarError(RuntimeError):
21
+ pass
22
+
23
+
24
+ def read_header(handle):
25
+ handle.seek(0)
26
+ first = handle.read(16)
27
+ if len(first) < 16:
28
+ raise AsarError("not an asar archive: file too short")
29
+ magic, header_size, json_size, json_length = struct.unpack("<IIII", first)
30
+ if magic != MAGIC:
31
+ raise AsarError("not an asar archive: bad magic %d" % magic)
32
+ if header_size < 8 or json_length <= 0 or json_length > 64 * 1024 * 1024:
33
+ raise AsarError("not an asar archive: implausible header")
34
+ handle.seek(HEADER_OFFSET)
35
+ blob = handle.read(header_size)
36
+ if len(blob) != header_size:
37
+ raise AsarError("truncated asar header")
38
+ try:
39
+ tree = json.loads(blob[8:8 + json_length].decode("utf-8"))
40
+ except (UnicodeDecodeError, ValueError) as exc:
41
+ raise AsarError("invalid asar header JSON: %s" % exc) from exc
42
+ if not isinstance(tree, dict) or not isinstance(tree.get("files"), dict):
43
+ raise AsarError("invalid asar header: missing files")
44
+ return tree, header_size
45
+
46
+
47
+ def walk(tree, prefix=""):
48
+ for name, entry in (tree.get("files") or {}).items():
49
+ path = prefix + "/" + name if prefix else name
50
+ if "files" in entry:
51
+ yield from walk(entry, path)
52
+ else:
53
+ yield path, entry
54
+
55
+
56
+ def find(tree, path):
57
+ node = tree
58
+ parts = [part for part in path.strip("/").split("/") if part]
59
+ if not parts:
60
+ raise AsarError("empty archive path")
61
+ for part in parts:
62
+ files = node.get("files")
63
+ if not isinstance(files, dict) or part not in files:
64
+ raise AsarError("archive entry not found: %s" % path)
65
+ node = files[part]
66
+ if "files" in node:
67
+ raise AsarError("archive path is a directory: %s" % path)
68
+ return node
69
+
70
+
71
+ def data_start(header_size):
72
+ return HEADER_OFFSET + header_size
73
+
74
+
75
+ def read_entry(handle, header_size, entry):
76
+ if entry.get("unpacked"):
77
+ raise AsarError("entry is unpacked")
78
+ if entry.get("link"):
79
+ raise AsarError("entry is a symlink")
80
+ start = data_start(header_size) + int(entry["offset"])
81
+ handle.seek(start)
82
+ data = handle.read(int(entry["size"]))
83
+ if len(data) != int(entry["size"]):
84
+ raise AsarError("truncated archive entry")
85
+ return data
86
+
87
+
88
+ def _integrity(data):
89
+ digest = hashlib.sha256(data).hexdigest()
90
+ blocks = [hashlib.sha256(data[i:i + BLOCK]).hexdigest()
91
+ for i in range(0, len(data), BLOCK)] or [hashlib.sha256(b"").hexdigest()]
92
+ return {"algorithm": "SHA256", "hash": digest, "blockSize": BLOCK, "blocks": blocks}
93
+
94
+
95
+ def _ensure_dir(root, parts):
96
+ node = root
97
+ for part in parts:
98
+ files = node.setdefault("files", {})
99
+ if part in files and "files" not in files[part]:
100
+ raise AsarError("file/directory conflict at %s" % part)
101
+ node = files.setdefault(part, {"files": {}})
102
+ return node
103
+
104
+
105
+ def _add(root, path, data):
106
+ parts = [part for part in path.strip("/").split("/") if part]
107
+ if not parts:
108
+ raise AsarError("empty add path")
109
+ parent = _ensure_dir(root, parts[:-1])
110
+ name = parts[-1]
111
+ existing = parent["files"].get(name)
112
+ if existing is not None:
113
+ if "files" in existing:
114
+ raise AsarError("directory/file conflict at %s" % path)
115
+ raise AsarError("entry already exists: %s" % path)
116
+ parent["files"][name] = {"size": len(data), "integrity": _integrity(data)}
117
+
118
+
119
+ def rewrite(source_path, output_path, replacements, additions):
120
+ """Write a patched copy of source_path.
121
+
122
+ ``replacements`` maps archive paths to bytes. ``additions`` maps new archive
123
+ paths to bytes. Original data is streamed; no full-archive copy is held in
124
+ memory.
125
+ """
126
+ with open(source_path, "rb") as src:
127
+ tree, header_size = read_header(src)
128
+ data_base = data_start(header_size)
129
+
130
+ # Deep-copy only the header; file payloads are streamed from source.
131
+ tree = json.loads(json.dumps(tree))
132
+ for path, data in replacements.items():
133
+ entry = find(tree, path)
134
+ if entry.get("unpacked") or entry.get("link"):
135
+ raise AsarError("cannot replace unpacked/link entry: %s" % path)
136
+ entry["size"] = len(data)
137
+ entry["integrity"] = _integrity(data)
138
+ for path, data in additions.items():
139
+ _add(tree, path, data)
140
+
141
+ # Collect data sources in traversal order and assign new offsets.
142
+ queue = []
143
+ offset = 0
144
+
145
+ def assign(node, prefix):
146
+ nonlocal offset
147
+ for name, entry in (node.get("files") or {}).items():
148
+ path = prefix + "/" + name if prefix else name
149
+ if "files" in entry:
150
+ assign(entry, path)
151
+ elif entry.get("unpacked") or entry.get("link"):
152
+ continue
153
+ else:
154
+ if path in replacements:
155
+ payload = replacements[path]
156
+ elif path in additions:
157
+ payload = additions[path]
158
+ else:
159
+ payload = None
160
+ size = len(payload) if payload is not None else int(entry["size"])
161
+ entry["offset"] = str(offset)
162
+ entry["size"] = size
163
+ queue.append((path, payload, int(entry.get("offset", 0))))
164
+ offset += size
165
+
166
+ # Keep original offsets before overwriting them for unchanged files.
167
+ original_offsets = {}
168
+ for path, entry in walk(tree):
169
+ if not entry.get("unpacked") and not entry.get("link"):
170
+ original_offsets[path] = int(entry.get("offset", 0))
171
+ assign(tree, "")
172
+
173
+ # Reassemble queue with original source offsets.
174
+ final_queue = []
175
+ for path, payload, _new_offset in queue:
176
+ final_queue.append((path, payload, original_offsets.get(path, 0)))
177
+
178
+ raw = json.dumps(tree, ensure_ascii=False, separators=(",", ":")).encode("utf-8")
179
+ pad = (-len(raw)) % 4
180
+ json_size = 4 + len(raw) + pad
181
+ new_header_size = 4 + json_size
182
+ new_data_start = HEADER_OFFSET + new_header_size
183
+
184
+ tmp = output_path + ".part"
185
+ try:
186
+ with open(tmp, "wb") as dst:
187
+ dst.write(struct.pack("<IIII", MAGIC, new_header_size, json_size, len(raw)))
188
+ dst.write(raw)
189
+ dst.write(b"\x00" * pad)
190
+ if dst.tell() != new_data_start:
191
+ raise AsarError("header sizing mismatch")
192
+ for path, payload, original_offset in final_queue:
193
+ if payload is not None:
194
+ dst.write(payload)
195
+ continue
196
+ src.seek(data_base + original_offset)
197
+ remaining = int(find(tree, path)["size"])
198
+ while remaining > 0:
199
+ chunk = src.read(min(1024 * 1024, remaining))
200
+ if not chunk:
201
+ raise AsarError("unexpected EOF while copying %s" % path)
202
+ dst.write(chunk)
203
+ remaining -= len(chunk)
204
+ os.replace(tmp, output_path)
205
+ finally:
206
+ if os.path.exists(tmp):
207
+ try:
208
+ os.remove(tmp)
209
+ except OSError:
210
+ pass
211
+ return tree
212
+
213
+
214
+ def verify(output_path, replacements, additions):
215
+ with open(output_path, "rb") as handle:
216
+ tree, header_size = read_header(handle)
217
+ for path, expected in list(replacements.items()) + list(additions.items()):
218
+ entry = find(tree, path)
219
+ actual = read_entry(handle, header_size, entry)
220
+ if actual != expected:
221
+ raise AsarError("entry verification failed: %s" % path)
222
+ digest = _integrity(actual)
223
+ if entry.get("integrity") != digest:
224
+ raise AsarError("entry integrity mismatch: %s" % path)
225
+ return tree
226
+
227
+
228
+ def sha256_file(path):
229
+ digest = hashlib.sha256()
230
+ with open(path, "rb") as handle:
231
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
232
+ digest.update(chunk)
233
+ return digest.hexdigest()
234
+
235
+
236
+ def count_entries(tree):
237
+ return sum(1 for _ in walk(tree))