[xiami] feat: add xiami support
This commit is contained in:
parent
1cdd68e448
commit
a3fbf9662b
@ -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
|
||||
|
||||
|
28
src/decrypt-worker/decipher/XiamiMusic.ts
Normal file
28
src/decrypt-worker/decipher/XiamiMusic.ts
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user