From 75e7a2d84995aeaa3721a85d985b7f5b09ce6da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= <188421097+HunYiSage@users.noreply.github.com> Date: Sun, 27 Sep 2026 14:57:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=91=E5=B8=83=201.1.22=EF=BC=8C?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E6=A1=8C=E9=9D=A2=20app.asar=20=E8=BF=98?= =?UTF-8?q?=E5=9C=A8=E6=97=B6=E5=BA=94=E7=94=A8=E4=B8=8D=E5=86=8D=20ENOENT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 归档还在时改写真实 resources/app;没有归档时仍用 node:fs。 Co-authored-by: Cursor --- README.md | 12 ++--- README.zh-CN.md | 12 ++--- lib/core.js | 8 +-- lib/desktop.js | 5 +- lib/extract-asar.js | 119 ++++++++++++++++++++++++++++++++++------- lib/hide-console.js | 21 ++++---- lib/index.js | 5 +- lib/official-update.js | 3 +- package.json | 2 +- release-notes.md | 16 ++++++ 10 files changed, 153 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index ae01d6a..52d66fb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)

-

Version 1.1.21

+

Version 1.1.22

Local official DeepSeek Harness cybersecurity red-team plugin. Evaluate and adjust host safety policy on a controlled local install; swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐ @@ -197,13 +197,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv

🌐 Open Hub page  ·  - 🚀 Install in desktop client + 🚀 Install in desktop client

