@h-t-m/app-inspect
v0.4.0
Published
A local app package inspector — 6 platforms, 16 formats, runs in browser and Node.js
Maintainers
Readme
特性
- 纯本地 — Rust → WebAssembly,所有解析在本地完成,不上传文件。
- 最大努力提取 — 文件部分损坏时尽可能提取有效数据,失败部分以
warnings报告。 - 六平台全覆盖 — 16 种格式,详见平台覆盖。
- 按需解析 —
ParseOptions可跳过签名、图标等耗时子操作。 - 快速检测 —
detect()通过扩展名和魔术字节瞬时识别格式,无需加载 WASM。 - 框架检测 — 自动识别 11 种应用框架:Electron、Tauri、React Native、Flutter、uniApp、Capacitor、Cordova、微信小程序、Xamarin、Unity、Godot。
- 安全特征 — 二进制安全检测:PIE (ASLR)、NX (DEP)、SafeSEH、CFG、HighEntropyVA、RELRO、ARC;APK 篡改检测(多 EOCD、空文件名、路径冲突、未知压缩方法、头部不一致)、BadPack 弹性解压。
- 深度提取 — Android:activities、services、receivers、providers + intent-filters、uses-features、uses-permissions、DEX 头元数据、ARSC 资源配置(density/locale/gpu)、BadPack 篡改检测(5 指标);Apple:platform_family、embeddedBundles(Frameworks/XPCServices)、primaryBundle 打分选择、bundleKind 分类、Mach-O 元数据(UUID/dylib deps/load commands)、Code Signing 增强(cdhash/designatedRequirement/authorityChain)、mobileprovision 增强、隐私清单、URL Schemes、Background Modes、App Transport Security、usageDescriptions。
- TypeScript 原生 — ESM + CJS 双模,完整类型声明,39 类型 + 16 个类型守卫。
安装
npm install @h-t-m/app-inspect无原生依赖。
使用
浏览器
import { AppInfoParser } from '@h-t-m/app-inspect';
const file = document.querySelector('input[type=file]').files[0];
const parser = new AppInfoParser(file);
const { data, warnings } = await parser.parse();
console.log(data.icon); // base64 data URI 或 null
console.log(data.platformInfo); // 按平台判别也接受 Blob、ArrayBuffer、Uint8Array。
Node.js
import { AppInfoParser, isAndroidInfo, isIosInfo } from '@h-t-m/app-inspect';
const parser = new AppInfoParser('/path/to/app.apk');
const { data, warnings } = await parser.parse();
const pi = data.platformInfo;
if (isAndroidInfo(pi)) {
console.log(pi.manifest.package);
console.log(pi.signing?.sha256Fingerprint);
} else if (isIosInfo(pi)) {
console.log(pi.plistInfo?.bundleIdentifier);
console.log(pi.codeSign?.keyAlgorithm);
}也接受 Buffer、Uint8Array。
CLI
# JSON 输出
npx @h-t-m/app-inspect app.apk
# 格式化输出
npx @h-t-m/app-inspect app.apk --pretty
# 单文件摘要
npx @h-t-m/app-inspect app.apk --format table
# 导出图标
npx @h-t-m/app-inspect app.apk --all
# 快速格式检测(不加载 WASM)
npx @h-t-m/app-inspect app.apk --detect
# 提取特定字段
npx @h-t-m/app-inspect app.apk --field platformInfo.manifest.package
npx @h-t-m/app-inspect app.ipa --field platformInfo.plist.CFBundleIdentifier
# 多文件汇总(所有格式混用)
npx @h-t-m/app-inspect app1.apk app2.ipa app3.exe app4.deb --summary原生 CLI
除 npm 包外,项目还提供原生 Rust 二进制文件,无需 Node.js 运行时,启动更快(无 WASM 加载开销)。
# 构建聚合 CLI(支持所有格式)
cargo build --release --bin app-inspect
# 直接使用
./target/release/app-inspect app.apk --pretty
./target/release/app-inspect app.apk --format table
./target/release/app-inspect app.apk app.ipa app.deb --summary
./target/release/app-inspect app.apk --detect每个解析器也可独立构建:
cargo build --release -p apk-parser # 仅 APK/AAB
cargo build --release -p ipa-parser # 仅 IPA/macOS
cargo build --release -p hap-parser # 仅 HAP/APP
cargo build --release -p win-parser # 仅 Windows
cargo build --release -p linux-parser # 仅 Linux
cargo build --release -p crx-parser # 仅 Chrome 扩展
cargo build --release -p xpi-parser # 仅 Firefox 附加组件
cargo build --release -p pkg-parser # 仅 macOS .pkg
cargo build --release -p dmg-parser # 仅 macOS .dmg原生 CLI 支持 npm CLI 的全部选项(--pretty、--format table、--field、--all、--detect、--summary、--icon、--warnings、--raw-refs)。详见 app-inspect --help。
平台覆盖
| 维度 | Android (APK/AAB) | iOS (IPA) | HarmonyOS (HAP/APP) | Windows (PE/APPX/MSI) | Linux (DEB/RPM/AppImage) | macOS (.app) | macOS (.pkg) | macOS (.dmg) |
|---|---|---|---|---|---|---|---|---|
| 标识符 | package | CFBundleIdentifier | bundleName | PE productName、APPX identityName、MSI productName | DEB package、RPM name、AppImage name | CFBundleIdentifier | PackageInfo/@identifier | via bundles(CFBundleIdentifier) |
| 版本 | versionName + versionCode | CFBundleShortVersionString + CFBundleVersion | versionName + versionCode | PE fileVersion、APPX version、MSI productVersion | DEB version、RPM version-release | CFBundleShortVersionString + CFBundleVersion | PackageInfo/@version | UDIF version |
| CPU 架构 | nativeAbi(lib/ 扫描) | architecture(Mach-O) | nativeAbi(libs/ 扫描) | PE machineType、APPX architecture | DEB/RPM architecture | architectures(Mach-O,支持 FAT) | 嵌入式 .app bundle(Mach-O) | via bundles(Mach-O) |
| 清单/配置 | AndroidManifest.xml(二进制→JSON) | Info.plist(二进制/XML→JSON) | module.json(JSON) | PE 版本资源、APPX AppxManifest.xml、MSI 摘要信息 | DEB control、RPM header、AppImage desktop | Info.plist | Distribution XML + PackageInfo XML | Koly + plist → volume header(HFS+/APFS)→ catalog B-tree(.app bundles) |
| 签名 | X.509 证书链 + 签名方案(v1/v2/v3) | mobileprovision + Mach-O 代码签名(entitlements + 证书链) | Provision + X.509 证书(v2/v3) | PE/APPX/MSI Authenticode 证书链 | RPM GPG/PGP 密钥 | Mach-O 代码签名 | XAR CMS/PKCS#7 X.509 证书链 | via bundles(code sign) |
| 权限 | uses-permissions | NS*UsageDescription | requestPermissions | APPX capabilities | — | — | — | via bundles(NS*UsageDescription) |
| 系统版本 | minSdkVersion / targetSdkVersion | minimumOsVersion | minAPIVersion / targetAPIVersion | — | — | minimumOsVersion | — | via bundles(minimumOsVersion) |
| 图标 | 多密度(standard/round/adaptive) | AppIcon(含 CgBI→PNG) | 分层(icon + iconBackground) | PE/APPX/MSI 内嵌图标 | AppImage 内嵌 PNG | ICNS→PNG 转换 | 嵌入式 .app bundle(ICNS→PNG) | via bundles(ICNS→PNG) |
| 特有信息 | resources.arsc 资源表 | machoMetadata(UUID/platform/dylib)、embeddedBundles、primaryBundle、provisionInfo(14 字段) | packInfo(仅 .app) | PE versionInfo(8 字段)、PE clrRuntime(.NET)、PE manifest(UAC/DPI) | DEB depends/priority/section、RPM description/license/group | machoMetadata、embeddedBundles、primaryBundle | pkgRefs(子包引用)、installKbytes、distribution/packageInfo XML、primaryBundle | partitions(分区表)、volume(文件系统统计)、bundles(嵌入式 .app MacOsInfo)、primaryBundle |
所有图标编码为 base64 data URI。
浏览器扩展
| 维度 | CRX (Chrome 扩展) | XPI (Firefox 附加组件) |
|---|---|---|
| 清单 | manifest.json (Manifest V2/V3) | manifest.json (Manifest V2),兼容 install.rdf 降级 |
| 版本 | manifest_version + version | manifest_version + version |
| 权限 | permissions、host_permissions (V3) / matches (V2) | permissions |
| 签名 | 公钥提取 | META-INF 签名信息 |
| 图标 | 内嵌 PNG/SVG → base64 data URI | 内嵌 PNG/SVG → base64 data URI |
API 文档
完整类型定义和接口参考见 docs/api.md。
架构
输入 File / path / Blob / ArrayBuffer
│
▼
┌──────────────────────────────────┐
│ TypeScript 胶水层 │
│ src/parser.ts AppInfoParser │ 输入标准化、WASM 加载、平台路由
│ src/shared/ 类型、平台适配 │
├──────────────────────────────────┤
│ 原生 CLI(Rust 二进制) │
│ cli/src/main.rs app-inspect │ clap CLI,聚合所有解析器
│ parsers/*/src/main.rs │ 各平台独立二进制
├──────────────────────────────────┤
│ Rust / WebAssembly (wasm-pack) │ 全部解析逻辑(双模式 lib+bin)
│ ├── parsers/apk/ APK + AAB │
│ │ ├── manifest.rs 二进制 AndroidManifest.xml
│ │ ├── resource.rs resources.arsc
│ │ ├── signing.rs X.509 证书链
│ │ ├── abi.rs CPU 架构
│ │ └── zip.rs ZIP + 图标(多密度)
│ ├── parsers/ipa/ IPA + macOS │
│ │ ├── plist.rs 二进制/XML plist
│ │ ├── icon.rs CgBI PNG / ICNS → PNG
│ │ ├── provision.rs 描述文件
│ │ ├── macho.rs Mach-O 代码签名 + 架构
│ │ └── zip.rs ZIP + 图标
│ ├── parsers/hap/ HAP + APP │
│ │ ├── config.rs module.json
│ │ ├── icon.rs 分层图标
│ │ ├── abi.rs CPU 架构
│ │ ├── signing.rs Provision + X.509
│ │ └── zip.rs ZIP
│ ├── parsers/win/ Windows │
│ │ ├── pe.rs PE 版本信息 + CLR + manifest
│ │ ├── appx.rs APPX/MSIX 清单 + capabilities
│ │ └── msi.rs MSI OLE 摘要信息 + 签名
│ ├── parsers/linux/ Linux │
│ │ ├── deb.rs DEB control 字段
│ │ ├── rpm.rs RPM Lead + Header + GPG
│ │ └── appimage.rs AppImage desktop + 图标
│ ├── parsers/crx/ Chrome 扩展 │
│ │ └── lib.rs CRX 头部解析 + manifest.json
│ ├── parsers/xpi/ Firefox 附加组件│
│ │ └── lib.rs XPI manifest.json + install.rdf
│ ├── parsers/pkg/ macOS .pkg │
│ │ └── lib.rs XAR→cpio→.app bundle(最佳努力提取)
│ ├── parsers/dmg/ macOS .dmg │
│ │ └── lib.rs UDIF koly trailer 解析(Tier 1 信封)
│ └── core/ 公共组件 │
│ ├── xar.rs XAR 容器解析(gzip TOC→XML)
│ ├── cpio.rs cpio newc 读取器
│ ├── udif.rs UDIF koly trailer + plist 解析
│ ├── plist.rs 二进制/XML plist(从 ipa 迁移)
│ ├── macho.rs Mach-O 头部 + 代码签名(从 ipa 迁移)
│ ├── icon.rs CgBI PNG→标准 PNG(从 ipa 迁移)
│ ├── icns.rs ICNS→PNG 提取(从 ipa 迁移)
│ ├── framework.rs 应用框架检测(泛化为 &[String])
│ ├── der.rs ASN.1 DER(X.509 / PKCS#7)
│ ├── pe.rs PE/COFF 头部 + 安全特征
│ ├── appx.rs APPX/MSIX 应用清单
│ ├── ole.rs OLE 结构化存储
│ ├── msi.rs MSI 摘要信息 + 签名
│ ├── ar.rs AR 档案格式
│ ├── deb.rs DEB control 字段
│ ├── rpm.rs RPM Lead + Header
│ ├── appimage.rs AppImage desktop + 图标
│ ├── extension.rs 浏览器扩展 (CRX/XPI)
│ ├── zip.rs ZIP 档案读取器(EOCD 回退、4-mode 压缩)
│ └── lib.rs 跨平台共享类型
└──────────────────────────────────┘开发
# 前置条件: Rust + wasm-pack + Node.js 18+
npm install
npm run build # 开发构建
npm run build:release # 生产构建(wasm-opt -Oz + wasm-strip)
npm test # Vitest (TS) + cargo test (Rust)
npm run test:batch # 批量真实文件测试(需先 cargo build --release)
npm run test:browser # 浏览器 E2E 测试(Playwright)
npm run test:cross # 三通道对比测试(默认 ~/Downloads)
# 单平台构建(加快迭代)
npm run build:wasm:apk
npm run build:wasm:ipa
npm run build:wasm:hap
npm run build:wasm:win
npm run build:wasm:linux
npm run build:wasm:crx
npm run build:wasm:xpi
npm run build:wasm:pkg
npm run build:wasm:dmg测试
| 命令 | 说明 |
|------|------|
| npx vitest run | TS 单元测试(112 tests) |
| cargo test | Rust 单元测试(573 tests) |
| cargo clippy --all-targets | Rust lint |
| npm run test:cross | 三通道对比测试(Native CLI vs Node CLI vs Node WASM) |
| npm run test:batch | CLI 关键字段批量验证 |
| npm run test:browser:all | 浏览器 E2E 测试(Playwright + Chromium WASM) |
批量测试详情见 tests/batch/README.md,完整测试指南见 TESTING.md。
变更日志
详见 CHANGELOG.md。
致谢
本项目受 app-info-parser 启发。
以下项目的研究成果与算法设计对本项目的实现至关重要,没有它们的先行探索,很多核心功能难以完成。我们谨此致谢,并严格遵守其开源许可协议要求。
| 项目 | 许可 | 关键贡献 |
|------|------|----------|
| Wine/msitools | LGPL-2.1 | OLE 结构化存储流名编码算法,指导了 MSI 属性读取、Icon 表遍历和 SummaryInformation 解析 |
| aapt2 | Apache 2.0 | ARSC 值类型体系、AXML 命名空间模型 |
| androguard | Apache 2.0 | DEX 格式参考、签名方案研究 |
| apk-info | Apache 2.0 | BadPack 4-mode ZIP 提取算法、APK Signature Block 元数据 ID 枚举(13 种块 ID)、含 intent-filter 的组件模型 |
| apkInspector | Apache 2.0 | ZIP 篡改指标分类体系 |
| bundletool | Apache 2.0 | AAB 格式参考实现;BundleConfig.pb protobuf schema 定义 |
| msix-packaging | MIT | APPX 清单 schema 参考,字段完整度对标 IAppxManifestReader 接口 |
| 7-Zip DMG | LGPL | UDIF 块映射与 mish 条目字段布局参考 |
| apple-xar | Apache 2.0 | XAR TOC 完整模型参考(18 字段/file,含嵌套目录树、encoding、checksum) |
纯 Rust 压缩库
以下 crate 使 WASM 构建成为可能,无需任何 C 编译器依赖:
| Crate | 用途 | 格式 | |-------|------|------| | miniz_oxide | DEFLATE/zlib/gzip | APK / IPA / HAP / AppImage / RPM | | bzip2-rs | bzip2 | DMG | | lzfse_rust | LZFSE | DMG | | lzma-rs | XZ/LZMA | DEB / RPM | | ruzstd | zstd | DEB / RPM / AppImage |
格式规范
部分格式解析参考了以下官方规范与社区文档:
- Microsoft PE/COFF Specification
- Open Packaging Conventions (ISO/IEC 29500-2)
- Android Binary XML (AOSP)
- Apple Binary Property List Format — bplist00 二进制 plist 结构定义,Info.plist 解析基础
- Apple Mach-O File Format — LC_ENCRYPTION_INFO、LC_CODE_SIGNATURE 加载命令定义
协议
MIT
