mirror of
https://git.unlock-music.dev/um/um-react.git
synced 2024-11-23 20:02:16 +00:00
fix: footer-less qmcv2 file support
This commit is contained in:
parent
5e890bca77
commit
9fed1ee610
@ -38,20 +38,32 @@ export class QQMusicV2Decipher implements DecipherInstance {
|
|||||||
this.cipherName = `QQMusic/QMC2(user_key=${+useUserKey})`;
|
this.cipherName = `QQMusic/QMC2(user_key=${+useUserKey})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async decrypt(buffer: Uint8Array, options: DecryptCommandOptions): Promise<DecipherResult | DecipherOK> {
|
parseFooter(buffer: Uint8Array): { size: number; ekey?: undefined | string } {
|
||||||
const footer = QMCFooter.parse(buffer.subarray(buffer.byteLength - 1024));
|
const footer = QMCFooter.parse(buffer.subarray(buffer.byteLength - 1024));
|
||||||
if (!footer) {
|
|
||||||
|
if (footer) {
|
||||||
|
const { size, ekey } = footer;
|
||||||
|
footer.free();
|
||||||
|
return { size, ekey };
|
||||||
|
}
|
||||||
|
|
||||||
|
// No footer, and we don't accept user key:
|
||||||
|
if (!this.useUserKey) {
|
||||||
throw new UnsupportedSourceFile('Not QMC2 File');
|
throw new UnsupportedSourceFile('Not QMC2 File');
|
||||||
}
|
}
|
||||||
|
|
||||||
const audioBuffer = buffer.slice(0, buffer.byteLength - footer.size);
|
return { size: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
async decrypt(buffer: Uint8Array, options: DecryptCommandOptions): Promise<DecipherResult | DecipherOK> {
|
||||||
|
const footer = this.parseFooter(buffer.subarray(buffer.byteLength - 1024));
|
||||||
const ekey = this.useUserKey ? options.qmc2Key : footer.ekey;
|
const ekey = this.useUserKey ? options.qmc2Key : footer.ekey;
|
||||||
footer.free();
|
|
||||||
if (!ekey) {
|
if (!ekey) {
|
||||||
throw new Error('EKey missing');
|
throw new Error('EKey required');
|
||||||
}
|
}
|
||||||
|
|
||||||
const qmc2 = new QMC2(ekey);
|
const qmc2 = new QMC2(ekey);
|
||||||
|
const audioBuffer = buffer.slice(0, buffer.byteLength - footer.size);
|
||||||
for (const [block, offset] of chunkBuffer(audioBuffer)) {
|
for (const [block, offset] of chunkBuffer(audioBuffer)) {
|
||||||
qmc2.decrypt(block, offset);
|
qmc2.decrypt(block, offset);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user