Compare commits

...

5 Commits

Author SHA1 Message Date
朱 征赜 62ecc63af0 bugfix for wrong buffer size for preDec 2023-08-29 00:55:06 +08:00
朱 征赜 c245ae7477 fix build script for Windows 2023-08-29 00:52:25 +08:00
朱 征赜 071ff334a0 ignore build output 2023-08-29 00:49:53 +08:00
朱 征赜 3cb0d86841 update url 2023-08-29 00:48:04 +08:00
朱 征赜 13afecb949 update readme 2023-08-29 00:45:58 +08:00
5 changed files with 37 additions and 20 deletions

10
.gitignore vendored
View File

@ -360,4 +360,12 @@ MigrationBackup/
.ionide/
# 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/

View File

@ -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/

View File

@ -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"

View File

@ -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;

View File

@ -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"
}