diff --git a/src/decrypt/kgm_wasm.ts b/src/decrypt/kgm_wasm.ts index 039c3be..b2092cb 100644 --- a/src/decrypt/kgm_wasm.ts +++ b/src/decrypt/kgm_wasm.ts @@ -2,9 +2,6 @@ import { KgmCrypto } from '@xhacker/kgmwasm/KgmWasmBundle'; import KgmCryptoModule from '@xhacker/kgmwasm/KgmWasmBundle'; import { MergeUint8Array } from '@/utils/MergeUint8Array'; -// 每次处理 2M 的数据 -const DECRYPTION_BUF_SIZE = 2 *1024 * 1024; - export interface KGMDecryptionResult { success: boolean; data: Uint8Array; @@ -34,6 +31,9 @@ export async function DecryptKgmWasm(kgmBlob: ArrayBuffer, ext: string): Promise return result; } + // 每次处理 2M 的数据 + const DECRYPTION_BUF_SIZE = Math.min(2 *1024 * 1024, kgmBlob.byteLength); + // 申请内存块,并文件末端数据到 WASM 的内存堆 let kgmBuf = new Uint8Array(kgmBlob); const pQmcBuf = KgmCryptoObj._malloc(DECRYPTION_BUF_SIZE); @@ -41,7 +41,6 @@ export async function DecryptKgmWasm(kgmBlob: ArrayBuffer, ext: string): Promise // 进行解密初始化 const headerSize = KgmCryptoObj.preDec(pQmcBuf, DECRYPTION_BUF_SIZE, ext); - console.log(headerSize); kgmBuf = kgmBuf.slice(headerSize); const decryptedParts = []; diff --git a/src/decrypt/qmc_wasm.ts b/src/decrypt/qmc_wasm.ts index f747bf4..7789409 100644 --- a/src/decrypt/qmc_wasm.ts +++ b/src/decrypt/qmc_wasm.ts @@ -2,9 +2,6 @@ import { QmcCrypto } from '@xhacker/qmcwasm/QmcWasmBundle'; import QmcCryptoModule from '@xhacker/qmcwasm/QmcWasmBundle'; import { MergeUint8Array } from '@/utils/MergeUint8Array'; -// 每次处理 2M 的数据 -const DECRYPTION_BUF_SIZE = 2 *1024 * 1024; - export interface QMCDecryptionResult { success: boolean; data: Uint8Array; @@ -35,6 +32,9 @@ export async function DecryptQmcWasm(qmcBlob: ArrayBuffer, ext: string): Promise return result; } + // 每次处理 2M 的数据 + const DECRYPTION_BUF_SIZE = Math.min(2 *1024 * 1024, qmcBlob.byteLength); + // 申请内存块,并文件末端数据到 WASM 的内存堆 const qmcBuf = new Uint8Array(qmcBlob); const pQmcBuf = QmcCryptoObj._malloc(DECRYPTION_BUF_SIZE);