首页 / 全部技能 / 基础工具与工作流 / baoyu-electron-extract
基础工具与工作流 · JimLiu/baoyu-skills

baoyu-electron-extract

Extracts resources and JavaScript from any installed Electron app (`.asar` bundle), restoring original sources from `.js.map` files when available or formatting minified code with Prettier otherwise. Use when user wants to "extract Electron app", "decompile Electron", "get the source code of <app>", "inspect app.asar", "看 Electron 应用源码", "提取 .asar", or asks how a desktop Electron app is built. Skips `node_modules` and supports both macOS and Windows.

L4 高权限 · 分级授权与审计V1 已固定执行命令联网读写文件Dual-pass Audit
Author JimLiuGitHub JimLiu/baoyu-skills ↗Stars 25926License MIT(仓库根 LICENSE,Copyright (c) 2026 Jim Liu;GitHub API spdx_id=MIT)Commit 1567581c26
管控等级描述 skill 的能力与建议配套的管控措施,不代表质量或安全认证,也不表示可用或不可用。是否使用由用户和管理者决定。不同 agent 宿主对权限的约束各不相同,请勿假定宿主一定会提供安全兜底。第三方 skill 版权归原作者,使用风险由使用者自行承担。

1实现原理 · 为什么它能做到

解包不靠自研实现,而是运行时用 npx 即时拉取第三方包 @electron/asar 来 extract;参数以数组形式交给 spawn,没有 shell 字符串拼接。

skills/baoyu-electron-extract/scripts/main.ts
const args = ["-y", "@electron/asar", "extract", asarPath, dest];
这里在做什么:把「解 asar」这一件事外包给官方生态工具,skill 只负责应用发现、目录编排、还原与报告。代价是运行时会从 npm registry 下载并执行未在本仓锁定的第三方代码(本目录无 package.json / lockfile)。

还原原始源码树的前提是 .js.map 内嵌 sourcesContent;不满足就退回 prettier 格式化压缩代码——这就是宣称的『decompile』实际能力边界。

skills/baoyu-electron-extract/SKILL.md
only works when the `.js.map` embeds `sourcesContent`
同段说明这是现代打包器(webpack/esbuild/Vite/rollup)的常见情形,未内嵌的 map 会被跳过并记入 extract-report.json 的 warnings。即:还原的是构建产物里自带的源码副本,不是反编译算法。

无可用 source map 的 JS/CSS 由 npx prettier --write 批量就地格式化,使压缩代码可读。

skills/baoyu-electron-extract/scripts/main.ts
const args = ["-y", "prettier", "--write", ...batch];
分批调用;退出码非 0 只打印告警并继续(`prettier batch exited with code ${code} (continuing)`),保证主流程不被格式化失败打断。

跨平台应用发现:macOS 枚举 /Applications 与 ~/Applications,Windows 走 LOCALAPPDATA/PROGRAMFILES 等根目录;多命中即报错退出,要求用户改用绝对路径。

skills/baoyu-electron-extract/scripts/main.ts
const roots = ["/Applications", join(homedir(), "Applications")];
SKILL.md 对应写明:`If discovery finds multiple matches, the script exits and lists them — re-run with an absolute path.`;Linux 等平台直接抛错要求 --asar(`platform ${process.platform} is not auto-supported. Pass --asar /path/to/app.asar to override.`)。

写盘有硬护栏:禁止把输出写给根目录、用户 home 本身或当前工作目录;已存在的非空输出目录必须 --force 才写。

skills/baoyu-electron-extract/scripts/main.ts
const forbidden = [root, home, cwd];
SKILL.md 原文:`the script refuses to write to `/`, the user home directly, or the current working directory, and refuses to populate an existing non-empty output dir without `--force`.` 另外 --dry-run 只打印解析结果、不落盘。

node_modules 与 webpack/runtime 噪声在解包统计、source-map 还原、prettier 格式化三个环节全部跳过。

