mirror of
https://github.com/xhacker-zzz/KgmWasm.git
synced 2024-01-30 00:16:29 +00:00
Compare commits
5 Commits
4c8c4625e0
...
62ecc63af0
Author | SHA1 | Date | |
---|---|---|---|
62ecc63af0 | |||
c245ae7477 | |||
071ff334a0 | |||
3cb0d86841 | |||
13afecb949 |
8
.gitignore
vendored
8
.gitignore
vendored
@ -361,3 +361,11 @@ MigrationBackup/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# content from build
|
||||
npm/LICENSE.txt
|
||||
npm/QmcWasm.wasm
|
||||
npm/QmcLegacy.js
|
||||
npm/QmcWasm.js
|
||||
npm/QmcWasmBundle.js
|
||||
build/
|
@ -25,6 +25,8 @@ const decrypted= (await DecryptKgmWasm(cipherText, extension)).data;
|
||||
|
||||
### 自行构建
|
||||
|
||||
#### 依赖
|
||||
要自行构建此项目,请确保已经安装[Git]与[CMake]且其路径已经添加到 `PATH`
|
||||
#### Linux
|
||||
在此项目根目录中执行 `./build-wasm` 即可构建。构建结果将位于此项目根目录的npm子目录中。
|
||||
#### Windows
|
||||
@ -37,3 +39,5 @@ const decrypted= (await DecryptKgmWasm(cipherText, extension)).data;
|
||||
[授权协议]: https://github.com/nullptr-0/KgmWasm/blob/master/LICENSE.txt
|
||||
[kgm_wasm.ts]: https://github.com/nullptr-0/KgmWasm/blob/master/kgm_wasm.ts
|
||||
[GitHub Actions]: https://github.com/nullptr-0/KgmWasm/actions
|
||||
[Git]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
|
||||
[CMake]: https://cmake.org/download/
|
||||
|
@ -11,6 +11,18 @@ if not exist build\emsdk (
|
||||
git clone https://github.com/emscripten-core/emsdk.git build\emsdk
|
||||
)
|
||||
|
||||
rem Check for Ninja binary
|
||||
pushd build\wasm
|
||||
if not exist "ninja.exe" (
|
||||
rem Install Ninja
|
||||
curl -L https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip -o ninja.zip
|
||||
tar -xzvf ninja.zip
|
||||
del ninja.zip
|
||||
)
|
||||
rem must setup PATH for ninja first to avoid conflict with emsdk_env.bat
|
||||
set PATH="%PATH%;%cd%"
|
||||
popd
|
||||
|
||||
pushd build\emsdk
|
||||
rem git pull
|
||||
call emsdk.bat install 3.0.0
|
||||
@ -21,13 +33,6 @@ popd
|
||||
pushd build\wasm
|
||||
|
||||
call emcmake cmake -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ..\..
|
||||
rem Check if Ninja binary exists
|
||||
if not exist "ninja.exe" (
|
||||
rem Install Ninja
|
||||
curl -L https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip -o ninja.zip
|
||||
unzip ninja.zip
|
||||
del ninja.zip
|
||||
)
|
||||
ninja.exe -f build.ninja -j 3
|
||||
|
||||
set "TARGET_FILES=KgmLegacy.js KgmWasm.js KgmWasm.wasm KgmWasmBundle.js %CURR_DIR%\LICENSE.txt"
|
||||
|
18
kgm_wasm.ts
18
kgm_wasm.ts
@ -2,7 +2,7 @@ import { KgmCrypto } from '@xhacker/kgmwasm/KgmWasmBundle';
|
||||
import KgmCryptoModule from '@xhacker/kgmwasm/KgmWasmBundle';
|
||||
import { MergeUint8Array } from '@/utils/MergeUint8Array';
|
||||
|
||||
// 每次处理 2M 的数据
|
||||
// 每次可以处理 2M 的数据
|
||||
const DECRYPTION_BUF_SIZE = 2 *1024 * 1024;
|
||||
|
||||
export interface KGMDecryptionResult {
|
||||
@ -36,12 +36,12 @@ export async function DecryptKgmWasm(kgmBlob: ArrayBuffer, ext: string): Promise
|
||||
|
||||
// 申请内存块,并文件末端数据到 WASM 的内存堆
|
||||
let kgmBuf = new Uint8Array(kgmBlob);
|
||||
const pQmcBuf = KgmCryptoObj._malloc(DECRYPTION_BUF_SIZE);
|
||||
KgmCryptoObj.writeArrayToMemory(kgmBuf.slice(0, DECRYPTION_BUF_SIZE), pQmcBuf);
|
||||
const pKgmBuf = KgmCryptoObj._malloc(DECRYPTION_BUF_SIZE);
|
||||
const preDecDataSize = Math.min(DECRYPTION_BUF_SIZE, kgmBlob.byteLength); // 初始化缓冲区大小
|
||||
KgmCryptoObj.writeArrayToMemory(kgmBuf.slice(0, preDecDataSize), pKgmBuf);
|
||||
|
||||
// 进行解密初始化
|
||||
const headerSize = KgmCryptoObj.preDec(pQmcBuf, DECRYPTION_BUF_SIZE, ext);
|
||||
console.log(headerSize);
|
||||
const headerSize = KgmCryptoObj.preDec(pKgmBuf, preDecDataSize, ext);
|
||||
kgmBuf = kgmBuf.slice(headerSize);
|
||||
|
||||
const decryptedParts = [];
|
||||
@ -52,14 +52,14 @@ export async function DecryptKgmWasm(kgmBlob: ArrayBuffer, ext: string): Promise
|
||||
|
||||
// 解密一些片段
|
||||
const blockData = new Uint8Array(kgmBuf.slice(offset, offset + blockSize));
|
||||
KgmCryptoObj.writeArrayToMemory(blockData, pQmcBuf);
|
||||
KgmCryptoObj.decBlob(pQmcBuf, blockSize, offset);
|
||||
decryptedParts.push(KgmCryptoObj.HEAPU8.slice(pQmcBuf, pQmcBuf + blockSize));
|
||||
KgmCryptoObj.writeArrayToMemory(blockData, pKgmBuf);
|
||||
KgmCryptoObj.decBlob(pKgmBuf, blockSize, offset);
|
||||
decryptedParts.push(KgmCryptoObj.HEAPU8.slice(pKgmBuf, pKgmBuf + blockSize));
|
||||
|
||||
offset += blockSize;
|
||||
bytesToDecrypt -= blockSize;
|
||||
}
|
||||
KgmCryptoObj._free(pQmcBuf);
|
||||
KgmCryptoObj._free(pKgmBuf);
|
||||
|
||||
result.data = MergeUint8Array(decryptedParts);
|
||||
result.success = true;
|
||||
|
@ -8,7 +8,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/xhacker-zzz/KgmWasm.git"
|
||||
"url": "git+https://github.com/nullptr-0/KgmWasm.git"
|
||||
},
|
||||
"keywords": [
|
||||
"unlock-music",
|
||||
@ -18,7 +18,7 @@
|
||||
"author": "xhacker-zzz",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/xhacker-zzz/KgmWasm/issues"
|
||||
"url": "https://github.com/nullptr-0/KgmWasm/issues"
|
||||
},
|
||||
"homepage": "https://github.com/xhacker-zzz/KgmWasm#readme"
|
||||
"homepage": "https://github.com/nullptr-0/KgmWasm#readme"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user