dsh-modpack-kit 0.0.0-stage → 0.1.1
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.
- package/LICENSE +75 -0
- package/README.md +191 -2
- package/client.js +840 -0
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +82 -0
- package/icon.svg +14 -0
- package/index.js +566 -0
- package/lib/classify.mjs +105 -0
- package/lib/compat.mjs +112 -0
- package/lib/install.mjs +344 -0
- package/lib/manifest.mjs +189 -0
- package/lib/market-catalog.mjs +419 -0
- package/lib/pack.mjs +382 -0
- package/lib/profile.mjs +274 -0
- package/lib/registry.mjs +223 -0
- package/lib/scan.mjs +278 -0
- package/lib/semver.mjs +143 -0
- package/lib/store.mjs +182 -0
- package/lib/tar.mjs +107 -0
- package/lib/yamlish.mjs +385 -0
- package/lib/zip.mjs +232 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +53 -3
package/lib/zip.mjs
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-modpack —— 最小 ZIP 读写(只用 node:zlib,不引入依赖)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么自己写:整合包要能在「没装本插件」的 DSH 上也读得懂,格式必须是
|
|
5
|
+
* 通用的(zip),但宿主没给我们打包库,多引一个依赖就多一份跑不起来的风险。
|
|
6
|
+
* 这里只实现 store / deflate 两种方法,够用且可审计。
|
|
7
|
+
*
|
|
8
|
+
* 安全约束(解包端):
|
|
9
|
+
* - 拒绝绝对路径、盘符、`..` 段、反斜杠路径;
|
|
10
|
+
* - 拒绝符号链接(外部属性 S_IFLNK);
|
|
11
|
+
* - 单文件 / 总解压体积 / 压缩比三重上限,挡 zip bomb;
|
|
12
|
+
* - 不支持 ZIP64 与加密,遇到就明确报错,不猜。
|
|
13
|
+
*/
|
|
14
|
+
import { crc32, deflateRawSync, inflateRawSync } from 'node:zlib'
|
|
15
|
+
|
|
16
|
+
const SIG_LOCAL = 0x04034b50
|
|
17
|
+
const SIG_CENTRAL = 0x02014b50
|
|
18
|
+
const SIG_EOCD = 0x06054b50
|
|
19
|
+
const SIG_EOCD64 = 0x06064b50
|
|
20
|
+
|
|
21
|
+
const LIMITS = {
|
|
22
|
+
entries: 20000,
|
|
23
|
+
entryBytes: 256 * 1024 * 1024,
|
|
24
|
+
totalBytes: 1024 * 1024 * 1024,
|
|
25
|
+
ratio: 200,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function dosTime(date) {
|
|
29
|
+
const d = date instanceof Date && !Number.isNaN(date.getTime()) ? date : new Date()
|
|
30
|
+
const year = Math.max(1980, d.getFullYear())
|
|
31
|
+
return {
|
|
32
|
+
time: (d.getHours() << 11) | (d.getMinutes() << 5) | Math.floor(d.getSeconds() / 2),
|
|
33
|
+
date: ((year - 1980) << 9) | ((d.getMonth() + 1) << 5) | d.getDate(),
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function dosToDate(time, date) {
|
|
38
|
+
const year = ((date >> 9) & 0x7f) + 1980
|
|
39
|
+
const month = ((date >> 5) & 0x0f) - 1
|
|
40
|
+
const day = date & 0x1f
|
|
41
|
+
const hours = (time >> 11) & 0x1f
|
|
42
|
+
const minutes = (time >> 5) & 0x3f
|
|
43
|
+
const seconds = (time & 0x1f) * 2
|
|
44
|
+
return new Date(year, Math.max(0, month), Math.max(1, day), hours, minutes, seconds)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 规范化条目名:统一正斜杠、去掉前导 ./,并拒绝逃逸。 */
|
|
48
|
+
export function safeEntryName(raw) {
|
|
49
|
+
if (typeof raw !== 'string' || raw === '') throw new Error('zip: 空条目名')
|
|
50
|
+
if (raw.includes('\u0000')) throw new Error('zip: 条目名含 NUL')
|
|
51
|
+
const name = raw.replace(/\\/gu, '/')
|
|
52
|
+
if (name.startsWith('/') || /^[A-Za-z]:/u.test(name)) throw new Error('zip: 绝对路径条目 ' + raw)
|
|
53
|
+
const parts = []
|
|
54
|
+
for (const part of name.split('/')) {
|
|
55
|
+
if (part === '' || part === '.') continue
|
|
56
|
+
if (part === '..') throw new Error('zip: 路径逃逸条目 ' + raw)
|
|
57
|
+
parts.push(part)
|
|
58
|
+
}
|
|
59
|
+
if (parts.length === 0) throw new Error('zip: 空路径条目 ' + raw)
|
|
60
|
+
return parts.join('/')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 写 zip。
|
|
65
|
+
* @param {{name: string, data: Buffer|string, compress?: boolean}[]} entries
|
|
66
|
+
* @param {{mtime?: Date}} [options]
|
|
67
|
+
* @returns {Buffer}
|
|
68
|
+
*/
|
|
69
|
+
export function writeZip(entries, options = {}) {
|
|
70
|
+
const { time, date } = dosTime(options.mtime)
|
|
71
|
+
const chunks = []
|
|
72
|
+
const central = []
|
|
73
|
+
let offset = 0
|
|
74
|
+
const seen = new Set()
|
|
75
|
+
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
const name = safeEntryName(entry.name)
|
|
78
|
+
if (seen.has(name)) throw new Error('zip: 重复条目 ' + name)
|
|
79
|
+
seen.add(name)
|
|
80
|
+
const data = Buffer.isBuffer(entry.data) ? entry.data : Buffer.from(String(entry.data), 'utf8')
|
|
81
|
+
const crc = crc32(data) >>> 0
|
|
82
|
+
let method = 0
|
|
83
|
+
let body = data
|
|
84
|
+
if (entry.compress !== false && data.length > 128) {
|
|
85
|
+
const deflated = deflateRawSync(data, { level: 9 })
|
|
86
|
+
if (deflated.length < data.length) {
|
|
87
|
+
method = 8
|
|
88
|
+
body = deflated
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const nameBuf = Buffer.from(name, 'utf8')
|
|
92
|
+
const local = Buffer.alloc(30)
|
|
93
|
+
local.writeUInt32LE(SIG_LOCAL, 0)
|
|
94
|
+
local.writeUInt16LE(20, 4)
|
|
95
|
+
local.writeUInt16LE(0x0800, 6) // UTF-8 名字
|
|
96
|
+
local.writeUInt16LE(method, 8)
|
|
97
|
+
local.writeUInt16LE(time, 10)
|
|
98
|
+
local.writeUInt16LE(date, 12)
|
|
99
|
+
local.writeUInt32LE(crc, 14)
|
|
100
|
+
local.writeUInt32LE(body.length, 18)
|
|
101
|
+
local.writeUInt32LE(data.length, 22)
|
|
102
|
+
local.writeUInt16LE(nameBuf.length, 26)
|
|
103
|
+
local.writeUInt16LE(0, 28)
|
|
104
|
+
chunks.push(local, nameBuf, body)
|
|
105
|
+
|
|
106
|
+
const cd = Buffer.alloc(46)
|
|
107
|
+
cd.writeUInt32LE(SIG_CENTRAL, 0)
|
|
108
|
+
cd.writeUInt16LE(20, 4)
|
|
109
|
+
cd.writeUInt16LE(20, 6)
|
|
110
|
+
cd.writeUInt16LE(0x0800, 8)
|
|
111
|
+
cd.writeUInt16LE(method, 10)
|
|
112
|
+
cd.writeUInt16LE(time, 12)
|
|
113
|
+
cd.writeUInt16LE(date, 14)
|
|
114
|
+
cd.writeUInt32LE(crc, 16)
|
|
115
|
+
cd.writeUInt32LE(body.length, 20)
|
|
116
|
+
cd.writeUInt32LE(data.length, 24)
|
|
117
|
+
cd.writeUInt16LE(nameBuf.length, 28)
|
|
118
|
+
cd.writeUInt16LE(0, 30)
|
|
119
|
+
cd.writeUInt16LE(0, 32)
|
|
120
|
+
cd.writeUInt16LE(0, 34)
|
|
121
|
+
cd.writeUInt16LE(0, 36)
|
|
122
|
+
cd.writeUInt32LE(0, 38)
|
|
123
|
+
cd.writeUInt32LE(offset, 42)
|
|
124
|
+
central.push(cd, nameBuf)
|
|
125
|
+
offset += local.length + nameBuf.length + body.length
|
|
126
|
+
if (offset > LIMITS.totalBytes) throw new Error('zip: 打包体积超过上限')
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const centralBuf = Buffer.concat(central)
|
|
130
|
+
const eocd = Buffer.alloc(22)
|
|
131
|
+
eocd.writeUInt32LE(SIG_EOCD, 0)
|
|
132
|
+
eocd.writeUInt16LE(0, 4)
|
|
133
|
+
eocd.writeUInt16LE(0, 6)
|
|
134
|
+
eocd.writeUInt16LE(entries.length, 8)
|
|
135
|
+
eocd.writeUInt16LE(entries.length, 10)
|
|
136
|
+
eocd.writeUInt32LE(centralBuf.length, 12)
|
|
137
|
+
eocd.writeUInt32LE(offset, 16)
|
|
138
|
+
eocd.writeUInt16LE(0, 20)
|
|
139
|
+
return Buffer.concat([...chunks, centralBuf, eocd])
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function findEocd(buf) {
|
|
143
|
+
const start = Math.max(0, buf.length - 0x10000 - 22)
|
|
144
|
+
for (let i = buf.length - 22; i >= start; i -= 1) {
|
|
145
|
+
if (buf.readUInt32LE(i) !== SIG_EOCD) continue
|
|
146
|
+
const commentLen = buf.readUInt16LE(i + 20)
|
|
147
|
+
if (i + 22 + commentLen === buf.length) return i
|
|
148
|
+
}
|
|
149
|
+
for (let i = buf.length - 22; i >= start; i -= 1) {
|
|
150
|
+
if (buf.readUInt32LE(i) === SIG_EOCD) return i
|
|
151
|
+
}
|
|
152
|
+
return -1
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 读 zip,返回条目数组(含 data Buffer)。
|
|
157
|
+
* 目录条目会被跳过;任何可疑输入直接抛错,不做“尽量解析”。
|
|
158
|
+
* @param {Buffer} buf
|
|
159
|
+
*/
|
|
160
|
+
export function readZip(buf, options = {}) {
|
|
161
|
+
if (!Buffer.isBuffer(buf) || buf.length < 22) throw new Error('zip: 内容太短,不是 zip')
|
|
162
|
+
const eocd = findEocd(buf)
|
|
163
|
+
if (eocd < 0) throw new Error('zip: 找不到中央目录结尾(文件损坏或不是 zip)')
|
|
164
|
+
const count = buf.readUInt16LE(eocd + 10)
|
|
165
|
+
const cdSize = buf.readUInt32LE(eocd + 12)
|
|
166
|
+
const cdOffset = buf.readUInt32LE(eocd + 16)
|
|
167
|
+
if (count === 0xffff || cdOffset === 0xffffffff) throw new Error('zip: 暂不支持 ZIP64')
|
|
168
|
+
if (cdOffset + cdSize > buf.length) throw new Error('zip: 中央目录越界')
|
|
169
|
+
if (count > LIMITS.entries) throw new Error('zip: 条目过多')
|
|
170
|
+
|
|
171
|
+
const entries = []
|
|
172
|
+
let p = cdOffset
|
|
173
|
+
let total = 0
|
|
174
|
+
for (let i = 0; i < count; i += 1) {
|
|
175
|
+
if (buf.readUInt32LE(p) !== SIG_CENTRAL) throw new Error('zip: 中央目录条目损坏')
|
|
176
|
+
const flags = buf.readUInt16LE(p + 8)
|
|
177
|
+
const method = buf.readUInt16LE(p + 10)
|
|
178
|
+
const crc = buf.readUInt32LE(p + 16)
|
|
179
|
+
const compSize = buf.readUInt32LE(p + 20)
|
|
180
|
+
const size = buf.readUInt32LE(p + 24)
|
|
181
|
+
const nameLen = buf.readUInt16LE(p + 28)
|
|
182
|
+
const extraLen = buf.readUInt16LE(p + 30)
|
|
183
|
+
const commentLen = buf.readUInt16LE(p + 32)
|
|
184
|
+
const external = buf.readUInt32LE(p + 38)
|
|
185
|
+
const localOffset = buf.readUInt32LE(p + 42)
|
|
186
|
+
const timeField = buf.readUInt16LE(p + 12)
|
|
187
|
+
const dateField = buf.readUInt16LE(p + 14)
|
|
188
|
+
const rawName = buf.toString('utf8', p + 46, p + 46 + nameLen)
|
|
189
|
+
p += 46 + nameLen + extraLen + commentLen
|
|
190
|
+
if (flags & 0x0001) throw new Error('zip: 不支持加密条目 ' + rawName)
|
|
191
|
+
if (((external >>> 16) & 0o170000) === 0o120000) throw new Error('zip: 拒绝符号链接 ' + rawName)
|
|
192
|
+
const name = safeEntryName(rawName)
|
|
193
|
+
if (name.endsWith('/')) continue
|
|
194
|
+
const entryLimit = options.maxEntryBytes ?? LIMITS.entryBytes
|
|
195
|
+
if (size > entryLimit) throw new Error('zip: 条目过大 ' + name)
|
|
196
|
+
total += size
|
|
197
|
+
if (total > (options.maxTotalBytes ?? LIMITS.totalBytes)) throw new Error('zip: 解压总量超过上限')
|
|
198
|
+
if (size > 1024 * 1024 && size / Math.max(1, compSize) > LIMITS.ratio) {
|
|
199
|
+
throw new Error('zip: 压缩比异常(疑似 zip bomb)' + name)
|
|
200
|
+
}
|
|
201
|
+
if (buf.readUInt32LE(localOffset) !== SIG_LOCAL) throw new Error('zip: 本地头损坏 ' + name)
|
|
202
|
+
const lNameLen = buf.readUInt16LE(localOffset + 26)
|
|
203
|
+
const lExtraLen = buf.readUInt16LE(localOffset + 28)
|
|
204
|
+
const dataStart = localOffset + 30 + lNameLen + lExtraLen
|
|
205
|
+
if (dataStart + compSize > buf.length) throw new Error('zip: 条目数据越界 ' + name)
|
|
206
|
+
const raw = buf.subarray(dataStart, dataStart + compSize)
|
|
207
|
+
let data
|
|
208
|
+
if (method === 0) data = Buffer.from(raw)
|
|
209
|
+
else if (method === 8) {
|
|
210
|
+
// 声明长度只是「声称」:真的解压时也卡死上限,避免声明 0 字节的炸弹先膨胀到 GB 再报错
|
|
211
|
+
const cap = Math.max(size, Math.min(entryLimit, 4096))
|
|
212
|
+
try {
|
|
213
|
+
data = inflateRawSync(raw, { maxOutputLength: cap })
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (/maxOutputLength|buffer/i.test(String(error?.message || error))) throw new Error('zip: 解压后超过声明长度(疑似 zip bomb)' + name)
|
|
216
|
+
throw error
|
|
217
|
+
}
|
|
218
|
+
} else throw new Error('zip: 不支持的压缩方法 ' + method + ' ' + name)
|
|
219
|
+
if (typeof crc === 'number' && (crc32(data) >>> 0) !== crc) throw new Error('zip: CRC 校验失败 ' + name)
|
|
220
|
+
if (data.length !== size) throw new Error('zip: 解压长度不符 ' + name)
|
|
221
|
+
entries.push({ name, data, mtime: dosToDate(timeField, dateField) })
|
|
222
|
+
}
|
|
223
|
+
return entries
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** 从条目数组里读一个文本文件;没有就返回 null。 */
|
|
227
|
+
export function readZipText(entries, name) {
|
|
228
|
+
const hit = entries.find((e) => e.name === name)
|
|
229
|
+
return hit ? hit.data.toString('utf8') : null
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export const zipLimits = LIMITS
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Modpack",
|
|
4
|
+
"description": "Bundle several plugins into one .dshpack and install them in a single pass: full packs carry the payloads, lite packs record names and versions and fetch them from the registry. Each plugin can be packed as upstream-basic or as your local copy. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); installing re-checks integrity, compatibility and licences, then re-applies the packed config, with an option to install without enabling. Categories, search, sorting and entries come from the same plugin-market catalog (first screen lists only what you have), and the UI can be shown in settings, the sidebar or the plugins tab, each switchable. Installing the plugin market (dshmarket) first is recommended but not required: packing, installing and scanning all work without it, you just lose its UI and the market-version comparison.",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "整合包",
|
|
4
|
+
"description": "把多个插件打成一个 .dshpack,一次装好:完整版自带插件本体,轻量版只记名字与版本、安装时按记录取包。每个插件可单独选「基础配置」或「本地改动」。打包前强制做敏感信息与风险代码检测(命中只留掩码、原文不落盘),安装前再查完整性、兼容性与许可证;装完按条目回填配置,也可选先不启用。分类、搜索、排序与条目都跟插件市场同源(首屏只列已装),三处入口(设置 / 侧边栏 / 插件页)可各自开关。建议先装插件市场(dshmarket)再一起用——不装也能打包、装包与检测,只是少了它的界面与市场版对照。",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-modpack-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Bundle several plugins into one .dshpack and install them in a single pass: full packs carry the payloads, lite packs record names and versions and fetch them from the registry. Each plugin can be packed as upstream-basic or as your local copy. Packing always runs an in-memory scan for secrets and risky code (masked, never written to disk); installing re-checks integrity, compatibility and licences, then re-applies the packed config, with an option to install without enabling. Categories, search, sorting and entries come from the same plugin-market catalog (first screen lists only what you have), and the UI can be shown in settings, the sidebar or the plugins tab, each switchable.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./index.js": "./index.js",
|
|
10
|
+
"./client": "./client.js",
|
|
11
|
+
"./locale/*.json": "./locale/*.json",
|
|
12
|
+
"./icon": "./icon.svg"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"client.js",
|
|
17
|
+
"lib",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"locale/*.json",
|
|
20
|
+
"docs",
|
|
21
|
+
"icon.svg",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"dsh-plugin",
|
|
27
|
+
"modpack",
|
|
28
|
+
"bundle",
|
|
29
|
+
"pack",
|
|
30
|
+
"installer",
|
|
31
|
+
"plugin-manager",
|
|
32
|
+
"security-scan"
|
|
33
|
+
],
|
|
34
|
+
"license": "PolyForm-Noncommercial-1.0.0",
|
|
35
|
+
"author": "Vesna-Strivozha-cn",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/Vesna-Strivozha-cn/dsh-modpack-kit.git"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/Vesna-Strivozha-cn/dsh-modpack-kit#readme",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"dsh": {
|
|
45
|
+
"bundle": {
|
|
46
|
+
"patch": "./cordis.patch.yml"
|
|
47
|
+
},
|
|
48
|
+
"client": {
|
|
49
|
+
"platform": "web",
|
|
50
|
+
"inject": []
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/Vesna-Strivozha-cn/dsh-modpack-kit/issues"
|
|
55
|
+
}
|
|
6
56
|
}
|