Skip to content

Commit bcba013

Browse files
committed
Update README.md
1 parent 6b4c3ce commit bcba013

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,106 @@
1+
# ncmdump-web
2+
3+
适用于Web页面的网易云加密格式NCM解密工具,直接在前端转换,无需后端交互。
4+
5+
[taurusxin/ncmdump](https://github.com/taurusxin/ncmdump/)移植而来。
6+
7+
## 示例页面
8+
9+
这是一个简单的示例页面,可以直接使用。
10+
11+
[NCM 解密工具](https://tools.athbe.cn/ncm)
12+
13+
![示例页面](https://cloud.athbe.cn/f/N0Ij/I@%28XB15M5_UU0FY4FDPM~EU.png)
14+
15+
16+
17+
## 构建
18+
19+
20+
21+
安装WASM工具链(如果没有的话)
22+
123
```bash
24+
git clone https://github.com/emscripten-core/emsdk.git
25+
cd emsdk
26+
./emsdk install latest
27+
./emsdk activate latest
28+
# 这条指令每次启动都需要执行,为了使它永久生效,可将其添加到~/.bashrc
29+
source ./emsdk_env.sh
30+
```
31+
32+
下载源码并编译
33+
34+
```bash
35+
git clone https://github.com/AthBe1337/ncmdump-web.git
36+
cd ncmdump-web
37+
mkdir build && cd build
238
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release
339
emmake make -j$nproc
440
```
541

42+
此时你将得到`ncmdump.js``ncmdump.wasm`,你可以将它集成到你的web页面中。
43+
44+
### 调用方法示例
45+
46+
`index.html``decrypt.worker.js`提供了一个简易的使用示例。以下是`decrypt.worker.js`
47+
48+
```js
49+
import createModule from './wasm/ncmdump.js';
50+
51+
let wasmModule = null;
52+
let isWasmReady = false;
53+
54+
createModule({
55+
locateFile: (path) => path.endsWith('.wasm') ? './wasm/ncmdump.wasm' : path,
56+
onRuntimeInitialized: function() {
57+
wasmModule = this;
58+
isWasmReady = true;
59+
self.postMessage({ type: 'wasm-ready' });
60+
}
61+
}).catch(err => {
62+
self.postMessage({
63+
type: 'error',
64+
error: `WASM加载失败: ${err.message}`
65+
});
66+
});
67+
68+
self.onmessage = async (e) => {
69+
const { type, payload } = e.data;
70+
71+
if (type === 'decrypt') {
72+
try {
73+
if (!isWasmReady) {
74+
throw new Error("WASM模块尚未初始化完成");
75+
}
76+
77+
const fileData = new Uint8Array(payload.fileData);
78+
const baseName = payload.baseNameWithoutExtension || "output";
79+
80+
// 此处调用wasm函数
81+
const resultView = wasmModule.decryptNCM(fileData, baseName);
82+
83+
const result = new Uint8Array(resultView.length);
84+
result.set(resultView);
85+
86+
self.postMessage({
87+
type: 'decrypted',
88+
payload: {
89+
index: payload.index,
90+
result: result.buffer
91+
}
92+
}, [result.buffer]);
93+
94+
} catch (error) {
95+
self.postMessage({
96+
type: 'error',
97+
payload: {
98+
index: payload.index,
99+
error: error.message
100+
}
101+
});
102+
}
103+
}
104+
};
105+
```
106+

0 commit comments

Comments
 (0)