mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 15:30:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
769515e1f1 | ||
|
|
b74c7f9bea | ||
|
|
7ec51691f7 |
No files matched your search
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.32</strong></p>
|
||||
<p align="center"><strong>Version 1.1.34</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>Local official DeepSeek Harness cybersecurity red-team plugin. Clean host policy, and ship a built-in drill console. Swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐</em>
|
||||
@@ -677,7 +677,7 @@ dsh-purge --edit
|
||||
purge_status purge_apply purge_revert
|
||||
```
|
||||
|
||||
Patched packages load only after a restart. Apply does not restart by itself. Under the patch title, **Stable** and **Beta** are separate: each has its own version list and switch action. A rollback is pinned; click **Update** to return to that channel's tip.
|
||||
Patched packages load only after a restart. Apply does not restart by itself. Under the patch title is the stable release: you can see versions and switch. A rollback is pinned; click **Update** to return to the latest. The beta channel is gone.
|
||||
|
||||
The composer **Undo** button drops the last turn and puts the last user sentence back in the input. On the main agent you can rewind once or the whole last round (including subagents). After rewind, send only what is in the box now. `/rewind` does the same. The host cannot truncate a session in place, so rewind opens another session for the shortened transcript and removes the old one from the sidebar. Repeating undo does not leave a stack of branches in the list.
|
||||
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.32</strong></p>
|
||||
<p align="center"><strong>Version 1.1.34</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||
@@ -680,7 +680,7 @@ dsh-purge --edit
|
||||
purge_status purge_apply purge_revert
|
||||
```
|
||||
|
||||
设置页「应用」完成后需要重启才会加载已改的包文件。点「重启」才会重启,不会自动重启。补丁标题下正式版和测试版分开两栏:各自看版本、各自切换;回退后会固定在该版本,要回到该通道最新再点「更新」。
|
||||
设置页「应用」完成后需要重启才会加载已改的包文件。点「重启」才会重启,不会自动重启。补丁标题下是正式版:可以看版本和切换。回退后会固定在该版本,要回到最新再点「更新」。测试版通道已去掉。
|
||||
|
||||
输入框旁的「回退」会丢掉最近一轮对话,并把上一句填回输入框;聊天里 `/rewind` 同样可用。宿主不能在原会话里截断,所以回退会另开一条承载截断后的内容,并把原来那条从侧边栏移出。多退几次不会在列表里堆出一串分支。
|
||||
|
||||
|
||||
@@ -1522,7 +1522,6 @@ body[data-ds-dark-theme] .dshp-dock-body .dshp-switch button.is-on{background:#3
|
||||
),
|
||||
h("div", { className: "dshp-editions" },
|
||||
renderEdition("stable"),
|
||||
renderEdition("beta"),
|
||||
),
|
||||
noticeNode(updateNotice),
|
||||
),
|
||||
@@ -1886,14 +1885,12 @@ body[data-ds-dark-theme] .dshp-dock-body .dshp-switch button.is-on{background:#3
|
||||
return best;
|
||||
}
|
||||
|
||||
function keepListedVersion(item, ceiling) {
|
||||
const ver = String((item && (item.version || item.ref)) || "").replace(/^v/i, "");
|
||||
if (/^1\.1\.11-beta/i.test(ver)) return false;
|
||||
if (!item || item.channel !== "beta") return true;
|
||||
// 与 lib/update.hideListedVersion 一致:测试 tip / beta 分支始终可见(并行通道)。
|
||||
if (item.ref === "beta" || item.kind === "head" || item.latest) return true;
|
||||
if (!ceiling) return true;
|
||||
return listedVersionNewer(ver, ceiling);
|
||||
function keepListedVersion(item, _ceiling) {
|
||||
const ver = String((item && (item.version || item.ref || item.id)) || "");
|
||||
if (!item) return false;
|
||||
if (item.channel === "beta" || item.ref === "beta") return false;
|
||||
if (/(?:^|[-._])(beta|rc|pre|preview|test)(?:\d|$|[-._])/i.test(ver)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function preferListed(list, localVer, pin) {
|
||||
@@ -5167,8 +5164,13 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
const [openId, setOpenId] = React.useState(null)
|
||||
const [detail, setDetail] = React.useState(null)
|
||||
const [detailBusy, setDetailBusy] = React.useState(false)
|
||||
const [tplOffset, setTplOffset] = React.useState(0)
|
||||
const tplPageSize = 40
|
||||
|
||||
const query = (over) => {
|
||||
const extra = over || {}
|
||||
const offset = Object.prototype.hasOwnProperty.call(extra, 'templateOffset') ? extra.templateOffset : 0
|
||||
setTplOffset(offset)
|
||||
const params = Object.assign({
|
||||
q: q.trim() || undefined,
|
||||
kind: kind || undefined,
|
||||
@@ -5176,7 +5178,9 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
engagement: engagement || undefined,
|
||||
asset_target: assetTarget.trim() || undefined,
|
||||
verified: verifiedOnly || undefined,
|
||||
}, over || {})
|
||||
templateOffset: offset || 0,
|
||||
templateLimit: tplPageSize,
|
||||
}, extra)
|
||||
setBusy(true); setMsg(null)
|
||||
api(Object.assign({ op: 'pocSearch' }, params)).then((r) => {
|
||||
setBusy(false)
|
||||
@@ -5210,8 +5214,15 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
|
||||
const stats = (data && data.stats) || { total: 0, verified: 0, reused: 0, byKind: [], bySource: [] }
|
||||
const items = (data && data.items) || []
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, items: [] }
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, matched: 0, offset: 0, items: [] }
|
||||
const tplItems = tpl.items || []
|
||||
const tplMatched = tpl.matched != null ? tpl.matched : tpl.total
|
||||
const tplStart = Number(tpl.offset) || 0
|
||||
const turnTpl = (next) => {
|
||||
const offset = Math.max(0, next)
|
||||
setTplOffset(offset)
|
||||
query({ templateOffset: offset })
|
||||
}
|
||||
|
||||
const card = (x) => {
|
||||
const isOpen = openId === x.id
|
||||
@@ -5351,8 +5362,9 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
tplItems.length
|
||||
? h('div', { className: 'rt-kb-tpl' },
|
||||
h('div', { className: 'rt-ap-sub' },
|
||||
'本机 nuclei 模板命中 · ' + tplItems.length + ' 条(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + i, className: 'rt-kb-tpl-row' },
|
||||
'本机 nuclei 模板 · ' + (tplStart + 1) + '–' + (tplStart + tplItems.length) + ' / ' + tplMatched
|
||||
+ '(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + tplStart + '-' + i, className: 'rt-kb-tpl-row' },
|
||||
h('span', { className: 'rt-tag' }, t.severity || '—'),
|
||||
h('span', { className: 'rt-mono rt-kb-tpl-path', title: t.path }, t.path),
|
||||
h('span', { className: 'rt-kb-tpl-name', title: t.name }, t.name || ''),
|
||||
@@ -5360,6 +5372,15 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
className: 'rt-btn', style: { padding: '0 6px', fontSize: 10.5 },
|
||||
onClick: () => copy('nuclei -t ' + t.path + ' -u <目标>', '模板命令'),
|
||||
}, '复制命令'))),
|
||||
h('div', { className: 'rt-kb-actions' },
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart <= 0,
|
||||
onClick: () => turnTpl(tplStart - tplPageSize),
|
||||
}, '上一页'),
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart + tplItems.length >= tplMatched,
|
||||
onClick: () => turnTpl(tplStart + tplPageSize),
|
||||
}, '下一页')),
|
||||
tpl.dir ? h('div', { className: 'rt-foot' }, h('span', null, '模板目录:' + tpl.dir)) : null)
|
||||
: null,
|
||||
data === null ? h('div', { className: 'rt-empty' }, '加载中…') : null,
|
||||
@@ -5369,7 +5390,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
q || kind || verifiedOnly
|
||||
? '没有命中:换个关键字再试,或去互联网找 / 自己手搓后回填。'
|
||||
: (tpl.total
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板 —— 在上方搜 CVE / 组件即可命中。')
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板,但这一页没有列出来。请完全退出后重新打开客户端。')
|
||||
: (tpl.dir
|
||||
? '知识库还是空的(本机模板目录存在但没有 yaml,请跑 nuclei -update-templates)。'
|
||||
: '知识库还是空的。本机也还没有 nuclei 模板库 —— 在演练机上跑 setup.sh 或 `nuclei -update-templates`,装好后这里会出现「本机模板 N」。'))),
|
||||
|
||||
+4
-1
@@ -109,6 +109,9 @@ export async function reapplyInstalled(options = {}) {
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
writeAppliedStamp(installedRev());
|
||||
const pending = Boolean(handoff?.asar && !renamed && options.scheduleSwap !== false);
|
||||
// 只有真的挪开了 app.asar,当前进程才还在旧包上,需要再开一次。
|
||||
// 官方端已经在 resources/app 里跑时,不能仅因 ELECTRON_RUN_AS_NODE 再弹「需要重启」,
|
||||
// 否则每次打开面板都会再要一次重启。
|
||||
return {
|
||||
ok: true,
|
||||
version: pluginVersion(),
|
||||
@@ -116,7 +119,7 @@ export async function reapplyInstalled(options = {}) {
|
||||
applied: summary.applied || 0,
|
||||
failed: summary.failed.length,
|
||||
renamed,
|
||||
needsFullQuit: renamed || pending || core.officialHostMustStayUp(),
|
||||
needsFullQuit: renamed || pending,
|
||||
cmdFlashOk: flash.ok === true,
|
||||
};
|
||||
}
|
||||
+29
-5
@@ -2243,8 +2243,13 @@ window.__ModuleLoader__.load({
|
||||
const [openId, setOpenId] = React.useState(null)
|
||||
const [detail, setDetail] = React.useState(null)
|
||||
const [detailBusy, setDetailBusy] = React.useState(false)
|
||||
const [tplOffset, setTplOffset] = React.useState(0)
|
||||
const tplPageSize = 40
|
||||
|
||||
const query = (over) => {
|
||||
const extra = over || {}
|
||||
const offset = Object.prototype.hasOwnProperty.call(extra, 'templateOffset') ? extra.templateOffset : 0
|
||||
setTplOffset(offset)
|
||||
const params = Object.assign({
|
||||
q: q.trim() || undefined,
|
||||
kind: kind || undefined,
|
||||
@@ -2252,7 +2257,9 @@ window.__ModuleLoader__.load({
|
||||
engagement: engagement || undefined,
|
||||
asset_target: assetTarget.trim() || undefined,
|
||||
verified: verifiedOnly || undefined,
|
||||
}, over || {})
|
||||
templateOffset: offset || 0,
|
||||
templateLimit: tplPageSize,
|
||||
}, extra)
|
||||
setBusy(true); setMsg(null)
|
||||
api(Object.assign({ op: 'pocSearch' }, params)).then((r) => {
|
||||
setBusy(false)
|
||||
@@ -2286,8 +2293,15 @@ window.__ModuleLoader__.load({
|
||||
|
||||
const stats = (data && data.stats) || { total: 0, verified: 0, reused: 0, byKind: [], bySource: [] }
|
||||
const items = (data && data.items) || []
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, items: [] }
|
||||
const tpl = (data && data.templates) || { dir: null, total: 0, matched: 0, offset: 0, items: [] }
|
||||
const tplItems = tpl.items || []
|
||||
const tplMatched = tpl.matched != null ? tpl.matched : tpl.total
|
||||
const tplStart = Number(tpl.offset) || 0
|
||||
const turnTpl = (next) => {
|
||||
const offset = Math.max(0, next)
|
||||
setTplOffset(offset)
|
||||
query({ templateOffset: offset })
|
||||
}
|
||||
|
||||
const card = (x) => {
|
||||
const isOpen = openId === x.id
|
||||
@@ -2427,8 +2441,9 @@ window.__ModuleLoader__.load({
|
||||
tplItems.length
|
||||
? h('div', { className: 'rt-kb-tpl' },
|
||||
h('div', { className: 'rt-ap-sub' },
|
||||
'本机 nuclei 模板命中 · ' + tplItems.length + ' 条(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + i, className: 'rt-kb-tpl-row' },
|
||||
'本机 nuclei 模板 · ' + (tplStart + 1) + '–' + (tplStart + tplItems.length) + ' / ' + tplMatched
|
||||
+ '(直接 `nuclei -t <模板路径>`)'),
|
||||
tplItems.map((t, i) => h('div', { key: 't' + tplStart + '-' + i, className: 'rt-kb-tpl-row' },
|
||||
h('span', { className: 'rt-tag' }, t.severity || '—'),
|
||||
h('span', { className: 'rt-mono rt-kb-tpl-path', title: t.path }, t.path),
|
||||
h('span', { className: 'rt-kb-tpl-name', title: t.name }, t.name || ''),
|
||||
@@ -2436,6 +2451,15 @@ window.__ModuleLoader__.load({
|
||||
className: 'rt-btn', style: { padding: '0 6px', fontSize: 10.5 },
|
||||
onClick: () => copy('nuclei -t ' + t.path + ' -u <目标>', '模板命令'),
|
||||
}, '复制命令'))),
|
||||
h('div', { className: 'rt-kb-actions' },
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart <= 0,
|
||||
onClick: () => turnTpl(tplStart - tplPageSize),
|
||||
}, '上一页'),
|
||||
h('button', {
|
||||
className: 'rt-btn', disabled: busy || tplStart + tplItems.length >= tplMatched,
|
||||
onClick: () => turnTpl(tplStart + tplPageSize),
|
||||
}, '下一页')),
|
||||
tpl.dir ? h('div', { className: 'rt-foot' }, h('span', null, '模板目录:' + tpl.dir)) : null)
|
||||
: null,
|
||||
data === null ? h('div', { className: 'rt-empty' }, '加载中…') : null,
|
||||
@@ -2445,7 +2469,7 @@ window.__ModuleLoader__.load({
|
||||
q || kind || verifiedOnly
|
||||
? '没有命中:换个关键字再试,或去互联网找 / 自己手搓后回填。'
|
||||
: (tpl.total
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板 —— 在上方搜 CVE / 组件即可命中。')
|
||||
? ('POC/EXP 库还是空的;本机已有 ' + tpl.total + ' 个 nuclei 模板,但这一页没有列出来。请完全退出后重新打开客户端。')
|
||||
: (tpl.dir
|
||||
? '知识库还是空的(本机模板目录存在但没有 yaml,请跑 nuclei -update-templates)。'
|
||||
: '知识库还是空的。本机也还没有 nuclei 模板库 —— 在演练机上跑 setup.sh 或 `nuclei -update-templates`,装好后这里会出现「本机模板 N」。'))),
|
||||
|
||||
+27
-14
@@ -739,11 +739,14 @@ export function dispatch(store, req = {}) {
|
||||
/* 知识库是全局的(跨靶标共享),所以这几个 op 不需要 engagement */
|
||||
if (op === 'pocSearch') {
|
||||
const items = store.searchPocs(req)
|
||||
/* "现成的"有两层:本机沉淀的 POC/EXP + 本机 nuclei 模板库。一次返回,省一轮往返。 */
|
||||
/* "现成的"有两层:本机沉淀的 POC/EXP + 本机 nuclei 模板库。一次返回,省一轮往返。
|
||||
没关键字时也返回一页模板,面板才能看见本机模板,而不是只显示总数。 */
|
||||
const q = req.q || req.query || req.cve || req.component || ''
|
||||
const templates = q
|
||||
? store.searchTemplates(q, Math.min(Number(req.templateLimit) || 20, 100))
|
||||
: { dir: store.nucleiTemplatesDir() || null, total: store.templateStats().total, items: [] }
|
||||
const templates = store.searchTemplates(
|
||||
q,
|
||||
Math.min(Number(req.templateLimit) || 40, 80),
|
||||
Number(req.templateOffset) || 0,
|
||||
)
|
||||
return { ok: true, items, stats: store.pocStats(), templates }
|
||||
}
|
||||
if (op === 'pocList') return { ok: true, items: store.searchPocs(req), stats: store.pocStats() }
|
||||
@@ -3762,19 +3765,29 @@ export class RedteamStore {
|
||||
* 在本机 nuclei 模板库里检索:CVE 编号按文件名就能命中,组件/关键字再匹配 name 与 tags。
|
||||
* 这是"知识库里没有、但本机其实已有现成 POC"的那一层,先查它能省掉一轮互联网检索。
|
||||
*/
|
||||
searchTemplates(q, limit = 40) {
|
||||
searchTemplates(q, limit = 40, offset = 0) {
|
||||
const { dir, items } = this.#nucleiIndex()
|
||||
if (dir === null) return { dir: null, total: 0, items: [] }
|
||||
if (dir === null) return { dir: null, total: 0, matched: 0, offset: 0, items: [] }
|
||||
const cap = Math.min(Math.max(Number(limit) || 40, 1), 80)
|
||||
const start = Math.max(Number(offset) || 0, 0)
|
||||
const raw = String(q || '').trim()
|
||||
if (raw === '') return { dir, total: items.length, items: [] }
|
||||
const needle = raw.toLowerCase()
|
||||
const out = []
|
||||
for (const [path, name, severity, tags] of items) {
|
||||
const hay = (path + ' ' + name + ' ' + tags).toLowerCase()
|
||||
if (hay.includes(needle)) out.push({ path, name, severity, tags })
|
||||
if (out.length >= limit) break
|
||||
/* 没关键字时也要列出一页。跳过 .github 这类没有 name/severity 的 yaml,否则第一页不是模板。 */
|
||||
const listed = (row) => {
|
||||
const file = String(row[0] || '').replace(/\\/g, '/')
|
||||
if (file.startsWith('.') || file.includes('/.')) return false
|
||||
return Boolean(row[1] || row[2])
|
||||
}
|
||||
return { dir, total: items.length, items: out }
|
||||
let matched = items.filter(listed)
|
||||
if (raw !== '') {
|
||||
const needle = raw.toLowerCase()
|
||||
matched = []
|
||||
for (const row of items) {
|
||||
const hay = (row[0] + ' ' + row[1] + ' ' + row[3]).toLowerCase()
|
||||
if (hay.includes(needle)) matched.push(row)
|
||||
}
|
||||
}
|
||||
const page = matched.slice(start, start + cap).map(([path, name, severity, tags]) => ({ path, name, severity, tags }))
|
||||
return { dir, total: items.length, matched: matched.length, offset: start, items: page }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+28
-14
@@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { findDshHome } from "./core.js";
|
||||
import { extractZipArchive, listZipFile } from "./zip-extract.js";
|
||||
|
||||
export { findDshHome };
|
||||
|
||||
@@ -377,14 +378,31 @@ function isUnsafeArchiveEntry(name) {
|
||||
return rel.split("/").some((part) => part === ".." || part === "");
|
||||
}
|
||||
|
||||
function splitLines(text) {
|
||||
return String(text || "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
function listArchiveEntries(archivePath) {
|
||||
const result = spawnSync("tar", ["-tf", archivePath], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 15000,
|
||||
});
|
||||
if (result.status !== 0) return null;
|
||||
return String(result.stdout || "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
||||
if (result.status === 0) return splitLines(result.stdout);
|
||||
if (/\.zip$/i.test(archivePath)) {
|
||||
const unzip = spawnSync("unzip", ["-Z1", archivePath], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 15000,
|
||||
});
|
||||
if (unzip.status === 0) return splitLines(unzip.stdout);
|
||||
try {
|
||||
return listZipFile(archivePath);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractArchive(archivePath, dest) {
|
||||
@@ -395,24 +413,20 @@ function extractArchive(archivePath, dest) {
|
||||
if (entries && entries.length > MAX_IMPORT_FILES) {
|
||||
throw new Error("压缩包里文件太多");
|
||||
}
|
||||
if (/\.zip$/i.test(archivePath)) {
|
||||
try {
|
||||
extractZipArchive(archivePath, dest);
|
||||
return;
|
||||
} catch (error) {
|
||||
throw new Error(String(error && error.message ? error.message : error));
|
||||
}
|
||||
}
|
||||
const result = spawnSync("tar", ["-xf", archivePath, "-C", dest], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 30000,
|
||||
});
|
||||
if (result.status === 0) return;
|
||||
if (/\.zip$/i.test(archivePath) && process.platform === "win32") {
|
||||
const ps = spawnSync("powershell", [
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
`Expand-Archive -LiteralPath '${String(archivePath).replace(/'/g, "''")}' -DestinationPath '${String(dest).replace(/'/g, "''")}' -Force`,
|
||||
], {
|
||||
windowsHide: true,
|
||||
encoding: "utf8",
|
||||
timeout: 30000,
|
||||
});
|
||||
if (ps.status === 0) return;
|
||||
}
|
||||
const detail = String(result.stderr || result.stdout || "").trim();
|
||||
throw new Error(detail || "无法解压,请改用文件夹导入");
|
||||
}
|
||||
|
||||
+25
-94
@@ -9,6 +9,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { findDshHome } from "./core.js";
|
||||
import { adapterFor, detectSurface } from "./surface.js";
|
||||
import { cliInvocation } from "./desktop.js";
|
||||
import { extractZipArchive } from "./zip-extract.js";
|
||||
|
||||
const REPO = "YuJunZhiXue/dsh-purge";
|
||||
const STABLE_REF = "master";
|
||||
@@ -91,8 +92,8 @@ function markAutoUpdateGuard(ref, sha = "") {
|
||||
}, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
export function normalizeChannel(value) {
|
||||
return String(value || "").toLowerCase() === "beta" ? "beta" : "stable";
|
||||
export function normalizeChannel(_value) {
|
||||
return "stable";
|
||||
}
|
||||
|
||||
function isBetaName(name) {
|
||||
@@ -136,27 +137,22 @@ export function latestStableVersion(versions) {
|
||||
return best;
|
||||
}
|
||||
|
||||
/** 正式版已经追上的旧测试版标签不再列出。1.1.11-beta 始终下线。
|
||||
* 正式/测试是并行通道(测试带红队等),beta 分支 tip 始终保留,避免 1.1.25 正式把 1.1.25-beta 整通道藏掉。 */
|
||||
export function hideListedVersion(item, stableVersion = "") {
|
||||
/** 测试通道已下线。beta 分支、测试标签和名称里带 beta/rc/pre 的条目都不再列出。 */
|
||||
export function hideListedVersion(item, _stableVersion = "") {
|
||||
if (!item || withdrawnVersion(item)) return true;
|
||||
const beta = item.channel === "beta" || isBetaName(item.version) || isBetaName(item.ref) || isBetaName(item.id);
|
||||
if (!beta) return false;
|
||||
// 并行测试通道 tip:始终可见。
|
||||
if (item.ref === BETA_REF || item.kind === "head") return false;
|
||||
const ceiling = String(stableVersion || "").replace(/^v/i, "");
|
||||
if (!ceiling || isBetaName(ceiling)) return false;
|
||||
const ver = String(item.version || item.ref || item.id || "").replace(/^v/i, "");
|
||||
if (!/^\d+\.\d+/.test(ver)) return false;
|
||||
return !versionIsNewer(ver, ceiling);
|
||||
return item.channel === "beta" || isBetaName(item.version) || isBetaName(item.ref) || isBetaName(item.id);
|
||||
}
|
||||
|
||||
export function readChannelState() {
|
||||
const raw = readJson(channelStatePath()) || {};
|
||||
return {
|
||||
channel: normalizeChannel(raw.channel),
|
||||
pin: typeof raw.pin === "string" ? raw.pin.trim() : "",
|
||||
const stored = String(raw.channel || "").toLowerCase();
|
||||
const pin = typeof raw.pin === "string" ? raw.pin.trim() : "";
|
||||
const state = {
|
||||
channel: "stable",
|
||||
pin: isBetaName(pin) || pin === BETA_REF ? "" : pin,
|
||||
};
|
||||
if (stored === "beta" || state.pin !== pin) writeChannelState(state);
|
||||
return state;
|
||||
}
|
||||
|
||||
function writeChannelState(next) {
|
||||
@@ -719,9 +715,8 @@ async function listRemoteVersions() {
|
||||
if (next) out.push(next);
|
||||
};
|
||||
|
||||
const [stableSha, betaSha, tags] = await Promise.all([
|
||||
const [stableSha, tags] = await Promise.all([
|
||||
remoteHeadSha(STABLE_REF),
|
||||
remoteHeadSha(BETA_REF),
|
||||
listGithubTags(),
|
||||
]);
|
||||
|
||||
@@ -738,34 +733,6 @@ async function listRemoteVersions() {
|
||||
latest: true,
|
||||
});
|
||||
}
|
||||
if (betaSha) {
|
||||
const version = await remotePackageVersion(betaSha, BETA_REF).catch(() => "");
|
||||
add({
|
||||
id: BETA_REF,
|
||||
ref: BETA_REF,
|
||||
sha: betaSha,
|
||||
version: version || "",
|
||||
channel: "beta",
|
||||
label: `${versionLabel(version, "beta", betaSha)} · 最新`,
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
} else {
|
||||
// API/atom 拿不到 tip 时,仍用 raw/jsDelivr 探一下 beta 分支,避免测试通道整栏空白。
|
||||
const version = await remotePackageVersion("", BETA_REF).catch(() => "");
|
||||
if (version) {
|
||||
add({
|
||||
id: BETA_REF,
|
||||
ref: BETA_REF,
|
||||
sha: "",
|
||||
version,
|
||||
channel: "beta",
|
||||
label: `${versionLabel(version, "beta")} · 最新`,
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const tag of tags) {
|
||||
if (!withdrawnVersion(tag)) add(tag);
|
||||
}
|
||||
@@ -786,26 +753,21 @@ async function listRemoteVersions() {
|
||||
localVer && !isBetaName(localVer) ? { channel: "stable", version: localVer } : null,
|
||||
].filter(Boolean));
|
||||
const visible = withLocal.filter((item) => !hideListedVersion(item, ceiling));
|
||||
const betaOpen = visible.some((item) => item.channel === "beta");
|
||||
return {
|
||||
versions: markCurrent(visible, state, localVer, localSha),
|
||||
hasBeta: betaOpen,
|
||||
hasBeta: false,
|
||||
stableSha,
|
||||
betaSha: betaOpen ? betaSha : "",
|
||||
betaSha: "",
|
||||
};
|
||||
}
|
||||
|
||||
function alignChannelState(state, listed, localRev, localVer) {
|
||||
if (state.pin) return state;
|
||||
if (listed.betaSha && localRev && sameRev(localRev, listed.betaSha) && state.channel !== "beta") {
|
||||
return writeChannelState({ channel: "beta", pin: "" });
|
||||
}
|
||||
if (listed.stableSha && localRev && sameRev(localRev, listed.stableSha) && state.channel !== "stable") {
|
||||
return writeChannelState({ channel: "stable", pin: "" });
|
||||
}
|
||||
if (!localRev && localVer) {
|
||||
const inferred = isBetaName(localVer) ? "beta" : "stable";
|
||||
if (inferred !== state.channel) return writeChannelState({ channel: inferred, pin: "" });
|
||||
if (!localRev && localVer && state.channel !== "stable") {
|
||||
return writeChannelState({ channel: "stable", pin: "" });
|
||||
}
|
||||
return state;
|
||||
}
|
||||
@@ -961,21 +923,9 @@ function gitResetTo(dir, ref, { force = false } = {}) {
|
||||
}
|
||||
|
||||
function extractZip(zip, dest) {
|
||||
try {
|
||||
execFileSync("tar", ["-xf", zip, "-C", dest], { ...HIDDEN, timeout: 60000 });
|
||||
return;
|
||||
} catch {
|
||||
// Windows 10+ 自带 tar;没有或失败时改 PowerShell。
|
||||
}
|
||||
execFileSync(
|
||||
"powershell",
|
||||
["-NoProfile", "-Command", "Expand-Archive -LiteralPath $env:DSH_UPD_ZIP -DestinationPath $env:DSH_UPD_DIR -Force"],
|
||||
{
|
||||
...HIDDEN,
|
||||
timeout: 60000,
|
||||
env: { ...process.env, DSH_UPD_ZIP: zip, DSH_UPD_DIR: dest },
|
||||
},
|
||||
);
|
||||
// win32:tar(bsdtar) → powershell。darwin/linux:tar → unzip → python3 → bsdtar。
|
||||
// 外部工具都不可用时用 Node 解 zip,Linux 不会再去调用 powershell。
|
||||
extractZipArchive(zip, dest);
|
||||
}
|
||||
|
||||
async function overlayFromZip(dests, ref = STABLE_REF) {
|
||||
@@ -1134,28 +1084,8 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) {
|
||||
}
|
||||
|
||||
export async function switchChannel(channel, { apply = true } = {}) {
|
||||
if (String(channel || "").toLowerCase() === "beta") throw new Error("测试版已下线");
|
||||
const next = normalizeChannel(channel);
|
||||
if (next === "beta") {
|
||||
const listed = await listRemoteVersions();
|
||||
if (!listed.hasBeta) {
|
||||
const state = readChannelState();
|
||||
const localVer = localVersion();
|
||||
const localRev = (gitOk() ? gitHead(PLUGIN_ROOT) : "") || readStamp();
|
||||
return rememberUpdate({
|
||||
ok: false,
|
||||
error: "还没有测试版",
|
||||
hasBeta: false,
|
||||
localVersion: localVer,
|
||||
versions: listed.versions,
|
||||
lanes: lanesOf(listed, state, localVer, localRev),
|
||||
...channelPublic(state),
|
||||
});
|
||||
}
|
||||
if (!listed.betaSha && apply) {
|
||||
const tag = listed.versions.find((item) => item.channel === "beta" && item.kind === "tag");
|
||||
if (tag) return applyUpdate(planUpdates(), { ref: tag.ref, channel: "beta", pin: false, force: true });
|
||||
}
|
||||
}
|
||||
if (!apply) {
|
||||
writeChannelState({ channel: next, pin: "" });
|
||||
return checkUpdate();
|
||||
@@ -1199,11 +1129,12 @@ export async function handleUpdateOp(body = {}) {
|
||||
const requested = body.ref || currentChannelRef(state);
|
||||
const ref = safeUpdateRef(requested);
|
||||
if (!ref) throw new Error("未知版本");
|
||||
if (ref !== STABLE_REF && ref !== BETA_REF) {
|
||||
if (ref === BETA_REF || isBetaName(ref)) throw new Error("测试版已下线");
|
||||
if (ref !== STABLE_REF) {
|
||||
const listed = await listRemoteVersions();
|
||||
if (!listedUpdateRef(ref, listed)) throw new Error("未知版本");
|
||||
}
|
||||
const channel = body.channel || (ref === BETA_REF ? "beta" : ref === STABLE_REF ? "stable" : state.channel);
|
||||
const channel = body.channel === "beta" ? "stable" : (body.channel || (ref === STABLE_REF ? "stable" : state.channel));
|
||||
return applyUpdate(planUpdates(), { ref, channel, pin: false, force: true });
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import zlib from "node:zlib";
|
||||
|
||||
const HIDDEN = {
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
windowsHide: true,
|
||||
timeout: 60000,
|
||||
};
|
||||
|
||||
/** 各平台解压顺序。node 不调用外部命令,macOS / Linux / Windows 都能用。 */
|
||||
export function unzipTools(platform = process.platform) {
|
||||
if (platform === "win32") return ["tar", "powershell", "node"];
|
||||
return ["tar", "unzip", "python3", "bsdtar", "node"];
|
||||
}
|
||||
|
||||
function safeZipName(name) {
|
||||
const rel = String(name || "").replace(/\\/g, "/").replace(/^\.?\//, "").replace(/\/+$/, "");
|
||||
if (!rel) return "";
|
||||
if (rel.startsWith("/") || /^[A-Za-z]:/.test(rel)) throw new Error("zip 路径不合法");
|
||||
const parts = rel.split("/");
|
||||
if (parts.some((part) => part === ".." || part === "")) throw new Error("zip 路径不合法");
|
||||
return parts.join("/");
|
||||
}
|
||||
|
||||
function findEocd(buf) {
|
||||
const min = Math.max(0, buf.length - 22 - 65535);
|
||||
for (let i = buf.length - 22; i >= min; i -= 1) {
|
||||
if (buf.readUInt32LE(i) === 0x06054b50) return i;
|
||||
}
|
||||
throw new Error("不是 zip");
|
||||
}
|
||||
|
||||
function readZipEntries(buf) {
|
||||
if (!Buffer.isBuffer(buf) || buf.length < 22) throw new Error("不是 zip");
|
||||
const eocd = findEocd(buf);
|
||||
const total = buf.readUInt16LE(eocd + 10);
|
||||
let cursor = buf.readUInt32LE(eocd + 16);
|
||||
const entries = [];
|
||||
for (let n = 0; n < total; n += 1) {
|
||||
if (cursor + 46 > buf.length || buf.readUInt32LE(cursor) !== 0x02014b50) {
|
||||
throw new Error("zip 目录损坏");
|
||||
}
|
||||
const method = buf.readUInt16LE(cursor + 10);
|
||||
const compSize = buf.readUInt32LE(cursor + 20);
|
||||
const nameLen = buf.readUInt16LE(cursor + 28);
|
||||
const extraLen = buf.readUInt16LE(cursor + 30);
|
||||
const commentLen = buf.readUInt16LE(cursor + 32);
|
||||
const localOffset = buf.readUInt32LE(cursor + 42);
|
||||
const name = buf.toString("utf8", cursor + 46, cursor + 46 + nameLen);
|
||||
entries.push({ name, method, compSize, localOffset });
|
||||
cursor += 46 + nameLen + extraLen + commentLen;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
export function listZipEntries(buf) {
|
||||
return readZipEntries(buf).map((entry) => entry.name.replace(/\\/g, "/"));
|
||||
}
|
||||
|
||||
export function listZipFile(zipPath) {
|
||||
return listZipEntries(fs.readFileSync(zipPath));
|
||||
}
|
||||
|
||||
function localDataOffset(buf, localOffset) {
|
||||
if (localOffset + 30 > buf.length || buf.readUInt32LE(localOffset) !== 0x04034b50) {
|
||||
throw new Error("zip 本地头损坏");
|
||||
}
|
||||
const nameLen = buf.readUInt16LE(localOffset + 26);
|
||||
const extraLen = buf.readUInt16LE(localOffset + 28);
|
||||
return localOffset + 30 + nameLen + extraLen;
|
||||
}
|
||||
|
||||
export function extractZipBuffer(buf, dest) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
const root = path.resolve(dest);
|
||||
for (const entry of readZipEntries(buf)) {
|
||||
const rel = safeZipName(entry.name);
|
||||
if (!rel) continue;
|
||||
if (entry.compSize === 0xffffffff || entry.localOffset === 0xffffffff) {
|
||||
throw new Error("不支持 zip64");
|
||||
}
|
||||
if (entry.method !== 0 && entry.method !== 8) {
|
||||
throw new Error(`不支持的 zip 压缩方式 ${entry.method}`);
|
||||
}
|
||||
const start = localDataOffset(buf, entry.localOffset);
|
||||
const end = start + entry.compSize;
|
||||
if (end > buf.length) throw new Error("zip 数据被截断");
|
||||
const compressed = buf.subarray(start, end);
|
||||
const body = entry.method === 0 ? compressed : zlib.inflateRawSync(compressed);
|
||||
const out = path.resolve(root, rel);
|
||||
const prefix = root.endsWith(path.sep) ? root : root + path.sep;
|
||||
if (out !== root && !out.startsWith(prefix)) throw new Error("zip 路径不合法");
|
||||
fs.mkdirSync(path.dirname(out), { recursive: true });
|
||||
fs.writeFileSync(out, body);
|
||||
}
|
||||
}
|
||||
|
||||
function attempt(file, args, extra = {}) {
|
||||
try {
|
||||
execFileSync(file, args, {
|
||||
...HIDDEN,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
...extra,
|
||||
});
|
||||
return "";
|
||||
} catch (error) {
|
||||
const detail = String((error && (error.stderr || error.stdout || error.message)) || "")
|
||||
.trim()
|
||||
.split(/\r?\n/)
|
||||
.filter(Boolean)[0];
|
||||
return detail ? `${file}: ${detail}` : file;
|
||||
}
|
||||
}
|
||||
|
||||
/** 按平台试外部工具,最后用 Node 解 zip。成功返回用到的方式。 */
|
||||
export function extractZipArchive(zipPath, dest, tools = unzipTools()) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
const notes = [];
|
||||
for (const tool of tools) {
|
||||
if (tool === "node") {
|
||||
try {
|
||||
extractZipBuffer(fs.readFileSync(zipPath), dest);
|
||||
return "node";
|
||||
} catch (error) {
|
||||
notes.push(`node: ${error && error.message ? error.message : error}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tool === "tar" || tool === "bsdtar") {
|
||||
const note = attempt(tool, ["-xf", zipPath, "-C", dest]);
|
||||
if (!note) return tool;
|
||||
notes.push(note);
|
||||
continue;
|
||||
}
|
||||
if (tool === "unzip") {
|
||||
const note = attempt("unzip", ["-o", "-q", zipPath, "-d", dest]);
|
||||
if (!note) return "unzip";
|
||||
notes.push(note);
|
||||
continue;
|
||||
}
|
||||
if (tool === "python3") {
|
||||
const note = attempt("python3", ["-m", "zipfile", "-e", zipPath, dest]);
|
||||
if (!note) return "python3";
|
||||
notes.push(note);
|
||||
continue;
|
||||
}
|
||||
if (tool === "powershell") {
|
||||
const note = attempt(
|
||||
"powershell",
|
||||
["-NoProfile", "-Command", "Expand-Archive -LiteralPath $env:DSH_UPD_ZIP -DestinationPath $env:DSH_UPD_DIR -Force"],
|
||||
{ env: { ...process.env, DSH_UPD_ZIP: zipPath, DSH_UPD_DIR: dest } },
|
||||
);
|
||||
if (!note) return "powershell";
|
||||
notes.push(note);
|
||||
}
|
||||
}
|
||||
throw new Error(`解压失败:${notes.join(" | ") || "没有可用的解压工具"}`);
|
||||
}
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.32",
|
||||
"version": "1.1.34",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
@@ -39,6 +39,8 @@
|
||||
"test:identity": "node scripts/test-identity-assembly.mjs",
|
||||
"test:yaml": "node scripts/test-yaml-comment.mjs",
|
||||
"test:update": "node scripts/test-update-guards.mjs",
|
||||
"test:zip": "node scripts/test-zip-extract.mjs",
|
||||
"test:templates": "node scripts/test-template-page.mjs",
|
||||
"test:rewind": "node scripts/test-rewind-plan.mjs",
|
||||
"test:idempotence": "node scripts/test-patch-idempotence.mjs",
|
||||
"test:surface": "node scripts/test-surface-desktop.mjs",
|
||||
|
||||
@@ -1,3 +1,29 @@
|
||||
# 1.1.34
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本升级到 1.1.34。
|
||||
- **演练台知识库直接列出本机模板**。打开「知识库 · POC / EXP」就能看到一页 nuclei 模板,并可以翻页、按 CVE 或组件搜索。不再只显示「本机模板 N」、下面是空的。
|
||||
- **更新包在 Windows、macOS、Linux 上都能解压**。Linux 不再调用 PowerShell。顺序是:Windows 用 tar,不行再用 PowerShell;macOS 和 Linux 用 tar、unzip、python3、bsdtar。这些都没有时,用 Node 自己解 zip。感谢 @cracer4869 在 #44 报出 Kali 上的 `spawnSync powershell ENOENT`。
|
||||
|
||||
## English
|
||||
|
||||
- Version 1.1.34.
|
||||
- **The drill knowledge page lists local templates.** Opening Knowledge shows a page of nuclei templates, with paging and search by CVE or component. It no longer shows only the template count.
|
||||
- **Update archives extract on Windows, macOS, and Linux.** Linux does not call PowerShell. Windows tries tar, then PowerShell. macOS and Linux try tar, unzip, python3, then bsdtar. If none of those exist, Node extracts the zip itself. Thanks to @cracer4869 for reporting `spawnSync powershell ENOENT` on Kali in #44.
|
||||
|
||||
# 1.1.33
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本升级到 1.1.33。
|
||||
- **修复已经重启后,打开面板仍弹出「需要重启」**。官方客户端已经从解开的 `resources/app` 运行时,不再仅因为当前是官方进程就再要求退出一次。只有这次真的挪开了 `app.asar`,才会提示重启。
|
||||
|
||||
## English
|
||||
|
||||
- Version 1.1.33.
|
||||
- **Fix the restart dialog coming back after you already restarted.** When the official app is already running from the unpacked `resources/app`, opening the panel no longer asks you to quit again just because this is the official process. The restart prompt appears only when `app.asar` was actually moved aside in this run.
|
||||
|
||||
# 1.1.32
|
||||
|
||||
## 中文
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { dispatch, RedteamStore } from "../lib/redteam/store-core.js";
|
||||
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-tpl-"));
|
||||
const templates = path.join(root, "templates");
|
||||
fs.mkdirSync(path.join(templates, ".github"), { recursive: true });
|
||||
fs.mkdirSync(path.join(templates, "http"), { recursive: true });
|
||||
fs.writeFileSync(path.join(templates, ".github", "auto.yml"), "name: nope\n");
|
||||
fs.writeFileSync(
|
||||
path.join(templates, "http", "cve.yml"),
|
||||
"id: x\ninfo:\n name: CVE-2024-1 demo\n severity: high\n tags: cve\n",
|
||||
);
|
||||
|
||||
const prev = process.env.NUCLEI_TEMPLATES_DIR;
|
||||
process.env.NUCLEI_TEMPLATES_DIR = templates;
|
||||
let store;
|
||||
try {
|
||||
store = new RedteamStore(path.join(root, "rt"));
|
||||
const page = store.searchTemplates("", 40, 0);
|
||||
assert.equal(page.total, 2);
|
||||
assert.equal(page.matched, 1);
|
||||
assert.equal(page.items.length, 1);
|
||||
assert.equal(page.items[0].name, "CVE-2024-1 demo");
|
||||
assert.equal(page.items[0].severity, "high");
|
||||
const found = store.searchTemplates("CVE-2024-1");
|
||||
assert.equal(found.items.length, 1);
|
||||
const hidden = store.searchTemplates("nope");
|
||||
assert.equal(hidden.items[0].path.replace(/\\/g, "/"), ".github/auto.yml");
|
||||
const listed = dispatch(store, { op: "pocSearch", templateLimit: 40, templateOffset: 0 });
|
||||
assert.equal(listed.ok, true);
|
||||
assert.equal(listed.templates.items.length, 1);
|
||||
assert.equal(listed.templates.total, 2);
|
||||
console.log("ok: template page");
|
||||
} finally {
|
||||
try { store?.close(); } catch { /* ignore */ }
|
||||
if (prev === undefined) delete process.env.NUCLEI_TEMPLATES_DIR;
|
||||
else process.env.NUCLEI_TEMPLATES_DIR = prev;
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -40,18 +40,16 @@ const caughtUp = [
|
||||
];
|
||||
const ceiling = latestStableVersion(caughtUp);
|
||||
assert.equal(ceiling, "1.1.12");
|
||||
assert.equal(hideListedVersion(caughtUp[2], ceiling), true); // 已追上的旧 beta 标签仍隐藏
|
||||
assert.equal(hideListedVersion(caughtUp[3], ceiling), false); // beta 分支 tip 始终保留(并行通道)
|
||||
assert.equal(hideListedVersion(caughtUp[4], ceiling), false);
|
||||
assert.equal(hideListedVersion(caughtUp[2], ceiling), true);
|
||||
assert.equal(hideListedVersion(caughtUp[3], ceiling), true);
|
||||
assert.equal(hideListedVersion(caughtUp[4], ceiling), true);
|
||||
assert.equal(hideListedVersion({ ref: "v1.1.11-beta.1", version: "1.1.11-beta.1", channel: "beta" }, ""), true);
|
||||
|
||||
const visible = caughtUp.filter((item) => !hideListedVersion(item, ceiling));
|
||||
assert.deepEqual(visible.map((item) => item.ref), ["master", "v1.1.12", "beta", "v1.1.13-beta.1"]);
|
||||
assert.deepEqual(visible.map((item) => item.ref), ["master", "v1.1.12"]);
|
||||
const staleSha = "423a91614baa747b56749003d054fedb8e725714";
|
||||
const shown = markCurrent(visible, { channel: "stable", pin: "" }, "1.1.12", staleSha);
|
||||
assert.equal(shown.find((item) => item.ref === "master").current, true);
|
||||
assert.equal(shown.find((item) => item.ref === "v1.1.12").current, false);
|
||||
assert.equal(shown.find((item) => item.ref === "beta").current, false);
|
||||
assert.equal(shown.find((item) => item.ref === "v1.1.13-beta.1").current, false);
|
||||
|
||||
console.log("ok: update guards");
|
||||
@@ -0,0 +1,108 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import zlib from "node:zlib";
|
||||
import { extractZipArchive, extractZipBuffer, listZipEntries, unzipTools } from "../lib/zip-extract.js";
|
||||
|
||||
function crc32(buf) {
|
||||
let c = ~0;
|
||||
for (const byte of buf) {
|
||||
c ^= byte;
|
||||
for (let i = 0; i < 8; i += 1) c = (c >>> 1) ^ (0xedb88320 & -(c & 1));
|
||||
}
|
||||
return ~c >>> 0;
|
||||
}
|
||||
|
||||
function u16(n) {
|
||||
const b = Buffer.alloc(2);
|
||||
b.writeUInt16LE(n);
|
||||
return b;
|
||||
}
|
||||
|
||||
function u32(n) {
|
||||
const b = Buffer.alloc(4);
|
||||
b.writeUInt32LE(n >>> 0);
|
||||
return b;
|
||||
}
|
||||
|
||||
function buildZip(files) {
|
||||
const locals = [];
|
||||
const centrals = [];
|
||||
let offset = 0;
|
||||
for (const file of files) {
|
||||
const name = Buffer.from(file.name, "utf8");
|
||||
const body = Buffer.from(file.body);
|
||||
const method = file.method === 8 ? 8 : 0;
|
||||
const data = method === 8 ? zlib.deflateRawSync(body) : body;
|
||||
const crc = crc32(body);
|
||||
const local = Buffer.concat([
|
||||
u32(0x04034b50), u16(20), u16(0), u16(method), u16(0), u16(0),
|
||||
u32(crc), u32(data.length), u32(body.length), u16(name.length), u16(0),
|
||||
name, data,
|
||||
]);
|
||||
locals.push(local);
|
||||
const central = Buffer.concat([
|
||||
u32(0x02014b50), u16(20), u16(20), u16(0), u16(method), u16(0), u16(0),
|
||||
u32(crc), u32(data.length), u32(body.length), u16(name.length), u16(0), u16(0),
|
||||
u16(0), u16(0), u32(0), u32(offset),
|
||||
name,
|
||||
]);
|
||||
centrals.push(central);
|
||||
offset += local.length;
|
||||
}
|
||||
const cd = Buffer.concat(centrals);
|
||||
const eocd = Buffer.concat([
|
||||
u32(0x06054b50), u16(0), u16(0), u16(files.length), u16(files.length),
|
||||
u32(cd.length), u32(offset), u16(0),
|
||||
]);
|
||||
return Buffer.concat([...locals, cd, eocd]);
|
||||
}
|
||||
|
||||
assert.deepEqual(unzipTools("win32"), ["tar", "powershell", "node"]);
|
||||
assert.deepEqual(unzipTools("linux"), ["tar", "unzip", "python3", "bsdtar", "node"]);
|
||||
assert.deepEqual(unzipTools("darwin"), ["tar", "unzip", "python3", "bsdtar", "node"]);
|
||||
assert.equal(unzipTools("linux").includes("powershell"), false);
|
||||
assert.equal(unzipTools("darwin").includes("powershell"), false);
|
||||
|
||||
const zip = buildZip([
|
||||
{ name: "hello.txt", body: "hello", method: 0 },
|
||||
{ name: "nested/a.txt", body: "deflated-body", method: 8 },
|
||||
{ name: "dir/", body: "", method: 0 },
|
||||
]);
|
||||
assert.deepEqual(listZipEntries(zip), ["hello.txt", "nested/a.txt", "dir/"]);
|
||||
|
||||
const dest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-"));
|
||||
try {
|
||||
extractZipBuffer(zip, dest);
|
||||
assert.equal(fs.readFileSync(path.join(dest, "hello.txt"), "utf8"), "hello");
|
||||
assert.equal(fs.readFileSync(path.join(dest, "nested", "a.txt"), "utf8"), "deflated-body");
|
||||
assert.equal(fs.existsSync(path.join(dest, "..", "evil.txt")), false);
|
||||
} finally {
|
||||
fs.rmSync(dest, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
assert.throws(() => extractZipBuffer(buildZip([{ name: "../evil.txt", body: "no", method: 0 }]), dest));
|
||||
assert.equal(fs.existsSync(path.join(os.tmpdir(), "evil.txt")), false);
|
||||
|
||||
const zipPath = path.join(os.tmpdir(), `dsh-zip-src-${process.pid}.zip`);
|
||||
const viaDest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-via-"));
|
||||
const liveDest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-live-"));
|
||||
const fallbackDest = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-zip-fallback-"));
|
||||
fs.writeFileSync(zipPath, zip);
|
||||
try {
|
||||
const via = extractZipArchive(zipPath, viaDest, ["node"]);
|
||||
assert.equal(via, "node");
|
||||
assert.equal(fs.readFileSync(path.join(viaDest, "hello.txt"), "utf8"), "hello");
|
||||
const fallback = extractZipArchive(zipPath, fallbackDest, ["tar-does-not-exist", "node"]);
|
||||
assert.equal(fallback, "node");
|
||||
assert.equal(fs.readFileSync(path.join(fallbackDest, "nested", "a.txt"), "utf8"), "deflated-body");
|
||||
const live = extractZipArchive(zipPath, liveDest);
|
||||
assert.ok(["tar", "powershell", "unzip", "python3", "bsdtar", "node"].includes(live));
|
||||
console.log(`ok: zip extract via ${live} on ${process.platform}`);
|
||||
} finally {
|
||||
fs.rmSync(zipPath, { force: true });
|
||||
fs.rmSync(viaDest, { recursive: true, force: true });
|
||||
fs.rmSync(liveDest, { recursive: true, force: true });
|
||||
fs.rmSync(fallbackDest, { recursive: true, force: true });
|
||||
}
|
||||
Reference in new issue
Block a user