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 |
10
.gitignore
vendored
10
.gitignore
vendored
@ -360,4 +360,12 @@ MigrationBackup/
|
|||||||
.ionide/
|
.ionide/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
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
|
#### Linux
|
||||||
在此项目根目录中执行 `./build-wasm` 即可构建。构建结果将位于此项目根目录的npm子目录中。
|
在此项目根目录中执行 `./build-wasm` 即可构建。构建结果将位于此项目根目录的npm子目录中。
|
||||||
#### Windows
|
#### Windows
|
||||||
@ -37,3 +39,5 @@ const decrypted= (await DecryptKgmWasm(cipherText, extension)).data;
|
|||||||
[授权协议]: https://github.com/nullptr-0/KgmWasm/blob/master/LICENSE.txt
|
[授权协议]: https://github.com/nullptr-0/KgmWasm/blob/master/LICENSE.txt
|
||||||
[kgm_wasm.ts]: https://github.com/nullptr-0/KgmWasm/blob/master/kgm_wasm.ts
|
[kgm_wasm.ts]: https://github.com/nullptr-0/KgmWasm/blob/master/kgm_wasm.ts
|
||||||
[GitHub Actions]: https://github.com/nullptr-0/KgmWasm/actions
|
[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
|
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
|
pushd build\emsdk
|
||||||
rem git pull
|
rem git pull
|
||||||
call emsdk.bat install 3.0.0
|
call emsdk.bat install 3.0.0
|
||||||
@ -21,13 +33,6 @@ popd
|
|||||||
pushd build\wasm
|
pushd build\wasm
|
||||||
|
|
||||||
call emcmake cmake -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ..\..
|
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
|
ninja.exe -f build.ninja -j 3
|
||||||
|
|
||||||
set "TARGET_FILES=KgmLegacy.js KgmWasm.js KgmWasm.wasm KgmWasmBundle.js %CURR_DIR%\LICENSE.txt"
|
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 KgmCryptoModule from '@xhacker/kgmwasm/KgmWasmBundle';
|
||||||
import { MergeUint8Array } from '@/utils/MergeUint8Array';
|
import { MergeUint8Array } from '@/utils/MergeUint8Array';
|
||||||
|
|
||||||
// 每次处理 2M 的数据
|
// 每次可以处理 2M 的数据
|
||||||
const DECRYPTION_BUF_SIZE = 2 *1024 * 1024;
|
const DECRYPTION_BUF_SIZE = 2 *1024 * 1024;
|
||||||
|
|
||||||
export interface KGMDecryptionResult {
|
export interface KGMDecryptionResult {
|
||||||
@ -36,12 +36,12 @@ export async function DecryptKgmWasm(kgmBlob: ArrayBuffer, ext: string): Promise
|
|||||||
|
|
||||||
// 申请内存块,并文件末端数据到 WASM 的内存堆
|
// 申请内存块,并文件末端数据到 WASM 的内存堆
|
||||||
let kgmBuf = new Uint8Array(kgmBlob);
|
let kgmBuf = new Uint8Array(kgmBlob);
|
||||||
const pQmcBuf = KgmCryptoObj._malloc(DECRYPTION_BUF_SIZE);
|
const pKgmBuf = KgmCryptoObj._malloc(DECRYPTION_BUF_SIZE);
|
||||||
KgmCryptoObj.writeArrayToMemory(kgmBuf.slice(0, DECRYPTION_BUF_SIZE), pQmcBuf);
|
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);
|
const headerSize = KgmCryptoObj.preDec(pKgmBuf, preDecDataSize, ext);
|
||||||
console.log(headerSize);
|
|
||||||
kgmBuf = kgmBuf.slice(headerSize);
|
kgmBuf = kgmBuf.slice(headerSize);
|
||||||
|
|
||||||
const decryptedParts = [];
|
const decryptedParts = [];
|
||||||
@ -52,14 +52,14 @@ export async function DecryptKgmWasm(kgmBlob: ArrayBuffer, ext: string): Promise
|
|||||||
|
|
||||||
// 解密一些片段
|
// 解密一些片段
|
||||||
const blockData = new Uint8Array(kgmBuf.slice(offset, offset + blockSize));
|
const blockData = new Uint8Array(kgmBuf.slice(offset, offset + blockSize));
|
||||||
KgmCryptoObj.writeArrayToMemory(blockData, pQmcBuf);
|
KgmCryptoObj.writeArrayToMemory(blockData, pKgmBuf);
|
||||||
KgmCryptoObj.decBlob(pQmcBuf, blockSize, offset);
|
KgmCryptoObj.decBlob(pKgmBuf, blockSize, offset);
|
||||||
decryptedParts.push(KgmCryptoObj.HEAPU8.slice(pQmcBuf, pQmcBuf + blockSize));
|
decryptedParts.push(KgmCryptoObj.HEAPU8.slice(pKgmBuf, pKgmBuf + blockSize));
|
||||||
|
|
||||||
offset += blockSize;
|
offset += blockSize;
|
||||||
bytesToDecrypt -= blockSize;
|
bytesToDecrypt -= blockSize;
|
||||||
}
|
}
|
||||||
KgmCryptoObj._free(pQmcBuf);
|
KgmCryptoObj._free(pKgmBuf);
|
||||||
|
|
||||||
result.data = MergeUint8Array(decryptedParts);
|
result.data = MergeUint8Array(decryptedParts);
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/xhacker-zzz/KgmWasm.git"
|
"url": "git+https://github.com/nullptr-0/KgmWasm.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"unlock-music",
|
"unlock-music",
|
||||||
@ -18,7 +18,7 @@
|
|||||||
"author": "xhacker-zzz",
|
"author": "xhacker-zzz",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bugs": {
|
"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