🔗 **Raw protocol URL:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.21&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.22&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz ```
@@ -219,7 +219,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.1.21', + version: '1.1.22', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz', @@ -238,7 +238,7 @@ export function installDshPurgeToDesktop() { **HTML link:** ```html - + 🚀 Install in desktop client ``` @@ -249,7 +249,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | Plugin id | | name | `dsh-purge` | Display name | -| version | `1.1.21` | Semver | +| version | `1.1.22` | Semver | | repo | `YuJunZhiXue/dsh-purge` | GitHub repo | | permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub source archive | diff --git a/README.zh-CN.md b/README.zh-CN.md index d9b8d3a..c414e82 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@

⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)

-

Version 1.1.21

+

Version 1.1.22

本机官方 DeepSeek Harness 网络安全红队评测插件。在受控本机里评测并调整宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -197,13 +197,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv

🌐 打开插件市场页  ·  - 🚀 唤起客户端一键安装 + 🚀 唤起客户端一键安装

🔗 **原生协议链接:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.21&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.22&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz ```
@@ -219,7 +219,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.1.21', + version: '1.1.22', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz', @@ -238,7 +238,7 @@ export function installDshPurgeToDesktop() { **HTML 静态链接方式:** ```html - + 🚀 唤起客户端一键安装 ``` @@ -249,7 +249,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | 插件唯一标识符 | | name | `dsh-purge` | 插件展示名称 | -| version | `1.1.21` | 语义化版本号 | +| version | `1.1.22` | 语义化版本号 | | repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 | | permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 | diff --git a/lib/core.js b/lib/core.js index aca4385..4ca2c39 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1,5 +1,3 @@ -import { promises as fsp } from "node:fs"; -import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { createHash } from "node:crypto"; @@ -13,10 +11,14 @@ import { revertHideConsoleFromBin, } from "./hide-console.js"; import * as desktop from "./desktop.js"; -import { asarArchiveIsFile, extractAsar, overlayAsarUnpacked, renameAsarAside } from "./extract-asar.js"; +import { asarArchiveIsFile, extractAsar, hostFs, overlayAsarUnpacked, renameAsarAside } from "./extract-asar.js"; import { adapterFor, detectSurface } from "./surface.js"; import { openSlot } from "./table-read.js"; +// 无归档时用 node:fs;app.asar 还在时改写真实的 resources/app,避免新建文件 ENOENT。 +const fs = hostFs; +const fsp = hostFs.promises; + const isWindows = process.platform === "win32"; const SHIM_NAMES = ["dsh.cmd", "dsh.ps1", "dsh"]; const HIDDEN_EXEC = { diff --git a/lib/desktop.js b/lib/desktop.js index c0f6583..ee9aac6 100644 --- a/lib/desktop.js +++ b/lib/desktop.js @@ -1,9 +1,12 @@ -import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { execFileSync, spawn } from "node:child_process"; import { fileURLToPath } from "node:url"; import { launchOfficialDesktopUpdate, pendingOfficialUpdate } from "./official-update.js"; +import { hostFs } from "./extract-asar.js"; + +// 无归档时用 node:fs。app.asar 还在时不能把映射出来的 resources/app 当成已经解开。 +const fs = hostFs; /** 路径落在 `app.asar/...` 里面。`app.asar` 文件本身和 `app.asar.unpacked` 不算。 */ export function isAsarSealedPath(p) { diff --git a/lib/extract-asar.js b/lib/extract-asar.js index 8c5ce42..e4e0197 100644 --- a/lib/extract-asar.js +++ b/lib/extract-asar.js @@ -1,15 +1,95 @@ -import fs from "node:fs"; +import nodeFs from "node:fs"; import path from "node:path"; import { createRequire } from "node:module"; -/** Electron 会把 app.asar 伪装成目录。读归档必须走 original-fs,否则 isFile 为假、解不开。 */ -function archiveFs() { +let cachedDiskFs; + +/** + * 真实磁盘上的 fs。 + * Electron 自带的 fs 会把 `resources/app` 映射进仍在的 `app.asar`, + * 往里面新建文件会 ENOENT。解开目录,以及归档还在时打补丁,走这里。 + * 非 Electron 环境没有 original-fs,退回 node:fs。 + */ +export function diskFs() { + if (cachedDiskFs) return cachedDiskFs; process.noDeprecation = true; try { - return createRequire(import.meta.url)("original-fs"); + cachedDiskFs = createRequire(import.meta.url)("original-fs"); } catch { - return fs; + cachedDiskFs = nodeFs; } + return cachedDiskFs; +} + +function asarFileIn(dir) { + if (!dir) return false; + try { + const asar = path.join(dir, "app.asar"); + return diskFs().existsSync(asar) && diskFs().statSync(asar).isFile(); + } catch { + return false; + } +} + +/** 这个路径会被 Electron 映射进旁边的 app.asar。已解开且归档已挪走时为假。 */ +export function asarShadowsPath(targetPath) { + const raw = String(targetPath || "").trim(); + if (!raw) return false; + let dir = path.normalize(raw); + for (let i = 0; i < 12; i += 1) { + const base = path.basename(dir).toLowerCase(); + if ((base === "app" || base.endsWith(".asar")) && asarFileIn(path.dirname(dir))) return true; + if (asarFileIn(dir)) return true; + const parent = path.dirname(dir); + if (!parent || parent === dir) break; + dir = parent; + } + return false; +} + +/** + * 宿主文件用哪套 fs。 + * 没有 app.asar(Web、第三方桌面、官方包已经解开并挪走归档)时继续用 node:fs。 + * 归档还在、Electron 会把 resources/app 映进去时,改用真实磁盘。 + */ +export function fsFor(targetPath) { + return asarShadowsPath(targetPath) ? diskFs() : nodeFs; +} + +function fsForPair(left, right) { + return asarShadowsPath(left) || asarShadowsPath(right) ? diskFs() : nodeFs; +} + +function route(method, pair) { + return (first, ...rest) => { + const f = pair ? fsForPair(first, rest[0]) : fsFor(first); + return f[method](first, ...rest); + }; +} + +const HOST_SYNC = [ + "existsSync", "statSync", "lstatSync", "readFileSync", "writeFileSync", + "readdirSync", "mkdirSync", "realpathSync", "chmodSync", "unlinkSync", + "rmSync", "renameSync", "appendFileSync", "openSync", "symlinkSync", +]; + +/** 按路径自动选择 node:fs 或真实磁盘。补丁、探测、状态都走这一个。 */ +export const hostFs = { + copyFileSync: route("copyFileSync", true), + promises: { + readFile: (p, ...args) => fsFor(p).promises.readFile(p, ...args), + writeFile: (p, ...args) => fsFor(p).promises.writeFile(p, ...args), + mkdir: (p, ...args) => fsFor(p).promises.mkdir(p, ...args), + unlink: (p, ...args) => fsFor(p).promises.unlink(p, ...args), + rm: (p, ...args) => fsFor(p).promises.rm(p, ...args), + copyFile: (src, dest, ...args) => fsForPair(src, dest).promises.copyFile(src, dest, ...args), + }, +}; +for (const method of HOST_SYNC) hostFs[method] = route(method, false); + +/** Electron 会把 app.asar 伪装成目录。读归档必须走 original-fs,否则 isFile 为假、解不开。 */ +function archiveFs() { + return diskFs(); } function renameBusy(error) { @@ -101,7 +181,8 @@ export function listAsarEntries(asarPath) { } function copyRange(afs, fd, offset, size, outPath) { - const out = fs.openSync(outPath, "w"); + const outFs = diskFs(); + const out = outFs.openSync(outPath, "w"); try { const buf = Buffer.alloc(Math.min(1024 * 1024, Math.max(size, 1))); let left = size; @@ -109,31 +190,32 @@ function copyRange(afs, fd, offset, size, outPath) { while (left > 0) { const n = afs.readSync(fd, buf, 0, Math.min(buf.length, left), pos); if (n <= 0) throw new Error(`asar short read at ${outPath}`); - fs.writeSync(out, buf, 0, n); + outFs.writeSync(out, buf, 0, n); pos += n; left -= n; } } finally { - fs.closeSync(out); + outFs.closeSync(out); } } /** asar 里标记 unpacked 的原生文件不在归档正文。解开目录启动前必须补到 resources/app。 */ export function overlayAsarUnpacked(asarPath, destDir) { + const outFs = diskFs(); const unpacked = `${asarPath}.unpacked`; - if (!destDir || !fs.existsSync(unpacked)) return { copied: 0, missing: true }; + if (!destDir || !outFs.existsSync(unpacked)) return { copied: 0, missing: true }; let copied = 0; const walk = (dir) => { - for (const ent of fs.readdirSync(dir, { withFileTypes: true })) { + for (const ent of outFs.readdirSync(dir, { withFileTypes: true })) { const from = path.join(dir, ent.name); const to = path.join(destDir, path.relative(unpacked, from)); if (ent.isDirectory()) { - fs.mkdirSync(to, { recursive: true }); + outFs.mkdirSync(to, { recursive: true }); walk(from); } else if (ent.isFile()) { - if (fs.existsSync(to)) continue; - fs.mkdirSync(path.dirname(to), { recursive: true }); - fs.copyFileSync(from, to); + if (outFs.existsSync(to)) continue; + outFs.mkdirSync(path.dirname(to), { recursive: true }); + outFs.copyFileSync(from, to); copied += 1; } } @@ -150,15 +232,16 @@ export function extractAsar(asarPath, destDir) { const { header, dataOffset } = readHeader(fd, afs); const entries = []; walk(header, "", entries); - fs.mkdirSync(destDir, { recursive: true }); + const outFs = diskFs(); + outFs.mkdirSync(destDir, { recursive: true }); for (const entry of entries) { const info = entry.info; const outPath = path.join(destDir, ...entry.rel.split("/")); - fs.mkdirSync(path.dirname(outPath), { recursive: true }); + outFs.mkdirSync(path.dirname(outPath), { recursive: true }); if (info.unpacked) continue; if (typeof info.link === "string") { try { - fs.symlinkSync(info.link, outPath); + outFs.symlinkSync(info.link, outPath); } catch { // 不能建链接就跳过,主程序文件仍在归档里 } @@ -167,7 +250,7 @@ export function extractAsar(asarPath, destDir) { const size = Number(info.size || 0); const offset = dataOffset + Number(info.offset || 0); if (size === 0) { - fs.writeFileSync(outPath, Buffer.alloc(0)); + outFs.writeFileSync(outPath, Buffer.alloc(0)); } else { copyRange(afs, fd, offset, size, outPath); } diff --git a/lib/hide-console.js b/lib/hide-console.js index 53403ef..1920ed8 100644 --- a/lib/hide-console.js +++ b/lib/hide-console.js @@ -3,6 +3,7 @@ import { pathToFileURL } from "node:url"; import { fileURLToPath } from "node:url"; import path from "node:path"; import { isAsarSealedPath } from "./desktop.js"; +import { diskFs, fsFor } from "./extract-asar.js"; const MARK = "__dshPurgeHideConsole"; const IMPORT_MARK = "dsh-purge-hide-console"; @@ -167,15 +168,15 @@ if (process.platform === "win32" && cp && !cp[MARK]) { `; } -function requireFs() { - return createRequire(import.meta.url)("node:fs"); -} function requirePath() { return createRequire(import.meta.url)("node:path"); } +function ioFor(explicit, targetPath) { + return explicit ?? fsFor(targetPath); +} + export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) { - const nodeFs = fs ?? requireFs(); const p = nodePath ?? requirePath(); const tries = []; const push = (x) => { @@ -199,7 +200,7 @@ export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) { try { const binJs = p.join(root, "lib", "bin.js"); if (isAsarSealedPath(root) || isAsarSealedPath(binJs)) continue; - if (nodeFs.existsSync(binJs)) return p.normalize(root); + if (ioFor(fs, binJs).existsSync(binJs)) return p.normalize(root); } catch {} } return null; @@ -209,16 +210,16 @@ const IMPORT_LINE = `import "./${IMPORT_MARK}.js"; // [dsh-purge] hide-console`; export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) { if (process.platform !== "win32") return "skipped_not_win32"; - const nodeFs = fs ?? requireFs(); const p = nodePath ?? requirePath(); - const root = resolveDshBinRoot(aiBase, { fs: nodeFs, path: p }); + const root = resolveDshBinRoot(aiBase, { fs, path: p }); if (!root) return "missing_bin"; + const nodeFs = ioFor(fs, root); const binJs = p.join(root, "lib", "bin.js"); const side = p.join(root, "lib", `${IMPORT_MARK}.js`); const facadeSide = p.join(root, "lib", "dsh-purge-child-process-hide.mjs"); if (isAsarSealedPath(root) || isAsarSealedPath(binJs)) return "sealed_asar"; - const facadeSrc = nodeFs.readFileSync( + const facadeSrc = diskFs().readFileSync( fileURLToPath(new URL("./child-process-hide.mjs", import.meta.url)), "utf8", ); @@ -244,10 +245,10 @@ export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) { } export function revertHideConsoleFromBin(aiBase, { fs, path: nodePath } = {}) { - const nodeFs = fs ?? requireFs(); const p = nodePath ?? requirePath(); - const root = resolveDshBinRoot(aiBase, { fs: nodeFs, path: p }); + const root = resolveDshBinRoot(aiBase, { fs, path: p }); if (!root) return "missing_bin"; + const nodeFs = ioFor(fs, root); const binJs = p.join(root, "lib", "bin.js"); const side = p.join(root, "lib", `${IMPORT_MARK}.js`); const facadeSide = p.join(root, "lib", "dsh-purge-child-process-hide.mjs"); diff --git a/lib/index.js b/lib/index.js index 1d4f852..271ff9e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,4 @@ -import fs from "node:fs"; -import { promises as fsp } from "node:fs"; +import { fsFor } from "./extract-asar.js"; import * as core from "./core.js"; import * as hostctl from "./host.js"; import * as rules from "./rules.js"; @@ -99,7 +98,7 @@ function watchWebTreeReady(ctx) { } function fsExists(fp) { - return fs.existsSync(fp); + return fsFor(fp).existsSync(fp); } function line(title, value, ok = null) { diff --git a/lib/official-update.js b/lib/official-update.js index 64425ce..af2f511 100644 --- a/lib/official-update.js +++ b/lib/official-update.js @@ -1,10 +1,9 @@ // 官方桌面已下载新版本时,重启改去跑安装包,装完再解开并重新打补丁。 -import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { spawn } from "node:child_process"; import { fileURLToPath } from "node:url"; -import { readAsarFile } from "./extract-asar.js"; +import { hostFs as fs, readAsarFile } from "./extract-asar.js"; const CACHE_DIR_NAME = "@deepseek-aidsh-desktop-updater"; const MARKER_NAME = "dsh-purge-reapply-asar"; diff --git a/package.json b/package.json index 51e991a..8d5efe8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-purge", - "version": "1.1.21", + "version": "1.1.22", "description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐", "type": "module", "main": "lib/index.js", diff --git a/release-notes.md b/release-notes.md index bd9ec94..6950d48 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,19 @@ +# 1.1.22 + +## 中文 + +- **修复官方桌面点「应用」报 ENOENT**。`app.asar` 还在时,新建 `dsh-purge-child-process-hide.mjs` 会失败,路径被写成 `resources\app.asar\...\dsh-purge-child-process-hide.mjs`,补丁停在待应用。 +- **原因**:官方客户端还带着 `app.asar` 时,Electron 会把 `resources\app` 映射进这个归档。归档里没有的新文件,用普通文件接口去创建就会 ENOENT。 +- **两种写法都保留**。归档还在时,改写真实磁盘上的 `resources\app`。没有 `app.asar` 时仍用原来的 `node:fs`,包括 Web、社区桌面,以及官方包已经解开并把归档挪成 `app.asar.bak` 的情况。 +- 安装目录不写死盘符。Web 和社区桌面的应用、重启保持原样。宿主仍对准 **dsh 0.1.7-rc.2**。 + +## English + +- **Fixes ENOENT when Apply runs on the official desktop.** While `app.asar` is still present, creating `dsh-purge-child-process-hide.mjs` failed. The path was rewritten to `resources\app.asar\...\dsh-purge-child-process-hide.mjs`, and patches stayed pending. +- **Cause**: with the archive still in place, Electron maps `resources\app` into `app.asar`. Creating a file that is not already in the archive through the normal file API throws ENOENT. +- **Both write paths stay.** If the archive is still there, files are written on the real `resources\app` directory. If there is no `app.asar`, the previous `node:fs` path is unchanged. That covers Web, community desktop, and an official install that has already been unpacked and had the archive moved to `app.asar.bak`. +- Install paths are not pinned to a drive letter. Web and community desktop keep their existing Apply and restart. The host target remains **dsh 0.1.7-rc.2**. + # 1.1.21 ## 中文