skills/baoyu-electron-extract/scripts/main.ts
return s.includes("node_modules/") || s.startsWith("webpack/runtime/");
SKILL.md 把它写成产品纪律:`**node_modules** is always skipped — both for source-map restoration and Prettier formatting — because vendored dependencies are noise when inspecting an app.`

source-map 的 sources[] 决定写盘路径,实现上先按 map 所在目录解析、再把可读路径收拢到 restored/ 下,只有无法归约成安全路径时才 hash 兜底。

skills/baoyu-electron-extract/SKILL.md
Use `restored/__unknown/<hash>.<ext>` only when the source name is empty or cannot be reduced to a safe file path.
这是本 skill 唯一接触『不可信输入决定路径』的地方,SKILL.md 用「Readable paths over hashes」段落把它规定为『先解析再消毒』;代码里对应 writeFileSync(target, content) 前的目录拼装与限制。

产物是文件树 + 机器可读报告:默认 ~/Downloads/<AppName>-electron-extract/,含 extract-report.json(计数、warnings),并支持 --json 单行摘要。

skills/baoyu-electron-extract/scripts/main.ts
join(outputDir, "extract-report.json"),
SKILL.md 输出树:`extract-report.json # JSON summary: counts, warnings, resolved paths`;--json 时改为单行 JSON 输出,便于 agent 直接读取计数。

2核心能力

01按应用名或绝对路径自动定位 app.asar(macOS/Windows 双平台)
02asar 解包(委托 @electron/asar)与 app.asar.unpacked/ 一并复制
03从 sourcesContent 还原原始源码目录树(含 sourceRoot 与 bundler 相对路径收拢)
04无 map 时用 Prettier 就地美化压缩 JS/CSS(可 --skip-format 关闭)
05安全写盘策略:拒绝危险目标目录、拒绝覆盖非空目录(除非 --force)、--dry-run 空跑预演
06结构化产物与报告:extracted/ + restored/ + extract-report.json(warnings 列出被跳过的 map)

3外部依赖

KindDependency / Endpoint
clinpx(Node 自带)/ bun
package@electron/asar(运行时 npx 拉取,未锁版本)
packageprettier(运行时 npx 拉取,未锁版本)
clibun(首选运行时;无 bun 时由 npx -y bun 兜底)

4管控建议与判定依据

