Skip to content

Commit 16b1384

Browse files
committed
First commit
0 parents  commit 16b1384

File tree

18 files changed

+8552
-0
lines changed

18 files changed

+8552
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.exe
2+
ncmdump
3+
4+
.vscode
5+
.idea
6+
7+
build
8+
9+
cmake-build-*

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "taglib"]
2+
path = taglib
3+
url = https://github.com/taglib/taglib.git

CMakeLists.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
3+
set(CMAKE_CXX_STANDARD 20)
4+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5+
project(ncmdump_wasm CXX)
6+
7+
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
8+
set(WITH_ZLIB OFF)
9+
set(BUILD_TESTING OFF)
10+
11+
add_subdirectory(taglib)
12+
13+
FILE(GLOB COMMON_HEADERS src/include/*.h)
14+
FILE(GLOB COMMON_SOURCES src/ncmcrypt.cpp src/utils/*.cpp)
15+
FILE(GLOB LIBRARY_HEADERS src/lib/libncmdump.h)
16+
FILE(GLOB LIBRARY_SOURCES src/lib/*.cpp)
17+
18+
# Emscripten 绑定接口的源文件
19+
set(WASM_INTERFACE_SOURCE src/wasm_interface.cpp)
20+
21+
if(EMSCRIPTEN)
22+
message(STATUS "Configuring WebAssembly build with Emscripten")
23+
24+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
25+
26+
add_executable(ncmdump_wasm
27+
${COMMON_SOURCES}
28+
${LIBRARY_SOURCES}
29+
${WASM_INTERFACE_SOURCE}
30+
)
31+
32+
target_include_directories(ncmdump_wasm PRIVATE
33+
src/include
34+
taglib
35+
taglib/taglib
36+
taglib/taglib/toolkit
37+
taglib/taglib/mpeg/id3v2
38+
)
39+
40+
target_link_libraries(ncmdump_wasm tag)
41+
42+
set_target_properties(ncmdump_wasm PROPERTIES OUTPUT_NAME "ncmdump")
43+
44+
target_compile_options(ncmdump_wasm PRIVATE
45+
-frtti # 启用运行时类型信息
46+
-fexceptions # 启用 C++ 异常
47+
)
48+
49+
target_link_options(ncmdump_wasm PRIVATE
50+
--bind
51+
-sMODULARIZE=1
52+
-sEXPORT_NAME="createNCMDumpModule"
53+
-sEXPORT_ES6=1
54+
-sUSE_ES6_IMPORT_META=1
55+
-sENVIRONMENT=web
56+
-sALLOW_MEMORY_GROWTH=1
57+
-sEXIT_RUNTIME=0
58+
#-sASSERTIONS=1
59+
-sNO_DISABLE_EXCEPTION_CATCHING
60+
)
61+
62+
install(TARGETS ncmdump_wasm
63+
RUNTIME DESTINATION wasm
64+
LIBRARY DESTINATION wasm
65+
ARCHIVE DESTINATION wasm
66+
)
67+
endif()

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```bash
2+
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release
3+
emmake make -j$nproc
4+
```
5+

decrypt.worker.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import createModule from './wasm/ncmdump.js';
2+
3+
let wasmModule = null;
4+
let isWasmReady = false;
5+
6+
createModule({
7+
locateFile: (path) => path.endsWith('.wasm') ? './wasm/ncmdump.wasm' : path,
8+
onRuntimeInitialized: function() {
9+
wasmModule = this;
10+
isWasmReady = true;
11+
self.postMessage({ type: 'wasm-ready' });
12+
}
13+
}).catch(err => {
14+
self.postMessage({
15+
type: 'error',
16+
error: `WASM加载失败: ${err.message}`
17+
});
18+
});
19+
20+
self.onmessage = async (e) => {
21+
const { type, payload } = e.data;
22+
23+
if (type === 'decrypt') {
24+
try {
25+
if (!isWasmReady) {
26+
throw new Error("WASM模块尚未初始化完成");
27+
}
28+
29+
const fileData = new Uint8Array(payload.fileData);
30+
const baseName = payload.baseNameWithoutExtension || "output";
31+
32+
const resultView = wasmModule.decryptNCM(fileData, baseName);
33+
34+
const result = new Uint8Array(resultView.length);
35+
result.set(resultView);
36+
37+
self.postMessage({
38+
type: 'decrypted',
39+
payload: {
40+
index: payload.index,
41+
result: result.buffer
42+
}
43+
}, [result.buffer]);
44+
45+
} catch (error) {
46+
self.postMessage({
47+
type: 'error',
48+
payload: {
49+
index: payload.index,
50+
error: error.message
51+
}
52+
});
53+
}
54+
}
55+
};

0 commit comments

Comments
 (0)