mirror of
https://git.unlock-music.dev/um/um-react.git
synced 2025-05-23 16:27:41 +08:00
Co-authored-by: 鲁树人 <lu.shuren@um-react.app> Co-committed-by: 鲁树人 <lu.shuren@um-react.app>
29 lines
816 B
TypeScript
29 lines
816 B
TypeScript
import { DecipherInstance, DecipherOK, DecipherResult, Status } from '~/decrypt-worker/Deciphers.ts';
|
|
import { Xiami } from '@unlock-music/crypto';
|
|
import { chunkBuffer } from '~/decrypt-worker/util/buffer.ts';
|
|
|
|
export class XiamiDecipher implements DecipherInstance {
|
|
cipherName = 'Xiami (XM)';
|
|
|
|
async decrypt(buffer: Uint8Array): Promise<DecipherResult | DecipherOK> {
|
|
const xm = Xiami.from_header(buffer.subarray(0, 0x10));
|
|
const { copyPlainLength } = xm;
|
|
const audioBuffer = buffer.slice(0x10);
|
|
|
|
for (const [block] of chunkBuffer(audioBuffer.subarray(copyPlainLength))) {
|
|
xm.decrypt(block);
|
|
}
|
|
xm.free();
|
|
|
|
return {
|
|
cipherName: this.cipherName,
|
|
status: Status.OK,
|
|
data: audioBuffer,
|
|
};
|
|
}
|
|
|
|
public static make() {
|
|
return new XiamiDecipher();
|
|
}
|
|
}
|