建议配套管控措施
面向 Agent
分级或逐次授权,建议在沙箱运行
面向管理者
审批流程、可回滚、全程审计
判定依据(文件路径与关键语句摘要)
  • scripts/: 执行本地脚本或命令: bun {baseDir}/scripts/main.ts(或 npx -y bun …)——SKILL.md 指定的调用方式
  • 网络端点: 声明外部网络访问: registry.npmjs.org:首次运行由 npx -y 拉取 @electron/asar 与 prettier(本目录无 package.j
  • 本地工作目录: 文件读写与工件输出: 默认 ~/Downloads/<AppName>-electron-extract/:extracted/、extracted.unpacked/、r
审计说明: 。三段自证:① 判级对象是本 skill 目录(SKILL.md + scripts/main.ts + main.test.ts),不是宿主;② 目录内自身行为=本地读取本机已安装 Electron 应用的 app.asar 资源并写盘(输出到 ~/Downloads/…,有 forbidden=[/、home、cwd] 与 --force 护栏),用户内容不出网;唯一外发是一次可预期的固定端点拉包:`skills/baoyu-electron-extract/SKILL.md` 写明 `**No global installs** — `@electron/asar` and `prettier` are resolved on-the-fly via `npx -y`.`,即运行时从 registry.npmjs.org 拉取两个未锁版本的第三方包并执行其代码;③ 无凭证读取、无用户内容外发、无逆向/冒充/绕过/安全降级,故不升橙更不升红。供应链留意点(未锁版本的 npx 拉包)已写入 verdict.risks。

5第二遍独立确认

  • [ok] 解包委托 @electron/asar(非自研) — main.ts:404 逐字为 `const args = ["-y", "@electron/asar", "extract", asarPath, dest];`,spawn 以 argv 数组调用,无 shell 拼接。
  • [ok] npx 拉取未锁版本第三方包(供应链面) — 本目录无 package.json / lockfile,main.ts 内两处 npx 调用分别拉 @electron/asar 与 prettier;SKILL.md Notes 自述 'resolved on-the-fly via `npx -y`',与代码一致。
  • [ok] source map 还原能力边界(需内嵌 sourcesContent) — SKILL.md 明写只在 `.js.map` 内嵌 sourcesContent 时可用,未内嵌则跳过并记 warnings;无夸大表述。
  • [ok] 写盘护栏(/、home、cwd 拒绝;非空目录需 --force) — main.ts assertSafeOutputDir 用 `const forbidden = [root, home, cwd];`;SKILL.md Safety 段文字与代码一致。
  • [ok] 平台支持范围(仅 macOS/Windows 自动发现) — main.ts:310-313 对非 darwin/win32 平台直接抛错要求 --asar;SKILL.md 同述,无夸大。
  • [ok] 外部依赖清单是否完整 — 全目录扫描 URL/API/凭证 token 零命中;唯二第三方包为 @electron/asar 与 prettier(均经 npx),运行时 bun/npx 为宿主运行时而非依赖。
  • [ok] 元数据(license/stars/commit) — git rev-parse HEAD=1567581c26ec29f4216c6e6835415bf30343b0e3;仓库根 LICENSE 首行 'MIT License'、'Copyright (c) 2026 Jim Liu';GitHub API 返回 MIT / 25926 stars / 2026-09-10T15:13:43Z。
  • [discrepancy] 『decompile』措辞与实际能力是否相符 — 出题/触发词里的『decompile Electron』并不等于反编译:实际是解包 + 用构建产物自带的 source map 还原 + Prettier 美化(SKILL.md 自己写明前提是 sourcesContent 存在)。判级与结论不受影响,但详情页应写清这不是字节码/压缩代码的结构化反编译。

6结论

  • 把『看 Electron 应用内部』这一需求做成一条命令:应用发现、解包、还原、美化、报告全自动串起来,默认输出到 Downloads 而非污染工作目录。
  • 还原优先于美化:有 sourcesContent 就重建原始目录结构(webpack://、file://、?loader 等噪声会被剥离),效果远好于纯格式化。
  • 安全护栏写进代码而非仅文档:拒绝写入 /、home、cwd,非空目录必须 --force,另有 --dry-run 预演。
  • 跳过 node_modules/webpack runtime,让输出聚焦应用自身代码;所有跳过与异常汇总到 warnings,不静默。
  • 适合: 适合想在本地快速查看某桌面 Electron 应用内部结构(菜单/更新器/内嵌 API 端点/前端资源)的开发与安全研究人员,尤其做第三方客户端行为核查、给 Electron 应用写扩展、或学习他人工程组织时。macOS/Windows 上一条命令即可(示例:bun scripts/main.ts Codex)。
    不适合: 不适合把输出当作官方源码或用于合规取证(还原依赖构建产物自带的 source map,缺 map 时只能得到 Prettier 美化后的压缩代码);不适合 Linux 无 bun/Node 环境或期望零网络下载的场景(首跑必须拉 npx 包);不适合期望对 native 二进制/字节码做反编译的需求——本 skill 只处理 asar 内的 JS/CSS/资源。
    Install Agent-Ready
    ① Verified Mirror 2026-09-15
    Option A · Direct DownloadDownload baoyu-electron-extract.tar.gz
    sha256: 3d2a2257d7155c7c…
    Option B · Copy Guide for Agent
    install.json
    agent 读 JSON 指南后会自动从本站下载安装,无需更多说明。
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit 1567581c26.