Upgrade to use @unlock-music/crypto #78

Merged
lsr merged 18 commits from upgrade/um-crypto-part1 into main 2024-09-24 22:19:32 +00:00
2 changed files with 30 additions and 1 deletions
Showing only changes of commit a3fbf9662b - Show all commits

View File

@ -5,6 +5,7 @@ import { QQMusicV1Decipher, QQMusicV2Decipher } from '~/decrypt-worker/decipher/
import { KuwoMusicDecipher } from '~/decrypt-worker/decipher/KuwoMusic.ts';
import { KugouMusicDecipher } from '~/decrypt-worker/decipher/KugouMusic.ts';
import { XimalayaAndroidDecipher, XimalayaPCDecipher } from '~/decrypt-worker/decipher/Ximalaya.ts';
import { XiamiDecipher } from '~/decrypt-worker/decipher/XiamiMusic.ts';
export enum Status {
OK = 0,
@ -51,7 +52,7 @@ export const allCryptoFactories: DecipherFactory[] = [
XimalayaPCDecipher.make,
// Xiami (*.xm)
// XiamiCrypto.make,
XiamiDecipher.make,
/// File with a fixed footer goes second

View File

@ -0,0 +1,28 @@
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();
}
}