parent
970d2485a6
commit
7ade485d2e
|
@ -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;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { QmcCrypto } from '@xhacker/qmcwasm/QmcWasmBundle';
|
||||||
import QmcCryptoModule from '@xhacker/qmcwasm/QmcWasmBundle';
|
import QmcCryptoModule from '@xhacker/qmcwasm/QmcWasmBundle';
|
||||||
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 QMCDecryptionResult {
|
export interface QMCDecryptionResult {
|
||||||
|
@ -38,11 +38,12 @@ export async function DecryptQmcWasm(qmcBlob: ArrayBuffer, ext: string): Promise
|
||||||
// 申请内存块,并文件末端数据到 WASM 的内存堆
|
// 申请内存块,并文件末端数据到 WASM 的内存堆
|
||||||
const qmcBuf = new Uint8Array(qmcBlob);
|
const qmcBuf = new Uint8Array(qmcBlob);
|
||||||
const pQmcBuf = QmcCryptoObj._malloc(DECRYPTION_BUF_SIZE);
|
const pQmcBuf = QmcCryptoObj._malloc(DECRYPTION_BUF_SIZE);
|
||||||
QmcCryptoObj.writeArrayToMemory(qmcBuf.slice(-DECRYPTION_BUF_SIZE), pQmcBuf);
|
const preDecDataSize = Math.min(DECRYPTION_BUF_SIZE, qmcBlob.byteLength); // 初始化缓冲区大小
|
||||||
|
QmcCryptoObj.writeArrayToMemory(qmcBuf.slice(-preDecDataSize), pQmcBuf);
|
||||||
|
|
||||||
// 进行解密初始化
|
// 进行解密初始化
|
||||||
ext = '.' + ext;
|
ext = '.' + ext;
|
||||||
const tailSize = QmcCryptoObj.preDec(pQmcBuf, DECRYPTION_BUF_SIZE, ext);
|
const tailSize = QmcCryptoObj.preDec(pQmcBuf, preDecDataSize, ext);
|
||||||
if (tailSize == -1) {
|
if (tailSize == -1) {
|
||||||
result.error = QmcCryptoObj.getErr();
|
result.error = QmcCryptoObj.getErr();
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user