Dependency upgrade + lib_um_crypto_rust (#78)

Co-authored-by: 鲁树人 <[email protected]>
Co-committed-by: 鲁树人 <[email protected]>
This commit is contained in:
鲁树人 authored and 鲁树人 committed 2024-09-24 22:19:30 +00:00
1 parent c5bc436ab2
commit 58c96f264b
65 files changed
+4160 -4025

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { DecipherInstance, DecipherOK, DecipherResult, Status } from '~/decrypt-worker/Deciphers';
import { KuwoHeader, KWMDecipher } from '@unlock-music/crypto';
import type { DecryptCommandOptions } from '~/decrypt-worker/types.ts';
import { chunkBuffer } from '~/decrypt-worker/util/buffer.ts';
export class KuwoMusicDecipher implements DecipherInstance {
cipherName = 'Kuwo';
async decrypt(buffer: Uint8Array, options: DecryptCommandOptions): Promise<DecipherResult | DecipherOK> {
let header: KuwoHeader | undefined;
let kwm: KWMDecipher | undefined;
try {
header = KuwoHeader.parse(buffer.subarray(0, 0x400));
kwm = new KWMDecipher(header, options.kwm2key);
const audioBuffer = new Uint8Array(buffer.subarray(0x400));
for (const [block, offset] of chunkBuffer(audioBuffer)) {
kwm.decrypt(block, offset);
}
return {
status: Status.OK,
cipherName: this.cipherName,
data: audioBuffer,
};
} finally {
kwm?.free();
header?.free();
}
}
public static make() {
return new KuwoMusicDecipher();
}
}